ACE3/addons/overheating/functions/fnc_overheat.sqf
Drofseh 99c85e3c12
Overheating - Fix issues from release (#8617)
* move overheating cookoff into separate function

* move heatCoef and require mission restart for setting change

- move heatCoef to a more sensible place
- require mission restart for heatCoef setting change (it gets cached per ammo type)

* add exit to ammo temp loop if cookoffCoef is changed to 0 mid-mission

- add exit to ammo temp loop if cookoffCoef is changed to 0 mid-mission, this prevents an issue where all weapon cookoff regardless of temp, because required temp gets multiplied by cookoffCoef which has been set to 0.

* file end new line

* update header for ace_overheating_fnc_cookoffWeapon

* use ambientTemperature as floor for weapon and ammo temp

* add coolingCoef setting

* improve feature documentation

* add fnc_cookoffWeapon to XEH_PREP

* add type of jam to ace_weaponJammed local event

- add type of jam to ace_weaponJammed local event
- fix #8637

* fix misspelling

Co-authored-by: TyroneMF <TyroneMF@hotmail.com>

* clear all weapon heat on death

* Update addons/overheating/functions/fnc_updateTemperature.sqf

Co-authored-by: GhostIsSpooky <69561145+Salluci@users.noreply.github.com>

* deprecate ace_overheating_fnc_getBarrelMass, cache weapon bolt and barrel mass values

- cache closed bolt value by moving config look up to ace_overheating_fnc_getWeaponData
- cache barrel mass value by moving calculation from ace_overheating_fnc_getBarrelMass to ace_overheating_fnc_getWeaponData
- deprecate ace_overheating_fnc_getBarrelMass to be a wrapper for ace_overheating_fnc_getWeaponData that only returns barrel mass

* add public functions to get and set weapon and ammo temperature

* add `canCoolWeaponWithItem` function, workaround for #8657

* Apply suggestions from code review

Co-authored-by: PabstMirror <pabstmirror@gmail.com>

* add coef setting for addition heat from suppressor

* Update fnc_overheat.sqf

* improve fnc_canCoolWeaponWithItem

* remove extra (

* Move canCoolWeaponWithItem action code to function

* Use hashmaps and reset on settings change

* Apply suggestions from code review

Co-authored-by: jonpas <jonpas33@gmail.com>

Co-authored-by: TyroneMF <TyroneMF@hotmail.com>
Co-authored-by: GhostIsSpooky <69561145+Salluci@users.noreply.github.com>
Co-authored-by: PabstMirror <pabstmirror@gmail.com>
Co-authored-by: jonpas <jonpas33@gmail.com>
2021-11-08 12:06:31 -06:00

69 lines
2.5 KiB
Plaintext

#include "script_component.hpp"
/*
* Author: Commy2 and esteldunedain
* Handle weapon fire, heat up the weapon
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Weapon <STRING>
* 3: Muzzle <STRING>
* 4: Ammo <STRING>
* 5: Magazine <STRING>
* 6: Projectile <OBJECT>
*
* Return Value:
* None
*
* Example:
* [bob, "weapon", "muzzle", "ammo", "magazine", bullet] call ace_overheating_fnc_overheat
*
* Public: No
*/
params ["_unit", "_weapon", "", "", "_ammo", "", "_projectile"];
TRACE_4("params",_unit,_weapon,_ammo,_projectile);
BEGIN_COUNTER(overheat);
// Get bullet parameters
private _energyIncrement = GVAR(cacheAmmoData) get _ammo;
if (isNil "_energyIncrement") then {
private _bulletMass = getNumber (configFile >> "CfgAmmo" >> _ammo >> "ACE_BulletMass");
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"));
};
// 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
_energyIncrement = GVAR(heatCoef) * 0.0015 * _bulletMass * (vectorMagnitudeSqr velocity _projectile);
GVAR(cacheAmmoData) set [_ammo, _energyIncrement];
};
// 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
private _suppressor = switch (_weapon) do {
case (primaryWeapon _unit) : {(primaryWeaponItems _unit) select 0};
case (handgunWeapon _unit) : {(handgunItems _unit) select 0};
default {""};
};
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];
};
_energyIncrement = _energyIncrement * _suppressorCoef;
};
TRACE_1("heat",_energyIncrement);
[_unit, _weapon, _energyIncrement] call FUNC(updateTemperature);
END_COUNTER(overheat);