Skip to content

Commit

Permalink
Fix "remove_vehicles" when used without or with empty "vehicles" (#78724
Browse files Browse the repository at this point in the history
)

* Fix "remove_vehicles" when used without or with empty "vehicles"
* Add usage to mx_laststand
  • Loading branch information
Procyonae authored Dec 24, 2024
1 parent 44f913f commit 47faee4
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3524,27 +3524,26 @@ class jmapgen_remove_vehicles : public jmapgen_piece
public:
std::vector<vproto_id> 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 {
return mapgen_phase::removal;
}
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<tripoint_bub_ms> range = tripoint_range<tripoint_bub_ms>( 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() );
}
}
}
Expand Down

0 comments on commit 47faee4

Please sign in to comment.