Skip to content

Commit

Permalink
add [endlevel] bonus=number
Browse files Browse the repository at this point in the history
instead of bonus=yes/no you can also pass a number, so bonus=0.5 will
give you only half of the bonus gold.
  • Loading branch information
gfgtdf committed Nov 30, 2015
1 parent 15df645 commit d755d3b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
14 changes: 11 additions & 3 deletions data/lua/wml-tags.lua
Expand Up @@ -1474,7 +1474,15 @@ function wml_actions.endlevel(cfg)
local there_is_a_human_defeat = false
local there_is_a_local_human_victory = false
local there_is_a_local_human_defeat = false

local bool_int = function(b)
if b == true then
return 0
elseif b == false then
return 1
else
return b
end
end
for k,v in ipairs(wesnoth.sides) do
local side_result = side_results[v.side] or {}
local victory_or_defeat = side_result.result or cfg.result or "victory"
Expand All @@ -1497,9 +1505,9 @@ function wml_actions.endlevel(cfg)
end
end
if side_result.bonus ~= nil then
v.carryover_bonus = side_result.bonus
v.carryover_bonus = bool_int(side_result.bonus)
elseif cfg.bonus ~= nil then
v.carryover_bonus = cfg.bonus
v.carryover_bonus = bool_int(cfg.bonus)
end
if side_result.carryover_add ~= nil then
v.carryover_add = side_result.carryover_add
Expand Down
4 changes: 2 additions & 2 deletions src/game_initialization/playcampaign.cpp
Expand Up @@ -65,7 +65,7 @@ void campaign_controller::report_victory(
{
report << "<small>" << _("Remaining gold: ") << utils::half_signed_value(t.gold()) << "</small>";

if(t.carryover_bonus()) {
if(t.carryover_bonus() != 0) {
if (turns_left > -1) {
report << "\n\n<b>" << _("Turns finished early: ") << turns_left << "</b>\n"
<< "<small>" << _("Early finish bonus: ") << finishing_bonus_per_turn << _(" per turn") << "</small>\n"
Expand Down Expand Up @@ -169,7 +169,7 @@ void campaign_controller::show_carryover_message(playsingle_controller& playcont
continue;
}
int finishing_bonus_per_turn = map.villages().size() * t.village_gold() + t.base_income();
int finishing_bonus = t.carryover_bonus() ? finishing_bonus_per_turn * turns_left : 0;
int finishing_bonus = t.carryover_bonus() * finishing_bonus_per_turn * turns_left;
t.set_carryover_gold(div100rounded((t.gold() + finishing_bonus) * t.carryover_percentage()));
if(!t.is_local_human())
{
Expand Down
8 changes: 6 additions & 2 deletions src/scripting/lua_team.cpp
Expand Up @@ -74,7 +74,7 @@ static int impl_side_get(lua_State *L)
return_cstring_attrib("controller", t.controller().to_string().c_str());
return_string_attrib("defeat_condition", t.defeat_condition().to_string());
return_string_attrib("share_vision", t.share_vision().to_string());
return_bool_attrib("carryover_bonus", t.carryover_bonus());
return_float_attrib("carryover_bonus", t.carryover_bonus());
return_int_attrib("carryover_percentage", t.carryover_percentage());
return_bool_attrib("carryover_add", t.carryover_add());
return_bool_attrib("lost", t.lost());
Expand Down Expand Up @@ -121,11 +121,15 @@ static int impl_side_set(lua_State *L)
modify_string_attrib("controller", t.change_controller_by_wml(value));
modify_string_attrib("color", t.set_color(value));
modify_string_attrib("defeat_condition", t.set_defeat_condition_string(value));
modify_bool_attrib("carryover_bonus", t.set_carryover_bonus(value));
modify_int_attrib("carryover_percentage", t.set_carryover_percentage(value));
modify_bool_attrib("carryover_add", t.set_carryover_add(value));
modify_bool_attrib("lost", t.set_lost(value));

if (strcmp(m, "carryover_bonus") == 0) {
t.set_carryover_bonus(luaL_checknumber(L, 3));
return 0;
}

if (strcmp(m, "recruit") == 0) {
t.set_recruits(std::set<std::string>());
if (!lua_istable(L, 3)) return 0;
Expand Down
4 changes: 2 additions & 2 deletions src/team.cpp
Expand Up @@ -112,7 +112,7 @@ team::team_info::team_info() :
lost(false),
carryover_percentage(game_config::gold_carryover_percentage),
carryover_add(false),
carryover_bonus(false),
carryover_bonus(0),
carryover_gold(0)
{
}
Expand Down Expand Up @@ -145,7 +145,7 @@ void team::team_info::read(const config &cfg)
side = cfg["side"].to_int(1);
carryover_percentage = cfg["carryover_percentage"].to_int(game_config::gold_carryover_percentage);
carryover_add = cfg["carryover_add"].to_bool(false);
carryover_bonus = cfg["carryover_bonus"].to_bool(false);
carryover_bonus = cfg["carryover_bonus"].to_double(1);
carryover_gold = cfg["carryover_gold"].to_int(0);
variables = cfg.child_or_empty("variables");

Expand Down
7 changes: 4 additions & 3 deletions src/team.hpp
Expand Up @@ -162,7 +162,8 @@ class team : public savegame::savegame_config

int carryover_percentage;
bool carryover_add;
bool carryover_bonus;
// TODO: maybe make this integer percentage? I like the float version more but this might casue OOS error because of floating point rounding differences on different hardware.
double carryover_bonus;
int carryover_gold;
config variables;
void handle_legacy_share_vision(const config& cfg);
Expand Down Expand Up @@ -350,8 +351,8 @@ class team : public savegame::savegame_config
int carryover_percentage() const { return info_.carryover_percentage; }
void set_carryover_add(bool value) { info_.carryover_add = value; }
bool carryover_add() const { return info_.carryover_add; }
void set_carryover_bonus(bool value) { info_.carryover_bonus = value; }
bool carryover_bonus() const { return info_.carryover_bonus; }
void set_carryover_bonus(double value) { info_.carryover_bonus = value; }
double carryover_bonus() const { return info_.carryover_bonus; }
void set_carryover_gold(int value) { info_.carryover_gold = value; }
int carryover_gold() const { return info_.carryover_gold; }
config& variables() { return info_.variables; }
Expand Down

0 comments on commit d755d3b

Please sign in to comment.