2015-09-01 23:23:32 +00:00
/*
2015-09-05 03:40:00 +00:00
DMS_fnc_AILocalityManager
2015-09-01 23:23:32 +00:00
Created by Defent and eraser1
2016-05-07 03:44:48 +00:00
Offloads AI groups to a nearby client in order to improve server performance.
2015-09-01 23:23:32 +00:00
*/
2016-05-07 03:44:48 +00:00
if (!DMS_ai_offload_to_client) exitWith {};
2015-09-01 23:23:32 +00:00
{
2015-09-20 05:37:13 +00:00
if (((count (units _x))>1) && {!((DMS_ai_offload_Only_DMS_AI && {!(_x getVariable ["DMS_SpawnedGroup",false])}) || {(_x getVariable ["DMS_LockLocality",false])})}) then
2015-09-01 23:23:32 +00:00
{
2016-05-07 03:44:48 +00:00
private _leader = leader _x;
private _group = _x;
2015-09-01 23:23:32 +00:00
if ((!isNull _leader) && {(alive _leader) && {!isPlayer _leader}}) then
{
2016-05-07 03:44:48 +00:00
if (DMS_DEBUG) then
2015-09-01 23:23:32 +00:00
{
2016-05-07 03:44:48 +00:00
(format ["AILocalityManager :: Finding owner for group: %1",_group]) call DMS_fnc_DebugLog;
};
2015-09-02 17:16:22 +00:00
2016-05-07 03:44:48 +00:00
private _groupOwner = groupOwner _group;
private _ownerObj = objNull;
2016-05-15 18:55:18 +00:00
private _isLocal = local _group;
2015-09-01 23:23:32 +00:00
2016-05-15 18:55:18 +00:00
if !(_isLocal) then // Only check for the group owner in players if it doesn't belong to the server.
2016-05-07 03:44:48 +00:00
{
2015-09-02 17:16:22 +00:00
{
2016-05-07 03:44:48 +00:00
if (_groupOwner isEqualTo (owner _x)) exitWith
2015-11-15 02:08:41 +00:00
{
2016-05-07 03:44:48 +00:00
_ownerObj = _x;
2015-11-15 02:08:41 +00:00
};
2016-05-07 03:44:48 +00:00
} forEach allPlayers;
};
// If the owner doesn't exist or is too far away... Attempt to set a new player owner, and if none are found... and if the group doesn't belong to the server...
2016-05-15 18:55:18 +00:00
if (((isNull _ownerObj) || {(_ownerObj distance2D _leader)>3500}) && {!([_group,_leader] call DMS_fnc_SetAILocality)} && {!_isLocal}) then
2015-09-01 23:23:32 +00:00
{
2016-05-07 03:44:48 +00:00
// Reset locality to the server
_group setGroupOwner 2;
if (DMS_DEBUG) then
2015-09-02 17:16:22 +00:00
{
2016-05-07 03:44:48 +00:00
(format ["AILocalityManager :: Current owner of group %1 is too far away and no other viable owner found; resetting ownership to the server.",_group]) call DMS_fnc_DebugLog;
2015-09-02 17:16:22 +00:00
};
2015-09-01 23:23:32 +00:00
};
};
};
2016-05-07 03:44:48 +00:00
} forEach allGroups;