Skip to content

Commit

Permalink
move next_underlying_unit_id
Browse files Browse the repository at this point in the history
from savefiles toplevel to savefiles [snapshot]/[replay_start]/[carryover_sides_start]
previously this was handled specialy at scenario toplevel sometimes and in those tags at some other times.

accoringly to that change we now set n_unit::id_manager at play_controller s constructor.
  • Loading branch information
gfgtdf committed Jun 10, 2014
1 parent 51a2c04 commit f26f992
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/carryover.cpp
Expand Up @@ -142,6 +142,7 @@ carryover_info::carryover_info(const config& cfg)
, rng_(cfg)
, wml_menu_items_()
, next_scenario_(cfg["next_scenario"])
, next_underlying_unit_id_(cfg["next_underlying_unit_id"].to_int(0))
{
end_level_.read(cfg.child_or_empty("end_level_data"));
BOOST_FOREACH(const config& side, cfg.child_range("side")){
Expand Down Expand Up @@ -212,7 +213,10 @@ void carryover_info::transfer_from(game_data& gamedata){
}

void carryover_info::transfer_to(config& level){

if(!level.has_attribute("next_underlying_unit_id"))
{
level["next_underlying_unit_id"] = next_underlying_unit_id_;
}

if(!end_level_.next_scenario_settings.empty()) {
level.merge_with(end_level_.next_scenario_settings);
Expand Down Expand Up @@ -245,7 +249,7 @@ void carryover_info::transfer_to(config& level){
const config carryover_info::to_config()
{
config cfg;

cfg["next_underlying_unit_id"] = next_underlying_unit_id_;
cfg["next_scenario"] = next_scenario_;

BOOST_FOREACH(carryover& c, carryover_sides_){
Expand Down
2 changes: 2 additions & 0 deletions src/carryover.hpp
Expand Up @@ -63,6 +63,7 @@ class carryover_info{
, rng_()
, wml_menu_items_()
, next_scenario_()
, next_underlying_unit_id_()
{}
// Turns config from a loaded savegame into carryover_info
explicit carryover_info(const config& cfg);
Expand Down Expand Up @@ -100,6 +101,7 @@ class carryover_info{
rand_rng::simple_rng rng_;
game_events::wmi_container wml_menu_items_;
std::string next_scenario_; /**< the scenario coming next (for campaigns) */
int next_underlying_unit_id_;
};


Expand Down
11 changes: 10 additions & 1 deletion src/gamestatus.cpp
Expand Up @@ -617,7 +617,6 @@ game_state::game_state(const config& cfg, bool show_replay) :
classification_(cfg),
mp_settings_(cfg)
{
n_unit::id_manager::instance().set_save_id(cfg["next_underlying_unit_id"]);
log_scope("read_game");

if(cfg.has_child("carryover_sides")){
Expand Down Expand Up @@ -759,7 +758,17 @@ void convert_old_saves(config& cfg){
LOG_RG<<"removing snapshot \n";
cfg.remove_child("snapshot", 0);
}
//?-1.11.? end
//1.12-1.13 begin

if(config& carryover_sides_start = cfg.child("carryover_sides_start"))
{
if(!carryover_sides_start.has_attribute("next_underlying_unit_id"))
{
carryover_sides_start["next_underlying_unit_id"] = cfg["next_underlying_unit_id"];
}
}
//1.12-1.13 end
LOG_RG<<"cfg after conversion "<<cfg<<"\n";
}

Expand Down
3 changes: 2 additions & 1 deletion src/play_controller.cpp
Expand Up @@ -155,7 +155,8 @@ play_controller::play_controller(const config& level, game_state& state_of_game,
resources::mp_settings = &gamestate_.mp_settings();

persist_.start_transaction();

n_unit::id_manager::instance().set_save_id(level_["next_underlying_unit_id"]);

// Setup victory and defeat music
set_victory_music_list(level_["victory_music"]);
set_defeat_music_list(level_["defeat_music"]);
Expand Down
2 changes: 2 additions & 0 deletions src/playcampaign.cpp
Expand Up @@ -270,6 +270,7 @@ static LEVEL_RESULT playsingle_scenario(const config& game_config,

end_level = playcontroller.get_end_level_data_const();
config& cfg_end_level = state_of_game.carryover_sides.child_or_add("end_level_data");
state_of_game.carryover_sides["next_underlying_unit_id"] = int(n_unit::id_manager::instance().get_save_id());
end_level.write(cfg_end_level);

if (res != QUIT)
Expand Down Expand Up @@ -312,6 +313,7 @@ static LEVEL_RESULT playmp_scenario(const config& game_config,
end_level = playcontroller.get_end_level_data_const();
config& cfg_end_level = state_of_game.carryover_sides.child_or_add("end_level_data");
end_level.write(cfg_end_level);
state_of_game.carryover_sides["next_underlying_unit_id"] = int(n_unit::id_manager::instance().get_save_id());

//Check if the player started as mp client and changed to host
if (io_type == IO_CLIENT && playcontroller.is_host())
Expand Down

0 comments on commit f26f992

Please sign in to comment.