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
This commit is contained in:
Josuan Albin 2018-10-24 19:55:12 +02:00 committed by PabstMirror
parent 25f36d9340
commit 8580cb250a
3 changed files with 25 additions and 14 deletions

View File

@ -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)];
};

View File

@ -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;

View File

@ -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;