Skip to content

Commit

Permalink
Add debug menu item for spawning nested mapgen
Browse files Browse the repository at this point in the history
  • Loading branch information
ralreegorganon committed Feb 7, 2020
1 parent 40c494c commit 7fe135d
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/debug_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,13 @@
#include "weather_gen.h"
#include "monstergenerator.h"
#include "cata_string_consts.h"
#include "mapgendata.h"

class vehicle;

extern std::map<std::string, std::vector<std::unique_ptr<mapgen_function_json_nested>>>
nested_mapgen;

#if defined(TILES)
#include "sdl_wrappers.h"
#endif
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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<std::string> 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<int>( nest_str.size() ) ) {
const cata::optional<tripoint> 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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 7fe135d

Please sign in to comment.