fn_baseSpawn.sqf 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. private ["_type", "_base", "_types", "_allVehs", "_class", "_lastIndex", "_tmp_class", "_tmp_type","_vehicles", "_x", "_veh", "_marker", "_markerPos", "_markers", "_exhaustedTypes", "_exhaustedBases", "_done", "_success"];
  2. _type = [_this,0,"",[""]] call BIS_fnc_param;
  3. _base = [_this,1,"",["",[],objNull],[2,3]] call BIS_fnc_param;
  4. if (typeName _base == "OBJECT") then { _base = getPos _base; };
  5. _types = [];
  6. _allVehs = [];
  7. _class = (missionConfigFile >> "AW_rewards");
  8. _lastIndex = ((count _class) - 1);
  9. for "_i" from 0 to _lastIndex do
  10. {
  11. _tmp_class = (_class select _i);
  12. _tmp_type = (configName _tmp_class);
  13. _types = _types + [_tmp_type];
  14. _vehicles = getArray _tmp_class;
  15. {
  16. _allVehs = _allVehs + [[_tmp_type, _x]];
  17. } forEach _vehicles;
  18. };
  19. _veh = "";
  20. _marker = "";
  21. _markerPos = [];
  22. _markers = [];
  23. _exhaustedTypes = [];
  24. _exhaustedBases = [];
  25. _done = false;
  26. _success = false;
  27. while { !_done } do
  28. {
  29. _skipCheck = false;
  30. //Get type and vehicle
  31. if (_type == "") then
  32. {
  33. //Nothing specified; grab a random vehicle
  34. _tmp = _allVehs call BIS_fnc_selectRandom;
  35. _type = _tmp select 0;
  36. _veh = _tmp select 1;
  37. } else {
  38. if (_type in _types) then
  39. {
  40. _tmp = getArray (missionConfigFile >> "AW_rewards" >> _type);
  41. _veh = _tmp call BIS_fnc_selectRandom;
  42. } else {
  43. _veh = _type;
  44. _class = getText (configFile >> "CfgVehicles" >> _veh >> "vehicleClass");
  45. if (_class == "Armored" || _class == "Car" || _class == "Static") then
  46. {
  47. _type = "land";
  48. } else {
  49. if (_class == "Air" || _class == "Autonomous") then
  50. {
  51. _type = "air";
  52. } else {
  53. _type = "sea";
  54. };
  55. };
  56. };
  57. };
  58. //Get available markers
  59. {
  60. if ([format["_%1", _type], _x] call BIS_fnc_inString) then
  61. {
  62. _markers = _markers + [_x];
  63. };
  64. } forEach baseSpawns;
  65. //Get base intended
  66. if (typeName _base == "ARRAY" || _base in _exhaustedBases) then
  67. {
  68. _base = [_base, _exhaustedBases] call AW_fnc_findNearestBase;
  69. } else {
  70. _tmp = _markers;
  71. {
  72. if (!([_base, _x] call BIS_fnc_inString)) then
  73. {
  74. _markers = _markers - [_x];
  75. };
  76. } forEach _tmp;
  77. };
  78. //Find some valid markers
  79. while { (count _markers) > 0 } do
  80. {
  81. if (_type in _exhaustedTypes) exitWith
  82. {
  83. _type = "";
  84. _skipCheck = true;
  85. };
  86. _marker = _markers call BIS_fnc_selectRandom;
  87. if (isNil "_marker") then { _marker = ""; };
  88. if (_marker != "") then
  89. {
  90. _markerPos = markerPos _marker;
  91. {
  92. if ((_x distance _markerPos) < 5) exitWith
  93. {
  94. _markers = _markers - [_marker];
  95. _marker = "";
  96. };
  97. } forEach vehicles;
  98. if (_marker != "") exitWith
  99. {
  100. _skipCheck = true;
  101. _done = true;
  102. _success = true;
  103. };
  104. };
  105. };
  106. //Final exhaustion checks
  107. if (!_skipCheck) then
  108. {
  109. _done = true;
  110. _exhaustedAllTypes = true;
  111. _exhaustedTypes = _exhaustedTypes + [_type];
  112. _type = [_this,0,"",[""]] call BIS_fnc_param;
  113. if (_type == "") then
  114. {
  115. {
  116. if (!(_x in _exhaustedTypes)) exitWith { _exhaustedAllTypes = false; };
  117. } forEach _types;
  118. };
  119. if (_exhaustedAllTypes) then
  120. {
  121. _exhaustedBases = _exhaustedBases + [_base];
  122. _exhaustedTypes = [];
  123. {
  124. if (!(_x in _exhaustedBases)) exitWith { _done = false; };
  125. } forEach basesOwned;
  126. } else {
  127. _done = false;
  128. };
  129. _veh = "";
  130. _marker = "";
  131. };
  132. };
  133. _ret = if (_success) then
  134. {
  135. [_veh, _markerPos, (markerDir _marker)] call AW_fnc_createVehicle
  136. } else {
  137. objNull
  138. };
  139. _ret