2016-05-22 05:05:16 +00:00
|
|
|
/*
|
|
|
|
DMS_fnc_FreezeManager
|
|
|
|
Created by eraser1
|
|
|
|
|
|
|
|
Determines which AI groups (if any) to "freeze" in order to improve server performance, and will "un-freeze" frozen AI when a player is nearby.
|
|
|
|
This function will also offload AI after "un-freezing" if configured to do so.
|
|
|
|
|
|
|
|
NOTE: If you want this function to ignore a specific group, then you can set the variable "DMS_AllowFreezing" on the group to false.
|
|
|
|
eg: _group setVariable ["DMS_AllowFreezing",false]
|
|
|
|
*/
|
|
|
|
|
|
|
|
private _recentlyUnfrozen = [];
|
|
|
|
|
|
|
|
{
|
|
|
|
if (isNull _x) then
|
|
|
|
{
|
2016-07-06 00:16:06 +00:00
|
|
|
diag_log format["DMS SORT OF AN ERROR :: Null Group found in DMS_FrozenAIGroups! Index: %1",_forEachIndex];
|
2016-05-22 05:05:16 +00:00
|
|
|
DMS_FrozenAIGroups deleteAt _forEachIndex;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
private _leader = leader _x;
|
|
|
|
if ([_leader,DMS_ai_unfreezingDistance] call DMS_fnc_IsPlayerNearby) then
|
|
|
|
{
|
2016-05-22 20:15:38 +00:00
|
|
|
[_x,false] call DMS_fnc_FreezeToggle;
|
2016-05-22 05:05:16 +00:00
|
|
|
_recentlyUnfrozen pushBack _x;
|
|
|
|
|
|
|
|
if (DMS_ai_offloadOnUnfreeze) then
|
|
|
|
{
|
2016-05-22 20:15:38 +00:00
|
|
|
[_x, _leader] call DMS_fnc_SetAILocality;
|
2016-05-22 05:05:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (DMS_DEBUG) then
|
|
|
|
{
|
|
|
|
format["FreezeManager :: Un-froze AI Group: %1",_x] call DMS_fnc_DebugLog;
|
|
|
|
};
|
|
|
|
|
|
|
|
DMS_FrozenAIGroups deleteAt _forEachIndex;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
} forEach DMS_FrozenAIGroups;
|
|
|
|
|
|
|
|
|
2016-06-07 03:47:15 +00:00
|
|
|
if (DMS_ai_allowFreezing) then
|
2016-05-22 05:05:16 +00:00
|
|
|
{
|
2016-06-07 03:47:15 +00:00
|
|
|
{
|
|
|
|
if (((count (units _x))>1) && {_x getVariable ["DMS_AllowFreezing",true]} && {!(DMS_ai_freeze_Only_DMS_AI && {!(_x getVariable ["DMS_SpawnedGroup",false])})}) then
|
|
|
|
{
|
|
|
|
private _leader = leader _x;
|
|
|
|
private _group = _x;
|
2016-05-22 05:05:16 +00:00
|
|
|
|
2016-06-07 03:47:15 +00:00
|
|
|
if (!(isPlayer _leader) && {!([_leader,DMS_ai_freezingDistance] call DMS_fnc_IsPlayerNearby)}) then
|
|
|
|
{
|
|
|
|
[_group,true] call DMS_fnc_FreezeToggle;
|
2016-05-22 20:15:38 +00:00
|
|
|
|
2016-06-07 03:47:15 +00:00
|
|
|
if (DMS_DEBUG) then
|
|
|
|
{
|
|
|
|
format["FreezeManager :: Froze AI Group: %1",_group] call DMS_fnc_DebugLog;
|
|
|
|
};
|
2016-05-22 05:05:16 +00:00
|
|
|
|
2016-06-07 03:47:15 +00:00
|
|
|
// So that we don't check this group for freezing later on.
|
|
|
|
_group setVariable ["DMS_AllowFreezing",false];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
} forEach allGroups;
|
|
|
|
};
|
2016-05-22 05:05:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
// NOW we allow them to be frozen again, so we avoid checking for nearby players TWICE on a group(s) that has just been un-frozen.
|
|
|
|
{
|
|
|
|
_x setVariable ["DMS_AllowFreezing", true];
|
|
|
|
} forEach _recentlyUnfrozen;
|