From 95ade30d56c6996a135d98ee431ccf19b570380a Mon Sep 17 00:00:00 2001 From: Phyma Date: Mon, 29 May 2017 20:49:21 +0200 Subject: [PATCH] Linkingbelt refactoring (#5213) * Linking belt refatoring startLinking belt now uses canLinkBelt so if condition needs to be changed then you can do it on one position. * Fixed requested change Fixed requested change * simplified it even more canLinkBelt now returns a value over 0 if success and -1 if something is not right. * Fixed bug where if error we would not exit Fixed bug where if error we would not exit * changed name on canLinkBelt Changed name to better reflect the function of the function. * Author hype * fixed return value info fixed return value info * fix header --- addons/reload/CfgVehicles.hpp | 2 +- addons/reload/XEH_PREP.hpp | 2 +- ...c_canLinkBelt.sqf => fnc_getAmmoToLinkBelt.sqf} | 14 +++++++------- addons/reload/functions/fnc_startLinkingBelt.sqf | 14 +++----------- 4 files changed, 12 insertions(+), 20 deletions(-) rename addons/reload/functions/{fnc_canLinkBelt.sqf => fnc_getAmmoToLinkBelt.sqf} (73%) diff --git a/addons/reload/CfgVehicles.hpp b/addons/reload/CfgVehicles.hpp index a9fa4deadd..05ac18ea70 100644 --- a/addons/reload/CfgVehicles.hpp +++ b/addons/reload/CfgVehicles.hpp @@ -6,7 +6,7 @@ class CfgVehicles { class GVAR(LinkBelt) { displayName = CSTRING(LinkBelt); distance = 2.0; - condition = QUOTE([ARR_2(_player, _target)] call FUNC(canLinkBelt)); + condition = QUOTE(([ARR_2(_player, _target)] call FUNC(getAmmoToLinkBelt)) > 0); statement = QUOTE([ARR_2(_player, _target)] call FUNC(startLinkingBelt)); }; class GVAR(CheckAmmo) { diff --git a/addons/reload/XEH_PREP.hpp b/addons/reload/XEH_PREP.hpp index bfd89b098e..f2b386ac37 100644 --- a/addons/reload/XEH_PREP.hpp +++ b/addons/reload/XEH_PREP.hpp @@ -1,6 +1,6 @@ PREP(canCheckAmmo); -PREP(canLinkBelt); +PREP(getAmmoToLinkBelt); PREP(checkAmmo); PREP(displayAmmo); PREP(startLinkingBelt); diff --git a/addons/reload/functions/fnc_canLinkBelt.sqf b/addons/reload/functions/fnc_getAmmoToLinkBelt.sqf similarity index 73% rename from addons/reload/functions/fnc_canLinkBelt.sqf rename to addons/reload/functions/fnc_getAmmoToLinkBelt.sqf index d29dc6efd6..decb922d80 100644 --- a/addons/reload/functions/fnc_canLinkBelt.sqf +++ b/addons/reload/functions/fnc_getAmmoToLinkBelt.sqf @@ -1,5 +1,5 @@ /* - * Author: esteldunedain + * Author: esteldunedain, phyma * Check if the target has an MG equiped with belt system that the player can link * * Arguments: @@ -7,10 +7,10 @@ * 1: Target * * Return Value: - * Can link belt + * Maximum ammo of magazine (-1 on error) * * Example: - * [player, cursorObject] call ace_reload_fnc_canLinkBelt; + * [player, cursorObject] call ace_reload_fnc_getAmmoToLinkBelt; * * Public: No */ @@ -18,18 +18,18 @@ params ["_player", "_target"]; -if (vehicle _target != _target) exitWith {false}; +if (vehicle _target != _target) exitWith {-1}; private _magazineType = currentMagazine _target; private _magazineCfg = configFile >> "CfgMagazines" >> _magazineType; -if (getNumber (_magazineCfg >> "ACE_isBelt") == 0) exitWith {false}; +if (getNumber (_magazineCfg >> "ACE_isBelt") == 0) exitWith {-1}; // Check if the ammo is not empty or full private _ammoCount = _target ammo currentWeapon _target; // Exit if the belt is full or empty -if (_ammoCount == 0 || getNumber (_magazineCfg >> "count") - _ammoCount == 0) exitWith {false}; +if (_ammoCount == 0 || getNumber (_magazineCfg >> "count") - _ammoCount == 0) exitWith {-1}; // Check if the player has any of the same magazines // Calculate max ammo @@ -39,4 +39,4 @@ private _maxAmmo = 0; _maxAmmo = _maxAmmo max (_x select 1); } forEach (magazinesAmmo _player select {_x select 0 == _magazineType}); -_maxAmmo > 0 +_maxAmmo diff --git a/addons/reload/functions/fnc_startLinkingBelt.sqf b/addons/reload/functions/fnc_startLinkingBelt.sqf index b43a515a3d..aabfadaf66 100644 --- a/addons/reload/functions/fnc_startLinkingBelt.sqf +++ b/addons/reload/functions/fnc_startLinkingBelt.sqf @@ -17,19 +17,11 @@ if (vehicle _target != _target) exitWith {false}; private _magazineType = currentMagazine _target; -private _canLink = [_player, _target] call FUNC(canLinkBelt); -if ( !_canLink ) exitWith {} ; +private _maxAmmo = [_player, _target] call FUNC(getAmmoToLinkBelt); -// Check if the player has any of the same same magazines -// Calculate max ammo it can link -private _maxAmmo = 0; - -{ - _maxAmmo = _maxAmmo max (_x select 1); -} forEach (magazinesAmmo _player select {_x select 0 == _magazineType}); - -if (_maxAmmo == 0) exitWith {}; +//if _maxAmmo is below 0 we quit +if (_maxAmmo <= 0) exitWith {}; // Condition to call each frame private _condition = {