DMS_Exile/@ExileServer/addons/a3_dms/scripts/fn_FreezeManager.sqf

80 lines
2.7 KiB
Plaintext
Raw Normal View History

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
{
diag_log format["DMS ERROR :: Null Group found in DMS_FrozenAIGroups! Index: %1 | You might want to consider reducing the value of 'DMS_ai_freezeCheckingDelay'! Current value: %2",_forEachIndex,DMS_ai_freezeCheckingDelay];
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
if !(isPlayer _leader) then
{
// Ignore Exile flyovers.
if (((side _group) isEqualTo independent) && {(count (units _group)) isEqualTo 1}) exitWith {};
2016-05-22 20:15:38 +00:00
if !([_leader,DMS_ai_freezingDistance] call DMS_fnc_IsPlayerNearby) then
2016-06-07 03:47:15 +00:00
{
[_group,true] call DMS_fnc_FreezeToggle;
2016-05-22 05:05:16 +00:00
if (DMS_DEBUG) then
{
format["FreezeManager :: Froze AI Group: %1",_group] call DMS_fnc_DebugLog;
};
// So that we don't check this group for freezing later on.
_group setVariable ["DMS_AllowFreezing",false];
};
};
2016-06-07 03:47:15 +00:00
};
} 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;