fix bug #7702 (and do it right this time)

This commit is contained in:
Jörg Hinrichs 2009-01-16 23:38:08 +00:00
parent 956672b2b3
commit 5ad98b06f0

View File

@ -1068,12 +1068,10 @@ attack::attack(game_display& gui, const gamemap& map,
// Used for stat calcualtion
int drains_damage = 0;
if (a_stats_->drains){
if (damage_defender_takes / 2 > d_->second.hitpoints())
// don't drain more than the defenders remaining hitpoints
drains_damage = d_->second.hitpoints();
else
// don't drain so much that the attacker gets more than his maximum hitpoints
drains_damage = std::min<int>(damage_defender_takes / 2,a_->second.max_hitpoints() - a_->second.hitpoints());
// don't drain so much that the attacker gets more than his maximum hitpoints
drains_damage = std::min<int>(damage_defender_takes / 2, a_->second.max_hitpoints() - a_->second.hitpoints());
// don't drain more than the defenders remaining hitpoints
drains_damage = std::min<int>(drains_damage, d_->second.hitpoints() / 2);
}
const int damage_done = std::min<int>(d_->second.hitpoints(), attacker_damage_);
bool dies = d_->second.take_hit(damage_defender_takes);
@ -1126,12 +1124,11 @@ attack::attack(game_display& gui, const gamemap& map,
if(dies || hits) {
int amount_drained = 0;
if (a_stats_->drains){
if (attacker_damage_ / 2 > d_->second.hitpoints())
// don't drain more than the defenders remaining hitpoints
amount_drained = d_->second.hitpoints();
else
// don't drain so much that the attacker gets more than his maximum hitpoints
amount_drained = std::min<int>(attacker_damage_ / 2,a_->second.max_hitpoints() - a_->second.hitpoints());
// don't drain so much that the attacker gets more than his maximum hitpoints
amount_drained = std::min<int>(attacker_damage_ / 2, a_->second.max_hitpoints() - a_->second.hitpoints());
// don't drain more than the defenders remaining hitpoints
// + attacker_damage accounts for the unit already being hit
amount_drained = std::min<int>(amount_drained, (d_->second.hitpoints() + attacker_damage_) / 2);
}
if(amount_drained > 0) {
@ -1353,12 +1350,10 @@ attack::attack(game_display& gui, const gamemap& map,
// used for stats calculation
int drains_damage = 0;
if (d_stats_->drains){
if (damage_attacker_takes / 2 > a_->second.hitpoints())
// don't drain more than the attackers remaining hitpoints
drains_damage = a_->second.hitpoints();
else
// don't drain so much that the defender gets more than his maximum hitpoints
drains_damage = std::min<int>(damage_attacker_takes / 2,d_->second.max_hitpoints() - d_->second.hitpoints());
// don't drain so much that the defender gets more than his maximum hitpoints
drains_damage = std::min<int>(damage_attacker_takes / 2, d_->second.max_hitpoints() - d_->second.hitpoints());
// don't drain more than the attackers remaining hitpoints
drains_damage = std::min<int>(drains_damage, a_->second.hitpoints() / 2);
}
const int damage_done = std::min<int>(a_->second.hitpoints(), defender_damage_);
bool dies = a_->second.take_hit(damage_attacker_takes);
@ -1404,14 +1399,13 @@ attack::attack(game_display& gui, const gamemap& map,
attack_stats.defend_result(hits ? (dies ? statistics::attack_context::KILLS : statistics::attack_context::HITS)
: statistics::attack_context::MISSES, damage_done, drains_damage);
if(hits || dies){
int amount_drained = d_stats_->drains ? defender_damage_ / 2 : 0;
int amount_drained = 0;
if (d_stats_->drains){
if (defender_damage_ / 2 > a_->second.hitpoints())
// don't drain more than the attackers remaining hitpoints
amount_drained = a_->second.hitpoints();
else
// don't drain so much that the defender gets more than his maximum hitpoints
amount_drained = std::min<int>(defender_damage_ / 2,d_->second.max_hitpoints() - d_->second.hitpoints());
// don't drain so much that the defender gets more than his maximum hitpoints
amount_drained = std::min<int>(defender_damage_ / 2, d_->second.max_hitpoints() - d_->second.hitpoints());
// don't drain more than the attackers remaining hitpoints
// + defender_damage accounts for the unit already being hit
amount_drained = std::min<int>(amount_drained, (a_->second.hitpoints() + defender_damage_) / 2);
}
if(amount_drained > 0) {