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

Add debug menu item for spawning nested mapgen #37788

Merged
merged 1 commit into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
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
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
1 change: 1 addition & 0 deletions src/debug_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<tripoint> &p );
Expand Down