From dae3d8d682f250139e1b917ba56bbc4c66f1c932 Mon Sep 17 00:00:00 2001 From: Grey-Soldierman Date: Sat, 27 Aug 2016 09:21:15 +0100 Subject: [PATCH] Definable classname for Spare Barrel (#4121) * Added definable barrel classname through weapon config * Improved condition for player carrying spare barrel --- addons/overheating/CfgVehicles.hpp | 6 ++--- addons/overheating/XEH_PREP.hpp | 2 ++ .../fnc_canCheckSpareBarrelsTemperatures.sqf | 25 ++++++++++++++++++ .../functions/fnc_canSwapBarrel.sqf | 26 +++++++++++++++++++ .../functions/fnc_loadCoolestSpareBarrel.sqf | 8 ++++-- .../fnc_sendSpareBarrelsTemperaturesHint.sqf | 10 ++++++- 6 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 addons/overheating/functions/fnc_canCheckSpareBarrelsTemperatures.sqf create mode 100644 addons/overheating/functions/fnc_canSwapBarrel.sqf diff --git a/addons/overheating/CfgVehicles.hpp b/addons/overheating/CfgVehicles.hpp index 33060027db..a096754ce3 100644 --- a/addons/overheating/CfgVehicles.hpp +++ b/addons/overheating/CfgVehicles.hpp @@ -15,7 +15,7 @@ class CfgVehicles { }; class GVAR(SwapBarrel) { displayName = CSTRING(SwapBarrel); - condition = QUOTE( GVAR(enabled) && {'ACE_SpareBarrel' in magazines _player} && {getNumber (configFile >> 'CfgWeapons' >> currentWeapon _player >> 'ACE_Overheating_allowSwapBarrel') == 1} ); + condition = QUOTE( [ARR_2(_player, currentWeapon _player)] call FUNC(canSwapBarrel) ); statement = QUOTE( [ARR_3(_player, _player, currentWeapon _player)] call FUNC(swapBarrel); ); showDisabled = 0; priority = 3; @@ -32,7 +32,7 @@ class CfgVehicles { }; class GVAR(CheckTemperatureSpareBarrels) { displayName = CSTRING(CheckTemperatureSpareBarrelsShort); - condition = QUOTE( GVAR(enabled) && {'ACE_SpareBarrel' in magazines _player}); + condition = QUOTE((_player) call FUNC(canCheckSpareBarrelsTemperatures) ); exceptions[] = {"isNotInside", "isNotSitting"}; statement = QUOTE( [_player] call FUNC(checkSpareBarrelsTemperatures); ); showDisabled = 0; @@ -46,7 +46,7 @@ class CfgVehicles { class ACE_Weapon { class GVAR(SwapBarrel) { displayName = CSTRING(SwapBarrel); - condition = QUOTE( GVAR(enabled) && {'ACE_SpareBarrel' in magazines _player} && {getNumber (configFile >> 'CfgWeapons' >> currentWeapon _target >> 'ACE_Overheating_allowSwapBarrel') == 1} ); + condition = QUOTE( [ARR_2(_player, currentWeapon _target)] call FUNC(canSwapBarrel) ); statement = QUOTE([ARR_3(_player, _target, currentWeapon _target)] call FUNC(swapBarrelAssistant);); icon = QUOTE(PATHTOF(UI\spare_barrel_ca.paa)); }; diff --git a/addons/overheating/XEH_PREP.hpp b/addons/overheating/XEH_PREP.hpp index 44fd931ca0..2436e390db 100644 --- a/addons/overheating/XEH_PREP.hpp +++ b/addons/overheating/XEH_PREP.hpp @@ -1,6 +1,8 @@ PREP(calculateCooling); PREP(canUnjam); +PREP(canSwapBarrel); +PREP(canCheckSpareBarrelsTemperatures); PREP(checkSpareBarrelsTemperatures); PREP(checkTemperature); PREP(clearJam); diff --git a/addons/overheating/functions/fnc_canCheckSpareBarrelsTemperatures.sqf b/addons/overheating/functions/fnc_canCheckSpareBarrelsTemperatures.sqf new file mode 100644 index 0000000000..1f6ec765b3 --- /dev/null +++ b/addons/overheating/functions/fnc_canCheckSpareBarrelsTemperatures.sqf @@ -0,0 +1,25 @@ +/* + * Author: Grey-Soldierman + * Return true if player can check temperatures of spare barrels + * + * Arguments: + * 0: Player + * + * Return Value: + * Bool + * + * Public: No + */ +#include "script_component.hpp" +params["_unit"]; + +//Get the classname of the spare barrel for the weapon +private _weaponBarrelClass = getText (configFile >> 'CfgWeapons' >> currentWeapon _player >> QGVAR(barrelClassname)); +//If the weapon has no defined classname then use the ACE one +if(_weaponBarrelClass == "") then { + _weaponBarrelClass = "ACE_SpareBarrel"; +}; +//Check if the player has the barrel and the weapon can have its barrel swapped +private _canCheckTemperature = GVAR(enabled) && {_weaponBarrelClass in magazines _player}; + +_canCheckTemperature; \ No newline at end of file diff --git a/addons/overheating/functions/fnc_canSwapBarrel.sqf b/addons/overheating/functions/fnc_canSwapBarrel.sqf new file mode 100644 index 0000000000..f68e4ccac8 --- /dev/null +++ b/addons/overheating/functions/fnc_canSwapBarrel.sqf @@ -0,0 +1,26 @@ +/* + * Author: Grey-Soldierman + * Return true if player can swap barrel + * + * Arguments: + * 0: Player + * 1: Weapon + * Return Value: + * Bool + * + * Public: No + */ +#include "script_component.hpp" +params["_unit","_weapon"]; + +//Check if weapon can have its barrel swapped. If not exit out of function +if( !GVAR(enabled) && (getNumber (configFile >> 'CfgWeapons' >> _weapon >> QGVAR(allowSwapBarrel))) != 1) exitWith{false}; + +//Get the classname of the spare barrel for the weapon +private _weaponBarrelClass = getText (configFile >> 'CfgWeapons' >> _weapon >> QGVAR(barrelClassname)); +//If the weapon has no defined classname then use the ACE one +if(_weaponBarrelClass == "") then { + _weaponBarrelClass = "ACE_SpareBarrel"; +}; +//If the player has the spare barrel then it can be swapped +(_weaponBarrelClass in magazines _unit) \ No newline at end of file diff --git a/addons/overheating/functions/fnc_loadCoolestSpareBarrel.sqf b/addons/overheating/functions/fnc_loadCoolestSpareBarrel.sqf index 5f0b3ae3a9..fa5cdd1c43 100644 --- a/addons/overheating/functions/fnc_loadCoolestSpareBarrel.sqf +++ b/addons/overheating/functions/fnc_loadCoolestSpareBarrel.sqf @@ -20,9 +20,13 @@ params ["_assistant", "_gunner", "_weapon", "_weaponTemp", "_barrelMass"]; TRACE_5("loadCoolestSpareBarrel1",_assistant,_gunner,_weapon,_weaponTemp,_barrelMass); - +private _weaponBarrelClass = getText (configFile >> 'CfgWeapons' >> _weapon >> QGVAR(barrelClassname)); +//If the weapon has no defined classname then use the ACE one +if(_weaponBarrelClass == "") then { + _weaponBarrelClass = "ACE_SpareBarrel"; +}; // Find all spare barrel the player has -private _allBarrels = [_assistant, "ACE_SpareBarrel"] call CBA_fnc_getMagazineIndex; +private _allBarrels = [_assistant, _weaponBarrelClass] call CBA_fnc_getMagazineIndex; TRACE_1("_allBarrels",_allBarrels); if ((count _allBarrels) < 1) exitWith {}; diff --git a/addons/overheating/functions/fnc_sendSpareBarrelsTemperaturesHint.sqf b/addons/overheating/functions/fnc_sendSpareBarrelsTemperaturesHint.sqf index 8bca16c589..3855f96d3f 100644 --- a/addons/overheating/functions/fnc_sendSpareBarrelsTemperaturesHint.sqf +++ b/addons/overheating/functions/fnc_sendSpareBarrelsTemperaturesHint.sqf @@ -19,7 +19,15 @@ params ["_player","_unit"]; // Find all spare barrel the player has TRACE_2("sendSpareBarrelsTemperatureHunt",_player,_unit); -private _allBarrels = [_unit, "ACE_SpareBarrel"] call CBA_fnc_getMagazineIndex; +//Get the weapon of the target unit +private _weapon = currentWeapon _player; +//Get the classname of the spare barrel of that weapon +private _weaponBarrelClass = getText (configFile >> 'CfgWeapons' >> _weapon >> QGVAR(barrelClassname)); +//If the weapon has no defined classname then use the ACE one +if(_weaponBarrelClass == "") then { + _weaponBarrelClass = "ACE_SpareBarrel"; +}; +private _allBarrels = [_unit, _weaponBarrelClass] call CBA_fnc_getMagazineIndex; TRACE_1("_allBarrels",_allBarrels); if ((count _allBarrels) < 1) exitWith {};