Skip to content

Commit

Permalink
fix(port): make shock absorbers actually absorb shock damage (#4321)
Browse files Browse the repository at this point in the history
vehicles: make shock absorbers actually absorb shock damage

Add the SHOCK_ABSORBER flag to shock absorbers, and change
vehicle::damage_all() so that parts on the same tile as a
shock absorber take substantially less damage from transmitted
shock damage in collisions.

Co-authored-by: Mark Langsdorf <mark.langsdorf@gmail.com>
  • Loading branch information
LordZanos and mlangsdorf authored Mar 9, 2024
1 parent 92d50db commit a0a694d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
5 changes: 3 additions & 2 deletions data/json/vehicleparts/armor.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@
"color": "dark_gray",
"broken_color": "dark_gray",
"durability": 340,
"bonus": 50,
"description": "A system of springs and pads, intended to cushion the effects of collisions on the interior of your vehicle.",
"breaks_into": [ { "item": "scrap", "count": [ 1, 5 ] }, { "item": "spring", "count": [ 0, 4 ] } ],
"requirements": {
"install": { "skills": [ [ "mechanics", 4 ] ], "time": "60 m", "using": [ [ "welding_standard", 5 ] ] },
"removal": { "skills": [ [ "mechanics", 2 ] ], "time": "30 m", "using": [ [ "vehicle_weld_removal", 1 ] ] },
"repair": { "skills": [ [ "mechanics", 5 ] ], "time": "60 m", "using": [ [ "welding_standard", 5 ] ] }
},
"flags": [ "ARMOR" ],
"damage_reduction": { "all": 15, "bash": 100 }
"flags": [ "SHOCK_ABSORBER" ],
"damage_reduction": { "all": 25 }
}
]
8 changes: 7 additions & 1 deletion data/json/vehicleparts/vp_flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"id": "ARMOR",
"type": "json_flag",
"context": [ "vehicle_part" ],
"info": "Armor plate. Will partially protect other components on the same frame from damage."
"info": "Armor plate. Will partially protect other components on the same frame from damage from direct attacks but not from the shock damage of a distant collision."
},
{
"id": "BED",
Expand Down Expand Up @@ -133,6 +133,12 @@
"info": "This part will help prevent you from being thrown from the vehicle in a collision. You will automatically enable this part when you move into a tile with it.",
"requires_flag": "BELTABLE"
},
{
"id": "SHOCK_ABSORBER",
"type": "json_flag",
"context": [ "vehicle_part" ],
"info": "Armor plate. Will partially protect other components on the same frame from the shock damage of a distant collision but not from direct attacks."
},
{
"id": "STABLE",
"type": "json_flag",
Expand Down
13 changes: 10 additions & 3 deletions src/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6613,9 +6613,16 @@ void vehicle::damage_all( int dmg1, int dmg2, damage_type type, point impact )
for( const vpart_reference &vp : get_all_parts() ) {
const size_t p = vp.part_index();
int distance = 1 + square_dist( vp.mount(), impact );
if( distance > 1 && part_info( p ).location == part_location_structure &&
!part_info( p ).has_flag( "PROTRUSION" ) ) {
damage_direct( p, rng( dmg1, dmg2 ) / ( distance * distance ), type );
if( distance > 1 ) {
int net_dmg = rng( dmg1, dmg2 ) / ( distance * distance );
if( part_info( p ).location != part_location_structure ||
!part_info( p ).has_flag( "PROTRUSION" ) ) {
int shock_absorber = part_with_feature( p, "SHOCK_ABSORBER", true );
if( shock_absorber >= 0 ) {
net_dmg = std::max( 0, net_dmg - parts[ shock_absorber ].info().bonus );
}
}
damage_direct( p, net_dmg, type );
}
}
}
Expand Down

0 comments on commit a0a694d

Please sign in to comment.