Skip to content

Commit

Permalink
Parameterized functions, as well as created logic for default value t…
Browse files Browse the repository at this point in the history
…o skip timeout evaluation.
  • Loading branch information
mrzachhigginsofficial committed May 10, 2022
1 parent 282431a commit aa63e9a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
18 changes: 10 additions & 8 deletions addons/ai/fnc_searchNearby.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Author:
---------------------------------------------------------------------------- */

params ["_group"];
params ["_group",["_timeoutcoef",-1],["_maxtimeout",-1]];

_group = _group call CBA_fnc_getGroup;
if !(local _group) exitWith {}; // Don't create waypoints on each machine
Expand All @@ -29,7 +29,7 @@ private _building = nearestBuilding (leader _group);
if ((leader _group) distanceSqr _building > 250e3) exitwith {};

[_group, _building] spawn {
params ["_group", "_building"];
params ["_group", "_building","_timeoutcoef","_maxtimeout"];
private _leader = leader _group;

// Add a waypoint to regroup after the search
Expand All @@ -52,8 +52,12 @@ if ((leader _group) distanceSqr _building > 250e3) exitwith {};
private _positions = _building buildingPos -1;

// Create limiters for each unit
private _timeout = (count _positions * 15) min 120;
private _timetag = "CBASearchTime";
private _timeout = if (_timeoutcoef > -1 && _maxtimeout > -1) then {(
count _positions * _timeoutcoef) min _maxtimeout
} else {
-1
};
private _timetag = QGVAR(StartSearchTime);
{_x setVariable [_timetag,time]} forEach units _group;

while {_positions isNotEqualTo []} do {
Expand All @@ -65,10 +69,8 @@ if ((leader _group) distanceSqr _building > 250e3) exitwith {};

// Send all available units to the next available position
{
private _starttime = _x getVariable _timetag;

if (_positions isEqualTo []) exitWith {};
if (unitReady _x || {_starttime + _timeout < time}) then {
if (unitReady _x || {if (_timeout > -1) then {(_x getVariable _timetag) + _timeout < time} else {false}) then {
private _pos = _positions deleteAt 0;
_x commandMove _pos;
_x setVariable [_timetag,time];
Expand All @@ -79,4 +81,4 @@ if ((leader _group) distanceSqr _building > 250e3) exitwith {};
} forEach _units;
};
_group lockWP false;
};
};
6 changes: 4 additions & 2 deletions addons/ai/fnc_taskSearchArea.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ params [
["_speed", "UNCHANGED", [""]],
["_formation", "NO CHANGE", [""]],
["_onComplete", "", [""]],
["_timeout", [0, 0, 0], [[]], 3]
["_timeout", [0, 0, 0], [[]], 3],
["_timeoutCoef",-1],
["_maxTimeout", -1]
];

_group = _group call CBA_fnc_getGroup;
Expand Down Expand Up @@ -77,7 +79,7 @@ if ((_building distanceSqr _pos) < 400) then {
// Clear waypoint to prevent getting stuck in a search loop
_statements append [
"deleteWaypoint [group this, currentWaypoint (group this)]",
"[group this] call CBA_fnc_searchNearby"
format["[group this,%1,%2] call CBA_fnc_searchNearby",_timeoutCoef,_maxTimeout]
];
};

Expand Down

0 comments on commit aa63e9a

Please sign in to comment.