Skip to content

Commit

Permalink
Merge pull request #78994 from mqrause/split_test_fix
Browse files Browse the repository at this point in the history
Fix vehicle_split_section test by only destroying the vehicle and not the terrain
  • Loading branch information
Maleclypse authored Jan 8, 2025
2 parents 53638c9 + f440bb7 commit bf978d6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4627,6 +4627,24 @@ void map::destroy_furn( const tripoint_bub_ms &p, const bool silent )
}
}

void map::destroy_vehicle( const tripoint_bub_ms &p, const bool silent )
{
if( !veh_at( p ) ) {
return;
}

// Break if it takes more than 25 destructions to remove to prevent infinite loops
// Example: A bashes to B, B bashes to A leads to A->B->A->...
int count = 0;
bash_params bsh{
999, silent, true, false, static_cast<float>( rng_float( 0, 1.0f ) ), false, false, false, false
};
while( count <= 25 && veh_at( p ) ) {
bash_vehicle( p, bsh );
count++;
}
}

void map::batter( const tripoint_bub_ms &p, int power, int tries, const bool silent )
{
int count = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,8 @@ class map
void destroy( const tripoint_bub_ms &p, bool silent = false );
/** Keeps bashing a square until there is no more furniture */
void destroy_furn( const tripoint_bub_ms &, bool silent = false );
/** Keeps bashing a square until there is no more vehicle part */
void destroy_vehicle( const tripoint_bub_ms &, bool silent = false );
void crush( const tripoint_bub_ms &p );
void shoot( const tripoint_bub_ms &p, projectile &proj, bool hit_items );
/** Checks if a square should collapse, returns the X for the one_in(X) collapse chance */
Expand Down
4 changes: 2 additions & 2 deletions tests/vehicle_split_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ TEST_CASE( "vehicle_split_section", "[vehicle]" )
REQUIRE( veh_ptr != nullptr );
std::set<tripoint_bub_ms> original_points = veh_ptr->get_points( true );

here.destroy( vehicle_origin );
here.destroy_vehicle( vehicle_origin );
veh_ptr->part_removal_cleanup();
REQUIRE( veh_ptr->get_parts_at( vehicle_origin, "", part_status_flag::available ).empty() );
vehs = here.get_vehicles();
Expand Down Expand Up @@ -73,7 +73,7 @@ TEST_CASE( "vehicle_split_section", "[vehicle]" )
vehicle_origin = { 20, 20, 0 };
veh_ptr = here.add_vehicle( vehicle_prototype_circle_split_test, vehicle_origin, dir, 0, 0 );
REQUIRE( veh_ptr != nullptr );
here.destroy( vehicle_origin );
here.destroy_vehicle( vehicle_origin );
veh_ptr->part_removal_cleanup();
REQUIRE( veh_ptr->get_parts_at( vehicle_origin, "", part_status_flag::available ).empty() );
vehs = here.get_vehicles();
Expand Down

0 comments on commit bf978d6

Please sign in to comment.