From 139d6252dd5a2c0fa6d9b0a5a45c1959f9320b1f Mon Sep 17 00:00:00 2001 From: gfgtdf Date: Thu, 26 Jun 2014 21:41:14 +0200 Subject: [PATCH] add update_label function to saved_game --- src/playcampaign.cpp | 18 +----------------- src/saved_game.cpp | 12 ++++++++++++ src/saved_game.hpp | 3 +++ 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/playcampaign.cpp b/src/playcampaign.cpp index c737c42e4303..13d8d4e4648e 100644 --- a/src/playcampaign.cpp +++ b/src/playcampaign.cpp @@ -278,16 +278,6 @@ LEVEL_RESULT play_game(game_display& disp, saved_game& gamestate, end_level_data end_level; try { - // Preserve old label eg. replay - if (gamestate.classification().label.empty()) { - if (gamestate.classification().abbrev.empty()) - gamestate.classification().label = starting_pos["name"].str(); - else { - gamestate.classification().label = gamestate.classification().abbrev; - gamestate.classification().label.append("-"); - gamestate.classification().label.append(starting_pos["name"]); - } - } gamestate.expand_random_scenario(); //In case this an mp scenario reloaded by sp this was not already done yet. @@ -440,13 +430,7 @@ LEVEL_RESULT play_game(game_display& disp, saved_game& gamestate, if(gamestate.valid()) { // Update the label - if (gamestate.classification().abbrev.empty()) - gamestate.classification().label = starting_pos["name"].str(); - else { - gamestate.classification().label = gamestate.classification().abbrev; - gamestate.classification().label.append("-"); - gamestate.classification().label.append(starting_pos["name"]); - } + gamestate.update_label(); // If this isn't the last scenario, then save the game if(save_game_after_scenario) { diff --git a/src/saved_game.cpp b/src/saved_game.cpp index 958bd0fa826c..5fe07e1721fd 100644 --- a/src/saved_game.cpp +++ b/src/saved_game.cpp @@ -204,6 +204,7 @@ void saved_game::expand_scenario() { this->starting_pos_type_ = STARTINGPOS_SCENARIO; this->starting_pos_ = scenario; + update_label(); //Set this default value immideately after reading the scenario is importent because otherwise //we might endup settings this value to the multiplayer players name, which would break carryover. @@ -327,6 +328,7 @@ void saved_game::expand_random_scenario() scenario_new.add_child("story", story); } starting_pos_ = scenario_new; + update_label(); } //it looks like we support a map= where map=filename equals more or less map_data={filename} if(starting_pos_["map_data"].empty() && starting_pos_["map"] != "") { @@ -383,6 +385,7 @@ void saved_game::set_scenario(const config& scenario) { this->carryover_sides_start.child_or_add("variables"); } + update_label(); } void saved_game::remove_snapshot() @@ -497,3 +500,12 @@ bool saved_game::not_corrupt() const } return r; } + +void saved_game::update_label() +{ + if (classification().abbrev.empty()) + classification().label = starting_pos_["name"].str(); + else { + classification().label = classification().abbrev + "-" + starting_pos_["name"]; + } +} diff --git a/src/saved_game.hpp b/src/saved_game.hpp index 72e97e748965..bc033c33852f 100644 --- a/src/saved_game.hpp +++ b/src/saved_game.hpp @@ -79,6 +79,9 @@ class saved_game const config& replay_start() const { return replay_start_; } bool not_corrupt() const; + /** sets classification().label to the correct value. */ + void update_label(); + /** * If the game is saved mid-level, we have a series of replay steps * to take the game up to the position it was saved at.