Damage calculation dialog: use existing battle prediction
The game already predicts the outcome of all possible battles when the player opens the unit attack dialog, for the purpose of choosing the best weapon to attack. Simply use that data in the damage calculation dialog instead of recalculating it. The change in mouse_handler::fill_weapon_choices() ensures that the damage prediction will be present for all weapons. If bc is first copied to the vector and bc::better_attack() is called only after that, the copy of bc in the vector will never receive the damage prediction result.
This commit is contained in:
parent
5f9a711dab
commit
265e41dbda
3 changed files with 9 additions and 7 deletions
|
@ -48,7 +48,7 @@ const int battle_prediction_pane::inter_column_gap_ = 30;
|
|||
const int battle_prediction_pane::inter_units_gap_ = 30;
|
||||
const int battle_prediction_pane::max_hp_distrib_rows_ = 10;
|
||||
|
||||
battle_prediction_pane::battle_prediction_pane(const battle_context &bc,
|
||||
battle_prediction_pane::battle_prediction_pane(battle_context &bc,
|
||||
const map_location &attacker_loc, const map_location &defender_loc) :
|
||||
gui::preview_pane(resources::screen->video()),
|
||||
attacker_loc_(attacker_loc),
|
||||
|
@ -86,9 +86,8 @@ battle_prediction_pane::battle_prediction_pane(const battle_context &bc,
|
|||
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 combatant& attacker_combatant = bc.get_attacker_combatant();
|
||||
const combatant& defender_combatant = bc.get_defender_combatant();
|
||||
|
||||
const battle_context_unit_stats& attacker_stats = bc.get_attacker_stats();
|
||||
const battle_context_unit_stats& defender_stats = bc.get_defender_stats();
|
||||
|
|
|
@ -29,8 +29,11 @@ class battle_prediction_pane : public gui::preview_pane
|
|||
public:
|
||||
|
||||
// Lengthy constructor.
|
||||
battle_prediction_pane(const battle_context& bc,
|
||||
battle_prediction_pane(battle_context& bc,
|
||||
const map_location& attacker_loc, const map_location& defender_loc);
|
||||
battle_prediction_pane(battle_context&& bc,
|
||||
const map_location& attacker_loc, const map_location& defender_loc) :
|
||||
battle_prediction_pane(bc, attacker_loc, defender_loc) {}
|
||||
|
||||
// This method is called to draw the dialog contents.
|
||||
void draw_contents();
|
||||
|
|
|
@ -946,11 +946,11 @@ int mouse_handler::fill_weapon_choices(std::vector<battle_context>& bc_vector, u
|
|||
// skip weapons with attack_weight=0
|
||||
if (attacker->attacks()[i].attack_weight() > 0) {
|
||||
battle_context bc(pc_.gamestate().board_.units_, attacker->get_location(), defender->get_location(), i);
|
||||
bc_vector.push_back(bc);
|
||||
if (bc.better_attack(bc_vector[best], 0.5)) {
|
||||
if (!bc_vector.empty() && bc.better_attack(bc_vector[best], 0.5)) {
|
||||
// as some weapons can be hidden, i is not a valid index into the resulting vector
|
||||
best = bc_vector.size() - 1;
|
||||
}
|
||||
bc_vector.push_back(bc);
|
||||
}
|
||||
}
|
||||
return best;
|
||||
|
|
Loading…
Add table
Reference in a new issue