2015-09-19 22:55:58 +00:00
|
|
|
/*
|
|
|
|
* Author: Glowbal
|
|
|
|
* Stack group switches. Will always trace back to original group.
|
2015-01-16 23:21:47 +00:00
|
|
|
*
|
2015-09-19 22:55:58 +00:00
|
|
|
* Arguments:
|
|
|
|
* 0: Unit <OBJECT>
|
|
|
|
* 1: switch <BOOLEAN>
|
|
|
|
* 2: id <STRING>
|
|
|
|
* 3: side <SIDE>
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
2017-06-08 13:31:51 +00:00
|
|
|
* Example:
|
|
|
|
* [bob, true, "id", SIDE] call ace_common_fnc_switchToGroupSide
|
|
|
|
*
|
2015-09-19 22:55:58 +00:00
|
|
|
* Public: Yes
|
2015-01-16 23:21:47 +00:00
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2017-05-31 21:09:36 +00:00
|
|
|
params [["_unit", objNull], ["_switch", false], ["_id", ""], ["_side", sideUnknown]];
|
2015-09-19 22:55:58 +00:00
|
|
|
|
2015-12-14 12:08:19 +00:00
|
|
|
private _previousGroupsList = _unit getVariable [QGVAR(previousGroupSwitchTo), []];
|
2015-01-16 23:21:47 +00:00
|
|
|
|
|
|
|
if (_switch) then {
|
2015-01-18 19:09:19 +00:00
|
|
|
// go forward
|
2015-12-14 12:08:19 +00:00
|
|
|
private _previousGroup = group _unit;
|
|
|
|
private _originalSide = side group _unit;
|
2015-01-16 23:21:47 +00:00
|
|
|
|
2015-11-30 16:14:05 +00:00
|
|
|
if (count units _previousGroup == 1 && _originalSide == _side) exitWith {
|
2015-09-19 22:55:58 +00:00
|
|
|
[format ["Current group has only 1 member and is of same side as switch. Not switching unit %1", _id]] call FUNC(debug);
|
2015-01-18 19:09:19 +00:00
|
|
|
};
|
2015-01-16 23:21:47 +00:00
|
|
|
|
2015-12-14 12:08:19 +00:00
|
|
|
private _newGroup = createGroup _side;
|
2015-01-18 19:09:19 +00:00
|
|
|
[_unit] joinSilent _newGroup;
|
2015-01-16 23:21:47 +00:00
|
|
|
|
2015-09-19 22:55:58 +00:00
|
|
|
_previousGroupsList pushBack [_previousGroup, _originalSide, _id, true];
|
|
|
|
_unit setVariable [QGVAR(previousGroupSwitchTo), _previousGroupsList, true];
|
2015-01-16 23:21:47 +00:00
|
|
|
} else {
|
2015-01-18 19:09:19 +00:00
|
|
|
// go one back
|
|
|
|
{
|
2015-11-30 16:14:05 +00:00
|
|
|
if (_id == (_x select 2)) exitWith {
|
2015-01-18 19:09:19 +00:00
|
|
|
_x set [ 3, false];
|
2015-09-19 22:55:58 +00:00
|
|
|
_previousGroupsList set [_forEachIndex, _x];
|
2015-01-18 19:09:19 +00:00
|
|
|
[format["found group with ID: %1", _id]] call FUNC(debug);
|
|
|
|
};
|
2015-09-19 22:55:58 +00:00
|
|
|
} forEach _previousGroupsList;
|
|
|
|
|
2015-01-18 19:09:19 +00:00
|
|
|
reverse _previousGroupsList;
|
2015-01-16 23:21:47 +00:00
|
|
|
|
2015-01-18 19:09:19 +00:00
|
|
|
{
|
2015-11-30 16:14:05 +00:00
|
|
|
if (_x select 3) exitWith {}; // stop at first id set to true
|
2015-01-18 19:09:19 +00:00
|
|
|
if !(_x select 3) then {
|
2015-12-14 12:08:19 +00:00
|
|
|
private _currentGroup = group _unit;
|
2015-01-18 19:09:19 +00:00
|
|
|
if (!isNull (_x select 0)) then {
|
|
|
|
[_unit] joinSilent (_x select 0);
|
|
|
|
} else {
|
2015-12-14 12:08:19 +00:00
|
|
|
private _newGroup = createGroup (_x select 1);
|
2015-01-18 19:09:19 +00:00
|
|
|
[_unit] joinSilent _newGroup;
|
|
|
|
};
|
|
|
|
if (count units _currentGroup == 0) then {
|
|
|
|
deleteGroup _currentGroup;
|
|
|
|
};
|
2015-09-19 22:55:58 +00:00
|
|
|
_previousGroupsList set [_forEachIndex, objNull];
|
2015-01-18 19:09:19 +00:00
|
|
|
};
|
2015-09-19 22:55:58 +00:00
|
|
|
} forEach _previousGroupsList;
|
|
|
|
|
2015-01-18 19:09:19 +00:00
|
|
|
_previousGroupsList = _previousGroupsList - [objNull];
|
|
|
|
reverse _previousGroupsList; // we have to reverse again, to ensure the list is in the right order.
|
2015-09-19 22:55:58 +00:00
|
|
|
|
|
|
|
_unit setVariable [QGVAR(previousGroupSwitchTo), _previousGroupsList, true];
|
2015-01-16 23:21:47 +00:00
|
|
|
};
|