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

feat(balance): increase variety of potential damage states for spawned vehicles #4746

Merged
merged 3 commits into from
Jun 6, 2024
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
29 changes: 22 additions & 7 deletions src/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,11 +620,15 @@ void vehicle::init_state( int init_veh_fuel, int init_veh_status )
}

for( const vpart_reference &vp : get_parts_including_carried( "FRIDGE" ) ) {
vp.part().enabled = true;
if( one_in( 2 ) ) {
vp.part().enabled = true;
}
}

for( const vpart_reference &vp : get_parts_including_carried( "FREEZER" ) ) {
vp.part().enabled = true;
if( one_in( 2 ) ) {
vp.part().enabled = true;
}
}

for( const vpart_reference &vp : get_parts_including_carried( "WATER_PURIFIER" ) ) {
Expand All @@ -637,8 +641,8 @@ void vehicle::init_state( int init_veh_fuel, int init_veh_status )
const size_t p = vp.part_index();
vehicle_part &pt = vp.part();

if( vp.has_feature( VPFLAG_REACTOR ) ) {
// De-hardcoded reactors. Should always start active
if( vp.has_feature( VPFLAG_REACTOR ) && one_in( 4 ) ) {
// De-hardcoded reactors, may or may not start active
pt.enabled = true;
}

Expand Down Expand Up @@ -733,6 +737,11 @@ void vehicle::init_state( int init_veh_fuel, int init_veh_status )
set_hp( pt, 0 );
}

// An added 5% chance to bust each windshield
if( vp.has_feature( "WINDSHIELD" ) && one_in( 20 ) ) {
set_hp( pt, 0 );
}

/* Bloodsplatter the front-end parts. Assume anything with x > 0 is
* the "front" of the vehicle (since the driver's seat is at (0, 0).
* We'll be generous with the blood, since some may disappear before
Expand Down Expand Up @@ -761,6 +770,11 @@ void vehicle::init_state( int init_veh_fuel, int init_veh_status )
blood_inside_pos.emplace( vp.mount() );
}
}

// Potentially bust a single tire if not already wrecking them
if( !destroyTires && !wheelcache.empty() && one_in( 20 ) ) {
set_hp( parts[random_entry( wheelcache )], 0 );
}
}
//sets the vehicle to locked, if there is no key and an alarm part exists
if( vp.has_feature( "SECURITY" ) && has_no_key && pt.is_available() ) {
Expand All @@ -772,11 +786,12 @@ void vehicle::init_state( int init_veh_fuel, int init_veh_status )
}
}
}
// destroy tires until the vehicle is not drivable
// destroy a random number of tires, vehicles with more wheels are more likely to survive
if( destroyTires && !wheelcache.empty() ) {
int tries = 0;
while( valid_wheel_config() && tries < 100 ) {
// wheel config is still valid, destroy the tire.
int maxtries = wheelcache.size();
while( valid_wheel_config() && tries < maxtries ) {
// keep going until either we've ruined all wheels or made one attempt for every wheel
set_hp( parts[random_entry( wheelcache )], 0 );
tries++;
}
Expand Down
1 change: 1 addition & 0 deletions tests/vehicle_power_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ TEST_CASE( "vehicle power with reactor and solar panels", "[vehicle][power]" )

REQUIRE( !veh_ptr->reactors.empty() );
vehicle_part &reactor = veh_ptr->part( veh_ptr->reactors.front() );
reactor.enabled = true;

GIVEN( "the reactor is empty" ) {
reactor.ammo_unset();
Expand Down
Loading