2018-09-17 19:19:29 +00:00
|
|
|
#include "script_component.hpp"
|
2016-01-20 18:19:46 +00:00
|
|
|
/*
|
|
|
|
* Author: PabstMirror and esteldunedain
|
|
|
|
* Get weapon data with caching
|
|
|
|
*
|
2016-06-18 09:50:41 +00:00
|
|
|
* Arguments:
|
2016-01-20 18:19:46 +00:00
|
|
|
* 0: weapon type <STRING>
|
|
|
|
*
|
2016-06-18 09:50:41 +00:00
|
|
|
* Return Value:
|
2021-11-08 18:06:31 +00:00
|
|
|
* 0: dispersion <NUMBER>
|
2016-01-20 18:19:46 +00:00
|
|
|
* 1: slowdownFactor <NUMBER>
|
|
|
|
* 2: jamChance <NUMBER>
|
2021-11-08 18:06:31 +00:00
|
|
|
* 3: modes <ARRAY>
|
|
|
|
* 4: muzzle <STRING>
|
|
|
|
* 5: reloadTime <NUMBER>
|
|
|
|
* 6: closedBolt <NUMBER>
|
|
|
|
* 7: barrelMass <NUMBER>
|
2016-01-20 18:19:46 +00:00
|
|
|
*
|
2017-06-08 13:31:51 +00:00
|
|
|
* Example:
|
|
|
|
* ["gun"] call ace_overheating_fnc_getWeaponData
|
|
|
|
*
|
2016-01-20 18:19:46 +00:00
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
2017-05-31 21:09:36 +00:00
|
|
|
params ["_weapon"];
|
|
|
|
|
2016-01-20 18:19:46 +00:00
|
|
|
// Look in the cache first
|
2021-11-08 18:06:31 +00:00
|
|
|
private _weaponData = GVAR(cacheWeaponData) get _weapon;
|
2016-01-20 18:19:46 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-10-14 15:47:52 +00:00
|
|
|
// for cookoff
|
|
|
|
private _modes = getArray (configFile >> "CfgWeapons" >> _weapon >> "modes");
|
|
|
|
private _muzzle = getArray (configFile >> "CfgWeapons" >> _weapon >> "muzzles") select 0;
|
|
|
|
if (_muzzle == "this") then {
|
|
|
|
_muzzle = _weapon;
|
|
|
|
};
|
2021-11-08 18:06:31 +00:00
|
|
|
|
2021-10-14 15:47:52 +00:00
|
|
|
private _reloadTime = getNumber (configfile >> "CfgWeapons" >> _weapon >> (_modes select 0) >> "reloadTime");
|
|
|
|
|
2021-11-08 18:06:31 +00:00
|
|
|
private _closedBolt = getNumber (configFile >> "CfgWeapons" >> _weapon >> QGVAR(closedBolt));
|
|
|
|
|
2022-05-11 23:21:05 +00:00
|
|
|
private _barrelMass = getNumber (configFile >> "CfgWeapons" >> _weapon >> QGVAR(barrelMass));
|
|
|
|
if (_barrelMass <= 0) then {
|
|
|
|
_barrelMass = METAL_MASS_RATIO * (getNumber (configFile >> "CfgWeapons" >> _weapon >> "WeaponSlotsInfo" >> "mass") / 22.0) max 1.0;
|
|
|
|
};
|
2021-11-08 18:06:31 +00:00
|
|
|
|
2016-01-20 18:19:46 +00:00
|
|
|
// Cache the values
|
2021-11-08 18:06:31 +00:00
|
|
|
_weaponData = [_dispersion, _slowdownFactor, _jamChance, _modes, _muzzle, _reloadTime, _closedBolt, _barrelMass];
|
2016-01-20 18:19:46 +00:00
|
|
|
TRACE_2("building cache",_weapon,_weaponData);
|
2021-11-08 18:06:31 +00:00
|
|
|
GVAR(cacheWeaponData) set [_weapon, _weaponData];
|
2016-01-20 18:19:46 +00:00
|
|
|
|
|
|
|
_weaponData
|