ACE3/addons/overheating/functions/fnc_getWeaponData.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

92 lines
3.0 KiB
Plaintext

#include "script_component.hpp"
/*
* Author: PabstMirror and esteldunedain
* Get weapon data with caching
*
* Arguments:
* 0: weapon type <STRING>
*
* Return Value:
* 0: dispersion <NUMBER>
* 1: slowdownFactor <NUMBER>
* 2: jamChance <NUMBER>
* 3: modes <ARRAY>
* 4: muzzle <STRING>
* 5: reloadTime <NUMBER>
* 6: closedBolt <NUMBER>
* 7: barrelMass <NUMBER>
*
* Example:
* ["gun"] call ace_overheating_fnc_getWeaponData
*
* Public: No
*/
params ["_weapon"];
// Look in the cache first
private _weaponData = GVAR(cacheWeaponData) get _weapon;
if (!isNil "_weaponData") exitWith {_weaponData};
// Search the config
// The old and new properties have the same name for dispersion, so read whichever is closer to the children
private _property = configFile >> "CfgWeapons" >> _weapon >> QGVAR(dispersion);
private _dispersion = if (isNumber _property) then {
getNumber _property;
} else {
if (isArray _property) then {
// Map old array property to new number property
((getArray _property) select 3) / 0.004;
} else {
1;
};
};
// The old and new properties have the same name for slowdownFactor, so read whichever is closer to the children
_property = configFile >> "CfgWeapons" >> _weapon >> QGVAR(slowdownFactor);
private _slowdownFactor = if (isNumber _property) then {
getNumber _property;
} else {
if (isArray _property) then {
// Map old array property to new number property
((getArray _property) select 3) / 0.9;
} else {
1;
};
};
// For jam chance, try reading the legacy property first (ace_overheating_jamChance).
private _jamChance = 1 / 3000;
_property = configFile >> "CfgWeapons" >> _weapon >> QGVAR(JamChance);
// If it exists read it, as the weapon is probably third party and not updated to the new properties
if (isArray _property) then {
// Map old array property to new number property
_jamChance = (getArray _property) select 1;
} else {
// No legacy property was found, look for the new one
_property = configFile >> "CfgWeapons" >> _weapon >> QGVAR(mrbs);
if (isNumber _property) then {
_jamChance = 1 / getNumber _property;
};
};
// for cookoff
private _modes = getArray (configFile >> "CfgWeapons" >> _weapon >> "modes");
private _muzzle = getArray (configFile >> "CfgWeapons" >> _weapon >> "muzzles") select 0;
if (_muzzle == "this") then {
_muzzle = _weapon;
};
private _reloadTime = getNumber (configfile >> "CfgWeapons" >> _weapon >> (_modes select 0) >> "reloadTime");
private _closedBolt = getNumber (configFile >> "CfgWeapons" >> _weapon >> QGVAR(closedBolt));
private _barrelMass = METAL_MASS_RATIO * (getNumber (configFile >> "CfgWeapons" >> _weapon >> "WeaponSlotsInfo" >> "mass") / 22.0) max 1.0;
// Cache the values
_weaponData = [_dispersion, _slowdownFactor, _jamChance, _modes, _muzzle, _reloadTime, _closedBolt, _barrelMass];
TRACE_2("building cache",_weapon,_weaponData);
GVAR(cacheWeaponData) set [_weapon, _weaponData];
_weaponData