a3_exile_occupation/scripts/functions/fnc_spawnStatics.sqf

181 lines
5.9 KiB
Plaintext
Raw Normal View History

_statics = _this select 0;
_side = _this select 1;
_static = [];
_currentSide = SC_BanditSide;
_debug = SC_debug;
_useLaunchers = DMS_ai_use_launchers;
_scaleAI = SC_scaleAI;
2016-04-27 00:05:03 +00:00
_staticUID = 1;
if(_side == "survivor") then { _currentSide = SC_SurvivorSide };
{
2016-05-12 12:44:47 +00:00
_currentStatic = _x;
_spawnPosition = _currentStatic select 0;
_aiCount = _currentStatic select 1;
_radius = _currentStatic select 2;
_staticSearch = _currentStatic select 3;
2016-04-26 09:29:50 +00:00
_logDetail = format ["[OCCUPATION Static]:: Checking static spawn @ %1 for existing %2 AI",_spawnPosition,_currentSide];
[_logDetail] call SC_fnc_log;
_okToSpawn = true;
Sleep 0.1;
while{_okToSpawn} do
{
2016-04-27 00:05:03 +00:00
// Don't spawn if a previous round of AI are already in place
_newStatic = [_staticUID,_spawnPosition];
if(_staticUID in SC_liveStaticGroups) exitwith
{
_okToSpawn = false;
if(_debug) then
{
2016-05-09 16:58:20 +00:00
_logDetail = format ["[OCCUPATION Static]:: %1 already has active AI patrolling",_spawnPosition];
[_logDetail] call SC_fnc_log;
2016-04-27 00:05:03 +00:00
};
};
// Don't spawn additional AI if there are players in range
if([_spawnPosition, 250] call ExileClient_util_world_isAlivePlayerInRange) exitwith
{
_okToSpawn = false;
if(_debug) then
{
_logDetail = format ["[OCCUPATION Static]:: %1 has players too close",_spawnPosition];
[_logDetail] call SC_fnc_log;
};
};
if(_okToSpawn) then
{
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Get AI to patrol the area
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
_groupRadius = _radius;
_difficulty = "random";
2016-04-26 09:29:50 +00:00
_initialGroup = createGroup _currentSide;
DMS_ai_use_launchers = false;
for "_i" from 1 to _aiCount do
{
_loadOut = [_side] call SC_fnc_selectGear;
2016-05-05 11:23:52 +00:00
_unit = [_initialGroup,_spawnPosition,"custom","random",_side,"soldier",_loadOut] call DMS_fnc_SpawnAISoldier;
2016-07-26 15:40:38 +00:00
_unit allowFleeing 0;
_unit allowDamage false;
_unit disableAI "AUTOTARGET";
_unit disableAI "TARGET";
_unit disableAI "MOVE";
2016-05-05 11:23:52 +00:00
_unitName = [_side] call SC_fnc_selectName;
2016-05-31 15:22:42 +00:00
if(!isNil "_unitName") then { _unit setName _unitName; };
2016-04-27 00:05:03 +00:00
_unit setVariable ["SC_staticUID",_staticUID];
_unit setVariable ["SC_staticSpawnPos",_spawnPosition];
_unit addMPEventHandler ["mpkilled", "_this call SC_fnc_staticUnitMPKilled;"];
2016-04-26 09:29:50 +00:00
};
DMS_ai_use_launchers = _useLaunchers;
_initialGroup setCombatMode "BLUE";
_initialGroup setBehaviour "SAFE";
_group = createGroup _currentSide;
_group setVariable ["DMS_LockLocality",nil];
_group setVariable ["DMS_SpawnedGroup",true];
_group setVariable ["DMS_Group_Side", _side];
2016-04-27 00:05:03 +00:00
SC_liveStaticGroups = SC_liveStaticGroups + [_staticUID,_spawnPosition];
{
_unit = _x;
[_unit] joinSilent grpNull;
[_unit] joinSilent _group;
2016-07-26 15:40:38 +00:00
_unit allowDamage true;
_unit enableAI "AUTOTARGET";
_unit enableAI "TARGET";
_unit enableAI "MOVE";
2016-05-12 12:44:47 +00:00
[_side,_unit] call SC_fnc_addMarker;
2016-05-09 16:58:20 +00:00
_unit setCaptive false;
}foreach units _initialGroup;
// Get the AI to shut the fuck up :)
enableSentences false;
enableRadio false;
if(!_staticSearch) then
{
[_group, _spawnPosition, _groupRadius] call bis_fnc_taskPatrol;
_group setBehaviour "AWARE";
_group setCombatMode "RED";
}
else
{
2016-05-09 16:58:20 +00:00
_group setBehaviour "AWARE";
_group setCombatMode "RED";
_buildings = _spawnPosition nearObjects ["building", _groupRadius];
{
_isEnterable = [_x] call BIS_fnc_isBuildingEnterable;
if(_isEnterable) then
{
_buildingPositions = [_x, 10] call BIS_fnc_buildingPositions;
_y = _x;
// Find Highest Point
_highest = [0,0,0];
{
if(_x select 2 > _highest select 2) then
{
_highest = _x;
};
} foreach _buildingPositions;
_wpPosition = _highest;
diag_log format ["Static Patrol %3 waypoint added - building: %1 position: %2",_y,_highest,_group];
_i = _buildingPositions find _wpPosition;
2016-05-17 20:42:51 +00:00
_wp = _group addWaypoint [_wpPosition, 5] ;
_wp setWaypointBehaviour "AWARE";
2016-05-17 20:42:51 +00:00
_wp setWaypointSpeed "NORMAL";
_wp setWaypointCombatMode "RED";
_wp setWaypointCompletionRadius 1;
_wp waypointAttachObject _y;
_wp setwaypointHousePosition _i;
_wp setWaypointType "SAD";
};
} foreach _buildings;
2016-05-17 20:42:51 +00:00
if(count _buildings > 1 && !isNil "_wp") then
{
_wp setWaypointType "CYCLE";
2016-05-17 20:42:51 +00:00
}
else
{
_group setBehaviour "AWARE";
_group setCombatMode "RED";
};
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
_logDetail = format ["[OCCUPATION Static]:: Spawning %1 AI in at %2 to patrol",_aiCount,_spawnPosition];
[_logDetail] call SC_fnc_log;
if(SC_mapMarkers && !isNil "_foundBuilding") then
{
2016-05-12 12:44:47 +00:00
_marker = createMarker [format ["%1", _staticUID],_spawnPosition];
_marker setMarkerShape "Icon";
_marker setMarkerSize [3,3];
_marker setMarkerType "mil_dot";
_marker setMarkerBrush "Solid";
_marker setMarkerAlpha 0.5;
_marker setMarkerColor "ColorRed";
_marker setMarkerText "Occupied Area (static)";
};
_okToSpawn = false;
};
};
2016-04-27 00:05:03 +00:00
_staticUID = _staticUID + 1;
}forEach _statics;