ACE3/addons/spectator/functions/fnc_updateUnits.sqf

70 lines
2.0 KiB
Plaintext
Raw Normal View History

2015-07-16 10:15:33 +00:00
/*
* Author: SilentSpike
2015-07-17 15:02:38 +00:00
* Adds units to spectator whitelist/blacklist and refreshes the filter units
2015-07-16 10:15:33 +00:00
*
* Arguments:
2015-07-17 17:40:49 +00:00
* 0: Units to add to the whitelist <ARRAY>
2015-10-04 17:30:07 +00:00
* 1: Use blacklist <BOOL> (default: false)
2015-07-16 10:15:33 +00:00
*
* Return Value:
* None <NIL>
*
* Example:
* [allUnits,true] call ace_spectator_fnc_updateUnits
*
* Public: Yes
*/
2015-07-15 13:58:38 +00:00
#include "script_component.hpp"
2015-07-17 15:02:38 +00:00
params [["_newUnits",[],[[]]],["_blacklist",false,[false]]];
2015-07-15 13:58:38 +00:00
2015-07-19 11:09:57 +00:00
// Function only matters on player clients
if (!hasInterface) exitWith {};
2015-07-17 17:40:49 +00:00
2015-07-19 11:09:57 +00:00
// If adding to a list we can exit here, since it won't show up until the UI refreshes anyway
if !(_newUnits isEqualTo []) exitWith {
2015-07-17 15:02:38 +00:00
if (_blacklist) then {
2015-07-16 10:15:33 +00:00
GVAR(unitWhitelist) = GVAR(unitWhitelist) - _newUnits;
GVAR(unitBlacklist) append _newUnits;
2015-07-17 15:02:38 +00:00
} else {
GVAR(unitBlacklist) = GVAR(unitBlacklist) - _newUnits;
GVAR(unitWhitelist) append _newUnits;
2015-07-15 13:58:38 +00:00
};
2015-07-16 10:15:33 +00:00
};
2015-07-15 13:58:38 +00:00
2015-07-19 11:09:57 +00:00
// Unit setting filter
private _newUnits = [[],allPlayers,playableUnits,allUnits] select GVAR(filterUnits);
2015-07-15 13:58:38 +00:00
2015-07-19 11:09:57 +00:00
// Side setting filter
private _sideFilter = [
{_x == (side group player)},
{(_x getFriend (side group player)) >= 0.6},
{(_x getFriend (side group player)) < 0.6},
{true}
] select GVAR(filterSides);
private _filteredSides = GVAR(availableSides) select _sideFilter;
2015-07-17 17:40:49 +00:00
// Filter units and append to list
private _filteredUnits = (_newUnits - GVAR(unitBlacklist)) select {
(alive _x) &&
{(_x isKindOf "CAManBase")} &&
{(side group _x) in _filteredSides} && // Side filter
{simulationEnabled _x} &&
{!(_x getVariable [QGVAR(isStaged), false])} // Who watches the watchmen?
};
2015-07-19 11:09:57 +00:00
_filteredUnits append GVAR(unitWhitelist);
2015-07-17 01:30:00 +00:00
2015-07-24 16:13:03 +00:00
// Cache icons and colour for drawing
private _filteredGroups = [];
2015-07-24 16:13:03 +00:00
{
// Intentionally re-applied to units in case their status changes
[_x] call FUNC(cacheUnitInfo);
_filteredGroups pushBackUnique (group _x);
2015-07-24 16:13:03 +00:00
} forEach _filteredUnits;
// Replace previous lists entirely (removes any no longer valid)
GVAR(groupList) = _filteredGroups;
2015-07-19 11:09:57 +00:00
GVAR(unitList) = _filteredUnits arrayIntersect _filteredUnits;