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

52 lines
1.4 KiB
Plaintext
Raw Normal View History

2015-09-01 23:23:32 +00:00
/*
DMS_fnc_AILocalityManager
2015-09-01 23:23:32 +00:00
Created by Defent and eraser1
Offloads AI groups to a nearby client or HC in order to improve server performance.
2015-09-01 23:23:32 +00:00
*/
if (!DMS_ai_offload_to_client && {isNull DMS_HC_Object}) exitWith {};
2015-09-01 23:23:32 +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
{
private ["_leader", "_group", "_owner"];
_leader = leader _x;
_group = _x;
if ((!isNull _leader) && {(alive _leader) && {!isPlayer _leader}}) then
{
2015-09-02 17:16:22 +00:00
if (isNull DMS_HC_Object) then
2015-09-01 23:23:32 +00:00
{
2015-09-02 18:01:39 +00:00
if (DMS_DEBUG) then
{
diag_log format ["DMS_DEBUG AILocalityManager :: DMS_HC_Object is null! Finding owner for group: %1",_group];
};
2015-09-02 17:16:22 +00:00
_owner = objNull;
2015-09-01 23:23:32 +00:00
{
2015-09-02 17:16:22 +00:00
if ((groupOwner _group) isEqualTo (owner _x)) exitWith
{
_owner = _x;
};
2015-09-04 16:35:19 +00:00
} forEach allPlayers;
2015-09-01 23:23:32 +00:00
2015-09-02 17:16:22 +00:00
if ((isNull _owner) || {(_owner distance2D _leader)>3500}) then
{
[_group,_leader] call DMS_fnc_SetAILocality;
2015-09-02 17:16:22 +00:00
};
}
else
2015-09-01 23:23:32 +00:00
{
if !((groupOwner _group) isEqualTo (owner DMS_HC_Object)) then
2015-09-02 17:16:22 +00:00
{
_transferSuccess = _group setGroupOwner (owner DMS_HC_Object);
if (DMS_DEBUG) then
{
diag_log format ["DMS_DEBUG AILocalityManager :: Setting ownership of group %1 to HC (%2). Success: %3",_group,DMS_HC_Object,_transferSuccess];
};
2015-09-02 17:16:22 +00:00
};
2015-09-01 23:23:32 +00:00
};
};
};
2015-09-04 16:35:19 +00:00
} forEach allGroups;