Advertisement
AdamKadmon

Untitled

Jan 25th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.10 KB | None | 0 0
  1. //SpawnBulding.sqf
  2. // Horbin
  3. // 1/4/2015
  4. // 5/15/15 modified to support M3 Editor format.
  5. // 6/11/15 modified to correct 'array of object' option and add Fire/smoke options to M3Editor!
  6. //INPUTS: Building data from Mission main, eCenter, themeIndex, _curMission
  7. //OUTPUTS: array of buildings
  8.  
  9. private ["_buildings","_buildingData","_eCenter","_themeIndex","_curMission","_vehicles"];
  10. _buildingData = _this select 0;
  11. _eCenter = _this select 1;
  12. _lineage = _this select 2;
  13. _curMission = _this select 3;
  14.  
  15. _buildings = [];
  16. _vehicles = [];
  17. // establish global variable prefix
  18. _themeIndex = _lineage select 0;
  19. _generation = _lineage select 1;
  20. _offspringID = _lineage select 2;
  21. _msnTag = format ["FuMS_%1_%2_%3",_themeIndex,_generation,_offspringID];
  22.  
  23. if (!isNil "_buildingData") then
  24. {
  25. if (count _buildingData > 0) then
  26. {
  27. private ["_firstBuilding","_useOffset","_fbLoc"];
  28. // check if 1st building is at [0,0,0]. If so, work offsets!
  29. _firstBuilding = _buildingData select 0;
  30. // if the 1st building is an array to be picked randomly, select one.
  31. if (TypeName _firstBuilding == "ARRAY") then {_firstBuilding = [_firstBuilding] call BIS_fnc_selectRandom;};
  32. _fbLoc = _firstBuilding select 1;
  33. _useOffset = false;
  34. if (_fbLoc select 0 == 0 and _fbLoc select 1 == 0 and _fbLoc select 2 ==0) then {_useOffset = true;}; //3d locations, using offsets!
  35. // diag_log format ["##SpawnBuildings: Debug: 1stBuilding: %1 _useOffset:%2",_firstBuilding, _useOffset];
  36. //foreach _buildingData
  37. {
  38. private ["_type","_offset","_rotation","_persist"];
  39. _type = _x select 0; // should be a 'class string name', 'array of class names', or 'keyword' string
  40. _offset = _x select 1;
  41. _rotation = _x select 2;
  42. _persist = _x select 3;
  43. // valid 'keywords' = M3EDITOR
  44.  
  45. // if _type is an Array, it should be a 'list' of building or vehicle class names, so pick one randomly.
  46. if (TypeName _type == "ARRAY") then {_type = _type call BIS_fnc_selectRandom;};
  47. // if the 'type' field is a string, search for the proper key word to determine the formatting to be handled
  48. // M3EDITOR = M3 Editor file format.
  49. if (TypeName _type == "STRING") then
  50. {
  51. if (toupper _type == "M3EDITOR") then
  52. {
  53. // diag_log format ["<FuMS:%1> SpawnBuildings: Found M3Editor building list!",FuMS_Version];
  54. private ["_xShift","_yShift","_buildingList","_anchorBldg","_fireNsmoke"];
  55. _fireNsmoke = _rotation; // firesmoke value stored at this location for M3Editor formating.
  56. _buildingList = _x select 4;
  57. if (_offset select 0 == -1) then {_xShift=0; _yShift=0; _useOffset = false;}
  58. else
  59. {
  60. _useOffset = true;
  61. _anchorBldg = _buildingList select 0;
  62. _xShift = (_anchorBldg select 1) select 0;
  63. _yShift = (_anchorBldg select 1) select 1;
  64. // diag_log format ["<FuMS:%1> SpawnBuildings:Using offsets of %2,%3",FuMS_Version,_xShift,_yShift];
  65. };
  66. {
  67. private ["_filePosX","_filePosY","_filePosZ","_eCenterX","_eCenterY","_newPos","_filePosition","_newPos","_keep","_bldg"];
  68. _newPos = [0,0,0];
  69. _type = _x select 0;
  70. if ( (TypeName _type) == "ARRAY") then
  71. {
  72. _type = _type call BIS_fnc_selectRandom;
  73. };
  74. // create proper position
  75. if (_useOffset) then
  76. {
  77. _filePosition = _x select 1;
  78. // position as defined in the M3Editor file
  79. _filePosX = _filePosition select 0;
  80. _filePosY = _filePosition select 1;
  81. _filePosZ = _filePosition select 2;
  82. // encounter's center
  83. _eCenterX = _eCenter select 0;
  84. _eCenterY = _eCenter select 1;
  85.  
  86. _newPos set [0, _eCenterX + (_filePosX - _xShift)];
  87. _newPos set [1, _eCenterY + (_filePosY - _yShift)];
  88. _newPos set [2, _filePosZ];
  89. // diag_log format ["<FuMS:%1> SpawnBuildings:Placing %2 at %3",FuMS_Version,_type,_newPos];
  90. }else { _newPos = _x select 1;};
  91.  
  92. if ( _type isKindOf "Air" or _type isKindOf "LandVehicle" or _type isKindOf "Ship") then
  93. {
  94. _bldg = [ _type, _newPos, [], 0 , "CAN_COLLIDE"] call FuMS_fnc_HC_Util_HC_CreateVehicle;
  95.  
  96. _vehicles = _vehicles + [_bldg];
  97. }else
  98. {
  99. if(_type in ["Land_UWreck_Heli_Attack_02_F", "Land_Wreck_Heli_Attack_01_F"]) then
  100. {
  101. _bldg = createSimpleObject [_type, ATLToASL _newpos];
  102. }
  103. else
  104. {
  105. _bldg = createVehicle [ _type, _newpos,[],0,"CAN_COLLIDE"];
  106. };
  107. _buildings = _buildings + [_bldg];
  108. };
  109. _bldg setVariable ["LINEAGE",_msnTag, false];
  110.  
  111. if (_x select 4) then
  112. {
  113. _bldg setDir (_x select 2);
  114. _bldg setPos (_newPos);
  115. }else
  116. {
  117. _bldg setPosATL (_newPos);
  118. _bldg setVectorDirAndUp (_x select 3);
  119. };
  120. _keep = false;
  121. if (_persist==1) then {_keep = true;};
  122. _bldg setVariable ["FuMS_PERSIST",_keep,false];
  123. if (TypeName _fireNsmoke == "STRING") then
  124. {
  125. [_bldg,toupper (_fireNsmoke)] call FuMS_fnc_HC_Util_Effects;
  126. };
  127. // _buildings = _buildings+ [_bldg];
  128. }foreach _buildingList;
  129. }else
  130. {
  131. private ["_fireEffect","_newpos"];
  132. // ASSERT: _type is a building or vehicle class name.
  133. if (count _x > 4) then
  134. {
  135. _fireEffect = toupper(_x select 4);
  136. // diag_log format ["<FuMS> SpawnBuildings: Fire/Smoke effect found for %1",_x];
  137. }else{_fireEffect="NONE";};
  138.  
  139. if (_useOffset) then
  140. {
  141. private ["_newx","_newy","_newz","_offz"];
  142. if (count _eCenter == 2) then {_eCenter set [2,0];};
  143. _newx = _eCenter select 0;
  144. _newx = _newx + (_offset select 0);
  145.  
  146. _newy = _eCenter select 1;
  147. _newy = _newy + (_offset select 1);
  148.  
  149. _newz = _eCenter select 2;
  150. _offz = _offset select 2;
  151. if (isNil "_offz") then {_offz = 0;};
  152. _newz = _newz + _offz;
  153. _newpos = [_newx, _newy, _newz];
  154. }else {_newpos = [ _eCenter, _offset] call FuMS_fnc_HC_MsnCtrl_Util_XPos;};
  155. // _newpos = [_newpos, 0, 100, 1,0, 8,0,[],[[0,0],[0,0]]] call BIS_fnc_findSafePos; // 1m clear, terraingradient 8 pretty hilly
  156. // if ( (_type isKindOf "Air" or _type isKindOf "LandVehicle" or _type isKindOf "Ship") and TypeName (_x select 3) == "ARRAY") then
  157. if (TypeName (_x select 3) == "ARRAY") then
  158. {
  159. private ["_data","_veh","_settings"];
  160. _settings = _x select 3;
  161. // diag_log format ["<FuMS> SpawnBuildings: Vehicle found: pos:%1, type:%2",_newpos, _type];
  162. _data = [_newpos, "none", _type] call FuMS_fnc_HC_MsnCtrl_Util_GetSafeSpawnVehPos;
  163. _veh = [ _type, _data select 0, [], 30 , _data select 1] call FuMS_fnc_HC_Util_HC_CreateVehicle;
  164. _veh setVariable ["LINEAGE",_msnTag, false];
  165. // diag_log format ["<FuMS> SpawnBuildings: created:%1, _type:%2",_veh,_type];
  166. _vehicles = _vehicles + [_veh];
  167. _veh setDir _rotation;
  168. _veh setFuel (_settings select 0);
  169. _veh setVehicleAmmo (_settings select 1);
  170. _veh setHitPointDamage ["hitEngine",_settings select 2];
  171. _veh setHitPointDamage ["hitFuel", _settings select 3];
  172. _veh setHitPointDamage ["HitHull", _settings select 4];
  173.  
  174. [_veh,_fireEffect] call FuMS_fnc_HC_Util_Effects;
  175.  
  176. }else
  177. {
  178. private ["_keep","_adjust","_bldg"];
  179. _bldg = createVehicle [ _type, _newpos,[],0,"CAN_COLLIDE"];
  180. _bldg setDir _rotation;
  181.  
  182. if (surfaceiswater _newpos and count _newpos ==3) then
  183. {
  184. _adjust = _newpos select 2;
  185. _adjust = _adjust - 1.5;
  186. _newpos set [2,_adjust];
  187. _bldg setposASL _newpos;
  188. };
  189.  
  190. _keep = false;
  191. if (_x select 3 == 1) then {_keep = true;};
  192. _bldg setVariable ["FuMS_PERSIST",_keep,false];
  193. _bldg setVariable ["LINEAGE",_msnTag, false];
  194. [_bldg,_fireEffect] call FuMS_fnc_HC_Util_Effects;
  195.  
  196. // store in HC variable.
  197. _buildings = _buildings+ [_bldg];
  198. // HC_HAL_NumBuildings = HC_HAL_NumBuildings + 1;
  199. // diag_log format ["## SPAWN Buildings: _bldg:%1 _buildings:%2",_bldg, _buildings];
  200. };
  201. };
  202. }
  203. else
  204. {
  205. // Data format error if this code is being executed!
  206. diag_log format ["<FuMS> SpawnBuilding: ERROR in building data format for mission %1/%2", FuMS_ActiveThemes select _themeIndex, _curMission];
  207. diag_log format ["<FuMS> SpawnBuilding: Offending building/vehicle : %1", _x];
  208. _buildingData=_buildingData-[_x];
  209. };
  210. } foreach _buildingData;
  211. //diag_log format ["## SPAWN Buildings: %1",_buildings];
  212. if (count _buildings > 0) then
  213. {
  214. ["Buildings",_buildings] call FuMS_fnc_HC_Util_HC_AddObject;
  215. };
  216. if (count _vehicles > 0 ) then
  217. {
  218. ["Vehicles",_vehicles] call FuMS_fnc_HC_Util_HC_AddObject;
  219. };
  220. };
  221. };
  222. [ _buildings, _vehicles]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement