mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Move the weapon caching code to a different function. Add compatibility for legacy overheating properties. Add some comments.
This commit is contained in:
parent
851615a234
commit
9d13cc6f60
@ -6,6 +6,7 @@ PREP(checkTemperature);
|
||||
PREP(clearJam);
|
||||
PREP(displayTemperature);
|
||||
PREP(firedEH);
|
||||
PREP(getWeaponData);
|
||||
PREP(handleTakeEH);
|
||||
PREP(jamWeapon);
|
||||
PREP(overheat);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Author: Commy2 and CAA-Picard
|
||||
* Author: Commy2 and esteldunedain
|
||||
* Handle weapon fire
|
||||
*
|
||||
* Argument:
|
||||
@ -42,30 +42,7 @@ private _scaledTemperature = linearConversion [0, 1000, _temperature, 0, 1, true
|
||||
TRACE_2("Unit fired with temp:",_unit,_temperature);
|
||||
|
||||
//Get weapon data from cache:
|
||||
private _weaponData = GVAR(weaponInfoCache) getVariable _weapon;
|
||||
if (isNil "_weaponData") then {
|
||||
private _dispersion = if (isNumber (configFile >> "CfgWeapons" >> _weapon >> QGVAR(dispersion))) then {
|
||||
getNumber (configFile >> "CfgWeapons" >> _weapon >> QGVAR(dispersion));
|
||||
} else {
|
||||
1;
|
||||
};
|
||||
private _slowdownFactor = if (isNumber (configFile >> "CfgWeapons" >> _weapon >> QGVAR(slowdownFactor))) then {
|
||||
getNumber (configFile >> "CfgWeapons" >> _weapon >> QGVAR(slowdownFactor));
|
||||
} else {
|
||||
1;
|
||||
};
|
||||
private _jamChance = if (isNumber (configFile >> "CfgWeapons" >> _weapon >> QGVAR(ACE_mrbs))) then {
|
||||
getNumber (configFile >> "CfgWeapons" >> _weapon >> QGVAR(ACE_mrbs));
|
||||
} else {
|
||||
3000;
|
||||
};
|
||||
_jamChance = if (_jamChance == 0) then {0} else {1/_jamChance};
|
||||
|
||||
_weaponData = [_dispersion, _slowdownFactor, _jamChance];
|
||||
TRACE_2("building cache",_weapon,_weaponData);
|
||||
GVAR(weaponInfoCache) setVariable [_weapon, _weaponData];
|
||||
};
|
||||
_weaponData params ["_dispersion", "_slowdownFactor", "_jamChance"];
|
||||
([_weapon] call FUNC(getWeaponData)) params ["_dispersion", "_slowdownFactor", "_jamChance"];
|
||||
TRACE_4("weapon data from cache",_weapon,_dispersion,_slowdownFactor,_jamChance);
|
||||
|
||||
// Dispersion and bullet slow down
|
||||
|
68
addons/overheating/functions/fnc_getWeaponData.sqf
Normal file
68
addons/overheating/functions/fnc_getWeaponData.sqf
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Author: PabstMirror and esteldunedain
|
||||
* Get weapon data with caching
|
||||
*
|
||||
* Argument:
|
||||
* 0: weapon type <STRING>
|
||||
*
|
||||
* Return value:
|
||||
* 0: dispresion <NUMBER>
|
||||
* 1: slowdownFactor <NUMBER>
|
||||
* 2: jamChance <NUMBER>
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
// Look in the cache first
|
||||
private _weaponData = GVAR(weaponInfoCache) getVariable _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;
|
||||
};
|
||||
};
|
||||
|
||||
// Cache the values
|
||||
_weaponData = [_dispersion, _slowdownFactor, _jamChance];
|
||||
TRACE_2("building cache",_weapon,_weaponData);
|
||||
GVAR(weaponInfoCache) setVariable [_weapon, _weaponData];
|
||||
|
||||
_weaponData
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Author: ??? probably CAA-Picard / Commy2
|
||||
* Author: Commy2
|
||||
* Handle "take" event
|
||||
* I think it fixs jams when manually dragging a new magazine in from player's inventory
|
||||
*
|
||||
|
@ -19,9 +19,12 @@
|
||||
params ["_player", "_weapon"];
|
||||
TRACE_2("params",_player,_weapon);
|
||||
|
||||
// Make the standing player kneel down
|
||||
if (stance _player != "PRONE") then {
|
||||
[_player, "amovpknlmstpsraswrfldnon", 1] call EFUNC(common,doAnimation);
|
||||
};
|
||||
|
||||
// Barrel dismount gesture
|
||||
_player playActionNow QGVAR(GestureDismountMuzzle);
|
||||
playSound "ACE_BarrelSwap";
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
params ["_player", "_weapon"];
|
||||
TRACE_2("params",_player,_weapon);
|
||||
|
||||
// Barrel mount gesture
|
||||
_player playAction QGVAR(GestureMountMuzzle);
|
||||
playSound "ACE_BarrelSwap";
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user