add game_config.combat experience

and make [harm_unit] use these values instead of hardcoded 8*level for
killing and level for combat.

(cherry-picked from commit 3591e82586)
This commit is contained in:
gfgtdf 2018-09-10 20:34:00 +02:00
parent 21e6b399e8
commit bc89512a5c
9 changed files with 25 additions and 15 deletions

View file

@ -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
@ -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

View file

@ -1458,8 +1458,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;

View file

@ -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) {
@ -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()) {

View file

@ -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){

View file

@ -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]);
@ -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();
@ -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;
}

View file

@ -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;
@ -277,6 +278,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);

View file

@ -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;
@ -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. */

View file

@ -1444,6 +1444,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",

View file

@ -879,6 +879,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);