The gold carryover can now be modified from WML (bug #10144).
There's a known bug where continuing from a linger-mode save will not give the proper amount of gold, but this was already not working as expected (bug #10354).
This commit is contained in:
parent
0a88a03f61
commit
6f23494f45
11 changed files with 119 additions and 19 deletions
|
@ -32,6 +32,7 @@ Version 1.3.10+svn:
|
|||
* fix the recall list duplication bug (bug #10183)
|
||||
* [modify_side] can now override the recruit list, just like [set_recruit];
|
||||
should be the preferred method at some point.
|
||||
* the gold carryover can now be modified from wml (fr #10144)
|
||||
* units:
|
||||
* balancing changes:
|
||||
* increased the melee attack of the Saurian Oracle from 5-2 to 4-3
|
||||
|
|
|
@ -64,8 +64,10 @@ private:
|
|||
namespace victory_conditions
|
||||
{
|
||||
static bool when_enemies_defeated = true;
|
||||
static int carryover_percentage = 80;
|
||||
static bool carryover_add = false;
|
||||
|
||||
void set_victory_when_enemies_defeated(bool on)
|
||||
void set_victory_when_enemies_defeated(const bool on)
|
||||
{
|
||||
when_enemies_defeated = on;
|
||||
}
|
||||
|
@ -74,6 +76,26 @@ namespace victory_conditions
|
|||
{
|
||||
return when_enemies_defeated;
|
||||
}
|
||||
|
||||
void set_carryover_percentage(const int percentage)
|
||||
{
|
||||
carryover_percentage = percentage;
|
||||
}
|
||||
|
||||
static int get_carryover_percentage()
|
||||
{
|
||||
return carryover_percentage;
|
||||
}
|
||||
|
||||
void set_carryover_add(const bool add)
|
||||
{
|
||||
carryover_add = add;
|
||||
}
|
||||
|
||||
static bool get_carryover_add()
|
||||
{
|
||||
return carryover_add;
|
||||
}
|
||||
}
|
||||
|
||||
bool can_recruit_on(const gamemap& map, const gamemap::location& leader, const gamemap::location loc)
|
||||
|
@ -1653,7 +1675,10 @@ void check_victory(unit_map& units, std::vector<team>& teams)
|
|||
}
|
||||
|
||||
LOG_NG << "throwing end level exception...\n";
|
||||
throw end_level_exception(found_player ? VICTORY : DEFEAT);
|
||||
|
||||
throw end_level_exception(found_player ? VICTORY : DEFEAT,
|
||||
victory_conditions::get_carryover_percentage(),
|
||||
victory_conditions::get_carryover_add());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -329,7 +329,9 @@ bool unit_can_move(const gamemap::location& loc, const unit_map& units,
|
|||
|
||||
|
||||
namespace victory_conditions {
|
||||
void set_victory_when_enemies_defeated(bool on);
|
||||
void set_victory_when_enemies_defeated(const bool on);
|
||||
void set_carryover_percentage(const int percentage);
|
||||
void set_carryover_add(const bool add);
|
||||
}
|
||||
|
||||
//! Function to check if an attack will satisfy the requirements for backstab.
|
||||
|
|
|
@ -75,8 +75,12 @@ void get_player_info(const config& cfg, game_state& gamestate,
|
|||
LOG_NG << "found gold: '" << gold << "'\n";
|
||||
|
||||
int ngold = lexical_cast_default<int>(gold);
|
||||
if ( (player != NULL) && (player->gold >= ngold) && (!snapshot) ) {
|
||||
ngold = player->gold;
|
||||
if ( (player != NULL) && (!snapshot) ) {
|
||||
if(player->gold_add) {
|
||||
ngold += player->gold;
|
||||
} else if(player->gold >= ngold) {
|
||||
ngold = player->gold;
|
||||
}
|
||||
}
|
||||
|
||||
LOG_NG << "set gold to '" << ngold << "'\n";
|
||||
|
|
|
@ -36,6 +36,8 @@ namespace game_config
|
|||
int recall_cost = 20;
|
||||
int kill_experience = 8;
|
||||
unsigned lobby_refresh = 2000;
|
||||
const int gold_carryover_percentage = 80;
|
||||
const bool gold_carryover_add = false;
|
||||
const std::string version = VERSION;
|
||||
#ifdef SVNREV
|
||||
const std::string svnrev = SVNREV;
|
||||
|
|
|
@ -36,6 +36,14 @@ namespace game_config
|
|||
extern const std::string version;
|
||||
extern const std::string svnrev;
|
||||
|
||||
//! Default percentage gold carried over to the next scenario.
|
||||
extern const int gold_carryover_percentage;
|
||||
|
||||
//! If true the carried over gold is added to the start gold
|
||||
//! in the next scenario, otherwise it uses the maximum of
|
||||
//! starting gold and carryover gold.
|
||||
extern const bool gold_carryover_add;
|
||||
|
||||
extern bool debug, editor, ignore_replay_errors, mp_debug, exit_at_end, no_delay, disable_autosave;
|
||||
|
||||
extern std::string path;
|
||||
|
|
|
@ -2162,7 +2162,13 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
|||
const std::string result = cfg["result"].base_str(); //do not translate
|
||||
if(result.empty() || result == "victory") {
|
||||
const bool bonus = utils::string_bool(cfg["bonus"],true);
|
||||
throw end_level_exception(VICTORY,bonus);
|
||||
const int carry_over = lexical_cast_default<int>
|
||||
(cfg["carryover_percentage"],
|
||||
game_config::gold_carryover_percentage);
|
||||
const bool gold_add = utils::string_bool(cfg["carryover_add"],
|
||||
game_config::gold_carryover_add);
|
||||
|
||||
throw end_level_exception(VICTORY, carry_over, gold_add, bonus);
|
||||
} else if(result == "continue") {
|
||||
throw end_level_exception(LEVEL_CONTINUE);
|
||||
} else if(result == "continue_no_save") {
|
||||
|
|
|
@ -405,6 +405,7 @@ static player_info read_player(const game_data& data, const config* cfg)
|
|||
res.name = (*cfg)["name"];
|
||||
|
||||
res.gold = atoi((*cfg)["gold"].c_str());
|
||||
res.gold_add = utils::string_bool((*cfg)["gold_add"]);
|
||||
|
||||
const config::child_list& units = cfg->get_children("unit");
|
||||
for(config::child_list::const_iterator i = units.begin(); i != units.end(); ++i) {
|
||||
|
@ -519,6 +520,8 @@ static void write_player(const player_info& player, config& cfg)
|
|||
|
||||
cfg["gold"] = buf;
|
||||
|
||||
cfg["gold_add"] = player.gold_add ? "true" : "false";
|
||||
|
||||
for(std::vector<unit>::const_iterator i = player.available_units.begin();
|
||||
i != player.available_units.end(); ++i) {
|
||||
config new_cfg;
|
||||
|
|
|
@ -73,10 +73,19 @@ struct wml_menu_item
|
|||
//! Information on a particular player of the game.
|
||||
struct player_info
|
||||
{
|
||||
player_info():gold(-1) {}
|
||||
player_info() :
|
||||
name(),
|
||||
gold(-1) ,
|
||||
gold_add(false),
|
||||
available_units(),
|
||||
can_recruit()
|
||||
{}
|
||||
|
||||
std::string name; //!< Stores the current_player name
|
||||
int gold; //!< Amount of gold the player has saved
|
||||
bool gold_add; //!< Amount of gold is added to the
|
||||
//!< starting gold, if not it uses the highest
|
||||
//!< of the two.
|
||||
std::vector<unit> available_units; //!< Units the player may recall
|
||||
std::set<std::string> can_recruit; //!< Units the player has the ability to recruit
|
||||
};
|
||||
|
|
|
@ -31,11 +31,18 @@ class gamestatus;
|
|||
enum LEVEL_RESULT { VICTORY, DEFEAT, QUIT, LEVEL_CONTINUE, LEVEL_CONTINUE_NO_SAVE, OBSERVER_END };
|
||||
|
||||
struct end_level_exception {
|
||||
end_level_exception(LEVEL_RESULT res, bool bonus=true)
|
||||
: result(res), gold_bonus(bonus)
|
||||
end_level_exception(LEVEL_RESULT res, const int percentage = -1,
|
||||
const bool add = false, const bool bonus=true) :
|
||||
result(res),
|
||||
gold_bonus(bonus),
|
||||
carryover_percentage(percentage),
|
||||
carryover_add(add)
|
||||
{}
|
||||
|
||||
LEVEL_RESULT result;
|
||||
bool gold_bonus;
|
||||
int carryover_percentage;
|
||||
bool carryover_add;
|
||||
};
|
||||
|
||||
struct end_turn_exception {
|
||||
|
|
|
@ -170,6 +170,11 @@ LEVEL_RESULT playsingle_controller::play_scenario(const std::vector<config*>& st
|
|||
|
||||
victory_conditions::set_victory_when_enemies_defeated(
|
||||
level_["victory_when_enemies_defeated"] != "no");
|
||||
victory_conditions::set_carryover_percentage(
|
||||
lexical_cast_default<int>(level_["carryover_percentage"],
|
||||
game_config::gold_carryover_percentage));
|
||||
victory_conditions::set_carryover_add(utils::string_bool(
|
||||
level_["carryover_add"], game_config::gold_carryover_add));
|
||||
|
||||
LOG_NG << "entering try... " << (SDL_GetTicks() - ticks_) << "\n";
|
||||
try {
|
||||
|
@ -201,8 +206,14 @@ LEVEL_RESULT playsingle_controller::play_scenario(const std::vector<config*>& st
|
|||
}
|
||||
|
||||
// if we loaded a save file in linger mode, skip to it.
|
||||
if (linger_)
|
||||
throw end_level_exception(gamestate_.completion == "defeat" ? DEFEAT : VICTORY);
|
||||
if (linger_)
|
||||
// @todo FIXME going to the next scenario in linger mode is broken
|
||||
// it was already broken before and it's unsure whether more parts
|
||||
// of the gamestate are missing. One of the other things which goes
|
||||
// wrong is that the second victory event does duplicate all units
|
||||
// so we have another recall list duplication bug.
|
||||
throw end_level_exception(gamestate_.completion == "defeat" ? DEFEAT : VICTORY,
|
||||
game_config::gold_carryover_percentage, game_config::gold_carryover_add);
|
||||
|
||||
// Avoid autosaving after loading, but still
|
||||
// allow the first turn to have an autosave.
|
||||
|
@ -337,7 +348,9 @@ LEVEL_RESULT playsingle_controller::play_scenario(const std::vector<config*>& st
|
|||
(finishing_bonus_per_turn * turns_left) : 0;
|
||||
|
||||
if(player) {
|
||||
player->gold = ((remaining_gold + finishing_bonus) * 80) / 100;
|
||||
player->gold = ((remaining_gold + finishing_bonus)
|
||||
* end_level.carryover_percentage) / 100;
|
||||
player->gold_add = end_level.carryover_add;
|
||||
|
||||
if(gamestate_.players.size()>1) {
|
||||
if(i!=teams_.begin()) {
|
||||
|
@ -358,19 +371,39 @@ LEVEL_RESULT playsingle_controller::play_scenario(const std::vector<config*>& st
|
|||
<< _("Bonus: ")
|
||||
<< finishing_bonus << "\n"
|
||||
<< _("Gold: ")
|
||||
<< (remaining_gold+finishing_bonus);
|
||||
<< (remaining_gold + finishing_bonus);
|
||||
}
|
||||
report << '\n' << font::BOLD_TEXT << _("Retained Gold: ") << player->gold;
|
||||
|
||||
report << '\n' << _("Carry over percentage: ") << end_level.carryover_percentage;
|
||||
if(end_level.carryover_add) {
|
||||
report << '\n' << font::BOLD_TEXT << _("Bonus Gold: ") << player->gold;
|
||||
} else {
|
||||
report << '\n' << font::BOLD_TEXT << _("Retained Gold: ") << player->gold;
|
||||
}
|
||||
|
||||
std::string goldmsg;
|
||||
utils::string_map symbols;
|
||||
symbols["gold"] = lexical_cast_default<std::string>(player->gold);
|
||||
// Note that both strings are the same in english, but some languages will
|
||||
// want to translate them differently.
|
||||
const std::string goldmsg = vngettext(
|
||||
"You will start the next scenario with $gold or its defined minimum starting gold, whichever is higher.",
|
||||
"You will start the next scenario with $gold or its defined minimum starting gold, whichever is higher.",
|
||||
player->gold, symbols);
|
||||
if(end_level.carryover_add) {
|
||||
std::string goldmsg = vngettext(
|
||||
"You will start the next scenario with $gold "
|
||||
"on top of the defined minimum starting gold.",
|
||||
"You will start the next scenario with $gold "
|
||||
"on top of the defined minimum starting gold.",
|
||||
player->gold, symbols);
|
||||
|
||||
} else {
|
||||
std::string goldmsg = vngettext(
|
||||
"You will start the next scenario with $gold "
|
||||
"or its defined minimum starting gold, "
|
||||
"whichever is higher.",
|
||||
"You will start the next scenario with $gold "
|
||||
"or its defined minimum starting gold, "
|
||||
"whichever is higher.",
|
||||
player->gold, symbols);
|
||||
}
|
||||
|
||||
// xgettext:no-c-format
|
||||
report << '\n' << goldmsg;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue