From 8580cb250a7d30cedb7b55bd6dd8185fcd5c85ae Mon Sep 17 00:00:00 2001 From: Josuan Albin Date: Wed, 24 Oct 2018 19:55:12 +0200 Subject: [PATCH] AI - Fix units not being removed from the garrison unitMove list consistently (#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 --- addons/ai/functions/fnc_garrison.sqf | 7 ++++++ addons/ai/functions/fnc_garrisonMove.sqf | 4 ++-- addons/ai/functions/fnc_unGarrison.sqf | 28 ++++++++++++++---------- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/addons/ai/functions/fnc_garrison.sqf b/addons/ai/functions/fnc_garrison.sqf index e206ea2589..30238e42a7 100644 --- a/addons/ai/functions/fnc_garrison.sqf +++ b/addons/ai/functions/fnc_garrison.sqf @@ -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); @@ -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)]; }; @@ -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)]; }; @@ -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)]; }; diff --git a/addons/ai/functions/fnc_garrisonMove.sqf b/addons/ai/functions/fnc_garrisonMove.sqf index e3f32f10d6..6bba35fbc3 100644 --- a/addons/ai/functions/fnc_garrisonMove.sqf +++ b/addons/ai/functions/fnc_garrisonMove.sqf @@ -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; diff --git a/addons/ai/functions/fnc_unGarrison.sqf b/addons/ai/functions/fnc_unGarrison.sqf index fa685fdd72..e098f4b130 100644 --- a/addons/ai/functions/fnc_unGarrison.sqf +++ b/addons/ai/functions/fnc_unGarrison.sqf @@ -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;