Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AI - Fix units not being removed from the garrison unitMove list consistently #6651

Merged
merged 3 commits into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;