Skip to content

Commit

Permalink
AI - Fix units not being removed from the garrison unitMove list cons…
Browse files Browse the repository at this point in the history
…istently (#6651)

* Fix units not being removed from the garrison unitMove list consistently

Not sure how I missed that.

* fix whitespace

* Fix typo in unGarrison check

dedmen saw nothing :D
  • Loading branch information
alganthe authored and PabstMirror committed Oct 24, 2018
1 parent a2c0b2c commit 2d1c1c4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
7 changes: 7 additions & 0 deletions addons/ai/functions/fnc_garrison.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ params [["_startingPos",[0,0,0], [[]], 3], ["_buildingTypes", ["Building"], [[]]
TRACE_6("fnc_garrison: Start",_startingPos,_buldingTypes,count _unitsArray,_fillingRadius,_fillingTYpe,_topDownFilling);

_unitsArray = _unitsArray select {alive _x && {!isPlayer _x}};
private _currentUnitMoveList = missionNameSpace getVariable [QGVAR(garrison_unitMoveList), []];

if (_startingPos isEqualTo [0,0,0]) exitWith {
TRACE_1("fnc_garrison: StartingPos error",_startingPos);
Expand Down Expand Up @@ -145,6 +146,8 @@ switch (_fillingType) do {
_unit setPosATL _pos;
};

_currentUnitMoveList deleteAt (_currentUnitMoveList findIf {_x select 0 == _unit});

} else {
_unitMoveList pushBack [_unit,[_pos, AGLToASL _pos] select (_posSurface)];
};
Expand Down Expand Up @@ -192,6 +195,8 @@ switch (_fillingType) do {
_unit setPosATL _pos;
};

_currentUnitMoveList deleteAt (_currentUnitMoveList findIf {_x select 0 == _unit});

} else {
_unitMoveList pushBack [_unit,[_pos, AGLToASL _pos] select (_posSurface)];
};
Expand Down Expand Up @@ -237,6 +242,8 @@ switch (_fillingType) do {
_unit setPosATL _pos;
};

_currentUnitMoveList deleteAt (_currentUnitMoveList findIf {_x select 0 == _unit});

} else {
_unitMoveList pushBack [_unit,[_pos, AGLToASL _pos] select (_posSurface)];
};
Expand Down
4 changes: 2 additions & 2 deletions addons/ai/functions/fnc_garrisonMove.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ if (isNil QGVAR(garrison_moveUnitPFH)) then {
};

// Check if unit is alive or even existing
if (!alive _unit) then {
if (!alive _unit || {_unit getVariable [QGVAR(garrisoned), false]}) then {
_unitMoveList deleteAt (_unitMoveList find _x);
LOG(format [ARR_2("garrisonMove PFH: unit dead or deleted | %1 units left", count _unitMoveList)]);
LOG(format [ARR_2("garrisonMove PFH: unit dead, deleted or garrisoned via TP | %1 units left", count _unitMoveList)]);

} else {
private _unitPos = getPos _unit;
Expand Down
28 changes: 16 additions & 12 deletions addons/ai/functions/fnc_unGarrison.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,31 @@ params [["_units", [], [[]]]];
_units = _units select {local _x};

{
if (!isPlayer _x && {local _x}) then {
_x enableAI "PATH";
_x enableAI "FSM";
private _unit = _x;
if (!isPlayer _unit && {local _unit}) then {
_unit enableAI "PATH";
_unit enableAI "FSM";

private _leader = leader _x;
private _leader = leader _unit;

TRACE_3("fnc_ungarrison: unit and leader",_x , _leader, (_leader == _x));
TRACE_3("fnc_ungarrison: unit and leader",_unit , _leader, (_leader == _unit));

_x setVariable [QGVAR(garrisonned), false, true];
_unit setVariable [QGVAR(garrisonned), false, true];

if (_leader != _x) then {
doStop _x;
_x doFollow _leader;
private _unitMoveList = missionNameSpace getVariable [QGVAR(garrison_unitMoveList), []];
_unitMoveList deleteAt (_unitMoveList findIf {_x select 0 == _unit});

if (_leader != _unit) then {
doStop _unit;
_unit doFollow _leader;

} else {
_x doMove ((nearestBuilding (getPos _x)) buildingExit 0);
_unit doMove ((nearestBuilding (getPos _unit)) buildingExit 0);
};

if ({(_x getVariable [QGVAR(garrisonned), false]) && !isPlayer _x} count (units _x) == 0) then {
if ((units _unit) findif {(_x getVariable [QGVAR(garrisonned), false]) && !isPlayer _x} == -1) then {
LOG("fnc_ungarrison: enableAttack true");
(group _x) enableAttack true;
(group _unit) enableAttack true;
};
};
} foreach _units;

0 comments on commit 2d1c1c4

Please sign in to comment.