From 937e3c548f7edc796ae814aab4d8eed78ed8a4d6 Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Wed, 10 Apr 2024 15:38:22 +0100 Subject: [PATCH 1/4] Fix "remove_vehicles" when used without or with empty "vehicles" --- src/mapgen.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/mapgen.cpp b/src/mapgen.cpp index d3ce5ca0ada1a..a27dbfb4e8d0a 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -3524,8 +3524,8 @@ class jmapgen_remove_vehicles : public jmapgen_piece public: std::vector vehicles_to_remove; jmapgen_remove_vehicles( const JsonObject &jo, const std::string_view/*context*/ ) { - for( std::string item_id : jo.get_string_array( "vehicles" ) ) { - vehicles_to_remove.emplace_back( item_id ); + for( std::string vehicle_prototype_id : jo.get_string_array( "vehicles" ) ) { + vehicles_to_remove.emplace_back( vehicle_prototype_id ); } } mapgen_phase phase() const override { @@ -3533,18 +3533,17 @@ class jmapgen_remove_vehicles : public jmapgen_piece } void apply( const mapgendata &dat, const jmapgen_int &x, const jmapgen_int &y, const jmapgen_int &z, const std::string &/*context*/ ) const override { - const tripoint_bub_ms start( int( x.val ), int( y.val ), dat.zlevel() + z.get() ); const tripoint_bub_ms end( int( x.valmax ), int( y.valmax ), dat.zlevel() + z.get() ); const tripoint_range range = tripoint_range( start, end ); + auto is_in_vehicles_to_remove = [&]( vproto_id & vproto ) -> bool { + return std::find( vehicles_to_remove.begin(), vehicles_to_remove.end(), vproto ) != vehicles_to_remove.end(); + }; for( const tripoint_bub_ms &p : range ) { - if( optional_vpart_position vp = dat.m.veh_at( p ) ) { - const auto rit = std::find( vehicles_to_remove.begin(), vehicles_to_remove.end(), - vp->vehicle().type ); - if( rit != vehicles_to_remove.end() ) { - get_map().remove_vehicle_from_cache( &vp->vehicle(), start.z(), end.z() ); - dat.m.destroy_vehicle( &vp->vehicle() ); - } + optional_vpart_position vp = dat.m.veh_at( p ); + if( vp && ( vehicles_to_remove.empty() || is_in_vehicles_to_remove( vp->vehicle().type ) ) ) { + get_map().remove_vehicle_from_cache( &vp->vehicle(), start.z(), end.z() ); + dat.m.destroy_vehicle( &vp->vehicle() ); } } } From b2b3e76f36ef6572c902dc627647737fb3c39fbf Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Sun, 22 Dec 2024 14:51:08 +0000 Subject: [PATCH 2/4] Remove Chesterton's fence --- src/mapgen.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/mapgen.cpp b/src/mapgen.cpp index a27dbfb4e8d0a..fd90079fa2197 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -5304,12 +5304,6 @@ static ret_val apply_mapgen_in_phases( const jmapgen_objects &objects, const tripoint_rel_ms &offset, const std::string &context, bool verify = false ) { - const ret_val has_vehicle_collision = objects.has_vehicle_collision( md, offset ); - if( verify && !has_vehicle_collision.success() ) { - - return has_vehicle_collision; - } - // We must apply all the mapgen in phases, but the mapgen is split between // setmap_points and objects. So we have to make an outer loop over // phases, and apply each type restricted to each phase. From 078acbf73cf5d7ddc59fe4bc07ee2c47316d9d71 Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Sun, 22 Dec 2024 14:51:32 +0000 Subject: [PATCH 3/4] Add usage to mx_laststand --- data/json/mapgen/map_extras/laststand.json | 1 + 1 file changed, 1 insertion(+) diff --git a/data/json/mapgen/map_extras/laststand.json b/data/json/mapgen/map_extras/laststand.json index b31f9ff584701..1d93a876b03a3 100644 --- a/data/json/mapgen/map_extras/laststand.json +++ b/data/json/mapgen/map_extras/laststand.json @@ -68,6 +68,7 @@ [ "f_null", 150 ] ] }, + "remove_vehicles": [ { "x": [ 0, 23 ], "y": [ 0, 23 ] } ], "place_monster": [ { "group": "GROUP_LAST_STAND", "x": [ 6, 17 ], "y": [ 6, 16 ], "chance": 100, "repeat": [ 10, 15 ] } ], "place_loot": [ { "group": "trash", "x": [ 6, 17 ], "y": [ 6, 16 ], "repeat": [ 5, 10 ] } ], "flags": [ "ERASE_ALL_BEFORE_PLACING_TERRAIN" ] From d40dd5373f3098299d5f58b9ff0b156ad97a5f59 Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Sun, 22 Dec 2024 15:42:23 +0000 Subject: [PATCH 4/4] Reinstate Chesterton's fence now I get what it's doing --- data/json/mapgen/map_extras/laststand.json | 1 - src/mapgen.cpp | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/data/json/mapgen/map_extras/laststand.json b/data/json/mapgen/map_extras/laststand.json index 1d93a876b03a3..b31f9ff584701 100644 --- a/data/json/mapgen/map_extras/laststand.json +++ b/data/json/mapgen/map_extras/laststand.json @@ -68,7 +68,6 @@ [ "f_null", 150 ] ] }, - "remove_vehicles": [ { "x": [ 0, 23 ], "y": [ 0, 23 ] } ], "place_monster": [ { "group": "GROUP_LAST_STAND", "x": [ 6, 17 ], "y": [ 6, 16 ], "chance": 100, "repeat": [ 10, 15 ] } ], "place_loot": [ { "group": "trash", "x": [ 6, 17 ], "y": [ 6, 16 ], "repeat": [ 5, 10 ] } ], "flags": [ "ERASE_ALL_BEFORE_PLACING_TERRAIN" ] diff --git a/src/mapgen.cpp b/src/mapgen.cpp index fd90079fa2197..a27dbfb4e8d0a 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -5304,6 +5304,12 @@ static ret_val apply_mapgen_in_phases( const jmapgen_objects &objects, const tripoint_rel_ms &offset, const std::string &context, bool verify = false ) { + const ret_val has_vehicle_collision = objects.has_vehicle_collision( md, offset ); + if( verify && !has_vehicle_collision.success() ) { + + return has_vehicle_collision; + } + // We must apply all the mapgen in phases, but the mapgen is split between // setmap_points and objects. So we have to make an outer loop over // phases, and apply each type restricted to each phase.