a3_exile_occupation/scripts/occupationPlaces.sqf

345 lines
12 KiB
Plaintext
Raw Normal View History

2016-04-12 10:14:07 +00:00
if (!isServer) exitWith {};
2016-04-02 19:06:53 +00:00
private["_wp","_wp2","_wp3"];
2016-04-10 14:42:45 +00:00
_logDetail = format ["[OCCUPATION]:: Starting Occupation Monitor @ %1",time];
2016-04-02 19:06:53 +00:00
[_logDetail] call SC_fnc_log;
_middle = worldSize/2;
_spawnCenter = [_middle,_middle,0]; // Centre point for the map
_maxDistance = _middle; // Max radius for the map
_maxAIcount = SC_maxAIcount;
_minFPS = SC_minFPS;
_useLaunchers = DMS_ai_use_launchers;
_scaleAI = SC_scaleAI;
_side = "bandit";
if(SC_occupyPlacesSurvivors) then
{
2016-04-12 10:14:07 +00:00
if(!isNil "DMS_Enable_RankChange") then { DMS_Enable_RankChange = true; };
};
2016-04-02 19:06:53 +00:00
// more than _scaleAI players on the server and the max AI count drops per additional player
_currentPlayerCount = count playableUnits;
if(_currentPlayerCount > _scaleAI) then
{
_maxAIcount = _maxAIcount - (_currentPlayerCount - _scaleAI) ;
};
// Don't spawn additional AI if the server fps is below _minFPS
if(diag_fps < _minFPS) exitWith
{
2016-04-10 14:42:45 +00:00
if(SC_extendedLogging) then
{
_logDetail = format ["[OCCUPATION:Places]:: Held off spawning more AI as the server FPS is only %1",diag_fps];
[_logDetail] call SC_fnc_log;
};
2016-04-02 19:06:53 +00:00
};
_aiActive = {alive _x && (side _x == SC_BanditSide OR side _x == SC_SurvivorSide)} count allUnits;
2016-04-02 19:06:53 +00:00
if(_aiActive > _maxAIcount) exitWith
{
2016-04-10 14:42:45 +00:00
if(SC_extendedLogging) then
{
_logDetail = format ["[OCCUPATION:Places]:: %1 active AI, so not spawning AI this time",_aiActive];
[_logDetail] call SC_fnc_log;
};
2016-04-02 19:06:53 +00:00
};
_locations = (nearestLocations [_spawnCenter, ["NameVillage","NameCity", "NameCityCapital"], _maxDistance]);
{
_okToSpawn = true;
_temppos = position _x;
_locationName = text _x;
_locationType = type _x;
_pos = [_temppos select 0, _temppos select 1, 0];
if(SC_extendedLogging) then
{
_logDetail = format ["[OCCUPATION:Places]:: Testing location name: %1 position: %2",_locationName,_pos];
2016-04-02 19:06:53 +00:00
[_logDetail] call SC_fnc_log;
};
while{_okToSpawn} do
{
// Percentage chance to spawn (roll 80 or more to spawn AI)
_spawnChance = round (random 100);
if(_spawnChance < 80) exitWith
{
_okToSpawn = false;
if(SC_extendedLogging) then
{
_logDetail = format ["[OCCUPATION:Places]:: Rolled %1 so not spawning AI this time",_spawnChance,_locationName];
2016-04-02 19:06:53 +00:00
[_logDetail] call SC_fnc_log;
};
};
// Don't spawn if too near a player base
_nearBase = (nearestObjects [_pos,["Exile_Construction_Flag_Static"],500]) select 0;
if (!isNil "_nearBase") exitwith
{
_okToSpawn = false;
if(SC_extendedLogging) then
{
_logDetail = format ["[OCCUPATION:Places]:: %1 is too close to player base",_locationName];
2016-04-02 19:06:53 +00:00
[_logDetail] call SC_fnc_log;
};
};
// Don't spawn AI near traders and spawn zones
_nearestMarker = [allMapMarkers, _pos] call BIS_fnc_nearestPosition; // Nearest Marker to the Location
_posNearestMarker = getMarkerPos _nearestMarker;
if(_pos distance _posNearestMarker < 500) exitwith
{
_okToSpawn = false;
if(SC_extendedLogging) then
{
_logDetail = format ["[OCCUPATION:Places]:: %1 is too close to a %2",_locationName,_nearestMarker];
2016-04-02 19:06:53 +00:00
[_logDetail] call SC_fnc_log;
};
};
// Don't spawn additional AI if there are players in range
if([_pos, 250] call ExileClient_util_world_isAlivePlayerInRange) exitwith
2016-04-02 19:06:53 +00:00
{
_okToSpawn = false;
if(SC_extendedLogging) then
{
_logDetail = format ["[OCCUPATION:Places]:: %1 has players too close",_locationName];
2016-04-02 19:06:53 +00:00
[_logDetail] call SC_fnc_log;
};
};
2016-04-02 19:06:53 +00:00
// Don't spawn additional AI if there are already AI in range
_nearBanditAI = { side _x == SC_BanditSide AND _x distance _pos < 500 } count allUnits;
_nearSurvivorAI = { side _x == SC_SurvivorSide AND _x distance _pos < 500 } count allUnits;
2016-04-14 14:09:04 +00:00
if(_nearBanditAI > 0 AND _nearSurvivorAI > 0) then
2016-04-02 19:06:53 +00:00
{
2016-04-14 14:09:04 +00:00
_okToSpawn = false;
if(SC_extendedLogging) then
{
_logDetail = format ["[OCCUPATION:Places]:: %1 already has active AI patrolling",_locationName];
2016-04-14 14:09:04 +00:00
[_logDetail] call SC_fnc_log;
};
}
else
{
if(_nearBanditAI == 0 AND _nearSurvivorAI == 0) then
2016-04-02 19:06:53 +00:00
{
_sideToSpawn = random 100;
if(_sideToSpawn <= SC_SurvivorsChance) then
{
_side = "survivor";
}
else
{
_side = "bandit";
};
2016-04-14 14:09:04 +00:00
}
else
{
if(_nearSurvivorAI == 0) then
{
2016-04-14 14:09:04 +00:00
_side = "survivor";
}
else
{
_side = "bandit";
2016-04-14 14:09:04 +00:00
};
};
2016-04-02 19:06:53 +00:00
};
2016-04-14 14:09:04 +00:00
2016-04-02 19:06:53 +00:00
if(_okToSpawn) then
{
if(!SC_occupyPlacesSurvivors) then { _side = "bandit"; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2016-04-02 19:06:53 +00:00
// Get AI to patrol the town
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
_aiCount = 1;
_groupRadius = 100;
if(_locationType isEqualTo "NameCityCapital") then { _aiCount = 5; _groupRadius = 300; };
if(_locationType isEqualTo "NameCity") then { _aiCount = 2 + (round (random 3)); _groupRadius = 200; };
if(_locationType isEqualTo "NameVillage") then { _aiCount = 1 + (round (random 2)); _groupRadius = 100; };
2016-04-02 19:06:53 +00:00
if(_aiCount < 1) then { _aiCount = 1; };
_difficulty = "random";
2016-04-02 19:06:53 +00:00
_spawnPos = [_pos,10,100,5,0,20,0] call BIS_fnc_findSafePos;
_spawnPosition = [_spawnPos select 0, _spawnPos select 1,0];
DMS_ai_use_launchers = false;
_initialGroup = [_spawnPosition, _aiCount, "randomEasy", "assault", _side] call DMS_fnc_SpawnAIGroup;
2016-04-02 19:06:53 +00:00
DMS_ai_use_launchers = _useLaunchers;
_group = createGroup SC_BanditSide;
if(_side == "survivor") then
{
deleteGroup _group;
_group = createGroup SC_SurvivorSide;
};
_group setVariable ["DMS_LockLocality",nil];
_group setVariable ["DMS_SpawnedGroup",true];
_group setVariable ["DMS_Group_Side", _side];
{
2016-04-13 21:03:44 +00:00
_unit = _x;
[_unit] joinSilent grpNull;
[_unit] joinSilent _group;
if(_side == "survivor") then
{
2016-04-13 21:03:44 +00:00
_unit addMPEventHandler ["mphit", "_this call SC_fnc_unitMPHit;"];
2016-04-16 01:32:48 +00:00
_unit addMPEventHandler ["mpkilled", "_this call SC_fnc_unitMPKilled;"];
removeUniform _unit;
_unit forceAddUniform "Exile_Uniform_BambiOverall";
if(SC_debug) then
{
_tag = createVehicle ["Sign_Arrow_Green_F", position _unit, [], 0, "CAN_COLLIDE"];
_tag attachTo [_unit,[0,0,0.6],"Head"];
};
}
else
{
if(SC_debug) then
{
_tag = createVehicle ["Sign_Arrow_F", position _unit, [], 0, "CAN_COLLIDE"];
_tag attachTo [_unit,[0,0,0.6],"Head"];
};
};
}foreach units _initialGroup;
2016-04-02 19:06:53 +00:00
// Get the AI to shut the fuck up :)
enableSentences false;
enableRadio false;
if(!SC_useWaypoints) then
{
[_group, _pos, _groupRadius] call bis_fnc_taskPatrol;
_group setBehaviour "COMBAT";
_group setCombatMode "RED";
}
else
{
[ _group,_pos,_difficulty,"COMBAT" ] call DMS_fnc_SetGroupBehavior;
_buildings = _pos nearObjects ["building", _groupRadius];
{
2016-04-08 13:48:25 +00:00
_isEnterable = [_x] call BIS_fnc_isBuildingEnterable;
if(_isEnterable) then
2016-04-02 19:06:53 +00:00
{
2016-04-08 13:48:25 +00:00
_buildingPositions = [_x, 10] call BIS_fnc_buildingPositions;
2016-04-10 14:42:45 +00:00
_y = _x;
2016-04-02 19:06:53 +00:00
// Find Highest Point
_highest = [0,0,0];
{
if(_x select 2 > _highest select 2) then
{
_highest = _x;
};
} foreach _buildingPositions;
2016-04-10 14:42:45 +00:00
_wpPosition = _highest;
2016-04-02 19:06:53 +00:00
2016-04-10 14:42:45 +00:00
_i = _buildingPositions find _wpPosition;
_wp = _group addWaypoint [_wpPosition, 0] ;
2016-04-02 19:06:53 +00:00
_wp setWaypointBehaviour "COMBAT";
_wp setWaypointCombatMode "RED";
_wp setWaypointCompletionRadius 1;
2016-04-10 14:42:45 +00:00
_wp waypointAttachObject _y;
2016-04-02 19:06:53 +00:00
_wp setwaypointHousePosition _i;
_wp setWaypointType "SAD";
};
} foreach _buildings;
if(count _buildings > 0 && !isNil "_wp") then
{
_wp setWaypointType "CYCLE";
};
};
if(_locationType isEqualTo "NameCityCapital") then
{
DMS_ai_use_launchers = false;
_initialGroup2 = [_spawnPosition, 5, _difficulty, "random", _side] call DMS_fnc_SpawnAIGroup;
2016-04-02 19:06:53 +00:00
DMS_ai_use_launchers = _useLaunchers;
_group2 = createGroup SC_BanditSide;
if(_side == "survivor") then
2016-04-13 21:03:44 +00:00
{
deleteGroup _group2;
_group2 = createGroup SC_SurvivorSide;
};
_group2 setVariable ["DMS_LockLocality",nil];
_group2 setVariable ["DMS_SpawnedGroup",true];
_group2 setVariable ["DMS_Group_Side", _side];
2016-04-02 19:06:53 +00:00
// Get the AI to shut the fuck up :)
enableSentences false;
enableRadio false;
{
_unit = _x;
[_unit] joinSilent grpNull;
[_unit] joinSilent _group2;
2016-04-12 16:16:40 +00:00
if(_side == "survivor") then
{
2016-04-13 21:03:44 +00:00
_unit addMPEventHandler ["mphit", "_this call SC_fnc_unitMPHit;"];
2016-04-16 01:32:48 +00:00
_unit addMPEventHandler ["mpkilled", "_this call SC_fnc_unitMPKilled;"];
removeUniform _unit;
_unit forceAddUniform "Exile_Uniform_BambiOverall";
if(SC_debug) then
{
_tag = createVehicle ["Sign_Arrow_Green_F", position _unit, [], 0, "CAN_COLLIDE"];
_tag attachTo [_unit,[0,0,0.6],"Head"];
2016-04-13 21:03:44 +00:00
};
}
else
{
if(SC_debug) then
{
2016-04-13 21:03:44 +00:00
_tag = createVehicle ["Sign_Arrow_F", position _unit, [], 0, "CAN_COLLIDE"];
_tag attachTo [_unit,[0,0,0.6],"Head"];
};
};
}foreach units _initialGroup2;
2016-04-02 19:06:53 +00:00
[_group2, _pos, _groupRadius] call bis_fnc_taskPatrol;
_group2 setBehaviour "AWARE";
2016-04-02 19:06:53 +00:00
_group2 setCombatMode "RED";
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(SC_mapMarkers) then
{
_marker = createMarker [format ["%1", _spawnPosition],_pos];
_marker setMarkerShape "Icon";
_marker setMarkerSize [3,3];
_marker setMarkerType "mil_dot";
_marker setMarkerBrush "Solid";
_marker setMarkerAlpha 0.5;
_marker setMarkerText "Occupied Area";
};
if(_side == "survivor") then
{
2016-04-16 01:32:48 +00:00
_marker setMarkerColor "ColorGreen";
_logDetail = format ["[OCCUPATION:Places]:: Spawning %2 survivor AI in at %3 to patrol %1",_locationName,_aiCount,_spawnPosition];
}
else
{
2016-04-16 01:32:48 +00:00
_marker setMarkerColor "ColorOrange";
_logDetail = format ["[OCCUPATION:Places]:: Spawning %2 bandit AI in at %3 to patrol %1",_locationName,_aiCount,_spawnPosition];
};
2016-04-02 19:06:53 +00:00
[_logDetail] call SC_fnc_log;
_okToSpawn = false;
};
};
sleep 0.2;
} forEach _locations;