Guest User

init.sqf

a guest
May 13th, 2015
292
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if ( !isServer ) exitWith {};
  2.  
  3. //Initial cross junction starts it all off.
  4. [] spawn { sleep 1; [ 0, 0, sets_nsew ] spawn build_go; };
  5.  
  6. //Load 100m^2 pre-set possibilities, arranged into files by "shape" (sides with connection points to adjacent cells)
  7. execVM "dungeons\e.sqf";
  8. execVM "dungeons\es.sqf";
  9. execVM "dungeons\ew.sqf";
  10. execVM "dungeons\ews.sqf";
  11. execVM "dungeons\n.sqf";
  12. execVM "dungeons\ne.sqf";
  13. execVM "dungeons\nes.sqf";
  14. execVM "dungeons\ns.sqf";
  15. execVM "dungeons\nsew.sqf";
  16. execVM "dungeons\nw.sqf";
  17. execVM "dungeons\nwe.sqf";
  18. execVM "dungeons\nws.sqf";
  19. execVM "dungeons\s.sqf";
  20. execVM "dungeons\w.sqf";
  21. execVM "dungeons\ws.sqf";
  22.  
  23. sleep 0.5;
  24.  
  25. //Array definitions, loaded above ^
  26. cell_array = [];
  27. all_sets = [ sets_e, sets_es, sets_ew, sets_ews, sets_n, sets_ne, sets_nes, sets_ns, sets_nsew, sets_nw, sets_nwe, sets_nws, sets_s, sets_w, sets_ws ];
  28. continue_sets = [ sets_es, sets_ew, sets_ews, sets_ne, sets_nes, sets_ns, sets_nw, sets_nwe, sets_nws, sets_ws ];
  29. from_n_sets = [ sets_ne, sets_nes, sets_ns, sets_nw, sets_nwe, sets_nws ];
  30. from_s_sets = [ sets_es, sets_ews, sets_nes, sets_ns, sets_nws, sets_ws ];
  31. from_e_sets = [ sets_es, sets_ew, sets_ews, sets_ne, sets_nes, sets_nwe ];
  32. from_w_sets = [ sets_ew, sets_ews, sets_nw, sets_nwe, sets_nws, sets_ws ];
  33.  
  34. //KillzoneKid's scripts
  35. KK_fnc_arrayShuffle = {
  36. private [ "_cnt","_el1","_rnd","_indx","_el2" ];
  37. _cnt = count _this - 1;
  38. _el1 = _this select _cnt;
  39. _this resize _cnt;
  40. _rnd = random diag_tickTime * _cnt;
  41. for "_i" from 0 to _cnt do {
  42. _indx = floor random _rnd % _cnt;
  43. _el2 = _this select _indx;
  44. _this set [ _indx, _el1 ];
  45. _el1 = _el2;
  46. };
  47. _this set [ _cnt, _el1 ];
  48. _this
  49. };
  50.  
  51. KK_fnc_isEqual = {
  52. switch (_this select 0) do {
  53. case (_this select 1) : {true};
  54. default {false};
  55. };
  56. };
  57.  
  58. KK_fnc_inString = {
  59. private ["_needle","_haystack","_needleLen","_hay","_found"];
  60. _needle = [_this, 0, "", [""]] call BIS_fnc_param;
  61. _haystack = toArray ([_this, 1, "", [""]] call BIS_fnc_param);
  62. _needleLen = count toArray _needle;
  63. _hay = +_haystack;
  64. _hay resize _needleLen;
  65. _found = false;
  66. for "_i" from _needleLen to count _haystack do {
  67. if (toString _hay == _needle) exitWith {_found = true};
  68. _hay set [_needleLen, _haystack select _i];
  69. _hay set [0, "x"];
  70. _hay = _hay - ["x"]
  71. };
  72. _found
  73. };
  74.  
  75. //By Muzzleflash, used in function below
  76. FancyIsEqual = {
  77. private ["_objectA","_objectB","_result","_elemB","_elemB"];
  78. _objectA = _this select 0;
  79. _objectB = _this select 1;
  80. //Nils?
  81. if (isNil "_objectA") exitWith {isNil "_objectB"};
  82. //Do they have the same type?
  83. if (typeName _objectA != typeName _objectB) exitWith {false};
  84. //Are they values?
  85. if (typeName _objectA != typeName []) exitWith {_objectA == _objectB};
  86. //It must be arrays. Do they have same length?
  87. if (count _objectA != count _objectB) exitWith {false};
  88. //Process each element; assume true
  89. _result = true;
  90. for "_i" from 0 to (count _objectA - 1) do {
  91. _elemA = _objectA select _i;
  92. _elemB = _objectB select _i;
  93. //Process recursively
  94. if (not ([_elemA, _elemB] call FancyIsEqual)) exitWith {_result = false;};
  95. };
  96. _result
  97. };
  98.  
  99. //By Muzzleflash, subtracts duplicate arrays within arrays.
  100. RemoveDuplicates = {
  101. private ["_array", "_unduplicated", "_original","_exists"];
  102. _array = _this;
  103. _unduplicated = [];
  104. {
  105. _original = _x;
  106. _exists = false;
  107. {
  108. if ([_original, _x] call FancyIsEqual) exitWith {
  109. _exists = true;
  110. };
  111. } forEach _unduplicated;
  112. if (not _exists) then {
  113. _unduplicated set [count _unduplicated, _original];
  114. };
  115. } forEach _array;
  116. _unduplicated
  117. };
  118.  
  119. //Build the given shape at the given coordinate.
  120. build_go = {
  121. _x_build = _this select 0;
  122. _y_build = _this select 1;
  123. _picked = _this select 2;
  124. _pick_dungeon = _picked select 0 select 2;
  125. _name_dir = _picked select 0 select 3;
  126.  
  127. //Construct all the parts to this cell
  128. { [ _x, _x_build, _y_build ] call silola_build; } forEach _pick_dungeon;
  129. cell_array pushBack [ [ _x_build, _y_build ] , _picked, _name_dir ];
  130.  
  131. //Continue the path if we're not at an endpoint.
  132. _end_n = [ _picked, sets_n ] call KK_fnc_isEqual;
  133. _end_s = [ _picked, sets_s ] call KK_fnc_isEqual;
  134. _end_e = [ _picked, sets_e ] call KK_fnc_isEqual;
  135. _end_w = [ _picked, sets_w ] call KK_fnc_isEqual;
  136. _ender = _end_n || _end_s || _end_e || _end_w;
  137.  
  138. if ( !_ender ) then {
  139. sleep 1;
  140. [ _name_dir, _x_build, _y_build ] spawn new_path; //comment this line to debug ingame
  141. };
  142. };
  143.  
  144. //Silola build script from x-cam, opec edit
  145. silola_build = {
  146. _obj = objNull;
  147. _dat = _this select 0;
  148. _dat_x = _this select 1;
  149. _dat_y = _this select 2;
  150.  
  151. _x_off = _dat_x * 100;
  152. _y_off = _dat_y * 100;
  153.  
  154. _pre_coord = call compile ( _dat select 1 );
  155. _pre_coord_x = _pre_coord select 0;
  156. _pre_coord_y = _pre_coord select 1;
  157. _new_coord_z = _pre_coord select 2;
  158. _new_coord_x = _pre_coord_x + _x_off;
  159. _new_coord_y = _pre_coord_y + _y_off;
  160.  
  161. _obj = createVehicle [ ( _dat select 0 ), [ _new_coord_x, _new_coord_y, _new_coord_z ], [], 0, "CAN_COLLIDE" ];
  162.  
  163. if ( ( _dat select 4 ) == 0 ) then {
  164. _obj enableSimulation false;
  165. };
  166. _obj setdir ( _dat select 2 );
  167.  
  168. if ( ( _dat select 3 ) == -100 ) then {
  169. _obj setposATL [ _new_coord_x, _new_coord_y, _new_coord_z ];
  170. } else {
  171. _obj setposASL [ _new_coord_x, _new_coord_y, _dat select 3 ];
  172. };
  173.  
  174. if ( ( _dat select 5 ) == 0 ) then {
  175. _obj setVectorUp [ 0, 0, 1 ];
  176. } else {
  177. _obj setVectorUp ( surfaceNormal ( getPosATL _obj ) );
  178. };
  179.  
  180. if (count (_dat select 6) > 0) then {
  181. { call _x } forEach ( _dat select 6 );
  182. };
  183. };
  184.  
  185. //Set up 4 paths around the first central NSEW area. If there are unfinished pathways, continue by making a connection (invoking pre_check).
  186. new_path = {
  187. _cont_pick = _this select 0;
  188. _cont_x = _this select 1;
  189. _cont_y = _this select 2;
  190. _is_4 = _cont_pick == "nsew";
  191.  
  192. if ( _is_4 ) then {
  193. from_n_sets call KK_fnc_arrayShuffle;
  194. _randy_n_set = from_n_sets select 0;
  195. [ 0, -1, _randy_n_set ] spawn build_go;
  196.  
  197. from_s_sets call KK_fnc_arrayShuffle;
  198. _randy_s_set = from_s_sets select 0;
  199. [ 0, 1, _randy_s_set ] spawn build_go;
  200.  
  201. from_e_sets call KK_fnc_arrayShuffle;
  202. _randy_e_set = from_e_sets select 0;
  203. [ -1, 0, _randy_e_set ] spawn build_go;
  204.  
  205. from_w_sets call KK_fnc_arrayShuffle;
  206. _randy_w_set = from_w_sets select 0;
  207. [ 1, 0, _randy_w_set ] spawn build_go;
  208. } else {
  209. _n_found = [ "n", _cont_pick ] call KK_fnc_inString;
  210. _s_found = [ "s", _cont_pick ] call KK_fnc_inString;
  211. _e_found = [ "e", _cont_pick ] call KK_fnc_inString;
  212. _w_found = [ "w", _cont_pick ] call KK_fnc_inString;
  213. if ( _n_found ) then { [ _cont_x, ( _cont_y + 1 ), "n" ] spawn pre_check; };
  214. if ( _s_found ) then { [ _cont_x, ( _cont_y - 1 ), "s" ] spawn pre_check; };
  215. if ( _e_found ) then { [ ( _cont_x + 1 ), _cont_y, "e" ] spawn pre_check; };
  216. if ( _w_found ) then { [ ( _cont_x - 1 ), _cont_y, "w" ] spawn pre_check; };
  217. };
  218. };
  219.  
  220. //Takes submitted coordinate, checks against already-made cells in the cell_array, determines what is already on each side of the submitted coordinate, gets an array of approved shapes from the rulebook function, picks one randomly and builds it.
  221. pre_check = {
  222. _pre_x = _this select 0;
  223. _pre_y = _this select 1;
  224. _pre_dir = _this select 2;
  225. _pre_coord = [ _pre_x, _pre_y ];
  226.  
  227. //Wait a little bit
  228. _randy_sl = random 3;
  229. _rand_sleep = _randy_sl + 1;
  230. sleep _rand_sleep;
  231.  
  232. { //forEach cell_array;
  233. _this_coord = _x select 0;
  234. _this_type = _x select 1;
  235. _occupied = [ _pre_coord, _this_coord ] call KK_fnc_isEqual;
  236. if ( !_occupied ) then {
  237. _check = _pre_coord call check_around;
  238. _final_allowed = [ _pre_dir, _check ] call rulebook;
  239.  
  240. _final_count = count _final_allowed;
  241. _none_allowed = _final_count < 1;
  242. if ( _none_allowed ) then {
  243. switch ( _pre_dir ) do {
  244. case "n": { _final_allowed = [ sets_s ]; };
  245. case "s": { _final_allowed = [ sets_n ]; };
  246. case "e": { _final_allowed = [ sets_w ]; };
  247. case "w": { _final_allowed = [ sets_e ]; };
  248. };
  249. };
  250.  
  251. //_final_allowed = all_sets; //debug
  252. _final_allowed call KK_fnc_arrayShuffle;
  253. _randy_final_set = _final_allowed select 0;
  254.  
  255. [ _pre_x, _pre_y, _randy_final_set ] spawn build_go;
  256. };
  257. } forEach cell_array;
  258. };
  259.  
  260. //Inspects all around the submitted coordinate, returns array of these arrays: [ string: direction of found coord, array: coordinate of found, string: type of thing found ]
  261. check_around = {
  262. _rnd_array = [];
  263. _rnd_x = _this select 0;
  264. _rnd_y = _this select 1;
  265.  
  266. _rnd_n = [ _rnd_x, ( _rnd_y + 1 ) ];
  267. _rnd_s = [ _rnd_x, ( _rnd_y - 1 ) ];
  268. _rnd_e = [ ( _rnd_x + 1 ), _rnd_y ];
  269. _rnd_w = [ ( _rnd_x - 1 ), _rnd_y ];
  270.  
  271. {
  272. _cell_coord = _x select 0;
  273. _cell_types = _x select 2;
  274.  
  275. _rnd_is_n = [ _rnd_n, _cell_coord ] call KK_fnc_isEqual;
  276. _rnd_is_s = [ _rnd_s, _cell_coord ] call KK_fnc_isEqual;
  277. _rnd_is_e = [ _rnd_e, _cell_coord ] call KK_fnc_isEqual;
  278. _rnd_is_w = [ _rnd_w, _cell_coord ] call KK_fnc_isEqual;
  279.  
  280. if ( _rnd_is_n ) then {
  281. _rnd_array pushBack [ "n", _rnd_n, _cell_types ];
  282. };
  283.  
  284. if ( _rnd_is_s ) then {
  285. _rnd_array pushBack [ "s", _rnd_s, _cell_types ];
  286. };
  287.  
  288. if ( _rnd_is_e ) then {
  289. _rnd_array pushBack [ "e", _rnd_e, _cell_types ];
  290. };
  291.  
  292. if ( _rnd_is_w ) then {
  293. _rnd_array pushBack [ "w", _rnd_n, _cell_types ];
  294. };
  295. } forEach cell_array;
  296.  
  297. _rnd_array
  298. };
  299.  
  300. //Takes submitted coordinate and results from the check_around function to determine which shapes are allowed
  301. rulebook = {
  302. _from = _this select 0;
  303. _checked_around = _this select 1;
  304.  
  305. _allow_n = [];
  306. _allow_s = [];
  307. _allow_e = [];
  308. _allow_w = [];
  309. _book_final_allowed = [];
  310.  
  311. {
  312. _book_dir = _x select 0;
  313. _book_str = _x select 2;
  314.  
  315. _n_got = "n" == _book_dir;
  316. _s_got = "s" == _book_dir;
  317. _e_got = "e" == _book_dir;
  318. _w_got = "w" == _book_dir;
  319.  
  320. if ( _n_got ) then {
  321. switch ( _book_str ) do {
  322. case "s": { _allow_n = [ sets_ne, sets_nes, sets_ns, sets_nw, sets_nwe, sets_nws ]; };
  323. case "s" : { _allow_n = [ sets_ne, sets_nes, sets_ns, sets_nw, sets_nwe, sets_nws ]; };
  324. case "ws" : { _allow_n = [ sets_ne, sets_nes, sets_ns, sets_nw, sets_nwe, sets_nws ]; };
  325. case "es" : { _allow_n = [ sets_ne, sets_nes, sets_ns, sets_nw, sets_nwe, sets_nws ]; };
  326. case "ews" : { _allow_n = [ sets_ne, sets_nes, sets_ns, sets_nw, sets_nwe, sets_nws ]; };
  327. case "nes" : { _allow_n = [ sets_ne, sets_nes, sets_ns, sets_nw, sets_nwe, sets_nws ]; };
  328. case "ns" : { _allow_n = [ sets_ne, sets_nes, sets_ns, sets_nw, sets_nwe, sets_nws ]; };
  329. case "nsew" : { _allow_n = [ sets_ne, sets_nes, sets_ns, sets_nw, sets_nwe, sets_nws ]; };
  330. case "nws" : { _allow_n = [ sets_ne, sets_nes, sets_ns, sets_nw, sets_nwe, sets_nws ]; };
  331. };
  332. };
  333. if ( _s_got ) then {
  334. switch ( _book_str ) do {
  335. case "n" : { _allow_s = [ sets_es, sets_ews, sets_nes, sets_ns, sets_nws, sets_ws ]; };
  336. case "ne" : { _allow_s = [ sets_es, sets_ews, sets_nes, sets_ns, sets_nws, sets_ws ]; };
  337. case "nes" : { _allow_s = [ sets_es, sets_ews, sets_nes, sets_ns, sets_nws, sets_ws ]; };
  338. case "ns" : { _allow_s = [ sets_es, sets_ews, sets_nes, sets_ns, sets_nws, sets_ws ]; };
  339. case "nsew" : { _allow_s = [ sets_es, sets_ews, sets_nes, sets_ns, sets_nws, sets_ws ]; };
  340. case "nw" : { _allow_s = [ sets_es, sets_ews, sets_nes, sets_ns, sets_nws, sets_ws ]; };
  341. case "nwe" : { _allow_s = [ sets_es, sets_ews, sets_nes, sets_ns, sets_nws, sets_ws ]; };
  342. case "nws" : { _allow_s = [ sets_es, sets_ews, sets_nes, sets_ns, sets_nws, sets_ws ]; };
  343. };
  344. };
  345. if ( _e_got ) then {
  346. switch ( _book_str ) do {
  347. case "ew" : { _allow_e = [ sets_es, sets_ew, sets_ews, sets_ne, sets_nes, sets_nwe ]; };
  348. case "ews" : { _allow_e = [ sets_es, sets_ew, sets_ews, sets_ne, sets_nes, sets_nwe ]; };
  349. case "nsew" : { _allow_e = [ sets_es, sets_ew, sets_ews, sets_ne, sets_nes, sets_nwe ]; };
  350. case "nw" : { _allow_e = [ sets_es, sets_ew, sets_ews, sets_ne, sets_nes, sets_nwe ]; };
  351. case "nwe" : { _allow_e = [ sets_es, sets_ew, sets_ews, sets_ne, sets_nes, sets_nwe ]; };
  352. case "nws" : { _allow_e = [ sets_es, sets_ew, sets_ews, sets_ne, sets_nes, sets_nwe ]; };
  353. case "w" : { _allow_e = [ sets_es, sets_ew, sets_ews, sets_ne, sets_nes, sets_nwe ]; };
  354. case "ws" : { _allow_e = [ sets_es, sets_ew, sets_ews, sets_ne, sets_nes, sets_nwe ]; };
  355. };
  356. };
  357. if ( _w_got ) then {
  358. switch ( _book_str ) do {
  359. case "e" : { _allow_w = [ sets_ew, sets_ews, sets_nw, sets_nwe, sets_nws, sets_ws ]; };
  360. case "es" : { _allow_w = [ sets_ew, sets_ews, sets_nw, sets_nwe, sets_nws, sets_ws ]; };
  361. case "ew" : { _allow_w = [ sets_ew, sets_ews, sets_nw, sets_nwe, sets_nws, sets_ws ]; };
  362. case "ews" : { _allow_w = [ sets_ew, sets_ews, sets_nw, sets_nwe, sets_nws, sets_ws ]; };
  363. case "ne" : { _allow_w = [ sets_ew, sets_ews, sets_nw, sets_nwe, sets_nws, sets_ws ]; };
  364. case "nes" : { _allow_w = [ sets_ew, sets_ews, sets_nw, sets_nwe, sets_nws, sets_ws ]; };
  365. case "nsew" : { _allow_w = [ sets_ew, sets_ews, sets_nw, sets_nwe, sets_nws, sets_ws ]; };
  366. case "nwe" : { _allow_w = [ sets_ew, sets_ews, sets_nw, sets_nwe, sets_nws, sets_ws ]; };
  367. };
  368. };
  369. } forEach _checked_around;
  370.  
  371. _new_array1 = [ _allow_n, _allow_s ] call RemoveDuplicates;
  372. _new_array2 = [ _new_array1, _allow_e ] call RemoveDuplicates;
  373. _book_final_allowed = [ _new_array2, _allow_w ] call RemoveDuplicates;
  374.  
  375. _book_final_allowed
  376. };
RAW Paste Data