From 54db27de0ef43fdc66a5692921295b5527d4198f Mon Sep 17 00:00:00 2001 From: Mark Langsdorf Date: Sat, 20 Apr 2019 11:44:17 -0500 Subject: [PATCH] mapgen: make add_mapgen_update_func work with mapgen_update_ids if the Json object has a mapgen_update_id string, use that instead of parsing inline mapgen_update. --- doc/MISSIONS_JSON.md | 2 +- src/mapgen.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/doc/MISSIONS_JSON.md b/doc/MISSIONS_JSON.md index eeb3eda37c43c..6cc5194d1cb39 100644 --- a/doc/MISSIONS_JSON.md +++ b/doc/MISSIONS_JSON.md @@ -160,7 +160,7 @@ The `update_mapgen`` object or array provides a way to modify existing overmap t As an array, `update_mapgen` consists of two or more `update_mapgen` objects. -As an object, `update_mapgen` contains any valid JSON mapgen objects. The objects are placed on the mission target terrain from "assign_mission_target" or optionally the closest overmap terrain specified by the `om_terrain` and `om_special` fields. +As an object, `update_mapgen` contains any valid JSON mapgen objects. The objects are placed on the mission target terrain from "assign_mission_target" or optionally the closest overmap terrain specified by the `om_terrain` and `om_special` fields. If "mapgen_update_id" is specified, the "mapge_update" object with the matching "mapgen_update_id" will be executed. See doc/MAPGEN.md for more details on JSON mapgen and `update_mapgen`. diff --git a/src/mapgen.cpp b/src/mapgen.cpp index b1feadeb7c8c2..5721faebf95be 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -8669,6 +8669,15 @@ bool update_mapgen_function_json::update_map( const tripoint &omt_pos, int offse mapgen_update_func add_mapgen_update_func( JsonObject &jo, bool &defer ) { + if( jo.has_string( "mapgen_update_id" ) ) { + const std::string mapgen_update_id = jo.get_string( "mapgen_update_id" ); + const auto update_function = [mapgen_update_id]( const tripoint & omt_pos, + mission * miss ) { + run_mapgen_update_func( mapgen_update_id, omt_pos, miss, false ); + }; + return update_function; + } + update_mapgen_function_json json_data( "" ); mapgen_defer::defer = defer; if( !json_data.setup_update( jo ) ) {