Improved default weapon selection on player attack

(patch #500, by John Smith <decker> )
This commit is contained in:
Benoît Timbert 2006-01-06 23:26:17 +00:00
parent f9ddc7b05a
commit 7401d9b1a3
4 changed files with 33 additions and 13 deletions

View file

@ -9,6 +9,8 @@ SVN trunk (1.1+svn):
* updated translations: German, Hebrew, Norwegian, Russian
* units
* gave names to mermaids
* gameplay change :
* improved default weapon selection on player attack (patch #500)
* user interface
* centered BFW title logo on main screen for 1024x768 (still off-center for
800x600)

View file

@ -307,6 +307,9 @@ battle_stats evaluate_battle_stats(const gamemap& map,
attacker_terrain_override : map[attacker.x][attacker.y];
const gamemap::TERRAIN defender_terrain = map[defender.x][defender.y];
res.attacker_hp = a->second.hitpoints();
res.defender_hp = d->second.hitpoints();
res.chance_to_hit_attacker = a->second.defense_modifier(map,attacker_terrain);
res.chance_to_hit_defender = d->second.defense_modifier(map,defender_terrain);
@ -631,8 +634,8 @@ d->second.hitpoints(), d->second.max_hitpoints())
(res.attacker_slows || res.defender_slows)))
{
const int maxrounds = (res.to_the_death ? 30 : 1);
const int hpa = a->second.hitpoints();
const int hpb = d->second.hitpoints();
const int hpa = res.attacker_hp;
const int hpb = res.defender_hp;
const int dmga = res.damage_defender_takes;
const int dmgb = res.damage_attacker_takes;
const double pa = res.chance_to_hit_defender/100.0;

View file

@ -48,6 +48,7 @@ std::string recruit_unit(const gamemap& map, int team, unit_map& units,
//battle that could take place.
struct battle_stats
{
int attacker_hp, defender_hp;
int chance_to_hit_attacker, chance_to_hit_defender;
int damage_attacker_takes, damage_defender_takes;
int amount_attacker_drains, amount_defender_drains;

View file

@ -490,31 +490,45 @@ bool is_right_click(const SDL_MouseButtonEvent& event)
class simple_attack_rating
{
public:
simple_attack_rating() : attacker_weapon_rating_(0), defender_weapon_rating_(0) {}
simple_attack_rating(const battle_stats& stats) :
attacker_weapon_rating_(stats.chance_to_hit_defender *
stats.damage_defender_takes * stats.nattacks),
defender_weapon_rating_(stats.chance_to_hit_attacker *
stats.damage_attacker_takes * stats.ndefends) {}
simple_attack_rating() {}
simple_attack_rating(const battle_stats& stats) : stats_(stats) {}
bool operator<(const simple_attack_rating& a) const
{
//if our weapon can kill the enemy in one blow, the enemy does not
//drain back and our weapon has more blows, prefer our weapon
if(stats_.damage_defender_takes >= stats_.defender_hp &&
stats_.amount_defender_drains == 0 &&
stats_.nattacks > a.stats_.nattacks)
{
return false;
}
int this_avg_damage_dealt = stats_.chance_to_hit_defender *
stats_.damage_defender_takes * stats_.nattacks;
int this_avg_damage_taken = stats_.chance_to_hit_attacker *
stats_.damage_attacker_takes * stats_.ndefends;
int other_avg_damage_dealt = a.stats_.chance_to_hit_defender *
a.stats_.damage_defender_takes * a.stats_.nattacks;
int other_avg_damage_taken = a.stats_.chance_to_hit_attacker *
a.stats_.damage_attacker_takes * a.stats_.ndefends;
//if our weapon does less damage, it's worse
if(attacker_weapon_rating_ < a.attacker_weapon_rating_)
if(this_avg_damage_dealt < other_avg_damage_dealt)
return true;
//if both weapons are the same but
//ours makes the enemy retaliate for more damage, it's worse
else if(attacker_weapon_rating_ == a.attacker_weapon_rating_ &&
defender_weapon_rating_ > a.defender_weapon_rating_)
else if(this_avg_damage_dealt == other_avg_damage_dealt &&
this_avg_damage_taken > other_avg_damage_taken)
return true;
//otherwise, ours is at least as good a default weapon
return false;
}
private:
int attacker_weapon_rating_, defender_weapon_rating_;
battle_stats stats_;
};
} //end anonymous namespace