Skip to content

Commit

Permalink
improved script & changed GVAR name
Browse files Browse the repository at this point in the history
  • Loading branch information
AdlerSalbei committed Aug 23, 2019
1 parent e6de0f2 commit 7fcb859
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 35 deletions.
10 changes: 5 additions & 5 deletions addons/trenches/functions/fnc_addDigger.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@

params ["_trench", "_unit"];

private _diggingPlayers = _trench getVariable [QGVAR(diggingPlayers), []];
private _diggingPlayers = _trench getVariable [QGVAR(diggers), []];

if (
(count _diggingPlayers) < 1
) exitWith {
[_trench, _unit] call FUNC(continueDiggingTrench);
};

[QGVAR(addDigger), [_trench, _unit]] call CBA_fnc_serverEvent;
[QGVAR(addDigger), [_trench, _unit, false]] call CBA_fnc_serverEvent;

private _finishCondition = {false};
private _digTime = 0;
Expand All @@ -48,7 +48,7 @@ private _handle = [{

if (
(_trench getVariable [QGVAR(nextDigger), ACE_player]) == ACE_player &&
{count (_trench getVariable [QGVAR(diggingPlayers), []]) < 1} ||
{count (_trench getVariable [QGVAR(diggers), []]) < 1} ||
{!(_trench getVariable [QGVAR(digging), false])}
) exitWith {
[_handle] call CBA_fnc_removePerFrameHandler;
Expand All @@ -67,7 +67,7 @@ private _fnc_onFinish = {
private _fnc_onFailure = {
(_this select 0) params ["_unit", "_trench"];

[QGVAR(addDigger), [_trench, _unit, false]] call CBA_fnc_serverEvent;
[QGVAR(addDigger), [_trench, _unit, true]] call CBA_fnc_serverEvent;

// Reset animation
[_unit, "", 1] call EFUNC(common,doAnimation);
Expand All @@ -76,7 +76,7 @@ private _fnc_condition = {
(_this select 0) params ["", "_trench", "_handle"];

if (isNil "_handle") exitWith {false};
if (count (_trench getVariable [QGVAR(diggingPlayers),[]]) <= 1) exitWith {false};
if (count (_trench getVariable [QGVAR(diggers),[]]) <= 1) exitWith {false};
if (GVAR(stopBuildingAtFatigueMax) && {QEGVAR(advanced_fatigue,anReserve) <= 0}) exitWith {false};
true
};
Expand Down
2 changes: 1 addition & 1 deletion addons/trenches/functions/fnc_canHelpDiggingTrench.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ params ["_trench", "_unit"];
if !("ACE_EntrenchingTool" in (_unit call EFUNC(common,uniqueItems))) exitWith {false};
if ((_trench getVariable [QGVAR(progress), 0]) >= 1) exitWith {false};
if !(_trench getVariable [QGVAR(digging), false]) exitWith {false};
if (count (_trench getVariable [QGVAR(diggingPlayers),[]]) < 1) exitWith {false};
if (count (_trench getVariable [QGVAR(diggers),[]]) < 1) exitWith {false};

true
14 changes: 7 additions & 7 deletions addons/trenches/functions/fnc_continueDiggingTrench.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ if (_actualProgress >= 1) exitWith {};
// Mark trench as being worked on
_trench setVariable [QGVAR(digging), true, true];
_trench setVariable [QGVAR(diggingType), "UP", true];
private _diggerCount = count (_trench getVariable [QGVAR(diggingPlayers), []]);
private _diggerCount = count (_trench getVariable [QGVAR(diggers), []]);

if (_diggerCount > 0) then {
if !(_switchingDigger) then {
[_trench, _unit] call FUNC(addDigger);
};
} else {
[QGVAR(addDigger), [_trench, _unit, true]] call CBA_fnc_serverEvent;
[QGVAR(addDigger), [_trench, _unit, false]] call CBA_fnc_serverEvent;
};

private _digTime = missionNamespace getVariable [getText (configFile >> "CfgVehicles" >> (typeOf _trench) >> QGVAR(diggingDuration)), 20];
Expand Down Expand Up @@ -65,7 +65,7 @@ private _fnc_onFailure = {
(_this select 0) params ["_unit", "_trench"];
_trench setVariable [QGVAR(digging), false, true];
_trench setVariable [QGVAR(diggingType), nil, true];
[QGVAR(addDigger), [_trench, _unit, false]] call CBA_fnc_serverEvent;;
[QGVAR(addDigger), [_trench, _unit, true]] call CBA_fnc_serverEvent;;

// Save progress global
private _progress = _trench getVariable [QGVAR(progress), 0];
Expand All @@ -79,7 +79,7 @@ private _fnc_condition = {
(_this select 0) params ["", "_trench"];

if !(_trench getVariable [QGVAR(digging), false]) exitWith {false};
if (count (_trench getVariable [QGVAR(diggingPlayers),[]]) <= 0) exitWith {false};
if (count (_trench getVariable [QGVAR(diggers),[]]) <= 0) exitWith {false};
if (GVAR(stopBuildingAtFatigueMax) && {EGVAR(advanced_fatigue,anReserve) <= 0}) exitWith {false};
true
};
Expand All @@ -101,15 +101,15 @@ if (_actualProgress == 0) then {
params ["_args", "_handle"];
_args params ["_trench", "_unit", "_digTime", "_vecDirAndUp"];
private _actualProgress = _trench getVariable [QGVAR(progress), 0];
private _diggerCount = count (_trench getVariable [QGVAR(diggingPlayers), []]);
private _diggerCount = count (_trench getVariable [QGVAR(diggers), []]);

if (
!(_trench getVariable [QGVAR(digging), false]) ||
{_diggerCount <= 0}
) exitWith {
[_handle] call CBA_fnc_removePerFrameHandler;
_trench setVariable [QGVAR(digging), false, true];
[QGVAR(addDigger), [_trench, _unit, false]] call CBA_fnc_serverEvent;
[QGVAR(addDigger), [_trench, _unit, true]] call CBA_fnc_serverEvent;
};

if (_actualProgress >= 1) exitWith {
Expand All @@ -130,7 +130,7 @@ if (_actualProgress == 0) then {
if (GVAR(stopBuildingAtFatigueMax) && {EGVAR(advanced_fatigue,anReserve) <= 0}) exitWith {
[_handle] call CBA_fnc_removePerFrameHandler;
_trench setVariable [QGVAR(digging), false, true];
[QGVAR(addDigger), [_trench, _unit, false]] call CBA_fnc_serverEvent;
[QGVAR(addDigger), [_trench, _unit, true]] call CBA_fnc_serverEvent;
};
}, 1, [_trench, _unit, _digTime, _vecDirAndUp]] call CBA_fnc_addPerFrameHandler;

Expand Down
24 changes: 11 additions & 13 deletions addons/trenches/functions/fnc_handleDiggerToGVAR.sqf
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "script_component.hpp"
/*
* Author: Salbei
* Add or remove a unit to the GVAR
* Add or remove a unit to the global Variable.
*
* Arguments:
* 0: Trench <OBJECT>
* 1: Unit <OBJECT>
* 2: State <BOOLEAN>
* 2: IsRemoveMode <BOOLEAN>
* 3: RemoveAll <BOOLEAN>
*
* Return Value:
Expand All @@ -18,20 +18,18 @@
* Public: No
*/

params ["_trench", "_unit", "_state", ["_removeAll", false]];
params ["_trench", "_unit", "_isRemoveMode", ["_removeAll", false]];

if (_removeAll) exitWith {
_trench setVariable [QGVAR(diggingPlayers), [], true];
_trench setVariable [QGVAR(diggers), [], true];
};

if (_state) then {
private _diggingPlayers = _trench getVariable [QGVAR(diggingPlayers), []];
private _return = _diggingPlayers pushBackUnique _unit;
if (_return > -1) then {
_trench setVariable [QGVAR(diggingPlayers), _diggingPlayers, true];
};
} else {
private _diggingPlayers = _trench getVariable [QGVAR(diggingPlayers), []];
private _diggingPlayers = _trench getVariable [QGVAR(diggers), []];

if (_isRemoveMode) then {
_diggingPlayers - [_unit];
_trench setVariable [QGVAR(diggingPlayers), _diggingPlayers, true];
} else {
_diggingPlayers pushBackUnique _unit;
};

_trench setVariable [QGVAR(diggers), _diggingPlayers, true];
4 changes: 2 additions & 2 deletions addons/trenches/functions/fnc_handleDiggingServer.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ if (_initiator) then {
params ["_args", "_handle"];
_args params ["_trench", "_digTime"];

private _diggingPlayers = _trench getVariable [QGVAR(diggingPlayers), []];
private _diggingPlayers = _trench getVariable [QGVAR(diggers), []];
_diggingPlayers = _diggingPlayers - [objNull];

if !(_diggingPlayers isEqualTo (_trench getVariable [QGVAR(diggingPlayers), []])) then {
if !(_diggingPlayers isEqualTo (_trench getVariable [QGVAR(diggers), []])) then {
[QGVAR(addDigger), [_trench, _unit, true]] call CBA_fnc_serverEvent;
};

Expand Down
14 changes: 7 additions & 7 deletions addons/trenches/functions/fnc_removeTrench.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ if (_actualProgress <= 0) exitWith {};
// Mark trench as being worked on
_trench setVariable [QGVAR(digging), true, true];
_trench setVariable [QGVAR(diggingType), "DOWN", true];
private _diggerCount = count (_trench getVariable [QGVAR(diggingPlayers), []]);
private _diggerCount = count (_trench getVariable [QGVAR(diggers), []]);

if (_diggerCount > 0) then {
if !(_switchingDigger) then {
[_trench, _unit] call FUNC(addDigger);
};
} else {
[QGVAR(addDigger), [_trench, _unit, true]] call CBA_fnc_serverEvent;
[QGVAR(addDigger), [_trench, _unit, false]] call CBA_fnc_serverEvent;
};

private _removeTime = missionNamespace getVariable [getText (configFile >> "CfgVehicles" >> (typeOf _trench) >> QGVAR(removalDuration)), 20];
Expand Down Expand Up @@ -63,7 +63,7 @@ private _fnc_onFailure = {
(_this select 0) params ["_unit", "_trench"];
_trench setVariable [QGVAR(digging), false, true];
_trench setVariable [QGVAR(diggingType), nil, true];
[QGVAR(addDigger), [_trench, _unit, false]] call CBA_fnc_serverEvent;
[QGVAR(addDigger), [_trench, _unit, true]] call CBA_fnc_serverEvent;

// Save progress global
private _progress = _trench getVariable [QGVAR(progress), 0];
Expand All @@ -77,7 +77,7 @@ private _fnc_condition = {
(_this select 0) params ["", "_trench"];

if !(_trench getVariable [QGVAR(digging), false]) exitWith {false};
if (count (_trench getVariable [QGVAR(diggingPlayers),[]]) <= 0) exitWith {false};
if (count (_trench getVariable [QGVAR(diggers),[]]) <= 0) exitWith {false};
if (GVAR(stopBuildingAtFatigueMax) && {EGVAR(advanced_fatigue,anReserve) <= 0}) exitWith {false};
true
};
Expand All @@ -87,7 +87,7 @@ private _fnc_condition = {
params ["_args", "_handle"];
_args params ["_trench", "_unit", "_removeTime", "_vecDirAndUp"];
private _actualProgress = _trench getVariable [QGVAR(progress), 0];
private _diggerCount = count (_trench getVariable [QGVAR(diggingPlayers), []]);
private _diggerCount = count (_trench getVariable [QGVAR(diggers), []]);

if (_actualProgress <= 0) exitWith {
[_handle] call CBA_fnc_removePerFrameHandler;
Expand All @@ -102,7 +102,7 @@ private _fnc_condition = {
) exitWith {
[_handle] call CBA_fnc_removePerFrameHandler;
_trench setVariable [QGVAR(digging), false, true];
[QGVAR(addDigger), [_trench, _unit, false]] call CBA_fnc_serverEvent;
[QGVAR(addDigger), [_trench, _unit, true]] call CBA_fnc_serverEvent;
};

private _pos = getPosWorld _trench;
Expand All @@ -119,7 +119,7 @@ private _fnc_condition = {
if (GVAR(stopBuildingAtFatigueMax) && {EGVAR(advanced_fatigue,anReserve) <= 0}) exitWith {
[_handle] call CBA_fnc_removePerFrameHandler;
_trench setVariable [QGVAR(digging), false, true];
[QGVAR(addDigger), [_trench, _unit, false]] call CBA_fnc_serverEvent;
[QGVAR(addDigger), [_trench, _unit, true]] call CBA_fnc_serverEvent;
};
},1,[_trench, _unit, _removeTime, _vecDirAndUp]] call CBA_fnc_addPerFrameHandler;

Expand Down

0 comments on commit 7fcb859

Please sign in to comment.