ACE3/addons/vehicle_damage/functions/fnc_handleVehicleDamage.sqf
johnb432 80b2fa9a05
Vehicle damage - Code cleanup (#9831)
* Cook-off improvements

* More changes

* Update fnc_getVehicleAmmo.sqf

* Better engine fire placement

* Update fnc_detonateAmmunition.sqf

* Update XEH_postInit.sqf

* Update fnc_getVehicleAmmo.sqf

* Update events-framework.md

* Various improvements

* Separate effect handling

* Tweaks

* Update XEH_postInit.sqf

* Prevent double ammo detonation

* Fixed objects not being able to cook-off again

* Added incendiary rounds as source of box cookoff

* Converted enable setting to bool

* Fixed brackets

* Update fnc_cookOff.sqf

* Update CfgEden.hpp

* Removed GVAR(enable), added GVAR(enableFire) back

* Vehicle damage fixes

* Made hitpoint hash common

* Update fnc_addEventHandler.sqf

* Update fnc_medicalDamage.sqf

* Update fnc_handleBail.sqf

* Changed API

* Remove `CBA_fnc_getConfigEntry` as much as possible, as it's 2x slower

* More cleanup

* More cleanup

* Fix merging issues, remove turret tossing

* Update translations

* More cleanup

* Reverted some logic back to original, minor tweaks & fixes

* Fix undefined variable

* Cleanup

* Fixed bad logic

* Update addons/vehicle_damage/script_macros.hpp

Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com>

* Update addons/vehicle_damage/functions/fnc_handleDamage.sqf

* Update addons/vehicle_damage/stringtable.xml

Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com>

* Update addons/vehicle_damage/stringtable.xml

Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com>

* Update addons/vehicle_damage/XEH_postInit.sqf

Co-authored-by: PabstMirror <pabstmirror@gmail.com>

---------

Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com>
Co-authored-by: PabstMirror <pabstmirror@gmail.com>
2024-08-20 16:23:21 -03:00

105 lines
3.2 KiB
Plaintext

#include "..\script_component.hpp"
/*
* Author: tcvm
* Process vehicle hit.
*
* Arguments:
* 0: Vehicle <OBJECT>
* 1: Hit point <STRING>
* 2: Hit index <NUMBER>
* 3: Selection <STIRNG>
* 4: Added damage to part <NUMBER>
* 5: Projectile <OBJECT>
* 6: Source of damage <OBJECT>
* 7: Person who caused damage <OBJECT>
*
* Return Value:
* Whether or not to continue handling last frame's damage <BOOL>
*
* Example:
* [ace_vehicle_damage_fnc_handleVehicleDamage, [cursorObject, "HitEngine", 12, "hit_engine_point", 0.25, projectile, player, player]] call CBA_fnc_execNextFrame
*
* Public: No
*/
params ["_vehicle", "_hitPoint", "_hitIndex", "_selection", "_addedDamage", "_projectile", "_source", "_instigator"];
TRACE_8("handleVehicleDamage",_vehicle,_hitPoint,_hitIndex,_selection,_addedDamage,_projectile,_source,_instigator);
if (!alive _vehicle) exitWith {
private _handleDamageEH = _vehicle getVariable [QGVAR(handleDamage), nil];
if (!isNil "_handleDamageEH") then {
_vehicle removeEventHandler ["HandleDamage", _handleDamageEH];
};
TRACE_1("vehicle no longer alive",_vehicle);
false
};
_hitPoint = toLowerANSI _hitPoint;
private _hitPointHash = GVAR(vehicleClassesHitPointHash) getOrDefault [typeOf _vehicle, createHashMap];
private _type = (_hitPointHash getOrDefault [_hitPoint, []]) select 0;
// Generic structural damage will be transfered into hull damage for simulation's sake
private _structural = false;
if (_selection == "") then {
_type = "hull";
_hitPoint = "hithull";
_structural = true;
TRACE_1("structural damage",_selection);
_addedDamage = abs _addedDamage;
};
if (isNil "_type") exitWith {
TRACE_1("no relevant hitpoints hit, exiting",_hitPoint);
true
};
// Ignore multiple hits at the same time
private _ignoreHit = false;
private _ignoreBailCheck = false;
private _multHit = _vehicle getVariable [QGVAR(hitTime), nil];
if (isNil "_multHit") then {
_vehicle setVariable [QGVAR(hitTime), [CBA_missionTime, _source, [_hitPoint]]];
} else {
private _hitPointInOldArray = _hitPoint in (_multHit select 2);
private _withinTime = (CBA_missionTime <= (_multHit select 0) + CONST_TIME) && {_source == (_multHit select 1)};
if (_hitPointInOldArray && _withinTime) then {
_ignoreHit = true;
} else {
// If the hitpoint isnt in the old array then that means that the time expired and a new array should be generated
if (!_hitPointInOldArray) then {
private _oldHitPoints = _multHit select 2;
_oldHitPoints pushBack _hitPoint;
_vehicle setVariable [QGVAR(hitTime), [CBA_missionTime, _source, _oldHitPoints]];
_ignoreBailCheck = true;
} else {
_vehicle setVariable [QGVAR(hitTime), [CBA_missionTime, _source, [_hitPoint]]];
};
};
};
if (_ignoreHit && !_structural) exitWith {
TRACE_3("ignoring multiple hits done to vehicle",_vehicle,_source,_hitPoint);
true
};
TRACE_3("processing hit done to vehicle",_vehicle,_source,CBA_missionTime);
if !([_vehicle, _hitPoint, _hitIndex, _addedDamage, _projectile, _source, _instigator] call FUNC(processHit)) exitWith {false};
if (!_ignoreBailCheck) then {
_vehicle call FUNC(handleBail);
};
true