Skip to content

Commit

Permalink
add game_config.combat experience
Browse files Browse the repository at this point in the history
and make [harm_unit] use these values instead of hardcoded 8*level for
killing and level for combat.
  • Loading branch information
gfgtdf committed Sep 10, 2018
1 parent 08b7d1b commit 3591e82
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 15 deletions.
6 changes: 3 additions & 3 deletions data/lua/wml/harm_unit.lua
Expand Up @@ -163,8 +163,8 @@ function wml_actions.harm_unit(cfg)
wesnoth.float_label( unit_to_harm.x, unit_to_harm.y, string.format( "<span foreground='red'>%s</span>", text ) )

local function calc_xp( level ) -- to calculate the experience in case of kill
if level == 0 then return 4
else return level * 8 end
if level == 0 then return math.ceil(wesnoth.game_config.kill_experience / 2)
else return level * wesnoth.game_config.kill_experience end
end

if experience ~= false and harmer and harmer.valid
Expand All @@ -174,7 +174,7 @@ function wml_actions.harm_unit(cfg)
harmer.experience = harmer.experience + calc_xp( unit_to_harm.__cfg.level )
else
unit_to_harm.experience = unit_to_harm.experience + harmer.__cfg.level
harmer.experience = harmer.experience + unit_to_harm.__cfg.level
harmer.experience = harmer.experience + wesnoth.game_config.combat_experience * unit_to_harm.__cfg.level
end
end

Expand Down
4 changes: 2 additions & 2 deletions src/actions/attack.cpp
Expand Up @@ -1449,8 +1449,8 @@ void attack::perform()
d_.orig_attacks_ = d_stats_->num_blows;
a_.n_attacks_ = a_.orig_attacks_;
d_.n_attacks_ = d_.orig_attacks_;
a_.xp_ = d_.get_unit().level();
d_.xp_ = a_.get_unit().level();
a_.xp_ = game_config::combat_xp(d_.get_unit().level());
d_.xp_ = game_config::combat_xp(a_.get_unit().level());

bool defender_strikes_first = (d_stats_->firststrike && !a_stats_->firststrike);
unsigned int rounds = std::max<unsigned int>(a_stats_->rounds, d_stats_->rounds) - 1;
Expand Down
4 changes: 2 additions & 2 deletions src/ai/default/attack.cpp
Expand Up @@ -194,7 +194,7 @@ void attack_analysis::analyze(const gamemap& map, unit_map& units,
if (xp_for_advance == 0)
xp_for_advance = 1;

int fight_xp = defend_it->level();
int fight_xp = game_config::combat_xp(defend_it->level());
int kill_xp = game_config::kill_xp(fight_xp);

if (fight_xp >= xp_for_advance) {
Expand Down Expand Up @@ -233,7 +233,7 @@ void attack_analysis::analyze(const gamemap& map, unit_map& units,
* directly. For each level of attacker def gets 1 xp or
* kill_experience.
*/
int fight_xp = up->level();
int fight_xp = game_config::combat_xp(up->level());
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()) {
Expand Down
4 changes: 2 additions & 2 deletions src/ai/simulated_actions.cpp
Expand Up @@ -61,8 +61,8 @@ bool simulated_attack(const map_location& attacker_loc, const map_location& defe
LOG_AI_SIM_ACTIONS << "attacker's hp after attack: " << attack_unit->hitpoints() << std::endl;
LOG_AI_SIM_ACTIONS << "defender's hp after attack: " << defend_unit->hitpoints() << std::endl;

int attacker_xp = defend_unit->level();
int defender_xp = attack_unit->level();
int attacker_xp = game_config::combat_xp(defend_unit->level());
int defender_xp = game_config::combat_xp(attack_unit->level());
bool attacker_died = false;
bool defender_died = false;
if(attack_unit->hitpoints() <= 0){
Expand Down
12 changes: 6 additions & 6 deletions src/attack_prediction.cpp
Expand Up @@ -2035,13 +2035,13 @@ void one_strike_fight(const battle_context_unit_stats& stats,
return;
}

if(stats.experience + opp_stats.level >= stats.max_experience) {
if(stats.experience + game_config::combat_xp(opp_stats.level) >= stats.max_experience) {
forced_levelup(hp_dist);
} else if(stats.experience + game_config::kill_xp(opp_stats.level) >= stats.max_experience) {
conditional_levelup(hp_dist, opp_hp_dist[0]);
}

if(opp_stats.experience + stats.level >= opp_stats.max_experience) {
if(opp_stats.experience + game_config::combat_xp(stats.level) >= opp_stats.max_experience) {
forced_levelup(opp_hp_dist);
} else if(opp_stats.experience + game_config::kill_xp(stats.level) >= opp_stats.max_experience) {
conditional_levelup(opp_hp_dist, hp_dist[0]);
Expand Down Expand Up @@ -2180,13 +2180,13 @@ void complex_fight(attack_prediction_mode mode,
}

if(levelup_considered) {
if(stats.experience + opp_stats.level >= stats.max_experience) {
if(stats.experience + game_config::combat_xp(opp_stats.level) >= stats.max_experience) {
m->forced_levelup_a();
} else if(stats.experience + game_config::kill_xp(opp_stats.level) >= stats.max_experience) {
m->conditional_levelup_a();
}

if(opp_stats.experience + stats.level >= opp_stats.max_experience) {
if(opp_stats.experience + game_config::combat_xp(stats.level) >= opp_stats.max_experience) {
m->forced_levelup_b();
} else if(opp_stats.experience + game_config::kill_xp(stats.level) >= opp_stats.max_experience) {
m->conditional_levelup_b();
Expand Down Expand Up @@ -2447,12 +2447,12 @@ void combatant::fight(combatant& opponent, bool levelup_considered)
opponent.slowed = std::min(std::accumulate(opponent.summary[1].begin(), opponent.summary[1].end(), 0.0), 1.0);
}

if(u_.experience + opponent.u_.level >= u_.max_experience) {
if(u_.experience + game_config::combat_xp(opponent.u_.level) >= u_.max_experience) {
// We'll level up after the battle -> slow/poison will go away
poisoned = 0.0;
slowed = 0.0;
}
if(opponent.u_.experience + u_.level >= opponent.u_.max_experience) {
if(opponent.u_.experience + game_config::combat_xp(u_.level) >= opponent.u_.max_experience) {
opponent.poisoned = 0.0;
opponent.slowed = 0.0;
}
Expand Down
2 changes: 2 additions & 0 deletions src/game_config.cpp
Expand Up @@ -55,6 +55,7 @@ int village_income = 1;
int village_support = 1;
int recall_cost = 20;
int kill_experience = 8;
int combat_experience = 1;

int poison_amount = 8;
int rest_heal_amount = 2;
Expand Down Expand Up @@ -269,6 +270,7 @@ void load_config(const config &v)
rest_heal_amount = v["rest_heal_amount"].to_int(2);
recall_cost = v["recall_cost"].to_int(20);
kill_experience = v["kill_experience"].to_int(8);
combat_experience= v["combat_experience"].to_int(1);
lobby_refresh = v["lobby_refresh"].to_int(2000);
default_terrain = v["default_terrain"].str();
tile_size = v["tile_size"].to_int(72);
Expand Down
6 changes: 6 additions & 0 deletions src/game_config.hpp
Expand Up @@ -34,6 +34,7 @@ namespace game_config
extern int rest_heal_amount;
extern int recall_cost;
extern int kill_experience;
extern int combat_experience;
extern unsigned int tile_size;
extern unsigned lobby_network_timer;
extern unsigned lobby_refresh;
Expand All @@ -47,6 +48,11 @@ namespace game_config
return level ? kill_experience * level : kill_experience / 2;
}

inline int combat_xp(int level)
{
return combat_experience * level;
}

extern std::string wesnoth_program_dir;

/** Default percentage gold carried over to the next scenario. */
Expand Down
1 change: 1 addition & 0 deletions src/scripting/game_lua_kernel.cpp
Expand Up @@ -1443,6 +1443,7 @@ int game_lua_kernel::impl_game_config_set(lua_State *L)
modify_int_attrib("rest_heal_amount", game_config::rest_heal_amount = value);
modify_int_attrib("recall_cost", game_config::recall_cost = value);
modify_int_attrib("kill_experience", game_config::kill_experience = value);
modify_int_attrib("combat_experience", game_config::combat_experience = value);
modify_int_attrib("last_turn", tod_man().set_number_of_turns_by_wml(value));
modify_string_attrib("next_scenario", gamedata().set_next_scenario(value));
modify_string_attrib("theme",
Expand Down
1 change: 1 addition & 0 deletions src/scripting/lua_kernel_base.cpp
Expand Up @@ -878,6 +878,7 @@ int lua_kernel_base::impl_game_config_get(lua_State* L)
return_int_attrib("rest_heal_amount", game_config::rest_heal_amount);
return_int_attrib("recall_cost", game_config::recall_cost);
return_int_attrib("kill_experience", game_config::kill_experience);
return_int_attrib("combat_experience", game_config::combat_experience);
return_string_attrib("version", game_config::wesnoth_version.str());
return_bool_attrib("debug", game_config::debug);
return_bool_attrib("debug_lua", game_config::debug_lua);
Expand Down

0 comments on commit 3591e82

Please sign in to comment.