Skip to content

Commit

Permalink
save replaydata of the undostack
Browse files Browse the repository at this point in the history
not saving these might result in currupt replays when redoing a move
from a saved game.
  • Loading branch information
gfgtdf committed May 11, 2014
1 parent 4a81ab0 commit 64e69cd
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions src/actions/undo.cpp
Expand Up @@ -231,13 +231,13 @@ undo_list::undo_action *
undo_list::undo_action::create(const config & cfg, const std::string & tag)
{
const std::string str = cfg["type"];

undo_list::undo_action * res = NULL;
// The general division of labor in this function is that the various
// constructors will parse the "unit" child config, while this function
// parses everything else.

if ( str == "move" )
return new move_action(cfg.child("unit", tag), cfg,
res = new move_action(cfg.child("unit", tag), cfg,
cfg["starting_moves"],
cfg["time_bonus"],
cfg["village_owner"],
Expand All @@ -254,28 +254,32 @@ undo_list::undo_action::create(const config & cfg, const std::string & tag)
<< child["type"] << "' was not found.\n";
return NULL;
}
return new recruit_action(child, *u_type,
res = new recruit_action(child, *u_type,
map_location(cfg, NULL),
map_location(cfg.child_or_empty("leader"), NULL));
}

if ( str == "recall" )
return new recall_action(cfg.child("unit", tag),
else if ( str == "recall" )
res = new recall_action(cfg.child("unit", tag),
map_location(cfg, NULL),
map_location(cfg.child_or_empty("leader"), NULL));

if ( str == "dismiss" )
return new dismiss_action(cfg.child("unit", tag));

if ( str == "auto_shroud" )
return new auto_shroud_action(cfg["active"].to_bool());
else if ( str == "dismiss" )
res = new dismiss_action(cfg.child("unit", tag));

if ( str == "update_shroud" )
return new update_shroud_action;
else if ( str == "auto_shroud" )
res = new auto_shroud_action(cfg["active"].to_bool());

// Unrecognized type.
ERR_NG << "Unrecognized undo action type: " << str << ".\n";
return NULL;
else if ( str == "update_shroud" )
res = new update_shroud_action;
else
{
// Unrecognized type.
ERR_NG << "Unrecognized undo action type: " << str << ".\n";
return NULL;
}
res->replay_data = cfg.child_or_empty("replay_data");
return res;
}


Expand All @@ -284,6 +288,7 @@ undo_list::undo_action::create(const config & cfg, const std::string & tag)
*/
void undo_list::dismiss_action::write(config & cfg) const
{
cfg.add_child("replay_data", replay_data);
cfg["type"] = "dismiss";
dismissed_unit.write(cfg.add_child("unit"));
}
Expand All @@ -293,6 +298,7 @@ void undo_list::dismiss_action::write(config & cfg) const
*/
void undo_list::recall_action::write(config & cfg) const
{
cfg.add_child("replay_data", replay_data);
cfg["type"] = "recall";
route.front().write(cfg);
recall_from.write(cfg.add_child("leader"));
Expand All @@ -307,6 +313,7 @@ void undo_list::recall_action::write(config & cfg) const
*/
void undo_list::recruit_action::write(config & cfg) const
{
cfg.add_child("replay_data", replay_data);
cfg["type"] = "recruit";
route.front().write(cfg);
recruit_from.write(cfg.add_child("leader"));
Expand All @@ -321,6 +328,7 @@ void undo_list::recruit_action::write(config & cfg) const
*/
void undo_list::move_action::write(config & cfg) const
{
cfg.add_child("replay_data", replay_data);
cfg["type"] = "move";
cfg["starting_direction"] = map_location::write_direction(starting_dir);
cfg["starting_moves"] = starting_moves;
Expand All @@ -339,6 +347,7 @@ void undo_list::move_action::write(config & cfg) const
*/
void undo_list::auto_shroud_action::write(config & cfg) const
{
cfg.add_child("replay_data", replay_data);
cfg["type"] = "auto_shroud";
cfg["active"] = active;
}
Expand All @@ -348,6 +357,7 @@ void undo_list::auto_shroud_action::write(config & cfg) const
*/
void undo_list::update_shroud_action::write(config & cfg) const
{
cfg.add_child("replay_data", replay_data);
cfg["type"] = "update_shroud";
}

Expand Down

0 comments on commit 64e69cd

Please sign in to comment.