From 47faee4dbe458b4a636c7620b5e62fa4612c63b6 Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Tue, 24 Dec 2024 18:59:20 +0000 Subject: [PATCH] Fix "remove_vehicles" when used without or with empty "vehicles" (#78724) * Fix "remove_vehicles" when used without or with empty "vehicles" * Add usage to mx_laststand --- src/mapgen.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/mapgen.cpp b/src/mapgen.cpp index f537e56db7581..3f269980bd609 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() ); } } }