Skip to content

Commit

Permalink
Linkingbelt refactoring (#5213)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Phyma authored and PabstMirror committed May 29, 2017
1 parent 3b7a304 commit 95ade30
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 20 deletions.
2 changes: 1 addition & 1 deletion addons/reload/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion addons/reload/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

PREP(canCheckAmmo);
PREP(canLinkBelt);
PREP(getAmmoToLinkBelt);
PREP(checkAmmo);
PREP(displayAmmo);
PREP(startLinkingBelt);
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
/*
* Author: esteldunedain
* Author: esteldunedain, phyma
* Check if the target has an MG equiped with belt system that the player can link
*
* Arguments:
* 0: Player <OBJECT>
* 1: Target <OBJECT>
*
* Return Value:
* Can link belt<BOOL>
* Maximum ammo of magazine (-1 on error) <NUMBER>
*
* Example:
* [player, cursorObject] call ace_reload_fnc_canLinkBelt;
* [player, cursorObject] call ace_reload_fnc_getAmmoToLinkBelt;
*
* Public: No
*/
#include "script_component.hpp"

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
Expand All @@ -39,4 +39,4 @@ private _maxAmmo = 0;
_maxAmmo = _maxAmmo max (_x select 1);
} forEach (magazinesAmmo _player select {_x select 0 == _magazineType});

_maxAmmo > 0
_maxAmmo
14 changes: 3 additions & 11 deletions addons/reload/functions/fnc_startLinkingBelt.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 95ade30

Please sign in to comment.