Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport #71328 #73961

Merged
merged 1 commit into from
May 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 29 additions & 25 deletions src/savegame_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4549,35 +4549,39 @@ void stats_tracker::deserialize( const JsonObject &jo )
event_multiset gan_evts = get_events( event_type::game_avatar_new );
if( !gan_evts.count() ) {
event_multiset gs_evts = get_events( event_type::game_start );
if( gs_evts.count() ) {
auto gs_evt = gs_evts.first().value();
cata::event::data_type gs_data = gs_evt.first;

// retroactively insert starting avatar
cata::event::data_type gan_data( gs_data );
gan_data["is_new_game"] = cata_variant::make<cata_variant_type::bool_>( true );
gan_data["is_debug"] = cata_variant::make<cata_variant_type::bool_>( false );
gan_data.erase( "game_version" );
get_event_bus().send( cata::event( event_type::game_avatar_new, calendar::start_of_game,
std::move( gan_data ) ) );

// retroactively insert current avatar, if different from starting avatar
// we don't know when they took over, so just use current time point
avatar &u = get_avatar();
if( u.getID() != gs_data["avatar_id"].get<cata_variant_type::character_id>() ) {
avatar &u = get_avatar();
// check if character ID set, if loadsave, the ID will not be -1
// if it's an old save without event_type::game_avatar_new, the event need to be done
// this function is invoked when load memorial, on this situation start a new game, below shouldn't be invoked.
if( u.getID() != character_id( -1 ) ) {
if( gs_evts.count() ) {
auto gs_evt = gs_evts.first().value();
cata::event::data_type gs_data = gs_evt.first;

// retroactively insert starting avatar
cata::event::data_type gan_data( gs_data );
gan_data["is_new_game"] = cata_variant::make<cata_variant_type::bool_>( true );
gan_data["is_debug"] = cata_variant::make<cata_variant_type::bool_>( false );
gan_data.erase( "game_version" );
get_event_bus().send( cata::event( event_type::game_avatar_new, calendar::start_of_game,
std::move( gan_data ) ) );

// retroactively insert current avatar, if different from starting avatar
// we don't know when they took over, so just use current time point
if( u.getID() != gs_data["avatar_id"].get<cata_variant_type::character_id>() ) {
profession_id prof_id = u.prof ? u.prof->ident() : profession::generic()->ident();
get_event_bus().send( cata::event::make<event_type::game_avatar_new>( false, false,
u.getID(), u.name, u.male, prof_id, u.custom_profession ) );
}
} else {
// last ditch effort for really old saves that don't even have event_type::game_start
// treat current avatar as the starting avatar; abuse is_new_game=false to flag such cases
profession_id prof_id = u.prof ? u.prof->ident() : profession::generic()->ident();
std::swap( calendar::turn, calendar::start_of_game );
get_event_bus().send( cata::event::make<event_type::game_avatar_new>( false, false,
u.getID(), u.name, u.male, prof_id, u.custom_profession ) );
std::swap( calendar::turn, calendar::start_of_game );
}
} else {
// last ditch effort for really old saves that don't even have event_type::game_start
// treat current avatar as the starting avatar; abuse is_new_game=false to flag such cases
avatar &u = get_avatar();
profession_id prof_id = u.prof ? u.prof->ident() : profession::generic()->ident();
std::swap( calendar::turn, calendar::start_of_game );
get_event_bus().send( cata::event::make<event_type::game_avatar_new>( false, false,
u.getID(), u.name, u.male, prof_id, u.custom_profession ) );
std::swap( calendar::turn, calendar::start_of_game );
}
}
}
Expand Down
Loading