2018-09-17 19:19:29 +00:00
|
|
|
#include "script_component.hpp"
|
2015-01-16 02:36:31 +00:00
|
|
|
/*
|
2015-12-15 07:09:26 +00:00
|
|
|
* Author: Commy2 and esteldunedain
|
2015-02-08 22:54:12 +00:00
|
|
|
* Handle weapon fire, heat up the weapon
|
2015-01-16 02:36:31 +00:00
|
|
|
*
|
2016-06-18 09:50:41 +00:00
|
|
|
* Arguments:
|
2015-02-08 22:54:12 +00:00
|
|
|
* 0: Unit <OBJECT>
|
|
|
|
* 1: Weapon <STRING>
|
|
|
|
* 3: Muzzle <STRING>
|
|
|
|
* 4: Ammo <STRING>
|
|
|
|
* 5: Magazine <STRING>
|
|
|
|
* 6: Projectile <OBJECT>
|
2015-01-16 02:36:31 +00:00
|
|
|
*
|
2016-06-18 09:50:41 +00:00
|
|
|
* Return Value:
|
2015-01-16 02:36:31 +00:00
|
|
|
* None
|
2015-02-08 22:54:12 +00:00
|
|
|
*
|
2017-06-08 13:31:51 +00:00
|
|
|
* Example:
|
|
|
|
* [bob, "weapon", "muzzle", "ammo", "magazine", bullet] call ace_overheating_fnc_overheat
|
|
|
|
*
|
2015-02-08 22:54:12 +00:00
|
|
|
* Public: No
|
2015-01-16 02:36:31 +00:00
|
|
|
*/
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2015-12-15 07:09:26 +00:00
|
|
|
params ["_unit", "_weapon", "", "", "_ammo", "", "_projectile"];
|
|
|
|
TRACE_4("params",_unit,_weapon,_ammo,_projectile);
|
2015-01-16 02:36:31 +00:00
|
|
|
|
2015-12-15 07:09:26 +00:00
|
|
|
BEGIN_COUNTER(overheat);
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2016-02-18 18:58:44 +00:00
|
|
|
// Get bullet parameters
|
2021-11-08 18:06:31 +00:00
|
|
|
private _energyIncrement = GVAR(cacheAmmoData) get _ammo;
|
2017-11-23 10:13:58 +00:00
|
|
|
if (isNil "_energyIncrement") then {
|
2021-11-08 18:06:31 +00:00
|
|
|
private _bulletMass = getNumber (configFile >> "CfgAmmo" >> _ammo >> "ACE_BulletMass");
|
2016-02-18 18:58:44 +00:00
|
|
|
if (_bulletMass == 0) then {
|
|
|
|
// If the bullet mass is not configured, estimate it
|
|
|
|
_bulletMass = 3.4334 + 0.5171 * (getNumber (configFile >> "CfgAmmo" >> _ammo >> "hit") + getNumber (configFile >> "CfgAmmo" >> _ammo >> "caliber"));
|
|
|
|
};
|
2019-04-07 12:22:25 +00:00
|
|
|
|
2017-11-23 10:13:58 +00:00
|
|
|
// Projectile motion is roughly equal to Barrel heat
|
|
|
|
// Ref: https://en.wikipedia.org/wiki/Physics_of_firearms
|
|
|
|
// Muzzle Engergy = 1/2 * m * v^2 = (1/2 * 0.001 g/kg * bulletMass (grams) * v^2)
|
|
|
|
// Multiple by 3 becase we only calc every 3rd bullet: (3 * 1/2 * 0.001) = 0.0015
|
2021-11-08 18:06:31 +00:00
|
|
|
_energyIncrement = GVAR(heatCoef) * 0.0015 * _bulletMass * (vectorMagnitudeSqr velocity _projectile);
|
2016-02-18 18:58:44 +00:00
|
|
|
|
2021-11-08 18:06:31 +00:00
|
|
|
GVAR(cacheAmmoData) set [_ammo, _energyIncrement];
|
2017-11-23 10:13:58 +00:00
|
|
|
};
|
2015-12-15 07:09:26 +00:00
|
|
|
|
2016-02-18 18:58:44 +00:00
|
|
|
// Increase overheating depending on how obstrusive is the current supressor,
|
|
|
|
// if any. Typical arma supressors have visibleFire=0.5 and audibleFire=0.3,
|
|
|
|
// so they produce x2.1 overheating
|
2021-11-08 18:06:31 +00:00
|
|
|
private _suppressor = switch (_weapon) do {
|
2016-02-18 18:58:44 +00:00
|
|
|
case (primaryWeapon _unit) : {(primaryWeaponItems _unit) select 0};
|
|
|
|
case (handgunWeapon _unit) : {(handgunItems _unit) select 0};
|
|
|
|
default {""};
|
|
|
|
};
|
2021-11-08 18:06:31 +00:00
|
|
|
if (_suppressor != "" && {GVAR(suppressorCoef) > 0}) then {
|
|
|
|
private _suppressorCoef = GVAR(cacheSilencerData) get _suppressor;
|
|
|
|
if (isNil "_suppressorCoef") then {
|
|
|
|
private _config = configFile >> "CfgWeapons" >> _suppressor >> "ItemInfo" >> "AmmoCoef";
|
|
|
|
_suppressorCoef = GVAR(suppressorCoef) * (1 + (1 - getNumber (_config >> "audibleFire")) + (1 - getNumber (_config >> "visibleFire")));
|
|
|
|
GVAR(cacheSilencerData) set [_suppressor, _suppressorCoef];
|
2016-02-18 18:58:44 +00:00
|
|
|
};
|
2021-11-08 18:06:31 +00:00
|
|
|
_energyIncrement = _energyIncrement * _suppressorCoef;
|
2016-02-18 18:58:44 +00:00
|
|
|
};
|
|
|
|
|
2017-11-23 10:13:58 +00:00
|
|
|
TRACE_1("heat",_energyIncrement);
|
2015-12-15 07:09:26 +00:00
|
|
|
|
|
|
|
[_unit, _weapon, _energyIncrement] call FUNC(updateTemperature);
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2015-12-15 07:09:26 +00:00
|
|
|
END_COUNTER(overheat);
|