removed the [player] tag from replay_start in savegames.
saves with player tags in replay_start still work
This commit is contained in:
parent
96ad766e9e
commit
1164d35f2a
3 changed files with 19 additions and 12 deletions
|
@ -164,28 +164,34 @@ game_state::game_state() :
|
|||
classification_()
|
||||
{}
|
||||
|
||||
void write_players(game_state& gamestate, config& cfg, const bool merge_side)
|
||||
void write_players(game_state& gamestate, config& cfg, const bool use_snapshot, const bool merge_side)
|
||||
{
|
||||
// If there is already a player config available it means we are loading
|
||||
// from a savegame. Don't do anything then, the information is already there
|
||||
config::child_itors player_cfg = cfg.child_range("player");
|
||||
if (player_cfg.first != player_cfg.second)
|
||||
return;
|
||||
|
||||
config *source = NULL;
|
||||
if (use_snapshot) {
|
||||
source = &gamestate.snapshot;
|
||||
} else {
|
||||
source = &gamestate.starting_pos;
|
||||
}
|
||||
|
||||
if (merge_side) {
|
||||
//merge sides/players from starting pos with the scenario cfg
|
||||
config temp(cfg);
|
||||
std::vector<std::string> tags;
|
||||
tags.push_back("side");
|
||||
tags.push_back("player"); //merge [player] tags for backwards compatibility of saves
|
||||
|
||||
foreach (const std::string side_tag, tags) {
|
||||
foreach (config* carryover_side, gamestate.starting_pos.get_children(side_tag)) {
|
||||
foreach (config* carryover_side, source->get_children(side_tag)) {
|
||||
config *scenario_side = NULL;
|
||||
|
||||
if (config& c = temp.find_child("side", "save_id", (*carryover_side)["save_id"])) {
|
||||
if (config& c = cfg.find_child("side", "save_id", (*carryover_side)["save_id"])) {
|
||||
scenario_side = &c;
|
||||
} else if (config& c = temp.find_child("side", "id", (*carryover_side)["save_id"])) {
|
||||
} else if (config& c = cfg.find_child("side", "id", (*carryover_side)["save_id"])) {
|
||||
scenario_side = &c;
|
||||
}
|
||||
|
||||
|
@ -211,14 +217,13 @@ void write_players(game_state& gamestate, config& cfg, const bool merge_side)
|
|||
(*scenario_side).merge_with(*carryover_side);
|
||||
} else {
|
||||
//no matching side in the current scenario, we add the persistent information in a [player] tag
|
||||
temp.add_child("player", (*carryover_side));
|
||||
cfg.add_child("player", (*carryover_side));
|
||||
}
|
||||
}
|
||||
}
|
||||
gamestate.starting_pos = temp;
|
||||
|
||||
} else {
|
||||
foreach(const config* snapshot_side, gamestate.snapshot.get_children("side")) {
|
||||
foreach(const config* snapshot_side, source->get_children("side")) {
|
||||
//take all side tags and add them as players (assuming they only contain carryover information)
|
||||
cfg.add_child("player", *snapshot_side);
|
||||
}
|
||||
|
|
|
@ -152,7 +152,7 @@ private:
|
|||
|
||||
std::string generate_game_uuid();
|
||||
|
||||
void write_players(game_state& gamestate, config& cfg, const bool merge_side = false);
|
||||
void write_players(game_state& gamestate, config& cfg, const bool use_snapshot=true, const bool merge_side = false);
|
||||
|
||||
void extract_summary_from_config(config& cfg_save, config& cfg_summary);
|
||||
|
||||
|
|
|
@ -228,7 +228,9 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
|
|||
if (*scenario) {
|
||||
starting_pos = *scenario;
|
||||
preload_lua_tags(game_config, starting_pos);
|
||||
write_players(gamestate, starting_pos, true);
|
||||
config temp(starting_pos);
|
||||
write_players(gamestate, temp, false, true);
|
||||
gamestate.starting_pos = temp;
|
||||
scenario = &starting_pos;
|
||||
} else
|
||||
scenario = NULL;
|
||||
|
@ -519,7 +521,7 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
|
|||
assert(next_cfg != NULL);
|
||||
gamestate.write_snapshot(next_cfg);
|
||||
assert (next_cfg.get_children("player").empty());
|
||||
write_players(gamestate, next_cfg);
|
||||
write_players(gamestate, next_cfg, true, true);
|
||||
network::send_data(cfg, 0, true);
|
||||
}
|
||||
}
|
||||
|
@ -570,7 +572,7 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
|
|||
if (gamestate.classification().campaign_type != "multiplayer"){
|
||||
gamestate.starting_pos = *scenario;
|
||||
assert (!gamestate.snapshot.empty());
|
||||
write_players(gamestate, gamestate.starting_pos);
|
||||
write_players(gamestate, gamestate.starting_pos, true, true);
|
||||
}
|
||||
}
|
||||
gamestate.snapshot = config();
|
||||
|
|
Loading…
Add table
Reference in a new issue