Epoch/Sources/epoch_code/compile/EPOCH_unitSpawn.sqf

220 lines
10 KiB
Plaintext
Raw Normal View History

2015-12-07 16:24:52 +00:00
/*
Author: Aaron Clark - EpochMod.com
Contributors: Andrew Gregory
2015-12-07 16:24:52 +00:00
Description:
Antagonist spawn function
Licence:
Arma Public License Share Alike (APL-SA) - https://www.bistudio.com/community/licenses/arma-public-license-share-alike
Github:
2016-06-13 16:54:19 +00:00
https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_code/compile/EPOCH_unitSpawn.sqf
2015-12-07 16:24:52 +00:00
*/
2016-09-01 00:40:18 +00:00
//[[[cog import generate_private_arrays ]]]
private ["_aiskill","_arrSkills","_arrUnits","_arrVals","_bomb","_config","_currentLimit","_disableAI","_driver","_grp","_index","_jammers","_loop","_minAISkill","_missionConfig","_nonJammer","_nonTrader","_nonTraderAIRange","_playerSpawnArray","_playerSpawnArrayKeyFinal","_pos","_restricted","_sapperHndl","_sapperNum","_spawnLimit","_targetPos","_unit","_units"];
2016-09-01 00:40:18 +00:00
//[[[end]]]
2017-05-02 13:28:52 +00:00
params ["_unitClass",["_trgt",player],["_doVariable",false],["_unitCount",1],["_extraData",[]] ];
2016-06-15 00:58:22 +00:00
2016-09-01 00:40:18 +00:00
_bomb = objNull;
2015-09-14 20:55:36 +00:00
_index = EPOCH_spawnIndex find _unitClass;
2017-03-02 17:22:35 +00:00
_spawnLimit = 0;
if (_index != -1) then {
2017-09-27 02:20:41 +00:00
_playerSpawnArrayKeyFinal = "EPOCH_playerSpawnArray";
2017-09-28 17:00:48 +00:00
if !(isNil "_playerSpawnArrayKey") then {_playerSpawnArrayKeyFinal = _playerSpawnArrayKey};
2017-09-27 02:20:41 +00:00
_playerSpawnArray = missionNamespace getVariable [_playerSpawnArrayKeyFinal,[]];
_spawnLimit = _playerSpawnArray select _index;
2017-03-02 17:22:35 +00:00
};
2016-06-15 00:58:22 +00:00
_currentLimit = count(_trgt nearEntities[_unitClass, 800]);
if (!_doVariable && (_currentLimit >= _spawnLimit)) exitWith {
diag_log format["DEBUG: too many %1 exiting unitspawn",_unitClass];
};
2015-09-14 20:55:36 +00:00
_nonJammer = ["CfgEpochClient", "nonJammerAI", ["B_Heli_Transport_01_F","PHANTOM","EPOCH_Sapper_F","Epoch_SapperG_F","Epoch_SapperB_F","I_UAV_01_F","EPOCH_RyanZombie_1"]] call EPOCH_fnc_returnConfigEntryV2;
_nonTrader = ["CfgEpochClient", "nonTraderAI", ["B_Heli_Transport_01_F","PHANTOM","EPOCH_Sapper_F","Epoch_SapperG_F","Epoch_SapperB_F","I_UAV_01_F","Epoch_Cloak_F","GreatWhite_F","EPOCH_RyanZombie_1"]] call EPOCH_fnc_returnConfigEntryV2;
Release 0.3.8 (#502) * first build for 0.3.8 * 0.3.8.0190 * 0.3.8.0202 * 0.3.8.0213 * 0.3.7.0214 * 0.3.8.0222 * 0.3.8.0246 * 0.3.8.0247 fixed typo * 0.3.8.0249 more fixes for server compiler * 0.3.8.0256 * add build number and simple batch file for packing * match build number with internal * add build numbers to server pbo's and mission files also reworked build script for more options * 0.3.8.0261 * 0.3.8.0261 * 0.3.8.0283 * 0.3.8.0284 * changelog * 0.3.8.0307 * 0.3.8.0311 * remove old BEC plugin * update redis-server.exe to latest build and full config * 0.3.8.0314 * 0.3.8.0315 * inverse logic This should correctly prevent spawning these units nearby jammer or protection zones * use pushbackUnique here * optimized loot function by using selectRandom instead of slower sqf logic * 0.3.8.0316 * make use of new getDir functionality instead of BIS fnc * add lower disconnect value to server.cfg * use new getpos functionality * 0.3.8.0317 * 0.3.8.0319 * 0.3.8.0327 * 0.3.8.0338 changelog update tba * changelog * 0.3.8.0341 * BE update * 0.3.8.0353 * changelog * removed duplicates * 0.3.8.0355 fixed error in getIDC * 0.3.8.0356 revert to BIS_fnc_param as params threw errors * 0.3.8.0357 fixes for #496 #497 * 0.3.8.0359 fixed #497 fixed #496 * 0.3.8.0365 * 0.3.8.0371 * 0.3.8.0373 * 0.3.8.0379 * 0.3.8.0381 * 0.3.8.0386 * 0.3.8.0393 * 0.3.8.0395 * 0.3.8.0396 * 0.3.8.0397 * 0.3.8.0406 * 0.3.8.0409 * 0.3.8.0410 loot balance suppress error in spawnloot make near object check based on building size * 0.3.8.0412 * 0.3.8.0414 removed classes with scope 0 test remove loot trash on gear for #498 fixed #501 * 0.3.8.0415 * same
2016-04-08 20:21:46 +00:00
_nonTraderAIRange = ["CfgEpochClient", "nonTraderAIRange", 150] call EPOCH_fnc_returnConfigEntryV2;
2016-06-15 00:58:22 +00:00
_loop = false;
2015-09-14 20:55:36 +00:00
_unit = objNull;
_targetPos = getPosATL _trgt;
2015-09-14 20:55:36 +00:00
_targetPos set [2,0];
2019-02-20 21:31:09 +00:00
_jammers = (nearestObjects[_targetPos, call EPOCH_JammerClasses, call EPOCH_MaxJammerRange]) select {_targetPos distance _x < (getnumber (getmissionconfig "CfgEpochClient" >> "CfgJammers" >> (typeof _x) >> "buildingJammerRange"))};
if(!(_jammers isEqualTo []) && (_unitClass in _nonJammer))exitWith{};
2015-09-14 20:55:36 +00:00
Release 0.3.8 (#502) * first build for 0.3.8 * 0.3.8.0190 * 0.3.8.0202 * 0.3.8.0213 * 0.3.7.0214 * 0.3.8.0222 * 0.3.8.0246 * 0.3.8.0247 fixed typo * 0.3.8.0249 more fixes for server compiler * 0.3.8.0256 * add build number and simple batch file for packing * match build number with internal * add build numbers to server pbo's and mission files also reworked build script for more options * 0.3.8.0261 * 0.3.8.0261 * 0.3.8.0283 * 0.3.8.0284 * changelog * 0.3.8.0307 * 0.3.8.0311 * remove old BEC plugin * update redis-server.exe to latest build and full config * 0.3.8.0314 * 0.3.8.0315 * inverse logic This should correctly prevent spawning these units nearby jammer or protection zones * use pushbackUnique here * optimized loot function by using selectRandom instead of slower sqf logic * 0.3.8.0316 * make use of new getDir functionality instead of BIS fnc * add lower disconnect value to server.cfg * use new getpos functionality * 0.3.8.0317 * 0.3.8.0319 * 0.3.8.0327 * 0.3.8.0338 changelog update tba * changelog * 0.3.8.0341 * BE update * 0.3.8.0353 * changelog * removed duplicates * 0.3.8.0355 fixed error in getIDC * 0.3.8.0356 revert to BIS_fnc_param as params threw errors * 0.3.8.0357 fixes for #496 #497 * 0.3.8.0359 fixed #497 fixed #496 * 0.3.8.0365 * 0.3.8.0371 * 0.3.8.0373 * 0.3.8.0379 * 0.3.8.0381 * 0.3.8.0386 * 0.3.8.0393 * 0.3.8.0395 * 0.3.8.0396 * 0.3.8.0397 * 0.3.8.0406 * 0.3.8.0409 * 0.3.8.0410 loot balance suppress error in spawnloot make near object check based on building size * 0.3.8.0412 * 0.3.8.0414 removed classes with scope 0 test remove loot trash on gear for #498 fixed #501 * 0.3.8.0415 * same
2016-04-08 20:21:46 +00:00
_restricted = nearestObjects [_targetPos, ["ProtectionZone_Invisible_F"], _nonTraderAIRange];
if(!(_restricted isEqualTo []) && (_unitClass in _nonTrader))exitWith{};
2015-09-14 20:55:36 +00:00
_disableAI = {
{_this disableAI _x}forEach["TARGET","AUTOTARGET","FSM"];
};
2016-06-15 00:58:22 +00:00
_units = [];
2015-09-14 20:55:36 +00:00
switch _unitClass do {
case "Epoch_Cloak_F": {
2017-03-02 16:58:12 +00:00
for "_i" from 0 to (_unitCount-1) do {
_unit = createAgent[_unitClass, _targetPos, [], 256, "FORM"];
_units pushBack _unit;
_unit call _disableAI;
[_unit,_trgt] execFSM "\x\addons\a3_epoch_code\System\cloak.fsm";
_unit addEventHandler ["Killed", {[_this, "AntagonistKills", 1, true] call Epoch_unit_onKilledEH;}];
2017-03-02 16:58:12 +00:00
};
2015-09-14 20:55:36 +00:00
};
case "GreatWhite_F": {
if (surfaceIsWater _targetPos) then{
if (((_targetPos vectorDiff getPosASL _trgt) select 2) > 25) then{
2017-03-02 16:58:12 +00:00
for "_i" from 0 to (_unitCount-1) do {
_unit = createAgent[_unitClass, _targetPos, [], 120, "FORM"];
_units pushBack _unit;
_unit call _disableAI;
[_unit] execFSM "\x\addons\a3_epoch_code\System\Shark_Brain.fsm";
_unit addEventHandler ["Killed", {[_this, "AntagonistKills", 1, true] call Epoch_unit_onKilledEH;}];
2017-03-02 16:58:12 +00:00
};
2015-12-07 16:24:52 +00:00
};
2015-09-14 20:55:36 +00:00
};
};
case "Epoch_Sapper_F": {
if(random 100 < 6 && isNull _trgt)then{
2015-09-14 20:55:36 +00:00
_config = 'CfgEpochSapper' call EPOCH_returnConfig;
_sapperNum = 8;
if(getNumber(_config >> "sapperMigrationCount") > 0)then{
_sapperNum = getNumber(_config >> "sapperMigrationCount");
};
[_trgt,_sapperNum] execVM "epoch_code\compile\EPOCH_callSapperMigration.sqf";
2015-09-14 20:55:36 +00:00
}else{
2017-03-02 16:58:12 +00:00
for "_i" from 0 to (_unitCount-1) do {
_unit = createAgent[_unitClass, _targetPos, [], 256, "FORM"];
_units pushBack _unit;
_bomb = createVehicle ["Sapper_Charge_Ammo", _targetPos, [], 0, "CAN_COLLIDE"];
_bomb attachTo [_unit, [0,0,0],"Pelvis"];
_unit call _disableAI;
_sapperHndl = [_unit, _bomb, _trgt] execFSM "\x\addons\a3_epoch_code\System\Sapper_Brain.fsm";
_unit setVariable ["sapperHndl",_sapperHndl];
_unit addEventHandler ["FiredNear", format ["%1 setFSMVariable [""_sFiredNear"",[_this select 1, _this select 2]];",_sapperHndl]];
_unit addEventHandler ["Hit", format ["%1 setFSMVariable [""_sHit"",[_this select 1, _this select 2]];",_sapperHndl]];
_unit addEventHandler ["Killed", {[_this, "AntagonistKills", 1, true] call Epoch_unit_onKilledEH;}];
2017-03-02 16:58:12 +00:00
};
};
};
case "Epoch_SapperG_F": {
for "_i" from 0 to (_unitCount-1) do {
2015-09-14 20:55:36 +00:00
_unit = createAgent[_unitClass, _targetPos, [], 256, "FORM"];
2016-06-15 00:58:22 +00:00
_units pushBack _unit;
2017-03-08 18:26:41 +00:00
_bomb = createVehicle ["SmokeShellToxicSapper", _targetPos, [], 0, "CAN_COLLIDE"];
2015-09-14 20:55:36 +00:00
_bomb attachTo [_unit, [0,0,0],"Pelvis"];
[_bomb, player, Epoch_personalToken,_unit,false] remoteExec ["EPOCH_server_handle_sapperObjs",2];
_bomb = createVehicle ["Sapper_Charge_Ammo", _targetPos, [], 0, "CAN_COLLIDE"];
_bomb attachTo [_unit, [0,0,0],"Pelvis"];
2015-09-14 20:55:36 +00:00
_unit call _disableAI;
_sapperHndl = [_unit, _bomb, _trgt] execFSM "\x\addons\a3_epoch_code\System\Sapper_Brain2.fsm";
2017-03-02 16:58:12 +00:00
_unit setVariable ["sapperHndl",_sapperHndl];
_unit addEventHandler ["FiredNear", format ["%1 setFSMVariable [""_sFiredNear"",[_this select 1, _this select 2]];",_sapperHndl]];
_unit addEventHandler ["Hit", format ["%1 setFSMVariable [""_sHit"",[_this select 1, _this select 2]];",_sapperHndl]];
_unit addEventHandler ["Killed", {[_this, "AntagonistKills", 1, true] call Epoch_unit_onKilledEH;}];
2015-09-14 20:55:36 +00:00
};
};
case "Epoch_SapperB_F": {
2017-03-02 16:58:12 +00:00
for "_i" from 0 to (_unitCount-1) do {
_unit = createAgent[_unitClass, _targetPos, [], 256, "FORM"];
_units pushBack _unit;
_bomb = createVehicle["SapperB_Charge_Ammo", _targetPos, [], 0, "CAN_COLLIDE"];
_bomb attachTo[_unit, [0, 0, 0], "Pelvis"];
_unit call _disableAI;
_sapperHndl = [_unit, _bomb, _trgt] execFSM "\x\addons\a3_epoch_code\System\Sapper_Brain2.fsm";
_unit setVariable ["sapperHndl",_sapperHndl];
_unit addEventHandler ["FiredNear", format ["%1 setFSMVariable [""_sFiredNear"",[_this select 1, _this select 2]];",_sapperHndl]];
_unit addEventHandler ["Hit", format ["%1 setFSMVariable [""_sHit"",[_this select 1, _this select 2]];",_sapperHndl]];
_unit addEventHandler ["Killed", {[_this, "AntagonistKills", 1, true] call Epoch_unit_onKilledEH;}];
2017-03-02 16:58:12 +00:00
};
2015-09-14 20:55:36 +00:00
};
case "I_UAV_01_F": {
2017-03-02 16:58:12 +00:00
for "_i" from 0 to (_unitCount-1) do {
_targetPos = [_targetPos, 600, 1200, 5, 0, 400, 0] call BIS_fnc_findSafePos;
_targetPos set[2, 600];
_unit = createVehicle["I_UAV_01_F", _targetPos, [], 0, "FLY"];
_unit disableTIEquipment true;
_units pushBack _unit;
addToRemainsCollector[_unit];
_unit flyInHeight 600;
2017-03-26 15:21:26 +00:00
_grp = createGroup [RESISTANCE, true];
2017-03-02 16:58:12 +00:00
_driver = _grp createUnit["I_UAV_AI", position _unit, [], 0, "CAN_COLLIDE"];
_driver moveInAny _unit;
[_unit, _trgt] execFSM "\x\addons\a3_epoch_code\System\Copter_brain.fsm";
_unit addEventHandler ["Killed", {[_this, "AIKills", 1, true] call Epoch_unit_onKilledEH;}];
2017-03-02 16:58:12 +00:00
};
2015-09-14 20:55:36 +00:00
};
case "PHANTOM": {
[] execFSM "\x\addons\a3_epoch_code\System\Phantom_Brain.fsm";
};
case "B_Heli_Transport_01_F": {
[] execFSM "\x\addons\a3_epoch_code\System\Event_Air_Drop.fsm";
};
case "EPOCH_RyanZombie_1": {
2016-06-15 00:58:22 +00:00
for "_i" from 1 to (_spawnLimit - _currentLimit) do
{
_unit = [] call EPOCH_zombieSpawn;
_units pushBack _unit;
2016-06-15 00:58:22 +00:00
};
};
case "I_Soldier_EPOCH": {
2017-03-22 21:52:04 +00:00
_extraData params [["_pos",[]],["_copter",objnull]];
if (_pos isEqualTo []) then {
_pos = [_targetPos,80,150,1,true] call EPOCH_fnc_findSafePos;
};
_pos set [2,0];
2017-03-26 15:21:26 +00:00
_grp = createGroup [RESISTANCE, true];
2017-03-02 16:58:12 +00:00
_grp setBehaviour "COMBAT";
_grp setCombatMode "RED";
_missionConfig = getMissionConfig "CfgEpochSoldier";
_minAISkill = getNumber (_missionConfig >> "minAISkill");
_arrUnits = getArray (_missionConfig >> "unitTypes");
_arrSkills = ["aimingAccuracy","aimingShake","aimingSpeed","endurance","spotDistance","spotTime","courage","reloadSpeed","commanding","general"];
_arrVals = [
getNumber (_missionConfig >> "maxAimingAccuracy"),
getNumber (_missionConfig >> "maxAimingShake"),
getNumber (_missionConfig >> "maxAimingSpeed"),
getNumber (_missionConfig >> "maxEndurance"),
getNumber (_missionConfig >> "maxSpotDistance"),
getNumber (_missionConfig >> "maxSpotTime"),
getNumber (_missionConfig >> "maxCourage"),
getNumber (_missionConfig >> "maxReloadSpeed"),
getNumber (_missionConfig >> "maxCommanding"),
getNumber (_missionConfig >> "maxGeneral")
];
for "_i" from 0 to (_unitCount - 1) do {
_unit = _grp createUnit[selectRandom _arrUnits, _pos, [], 0, "FORM"];
_units pushBack _unit;
_unit setRank "Private";
_unit enableAI "TARGET";
_unit enableAI "AUTOTARGET";
_unit enableAI "MOVE";
_unit enableAI "ANIM";
_unit disableAI "FSM";
_unit addEventHandler ["Killed", {[_this, "AIKills", 1, true] call Epoch_unit_onKilledEH;}];
// randomize skill
for "_i" from 0 to ((count _arrSkills)-1) do {
_aiskill = floor random (_arrVals select _i);
2017-05-02 13:28:52 +00:00
if (_aiskill < _minAISkill) then {_aiskill = _minAISkill};
_unit setSkill [_arrSkills select _i,_arrVals select _i];
};
// spawn brains only on leader
if (_i == 0) then {
_grp selectLeader _unit;
[_pos,_copter,_trgt,_unit] execFSM "\x\addons\a3_epoch_code\System\Group_Leader_Brain.fsm";
};
};
};
2015-09-14 20:55:36 +00:00
};
if(_doVariable && (!isNull _unit) && (!isNull _trgt))then{
_trgt setVariable ["EPOCH_antagObj", _unit, true];
if!(isNull _bomb)then{
_trgt setVariable ["EPOCH_antagBomb", _bomb, true];
};
};
2016-06-15 00:58:22 +00:00
if !(_units isEqualTo []) then {
_units remoteExec ["EPOCH_localCleanup",2];
2016-04-26 14:28:07 +00:00
};