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

105 lines
3.0 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]
*/
{
2016-09-01 19:48:58 +00:00
private _leader = leader _x;
private _units = units _x;
if (_x getVariable ["DMS_isGroupFrozen",false]) then
2016-05-22 05:05:16 +00:00
{
if ([_leader,DMS_ai_unfreezingDistance] call DMS_fnc_IsPlayerNearby) then
{
2016-09-01 19:48:58 +00:00
{
_x enableSimulationGlobal true;
2017-04-25 02:21:29 +00:00
if!(dynamicSimulationEnabled (vehicle _x))then
{
(vehicle _x) enableSimulationGlobal true;
};
2016-09-01 19:48:58 +00:00
} forEach _units;
_x setVariable ["DMS_isGroupFrozen",false];
2016-05-22 05:05:16 +00:00
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
};
2016-09-01 19:48:58 +00:00
2016-05-22 05:05:16 +00:00
if (DMS_DEBUG) then
{
format["FreezeManager :: Un-froze AI Group: %1",_x] call DMS_fnc_DebugLog;
};
};
2016-09-01 19:48:58 +00:00
}
else
{
if (DMS_ai_allowFreezing) then
{
private _canFreeze = false;
2016-05-22 05:05:16 +00:00
2016-09-01 19:48:58 +00:00
try
{
if !(_x getVariable ["DMS_AllowFreezing",true]) throw "not allowed to be frozen";
2016-05-22 05:05:16 +00:00
2016-09-01 19:48:58 +00:00
if ((side _x) isEqualTo independent) then
{
{
if (isPlayer _x) throw "player group";
} forEach _units;
if ((count _units) isEqualTo 1) throw "Exile flyover (probably)";
};
if (DMS_ai_freeze_Only_DMS_AI && {!(_x getVariable ["DMS_SpawnedGroup",false])}) throw "not a DMS-spawned group";
2016-05-22 05:05:16 +00:00
2016-09-01 19:48:58 +00:00
_canFreeze = true;
}
catch
{
2016-09-01 19:48:58 +00:00
// Mark the group to speed up future checks
_x setVariable ["DMS_AllowFreezing",false];
if (DMS_DEBUG) then
{
format["FreezeManager :: Cannot freeze group ""%1"": %2", _x, _exception] call DMS_fnc_DebugLog;
};
};
2016-05-22 20:15:38 +00:00
2016-09-01 19:48:58 +00:00
if (_canFreeze) then
{
if !([_leader,DMS_ai_freezingDistance] call DMS_fnc_IsPlayerNearby) then
2016-06-07 03:47:15 +00:00
{
2016-09-01 19:48:58 +00:00
{
_x enableSimulationGlobal false;
2017-04-25 02:21:29 +00:00
if!(dynamicSimulationEnabled (vehicle _x))then
{
(vehicle _x) enableSimulationGlobal false;
};
2016-09-01 19:48:58 +00:00
} forEach _units;
_x setVariable ["DMS_isGroupFrozen",true];
2016-05-22 05:05:16 +00:00
if (DMS_DEBUG) then
{
2016-09-01 19:48:58 +00:00
format["FreezeManager :: Froze AI Group: %1",_x] call DMS_fnc_DebugLog;
};
};
};
2016-09-01 19:48:58 +00:00
};
};
} forEach allGroups;