This fixes bug #10354 (loading linger-mode saves loses branch choices)

...and gets rid of a couple of ugly work arounds. Adding next_scenario
to the gamestate made them obsolete.
This commit is contained in:
Jörg Hinrichs 2007-12-01 08:27:12 +00:00
parent 023857ce61
commit 29f5b458a3
5 changed files with 14 additions and 20 deletions

View File

@ -2180,7 +2180,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
const std::string next_scenario = cfg["next_scenario"];
if(next_scenario.empty() == false) {
state_of_game->scenario = next_scenario;
state_of_game->next_scenario = next_scenario;
}
const std::string result = cfg["result"].base_str(); //do not translate

View File

@ -429,6 +429,7 @@ game_state::game_state(const game_data& data, const config& cfg)
label = cfg["label"];
version = cfg["version"];
scenario = cfg["scenario"];
next_scenario = cfg["next_scenario"];
completion = cfg["completion"];
campaign = cfg["campaign"];
@ -454,6 +455,7 @@ game_state::game_state(const game_data& data, const config& cfg)
}
std::cerr << "scenario: '" << scenario << "'\n";
std::cerr << "next_scenario: '" << next_scenario << "'\n";
difficulty = cfg["difficulty"];
if(difficulty.empty())
@ -559,6 +561,7 @@ void write_game(const game_state& gamestate, config& cfg, WRITE_GAME_MODE mode)
cfg["version"] = game_config::version;
cfg["scenario"] = gamestate.scenario;
cfg["next_scenario"] = gamestate.next_scenario;
cfg["completion"] = gamestate.completion;
@ -616,6 +619,7 @@ void write_game(config_writer &out, const game_state& gamestate, WRITE_GAME_MODE
out.write_key_val("label", gamestate.label);
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);

View File

@ -110,6 +110,7 @@ public:
std::string campaign; //!< the campaign being played
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
//! Information about campaign players who carry resources

View File

@ -314,8 +314,7 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
}
const config::child_list& story = scenario->get_children("story");
const std::string current_scenario = gamestate.scenario;
const std::string next_scenario = (*scenario)["next_scenario"];
gamestate.next_scenario = (*scenario)["next_scenario"];
bool save_game_after_scenario = true;
@ -403,9 +402,6 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
// if MP campaigns ever work again, we might
// need to change this test.
if(res == VICTORY || io_type != IO_NONE) {
const std::string orig_scenario = gamestate.scenario;
gamestate.scenario = current_scenario;
if (preferences::delete_saves())
clean_saves(gamestate.label);
@ -419,8 +415,6 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
gui::show_error_message(disp, _("The replay could not be saved"));
}
}
gamestate.scenario = orig_scenario;
}
recorder.clear();
@ -432,10 +426,10 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
{
// In case we are the host and there is a next scenario, notify
// the other players so they can leave linger mode.
if (!next_scenario.empty() && io_type == IO_SERVER)
if (!gamestate.next_scenario.empty() && io_type == IO_SERVER)
notify_next_scenario(IO_SERVER);
if (res != OBSERVER_END || next_scenario.empty())
if (res != OBSERVER_END || gamestate.next_scenario.empty())
return res;
const int dlg_res = gui::dialog(disp,"Game Over",
@ -450,12 +444,11 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
if(res == LEVEL_CONTINUE_NO_SAVE)
save_game_after_scenario = false;
// If the scenario hasn't been set in-level, set it now.
if(gamestate.scenario == current_scenario)
gamestate.scenario = next_scenario;
// Switch to the next scenario.
gamestate.scenario = gamestate.next_scenario;
if(io_type == IO_CLIENT) {
if (!next_scenario.empty()){
if (!gamestate.next_scenario.empty()){
//notifies the clients that this player advanced to the next scenario
notify_next_scenario(IO_CLIENT);

View File

@ -331,12 +331,8 @@ LEVEL_RESULT playsingle_controller::play_scenario(const std::vector<config*>& st
if (first_human_team_ != -1)
log.victory(status_.turn(), teams_[first_human_team_].gold());
if(gamestate_.scenario == (level_)["id"]) {
gamestate_.scenario = (level_)["next_scenario"];
}
const bool has_next_scenario = !gamestate_.scenario.empty() &&
gamestate_.scenario != "null";
const bool has_next_scenario = !gamestate_.next_scenario.empty() &&
gamestate_.next_scenario != "null";
// Save current_player name to reuse it when setting next_scenario side info
std::vector<team>::iterator i;