35 snprintf(str_buf, 10,
"100 %%");
36 }
else if(prob >= 0.1) {
37 snprintf(str_buf, 10,
"%4.1f %%", 100.0 * prob);
39 snprintf(str_buf, 10,
" %3.1f %%", 100.0 * prob);
54 attacker_loc_(attacker_loc),
55 defender_loc_(defender_loc),
60 attacker_label_width_(0),
61 defender_label_width_(0),
62 attacker_left_strings_(),
63 attacker_right_strings_(),
64 defender_left_strings_(),
65 defender_right_strings_(),
66 attacker_strings_width_(0),
67 attacker_left_strings_width_(0),
68 attacker_right_strings_width_(0),
69 defender_strings_width_(0),
70 defender_left_strings_width_(0),
71 defender_right_strings_width_(0),
72 units_strings_height_(0),
74 attacker_hp_distrib_(),
75 defender_hp_distrib_(),
76 hp_distrib_string_width_(0),
77 attacker_hp_distrib_width_(0),
78 defender_hp_distrib_width_(0),
79 attacker_hp_distrib_height_(0),
80 defender_hp_distrib_height_(0),
81 hp_distribs_height_(0),
91 attacker_combatant.
fight(defender_combatant);
97 std::vector<std::pair<int, double> > hp_prob_vector;
147 std::vector<std::string>& left_strings, std::vector<std::string>& right_strings,
148 int& left_strings_width,
int& right_strings_width,
int& strings_width)
150 std::stringstream str;
154 if(stats.
weapon !=
nullptr) {
167 for(i = dmg_effect.begin(); i != dmg_effect.end(); ++
i) {
169 set_dmg_effect = &*
i;
175 if(set_dmg_effect ==
nullptr) {
176 left_strings.push_back(weapon->
name());
179 right_strings.push_back(str.str());
181 assert(set_dmg_effect->ability);
183 left_strings.push_back((*set_dmg_effect->ability)[
"name"]);
185 str << set_dmg_effect->value;
186 right_strings.push_back(str.str());
190 for(i = dmg_effect.begin(); i != dmg_effect.end(); ++
i) {
192 left_strings.push_back((*i->ability)[
"name"]);
194 if(i->value >= 0) str <<
"+" << i->value;
195 else str << i->value;
196 right_strings.push_back(str.str());
201 for(i = dmg_effect.begin(); i != dmg_effect.end(); ++
i) {
203 left_strings.push_back((*i->ability)[
"name"]);
205 str <<
"× " << (i->value / 100);
207 str <<
"." << ((i->value % 100) / 10);
208 if(i->value % 10) str << (i->value % 10);
210 right_strings.push_back(str.str());
216 if(tod_modifier != 0) {
217 left_strings.push_back(
_(
"Time of day"));
220 right_strings.push_back(str.str());
224 int leadership_bonus = 0;
226 if(leadership_bonus != 0) {
227 left_strings.push_back(
_(
"Leadership"));
230 right_strings.push_back(str.str());
236 if(resistance_modifier != 100) {
239 else str <<
_(
"Attacker");
240 if(resistance_modifier < 100) str <<
_(
" resistance vs ");
241 else str <<
_(
" vulnerability vs ");
243 left_strings.push_back(str.str());
245 str <<
"× " << (resistance_modifier / 100) <<
"." << ((resistance_modifier % 100) / 10);
246 right_strings.push_back(str.str());
251 left_strings.push_back(
_(
"Slowed"));
252 right_strings.push_back(
"/ 2");
256 left_strings.push_back(
_(
"Total damage"));
259 right_strings.push_back(str.str());
263 left_strings.push_back(
_(
"No usable weapon"));
264 right_strings.push_back(
"");
268 left_strings.push_back(
_(
"Chance of being unscathed"));
270 right_strings.push_back(str_buf);
272 #if 0 // might not be in English!
274 for(
int i = 0;
i < (
int) left_strings.size();
i++)
275 if(left_strings[
i].
size() > 0) left_strings[
i][0] = toupper(left_strings[
i][0]);
288 for(
int i = 0; i < static_cast<int>(strings.size());
i++)
295 std::vector<std::pair<int, double> >& hp_prob_vector)
297 hp_prob_vector.clear();
300 std::vector<std::pair<double, int> > prob_hp_vector;
303 for(i = 0; i < static_cast<int>(hp_dist.size()); i++) {
304 double prob = hp_dist[
i];
308 prob_hp_vector.push_back(std::pair<double, int>(prob, i));
311 std::sort(prob_hp_vector.begin(), prob_hp_vector.end());
316 for(i = prob_hp_vector.size() - nb_elem;
317 i < static_cast<int>(prob_hp_vector.size()); i++) {
319 hp_prob_vector.push_back(std::pair<int, double>
320 (prob_hp_vector[i].second, prob_hp_vector[i].
first));
324 std::sort(hp_prob_vector.begin(), hp_prob_vector.end());
342 const std::vector<std::string>& left_strings,
343 const std::vector<std::string>& right_strings,
345 surface& hp_distrib,
int hp_distrib_width)
366 clip_rect.x + x_off + (
units_width_ - label_width) / 2, clip_rect.y + y_off, 0, TTF_STYLE_BOLD);
371 for(i = 0; i < static_cast<int>(left_strings.size()) - 2; i++) {
374 0, TTF_STYLE_NORMAL);
385 for(i = 0; i < 2; i++) {
386 const std::string& left_string = left_strings[left_strings.size() - 2 +
i];
387 const std::string& right_string = right_strings[right_strings.size() - 2 +
i];
391 0, TTF_STYLE_NORMAL);
425 int percent_sep = 43 + 6;
428 width = 30 + 2 + bar_space + 2 + percent_sep;
429 height = 5 + (fs + 2) * hp_prob_vector.size();
438 Uint32 grey_color = SDL_MapRGBA(surf->format, 0xb7, 0xc1, 0xc1, SDL_ALPHA_OPAQUE);
440 Uint32 background_color = SDL_MapRGBA(surf->format, 25, 25, 25, SDL_ALPHA_OPAQUE);
459 SDL_Rect percent_sep_rect =
sdl::create_rect(width - percent_sep - 2, 0, 2, height);
463 for(
int i = 0; i < static_cast<int>(hp_prob_vector.size());
i++) {
467 int hp = hp_prob_vector[hp_prob_vector.size() -
i - 1].first;
468 double prob = hp_prob_vector[hp_prob_vector.size() -
i - 1].second;
474 SDL_Color
color = {0xe5, 0, 0, SDL_ALPHA_OPAQUE};
479 else if(hp < static_cast<int>(stats.
hp)) {
482 SDL_Color
color = {0x9a, 0x9a, 0x9a, SDL_ALPHA_OPAQUE};
485 SDL_Color
color = {0xf4, 0xc9, 0, SDL_ALPHA_OPAQUE};
492 SDL_Color
color = {0x08, 0xca, 0, SDL_ALPHA_OPAQUE};
497 snprintf(str_buf, 10,
"%d", hp);
503 hp_sep - hp_width - 2, 2 + (fs + 2) *
i, 0, TTF_STYLE_NORMAL);
505 int bar_len = std::max<int>(
static_cast<int>((prob * (bar_space - 4)) + 0.5), 2);
507 SDL_Rect bar_rect_1 =
sdl::create_rect(hp_sep + 4, 6 + (fs + 2) *
i, bar_len, 8);
510 SDL_Rect bar_rect_2 =
sdl::create_rect(hp_sep + 4, 7 + (fs + 2) *
i, bar_len, 6);
513 SDL_Rect bar_rect_3 =
sdl::create_rect(hp_sep + 4, 8 + (fs + 2) *
i, bar_len, 4);
516 SDL_Rect bar_rect_4 =
sdl::create_rect(hp_sep + 4, 9 + (fs + 2) *
i, bar_len, 2);
523 width - prob_width - 4, 2 + (fs + 2) *
i, 0, TTF_STYLE_NORMAL);
530 const size_t index = size_t(selection);
534 std::vector<gui::preview_pane*> preview_panes;
535 preview_panes.push_back(&battle_pane);
std::vector< std::string > defender_left_strings_
int attacker_hp_distrib_height_
const t_string & name() const
int get_strings_max_length(const std::vector< std::string > &strings)
void get_hp_prob_vector(const std::vector< double > &hp_dist, std::vector< std::pair< int, double > > &hp_prob_vector)
surface create_neutral_surface(int w, int h)
int attacker_hp_distrib_width_
int hp_distrib_string_width_
std::string hp_distrib_string_
void fill_rect(surface &dst, SDL_Rect *dst_rect, const Uint32 color)
Fill a rectangle on a given surface.
std::string defender_label_
void set_specials_context(const map_location &unit_loc, const map_location &other_loc, bool attacking, const attack_type *other_attack) const
Sets the context under which specials will be checked for being active.
unsigned int hp
Hitpoints of the unit at the beginning of the battle.
surface defender_hp_distrib_
Various functions that implement attacks and attack calculations.
surface attacker_hp_distrib_
int attacker_strings_width_
bool is_slowed
True if the unit is slowed at the beginning of the battle.
const attack_type * weapon
The weapon used by the unit to attack the opponent, or nullptr if there is none.
void blit_surface(int x, int y, surface surf, SDL_Rect *srcrect=nullptr, SDL_Rect *clip_rect=nullptr)
int attacker_right_strings_width_
const SDL_Color NORMAL_COLOR
static const int inter_column_gap_
unsigned int chance_to_hit
Effective chance to hit as a percentage (all factors accounted for).
static void format_prob(char str_buf[10], double prob)
int attacker_label_width_
const map_location & defender_loc_
bool backstab_pos
True if the attacker is in position to backstab the defender (this is used to determine whether to ap...
battle_prediction_pane(const battle_context &bc, const map_location &attacker_loc, const map_location &defender_loc)
std::vector< std::string > attacker_left_strings_
static UNUSEDNOWARN std::string _(const char *str)
int damage
Effective damage of the weapon (all factors accounted for).
void get_unit_strings(const battle_context_unit_stats &stats, const unit &u, const map_location &u_loc, float u_unscathed, const unit &opp, const map_location &opp_loc, const attack_type *opp_weapon, std::vector< std::string > &left_strings, std::vector< std::string > &right_strings, int &left_strings_width, int &right_strings_width, int &strings_width)
unit_type::ALIGNMENT alignment() const
const std::vector< battle_context > & bc_vector_
const std::string unicode_en_dash
void draw_unit(int x_off, int damage_line_skip, int left_strings_width, const std::vector< std::string > &left_strings, const std::vector< std::string > &right_strings, const std::string &label, int label_width, surface &hp_distrib, int hp_distrib_width)
const battle_context_unit_stats & get_defender_stats() const
This method returns the statistics of the defender.
static const int inter_line_gap_
Computes the statistics of a battle between an attacker and a defender unit.
int show_dialog(CVideo &video, surface image, const std::string &caption, const std::string &message, DIALOG_TYPE type, const std::vector< std::string > *menu_items, const std::vector< preview_pane * > *preview_panes, const std::string &text_widget_label, std::string *text_widget_text, const int text_widget_max_chars, std::vector< check_item > *options, int xloc, int yloc, const dialog_frame::style *dialog_style, std::vector< dialog_button_info > *action_buttons, const menu::sorter *sorter, menu::style *menu_style)
void fight(combatant &opponent, bool levelup_considered=true)
Simulate a fight! Can be called multiple times for cumulative calculations.
std::string attacker_label_
int defender_hp_distrib_height_
void get_hp_distrib_surface(const std::vector< std::pair< int, double > > &hp_prob_vector, const battle_context_unit_stats &stats, const battle_context_unit_stats &opp_stats, surface &surf, int &width, int &height)
Structure describing the statistics of a unit involved in the battle.
int damage_from(const attack_type &attack, bool attacker, const map_location &loc) const
static const int inter_units_gap_
static const int max_hp_distrib_rows_
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
const std::string & type() const
Encapsulates the map of the game.
const map_location & attacker_loc_
SDL_Rect draw_text(surface &dst, const SDL_Rect &area, int size, const SDL_Color &color, const std::string &txt, int x, int y, bool use_tooltips, int style)
Function to draw text on a surface.
GLsizei const GLchar ** strings
surface & get_screen_surface()
return the screen surface or the surface used for map_screenshot.
int attacker_left_strings_width_
int defender_left_strings_width_
std::string signed_percent(int val)
Convert into a percentage (using the Unicode "−" and +0% convention.
int defender_right_strings_width_
int units_strings_height_
static int sort(lua_State *L)
unit_ability_list get_specials(const std::string &special) const
Returns the currently active specials as an ability list, given the current context (see set_specials...
GLint GLint GLint GLint GLint GLint GLsizei GLsizei height
SDL_Rect create_rect(const int x, const int y, const int w, const int h)
Creates an empty SDL_Rect.
std::vector< std::string > defender_right_strings_
SDL_Rect draw_text_line(surface &gui_surface, const SDL_Rect &area, int size, const SDL_Color &color, const std::string &text, int x, int y, bool use_tooltips, int style)
bool find(E event, F functor)
Tests whether an event handler is available.
const map_location & attacker_loc_
symbol_table string_table
const map_location & defender_loc_
unsigned int num_blows
Effective number of blows, takes swarm into account.
RESULT button_pressed(int selection)
std::vector< std::string > attacker_right_strings_
const battle_context_unit_stats & get_attacker_stats() const
This method returns the statistics of the attacker.
GLint GLint GLint GLint GLint GLint GLsizei width
bool is_attacker
True if the unit is the attacker.
int SDL_SetAlpha(SDL_Surface *surface, Uint32 flag, Uint8 alpha)
bool petrifies
Attack petrifies opponent when it hits.
Compatibility layer for using SDL 1.2 and 2.0.
map_location under_leadership(const unit_map &units, const map_location &loc, int *bonus)
function which tests if the unit at loc is currently affected by leadership.
GLsizei const GLcharARB ** string
Uint32 blend_rgba(const surface &surf, unsigned char r, unsigned char g, unsigned char b, unsigned char a, unsigned char drop)
This method blends a RGBA color.
int line_width(const std::string &line, int font_size, int style)
Determine the width of a line of text given a certain font size.
int defender_strings_width_
std::vector< individual_effect >::const_iterator const_iterator
int defender_hp_distrib_width_
int combat_modifier(const unit_map &units, const gamemap &map, const map_location &loc, unit_type::ALIGNMENT alignment, bool is_fearless)
Returns the amount that a unit's damage should be multiplied by due to the current time of day...
int defender_label_width_