savegame reorganization:

...migrated the primitve members of game_state to game_classification
This commit is contained in:
Eugen Jiresch 2009-06-05 08:39:48 +00:00
parent df015ab73f
commit 9beb622b6a
16 changed files with 158 additions and 237 deletions

View file

@ -341,7 +341,7 @@ bool ai_default::recruit_usage(const std::string& usage)
//FIXME: This message should be suppressed when WML author
//chooses the default recruitment pattern.
const std::string warning = "At difficulty level " +
state_.sog().difficulty + ", trying to recruit a:" +
state_.sog().classification().difficulty + ", trying to recruit a:" +
usage + " but no unit of that type (usage=) is"
" available. Check the recruit and [ai]"
" recruitment_pattern keys for team '" +

View file

@ -649,9 +649,9 @@ bool game_controller::play_test()
first_time = false;
state_.campaign_type = "test";
state_.scenario = test_scenario_;
state_.campaign_define = "TEST";
state_.classification().campaign_type = "test";
state_.classification().scenario = test_scenario_;
state_.classification().campaign_define = "TEST";
cache_.clear_defines();
cache_.add_define("TEST");
@ -752,8 +752,8 @@ bool game_controller::play_multiplayer_mode()
return false;
}
state_.campaign_type = "multiplayer";
state_.scenario = "";
state_.classification().campaign_type = "multiplayer";
state_.classification().scenario = "";
state_.snapshot = config();
config level = lvl;
@ -895,15 +895,15 @@ bool game_controller::load_game()
load.load_game(loaded_game_, loaded_game_show_replay_, loaded_game_cancel_orders_);
cache_.clear_defines();
game_config::scoped_preproc_define dificulty_def(state_.difficulty);
game_config::scoped_preproc_define dificulty_def(state_.classification().difficulty);
game_config::scoped_preproc_define campaign_define_def(state_.campaign_define, !state_.campaign_define.empty());
game_config::scoped_preproc_define campaign_define_def(state_.classification().campaign_define, !state_.classification().campaign_define.empty());
game_config::scoped_preproc_define campaign_type_def("MULTIPLAYER", state_.campaign_define.empty() && (state_.campaign_type == "multiplayer"));
game_config::scoped_preproc_define campaign_type_def("MULTIPLAYER", state_.classification().campaign_define.empty() && (state_.classification().campaign_type == "multiplayer"));
typedef boost::shared_ptr<game_config::scoped_preproc_define> define_ptr;
std::deque<define_ptr> extra_defines;
for(std::vector<std::string>::const_iterator i = state_.campaign_xtra_defines.begin(); i != state_.campaign_xtra_defines.end(); ++i) {
for(std::vector<std::string>::const_iterator i = state_.classification().campaign_xtra_defines.begin(); i != state_.classification().campaign_xtra_defines.end(); ++i) {
define_ptr newdefine(new game_config::scoped_preproc_define(*i));
extra_defines.push_back(newdefine);
}
@ -974,7 +974,7 @@ bool game_controller::load_game()
}
}
if(state_.campaign_type == "multiplayer") {
if(state_.classification().campaign_type == "multiplayer") {
foreach (config &side, state_.snapshot.child_range("side"))
{
if (side["controller"] == "network")
@ -1002,9 +1002,9 @@ bool game_controller::load_game()
void game_controller::set_tutorial()
{
state_ = game_state();
state_.campaign_type = "tutorial";
state_.scenario = "tutorial";
state_.campaign_define = "TUTORIAL";
state_.classification().campaign_type = "tutorial";
state_.classification().scenario = "tutorial";
state_.classification().campaign_define = "TUTORIAL";
cache_.clear_defines();
cache_.add_define("TUTORIAL");
@ -1013,7 +1013,7 @@ void game_controller::set_tutorial()
bool game_controller::new_campaign()
{
state_ = game_state();
state_.campaign_type = "scenario";
state_.classification().campaign_type = "scenario";
const config::const_child_itors &ci = game_config_.child_range("campaign");
std::vector<config> campaigns(ci.first, ci.second);
@ -1094,11 +1094,11 @@ bool game_controller::new_campaign()
const config &campaign = campaigns[campaign_num];
state_.campaign = campaign["id"];
state_.abbrev = campaign["abbrev"];
state_.scenario = campaign["first_scenario"];
state_.end_text = campaign["end_text"];
state_.end_text_duration = lexical_cast_default<unsigned int>(campaign["end_text_duration"]);
state_.classification().campaign = campaign["id"];
state_.classification().abbrev = campaign["abbrev"];
state_.classification().scenario = campaign["first_scenario"];
state_.classification().end_text = campaign["end_text"];
state_.classification().end_text_duration = lexical_cast_default<unsigned int>(campaign["end_text_duration"]);
const std::string difficulty_descriptions = campaign["difficulty_descriptions"];
std::vector<std::string> difficulty_options = utils::split(difficulty_descriptions, ';');
@ -1119,13 +1119,13 @@ bool game_controller::new_campaign()
return new_campaign();
}
state_.difficulty = difficulties[dlg.result()];
state_.classification().difficulty = difficulties[dlg.result()];
cache_.clear_defines();
cache_.add_define(difficulties[dlg.result()]);
}
state_.campaign_define = campaign["define"];
state_.campaign_xtra_defines = utils::split(campaign["extra_defines"]);
state_.classification().campaign_define = campaign["define"];
state_.classification().campaign_xtra_defines = utils::split(campaign["extra_defines"]);
return true;
}
@ -1224,8 +1224,8 @@ bool game_controller::play_multiplayer()
int res;
state_ = game_state();
state_.campaign_type = "multiplayer";
state_.campaign_define = "MULTIPLAYER";
state_.classification().campaign_type = "multiplayer";
state_.classification().campaign_define = "MULTIPLAYER";
//Print Gui only if the user hasn't specified any server
if( multiplayer_server_.empty() ){
@ -1292,7 +1292,7 @@ bool game_controller::play_multiplayer()
/* do */ {
cache_.clear_defines();
game_config::scoped_preproc_define multiplayer(state_.campaign_define);
game_config::scoped_preproc_define multiplayer(state_.classification().campaign_define);
load_game_cfg();
events::discard(INPUT_MASK); // prevent the "keylogger" effect
cursor::set(cursor::NORMAL);
@ -1547,11 +1547,11 @@ void game_controller::launch_game(RELOAD_GAME_DATA reload)
loadscreen::global_loadscreen_manager loadscreen_manager(disp().video());
loadscreen::global_loadscreen->set_progress(0, _("Loading data files"));
if(reload == RELOAD_DATA) {
game_config::scoped_preproc_define campaign_define(state_.campaign_define, state_.campaign_define.empty() == false);
game_config::scoped_preproc_define campaign_define(state_.classification().campaign_define, state_.classification().campaign_define.empty() == false);
typedef boost::shared_ptr<game_config::scoped_preproc_define> define_ptr;
std::deque<define_ptr> extra_defines;
for(std::vector<std::string>::const_iterator i = state_.campaign_xtra_defines.begin(); i != state_.campaign_xtra_defines.end(); ++i) {
for(std::vector<std::string>::const_iterator i = state_.classification().campaign_xtra_defines.begin(); i != state_.classification().campaign_xtra_defines.end(); ++i) {
define_ptr newdefine(new game_config::scoped_preproc_define(*i));
extra_defines.push_back(newdefine);
}
@ -1570,16 +1570,16 @@ void game_controller::launch_game(RELOAD_GAME_DATA reload)
try {
// Only record log for single-player games & tutorial.
upload_log log(state_.campaign_type.empty()
|| state_.campaign_type == "scenario"
|| state_.campaign_type == "tutorial");
upload_log log(state_.classification().campaign_type.empty()
|| state_.classification().campaign_type == "scenario"
|| state_.classification().campaign_type == "tutorial");
const LEVEL_RESULT result = play_game(disp(),state_,game_config_, log);
// don't show The End for multiplayer scenario
// change this if MP campaigns are implemented
if(result == VICTORY && (state_.campaign_type.empty() || state_.campaign_type != "multiplayer")) {
the_end(disp(), state_.end_text, state_.end_text_duration);
about::show_about(disp(),state_.campaign);
if(result == VICTORY && (state_.classification().campaign_type.empty() || state_.classification().campaign_type != "multiplayer")) {
the_end(disp(), state_.classification().end_text, state_.classification().end_text_duration);
about::show_about(disp(),state_.classification().campaign);
}
if (result == QUIT)
{

View file

@ -2759,17 +2759,17 @@ WML_HANDLER_FUNCTION(endlevel, /*event_info*/, cfg)
const std::string next_scenario = cfg["next_scenario"];
if(next_scenario.empty() == false) {
state_of_game->next_scenario = next_scenario;
state_of_game->classification().next_scenario = next_scenario;
}
const std::string end_of_campaign_text = cfg["end_text"];
if(! end_of_campaign_text.empty()) {
state_of_game->end_text = end_of_campaign_text;
state_of_game->classification().end_text = end_of_campaign_text;
}
const std::string end_of_campaign_text_delay = cfg["end_text_duration"];
if(! end_of_campaign_text_delay.empty()) {
state_of_game->end_text_duration =
lexical_cast_default<unsigned int,const std::string&>(end_of_campaign_text_delay, state_of_game->end_text_duration);
state_of_game->classification().end_text_duration =
lexical_cast_default<unsigned int,const std::string&>(end_of_campaign_text_delay, state_of_game->classification().end_text_duration);
}
const std::string result = cfg["result"].base_str(); //do not translate

View file

@ -426,24 +426,9 @@ static player_info read_player(const config &cfg)
}
game_state::game_state() :
label(),
parent(),
version(),
campaign_type(),
campaign_define(),
campaign_xtra_defines(),
campaign(),
history(),
abbrev(),
scenario(),
next_scenario(),
completion(),
end_text(),
end_text_duration(),
players(),
scoped_variables(),
wml_menu_items(),
difficulty("NORMAL"),
replay_data(),
starting_pos(),
snapshot(),
@ -505,24 +490,9 @@ void write_players(game_state& gamestate, config& cfg)
}
game_state::game_state(const config& cfg, bool show_replay) :
label(cfg["label"]),
parent(cfg["parent"]),
version(cfg["version"]),
campaign_type(cfg["campaign_type"]),
campaign_define(cfg["campaign_define"]),
campaign_xtra_defines(utils::split(cfg["campaign_extra_defines"])),
campaign(cfg["campaign"]),
history(cfg["history"]),
abbrev(cfg["abbrev"]),
scenario(cfg["scenario"]),
next_scenario(cfg["next_scenario"]),
completion(cfg["completion"]),
end_text(cfg["end_text"]),
end_text_duration(lexical_cast_default<unsigned int>(cfg["end_text_duration"])),
players(),
scoped_variables(),
wml_menu_items(),
difficulty(cfg["difficulty"]),
replay_data(),
starting_pos(),
snapshot(),
@ -563,16 +533,14 @@ game_state::game_state(const config& cfg, bool show_replay) :
load_recall_list(cfg_players);
}
LOG_NG << "scenario: '" << scenario << "'\n";
LOG_NG << "next_scenario: '" << next_scenario << "'\n";
LOG_NG << "scenario: '" << classification_.scenario << "'\n";
LOG_NG << "next_scenario: '" << classification_.next_scenario << "'\n";
if(difficulty.empty()) {
difficulty = "NORMAL";
if(classification_.difficulty.empty()) {
classification_.difficulty = "NORMAL";
}
if(campaign_type.empty()) {
campaign_type = "scenario";
if(classification_.campaign_type.empty()) {
classification_.campaign_type = "scenario";
}
@ -610,29 +578,29 @@ game_state::game_state(const config& cfg, bool show_replay) :
void game_state::write_snapshot(config& cfg) const
{
log_scope("write_game");
cfg["label"] = label;
cfg["history"] = history;
cfg["abbrev"] = abbrev;
cfg["label"] = classification_.label;
cfg["history"] = classification_.history;
cfg["abbrev"] = classification_.abbrev;
cfg["version"] = game_config::version;
cfg["scenario"] = scenario;
cfg["next_scenario"] = next_scenario;
cfg["scenario"] = classification_.scenario;
cfg["next_scenario"] = classification_.next_scenario;
cfg["completion"] = completion;
cfg["completion"] = classification_.completion;
cfg["campaign"] = campaign;
cfg["campaign_type"] = campaign_type;
cfg["difficulty"] = difficulty;
cfg["campaign"] = classification_.campaign;
cfg["campaign_type"] = classification_.campaign_type;
cfg["difficulty"] = classification_.difficulty;
cfg["campaign_define"] = campaign_define;
cfg["campaign_extra_defines"] = utils::join(campaign_xtra_defines);
cfg["campaign_define"] = classification_.campaign_define;
cfg["campaign_extra_defines"] = utils::join(classification_.campaign_xtra_defines);
cfg["next_underlying_unit_id"] = lexical_cast<std::string>(n_unit::id_manager::instance().get_save_id());
cfg["random_seed"] = lexical_cast<std::string>(rng_.get_random_seed());
cfg["random_calls"] = lexical_cast<std::string>(rng_.get_random_calls());
cfg["end_text"] = end_text;
cfg["end_text_duration"] = str_cast<unsigned int>(end_text_duration);
cfg["end_text"] = classification_.end_text;
cfg["end_text_duration"] = str_cast<unsigned int>(classification_.end_text_duration);
cfg.add_child("variables", variables);
@ -828,24 +796,9 @@ static void clear_wmi(std::map<std::string, wml_menu_item*>& gs_wmi) {
game_state::game_state(const game_state& state) :
/* default construct everything to silence compiler warnings. */
variable_set(),
label(),
parent(),
version(),
campaign_type(),
campaign_define(),
campaign_xtra_defines(),
campaign(),
history(),
abbrev(),
scenario(),
next_scenario(),
completion(),
end_text(),
end_text_duration(),
players(),
scoped_variables(),
wml_menu_items(),
difficulty(),
replay_data(),
starting_pos(),
snapshot(),
@ -865,19 +818,6 @@ game_state& game_state::operator=(const game_state& state)
return *this;
}
history = state.history;
abbrev = state.abbrev;
label = state.label;
parent = state.parent;
version = state.version;
campaign_type = state.campaign_type;
campaign_define = state.campaign_define;
campaign_xtra_defines = state.campaign_xtra_defines;
campaign = state.campaign;
scenario = state.scenario;
completion = state.completion;
end_text = state.end_text;
end_text_duration = state.end_text_duration;
rng_ = state.rng_;
players = state.players;
scoped_variables = state.scoped_variables;
@ -890,7 +830,6 @@ game_state& game_state::operator=(const game_state& state)
mref = new wml_menu_item(*(itor->second));
}
difficulty = state.difficulty;
replay_data = state.replay_data;
starting_pos = state.starting_pos;
snapshot = state.snapshot;

View file

@ -98,23 +98,6 @@ public:
~game_state();
game_state& operator=(const game_state& state);
std::string label; /**< Name of the game (e.g. name of save file). */
std::string parent; /**< Parent of the game (for save-threading purposes). */
std::string version; /**< Version game was created with. */
std::string campaign_type; /**< Type of the game - campaign, multiplayer etc. */
std::string campaign_define; /**< If there is a define the campaign uses to customize data */
std::vector<std::string> campaign_xtra_defines; /**< more customization of data */
std::string campaign; /**< the campaign being played */
std::string history; /**< ancestral IDs */
std::string abbrev; /**< the campaign abbreviation */
std::string scenario; /**< the scenario being played */
std::string next_scenario; /**< the scenario coming next (for campaigns) */
std::string completion; /**< running. victory, or defeat */
std::string end_text; /**< end-of-campaign text */
unsigned int end_text_duration; /**< for how long the end-of-campaign text is shown */
/**
* Information about campaign players who carry resources from previous
@ -164,9 +147,8 @@ public:
void get_player_info(const config& cfg, std::string save_id, std::vector<team>& teams, const config& level, gamemap& map, unit_map& units, gamestatus& game_status, bool snapshot);
game_classification classification() {return classification_;}
std::string difficulty; /**< The difficulty level the game is being played on. */
game_classification& classification() { return classification_; }
const game_classification& classification() const { return classification_; } //FIXME: const getter to allow use from const gamestatus::sog() (see ai.cpp:344) - remove after merge?
/**
* If the game is saved mid-level, we have a series of replay steps

View file

@ -418,7 +418,7 @@ private:
leader_bools.push_back(false);
leader_name = "Unknown";
}
if (gamestate_.campaign_type == "multiplayer")
if (gamestate_.classification().campaign_type == "multiplayer")
leader_name = teams_[n].current_player();
#ifndef LOW_MEM
@ -2812,7 +2812,7 @@ private:
}
void console_handler::do_next_level() {
if (!get_data().empty())
menu_handler_.gamestate_.next_scenario = get_data();
menu_handler_.gamestate_.classification().next_scenario = get_data();
throw end_level_exception(VICTORY, "", 100, false, false, false, true, false);
}
void console_handler::do_choose_level() {
@ -2822,7 +2822,7 @@ private:
{
const std::string &id = sc["id"];
options.push_back(id);
if (id == menu_handler_.gamestate_.next_scenario)
if (id == menu_handler_.gamestate_.classification().next_scenario)
next = nb;
++nb;
}
@ -2835,7 +2835,7 @@ private:
}
if (size_t(choice) < options.size()) {
menu_handler_.gamestate_.next_scenario = options[choice];
menu_handler_.gamestate_.classification().next_scenario = options[choice];
throw end_level_exception(VICTORY, "", 100, false, false, false, true, false);
}
}

View file

@ -118,9 +118,9 @@ void level_to_gamestate(config& level, game_state& state)
state.starting_pos = level.child("replay_start");
level["campaign_type"] = "multiplayer";
state.campaign_type = "multiplayer";
state.completion = level["completion"];
state.version = level["version"];
state.classification().campaign_type = "multiplayer";
state.classification().completion = level["completion"];
state.classification().version = level["version"];
if (const config &vars = level.child("variables")) {
state.set_variables(vars);

View file

@ -361,7 +361,7 @@ void wait::start_game()
// the old way, no clue why however. Code is a copy paste of
// playcampaign.cpp:576 which shows an 'Unknown scenario: '$scenario|'
// error. This seems to work and have no side effects....
if(!state_.scenario.empty() && state_.scenario != "null") {
if(!state_.classification().scenario.empty() && state_.classification().scenario != "null") {
DBG_NW << "Falling back to loading the old way.\n";
level_to_gamestate(level_, state_);
}

View file

@ -846,7 +846,7 @@ void play_controller::expand_autosaves(std::vector<std::string>& items)
std::vector<std::string> newitems;
std::vector<std::string> newsaves;
for (unsigned int turn = status_.turn(); turn != 0; turn--) {
std::string name = gamestate_.label + "-" + _("Auto-Save") + lexical_cast<std::string>(turn);
std::string name = gamestate_.classification().label + "-" + _("Auto-Save") + lexical_cast<std::string>(turn);
if (savegame_manager::save_game_exists(name, preferences::compress_saves())) {
if(preferences::compress_saves()) {
newsaves.push_back(name + ".gz");

View file

@ -66,7 +66,7 @@ typedef std::map<std::string, player_controller> controller_map;
void play_replay(display& disp, game_state& gamestate, const config& game_config,
CVideo& video)
{
std::string type = gamestate.campaign_type;
std::string type = gamestate.classification().campaign_type;
if(type.empty())
type = "scenario";
@ -75,7 +75,7 @@ void play_replay(display& disp, game_state& gamestate, const config& game_config
if (gamestate.starting_pos.empty()){
// Backwards compatibility code for 1.2 and 1.2.1
const config &scenario = game_config.find_child(type,"id",gamestate.scenario);
const config &scenario = game_config.find_child(type,"id",gamestate.classification().scenario);
assert(scenario);
gamestate.starting_pos = scenario;
}
@ -83,8 +83,8 @@ void play_replay(display& disp, game_state& gamestate, const config& game_config
try {
// Preserve old label eg. replay
if (gamestate.label.empty())
gamestate.label = starting_pos["name"];
if (gamestate.classification().label.empty())
gamestate.classification().label = starting_pos["name"];
//if (gamestate.abbrev.empty())
// gamestate.abbrev = (*scenario)["abbrev"];
@ -198,7 +198,7 @@ static void preload_lua_tags(const config &game_config, config &target)
LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_config,
upload_log &log, io_type_t io_type, bool skip_replay)
{
std::string type = gamestate.campaign_type;
std::string type = gamestate.classification().campaign_type;
if(type.empty())
type = "scenario";
@ -211,7 +211,7 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
// yes => this must be a savegame
// no => we are starting a fresh scenario
if(gamestate.snapshot.child("side") == NULL || !recorder.at_end()) {
gamestate.completion = "running";
gamestate.classification().completion = "running";
// Campaign or Multiplayer?
// If the gamestate already contains a starting_pos,
// then we are starting a fresh multiplayer game.
@ -222,8 +222,8 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
starting_pos = gamestate.starting_pos;
scenario = &starting_pos;
} else {
LOG_G << "loading scenario: '" << gamestate.scenario << "'\n";
scenario = &game_config.find_child(type, "id", gamestate.scenario);
LOG_G << "loading scenario: '" << gamestate.classification().scenario << "'\n";
scenario = &game_config.find_child(type, "id", gamestate.classification().scenario);
if (*scenario) {
starting_pos = *scenario;
preload_lua_tags(game_config, starting_pos);
@ -246,7 +246,7 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
gamestate.set_menu_items(gamestate.snapshot.child_range("menu_item"));
// Replace game label with that from snapshot
if (!gamestate.snapshot["label"].empty()){
gamestate.label = gamestate.snapshot["label"];
gamestate.classification().label = gamestate.snapshot["label"];
}
// Get the current gold values of players, so they don't start
@ -308,7 +308,7 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
}
config::const_child_itors story = scenario->child_range("story");
gamestate.next_scenario = (*scenario)["next_scenario"];
gamestate.classification().next_scenario = (*scenario)["next_scenario"];
bool save_game_after_scenario = true;
@ -317,13 +317,13 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
try {
// Preserve old label eg. replay
if (gamestate.label.empty()) {
if (gamestate.abbrev.empty())
gamestate.label = (*scenario)["name"];
if (gamestate.classification().label.empty()) {
if (gamestate.classification().abbrev.empty())
gamestate.classification().label = (*scenario)["name"];
else {
gamestate.label = std::string(gamestate.abbrev);
gamestate.label.append("-");
gamestate.label.append((*scenario)["name"]);
gamestate.classification().label = std::string(gamestate.classification().abbrev);
gamestate.classification().label.append("-");
gamestate.classification().label.append((*scenario)["name"]);
}
}
@ -400,7 +400,7 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
// need to change this test.
if (res == VICTORY || (io_type != IO_NONE && res == DEFEAT)) {
if (preferences::delete_saves())
savegame_manager::clean_saves(gamestate.label);
savegame_manager::clean_saves(gamestate.classification().label);
if (preferences::save_replays()) {
replay_savegame save(gamestate, preferences::compress_saves());
@ -414,7 +414,7 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
// On DEFEAT, QUIT, or OBSERVER_END, we're done now
if (res != VICTORY)
{
if (res != OBSERVER_END || gamestate.next_scenario.empty())
if (res != OBSERVER_END || gamestate.classification().next_scenario.empty())
return res;
const int dlg_res = gui::dialog(disp,"Game Over",
@ -430,11 +430,11 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
save_game_after_scenario = false;
// Switch to the next scenario.
gamestate.scenario = gamestate.next_scenario;
gamestate.classification().scenario = gamestate.classification().next_scenario;
gamestate.rng().rotate_random();
if(io_type == IO_CLIENT) {
if (gamestate.next_scenario.empty()) return res;
if (gamestate.classification().next_scenario.empty()) return res;
// Ask for the next scenario data.
network::send_data(config("load_next_scenario"), 0, true);
@ -455,7 +455,7 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
return QUIT;
}
} else {
scenario = &game_config.find_child(type, "id", gamestate.scenario);
scenario = &game_config.find_child(type, "id", gamestate.classification().scenario);
if (!*scenario)
scenario = NULL;
else
@ -536,13 +536,13 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
if(scenario != NULL) {
// Update the label
std::string oldlabel = gamestate.label;
if (gamestate.abbrev.empty())
gamestate.label = (*scenario)["name"];
std::string oldlabel = gamestate.classification().label;
if (gamestate.classification().abbrev.empty())
gamestate.classification().label = (*scenario)["name"];
else {
gamestate.label = std::string(gamestate.abbrev);
gamestate.label.append("-");
gamestate.label.append((*scenario)["name"]);
gamestate.classification().label = std::string(gamestate.classification().abbrev);
gamestate.classification().label.append("-");
gamestate.classification().label.append((*scenario)["name"]);
}
// If this isn't the last scenario, then save the game
@ -554,7 +554,7 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
// start-of-scenario save and the
// starting position needs to be empty,
// to force a reload of the scenario config.
if (gamestate.campaign_type == "multiplayer"){
if (gamestate.classification().campaign_type == "multiplayer"){
gamestate.starting_pos = *scenario;
}
else{
@ -577,25 +577,25 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
#endif /* TINY_GUI */
}
if (gamestate.campaign_type != "multiplayer"){
if (gamestate.classification().campaign_type != "multiplayer"){
gamestate.starting_pos = *scenario;
write_players(gamestate, gamestate.starting_pos);
}
}
}
if (!gamestate.scenario.empty() && gamestate.scenario != "null") {
if (!gamestate.classification().scenario.empty() && gamestate.classification().scenario != "null") {
std::string message = _("Unknown scenario: '$scenario|'");
utils::string_map symbols;
symbols["scenario"] = gamestate.scenario;
symbols["scenario"] = gamestate.classification().scenario;
message = utils::interpolate_variables_into_string(message, &symbols);
gui2::show_error_message(disp.video(), message);
return QUIT;
}
if (gamestate.campaign_type == "scenario"){
if (gamestate.classification().campaign_type == "scenario"){
if (preferences::delete_saves())
savegame_manager::clean_saves(gamestate.label);
savegame_manager::clean_saves(gamestate.classification().label);
}
return VICTORY;
}

View file

@ -319,7 +319,7 @@ void playmp_controller::linger(upload_log& log)
// this is actually for after linger mode is over -- we don't want to
// stay stuck in linger state when the *next* scenario is over.
gamestate_.completion = "running";
gamestate_.classification().completion = "running";
// End all unit moves
for (unit_map::iterator u = units_.begin(); u != units_.end(); u++) {
u->second.set_user_end_turn(true);

View file

@ -60,7 +60,7 @@ playsingle_controller::playsingle_controller(const config& level,
defeat_music_()
{
// game may need to start in linger mode
if (state_of_game.completion == "victory" || state_of_game.completion == "defeat")
if (state_of_game.classification().completion == "victory" || state_of_game.classification().completion == "defeat")
{
LOG_NG << "Setting linger mode.\n";
browse_ = linger_ = true;
@ -356,7 +356,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(
exit(0);
}
if (end_level.result == DEFEAT || end_level.result == VICTORY) {
gamestate_.completion = (end_level.result == VICTORY) ? "victory" : "defeat";
gamestate_.classification().completion = (end_level.result == VICTORY) ? "victory" : "defeat";
// If we're a player, and the result is victory/defeat, then send
// a message to notify the server of the reason for the game ending.
if (!obs) {
@ -364,7 +364,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(
config& info = cfg.add_child("info");
info["type"] = "termination";
info["condition"] = "game over";
info["result"] = gamestate_.completion;
info["result"] = gamestate_.classification().completion;
network::send_data(cfg, 0, true);
} else {
gui2::show_transient_message(gui_->video(),_("Game Over"),
@ -377,7 +377,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(
log.quit(status_.turn());
return end_level.result;
} else if(end_level.result == DEFEAT) {
gamestate_.completion = "defeat";
gamestate_.classification().completion = "defeat";
log.defeat(status_.turn());
try {
game_events::fire("defeat");
@ -396,7 +396,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(
}
} else if (end_level.result == VICTORY)
{
gamestate_.completion = (!end_level.linger_mode ?
gamestate_.classification().completion = (!end_level.linger_mode ?
"running" : "victory");
try {
game_events::fire("victory");
@ -420,8 +420,8 @@ LEVEL_RESULT playsingle_controller::play_scenario(
if (first_human_team_ != -1)
log.victory(status_.turn(), teams_[first_human_team_].gold());
const bool has_next_scenario = !gamestate_.next_scenario.empty() &&
gamestate_.next_scenario != "null";
const bool has_next_scenario = !gamestate_.classification().next_scenario.empty() &&
gamestate_.classification().next_scenario != "null";
// Save current_player name to reuse it when setting next_scenario side info
std::vector<team>::iterator i;
@ -455,7 +455,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(
}
if (gamestate_.players.size() > 0 &&
(has_next_scenario ||
gamestate_.campaign_type == "test")) {
gamestate_.classification().campaign_type == "test")) {
const int finishing_bonus_per_turn =
map_.villages().size() * game_config::village_income +
game_config::base_income;
@ -739,7 +739,7 @@ struct set_completion
}
~set_completion()
{
state_.completion = completion_;
state_.classification().completion = completion_;
}
private:
game_state& state_;

View file

@ -63,7 +63,7 @@ replay_controller::replay_controller(const config& level,
delay_(0),
is_playing_(false),
show_everything_(false),
show_team_(state_of_game.campaign_type == "multiplayer" ? 0 : 1),
show_team_(state_of_game.classification().campaign_type == "multiplayer" ? 0 : 1),
skip_next_turn_(false)
{
init();

View file

@ -1,6 +1,6 @@
/* $Id$ */
/*
Copyright (C) 2003 - 2009 by Jörg Hinrichs, refactored from various
Copyright (C) 2003 - 2009 by J<EFBFBD>rg Hinrichs, refactored from various
places formerly created by David White <dave@whitevine.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
@ -375,14 +375,14 @@ void loadgame::load_game(std::string& filename, bool show_replay, bool cancel_or
}
}
gamestate_.difficulty = load_config_["difficulty"];
gamestate_.campaign_define = load_config_["campaign_define"];
gamestate_.campaign_type = load_config_["campaign_type"];
gamestate_.campaign_xtra_defines = utils::split(load_config_["campaign_extra_defines"]);
gamestate_.version = load_config_["version"];
gamestate_.classification().difficulty = load_config_["difficulty"];
gamestate_.classification().campaign_define = load_config_["campaign_define"];
gamestate_.classification().campaign_type = load_config_["campaign_type"];
gamestate_.classification().campaign_xtra_defines = utils::split(load_config_["campaign_extra_defines"]);
gamestate_.classification().version = load_config_["version"];
if(gamestate_.version != game_config::version) {
const version_info parsed_savegame_version(gamestate_.version);
if(gamestate_.classification().version != game_config::version) {
const version_info parsed_savegame_version(gamestate_.classification().version);
if(game_config::wesnoth_version.minor_version() % 2 != 0 ||
game_config::wesnoth_version.major_version() != parsed_savegame_version.major_version() ||
game_config::wesnoth_version.minor_version() != parsed_savegame_version.minor_version()) {
@ -396,7 +396,7 @@ void loadgame::check_version_compatibility()
{
// do not load if too old, if either the savegame or the current game
// has the version 'test' allow loading
if(!game_config::is_compatible_savegame_version(gamestate_.version)) {
if(!game_config::is_compatible_savegame_version(gamestate_.classification().version)) {
gui2::show_message(gui_.video(), "", _("This save is from a version too old to be loaded."));
throw load_game_cancelled_exception();
}
@ -449,7 +449,7 @@ void loadgame::load_multiplayer_game()
throw load_game_cancelled_exception();
}
if(gamestate_.campaign_type != "multiplayer") {
if(gamestate_.classification().campaign_type != "multiplayer") {
gui2::show_message(gui_.video(), "", _("This is not a multiplayer save"));
throw load_game_cancelled_exception();
}
@ -620,11 +620,11 @@ bool savegame::save_game(CVideo* video, const std::string& filename)
// use the grandparent name. When user loads a savegame,
// we load its correct parent link along with it.
if (filename_ == parent) {
gamestate_.parent = grandparent;
gamestate_.classification().parent = grandparent;
} else {
gamestate_.parent = parent;
gamestate_.classification().parent = parent;
}
LOG_SAVE << "Setting parent of '" << filename_<< "' to " << gamestate_.parent << "\n";
LOG_SAVE << "Setting parent of '" << filename_<< "' to " << gamestate_.classification().parent << "\n";
write_game_to_disk(filename_);
@ -676,24 +676,24 @@ void savegame::write_game(config_writer &out) const
{
log_scope("write_game");
out.write_key_val("label", gamestate_.label);
out.write_key_val("parent", gamestate_.parent);
out.write_key_val("history", gamestate_.history);
out.write_key_val("abbrev", gamestate_.abbrev);
out.write_key_val("label", gamestate_.classification().label);
out.write_key_val("parent", gamestate_.classification().parent);
out.write_key_val("history", gamestate_.classification().history);
out.write_key_val("abbrev", gamestate_.classification().abbrev);
out.write_key_val("version", game_config::version);
out.write_key_val("scenario", gamestate_.scenario);
out.write_key_val("next_scenario", gamestate_.next_scenario);
out.write_key_val("completion", gamestate_.completion);
out.write_key_val("campaign", gamestate_.campaign);
out.write_key_val("campaign_type", gamestate_.campaign_type);
out.write_key_val("difficulty", gamestate_.difficulty);
out.write_key_val("campaign_define", gamestate_.campaign_define);
out.write_key_val("campaign_extra_defines", utils::join(gamestate_.campaign_xtra_defines));
out.write_key_val("scenario", gamestate_.classification().scenario);
out.write_key_val("next_scenario", gamestate_.classification().next_scenario);
out.write_key_val("completion", gamestate_.classification().completion);
out.write_key_val("campaign", gamestate_.classification().campaign);
out.write_key_val("campaign_type", gamestate_.classification().campaign_type);
out.write_key_val("difficulty", gamestate_.classification().difficulty);
out.write_key_val("campaign_define", gamestate_.classification().campaign_define);
out.write_key_val("campaign_extra_defines", utils::join(gamestate_.classification().campaign_xtra_defines));
out.write_key_val("random_seed", lexical_cast<std::string>(gamestate_.rng().get_random_seed()));
out.write_key_val("random_calls", lexical_cast<std::string>(gamestate_.rng().get_random_calls()));
out.write_key_val("next_underlying_unit_id", lexical_cast<std::string>(n_unit::id_manager::instance().get_save_id()));
out.write_key_val("end_text", gamestate_.end_text);
out.write_key_val("end_text_duration", str_cast<unsigned int>(gamestate_.end_text_duration));
out.write_key_val("end_text", gamestate_.classification().end_text);
out.write_key_val("end_text_duration", str_cast<unsigned int>(gamestate_.classification().end_text_duration));
out.write_child("variables", gamestate_.get_variables());
for(std::map<std::string, wml_menu_item *>::const_iterator j=gamestate_.wml_menu_items.begin();
@ -725,7 +725,7 @@ void savegame::write_game(config_writer &out) const
void savegame::finish_save_game(const config_writer &out)
{
std::string name = gamestate_.label;
std::string name = gamestate_.classification().label;
replace_space2underbar(name);
std::string fname(get_saves_dir() + "/" + name);
@ -734,7 +734,7 @@ void savegame::finish_save_game(const config_writer &out)
throw game::save_game_failed(_("Could not write to file"));
}
config& summary = save_index::save_summary(gamestate_.label);
config& summary = save_index::save_summary(gamestate_.classification().label);
extract_summary_data_from_save(summary);
const int mod_time = static_cast<int>(file_create_time(fname));
summary["mod_time"] = str_cast(mod_time);
@ -765,13 +765,13 @@ void savegame::extract_summary_data_from_save(config& out)
out["replay"] = has_replay ? "yes" : "no";
out["snapshot"] = has_snapshot ? "yes" : "no";
out["label"] = gamestate_.label;
out["parent"] = gamestate_.parent;
out["campaign"] = gamestate_.campaign;
out["campaign_type"] = gamestate_.campaign_type;
out["scenario"] = gamestate_.scenario;
out["difficulty"] = gamestate_.difficulty;
out["version"] = gamestate_.version;
out["label"] = gamestate_.classification().label;
out["parent"] = gamestate_.classification().parent;
out["campaign"] = gamestate_.classification().campaign;
out["campaign_type"] = gamestate_.classification().campaign_type;
out["scenario"] = gamestate_.classification().scenario;
out["difficulty"] = gamestate_.classification().difficulty;
out["version"] = gamestate_.classification().version;
out["corrupt"] = "";
if(has_snapshot) {
@ -838,7 +838,7 @@ void savegame::extract_summary_data_from_save(config& out)
scenariostart_savegame::scenariostart_savegame(game_state &gamestate, const bool compress_saves)
: savegame(gamestate, compress_saves)
{
set_filename(gamestate.label);
set_filename(gamestate.classification().label);
}
void scenariostart_savegame::before_save()
@ -856,7 +856,7 @@ void replay_savegame::create_filename()
{
std::stringstream stream;
const std::string ellipsed_name = font::make_text_ellipsis(gamestate().label,
const std::string ellipsed_name = font::make_text_ellipsis(gamestate().classification().label,
font::SIZE_NORMAL, 200);
stream << ellipsed_name << " " << _("replay");
@ -885,10 +885,10 @@ void autosave_savegame::autosave(const bool disable_autosave, const int autosave
void autosave_savegame::create_filename()
{
std::string filename;
if (gamestate().label.empty())
if (gamestate().classification().label.empty())
filename = _("Auto-Save");
else
filename = gamestate().label + "-" + _("Auto-Save") + lexical_cast<std::string>(gamestatus_.turn());
filename = gamestate().classification().label + "-" + _("Auto-Save") + lexical_cast<std::string>(gamestatus_.turn());
set_filename(filename);
}
@ -935,7 +935,7 @@ void game_savegame::create_filename()
{
std::stringstream stream;
const std::string ellipsed_name = font::make_text_ellipsis(gamestate().label,
const std::string ellipsed_name = font::make_text_ellipsis(gamestate().classification().label,
font::SIZE_NORMAL, 200);
stream << ellipsed_name << " " << _("Turn") << " " << gamestatus_.turn();
set_filename(stream.str());

View file

@ -111,8 +111,8 @@ namespace test_utils {
upload_log no_upload(false);
game_state& state = end->get_state();
state.campaign_type = "test";
state.scenario = id_;
state.classification().campaign_type = "test";
state.classification().scenario = id_;
play_game(get_fake_display(1024, 768), state, game_config_, no_upload);
}

View file

@ -243,11 +243,11 @@ void upload_log::start(game_state &state, const team &team,
delete game_;
game_ = new config();
(*game_)["time"] = lexical_cast<std::string>(SDL_GetTicks() / 1000);
(*game_)["campaign"] = state.campaign_define;
(*game_)["difficulty"] = state.difficulty;
(*game_)["scenario"] = state.scenario;
if (!state.version.empty())
(*game_)["version"] = state.version;
(*game_)["campaign"] = state.classification().campaign_define;
(*game_)["difficulty"] = state.classification().difficulty;
(*game_)["scenario"] = state.classification().scenario;
if (!state.classification().version.empty())
(*game_)["version"] = state.classification().version;
if (!turn.empty())
(*game_)["start_turn"] = turn;
(*game_)["gold"] = lexical_cast<std::string>(team.gold());