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

vehicles: make shock absorbers actually absorb shock damage #43013

Merged
merged 1 commit into from
Aug 19, 2020
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 @@ -139,6 +139,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
1 change: 1 addition & 0 deletions doc/JSON_FLAGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,7 @@ Those flags are added by the game code to specific items (for example, that spec
- ```SEAT``` A seat where the player can sit or sleep.
- ```SECURITY```
- ```SHARP``` Striking a monster with this part does cutting damage instead of bashing damage, and prevents stunning the monster.
- ```SHOCK_ABSORBER``` This part protects non-frame parts on the same tile from shock damage from collisions. It doesn't provide protect against diret impacts or other attacks.
- ```SIMPLE_PART``` This part can be installed or removed from that otherwise prevent modification.
- ```SMASH_REMOVE``` When you remove this part, instead of getting the item back, you will get the bash results.
- ```SOLAR_PANEL``` Recharges vehicle batteries when exposed to sunlight. Has a 1 in 4 chance of being broken on car generation.
Expand Down
13 changes: 10 additions & 3 deletions src/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6359,9 +6359,16 @@ void vehicle::damage_all( int dmg1, int dmg2, damage_type type, const point &imp
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