Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AdlerSalbei committed Oct 22, 2023
1 parent e932b67 commit e7857d0
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 15 deletions.
33 changes: 24 additions & 9 deletions addons/functions/functions/fnc_addDigger.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,38 @@ private _condition = if (!isNil "_diggingType" && {_diggingType == "DOWN"}) then
}
};

private _handle = [
[
{
params ["_args", "_handle"];
_args params ["_unit", "_trench", "_condition"];

if (isNull _trench || {[_trench] call _condition} || {!alive _unit}) then {
systemChat "Helping";

if (isNull _trench || {[_trench] call _condition} || {!alive _unit}) exitWith {

systemChat "Stopped PFH Help 1";

[_handle] call CBA_fnc_removePerFrameHandler;
_unit setVariable [QGVAR(diggingTrench), false, true];
[QGVAR(handleDiggerToGVAR), [_trench, _unit, true]] call CBA_fnc_serverEvent;
};

if (_unit getVariable [QGVAR(diggingTrench), false] && {((_trench getVariable [QGVAR(diggers), []]) select 0) isEqualTo ([] call CBA_fnc_currentUnit)}) then {
if (_unit getVariable [QGVAR(diggingTrench), false] && {((_trench getVariable [QGVAR(diggers), []]) select 0) isEqualTo ([] call CBA_fnc_currentUnit)}) exitWith {

systemChat "Stopped PFH Help 2";

[_handle] call CBA_fnc_removePerFrameHandler;
[_trench, _unit, true] call FUNC(continueDiggingTrench);
};

if !(_unit getVariable [QGVAR(diggingTrench), false]) exitWith {

systemChat "Stopped PFH Help 3";

[_handle] call CBA_fnc_removePerFrameHandler;
[QGVAR(handleDiggerToGVAR), [_trench, _unit, true]] call CBA_fnc_serverEvent;
};

// Fatigue impact
ace_advanced_fatigue_anReserve = (ace_advanced_fatigue_anReserve - (2 * GVAR(buildFatigueFactor))) max 0;
ace_advanced_fatigue_anFatigue = (ace_advanced_fatigue_anFatigue + (GVAR(buildFatigueFactor) / 1000)) min 0.8; // 2 * GVAR(buildFatigueFactor) / 2000
Expand All @@ -74,21 +92,18 @@ private _handle = [

// Create progress bar
private _fnc_onFinish = {
(_this select 0) params ["_unit", "_trench", "", "_handle"];
(_this select 0) params ["_unit", "_trench", ""];

_unit setVariable [QGVAR(diggingTrench), false, true];
[_handle] call CBA_fnc_removePerFrameHandler;

// Reset animation
[_unit, "", 1] call ace_common_fnc_doAnimation;
};

private _fnc_onFailure = {
(_this select 0) params ["_unit", "_trench", "", "_handle"];
(_this select 0) params ["_unit", "_trench", ""];

[QGVAR(handleDiggerToGVAR), [_trench, _unit, true]] call CBA_fnc_serverEvent;
[_handle] call CBA_fnc_removePerFrameHandler;
_unit setVariable [QGVAR(diggingTrench), false, true];
systemChat "Stopped Help Bar";

// Reset animation
[_unit, "", 1] call ace_common_fnc_doAnimation;
Expand Down
26 changes: 21 additions & 5 deletions addons/functions/functions/fnc_continueDiggingTrench.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,23 @@ _trench setVariable ["ace_trenches_digging", true, true];
_trench setVariable [QGVAR(diggingType), "UP", true];
_unit setVariable [QGVAR(diggingTrench), true, true];

private _diggerCount = count (_trench getVariable [QGVAR(diggers), []]);
private _diggers = (_trench getVariable [QGVAR(diggers), []]);

if (_diggerCount > 0 && {!_switchingDigger}) exitWith {
if (count _diggers > 0 && {!_switchingDigger}) exitWith {
[_trench, _unit] call FUNC(addDigger);
};

private _digTime = missionNamespace getVariable [getText (configOf _trench >> "ace_trenches_diggingDuration"), 20];
_diggers pushBackUnique _unit;
_trench setVariable [QGVAR(diggers), _diggers, true];

_trench setVariable [QGVAR(diggers), [_unit], true];
private _digTime = missionNamespace getVariable [getText (configOf _trench >> "ace_trenches_diggingDuration"), 20];

// Create progress bar
private _fnc_onFinish = {
(_this select 0) params ["_unit", "_trench"];

systemChat "Done";

_unit setVariable [QGVAR(diggingTrench), false, true];
[QGVAR(handleTrenchState), [_trench]] call CBA_fnc_serverEvent;
[QGVAR(handleDiggerToGVAR), [_trench, _unit, false, true]] call CBA_fnc_serverEvent;
Expand All @@ -55,6 +58,9 @@ private _fnc_onFinish = {
};
private _fnc_onFailure = {
(_this select 0) params ["_unit", "_trench"];

systemChat "Stopped Continue Bar";

_unit setVariable [QGVAR(diggingTrench), false, true];
[QGVAR(handleDiggerToGVAR), [_trench, _unit, true]] call CBA_fnc_serverEvent;

Expand All @@ -66,9 +72,10 @@ private _fnc_onFailure = {
[_unit, "", 1] call ace_common_fnc_doAnimation;
};
private _fnc_condition = {
(_this select 0) params ["", "_trench"];
(_this select 0) params ["_unit", "_trench"];

if !(_trench getVariable ["ace_trenches_digging", false]) exitWith {false};
if !(_unit getVariable [QGVAR(diggingTrench), false]) exitWith {false};
if (count (_trench getVariable [QGVAR(diggers),[]]) <= 0) exitWith {false};
if (GVAR(stopBuildingAtFatigueMax) && (ace_advanced_fatigue_anReserve <= 0)) exitWith {false};

Expand All @@ -92,19 +99,28 @@ if (_actualProgress == 0) then {
params ["_args", "_handle"];
_args params ["_trench", "_unit", "_digTime"];

systemChat "UP";

private _actualProgress = _trench getVariable ["ace_trenches_progress", 0];
private _diggerCount = count (_trench getVariable [QGVAR(diggers), []]);

if (
!(_trench getVariable ["ace_trenches_digging", false]) ||
{!(_unit getVariable [QGVAR(diggingTrench), false])} ||
{_diggerCount <= 0}
) exitWith {

systemChat "Stopped PFH continue 1";

[_handle] call CBA_fnc_removePerFrameHandler;
_trench setVariable ["ace_trenches_digging", false, true];
[QGVAR(handleDiggerToGVAR), [_trench, _unit, true]] call CBA_fnc_serverEvent;
};

if (_actualProgress >= 1) exitWith {

systemChat "Stopped PFH continue 2";

[_handle] call CBA_fnc_removePerFrameHandler;
};

Expand Down
1 change: 1 addition & 0 deletions addons/functions/functions/fnc_handleDiggerToGVAR.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ if (_removeAll) then {
if (count _diggingPlayers <= 0) then {
[QGVAR(handleTrenchState), [_trench]] call CBA_fnc_serverEvent;
};

_trench setVariable [QGVAR(diggers), _diggingPlayers, true];
15 changes: 14 additions & 1 deletion addons/functions/functions/fnc_removeTrench.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ _trench setVariable [QGVAR(diggers), [_unit], true];
private _fnc_onFinish = {
(_this select 0) params ["_unit", "_trench"];

systemChat "Deleted";

[_trench, _unit] call FUNC(deleteTrench);

// Reset animation
Expand All @@ -54,6 +56,8 @@ private _fnc_onFinish = {
private _fnc_onFailure = {
(_this select 0) params ["_unit", "_trench"];

systemChat "Stopped";

_unit setVariable [QGVAR(diggingTrench), false, true];
[QGVAR(handleDiggerToGVAR), [_trench, _unit, true]] call CBA_fnc_serverEvent;

Expand All @@ -68,9 +72,10 @@ private _fnc_onFailure = {
[QGVAR(resetDecay), [_trench]] call CBA_fnc_serverEvent;
};
private _fnc_condition = {
(_this select 0) params ["", "_trench"];
(_this select 0) params ["_unit", "_trench"];

if !(_trench getVariable ["ace_trenches_digging", false]) exitWith {false};
if !(_unit getVariable [QGVAR(diggingTrench), false]) exitWith {false};
if (count (_trench getVariable [QGVAR(diggers), []]) <= 0) exitWith {false};
if (GVAR(stopBuildingAtFatigueMax) && {ace_advanced_fatigue_anReserve <= 0}) exitWith {false};

Expand All @@ -83,19 +88,27 @@ private _fnc_condition = {
params ["_args", "_handle"];
_args params ["_trench", "_unit", "_removeTime"];

systemChat "Down";

private _actualProgress = _trench getVariable ["ace_trenches_progress", 0];
private _diggerCount = count (_trench getVariable [QGVAR(diggers), []]);

if (
!(_trench getVariable ["ace_trenches_digging", false]) ||
{!(_unit getVariable [QGVAR(diggingTrench), false])} ||
{_diggerCount <= 0}
) exitWith {

systemChat "Stopped PFH remove 1";

[_handle] call CBA_fnc_removePerFrameHandler;
_trench setVariable ["ace_trenches_digging", false, true];
[QGVAR(handleDiggerToGVAR), [_trench, _unit, false, true]] call CBA_fnc_serverEvent;
};

if (_actualProgress <= 0) exitWith {

systemChat "Stopped PFH remove 2";
[_handle] call CBA_fnc_removePerFrameHandler;
};

Expand Down

0 comments on commit e7857d0

Please sign in to comment.