Skip to content

Commit

Permalink
track debugged character swaps
Browse files Browse the repository at this point in the history
  • Loading branch information
cake-pie committed Feb 9, 2023
1 parent acb1946 commit 1a90334
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 20 deletions.
10 changes: 5 additions & 5 deletions src/avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ static void swap_npc( npc &one, npc &two, npc &tmp )
two = std::move( tmp );
}

void avatar::control_npc( npc &np )
void avatar::control_npc( npc &np, const bool debug )
{
if( !np.is_player_ally() ) {
debugmsg( "control_npc() called on non-allied npc %s", np.name );
Expand Down Expand Up @@ -204,11 +204,11 @@ void avatar::control_npc( npc &np )
character_mood_face( true );

profession_id prof_id = prof ? prof->ident() : profession::generic()->ident();
get_event_bus().send<event_type::game_avatar_new>( false, getID(), name, male,
prof_id, custom_profession );
get_event_bus().send<event_type::game_avatar_new>( /*is_new_game=*/false, debug,
getID(), name, male, prof_id, custom_profession );
}

void avatar::control_npc_menu()
void avatar::control_npc_menu( const bool debug )
{
std::vector<shared_ptr_fast<npc>> followers;
uilist charmenu;
Expand All @@ -228,7 +228,7 @@ void avatar::control_npc_menu()
if( charmenu.ret < 0 || static_cast<size_t>( charmenu.ret ) >= followers.size() ) {
return;
}
get_avatar().control_npc( *followers[charmenu.ret] );
get_avatar().control_npc( *followers[charmenu.ret], debug );
}

void avatar::longpull( const std::string &name )
Expand Down
4 changes: 2 additions & 2 deletions src/avatar.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ class avatar : public Character
* Makes the avatar "take over" the given NPC, while the current avatar character
* becomes an NPC.
*/
void control_npc( npc & );
void control_npc( npc &, bool debug = false );
/**
* Open a menu to choose the NPC to take over.
*/
void control_npc_menu();
void control_npc_menu( bool debug = false );
using Character::query_yn;
bool query_yn( const std::string &mes ) const override;

Expand Down
2 changes: 1 addition & 1 deletion src/debug_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,7 @@ static void spawn_nested_mapgen()

static void control_npc_menu()
{
get_avatar().control_npc_menu();
get_avatar().control_npc_menu( true );
}

static void character_edit_stats_menu( Character &you )
Expand Down
3 changes: 2 additions & 1 deletion src/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,9 @@ struct event_spec<event_type::game_avatar_death> {

template<>
struct event_spec<event_type::game_avatar_new> {
static constexpr std::array<std::pair<const char *, cata_variant_type>, 6> fields = {{
static constexpr std::array<std::pair<const char *, cata_variant_type>, 7> fields = {{
{ "is_new_game", cata_variant_type::bool_ },
{ "is_debug", cata_variant_type::bool_ },
{ "avatar_id", cata_variant_type::character_id },
{ "avatar_name", cata_variant_type::string },
{ "avatar_is_male", cata_variant_type::bool_ },
Expand Down
4 changes: 2 additions & 2 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1009,8 +1009,8 @@ bool game::start_game()
}

get_event_bus().send<event_type::game_start>( getVersionString() );
get_event_bus().send<event_type::game_avatar_new>( true, u.getID(), u.name, u.male,
u.prof->ident(), u.custom_profession );
get_event_bus().send<event_type::game_avatar_new>( /*is_new_game=*/true, /*is_debug=*/false,
u.getID(), u.name, u.male, u.prof->ident(), u.custom_profession );
time_played_at_last_load = std::chrono::seconds( 0 );
time_of_last_load = std::chrono::steady_clock::now();
tripoint_abs_omt abs_omt = u.global_omt_location();
Expand Down
11 changes: 6 additions & 5 deletions src/savegame_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4702,6 +4702,7 @@ void stats_tracker::deserialize( const JsonObject &jo )
// 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 ) ) );
Expand All @@ -4711,17 +4712,17 @@ void stats_tracker::deserialize( const JsonObject &jo )
avatar &u = get_avatar();
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, u.getID(), u.name, u.male, prof_id, u.custom_profession ) );
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
// 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, u.getID(), u.name, u.male, prof_id, u.custom_profession ) );
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
4 changes: 2 additions & 2 deletions tests/memorial_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ TEST_CASE( "memorials", "[memorial]" )
"last_words" );

check_memorial<event_type::game_avatar_new>(
m, b, u_name + " began their journey into the Cataclysm.", true, ch, u_name, player_character.male,
player_character.prof->ident(), player_character.custom_profession );
m, b, u_name + " began their journey into the Cataclysm.", true, false, ch, u_name,
player_character.male, player_character.prof->ident(), player_character.custom_profession );

check_memorial<event_type::installs_cbm>(
m, b, "Installed bionic: Alarm System.", ch, cbm );
Expand Down
4 changes: 2 additions & 2 deletions tests/stats_tracker_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ TEST_CASE( "stats_tracker_event_time_bounds", "[stats]" )
static void send_game_start( event_bus &b, const character_id &u_id )
{
b.send<event_type::game_start>( "VERION_STRING" );
b.send<event_type::game_avatar_new>( /*is_new_game=*/true, u_id, "Avatar name",
/*is_male=*/false, profession_id::NULL_ID(), "CUSTOM_PROFESSION" );
b.send<event_type::game_avatar_new>( /*is_new_game=*/true, /*is_debug=*/false, u_id,
"Avatar name", /*is_male=*/false, profession_id::NULL_ID(), "CUSTOM_PROFESSION" );
}

TEST_CASE( "stats_tracker_with_event_statistics", "[stats]" )
Expand Down

0 comments on commit 1a90334

Please sign in to comment.