2021-10-14 15:47:52 +00:00
|
|
|
#include "script_component.hpp"
|
|
|
|
/*
|
|
|
|
* Author: drofseh
|
|
|
|
* Update temperature of the round in the chamber and determine if a cookoff should occur.
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Unit <OBJECT>
|
|
|
|
* 1: Weapon <STRING>
|
|
|
|
* 2: Barrel Temperature <STRING>
|
|
|
|
*
|
|
|
|
* Return Value:
|
2021-11-08 18:06:31 +00:00
|
|
|
* New temperature <NUMBER>
|
2021-10-14 15:47:52 +00:00
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [player, currentWeapon player, 600] call ace_overheating_fnc_updateAmmoTemperature
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
|
|
|
params ["_unit", "_weapon", "_barrelTemperature"];
|
|
|
|
TRACE_3("params",_unit,_weapon,_barrelTemperature);
|
|
|
|
|
2021-11-08 19:08:43 +00:00
|
|
|
private _closedBolt = ([_weapon] call FUNC(getWeaponData)) select 6;
|
2021-10-14 15:47:52 +00:00
|
|
|
private _canUnjam = [_unit] call FUNC(canUnjam);
|
2021-11-08 18:06:31 +00:00
|
|
|
private _jamType = _unit getVariable [format [QGVAR(%1_jamType), _weapon], "None"];
|
2021-10-14 15:47:52 +00:00
|
|
|
|
|
|
|
// Skip if no ammo in chamber
|
|
|
|
if (
|
|
|
|
_unit ammo _weapon < 1
|
|
|
|
// closed bolt, and jammed and type not failure to fire
|
2021-11-08 18:06:31 +00:00
|
|
|
|| {_closedBolt == 1 && {_canUnjam} && {!(_jamType in ["Fire","Dud"])}}
|
2021-10-14 15:47:52 +00:00
|
|
|
// open bolt, and not jammed, or jammed and type not failure to fire
|
2021-11-08 18:06:31 +00:00
|
|
|
|| {_closedBolt == 0 && {!_canUnjam || {_canUnjam && {!(_jamType in ["Fire","Dud"])}}}}
|
2021-10-14 15:47:52 +00:00
|
|
|
) exitWith {
|
2021-11-08 18:06:31 +00:00
|
|
|
private _ambientTemperature = ambientTemperature select 0;
|
|
|
|
_unit setVariable [format [QGVAR(%1_ammoTemp), _weapon], _ambientTemperature];
|
|
|
|
_ambientTemperature
|
2021-10-14 15:47:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
private _ammoTempVarName = format [QGVAR(%1_ammoTemp), _weapon];
|
2021-11-08 18:06:31 +00:00
|
|
|
private _ammoTemperature = _unit getVariable [_ammoTempVarName, ambientTemperature select 0];
|
2021-10-14 15:47:52 +00:00
|
|
|
|
|
|
|
// heat or cool the ammo
|
|
|
|
if (_ammoTemperature < _barrelTemperature) then {
|
|
|
|
// this is functional and feels ok, but someone please do better heat transfer math here, my head hurts.
|
|
|
|
private _temperatureDifference = _barrelTemperature - _ammoTemperature;
|
|
|
|
_ammoTemperature = _ammoTemperature + (1 max ((_temperatureDifference / 2.75) - 100));
|
|
|
|
} else {
|
|
|
|
_ammoTemperature = _barrelTemperature;
|
|
|
|
};
|
|
|
|
|
2021-11-08 18:06:31 +00:00
|
|
|
// cookoff if too hot
|
2021-10-14 15:47:52 +00:00
|
|
|
if (_ammoTemperature > (GUNPOWDER_IGNITION_TEMP * GVAR(cookoffCoef))) then {
|
2021-11-08 18:06:31 +00:00
|
|
|
[_unit, _weapon, _canUnjam, _jamType] call FUNC(cookoffWeapon);
|
2021-10-14 15:47:52 +00:00
|
|
|
|
2021-11-08 18:06:31 +00:00
|
|
|
// since a cookoff happened then the next round should start at the ambient temperature.
|
|
|
|
_ammoTemperature = ambientTemperature select 0;
|
2021-10-14 15:47:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
_unit setVariable [_ammoTempVarName, _ammoTemperature];
|
|
|
|
|
|
|
|
_ammoTemperature
|