From d54f2fbb4cd1afc09d1951b7fb9b5a8d19ce8323 Mon Sep 17 00:00:00 2001 From: Jason Jones Date: Thu, 6 Feb 2020 14:24:12 -0900 Subject: [PATCH] Add debug menu item for spawning nested mapgen --- src/debug_menu.cpp | 44 +++++++++++++++++++++++++++++++++++++++++++- src/debug_menu.h | 1 + 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/debug_menu.cpp b/src/debug_menu.cpp index 688abf7a991c8..a4d1b1d81cadc 100644 --- a/src/debug_menu.cpp +++ b/src/debug_menu.cpp @@ -86,9 +86,13 @@ #include "weather_gen.h" #include "monstergenerator.h" #include "cata_string_consts.h" +#include "mapgendata.h" class vehicle; +extern std::map>> +nested_mapgen; + #if defined(TILES) #include "sdl_wrappers.h" #endif @@ -151,7 +155,8 @@ enum debug_menu_index { DEBUG_DISPLAY_RADIATION, DEBUG_LEARN_SPELLS, DEBUG_LEVEL_SPELLS, - DEBUG_TEST_MAP_EXTRA_DISTRIBUTION + DEBUG_TEST_MAP_EXTRA_DISTRIBUTION, + DEBUG_NESTED_MAPGEN }; class mission_debug @@ -267,6 +272,7 @@ static int map_uilist() { uilist_entry( DEBUG_CHANGE_TIME, true, 't', _( "Change time" ) ) }, { uilist_entry( DEBUG_OM_EDITOR, true, 'O', _( "Overmap editor" ) ) }, { uilist_entry( DEBUG_MAP_EXTRA, true, 'm', _( "Spawn map extra" ) ) }, + { uilist_entry( DEBUG_NESTED_MAPGEN, true, 'n', _( "Spawn nested mapgen" ) ) }, }; return uilist( _( "Map…" ), uilist_initializer ); @@ -375,6 +381,39 @@ void teleport_overmap() add_msg( _( "You teleport to overmap (%d,%d,%d)." ), new_pos.x, new_pos.y, new_pos.z ); } +void spawn_nested_mapgen() +{ + uilist nest_menu; + std::vector nest_str; + for( auto &nested : nested_mapgen ) { + nest_menu.addentry( -1, true, -1, nested.first ); + nest_str.push_back( nested.first ); + } + nest_menu.query(); + const int nest_choice = nest_menu.ret; + if( nest_choice >= 0 && nest_choice < static_cast( nest_str.size() ) ) { + const cata::optional where = g->look_around(); + if( !where ) { + return; + } + + const tripoint abs_ms = g->m.getabs( *where ); + const tripoint abs_omt = ms_to_omt_copy( abs_ms ); + const tripoint abs_sub = ms_to_sm_copy( abs_ms ); + + map target_map; + target_map.load( abs_sub, true ); + const tripoint local_ms = target_map.getlocal( abs_ms ); + mapgendata md( abs_omt, target_map, 0.0f, calendar::turn, nullptr ); + const auto &ptr = random_entry_ref( nested_mapgen[nest_str[nest_choice]] ); + ptr->nest( md, local_ms.xy() ); + target_map.save(); + g->load_npcs(); + g->m.invalidate_map_cache( g->get_levz() ); + g->refresh_all(); + } +} + void character_edit_menu() { std::vector< tripoint > locations; @@ -1553,6 +1592,9 @@ void debug() } break; } + case DEBUG_NESTED_MAPGEN: + debug_menu::spawn_nested_mapgen(); + break; case DEBUG_DISPLAY_NPC_PATH: g->debug_pathfinding = !g->debug_pathfinding; break; diff --git a/src/debug_menu.h b/src/debug_menu.h index afedbe198f289..6b0c3158d4a97 100644 --- a/src/debug_menu.h +++ b/src/debug_menu.h @@ -19,6 +19,7 @@ void teleport_short(); void teleport_long(); void teleport_overmap(); +void spawn_nested_mapgen(); void character_edit_menu(); void wishitem( player *p = nullptr, int x = -1, int y = -1, int z = -1 ); void wishmonster( const cata::optional &p );