2018-09-17 19:19:29 +00:00
|
|
|
#include "script_component.hpp"
|
2016-07-14 14:16:53 +00:00
|
|
|
/*
|
|
|
|
* Author: KoffeinFlummi, commy2
|
|
|
|
* Handles all incoming damage for tanks (including wheeled APCs).
|
|
|
|
*
|
|
|
|
* Arguments:
|
2017-06-08 13:31:51 +00:00
|
|
|
* HandleDamage EH <ARRAY>
|
2016-07-14 14:16:53 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
2017-06-08 13:31:51 +00:00
|
|
|
* Damage to be inflicted. <NUMBER>
|
2016-07-14 14:16:53 +00:00
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* _this call ace_cookoff_fnc_handleDamage
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
|
|
|
params ["_simulationType", "_thisHandleDamage"];
|
2016-10-06 20:37:38 +00:00
|
|
|
_thisHandleDamage params ["_vehicle", "", "_damage", "_source", "_ammo", "_hitIndex", "_shooter"];
|
2016-07-14 14:16:53 +00:00
|
|
|
|
|
|
|
// it's already dead, who cares?
|
|
|
|
if (damage _vehicle >= 1) exitWith {};
|
|
|
|
|
2019-11-05 17:55:15 +00:00
|
|
|
// If cookoff is disabled exit
|
|
|
|
if (_vehicle getVariable [QGVAR(enable), GVAR(enable)] in [0, false]) exitWith {};
|
|
|
|
|
|
|
|
// Check for players and exit if none found and the enable for players only setting is true
|
2021-02-27 17:50:09 +00:00
|
|
|
if (
|
|
|
|
_vehicle getVariable [QGVAR(enable), GVAR(enable)] isEqualTo 1
|
|
|
|
&& {fullCrew [_vehicle, "", false] findIf {isPlayer (_x select 0)} == -1}
|
|
|
|
&& {_simulationType isNotEqualTo "box"}
|
|
|
|
) exitWith {};
|
2019-11-05 17:55:15 +00:00
|
|
|
|
2016-07-14 14:16:53 +00:00
|
|
|
// get hitpoint name
|
|
|
|
private _hitpoint = "#structural";
|
|
|
|
|
|
|
|
if (_hitIndex != -1) then {
|
|
|
|
_hitpoint = toLower ((getAllHitPointsDamage _vehicle param [0, []]) select _hitIndex);
|
|
|
|
};
|
|
|
|
|
|
|
|
// get change in damage
|
2017-10-10 14:39:59 +00:00
|
|
|
private _oldDamage = 0;
|
2016-07-14 14:16:53 +00:00
|
|
|
|
|
|
|
if (_hitpoint isEqualTo "#structural") then {
|
|
|
|
_oldDamage = damage _vehicle;
|
|
|
|
} else {
|
|
|
|
_oldDamage = _vehicle getHitIndex _hitIndex;
|
|
|
|
};
|
|
|
|
|
|
|
|
private _newDamage = _damage - _oldDamage;
|
|
|
|
|
|
|
|
// handle different types of vehicles
|
|
|
|
// note: exitWith only works here, because this is not the main scope of handleDamage
|
|
|
|
// you cannot use the return value together with exitWith in the main scope, it's a bug
|
|
|
|
// also, we add this event handler with the addEventHandler SQF command,
|
|
|
|
// because the config version ignores the return value completely
|
|
|
|
if (_simulationType == "car") exitWith {
|
|
|
|
// prevent destruction, let cook-off handle it if necessary
|
|
|
|
if (_hitpoint in ["hithull", "hitfuel", "#structural"] && {!IS_EXPLOSIVE_AMMO(_ammo)}) then {
|
|
|
|
_damage min 0.89
|
|
|
|
} else {
|
|
|
|
if (_hitpoint isEqualTo "hitengine" && {_damage > 0.9}) then {
|
|
|
|
_vehicle call FUNC(engineFire);
|
|
|
|
};
|
|
|
|
_damage
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
if (_simulationType == "tank") exitWith {
|
|
|
|
// determine ammo storage location
|
2016-10-06 20:37:38 +00:00
|
|
|
private _ammoLocationHitpoint = getText (_vehicle call CBA_fnc_getObjectConfig >> QGVAR(ammoLocation));
|
2016-07-14 14:16:53 +00:00
|
|
|
|
2016-08-23 07:57:54 +00:00
|
|
|
if (_hitIndex in (GVAR(cacheTankDuplicates) getVariable (typeOf _vehicle))) then {
|
|
|
|
_hitpoint = "#subturret";
|
|
|
|
};
|
2016-10-06 20:37:38 +00:00
|
|
|
|
2016-07-14 14:16:53 +00:00
|
|
|
// ammo was hit, high chance for cook-off
|
|
|
|
if (_hitpoint == _ammoLocationHitpoint) then {
|
2017-11-30 22:54:47 +00:00
|
|
|
if (_damage > 0.5) then {
|
|
|
|
// get cookoff probability for vehicle
|
|
|
|
private _probability = [_vehicle call CBA_fnc_getObjectConfig >> QGVAR(probability), "number", 0.7] call CBA_fnc_getConfigEntry;
|
|
|
|
// probability multiplied by coef for global probability control (higher coef = more probable cookoff)
|
|
|
|
if (GVAR(probabilityCoef) > 1) then {
|
|
|
|
_probability = 1 - (1 - _probability) / GVAR(probabilityCoef);
|
|
|
|
} else {
|
|
|
|
_probability = _probability * GVAR(probabilityCoef);
|
|
|
|
};
|
|
|
|
if (random 1 < _probability) then {
|
|
|
|
_vehicle call FUNC(cookOff);
|
|
|
|
};
|
2016-07-14 14:16:53 +00:00
|
|
|
};
|
|
|
|
} else {
|
2017-11-30 22:54:47 +00:00
|
|
|
if (_hitpoint in ["hithull", "hitturret", "#structural"] && {_newDamage > 0.8 + random 0.2}) then {
|
2017-11-30 23:07:46 +00:00
|
|
|
if ((_hitpoint == "hitturret") && {(getNumber (_vehicle call CBA_fnc_getObjectConfig >> QGVAR(ignoreTurret))) == 1}) exitWith {}; // ignore turrets like RCWS
|
2017-11-30 22:54:47 +00:00
|
|
|
_vehicle setDamage 1;
|
2016-07-14 14:16:53 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// prevent destruction, let cook-off handle it if necessary
|
|
|
|
if (_hitpoint in ["hithull", "hitfuel", "#structural"]) then {
|
|
|
|
_damage min 0.89
|
|
|
|
} else {
|
|
|
|
_damage
|
|
|
|
};
|
|
|
|
};
|
2016-10-06 20:37:38 +00:00
|
|
|
|
|
|
|
if (_simulationType == "box") exitWith {
|
|
|
|
if (_hitpoint == "#structural" && _damage > 0.5) then {
|
|
|
|
// Almost always catch fire when hit by an explosive
|
|
|
|
if (IS_EXPLOSIVE_AMMO(_ammo)) then {
|
|
|
|
_vehicle call FUNC(cookOffBox);
|
|
|
|
} else {
|
|
|
|
// Need magazine to check for tracers
|
|
|
|
private _mag = "";
|
|
|
|
if (_source == _shooter) then {
|
|
|
|
_mag = currentMagazine _source;
|
|
|
|
} else {
|
|
|
|
_mag = _source currentMagazineTurret ([_shooter] call CBA_fnc_turretPath);
|
|
|
|
};
|
|
|
|
private _magCfg = configFile >> "CfgMagazines" >> _mag;
|
|
|
|
|
|
|
|
// Magazine could have changed during flight time (just ignore if so)
|
|
|
|
if (getText (_magCfg >> "ammo") == _ammo) then {
|
|
|
|
// If magazine's tracer density is high enough then low chance for cook off
|
|
|
|
private _tracers = getNumber (_magCfg >> "tracersEvery");
|
|
|
|
if (_tracers >= 1 && {_tracers <= 4}) then {
|
|
|
|
if (random 1 < _oldDamage*0.05) then {
|
|
|
|
_vehicle call FUNC(cookOffBox);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// prevent destruction, let cook-off handle it if necessary
|
|
|
|
_damage min 0.89
|
|
|
|
} else {
|
|
|
|
_damage
|
|
|
|
};
|
|
|
|
};
|