Implement nonzero attack_weight, closes #3923 (#9096)

This commit is contained in:
Toom 2024-07-22 01:51:17 +03:00 committed by GitHub
parent ebaafe6d6b
commit f22f13f850
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 5 deletions

View file

@ -498,9 +498,14 @@ bool battle_context::better_combat(const combatant& us_a,
double poison_b_us = us_b.poisoned > 0 ? (us_b.poisoned - us_b.hp_dist[0]) * game_config::poison_amount : 0;
double poison_b_them = them_b.poisoned > 0 ? (them_b.poisoned - them_b.hp_dist[0]) * game_config::poison_amount : 0;
double attack_weight_a = us_a.u_.weapon->attack_weight();
double attack_weight_b = us_b.u_.weapon->attack_weight();
double damage_a = (them_a.u_.hp - them_a.average_hp()) * attack_weight_a;
double damage_b = (them_b.u_.hp - them_b.average_hp()) * attack_weight_b;
// Compare: damage to them - damage to us (average_hp replaces -damage)
a = (us_a.average_hp() - poison_a_us) * harm_weight - (them_a.average_hp() - poison_a_them);
b = (us_b.average_hp() - poison_b_us) * harm_weight - (them_b.average_hp() - poison_b_them);
a = (us_a.average_hp() - poison_a_us) * harm_weight + damage_a + poison_a_them;
b = (us_b.average_hp() - poison_b_us) * harm_weight + damage_b + poison_b_them;
if(a - b < -0.01) {
return false;
@ -511,7 +516,7 @@ bool battle_context::better_combat(const combatant& us_a,
}
// All else equal: go for most damage.
return them_a.average_hp() < them_b.average_hp();
return damage_a >= damage_b;
}
battle_context battle_context::choose_attacker_weapon(nonempty_unit_const_ptr attacker,

View file

@ -57,11 +57,11 @@ struct combatant
void reset();
#endif
const battle_context_unit_stats &u_;
private:
static const unsigned int MONTE_CARLO_SIMULATION_THRESHOLD = 50000u;
const battle_context_unit_stats &u_;
/** Summary of matrix used to calculate last battle (unslowed & slowed).
* Invariant: summary[1].size() == summary[0].size() or summary[1].empty() */
std::array<std::vector<double>, 2> summary;