Fixed attack prediction hardcoding kill xp.

Factored code for computing kill xp.
This commit is contained in:
Guillaume Melquiond 2009-09-13 07:04:36 +00:00
parent 6c6eb60020
commit 5ee8f2ce84
4 changed files with 11 additions and 13 deletions

View File

@ -1237,9 +1237,7 @@ attack::attack(const map_location &attacker, const map_location &defender,
}
if(dies) { // attacker kills defender
a_.xp_ = game_config::kill_experience * d_.get_unit().level();
if(d_.get_unit().level() == 0)
a_.xp_ = game_config::kill_experience / 2;
a_.xp_ = game_config::kill_xp(d_.get_unit().level());
d_.xp_ = 0;
resources::screen->invalidate(a_.iter_->first);
@ -1507,9 +1505,7 @@ attack::attack(const map_location &attacker, const map_location &defender,
}
if(dies) { // defender kills attacker
d_.xp_ = game_config::kill_experience * a_.get_unit().level();
if(a_.get_unit().level() == 0)
d_.xp_ = game_config::kill_experience / 2;
d_.xp_ = game_config::kill_xp(a_.get_unit().level());
a_.xp_ = 0;
resources::screen->invalidate(d_.iter_->first);

View File

@ -180,8 +180,7 @@ void attack_analysis::analyze(const gamemap& map, unit_map& units,
xp_for_advance = 1;
fight_xp = defend_it->second.level();
kill_xp = fight_xp ? fight_xp * game_config::kill_experience :
game_config::kill_experience / 2;
kill_xp = game_config::kill_xp(fight_xp);
if (fight_xp >= xp_for_advance) {
advance_prob = prob_fought;
@ -220,8 +219,7 @@ void attack_analysis::analyze(const gamemap& map, unit_map& units,
* kill_experience.
*/
int fight_xp = up->second.level();
int kill_xp = fight_xp ? fight_xp * game_config::kill_experience :
game_config::kill_experience / 2;
int kill_xp = game_config::kill_xp(fight_xp);
def_avg_experience += fight_xp * (1.0 - att.hp_dist[0]) + kill_xp * att.hp_dist[0];
if (m == movements.begin()) {
first_chance_kill = def.hp_dist[0];

View File

@ -24,7 +24,7 @@
#include "attack_prediction.hpp"
#include "game_config.hpp"
// Compile with -O3 -DBENCHMARK for speed testing,
// -DCHECK for testing correctness
@ -734,8 +734,7 @@ void combatant::consider_levelup(combatant &opp) {
} else if (u_.experience + ((opp.u_.level == 0) ? 4 : opp.u_.level * 8)
>= u_.max_experience) {
} else if (u_.experience + game_config::kill_xp(opp.u_.level) >= u_.max_experience) {
// if we kill, we will level up. So then the damage we had
// becomes less probable since it's now conditional on us not
// levelling up. This doesn't apply to the probability of us

View File

@ -37,6 +37,11 @@ namespace game_config
extern const std::string version;
extern const std::string revision;
inline int kill_xp(int level)
{
return level ? kill_experience * level : kill_experience / 2;
}
extern std::string wesnoth_program_dir;
/** Default percentage gold carried over to the next scenario. */