Skip to content

Commit

Permalink
Improve garrison and task patrols (#403)
Browse files Browse the repository at this point in the history
* Improve satellite patrols rejoin garrison and camp groups

Allows sub-patrols to rejoin main formation on Garrison and Camp tasks
- Good for performance
- Good for combat ability of main group

* Update fnc_taskGarrison.sqf

* Update sqf_linter_LogChecker.py

We all love the linter. <3
  • Loading branch information
nk3nny authored Jul 7, 2024
1 parent 6f37998 commit 721ac5b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
27 changes: 18 additions & 9 deletions addons/wp/functions/fnc_taskCamp.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,37 @@ if (_area isNotEqualTo []) then {

// STAGE 1 - PATROL --------------------------
if (_patrol) then {
private _group2 = createGroup [(side _group), true];
[selectRandom _units] join _group2;
if (count _units > 4) then { [selectRandom units _group] join _group2; };
private _patrolGroup = createGroup [(side _group), true];
[selectRandom _units] join _patrolGroup;
if (count _units > 4) then { [selectRandom units _group] join _patrolGroup; };

// performance
if (dynamicSimulationEnabled _group) then {
[_group2, true] remoteExecCall ["enableDynamicSimulation", 2];
[_patrolGroup, true] remoteExec ["enableDynamicSimulation", 2];
};

// id
_group2 setGroupIDGlobal [format ["Patrol (%1)", groupId _group2]];
_patrolGroup setGroupIDGlobal [format ["Patrol (%1)", groupId _patrolGroup]];

// orders
if (_area isEqualTo []) then {
[_group2, _pos, _range * 2, 4, nil, true] call FUNC(taskPatrol);
[_patrolGroup, _pos, _range * 2, 4, nil, true] call FUNC(taskPatrol);
} else {
private _area2 = +_area;
_area2 set [0, (_area2 select 0) * 2];
_area2 set [0, (_area2 select 1) * 2];
[_group2, _pos, _range * 2, 4, _area2, true] call FUNC(taskPatrol);
[_patrolGroup, _pos, _range * 2, 4, _area2, true] call FUNC(taskPatrol);
};

// eventhandler
_group setVariable [QGVAR(baseGroup), _patrolGroup];
_group addEventHandler ["CombatModeChanged", {
params ["_group"];
private _patrolGroup = _group getVariable [QGVAR(baseGroup), grpNull];
(units _patrolGroup) joinSilent _group;
_group removeEventHandler [_thisEvent, _thisEventHandler];
}];

// update
_units = units _group;
};
Expand Down Expand Up @@ -117,7 +126,7 @@ reverse _units;
},
{
params ["_unit", "_target"];
if (surfaceIsWater (getPos _unit) || (_unit distance _target > 2)) exitWith { _unit doFollow (leader _unit); };
if (surfaceIsWater (getPosASL _unit) || (_unit distance _target > 2)) exitWith { _unit doFollow (leader _unit); };
doStop _unit;
_unit setUnitPos selectRandom ["UP", "UP", "MIDDLE"];
},
Expand Down Expand Up @@ -192,7 +201,7 @@ private _dir = random 360;
unitReady _unit
}, {
params ["_unit", "_target", "_center", "_anim"];
if (surfaceIsWater (getPos _unit) || (_unit distance2D _target > 1)) exitWith { _unit doFollow (leader _unit); };
if (surfaceIsWater (getPosASL _unit) || (_unit distance2D _target > 1)) exitWith { _unit doFollow (leader _unit); };
[_unit, _anim, 2] call EFUNC(main,doAnimation);

_unit disableAI "ANIM";
Expand Down
16 changes: 13 additions & 3 deletions addons/wp/functions/fnc_taskGarrison.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* 1: Position to occupy, default group location <ARRAY or OBJECT>
* 2: Range of tracking, default is 50 meters <NUMBER>
* 3: Area the AI Camps in, default [] <ARRAY>
* 4: Teleprt Units to Position <BOOL>
* 4: Teleport Units to Position <BOOL>
* 5: Sort Based on Height <BOOL>
* 6: Exit Conditions that breaks a Unit free (-2 Random, -1 All, 0 Hit, 1 Fired, 2 FiredNear), default -2 <NUMBER>
* 7: Patrol <BOOL>
Expand Down Expand Up @@ -84,7 +84,7 @@ if (_patrol) then {

// performance
if (dynamicSimulationEnabled _group) then {
[_patrolGroup, true] remoteExecCall ["enableDynamicSimulation", 2];
[_patrolGroup, true] remoteExec ["enableDynamicSimulation", 2];
};

// id
Expand All @@ -99,6 +99,16 @@ if (_patrol) then {
_area2 set [1, (_area2 select 1) * 2];
[_patrolGroup, _pos, _radius, 4, _area2, true] call FUNC(taskPatrol);
};

// eventhandler
_group setVariable [QGVAR(baseGroup), _patrolGroup];
_group addEventHandler ["CombatModeChanged", {
params ["_group"];
private _patrolGroup = _group getVariable [QGVAR(baseGroup), grpNull];
(units _patrolGroup) joinSilent _group;
_group removeEventHandler [_thisEvent, _thisEventHandler];
}];

};

// man static weapons
Expand Down Expand Up @@ -203,7 +213,7 @@ private _fnc_addEventHandler = {
unitReady _unit
}, {
params ["_unit", "_target"];
if (surfaceIsWater (getPos _unit) || (_unit distance _target > 1.5)) exitWith { _unit doFollow (leader _unit); };
if (surfaceIsWater (getPosASL _unit) || (_unit distance _target > 1.5)) exitWith { _unit doFollow (leader _unit); };
_unit disableAI "PATH";
_unit setUnitPos selectRandom ["UP", "UP", "MIDDLE"];
}, [_x, _house]
Expand Down
2 changes: 1 addition & 1 deletion tools/sqf_linter_LogChecker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
import os

defaultFalsePositives = 22
defaultFalsePositives = 26
def main():
f = open("sqf.log", "r")
log = f.readlines()
Expand Down

0 comments on commit 721ac5b

Please sign in to comment.