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

Medical - Add damage handling for explosive damage while inside vehicles #9246

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
816d534
Add vehicle explosion handling
pterolatypus Feb 20, 2022
93bb7cd
Missing semicolon
pterolatypus Jun 10, 2022
75f1cec
scale armor damage using passthrough
LinkIsGrim Jun 13, 2023
386eda6
add - to comment
LinkIsGrim Jun 14, 2023
510e6aa
improve condition
LinkIsGrim Jun 14, 2023
f290e28
remove extra brackets
LinkIsGrim Jun 14, 2023
9ad380d
remove extra brackets
LinkIsGrim Jun 14, 2023
0c82347
fix damage sorting
LinkIsGrim Jun 14, 2023
27ef26f
whitespace
LinkIsGrim Jun 14, 2023
0098ecb
comment
LinkIsGrim Jun 14, 2023
92d636d
fix function header
LinkIsGrim Jun 14, 2023
cdf6520
fix infinite armor when no item equipped
LinkIsGrim Jun 14, 2023
61b0510
Merge remote-tracking branch 'upstream' into feature/vehicleExplosion
LinkIsGrim Jun 24, 2023
f925f0d
modify condition & handling for vehicle explosion
LinkIsGrim Jun 24, 2023
4464062
Merge remote-tracking branch 'upstream' into feature/vehicleExplosion…
LinkIsGrim Jun 27, 2023
454633f
add vehiclehit woundHandler
LinkIsGrim Jun 27, 2023
182f946
finalize
LinkIsGrim Jun 27, 2023
109ec33
add vehiclehit woundHandler
LinkIsGrim Jun 27, 2023
7ba4a64
finalize
LinkIsGrim Jun 27, 2023
af8359b
Merge branch 'feature/vehicleExplosion-grimpatch' of https://github.c…
LinkIsGrim Jun 27, 2023
34a4b24
cleanup
LinkIsGrim Jun 28, 2023
2b32870
more cleanup
LinkIsGrim Jun 28, 2023
aafef61
name
LinkIsGrim Jul 6, 2023
c46f811
Merge remote-tracking branch 'upstream' into feature/vehicleExplosion…
LinkIsGrim Jul 9, 2023
f93c4b3
randomize hitpoints
LinkIsGrim Jul 9, 2023
d13d315
Merge branch 'scale-armor-damage' of https://github.com/Salluci/ACE3 …
LinkIsGrim Jul 9, 2023
e608f94
finalize
LinkIsGrim Jul 9, 2023
260e1c3
don't scale structural damage
LinkIsGrim Jul 9, 2023
99abcbd
Merge branch 'scale-armor-damage' of https://github.com/Salluci/ACE3 …
LinkIsGrim Jul 9, 2023
69c01bd
fix undefined var
LinkIsGrim Aug 31, 2023
8954f08
Merge remote-tracking branch 'upstream/master' into feature/vehicleEx…
LinkIsGrim Aug 31, 2023
1f07466
remove _i
LinkIsGrim Aug 31, 2023
869f340
Merge remote-tracking branch 'upstream/master' into feature/vehicleEx…
LinkIsGrim Sep 6, 2023
f4c2925
fix script error, tone down scaling
LinkIsGrim Sep 6, 2023
73cc01b
add AVD checks
LinkIsGrim Sep 6, 2023
714ccc1
Merge remote-tracking branch 'upstream/master' into feature/vehicleEx…
LinkIsGrim Sep 23, 2023
d89d7d1
Update addons/medical_damage/functions/fnc_woundsHandlerVehiclehit.sqf
LinkIsGrim Sep 23, 2023
7cf5451
nuke AVD crew damage handling
LinkIsGrim Sep 23, 2023
661768b
get rid of aircraft crash lethality compensation
LinkIsGrim Sep 23, 2023
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
7 changes: 7 additions & 0 deletions addons/medical_damage/ACE_Medical_Injuries.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ class ACE_Medical_Injuries {
painMultiplier = 0.9;
};
};
class vehiclehit: explosive {
// vehicle explosions are usually caused by explosive damage and should behave similarly
thresholds[] = {{6, 3}, {4.5, 2}, {2, 2}, {0.8, 1}, {0.2, 1}, {0, 0}};
class woundHandlers: woundHandlers {
GVAR(vehiclehit) = QFUNC(woundsHandlerVehiclehit);
};
};
class vehiclecrash {
thresholds[] = {{1.5, 3}, {1.5, 2}, {1, 2}, {1, 1}, {0.05, 1}}; // prevent subdividing wounds past FRACTURE_DAMAGE_THRESHOLD to ensure limp/fractue is triggered
selectionSpecific = 0;
Expand Down
1 change: 1 addition & 0 deletions addons/medical_damage/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ PREP(woundReceived);
PREP(woundsHandlerBase);
PREP(woundsHandlerBurning);
PREP(woundsHandlerVehiclecrash);
PREP(woundsHandlerVehiclehit);
37 changes: 37 additions & 0 deletions addons/medical_damage/functions/fnc_woundsHandlerVehiclehit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "..\script_component.hpp"
/*
* Author: Pterolatypus, LinkIsGrim
* Custom wound handler for vehicle hits and explosions, sends damage to a random hitpoint
*
* Arguments:
* 0: Unit That Was Hit <OBJECT>
* 1: Damage done to each body part <ARRAY>
* 2: Type of the damage done <STRING>
*
* Return Value:
* None
*
* Example:
* [player, [[0.5, "#structural", 1.5]], "vehiclehit"] call ace_medical_damage_fnc_woundsHandlerVehiclehit
*
* Public: No
*/
params ["_unit", "_allDamages", "_typeOfDamage"];
TRACE_3("woundsHandlerVehiclehit",_unit,_allDamages,_typeOfDamage);

// this should only trigger for hits to just structural
if (count _allDamages > 1) exitWith {_this};

// damage can sometimes be negative (why?)
// damage to structural is low unless it's a very large explosion, in which case it is typically >= 1
private _damageToApply = (abs (_allDamages select 0 select 0));

private _newDamages = [];

// hitpoints are randomized, more damage means more wounds in different body parts
for "_i" from 1 to (_damageToApply * 6) do {
_newDamages pushBack [_damageToApply, selectRandom ALL_BODY_PARTS, _damageToApply]
};

TRACE_1("Vehicle explosion handled, passing damage", _newDamages);
[_unit, _newDamages, _typeOfDamage] //return
14 changes: 0 additions & 14 deletions addons/medical_engine/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,6 @@
};
}] call CBA_fnc_addClassEventHandler;

// Guarantee aircraft crashes are more lethal
["Air", "Killed", {
params ["_vehicle", "_killer"];
TRACE_3("air killed",_vehicle,typeOf _vehicle,velocity _vehicle);
if ((getText (configOf _vehicle >> "destrType")) == "") exitWith {};
if (unitIsUAV _vehicle) exitWith {};

private _lethality = linearConversion [0, 25, (vectorMagnitude velocity _vehicle), 0.5, 1];
TRACE_2("air crash",_lethality,crew _vehicle);
{
[QEGVAR(medical,woundReceived), [_x, [[_lethality, "Head", _lethality]], _killer, "#vehiclecrash"], _x] call CBA_fnc_targetEvent;
} forEach (crew _vehicle);
}, true, ["ParachuteBase"]] call CBA_fnc_addClassEventHandler;

// Fixes units being stuck in unconscious animation when being knocked over by a PhysX object
["CAManBase", "AnimDone", {
params ["_unit", "_anim"];
Expand Down
29 changes: 27 additions & 2 deletions addons/medical_engine/functions/fnc_handleDamage.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,16 @@ if (
0
};

// Faster than (vehicle _unit), also handles dead units
private _vehicle = objectParent _unit;

// Crashing a vehicle doesn't fire the EH for each hitpoint so the "ace_hdbracket" code never runs
// It does fire the EH multiple times, but this seems to scale with the intensity of the crash
private _vehicle = vehicle _unit;
if (
EGVAR(medical,enableVehicleCrashes) &&
{_hitPoint isEqualTo "#structural"} &&
{_ammo isEqualTo ""} &&
{_vehicle != _unit} &&
{!isNull _vehicle} &&
{vectorMagnitude (velocity _vehicle) > 5}
LinkIsGrim marked this conversation as resolved.
Show resolved Hide resolved
// todo: no way to detect if stationary and another vehicle hits you
) exitWith {
Expand All @@ -74,6 +76,29 @@ if (
0
};

// Receiving explosive damage inside a vehicle doesn't trigger for each hitpoint
// This is the case for mines, explosives, artillery, and catasthrophic vehicle explosions
// Triggers twice, but that doesn't matter as damage is low
if (
_hitPoint isEqualTo "#structural" &&
{!isNull _vehicle} &&
{_ammo isNotEqualTo ""} &&
{
private _ammoCfg = configFile >> "CfgAmmo" >> _ammo;
GET_NUMBER(_ammoCfg >> "explosive", 0) > 0 ||
{GET_NUMBER(_ammoCfg >> "indirectHit", 0) > 0}
}
) exitwith {
TRACE_6("Vehicle hit",_unit,_shooter,_instigator,_damage,_newDamage,_damages);

_unit setVariable [QEGVAR(medical,lastDamageSource), _shooter];
_unit setVariable [QEGVAR(medical,lastInstigator), _instigator];

[QEGVAR(medical,woundReceived), [_unit, [[_newDamage, _hitPoint, _newDamage]], _shooter, "vehiclehit"]] call CBA_fnc_localEvent;

0
};

// This hitpoint is set to trigger last, evaluate all the stored damage values
// to determine where wounds are applied
if (_hitPoint isEqualTo "ace_hdbracket") exitWith {
Expand Down
1 change: 0 additions & 1 deletion addons/vehicle_damage/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ PREP(handleVehicleDamage);
PREP(handleCookoff);
PREP(detonate);
PREP(processHit);
PREP(injureOccupants);
PREP(handleDetonation);
PREP(handleDamage);
PREP(knockOut);
Expand Down
76 changes: 0 additions & 76 deletions addons/vehicle_damage/functions/fnc_injureOccupants.sqf

This file was deleted.

27 changes: 0 additions & 27 deletions addons/vehicle_damage/functions/fnc_processHit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -119,28 +119,6 @@ if (_isCar) then {
_ammoEffectiveness = (_ammoEffectiveness + (_ammoEffectiveness * 0.5)) min 1;
};

private _injuryChance = 0;
private _injuryCount = 0;
switch (_warheadType) do {
case WARHEAD_TYPE_AP: {
_injuryChance = (_ammoEffectiveness * 2) min 1;
_injuryCount = 1 + (_ammoEffectiveness * round random 9);
};
case WARHEAD_TYPE_HE: {
_injuryChance = 0.03 * (1 + _ammoEffectiveness); // spalling injury chance alongside direct hit potential
_injuryCount = 2 + (ceil random 3);
if (_isCar) then {
_injuryChance = 0.8;
_injuryCount = 3 max random count crew _vehicle;
};
};
default {
_injuryChance = (4 * _ammoEffectiveness) min 1;
_injuryCount = 2 + round random 3;
};
};
_injuryChance = _injuryChance * _penChance;

private _currentVehicleAmmo = [_vehicle] call EFUNC(cookoff,getVehicleAmmo);
private _chanceOfDetonation = 0;
private _explosiveAmmoCount = 0;
Expand Down Expand Up @@ -200,8 +178,6 @@ switch (_hitArea) do {
[_vehicle, _hitIndex, _hitpointName, _nextPartDamage * _penChance] call FUNC(addDamage);
};

// slightly lower injury chance since this hit the engine block
[_vehicle, _injuryChance, _injuryCount, _injurer, [0.2, 0.2, 0.2, 0.4]] call FUNC(injureOccupants);
[_vehicle, _chanceOfFire, _cookoffIntensity, _injurer, _hitArea, false] call FUNC(handleCookoff);
};
case "hull": {
Expand All @@ -220,8 +196,6 @@ switch (_hitArea) do {
[_vehicle] call FUNC(knockOut);
};

[_vehicle, _injuryChance, _injuryCount, _injurer, [1, 0.4, 0.4, 1]] call FUNC(injureOccupants);

private _hash = _vehicle getVariable [QGVAR(hitpointHash), []];
private _hashKeys = [_hash] call CBA_fnc_hashKeys;

Expand Down Expand Up @@ -301,7 +275,6 @@ switch (_hitArea) do {
_vehicle setVariable [QGVAR(canShoot), false];
};

[_vehicle, _injuryChance, _injuryCount, _injurer, [0.5, 1.5, 1.5, 0.8]] call FUNC(injureOccupants);
[_vehicle, _chanceOfFire, _cookoffIntensity, _injurer, "", true] call FUNC(handleCookoff);
};
case "gun": {
Expand Down