Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix vehicle_split_section test by only destroying the vehicle and not the terrain #78994

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1326,6 +1326,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
Loading