Skip to content

Commit

Permalink
fix bug 22086, by storing map data correctly in savegame summaries
Browse files Browse the repository at this point in the history
The bug was that minimap previews for save games were not appearing,
or that the wrong ones were appearing.

It seems that because of more relics from this commit / related,

c17d84b12

the savegame summaries generated by "extract savegame summary" were
bugged and didn't store the map data correctly. This bug wasn't
obvious because the save game load dialog tries to scavenge what
ever the current game config is for map data if it can't find this,
but all of the saveindex data was being generated incorrectly.

After this commit all the save files seem to work correctly,
except for start-of-scenario saves for reasons that aren't clear
to me, and which I think is a separate issue. (In that case,
something is going wrong with the game_config lookup process most
likely.)

This only appears to fix the bug for normal saves, autosaves, and
replay saves.
  • Loading branch information
cbeck88 committed Jul 10, 2014
1 parent d65d03c commit e7eb08d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
10 changes: 10 additions & 0 deletions src/dialogs.cpp
Expand Up @@ -719,7 +719,15 @@ void save_preview_pane::draw_contents()

std::string map_data = summary["map_data"];
if(map_data.empty()) {
LOG_DP << "When parsing save summary " << ((*info_)[index_]).name() << std::endl
<< "Did not find a map_data field. Looking in game config for a child [" << summary["campaign_type"] << "] with id " << summary["scenario"] << std::endl;
assert(game_config_ && "ran into a null game config pointer inside a game preview pane");
const config &scenario = game_config_->find_child(summary["campaign_type"], "id", summary["scenario"]);

if (!scenario) {
LOG_DP << "Did not find a matching scenario." << std::endl;
}

if (scenario && !scenario.find_child("side", "shroud", "yes")) {
map_data = scenario["map_data"].str();
if (map_data.empty() && scenario.has_attribute("map")) {
Expand Down Expand Up @@ -765,6 +773,8 @@ void save_preview_pane::draw_contents()

ypos = std::max<int>(ypos,map_rect.y + map_rect.h + save_preview_border);
sdl_blit(map_surf,NULL,screen,&map_rect);
} else {
LOG_DP << "Never found a map for savefile " << (*info_)[index_].name() << std::endl;
}

char time_buf[256] = {0};
Expand Down
9 changes: 9 additions & 0 deletions src/game_controller.cpp
Expand Up @@ -447,6 +447,15 @@ bool game_controller::is_loading() const

bool game_controller::load_game()
{
assert(resources::config_manager);

if (state_.classification().campaign_type.size() == 0) {
state_ = game_state();
state_.classification().campaign_type = "scenario";
}

DBG_GENERAL << "Current campaign type: " << state_.classification().campaign_type << std::endl;

savegame::loadgame load(disp(), resources::config_manager->game_config(),
state_);

Expand Down
12 changes: 8 additions & 4 deletions src/gamestatus.cpp
Expand Up @@ -1167,12 +1167,16 @@ void extract_summary_from_config(config& cfg_save, config& cfg_summary)

if(!shrouded) {
if(has_snapshot) {
if (!cfg_snapshot.find_child("side", "shroud", "yes")) {
cfg_summary.add_child("map", cfg_snapshot.child_or_empty("map"));
if (!cfg_snapshot.find_child("side", "shroud", "yes") && cfg_snapshot.has_attribute("map_data")) {
cfg_summary["map_data"] = cfg_snapshot["map_data"].str();
} else {
ERR_NG << "Not saving map because there is shroud" << std::endl;
}
} else if(has_replay) {
if (!cfg_replay_start.find_child("side","shroud","yes")) {
cfg_summary.add_child("map", cfg_replay_start.child_or_empty("map"));
if (!cfg_replay_start.find_child("side","shroud","yes") && cfg_replay_start.has_attribute("map_data")) {
cfg_summary["map_data"] = cfg_replay_start["map_data"];
} else {
ERR_NG << "Not saving map because there is shroud" << std::endl;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/savegame.cpp
Expand Up @@ -707,7 +707,7 @@ void loadgame::fill_mplevel_config(config& level){
// is empty the starting position contains the wanted info.
const config& start_data = !gamestate_.snapshot.empty() ? gamestate_.snapshot : gamestate_.replay_start();

level.add_child("map", start_data.child_or_empty("map"));
level["map_data"], start_data["map_data"];
level["id"] = start_data["id"];
level["name"] = start_data["name"];
level["completion"] = start_data["completion"];
Expand Down

0 comments on commit e7eb08d

Please sign in to comment.