ACE3/addons/spectator/functions/fnc_updateUnits.sqf

76 lines
2.2 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-07-17 15:02:38 +00:00
* 1: Use blacklist <BOOL> <OPTIONAL>
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
2015-07-17 17:40:49 +00:00
if !(hasInterface) exitWith {};
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
private ["_sides","_cond","_filteredUnits","_filteredGroups"];
2015-07-17 17:40:49 +00:00
2015-07-19 11:09:57 +00:00
// Unit setting filter
_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
2015-07-19 19:19:26 +00:00
_sides = [];
2015-07-20 16:17:23 +00:00
_cond = [{_this == (side group player)},{(_this getFriend (side group player)) >= 0.6},{(_this getFriend (side group player)) < 0.6},{true}] select GVAR(filterSides);
2015-07-19 19:19:26 +00:00
{
if (_x call _cond) then {
_sides pushBack _x;
2015-07-17 23:40:20 +00:00
};
} forEach GVAR(availableSides);
2015-07-17 17:40:49 +00:00
// Filter units and append to list
2015-07-19 11:09:57 +00:00
_filteredUnits = [];
2015-07-17 15:02:38 +00:00
{
if (
(alive _x) &&
{(_x isKindOf "CAManBase")} &&
2015-07-19 19:19:26 +00:00
{(side group _x) in _sides} && // Side filter
2015-07-18 16:13:27 +00:00
{simulationEnabled _x} &&
{!(_x getVariable [QGVAR(isStaged), false])} // Who watches the watchmen?
2015-07-17 15:02:38 +00:00
) then {
2015-07-19 11:09:57 +00:00
_filteredUnits pushBack _x;
2015-07-17 15:02:38 +00:00
};
} forEach (_newUnits - GVAR(unitBlacklist));
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
_filteredGroups = [];
2015-07-24 16:13:03 +00:00
{
// Intentionally re-applied to units in case their status changes
[_x] call FUNC(cacheUnitInfo);
_filteredGroups pushBack (group _x);
2015-07-24 16:13:03 +00:00
} forEach _filteredUnits;
// Replace previous lists entirely (removes any no longer valid)
2015-07-19 11:09:57 +00:00
GVAR(unitList) = _filteredUnits arrayIntersect _filteredUnits;
GVAR(groupList) = _filteredGroups arrayIntersect _filteredGroups;