diff --git a/src/map_extras.cpp b/src/map_extras.cpp index bf02a4b81d6e8..3e9080f333793 100644 --- a/src/map_extras.cpp +++ b/src/map_extras.cpp @@ -2740,14 +2740,13 @@ void apply_function( const string_id &id, map &m, const tripoint &abs break; } case map_extra_method::mapgen: { - tripoint over( abs_sub ); - sm_to_omt( over ); - mapgendata dat( over, m, 0.0f, calendar::turn, nullptr ); + mapgendata dat( sm_to_omt_copy( abs_sub ), m, 0.0f, calendar::turn, nullptr ); run_mapgen_func( extra.generator_id, dat ); break; } case map_extra_method::update_mapgen: { - run_mapgen_update_func( extra.generator_id, sm_to_omt_copy( abs_sub ) ); + mapgendata dat( sm_to_omt_copy( abs_sub ), m, 0.0f, calendar::start_of_cataclysm, nullptr ); + run_mapgen_update_func( extra.generator_id, dat ); break; } case map_extra_method::null: diff --git a/src/mapgen.cpp b/src/mapgen.cpp index 8af82206d208c..47ae641a37b4d 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -7752,31 +7752,37 @@ bool update_mapgen_function_json::update_map( const tripoint &omt_pos, const poi mapgendata md( omt_pos, update_tmap, 0.0f, calendar::start_of_cataclysm, miss ); - // If the existing map is rotated, we need to rotate it back to the north - // orientation before applying our updates. - const int rotation = oter_get_rotation( overmap_buffer.ter( omt_pos ) ); - if( rotation > 0 ) { - md.m.rotate( rotation, true ); - } - - const bool applied = update_map( md, offset, verify ); - - // If we rotated the map before applying updates, we now need to rotate - // it back to where we found it. - if( rotation ) { - md.m.rotate( 4 - rotation, true ); - } - - if( applied ) { - md.m.save(); - } - - return applied; + return update_map( md, offset, verify ); } bool update_mapgen_function_json::update_map( mapgendata &md, const point &offset, const bool verify ) const { + class rotation_guard + { + public: + rotation_guard( const mapgendata &md ) + : md( md ), rotation( oter_get_rotation( md.terrain_type() ) ) { + // If the existing map is rotated, we need to rotate it back to the north + // orientation before applying our updates. + if( rotation != 0 ) { + md.m.rotate( rotation, true ); + } + } + + ~rotation_guard() { + // If we rotated the map before applying updates, we now need to rotate + // it back to where we found it. + if( rotation != 0 ) { + md.m.rotate( 4 - rotation, true ); + } + } + private: + const mapgendata &md; + const int rotation; + }; + rotation_guard rot( md ); + for( auto &elem : setmap_points ) { if( verify && elem.has_vehicle_collision( md, offset ) ) { return false; @@ -7831,6 +7837,16 @@ bool run_mapgen_update_func( const std::string &update_mapgen_id, const tripoint return update_function->second[0]->update_map( omt_pos, point_zero, miss, cancel_on_collision ); } +bool run_mapgen_update_func( const std::string &update_mapgen_id, mapgendata &dat, + const bool cancel_on_collision ) +{ + const auto update_function = update_mapgen.find( update_mapgen_id ); + if( update_function == update_mapgen.end() || update_function->second.empty() ) { + return false; + } + return update_function->second[0]->update_map( dat, point_zero, cancel_on_collision ); +} + std::pair, std::map> get_changed_ids_from_update( const std::string &update_mapgen_id ) { diff --git a/src/mapgen_functions.h b/src/mapgen_functions.h index fb2994bac3233..9d23b552bca77 100644 --- a/src/mapgen_functions.h +++ b/src/mapgen_functions.h @@ -86,6 +86,8 @@ void place_stairs( mapgendata &dat ); mapgen_update_func add_mapgen_update_func( const JsonObject &jo, bool &defer ); bool run_mapgen_update_func( const std::string &update_mapgen_id, const tripoint &omt_pos, mission *miss = nullptr, bool cancel_on_collision = true ); +bool run_mapgen_update_func( const std::string &update_mapgen_id, mapgendata &dat, + bool cancel_on_collision = true ); bool run_mapgen_func( const std::string &mapgen_id, mapgendata &dat ); std::pair, std::map> get_changed_ids_from_update( const std::string &update_mapgen_id );