2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2021-10-14 15:49:27 +00:00
|
|
|
/*
|
2023-08-16 23:18:01 +00:00
|
|
|
* Author: tcvm
|
2021-10-14 15:49:27 +00:00
|
|
|
* Called by "HandleDamage" event handler. Sets up hit array for this frame's damage.
|
|
|
|
*
|
|
|
|
* Arguments:
|
2024-08-20 19:23:21 +00:00
|
|
|
* 0: Vehicle <OBJECT>
|
|
|
|
* 1: Selection <STRING>
|
|
|
|
* 2: New level of damage <NUMBER>
|
|
|
|
* 3: Source of damage <OBJECT>
|
2021-10-14 15:49:27 +00:00
|
|
|
* 4: Projectile that caused damage <STRING>
|
2024-08-20 19:23:21 +00:00
|
|
|
* 5: Hit index <NUMBER>
|
|
|
|
* 6: Person who caused damage <OBJECT>
|
|
|
|
* 7: Hit point <STRING>
|
2021-10-14 15:49:27 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
2024-08-20 19:23:21 +00:00
|
|
|
* Current or maximum damage of part <NUMBER>
|
2021-10-14 15:49:27 +00:00
|
|
|
*
|
|
|
|
* Example:
|
2024-08-20 19:23:21 +00:00
|
|
|
* [cursorObject, "hit_engine_point", 0.5, player, projectile, 1, player, "HitEngine"] call ace_vehicle_damage_fnc_handleDamage
|
2021-10-14 15:49:27 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
2024-08-20 19:23:21 +00:00
|
|
|
params ["_vehicle", "_selection", "_newDamage", "_source", "_projectile", "_hitIndex", "_instigator", "_hitPoint"];
|
|
|
|
TRACE_8("handleDamage",_vehicle,_selection,_newDamage,_source,_projectile,_hitIndex,_instigator,_hitPoint);
|
2023-06-28 10:39:33 +00:00
|
|
|
|
2024-08-20 19:23:21 +00:00
|
|
|
if (!local _vehicle) exitWith {};
|
|
|
|
|
|
|
|
private _currentDamage = if (_selection != "") then {
|
2023-06-28 10:39:33 +00:00
|
|
|
_vehicle getHitIndex _hitIndex
|
|
|
|
} else {
|
|
|
|
damage _vehicle
|
|
|
|
};
|
|
|
|
|
2021-10-14 15:49:27 +00:00
|
|
|
if !(_projectile in ["ace_ammoExplosion", "ACE_ammoExplosionLarge"]) then {
|
2024-08-20 19:23:21 +00:00
|
|
|
// 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;
|
2021-10-14 15:49:27 +00:00
|
|
|
};
|
2024-08-20 19:23:21 +00:00
|
|
|
|
|
|
|
_currentFrameArray pushBack _this;
|
2021-10-14 15:49:27 +00:00
|
|
|
};
|
|
|
|
|
2024-08-20 19:23:21 +00:00
|
|
|
// 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);
|
2021-10-14 15:49:27 +00:00
|
|
|
};
|
|
|
|
|
2024-08-20 19:23:21 +00:00
|
|
|
if (_hitPoint == "" && {_hitIndex < 0}) then {
|
|
|
|
_currentDamage = _currentDamage min 0.89;
|
2021-10-14 15:49:27 +00:00
|
|
|
};
|
|
|
|
|
2024-08-20 19:23:21 +00:00
|
|
|
_currentDamage
|