Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if ( !isServer ) exitWith {};
- //Initial cross junction starts it all off.
- [] spawn { sleep 1; [ 0, 0, sets_nsew ] spawn build_go; };
- //Load 100m^2 pre-set possibilities, arranged into files by "shape" (sides with connection points to adjacent cells)
- execVM "dungeons\e.sqf";
- execVM "dungeons\es.sqf";
- execVM "dungeons\ew.sqf";
- execVM "dungeons\ews.sqf";
- execVM "dungeons\n.sqf";
- execVM "dungeons\ne.sqf";
- execVM "dungeons\nes.sqf";
- execVM "dungeons\ns.sqf";
- execVM "dungeons\nsew.sqf";
- execVM "dungeons\nw.sqf";
- execVM "dungeons\nwe.sqf";
- execVM "dungeons\nws.sqf";
- execVM "dungeons\s.sqf";
- execVM "dungeons\w.sqf";
- execVM "dungeons\ws.sqf";
- sleep 0.5;
- //Array definitions, loaded above ^
- cell_array = [];
- 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 ];
- continue_sets = [ sets_es, sets_ew, sets_ews, sets_ne, sets_nes, sets_ns, sets_nw, sets_nwe, sets_nws, sets_ws ];
- from_n_sets = [ sets_ne, sets_nes, sets_ns, sets_nw, sets_nwe, sets_nws ];
- from_s_sets = [ sets_es, sets_ews, sets_nes, sets_ns, sets_nws, sets_ws ];
- from_e_sets = [ sets_es, sets_ew, sets_ews, sets_ne, sets_nes, sets_nwe ];
- from_w_sets = [ sets_ew, sets_ews, sets_nw, sets_nwe, sets_nws, sets_ws ];
- //KillzoneKid's scripts
- KK_fnc_arrayShuffle = {
- private [ "_cnt","_el1","_rnd","_indx","_el2" ];
- _cnt = count _this - 1;
- _el1 = _this select _cnt;
- _this resize _cnt;
- _rnd = random diag_tickTime * _cnt;
- for "_i" from 0 to _cnt do {
- _indx = floor random _rnd % _cnt;
- _el2 = _this select _indx;
- _this set [ _indx, _el1 ];
- _el1 = _el2;
- };
- _this set [ _cnt, _el1 ];
- _this
- };
- KK_fnc_isEqual = {
- switch (_this select 0) do {
- case (_this select 1) : {true};
- default {false};
- };
- };
- KK_fnc_inString = {
- private ["_needle","_haystack","_needleLen","_hay","_found"];
- _needle = [_this, 0, "", [""]] call BIS_fnc_param;
- _haystack = toArray ([_this, 1, "", [""]] call BIS_fnc_param);
- _needleLen = count toArray _needle;
- _hay = +_haystack;
- _hay resize _needleLen;
- _found = false;
- for "_i" from _needleLen to count _haystack do {
- if (toString _hay == _needle) exitWith {_found = true};
- _hay set [_needleLen, _haystack select _i];
- _hay set [0, "x"];
- _hay = _hay - ["x"]
- };
- _found
- };
- //By Muzzleflash, used in function below
- FancyIsEqual = {
- private ["_objectA","_objectB","_result","_elemB","_elemB"];
- _objectA = _this select 0;
- _objectB = _this select 1;
- //Nils?
- if (isNil "_objectA") exitWith {isNil "_objectB"};
- //Do they have the same type?
- if (typeName _objectA != typeName _objectB) exitWith {false};
- //Are they values?
- if (typeName _objectA != typeName []) exitWith {_objectA == _objectB};
- //It must be arrays. Do they have same length?
- if (count _objectA != count _objectB) exitWith {false};
- //Process each element; assume true
- _result = true;
- for "_i" from 0 to (count _objectA - 1) do {
- _elemA = _objectA select _i;
- _elemB = _objectB select _i;
- //Process recursively
- if (not ([_elemA, _elemB] call FancyIsEqual)) exitWith {_result = false;};
- };
- _result
- };
- //By Muzzleflash, subtracts duplicate arrays within arrays.
- RemoveDuplicates = {
- private ["_array", "_unduplicated", "_original","_exists"];
- _array = _this;
- _unduplicated = [];
- {
- _original = _x;
- _exists = false;
- {
- if ([_original, _x] call FancyIsEqual) exitWith {
- _exists = true;
- };
- } forEach _unduplicated;
- if (not _exists) then {
- _unduplicated set [count _unduplicated, _original];
- };
- } forEach _array;
- _unduplicated
- };
- //Build the given shape at the given coordinate.
- build_go = {
- _x_build = _this select 0;
- _y_build = _this select 1;
- _picked = _this select 2;
- _pick_dungeon = _picked select 0 select 2;
- _name_dir = _picked select 0 select 3;
- //Construct all the parts to this cell
- { [ _x, _x_build, _y_build ] call silola_build; } forEach _pick_dungeon;
- cell_array pushBack [ [ _x_build, _y_build ] , _picked, _name_dir ];
- //Continue the path if we're not at an endpoint.
- _end_n = [ _picked, sets_n ] call KK_fnc_isEqual;
- _end_s = [ _picked, sets_s ] call KK_fnc_isEqual;
- _end_e = [ _picked, sets_e ] call KK_fnc_isEqual;
- _end_w = [ _picked, sets_w ] call KK_fnc_isEqual;
- _ender = _end_n || _end_s || _end_e || _end_w;
- if ( !_ender ) then {
- sleep 1;
- [ _name_dir, _x_build, _y_build ] spawn new_path; //comment this line to debug ingame
- };
- };
- //Silola build script from x-cam, opec edit
- silola_build = {
- _obj = objNull;
- _dat = _this select 0;
- _dat_x = _this select 1;
- _dat_y = _this select 2;
- _x_off = _dat_x * 100;
- _y_off = _dat_y * 100;
- _pre_coord = call compile ( _dat select 1 );
- _pre_coord_x = _pre_coord select 0;
- _pre_coord_y = _pre_coord select 1;
- _new_coord_z = _pre_coord select 2;
- _new_coord_x = _pre_coord_x + _x_off;
- _new_coord_y = _pre_coord_y + _y_off;
- _obj = createVehicle [ ( _dat select 0 ), [ _new_coord_x, _new_coord_y, _new_coord_z ], [], 0, "CAN_COLLIDE" ];
- if ( ( _dat select 4 ) == 0 ) then {
- _obj enableSimulation false;
- };
- _obj setdir ( _dat select 2 );
- if ( ( _dat select 3 ) == -100 ) then {
- _obj setposATL [ _new_coord_x, _new_coord_y, _new_coord_z ];
- } else {
- _obj setposASL [ _new_coord_x, _new_coord_y, _dat select 3 ];
- };
- if ( ( _dat select 5 ) == 0 ) then {
- _obj setVectorUp [ 0, 0, 1 ];
- } else {
- _obj setVectorUp ( surfaceNormal ( getPosATL _obj ) );
- };
- if (count (_dat select 6) > 0) then {
- { call _x } forEach ( _dat select 6 );
- };
- };
- //Set up 4 paths around the first central NSEW area. If there are unfinished pathways, continue by making a connection (invoking pre_check).
- new_path = {
- _cont_pick = _this select 0;
- _cont_x = _this select 1;
- _cont_y = _this select 2;
- _is_4 = _cont_pick == "nsew";
- if ( _is_4 ) then {
- from_n_sets call KK_fnc_arrayShuffle;
- _randy_n_set = from_n_sets select 0;
- [ 0, -1, _randy_n_set ] spawn build_go;
- from_s_sets call KK_fnc_arrayShuffle;
- _randy_s_set = from_s_sets select 0;
- [ 0, 1, _randy_s_set ] spawn build_go;
- from_e_sets call KK_fnc_arrayShuffle;
- _randy_e_set = from_e_sets select 0;
- [ -1, 0, _randy_e_set ] spawn build_go;
- from_w_sets call KK_fnc_arrayShuffle;
- _randy_w_set = from_w_sets select 0;
- [ 1, 0, _randy_w_set ] spawn build_go;
- } else {
- _n_found = [ "n", _cont_pick ] call KK_fnc_inString;
- _s_found = [ "s", _cont_pick ] call KK_fnc_inString;
- _e_found = [ "e", _cont_pick ] call KK_fnc_inString;
- _w_found = [ "w", _cont_pick ] call KK_fnc_inString;
- if ( _n_found ) then { [ _cont_x, ( _cont_y + 1 ), "n" ] spawn pre_check; };
- if ( _s_found ) then { [ _cont_x, ( _cont_y - 1 ), "s" ] spawn pre_check; };
- if ( _e_found ) then { [ ( _cont_x + 1 ), _cont_y, "e" ] spawn pre_check; };
- if ( _w_found ) then { [ ( _cont_x - 1 ), _cont_y, "w" ] spawn pre_check; };
- };
- };
- //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.
- pre_check = {
- _pre_x = _this select 0;
- _pre_y = _this select 1;
- _pre_dir = _this select 2;
- _pre_coord = [ _pre_x, _pre_y ];
- //Wait a little bit
- _randy_sl = random 3;
- _rand_sleep = _randy_sl + 1;
- sleep _rand_sleep;
- { //forEach cell_array;
- _this_coord = _x select 0;
- _this_type = _x select 1;
- _occupied = [ _pre_coord, _this_coord ] call KK_fnc_isEqual;
- if ( !_occupied ) then {
- _check = _pre_coord call check_around;
- _final_allowed = [ _pre_dir, _check ] call rulebook;
- _final_count = count _final_allowed;
- _none_allowed = _final_count < 1;
- if ( _none_allowed ) then {
- switch ( _pre_dir ) do {
- case "n": { _final_allowed = [ sets_s ]; };
- case "s": { _final_allowed = [ sets_n ]; };
- case "e": { _final_allowed = [ sets_w ]; };
- case "w": { _final_allowed = [ sets_e ]; };
- };
- };
- //_final_allowed = all_sets; //debug
- _final_allowed call KK_fnc_arrayShuffle;
- _randy_final_set = _final_allowed select 0;
- [ _pre_x, _pre_y, _randy_final_set ] spawn build_go;
- };
- } forEach cell_array;
- };
- //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 ]
- check_around = {
- _rnd_array = [];
- _rnd_x = _this select 0;
- _rnd_y = _this select 1;
- _rnd_n = [ _rnd_x, ( _rnd_y + 1 ) ];
- _rnd_s = [ _rnd_x, ( _rnd_y - 1 ) ];
- _rnd_e = [ ( _rnd_x + 1 ), _rnd_y ];
- _rnd_w = [ ( _rnd_x - 1 ), _rnd_y ];
- {
- _cell_coord = _x select 0;
- _cell_types = _x select 2;
- _rnd_is_n = [ _rnd_n, _cell_coord ] call KK_fnc_isEqual;
- _rnd_is_s = [ _rnd_s, _cell_coord ] call KK_fnc_isEqual;
- _rnd_is_e = [ _rnd_e, _cell_coord ] call KK_fnc_isEqual;
- _rnd_is_w = [ _rnd_w, _cell_coord ] call KK_fnc_isEqual;
- if ( _rnd_is_n ) then {
- _rnd_array pushBack [ "n", _rnd_n, _cell_types ];
- };
- if ( _rnd_is_s ) then {
- _rnd_array pushBack [ "s", _rnd_s, _cell_types ];
- };
- if ( _rnd_is_e ) then {
- _rnd_array pushBack [ "e", _rnd_e, _cell_types ];
- };
- if ( _rnd_is_w ) then {
- _rnd_array pushBack [ "w", _rnd_n, _cell_types ];
- };
- } forEach cell_array;
- _rnd_array
- };
- //Takes submitted coordinate and results from the check_around function to determine which shapes are allowed
- rulebook = {
- _from = _this select 0;
- _checked_around = _this select 1;
- _allow_n = [];
- _allow_s = [];
- _allow_e = [];
- _allow_w = [];
- _book_final_allowed = [];
- {
- _book_dir = _x select 0;
- _book_str = _x select 2;
- _n_got = "n" == _book_dir;
- _s_got = "s" == _book_dir;
- _e_got = "e" == _book_dir;
- _w_got = "w" == _book_dir;
- if ( _n_got ) then {
- switch ( _book_str ) do {
- case "s": { _allow_n = [ sets_ne, sets_nes, sets_ns, sets_nw, sets_nwe, sets_nws ]; };
- case "s" : { _allow_n = [ sets_ne, sets_nes, sets_ns, sets_nw, sets_nwe, sets_nws ]; };
- case "ws" : { _allow_n = [ sets_ne, sets_nes, sets_ns, sets_nw, sets_nwe, sets_nws ]; };
- case "es" : { _allow_n = [ sets_ne, sets_nes, sets_ns, sets_nw, sets_nwe, sets_nws ]; };
- case "ews" : { _allow_n = [ sets_ne, sets_nes, sets_ns, sets_nw, sets_nwe, sets_nws ]; };
- case "nes" : { _allow_n = [ sets_ne, sets_nes, sets_ns, sets_nw, sets_nwe, sets_nws ]; };
- case "ns" : { _allow_n = [ sets_ne, sets_nes, sets_ns, sets_nw, sets_nwe, sets_nws ]; };
- case "nsew" : { _allow_n = [ sets_ne, sets_nes, sets_ns, sets_nw, sets_nwe, sets_nws ]; };
- case "nws" : { _allow_n = [ sets_ne, sets_nes, sets_ns, sets_nw, sets_nwe, sets_nws ]; };
- };
- };
- if ( _s_got ) then {
- switch ( _book_str ) do {
- case "n" : { _allow_s = [ sets_es, sets_ews, sets_nes, sets_ns, sets_nws, sets_ws ]; };
- case "ne" : { _allow_s = [ sets_es, sets_ews, sets_nes, sets_ns, sets_nws, sets_ws ]; };
- case "nes" : { _allow_s = [ sets_es, sets_ews, sets_nes, sets_ns, sets_nws, sets_ws ]; };
- case "ns" : { _allow_s = [ sets_es, sets_ews, sets_nes, sets_ns, sets_nws, sets_ws ]; };
- case "nsew" : { _allow_s = [ sets_es, sets_ews, sets_nes, sets_ns, sets_nws, sets_ws ]; };
- case "nw" : { _allow_s = [ sets_es, sets_ews, sets_nes, sets_ns, sets_nws, sets_ws ]; };
- case "nwe" : { _allow_s = [ sets_es, sets_ews, sets_nes, sets_ns, sets_nws, sets_ws ]; };
- case "nws" : { _allow_s = [ sets_es, sets_ews, sets_nes, sets_ns, sets_nws, sets_ws ]; };
- };
- };
- if ( _e_got ) then {
- switch ( _book_str ) do {
- case "ew" : { _allow_e = [ sets_es, sets_ew, sets_ews, sets_ne, sets_nes, sets_nwe ]; };
- case "ews" : { _allow_e = [ sets_es, sets_ew, sets_ews, sets_ne, sets_nes, sets_nwe ]; };
- case "nsew" : { _allow_e = [ sets_es, sets_ew, sets_ews, sets_ne, sets_nes, sets_nwe ]; };
- case "nw" : { _allow_e = [ sets_es, sets_ew, sets_ews, sets_ne, sets_nes, sets_nwe ]; };
- case "nwe" : { _allow_e = [ sets_es, sets_ew, sets_ews, sets_ne, sets_nes, sets_nwe ]; };
- case "nws" : { _allow_e = [ sets_es, sets_ew, sets_ews, sets_ne, sets_nes, sets_nwe ]; };
- case "w" : { _allow_e = [ sets_es, sets_ew, sets_ews, sets_ne, sets_nes, sets_nwe ]; };
- case "ws" : { _allow_e = [ sets_es, sets_ew, sets_ews, sets_ne, sets_nes, sets_nwe ]; };
- };
- };
- if ( _w_got ) then {
- switch ( _book_str ) do {
- case "e" : { _allow_w = [ sets_ew, sets_ews, sets_nw, sets_nwe, sets_nws, sets_ws ]; };
- case "es" : { _allow_w = [ sets_ew, sets_ews, sets_nw, sets_nwe, sets_nws, sets_ws ]; };
- case "ew" : { _allow_w = [ sets_ew, sets_ews, sets_nw, sets_nwe, sets_nws, sets_ws ]; };
- case "ews" : { _allow_w = [ sets_ew, sets_ews, sets_nw, sets_nwe, sets_nws, sets_ws ]; };
- case "ne" : { _allow_w = [ sets_ew, sets_ews, sets_nw, sets_nwe, sets_nws, sets_ws ]; };
- case "nes" : { _allow_w = [ sets_ew, sets_ews, sets_nw, sets_nwe, sets_nws, sets_ws ]; };
- case "nsew" : { _allow_w = [ sets_ew, sets_ews, sets_nw, sets_nwe, sets_nws, sets_ws ]; };
- case "nwe" : { _allow_w = [ sets_ew, sets_ews, sets_nw, sets_nwe, sets_nws, sets_ws ]; };
- };
- };
- } forEach _checked_around;
- _new_array1 = [ _allow_n, _allow_s ] call RemoveDuplicates;
- _new_array2 = [ _new_array1, _allow_e ] call RemoveDuplicates;
- _book_final_allowed = [ _new_array2, _allow_w ] call RemoveDuplicates;
- _book_final_allowed
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement