Don't store duplicate current side num in savefiles

This not only removes duplicate information which can always cause bugs if it's out of sync,
this can also be used an an easy way to detect the old undo stack format
This commit is contained in:
gfgtdf 2024-11-28 00:50:15 +01:00
parent 8a91549fe8
commit c08152a0e7
3 changed files with 9 additions and 7 deletions

View file

@ -196,13 +196,16 @@ void undo_list::new_side_turn(int side)
* Currently, this is only used when the undo_list is empty, but in theory
* it could be used to append the config to the current data.
*/
void undo_list::read(const config & cfg)
void undo_list::read(const config& cfg, int current_side)
{
// Merge header data.
// TODO: remove side parameter, its already stored in [snapshot].
side_ = cfg["side"].to_int(side_);
side_ = current_side;
committed_actions_ = committed_actions_ || cfg["committed"].to_bool();
//If we have the side parameter this means that this was the old format pre 1.19.7, we ignore this since it's incompatible.
if(cfg.has_attribute("side")) {
return;
}
// Build the undo stack.
try {
for(const config& child : cfg.child_range("undo")) {
@ -235,7 +238,6 @@ void undo_list::read(const config & cfg)
*/
void undo_list::write(config & cfg) const
{
cfg["side"] = side_;
cfg["committed"] = committed_actions_;
for ( const auto& action_ptr : undos_)

View file

@ -85,7 +85,7 @@ public:
/** Returns true if the player has performed any actions this turn. */
bool player_acted() const { return committed_actions_ || !undos_.empty(); }
/** Read the undo_list from the provided config. */
void read(const config & cfg);
void read(const config & cfg, int current_side);
/** Write the undo_list into the provided config. */
void write(config & cfg) const;

View file

@ -189,7 +189,7 @@ void game_state::init(const config& level, play_controller & pc)
tod_manager_.resolve_random(*randomness::generator);
undo_stack_->read(level.child_or_empty("undo_stack"));
undo_stack_->read(level.child_or_empty("undo_stack"), player_number_);
for(team_builder& tb : team_builders) {
tb.build_team_stage_two();