Skip to content

Commit

Permalink
add update_label function to saved_game
Browse files Browse the repository at this point in the history
  • Loading branch information
gfgtdf committed Jun 27, 2014
1 parent 83d9976 commit 139d625
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
18 changes: 1 addition & 17 deletions src/playcampaign.cpp
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions src/saved_game.cpp
Expand Up @@ -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.
Expand Down Expand Up @@ -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"] != "") {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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"];
}
}
3 changes: 3 additions & 0 deletions src/saved_game.hpp
Expand Up @@ -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.
Expand Down

0 comments on commit 139d625

Please sign in to comment.