int defender_weapon() const { return bc_.get_defender_stats().attack_num; }
battle_prediction_pane::battle_prediction_pane(const battle_context &bc, const map_location &attacker_loc, const map_location &defender_loc) : gui::preview_pane(resources::screen->video()), attacker_loc_(attacker_loc), defender_loc_(defender_loc), attacker_(*resources::units->find(attacker_loc)), defender_(*resources::units->find(defender_loc)), attacker_label_(), defender_label_(), attacker_label_width_(0), defender_label_width_(0), attacker_left_strings_(), attacker_right_strings_(), defender_left_strings_(), defender_right_strings_(), attacker_strings_width_(0), attacker_left_strings_width_(0), attacker_right_strings_width_(0), defender_strings_width_(0), defender_left_strings_width_(0), defender_right_strings_width_(0), units_strings_height_(0), hp_distrib_string_(), attacker_hp_distrib_(), defender_hp_distrib_(), hp_distrib_string_width_(0), attacker_hp_distrib_width_(0), defender_hp_distrib_width_(0), attacker_hp_distrib_height_(0), defender_hp_distrib_height_(0), hp_distribs_height_(0), attacker_width_(0), defender_width_(0), units_width_(0), dialog_width_(0), dialog_height_(0) { // Predict the battle outcome. combatant attacker_combatant(bc.get_attacker_stats()); combatant defender_combatant(bc.get_defender_stats()); attacker_combatant.fight(defender_combatant); const battle_context_unit_stats& attacker_stats = bc.get_attacker_stats(); const battle_context_unit_stats& defender_stats = bc.get_defender_stats(); // Create the hitpoints distribution graphics. std::vector<std::pair<int, double> > hp_prob_vector; get_hp_prob_vector(attacker_combatant.hp_dist, hp_prob_vector); get_hp_distrib_surface(hp_prob_vector, attacker_stats, defender_stats, attacker_hp_distrib_, attacker_hp_distrib_width_, attacker_hp_distrib_height_); get_hp_prob_vector(defender_combatant.hp_dist, hp_prob_vector); get_hp_distrib_surface(hp_prob_vector, defender_stats, attacker_stats, defender_hp_distrib_, defender_hp_distrib_width_, defender_hp_distrib_height_); hp_distribs_height_ = std::max<int>(attacker_hp_distrib_height_, defender_hp_distrib_height_); // Build the strings and compute the layout. attacker_label_ = _("Attacker"); defender_label_ = _("Defender"); attacker_label_width_ = font::line_width(attacker_label_, font::SIZE_PLUS, TTF_STYLE_BOLD); defender_label_width_ = font::line_width(defender_label_, font::SIZE_PLUS, TTF_STYLE_BOLD); // Get the units strings. get_unit_strings(attacker_stats, attacker_, attacker_loc_, static_cast<float>(attacker_combatant.untouched), defender_, defender_loc_, defender_stats.weapon, attacker_left_strings_, attacker_right_strings_, attacker_left_strings_width_, attacker_right_strings_width_, attacker_strings_width_); get_unit_strings(defender_stats, defender_, defender_loc_, static_cast<float>(defender_combatant.untouched), attacker_, attacker_loc_, attacker_stats.weapon, defender_left_strings_, defender_right_strings_, defender_left_strings_width_, defender_right_strings_width_, defender_strings_width_); units_strings_height_ = std::max<int>(attacker_left_strings_.size(), defender_left_strings_.size()) * (font::SIZE_NORMAL + inter_line_gap_) + 14; hp_distrib_string_ = _("Expected Battle Result (HP)"); hp_distrib_string_width_ = font::line_width(hp_distrib_string_, font::SIZE_SMALL); attacker_width_ = std::max<int>(attacker_label_width_, attacker_strings_width_); attacker_width_ = std::max<int>(attacker_width_, hp_distrib_string_width_); attacker_width_ = std::max<int>(attacker_width_, attacker_hp_distrib_width_); defender_width_ = std::max<int>(defender_label_width_, defender_strings_width_); defender_width_ = std::max<int>(defender_width_, hp_distrib_string_width_); defender_width_ = std::max<int>(defender_width_, defender_hp_distrib_width_); units_width_ = std::max<int>(attacker_width_, defender_width_); dialog_width_ = 2 * units_width_ + inter_units_gap_; dialog_height_ = 15 + 24 + units_strings_height_ + 14 + 19 + hp_distribs_height_ + 18; // Set the dialog size. set_measurements(dialog_width_, dialog_height_); }
int weapon() const { return bc_.get_attacker_stats().attack_num; }