ACE3/addons/vehicle_damage/functions/fnc_handleDamage.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

92 lines
3.3 KiB
Plaintext

#include "..\script_component.hpp"
/*
* Author: tcvm
* Called by "HandleDamage" event handler. Sets up hit array for this frame's damage.
*
* Arguments:
* 0: Vehicle <OBJECT>
* 1: Selection <STRING>
* 2: New level of damage <NUMBER>
* 3: Source of damage <OBJECT>
* 4: Projectile that caused damage <STRING>
* 5: Hit index <NUMBER>
* 6: Person who caused damage <OBJECT>
* 7: Hit point <STRING>
*
* Return Value:
* Current or maximum damage of part <NUMBER>
*
* Example:
* [cursorObject, "hit_engine_point", 0.5, player, projectile, 1, player, "HitEngine"] call ace_vehicle_damage_fnc_handleDamage
*
* Public: No
*/
params ["_vehicle", "_selection", "_newDamage", "_source", "_projectile", "_hitIndex", "_instigator", "_hitPoint"];
TRACE_8("handleDamage",_vehicle,_selection,_newDamage,_source,_projectile,_hitIndex,_instigator,_hitPoint);
if (!local _vehicle) exitWith {};
private _currentDamage = if (_selection != "") then {
_vehicle getHitIndex _hitIndex
} else {
damage _vehicle
};
if !(_projectile in ["ace_ammoExplosion", "ACE_ammoExplosionLarge"]) then {
// If an invalid hit, don't process it
if (_newDamage <= 0 || {"#light" in _hitPoint}) exitWith {};
// Set up hit array so we can execute all damage next frame. Always in order of hit done.
private _hitHash = _vehicle getVariable QGVAR(hitHash);
private _currentFrameArray = _hitHash getOrDefault [diag_frameNo, [], true];
if (_currentFrameArray isEqualTo []) then {
[{
params ["_vehicle", "_processingFrame"];
private _hitHash = _vehicle getVariable QGVAR(hitHash);
private _hitArray = _hitHash deleteAt _processingFrame;
if (_hitArray isEqualTo []) exitWith {};
TRACE_3("processing data from old frame",diag_frameNo,_processingFrame,_hitArray);
// Start from newest damage and work backwards
{
_x params ["_vehicle", "_selection", "_newDamage", "_source", "_projectile", "_hitIndex", "_instigator", "_hitPoint"];
private _currentDamage = if (_selection != "") then {
_vehicle getHitIndex _hitIndex
} else {
damage _vehicle
};
private _addedDamage = _newDamage - _currentDamage;
TRACE_1("handleDamage",_currentDamage);
if !([_vehicle, _hitPoint, _hitIndex, _selection, _addedDamage, _projectile, _source, _instigator] call FUNC(handleVehicleDamage)) exitWith {
TRACE_2("cancelling rest of vehicle damage queue",(count (_hitArray#1)) - _forEachIndex,count (_hitArray#1))
};
} forEachReversed _hitArray;
}, [_vehicle, diag_frameNo]] call CBA_fnc_execNextFrame;
};
_currentFrameArray pushBack _this;
};
// Damage is never to be handled in-engine. Always handle out of engine with this event handler
// Don't return 0 or else old parts will be reset in damage
private _criticalDamageIndex = CRITICAL_HITPOINTS findIf {_x == _hitPoint};
if (_criticalDamageIndex != -1) then {
_currentDamage = _currentDamage min (CRITICAL_HITPOINTS_THRESHOLDS select _criticalDamageIndex);
};
if (_hitPoint == "" && {_hitIndex < 0}) then {
_currentDamage = _currentDamage min 0.89;
};
_currentDamage