Advertisement
Brenner650

@FuMS\addons\FuMS\HC\AI\SpawnSoldier.sqf

Sep 22nd, 2018
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.13 KB | None | 0 0
  1. //SpawnSoldier.sqf
  2. // Horbin
  3. // 1/11/15
  4. // Inputs: Group, typeSoldier, position, Theme Index
  5. // Outputs: Unit created.
  6. // Input Data format expected:
  7. // 0:"Type", 1:[ 8 numbers], 2:Uniform, 3:Vest, 4:Helmet, 5:Backpack, 6;Rifle, 7:[3 numbers],
  8. // 8: Pistol,9: [5 numbers beltItems], 10:[3numbers visionItems], 11:[2 Flags],12:[ array of items]
  9. //AddIt = compile preprocessFileLineNumbers "HC\Encounters\Functions\AddIt.sqf";
  10. //GetChoice = compile preprocessFileLineNumbers "HC\Encounters\LogicBomb\GetChoice.sqf";
  11. //AttachMuzzle = compile preprocessFileLineNumbers "HC\Encounters\AI_Logic\AttachMuzzle.sqf";
  12. private ["_group","_type","_pos","_themeIndex","_unit","_typeFound","_aiName","_gear","_flags","_skills","_types","_i","_priweapon","_soldierData","_secweapon"];
  13. _group = _this select 0;
  14. _type = toupper (_this select 1);
  15. _pos = _this select 2;
  16. _themeIndex = _this select 3;
  17.  
  18. if (((FuMS_THEMEDATA select _themeIndex) select 0) select 4) then
  19. {
  20. _soldierData = FuMS_SOLDIERDATA select FuMS_GlobalDataIndex;
  21. }else
  22. {
  23. _soldierData = FuMS_SOLDIERDATA select _themeIndex;
  24. };
  25. if (isNil "_soldierData") exitWith
  26. {
  27. diag_log format ["<FuMS:%2> SpawnSoldier: ERROR: no theme specific SoldierData.sqf for theme #%1",_themeIndex,FuMS_Version];
  28. diag_log format ["Check options in ThemeData.sqf for theme %1",((FuMS_THEMEDATA select _themeIndex) select 0) select 0];
  29. };
  30.  
  31. //diag_log format ["<FuMS:%3> SpawnSoldier: Index:%2 _soldierData:%1",_soldierData,_themeIndex,FuMS_Version];
  32. _typeFound = false;
  33. // locate the data for 'type' soldier.
  34. {
  35. _aiName = toupper (_x select 0); // type name
  36. //diag_log format ["<FuMS:%3> SpawnSoldier: _aiName:%1 _type:%2",_type,_aiName,FuMS_Version];
  37. if (_type == _aiName) then
  38. {
  39. _typeFound = true;
  40. switch (_type) do
  41. {
  42. case "RAPTORM";
  43. case "RAPTORF":
  44. {
  45. if (true) then // addon flag disabled, logic left for now.
  46. {
  47. // All combat related AI logic is handled by the Raptors Addon.
  48. // Waypoint movement is controlled by FuMS, as though the raptor was a normal soldier
  49. if (_type=="RAPTORM") then {_unit = _group createUnit["RaptorAIM1_W", _pos, [], 25, "FORM"]; };
  50. if (_type=="RAPTORF") then {_unit = _group createUnit["RaptorAIF2_E", _pos, [], 25, "FORM"]; };
  51. // _unit addEventHandler ["killed",{[(_this select 0), (_this select 1)] spawn FuMS_fnc_HC_AI_AIKilled;}];
  52. }
  53. else
  54. {
  55. diag_log format ["<FuMS> SpawnSoldier: Request for spawn of Raptors requested and Mod is not enabled!"];
  56. diag_log format ["<FuMS> see http://makearmanotwar.com/entry/ec2EDrOCkM#.VT0zFfnF9EK for the mod."];
  57. diag_log format ["<FuMS> and FuMS installation instructions for usage."];
  58. };
  59. };
  60. case "ZOMBIE":
  61. {
  62. _zombie = ["RyanZombieC_man_1", "RyanZombieC_man_polo_1_F", "RyanZombieC_man_polo_2_F", "RyanZombieC_man_polo_4_F", "RyanZombieC_man_polo_5_F", "RyanZombieC_man_polo_6_F", "RyanZombieC_man_p_fugitive_F", "RyanZombieC_man_w_worker_F", "RyanZombieC_scientist_F", "RyanZombieC_man_hunter_1_F", "RyanZombieC_man_pilot_F", "RyanZombieC_journalist_F", "RyanZombieC_Orestes", "RyanZombieC_Nikos"];
  63. if (!FuMS_ZnDs) then {_zombie = "Exile_Unit_Player";};
  64. _unit = _group createUnit[_zombie call Bis_fnc_selectRandom, _pos, [], 25, "NONE"]; // swap when skins available
  65. _unit setVariable ["FuMS_RyanZombieType", "ZOMBIE"];
  66. };
  67. case "ZOMBIESOLDIER":
  68. {
  69. _zombieSoldier = ["RyanZombieB_Soldier_02_f", "RyanZombieB_Soldier_02_f_1", "RyanZombieB_Soldier_02_f_1_1", "RyanZombieB_Soldier_03_f", "RyanZombieB_Soldier_03_f_1", "RyanZombieB_Soldier_03_f_1_1", "RyanZombieB_Soldier_04_f", "RyanZombieB_Soldier_04_f_1", "RyanZombieB_Soldier_04_f_1_1", "RyanZombieB_Soldier_lite_F", "RyanZombieB_Soldier_lite_F_1"];
  70. if (!FuMS_ZnDs) then {_zombieSoldier = "Exile_Unit_Player";};
  71. _unit = _group createUnit[_zombieSoldier call Bis_fnc_selectRandom, _pos, [], 25, "NONE"]; // swap when skins available
  72. _unit setVariable ["FuMS_RyanZombieType", "ZOMBIESOLDIER"];
  73. };
  74. case "ZOMBIESPIDER":
  75. {
  76. _zombieSpider = ["RyanZombieSpider1", "RyanZombieSpider2", "RyanZombieSpider3", "RyanZombieSpider4", "RyanZombieSpider5", "RyanZombieSpider6", "RyanZombieSpider7", "RyanZombieSpider8", "RyanZombieSpider9", "RyanZombieSpider10", "RyanZombieSpider11", "RyanZombieSpider12", "RyanZombieSpider13", "RyanZombieSpider14"];
  77. if (!FuMS_ZnDs) then {_zombieSpider = "Exile_Unit_Player";};
  78. _unit = _group createUnit[_zombieSpider call Bis_fnc_selectRandom, _pos, [], 25, "NONE"]; // swap when skins available
  79. _unit setVariable ["FuMS_RyanZombieType", "ZOMBIESPIDER"];
  80. };
  81. case "ZOMBIEBOSS":
  82. {
  83. _zombieBoss =["RyanZombieboss1", "RyanZombieboss2", "RyanZombieboss3", "RyanZombieboss4", "RyanZombieboss5", "RyanZombieboss6", "RyanZombieboss7", "RyanZombieboss8", "RyanZombieboss9", "RyanZombieboss10", "RyanZombieboss11", "RyanZombieboss12", "RyanZombieboss13", "RyanZombieboss14"];
  84. if (!FuMS_ZnDs) then {_zombieBoss = "Exile_Unit_Player";};
  85. _unit = _group createUnit[_zombieBoss call Bis_fnc_selectRandom, _pos, [], 25, "NONE"]; // swap when skins available
  86. _unit setVariable ["FuMS_RyanZombieType", "ZOMBIEBOSS"];
  87. };
  88. default
  89. {
  90. // NOTE if I_Soldier_EPOCH type is changed, AllDeadorGone.sqf will need to be modified
  91. _unit = _group createUnit["O_G_Soldier_F", _pos, [], 0, "FORM"];
  92. removeUniform _unit;
  93. removeHeadgear _unit;
  94. removeVest _unit;
  95. removeAllWeapons _unit;
  96. _unit removeweapon "ItemWatch";
  97. _unit removeweapon "ItemRadio";
  98. _unit removeweapon "ItemCompass";
  99. _unit removeweapon "ItemMap";
  100. // Destroys gear for AI killed by AI and handle other stuff
  101. // ONLY NEEDS TO RUN ON HeadlessClient!
  102. // If a port to server only occurs, this will possibly need to be modified to MP to support server notifications.
  103. _gear = [_x select 2] call FuMS_fnc_HC_Loot_GetChoice;if (_gear != "") then {_unit forceAddUniform _gear;};
  104. // if (toupper _type == "ZOMBIE")then { _unit setObjectTextureGlobal [0, "HC\Zombies\zskin.jpg"];};
  105. _gear = [_x select 3] call FuMS_fnc_HC_Loot_GetChoice;if (_gear != "") then {_unit addVest _gear;};
  106. _gear = [_x select 5] call FuMS_fnc_HC_Loot_GetChoice;if (_gear != "") then {_unit addBackpack _gear;};
  107. // Rifle
  108. _gear = [_x select 6] call FuMS_fnc_HC_Loot_GetChoice;
  109. //diag_log format ["##SpawnSoldier: Rifle-gear:%1",_gear];
  110. _priweapon = "";
  111. if (TypeName _gear =="ARRAY") then
  112. {
  113. _priweapon = _gear select 0;
  114. _unit addWeapon _priweapon;
  115. _mag = getArray (configFile >> "CfgWeapons" >> _priweapon >> "magazines") select 0;
  116. // diag_log format ["<FuMS> SpawnSoldier: %1 with %2 has ammo %3",_unit,_priweapon,_mag];
  117. _unit addMagazines [ _mag, FuMS_SoldierMagCount_Rifle];
  118. // _unit addMagazine [(_gear select 1),_numRifleMags];
  119. }else
  120. {
  121. if (_gear != "") then
  122. {
  123. _priweapon= _gear;
  124. _unit addWeapon _priweapon;
  125. _mag = getArray (configFile >> "CfgWeapons" >> _priweapon >> "magazines") select 0;
  126. _unit addMagazines [ _mag, FuMS_SoldierMagCount_Rifle];
  127. };
  128.  
  129. // diag_log format ["##SpawnSoldier: Rifle added:%1",_priweapon];
  130. //Pistol
  131. _secweapon = "";
  132. _gear = [_x select 8] call FuMS_fnc_HC_Loot_GetChoice;
  133. // diag_log format ["##SpawnSoldier: Pistol-gear:%1",_gear];
  134. if (TypeName _gear =="ARRAY") then
  135. {
  136. _secweapon = _gear select 0;
  137. _unit addWeapon _secweapon;
  138. _mag = getArray (configFile >> "CfgWeapons" >> _secweapon >> "magazines") select 0;
  139. _unit addMagazines [ _mag, FuMS_SoldierMagCount_Pistol];
  140. //_unit addMagazine [(_gear select 1),_numPistolMags];
  141. }else
  142. {
  143. if (_gear != "") then
  144. {
  145. _secweapon= _gear;
  146. _unit addWeapon _secweapon;
  147. _mag = getArray (configFile >> "CfgWeapons" >> _secweapon >> "magazines") select 0;
  148. _unit addMagazines [ _mag, FuMS_SoldierMagCount_Pistol];
  149. };
  150. };
  151. // Rifle Attachments
  152. //diag_log format ["##Starting to add Rifle Attachments!"];
  153.  
  154. _gear = _x select 7;
  155. //diag_log format ["##Trying to add Scope:%1 to Primary weapon",(_gear select 0)];
  156. if (TypeName (_gear select 0) == "STRING") then { _unit addPrimaryWeaponItem (_gear select 0);};
  157. if (TypeName (_gear select 0) == "ARRAY") then { _unit addPrimaryWeaponItem ( (_gear select 0) call BIS_fnc_selectRandom);};
  158. if ([_gear select 0] call FuMS_fnc_HC_Loot_AddIt) then{ _unit addPrimaryWeaponItem (FuMS_W_Attachments call BIS_fnc_selectRandom);}; //scopes
  159. //diag_log format ["## Trying to add Muzzle:%1 to Primary weapon",(_gear select 1)];
  160. if ([_gear select 1] call FuMS_fnc_HC_Loot_AddIt) then
  161. {
  162. _muzzle = [_priweapon] call FuMS_fnc_HC_AI_AttachMuzzle;
  163. //if (_muzzle != "None") then
  164. if (!isNil "_muzzle") then
  165. {
  166. // diag_log format ["##SpawnSolder: Adding %1",_muzzle];
  167. _unit addPrimaryWeaponItem _muzzle;
  168. };
  169. }; //muzzle
  170. if ([_gear select 2] call FuMS_fnc_HC_Loot_AddIt) then { _unit addPrimaryWeaponItem "acc_flashlight"}; //flashlight
  171. // Belt Items
  172. _gear = _x select 9;
  173. if ([_gear select 0] call FuMS_fnc_HC_Loot_AddIt) then {_unit addweapon "ItemMap";}; //Map.
  174. if ([_gear select 1] call FuMS_fnc_HC_Loot_AddIt) then {_unit addweapon "ItemCompass";}; //Compass
  175. if ([_gear select 3] call FuMS_fnc_HC_Loot_AddIt) then {_unit addweapon "ItemGPS";}; //GPS
  176. if ([_gear select 4] call FuMS_fnc_HC_Loot_AddIt) then {_unit addweapon "ItemWatch";}; //Watch
  177. if ((_gear select 5) > 0 ) then
  178. {
  179. // _radio = format ["EpochRadio%1",(_gear select 5)];
  180. _unit addweapon "ItemRadio";
  181. }; //Radio
  182. // Vision items
  183. _gear = _x select 10;
  184. if ([_gear select 0] call FuMS_fnc_HC_Loot_AddIt) then {_unit addweapon "Binocular";}; //Binoculars
  185. if ([_gear select 1] call FuMS_fnc_HC_Loot_AddIt) then {_unit addweapon "Rangefinder";}; //RangeFinders
  186. if ([_gear select 2] call FuMS_fnc_HC_Loot_AddIt) then {_unit addweapon "NVGoggles_INDEP"}; //NVGs
  187. // Other Equipment --see below--
  188. // Flags
  189. _flags = _x select 11;
  190. // in water, so give them scuba gear!
  191. if (_flags select 0) then
  192. {
  193. if (surfaceIsWater _pos) then
  194. {
  195. _unit forceAddUniform "U_B_Wetsuit" ;
  196. _unit addVest "V_RebreatherB";
  197. _unit addGoggles "G_Diving";
  198. };
  199. };
  200. // give them unlimited ammo!
  201. if (_flags select 1) then
  202. {
  203. _unit addeventhandler ["fired",
  204. {
  205. _gunDevice = vehicle (_this select 0); // if in a vehicle and firing, refill vehicle's ammo. _gunDevice is the AI if not in a vehicle.
  206. _gunDevice setvehicleammo 1;
  207. }];
  208. };
  209. // give them some RPG's!
  210. _rpg = _flags select 2;
  211. if (!isNil "_rpg") then
  212. {
  213. private ["_launcher","_ammo1","_ammo2"];
  214. _launcher = "none";
  215. _ammo1 = "none";
  216. _ammo2 = "none";
  217. if (TypeName _rpg == "BOOL") then
  218. {
  219. if (_rpg) then
  220. {
  221. _ammo1 = "RPG32_HE_F";
  222. _ammo2 = "RPG32_F";
  223. _launcher ="launch_RPG32_F";
  224. };
  225. }
  226. else
  227. {
  228. if (toupper _rpg == "RANDOM") then
  229. {
  230. _rpg = ["AIR","LAND"] call BIS_fnc_selectRandom;
  231. };
  232. if (toupper _rpg == "LAND") then
  233. {
  234. _ammo1 = "RPG32_HE_F";
  235. _ammo2 = "RPG32_F";
  236. _launcher = "launch_RPG32_F";
  237. }else
  238. {
  239. _ammo1 = "Titan_AA";
  240. _ammo2 = "Titan_AA";
  241. _launcher = "launch_I_Titan_F";
  242. };
  243. };
  244. if (_launcher != "none") then
  245. {
  246. _unit addMagazines [_ammo1, 1];
  247. _unit addMagazines [_ammo2, 1];
  248. _unit addWeapon _launcher;
  249. }
  250. };
  251. _isCaptured = _flags select 3;
  252. if (!isNil "_isCaptured") then
  253. {
  254. if (_isCaptured) then
  255. {
  256. _unit setCaptive true;
  257. // diag_log format ["<FuMS> SpawnSoldier: Set %1 as a captive:%2",_unit,captive _unit];
  258. };
  259. // diag_log format ["<FuMS> SpawnSoldier: Set %1 as a captive:%2",_unit,captive _unit];
  260. };
  261. // Set skills
  262. _skills = _x select 1;
  263. _types = ["aimingAccuracy","aimingShake","aimingSpeed","spotDistance","spotTime","courage","reloadSpeed","commanding"];
  264. for [ {_i=0},{_i<8},{_i=_i+1}] do
  265. {
  266. if (FuMS_SoldierSkillsOverride select _i == 0) then
  267. {
  268. _unit setSkill [ (_types select _i), (_skills select _i)];
  269. }else
  270. {
  271. _unit setSkill [ (_types select _i), (FuMS_SoldierSkillsOverride select _i)];
  272. };
  273. _unit setSkill ["general", 0.9]; // or you could do _unit setSkill 1; which will be the ultimate test, but they'll be true killers....
  274. _unit allowFleeing 0;
  275. };
  276. // Set FuMS specific AI Logic
  277. [_unit] spawn FuMS_fnc_HC_AI_Logic_VehStuck;
  278. };
  279. }
  280. };
  281. // All AI, Zombies, and Raptors
  282. _unit addEventHandler ["killed",{[(_this select 0), (_this select 1)] spawn FuMS_fnc_HC_AI_AIKilled;}];
  283. // Add custom variables
  284. _gear = [_x select 4] call FuMS_fnc_HC_Loot_GetChoice;if (_gear != "") then {_unit addHeadgear _gear;};
  285. _gear = _x select 12;
  286. // diag_log format ["##SpawnSoldier: Other Equipment:%1",_gear];
  287. {
  288. private ["_item","_variance","_min","_numitems"];
  289. // diag_log format ["##SpawnSoldier: Attempting to add %1", _x];
  290. _item = [_x select 0] call FuMS_fnc_HC_Loot_GetChoice;
  291. if (_item != "") then
  292. {
  293. _variance = _x select 1;
  294. _min = _variance select 0;
  295. _numItems = _min + floor (random ( (_variance select 1)-_min) );
  296. // diag_log format ["##SpawnSoldier: Adding %1 %2",_numItems, _item];
  297. _unit addMagazines [ _item, _numItems];
  298. };
  299. }foreach _gear;
  300.  
  301. _faction = _x select 13;
  302. _unit setVariable ["FumS_Krypto", _faction];
  303. // diag_log format ["<FuMS> SpawnSoldier: %1 Crypto/Faction data %2",_unit, _faction];
  304. };
  305. }foreach _soldierData;
  306.  
  307. if (!_typeFound) then
  308. {
  309. diag_log format ["*******************************************************"];
  310. diag_log format ["******SpawnSoldier: %1 not found in Theme index %2's SoldierData.sqf",_type, _themeIndex];
  311. diag_log format ["*******************************************************"];
  312. };
  313. _unit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement