fn_spawnEnemy.sqf 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. private ["_spawnedUnits", "_side", "_soldiers", "_vehicles", "_toSpawn", "_type", "_pos", "_randomUnit", "_i", "_c", "_group", "_amount", "_loc", "_radius"];
  2. // Set defaults
  3. _side = [_this,0,EAST,[EAST]] call BIS_fnc_param;
  4. _amount = [_this,1,5,[0]] call BIS_fnc_param;
  5. _loc = [_this,2,[0,0,0],[[],""],[2,3]] call BIS_fnc_param;
  6. _radius = [_this,3,100,[[],0],[2]] call BIS_fnc_param;
  7. // Grab enemy units
  8. _spawnedUnits = [];
  9. _soldiers = getArray (missionConfigFile >> "enemy" >> "infantry");
  10. _vehicles = getArray (missionConfigFile >> "enemy" >> "vehicles");
  11. _static = getArray (missionConfigFile >> "enemy" >> "static");
  12. _boats = getArray (missionConfigFile >> "enemy" >> "boats");
  13. _air = getArray (missionConfigFile >> "enemy" >> "air");
  14. _unitTypes = ["infantry", "vehicle", "air", "static"];
  15. _chances = [0.75, 0.15, 0.03, 0.07];
  16. // Creation loop
  17. for [{_i = 0}, {_i < _amount}, {_i = _i + 1}] do
  18. {
  19. _toSpawn = [];
  20. _ret = [];
  21. _lName = typeName _loc;
  22. _type = [_unitTypes, _chances] call BIS_fnc_selectRandomWeighted;
  23. _pos = switch (_lName) do
  24. {
  25. case "ARRAY":
  26. {
  27. _rName = typeName _radius;
  28. _ret = switch (_rName) do
  29. {
  30. case "ARRAY":
  31. {
  32. [_loc, (_radius select 0), (_radius select 1), 1, 0, 2000, 0] call BIS_fnc_findSafePos
  33. };
  34. case "SCALAR":
  35. {
  36. [[[_loc, _radius]], ["water", "out"]] call BIS_fnc_randomPos
  37. };
  38. };
  39. _ret
  40. };
  41. case "STRING":
  42. {
  43. _tempPos = [_loc] call AW_fnc_randomPosTrigger;
  44. _ret = [_tempPos, 0, 50, 2, 0, 2000, 0] call BIS_fnc_findSafePos;
  45. _ret
  46. };
  47. };
  48. switch (_type) do
  49. {
  50. case "infantry":
  51. {
  52. _rand = round(6 + random(4));
  53. for [{_c = 0}, {_c < _rand}, {_c = _c + 1}] do
  54. {
  55. _randomUnit = _soldiers call BIS_fnc_selectRandom;
  56. _toSpawn = _toSpawn + [_randomUnit];
  57. };
  58. _group = [_pos, _side, _toSpawn] call BIS_fnc_spawnGroup;
  59. {
  60. _x addEventHandler ["killed", { (_this select 0) call AW_fnc_addDead; }];
  61. } foreach (units _group);
  62. _spawnedUnits = _spawnedUnits + [_group];
  63. };
  64. case "vehicle":
  65. {
  66. _randomUnit = _vehicles call BIS_fnc_selectRandom;
  67. _group = [_pos, random 360, _randomUnit, _side] call BIS_fnc_spawnVehicle;
  68. {
  69. {
  70. _x addEventHandler ["killed", { (_this select 0) call AW_fnc_addDead; }];
  71. } forEach _x;
  72. } forEach [[(_group select 0)], (_group select 1)];
  73. _spawnedUnits = _spawnedUnits + [_group select 2];
  74. _spawnedUnits = _spawnedUnits + [_group select 0];
  75. };
  76. case "air": // Needs splitting into "plane" and "helicopter"
  77. {
  78. _randomUnit = _air call BIS_fnc_selectRandom;
  79. _group = [_pos, random 360, _randomUnit, _side] call BIS_fnc_spawnVehicle;
  80. {
  81. {
  82. _x addEventHandler ["killed", { (_this select 0) call AW_fnc_addDead; }];
  83. } foreach _x;
  84. } foreach [[(_group select 0)], (_group select 1)];
  85. _spawnedUnits = _spawnedUnits + [_group select 2];
  86. _spawnedUnits = _spawnedUnits + [_group select 0];
  87. };
  88. case "static":
  89. {
  90. _randomUnit = _static call BIS_fnc_selectRandom;
  91. _group = [_pos, random 360, _randomUnit, _side] call BIS_fnc_spawnVehicle;
  92. {
  93. {
  94. _x addEventHandler ["killed", { (_this select 0) call AW_fnc_addDead; }];
  95. } foreach _x;
  96. } foreach [[(_group select 0)], (_group select 1)];
  97. _spawnedUnits = _spawnedUnits + [_group select 2];
  98. _spawnedUnits = _spawnedUnits + [_group select 0];
  99. };
  100. };
  101. };
  102. _spawnedUnits