Fix: Chance to hit wasn't protected from becoming negative

Manual merge of pull request #3550. Credit to @newfrenchy83.

(cherry-picked from commit 79206d92d5)
This commit is contained in:
Jyrki Vesterinen 2018-09-23 16:52:24 +03:00
parent f55e11e733
commit d8869b8d2b

View file

@ -157,21 +157,21 @@ battle_context_unit_stats::battle_context_unit_stats(const unit& u,
}
// Compute chance to hit.
chance_to_hit = opp.defense_modifier(resources::gameboard->map().get_terrain(opp_loc)) + weapon->accuracy()
signed int cth = opp.defense_modifier(resources::gameboard->map().get_terrain(opp_loc)) + weapon->accuracy()
- (opp_weapon ? opp_weapon->parry() : 0);
if(chance_to_hit > 100) {
chance_to_hit = 100;
}
cth = utils::clamp(cth, 0, 100);
unit_ability_list cth_specials = weapon->get_specials("chance_to_hit");
unit_abilities::effect cth_effects(cth_specials, chance_to_hit, backstab_pos);
chance_to_hit = cth_effects.get_composite_value();
unit_abilities::effect cth_effects(cth_specials, cth, backstab_pos);
cth = cth_effects.get_composite_value();
if(opp.get_state("invulnerable")) {
chance_to_hit = 0;
cth = 0;
}
chance_to_hit = utils::clamp(cth, 0, 100);
// Compute base damage done with the weapon.
int base_damage = weapon->modified_damage(backstab_pos);
@ -306,13 +306,13 @@ battle_context_unit_stats::battle_context_unit_stats(const unit_type* u_type,
}
signed int cth = 100 - opp_terrain_defense + weapon->accuracy() - (opp_weapon ? opp_weapon->parry() : 0);
cth = std::min(100, cth);
cth = std::max(0, cth);
chance_to_hit = cth;
cth = utils::clamp(cth, 0, 100);
unit_ability_list cth_specials = weapon->get_specials("chance_to_hit");
unit_abilities::effect cth_effects(cth_specials, chance_to_hit, backstab_pos);
chance_to_hit = cth_effects.get_composite_value();
unit_abilities::effect cth_effects(cth_specials, cth, backstab_pos);
cth = cth_effects.get_composite_value();
chance_to_hit = utils::clamp(cth, 0, 100);
int base_damage = weapon->modified_damage(backstab_pos);
int damage_multiplier = 100;