2015-02-13 21:55:13 +00:00
|
|
|
/*
|
|
|
|
* Author: KoffeinFlummi, Glowbal
|
|
|
|
* Cache a handleDamage call to execute it 3 frames later
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Unit That Was Hit <OBJECT>
|
|
|
|
* 1: Name Of Hit Selection <STRING>
|
|
|
|
* 2: Amount Of Damage <NUMBER>
|
|
|
|
* 3: Shooter <OBJECT>
|
|
|
|
* 4: Projectile <STRING>
|
2015-11-21 17:11:13 +00:00
|
|
|
* 5: HitPointIndex (-1 for structural) <NUMBER>
|
2015-02-13 21:55:13 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* <nil>
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-08-22 14:25:10 +00:00
|
|
|
private ["_hitSelections", "_hitPoints", "_impactVelocity", "_newDamage", "_cache_hitpoints", "_cache_projectiles", "_cache_params", "_cache_damages"];
|
2015-11-21 17:11:13 +00:00
|
|
|
params ["_unit", "_selectionName", "_damage", "_source", "_projectile", "_hitPointIndex"];
|
|
|
|
|
2015-04-11 20:30:52 +00:00
|
|
|
_hitSelections = GVAR(SELECTIONS);
|
2015-02-13 21:55:13 +00:00
|
|
|
|
2015-11-21 17:11:13 +00:00
|
|
|
// Calculate change in damage - use getHitIndex because selection is translated (hitdiaphragm->body)
|
2015-02-13 21:55:13 +00:00
|
|
|
_newDamage = _damage - (damage _unit);
|
2015-11-21 17:11:13 +00:00
|
|
|
if (_hitPointIndex >= 0) then {_newDamage = _damage - (_unit getHitIndex _hitPointIndex)};
|
2015-02-13 21:55:13 +00:00
|
|
|
|
2015-11-21 17:11:13 +00:00
|
|
|
TRACE_7("ACE_DEBUG: HandleDamage_Caching Called",_unit, _selectionName, _damage, _source, _projectile,_hitPointIndex,_newDamage);
|
2015-04-11 20:30:52 +00:00
|
|
|
|
2015-03-05 17:42:32 +00:00
|
|
|
// Check for vehicle crash
|
2016-02-15 23:11:04 +00:00
|
|
|
private _vehicle = vehicle _unit;
|
|
|
|
if ((_vehicle != _unit) && {!(_vehicle isKindOf "StaticWeapon")} && {_source in [objNull, driver _vehicle, _vehicle]} && {_projectile == ""} && {_selectionName == ""}) then {
|
2015-04-17 21:15:41 +00:00
|
|
|
if (GVAR(enableVehicleCrashes)) then {
|
2015-11-29 15:33:25 +00:00
|
|
|
_selectionName = selectRandom _hitSelections;
|
2015-03-05 17:42:32 +00:00
|
|
|
_projectile = "vehiclecrash";
|
2015-06-10 15:02:14 +00:00
|
|
|
_this set [1, _selectionName];
|
|
|
|
_this set [4, _projectile];
|
2015-03-05 17:42:32 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-06-13 09:53:30 +00:00
|
|
|
// Handle falling damage
|
|
|
|
_impactVelocity = (velocity _unit) select 2;
|
2016-02-15 23:11:04 +00:00
|
|
|
if (_impactVelocity < -5 && {_vehicle == _unit}) then {
|
2015-11-21 17:11:13 +00:00
|
|
|
TRACE_1("Starting isFalling", time);
|
2015-06-10 14:51:46 +00:00
|
|
|
_unit setVariable [QGVAR(isFalling), true];
|
2015-06-13 09:53:30 +00:00
|
|
|
_unit setVariable [QGVAR(impactVelocity), _impactVelocity];
|
2015-11-21 17:11:13 +00:00
|
|
|
} else {
|
|
|
|
if ((_unit getVariable [QGVAR(isFalling), false]) && {diag_frameno > (_unit getVariable [QGVAR(frameNo_damageCaching), -3]) + 2}) then {
|
|
|
|
TRACE_1("Ending isFalling", time);
|
|
|
|
_unit setVariable [QGVAR(isFalling), false];
|
|
|
|
};
|
2015-02-13 21:55:13 +00:00
|
|
|
};
|
|
|
|
if (_unit getVariable [QGVAR(isFalling), false]) then {
|
2015-06-12 11:54:52 +00:00
|
|
|
if !(_selectionName in ["", "leg_l", "leg_r"]) then {
|
|
|
|
if (_selectionName == "body") then {
|
2015-06-13 09:53:30 +00:00
|
|
|
_newDamage = _newDamage * abs(_unit getVariable [QGVAR(impactVelocity), _impactVelocity]) / 50;
|
2015-06-12 11:54:52 +00:00
|
|
|
} else {
|
|
|
|
_newDamage = _newDamage * 0.5;
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
if (_selectionName == "") then {
|
2015-11-29 15:33:25 +00:00
|
|
|
_selectionName = selectRandom ["leg_l", "leg_r"];
|
2015-06-12 11:54:52 +00:00
|
|
|
_this set [1, _selectionName];
|
|
|
|
};
|
|
|
|
_newDamage = _newDamage * 0.7;
|
2015-06-10 14:51:46 +00:00
|
|
|
};
|
2015-06-13 09:53:30 +00:00
|
|
|
_projectile = "falling";
|
|
|
|
_this set [4, "falling"];
|
2015-02-13 21:55:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Finished with the current frame, reset variables
|
|
|
|
// Note: sometimes handleDamage spans over 2 or even 3 frames.
|
|
|
|
if (diag_frameno > (_unit getVariable [QGVAR(frameNo_damageCaching), -3]) + 2) then {
|
|
|
|
_unit setVariable [QGVAR(frameNo_damageCaching), diag_frameno];
|
|
|
|
|
|
|
|
// handle the cached damages 3 frames later
|
|
|
|
[{
|
2015-04-11 20:30:52 +00:00
|
|
|
private ["_args", "_params"];
|
2015-08-22 14:25:10 +00:00
|
|
|
params ["_args", "_idPFH"];
|
2015-08-22 16:33:06 +00:00
|
|
|
_args params ["_unit", "_frameno"];
|
2015-09-14 13:19:58 +00:00
|
|
|
if (diag_frameno >= _frameno + 2) then {
|
2015-08-22 14:25:10 +00:00
|
|
|
_unit setDamage 0;
|
2015-04-11 19:27:49 +00:00
|
|
|
|
2015-08-26 08:04:51 +00:00
|
|
|
if (GVAR(level) < 2 || {!([_unit] call FUNC(hasMedicalEnabled))}) then {
|
2015-08-29 10:01:00 +00:00
|
|
|
[_unit] call FUNC(handleDamage_basic);
|
2015-08-26 08:04:51 +00:00
|
|
|
} else {
|
|
|
|
_cache_params = _unit getVariable [QGVAR(cachedHandleDamageParams), []];
|
|
|
|
_cache_damages = _unit getVariable QGVAR(cachedDamages);
|
|
|
|
{
|
2015-11-30 16:23:48 +00:00
|
|
|
_params = _x + [_cache_damages select _forEachIndex];
|
2015-08-26 08:04:51 +00:00
|
|
|
_params call FUNC(handleDamage_advanced);
|
2015-11-30 16:23:48 +00:00
|
|
|
} forEach _cache_params;
|
2015-08-26 08:04:51 +00:00
|
|
|
[_unit] call FUNC(handleDamage_advancedSetDamage);
|
|
|
|
};
|
2015-08-22 14:25:10 +00:00
|
|
|
[_idPFH] call CBA_fnc_removePerFrameHandler;
|
2015-02-13 21:55:13 +00:00
|
|
|
};
|
|
|
|
}, 0, [_unit, diag_frameno] ] call CBA_fnc_addPerFrameHandler;
|
|
|
|
|
|
|
|
_unit setVariable [QGVAR(cachedProjectiles), []];
|
|
|
|
_unit setVariable [QGVAR(cachedHitPoints), []];
|
|
|
|
_unit setVariable [QGVAR(cachedDamages), []];
|
|
|
|
_unit setVariable [QGVAR(cachedHandleDamageParams), []];
|
|
|
|
};
|
|
|
|
|
|
|
|
// Caching of the damage events
|
|
|
|
if (_selectionName != "") then {
|
2015-04-11 20:30:52 +00:00
|
|
|
_cache_projectiles = _unit getVariable QGVAR(cachedProjectiles);
|
2015-04-11 19:27:49 +00:00
|
|
|
private ["_index","_otherDamage"];
|
|
|
|
_index = _cache_projectiles find _projectile;
|
2015-02-13 21:55:13 +00:00
|
|
|
// Check if the current projectile has already been handled once
|
2015-11-30 16:14:05 +00:00
|
|
|
if (_index >= 0 && {_projectile != "falling"}) exitWith {
|
2015-04-11 20:30:52 +00:00
|
|
|
_cache_damages = _unit getVariable QGVAR(cachedDamages);
|
2015-02-13 21:55:13 +00:00
|
|
|
// Find the previous damage this projectile has done
|
|
|
|
_otherDamage = (_cache_damages select _index);
|
|
|
|
|
|
|
|
// Take the highest damage of the two
|
2015-04-11 19:27:49 +00:00
|
|
|
if (_newDamage > _otherDamage) then {
|
2015-04-11 20:30:52 +00:00
|
|
|
_cache_params = _unit getVariable QGVAR(cachedHandleDamageParams);
|
|
|
|
_cache_hitpoints = _unit getVariable QGVAR(cachedHitPoints);
|
|
|
|
|
2015-02-13 21:55:13 +00:00
|
|
|
private ["_hitPoint", "_restore"];
|
|
|
|
// Restore the damage before the previous damage was processed
|
|
|
|
_hitPoint = _cache_hitpoints select _index;
|
2015-11-21 17:11:13 +00:00
|
|
|
_restore = ((_unit getHitIndex _hitPoint) - _otherDamage) max 0;
|
|
|
|
_unit setHitIndex [_hitPoint, _restore];
|
2015-02-13 21:55:13 +00:00
|
|
|
|
2015-11-21 17:11:13 +00:00
|
|
|
_cache_hitpoints set [_index, _hitPointIndex];
|
2015-04-11 19:27:49 +00:00
|
|
|
_cache_damages set [_index, _newDamage];
|
|
|
|
_cache_params set[_index, _this];
|
2015-04-11 20:30:52 +00:00
|
|
|
|
|
|
|
_unit setVariable [QGVAR(cachedProjectiles), _cache_projectiles];
|
|
|
|
_unit setVariable [QGVAR(cachedHitPoints), _cache_hitpoints];
|
|
|
|
_unit setVariable [QGVAR(cachedDamages), _cache_damages];
|
|
|
|
_unit setVariable [QGVAR(cachedHandleDamageParams), _cache_params];
|
2015-02-13 21:55:13 +00:00
|
|
|
};
|
|
|
|
};
|
2015-04-11 19:27:49 +00:00
|
|
|
|
2015-04-11 20:30:52 +00:00
|
|
|
_cache_hitpoints = _unit getVariable QGVAR(cachedHitPoints);
|
|
|
|
_cache_damages = _unit getVariable QGVAR(cachedDamages);
|
|
|
|
_cache_params = _unit getVariable QGVAR(cachedHandleDamageParams);
|
|
|
|
|
2015-04-11 19:27:49 +00:00
|
|
|
// This is an unhandled projectile
|
|
|
|
_cache_projectiles pushBack _projectile;
|
2015-11-21 17:11:13 +00:00
|
|
|
_cache_hitpoints pushBack _hitPointIndex;
|
2015-04-11 19:27:49 +00:00
|
|
|
_cache_damages pushBack _newDamage;
|
|
|
|
_cache_params pushBack _this;
|
2015-04-11 20:30:52 +00:00
|
|
|
|
|
|
|
// Store the new cached values
|
|
|
|
_unit setVariable [QGVAR(cachedProjectiles), _cache_projectiles];
|
|
|
|
_unit setVariable [QGVAR(cachedHitPoints), _cache_hitpoints];
|
|
|
|
_unit setVariable [QGVAR(cachedDamages), _cache_damages];
|
|
|
|
_unit setVariable [QGVAR(cachedHandleDamageParams), _cache_params];
|
2015-02-13 21:55:13 +00:00
|
|
|
};
|
|
|
|
|
2015-09-05 22:31:14 +00:00
|
|
|
TRACE_8("ACE_DEBUG: HandleDamage_Caching",_unit, _newDamage, _cache_params, _cache_damages, _unit getVariable QGVAR(cachedProjectiles), _unit getVariable QGVAR(cachedHitPoints), _unit getVariable QGVAR(cachedDamages), _unit getVariable QGVAR(cachedHandleDamageParams));
|
|
|
|
|
2015-08-22 14:25:10 +00:00
|
|
|
_newDamage
|