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(port): make shock absorbers actually absorb shock damage #4321

Merged
merged 1 commit into from
Mar 9, 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
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
Loading