Skip to content

Commit

Permalink
Merge pull request #75057 from Maleclypse/Debug-Special-NPCs
Browse files Browse the repository at this point in the history
Debug NPC by class ID ie special npcs
  • Loading branch information
dseguin authored Sep 29, 2024
2 parents 879a471 + 67847b0 commit 5efdf7a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/debug_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ std::string enum_to_string<debug_menu::debug_menu_index>( debug_menu::debug_menu
case debug_menu::debug_menu_index::LONG_TELEPORT: return "LONG_TELEPORT";
case debug_menu::debug_menu_index::REVEAL_MAP: return "REVEAL_MAP";
case debug_menu::debug_menu_index::SPAWN_NPC: return "SPAWN_NPC";
case debug_menu::debug_menu_index::SPAWN_NAMED_NPC: return "SPAWN_NAMED_NPC";
case debug_menu::debug_menu_index::SPAWN_OM_NPC: return "SPAWN_OM_NPC";
case debug_menu::debug_menu_index::SPAWN_MON: return "SPAWN_MON";
case debug_menu::debug_menu_index::GAME_STATE: return "GAME_STATE";
Expand Down Expand Up @@ -862,6 +863,7 @@ static int spawning_uilist()
const std::vector<uilist_entry> uilist_initializer = {
{ uilist_entry( debug_menu_index::WISH, true, 'w', _( "Spawn an item" ) ) },
{ uilist_entry( debug_menu_index::SPAWN_NPC, true, 'n', _( "Spawn NPC" ) ) },
{ uilist_entry( debug_menu_index::SPAWN_NAMED_NPC, true, 'p', _( "Spawn Named NPC" ) ) },
{ uilist_entry( debug_menu_index::SPAWN_OM_NPC, true, 'N', _( "Spawn random NPC on overmap" ) ) },
{ uilist_entry( debug_menu_index::SPAWN_MON, true, 'm', _( "Spawn monster" ) ) },
{ uilist_entry( debug_menu_index::SPAWN_VEHICLE, true, 'v', _( "Spawn a vehicle" ) ) },
Expand Down Expand Up @@ -3544,6 +3546,34 @@ static void spawn_npc()
g->load_npcs();
}

static void spawn_named_npc()
{
const std::string input = string_input_popup()
.title( _( "Enter NPC template" ) )
.width( 20 )
.query_string();

if( input.empty() ) {
return;
}

const npc_template_id npc_template = npc_template_id( input );
if( !npc_template.is_valid() ) {
popup( "Invalid template id" );
return;
}

avatar &player_character = get_avatar();
shared_ptr_fast<npc> temp = make_shared_fast<npc>();
temp->normalize();
temp->load_npc_template( npc_template );
temp->spawn_at_precise( player_character.get_location() + point( -4, -4 ) );
overmap_buffer.insert_npc( temp );
temp->form_opinion( player_character );

g->load_npcs();
}

static void unlock_all()
{
if( query_yn( _(
Expand Down Expand Up @@ -3779,6 +3809,10 @@ void debug()
spawn_npc();
break;

case debug_menu_index::SPAWN_NAMED_NPC:
spawn_named_npc();
break;

case debug_menu_index::SPAWN_OM_NPC: {
int num_of_npcs = 1;
if( query_int( num_of_npcs, _( "How many NPCs to try spawning?" ), num_of_npcs ) ) {
Expand Down
1 change: 1 addition & 0 deletions src/debug_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ enum class debug_menu_index : int {
LONG_TELEPORT,
REVEAL_MAP,
SPAWN_NPC,
SPAWN_NAMED_NPC,
SPAWN_OM_NPC,
SPAWN_MON,
GAME_STATE,
Expand Down

0 comments on commit 5efdf7a

Please sign in to comment.