Skip to content

Commit

Permalink
factions: don't duplicate factions loaded from templates and from gsav
Browse files Browse the repository at this point in the history
When reloading factions from master.gsav after they've already been
loaded from the templates by loading NPCs, find the existing factions
instead of making multiple copies.
  • Loading branch information
mlangsdorf committed Jun 15, 2019
1 parent 893d96b commit a7e51e1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/savegame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1585,7 +1585,19 @@ void faction_manager::serialize( JsonOut &jsout ) const

void faction_manager::deserialize( JsonIn &jsin )
{
jsin.read( factions );
jsin.start_array();
while( !jsin.end_array() ) {
faction add_fac;
jsin.read( add_fac );
faction *old_fac = get( add_fac.id );
if( old_fac ) {
*old_fac = add_fac;
// force a revalidation of add_fac
get( add_fac.id );
} else {
factions.emplace_back( add_fac );
}
}
}

void Creature_tracker::deserialize( JsonIn &jsin )
Expand Down
2 changes: 1 addition & 1 deletion src/savegame_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,7 @@ void npc::store( JsonOut &json ) const
json.member( "previous_mission", previous_mission );
json.member( "faction_api_ver", faction_api_version );
if( !fac_id.str().empty() ) { // set in constructor
json.member( "my_fac", my_fac->id.c_str() );
json.member( "my_fac", fac_id.c_str() );
}
json.member( "attitude", static_cast<int>( attitude ) );
json.member( "previous_attitude", static_cast<int>( attitude ) );
Expand Down

0 comments on commit a7e51e1

Please sign in to comment.