Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// @description buildDungeon(height,width,minwidth,minheight)
  2. /// @param height
  3. /// @param width
  4. /// @param minwidth
  5. /// @param minheight
  6. /*
  7. We start with a rectangular dungeon filled with wall cells. We are going to split this dungeon recursively until each sub-dungeon has approximately the size of a room.
  8. The dungeon splitting uses this operation :
  9.  
  10. 1.choose a random direction : horizontal or vertical splitting
  11. 2.choose a random position (x for vertical, y for horizontal)
  12. 3.split the dungeon into two sub-dungeons
  13. 4. Repeat until the lowest sub-dungeons have approximately the size of the rooms we want to generate.
  14.  
  15. Connecting the BSP
  16. To build corridors, we loop through all the leafs of the tree, connecting each leaf to its sister. If the two rooms have face-to-face walls, we can use a straight corridor. Else we have to use a Z shaped corridor.
  17. Repeat for all levels
  18.  */
  19.  
  20. //script arguments
  21. //randomize();
  22. //random_set_seed(3); //3-4 produces a wrong link.
  23. var height    = argument0;
  24. var width     = argument1;
  25. var minwidth  = argument2;
  26. var minheight = argument3;
  27.  
  28. var spawnPlaced = false;
  29. //setup for bsp records to be stored in an array
  30. enum bsp{
  31. Final,
  32. Parent,
  33. Generation,
  34. Xleft,
  35. Xright,
  36. Ytop,
  37. Ybot,
  38. Joined,
  39. Child1,
  40. Child2,
  41. Sibling
  42. };
  43.  
  44. var bspList = 0; //room records
  45. var bspcount = 0;//current room
  46.  
  47. //initial dungeon size, before subdivisions
  48. bspList[0,bsp.Final]      = false;
  49. bspList[0,bsp.Parent]     = "farts";
  50. bspList[0,bsp.Generation] = 0;
  51. bspList[0,bsp.Xleft]      = 0;
  52. bspList[0,bsp.Xright]     = width;
  53. bspList[0,bsp.Ytop]       = 0;
  54. bspList[0,bsp.Ybot]       = height;
  55. bspList[0,bsp.Joined]     = true;
  56. bspList[0,bsp.Child1]     = 1;
  57. bspList[0,bsp.Child2]     = 2;
  58. bspList[0,bsp.Sibling]    = "farts";
  59.  
  60. //loop through each entry in the bspList until we run out of entries that can be divided along either axis
  61. while(true)
  62. {
  63.     //this is our constantly updated terminate condition
  64.     var entries = array_height_2d(bspList);
  65.     if (bspcount == entries)
  66.     {
  67.         break;
  68.     }
  69.    
  70.     //consider the current dungeon, divide it if it is not finalized
  71.     if (bspList[bspcount,bsp.Final] == false)
  72.     {
  73.         //1.choose a random direction : 0 horizontal or 1 vertical splitting
  74.         if (abs(bspList[bspcount,bsp.Xleft] - bspList[bspcount,bsp.Xright]) < 2*minwidth)
  75.         {
  76.             var dirbranch = 1;
  77.         }
  78.         else if (abs(bspList[bspcount,bsp.Ybot] - bspList[bspcount,bsp.Ytop]) < 2*minheight)
  79.         {
  80.             var dirbranch = 0;
  81.         }
  82.         else
  83.         {
  84.             var dirbranch = irandom(1);
  85.         }
  86.         //2.choose a random position (x for vertical, y for horizontal)
  87.         if (dirbranch == 0) //horizontal
  88.         {
  89.             var leftbound = bspList[bspcount,bsp.Xleft] + minwidth;
  90.             var rightbound = bspList[bspcount,bsp.Xright] - minwidth;
  91.             var splitpos = irandom_range(leftbound,rightbound) ;
  92.         }
  93.         else if (dirbranch == 1) //vertical
  94.         {
  95.             var splitpos = irandom_range(bspList[bspcount,bsp.Ytop] + minheight ,  bspList[bspcount,bsp.Ybot] - minheight);
  96.         }
  97.         //3.split the dungeon into two sub-dungeons/leaves
  98.         //1st leaf
  99.         var leafid = entries;
  100.         bspList[leafid,bsp.Parent]     = bspcount;
  101.         bspList[leafid,bsp.Generation] = bspList[bspcount,bsp.Generation] + 1;
  102.         bspList[bspcount,bsp.Child1]   = leafid; //add children to parent
  103.         bspList[leafid,bsp.Sibling]    = leafid + 1; //add sibling for lookup
  104.         //this part depends on how the split happened.
  105.         //as a rule, leaf one is top/left and two is bot/right. Just because.
  106.         if (dirbranch == 0) //horizontal
  107.         {
  108.             bspList[leafid,bsp.Xleft]  = bspList[bspcount,bsp.Xleft] ;
  109.             bspList[leafid,bsp.Xright] = splitpos;
  110.             bspList[leafid,bsp.Ytop]   = bspList[bspcount,bsp.Ytop];
  111.             bspList[leafid,bsp.Ybot]   = bspList[bspcount,bsp.Ybot];
  112.         }
  113.         else if (dirbranch == 1) //vertical
  114.         {
  115.             bspList[leafid,bsp.Xleft]  = bspList[bspcount,bsp.Xleft] ;
  116.             bspList[leafid,bsp.Xright] = bspList[bspcount,bsp.Xright];
  117.             bspList[leafid,bsp.Ytop]   = bspList[bspcount,bsp.Ytop] ;
  118.             bspList[leafid,bsp.Ybot]   = splitpos;
  119.         }
  120.         //mark as unjoined
  121.         bspList[leafid,bsp.Joined] = false;
  122.  
  123.         //2nd leaf
  124.         leafid = bspList[leafid,bsp.Sibling];
  125.         bspList[leafid,bsp.Parent]     = bspcount;
  126.         bspList[leafid,bsp.Generation] = bspList[bspcount,bsp.Generation] + 1;
  127.         bspList[bspcount,bsp.Child2]   = leafid; //add children to parent
  128.         bspList[leafid,bsp.Sibling]    = leafid - 1; //add sibling for lookup
  129.         //this part depends on how the split happened.
  130.         //as a rule, leaf one is top/left and two is bot/right. Just because.
  131.         if (dirbranch == 0) //horizontal
  132.         {
  133.             bspList[leafid,bsp.Xleft]  = splitpos ;
  134.             bspList[leafid,bsp.Xright] = bspList[bspcount,bsp.Xright];
  135.             bspList[leafid,bsp.Ytop]   = bspList[bspcount,bsp.Ytop];
  136.             bspList[leafid,bsp.Ybot]   = bspList[bspcount,bsp.Ybot];
  137.         }
  138.         else if (dirbranch == 1) //vertical
  139.         {
  140.             bspList[leafid,bsp.Xleft]  = bspList[bspcount,bsp.Xleft] ;
  141.             bspList[leafid,bsp.Xright] = bspList[bspcount,bsp.Xright];
  142.             bspList[leafid,bsp.Ytop]   = splitpos ;
  143.             bspList[leafid,bsp.Ybot]   = bspList[bspcount,bsp.Ybot];
  144.         }
  145.         //not joined yet
  146.         bspList[leafid,bsp.Joined] = false;
  147.         //mark as final/not final
  148.         if (abs(bspList[leafid,bsp.Xleft] - bspList[leafid,bsp.Xright]) <= (2*minwidth) &&
  149.             abs(bspList[leafid,bsp.Ytop] - bspList[leafid,bsp.Ybot]) <= (2*minheight)   ||
  150.            (abs(bspList[leafid-1,bsp.Xleft] - bspList[leafid-1,bsp.Xright]) <= (2*minwidth ) &&
  151.             abs(bspList[leafid-1,bsp.Ytop] - bspList[leafid-1,bsp.Ybot]) <= (2*minheight ))
  152.         )
  153.         {
  154.             bspList[leafid,bsp.Final] = true;
  155.             bspList[leafid-1,bsp.Final] = true;
  156.         }
  157.         else
  158.         {
  159.             bspList[leafid,bsp.Final] = false;
  160.             bspList[leafid-1,bsp.Final] = false;
  161.         }
  162.       }
  163. //move on to next leaf
  164. bspcount ++;
  165. }
  166.  
  167. //Copy final room data into into a ds_grid
  168. var dungeon_map = ds_grid_create(width+1,height+1);
  169. ds_grid_set_region(dungeon_map,0,0,width,height,0); //0 is filled, 1 is walkable
  170.  
  171. var bspcount = 0;
  172. var entries = array_height_2d(bspList);
  173. while (bspcount < entries )
  174. {
  175.     if bspList[bspcount,bsp.Final] == true
  176.     {
  177.         //move the rooms in by one square, prevent them from touching
  178.         var roompad = 1;
  179.         var xleft   = bspList[bspcount,bsp.Xleft] + roompad;
  180.         var xright  = bspList[bspcount,bsp.Xright] - roompad;
  181.         var ytop    = bspList[bspcount,bsp.Ytop] + roompad;
  182.         var ybot    = bspList[bspcount,bsp.Ybot] - roompad;
  183.         var xwig    = abs(xleft-xright);
  184.         var ywig    = abs(ytop-ybot);
  185.         //re-randomize the rooms within their new bounds, keeping in mind the minimum size
  186.        
  187.         if(xwig >= minwidth)
  188.         {
  189.             xright = irandom_range(xleft+minwidth,xright);
  190.         }
  191.         else
  192.         {
  193.             xright = irandom_range(xleft+minwidth/2,xright);
  194.         }
  195.         if(ywig >= minheight)
  196.         {
  197.             ybot = irandom_range(ytop + minheight,ybot);
  198.         }
  199.         else
  200.         {
  201.             ybot = irandom_range(ytop + minheight/2,ybot);
  202.         }
  203.  
  204.             bspList[bspcount,bsp.Xleft]  = xleft;
  205.             bspList[bspcount,bsp.Xright] = xright;
  206.             bspList[bspcount,bsp.Ytop]   = ytop;
  207.             bspList[bspcount,bsp.Ybot]   = ybot;
  208.             ds_grid_set_region(dungeon_map,bspList[bspcount,bsp.Xleft],bspList[bspcount,bsp.Ytop],bspList[bspcount,bsp.Xright],bspList[bspcount,bsp.Ybot],irandom_range(2,4));
  209.            
  210.             //Place the spawn point if we haven't already.
  211.             if (!spawnPlaced)
  212.             {
  213.                 ds_grid_set(dungeon_map,(bspList[bspcount,bsp.Xleft] + bspList[bspcount,bsp.Xright])/2,(bspList[bspcount,bsp.Ytop] + bspList[bspcount,bsp.Ybot])/2,"P");
  214.                 spawnPlaced = true;
  215.             }
  216.    
  217.     }
  218.     bspcount++
  219. }
  220. //list to hold rooms to be joined, parents of final rooms will be added as they are joined
  221. var worklist = ds_list_create();
  222.  
  223. var bspcount = 0;
  224. var entries = array_height_2d(bspList);
  225. while (bspcount < entries)
  226. {
  227.     if (bspList[bspcount,bsp.Final] == true && bspList[bspcount,bsp.Joined] == false)
  228.     {
  229.         var tleaf1 = bspcount;
  230.         var tleaf2 = bspList[bspcount,bsp.Sibling];
  231.         /*so what we want to do is determine the viable range of path locations.
  232.         there are only 2 possible positions:
  233.         1. Both arrayed Horizontally
  234.         2. Both arrayed vertically
  235.         */
  236.         //step one, determine direction of join
  237.        
  238.         if  ((bspList[tleaf1,bsp.Xleft] >= bspList[tleaf2,bsp.Xleft] && bspList[tleaf1,bsp.Xleft] <= bspList[tleaf2,bsp.Xright])
  239.             ||
  240.             (bspList[tleaf2,bsp.Xleft] >= bspList[tleaf1,bsp.Xleft] && bspList[tleaf2,bsp.Xleft] <= bspList[tleaf1,bsp.Xright])
  241.             )
  242.         {
  243.             //vertical join
  244.             var xrangel = max(bspList[tleaf1,bsp.Xleft],bspList[tleaf2,bsp.Xleft]);
  245.             var xranger = min(bspList[tleaf1,bsp.Xright],bspList[tleaf2,bsp.Xright]);
  246.             var hallx   = irandom_range(xrangel,xranger)
  247.             var ybot    = min(bspList[tleaf1,bsp.Ybot],bspList[tleaf2,bsp.Ybot]);
  248.             var ytop    = max(bspList[tleaf1,bsp.Ytop],bspList[tleaf2,bsp.Ytop]);
  249.             //create the hall
  250.             ds_grid_set_region(dungeon_map,hallx,ytop,hallx,ybot,1)
  251.         }
  252.         else
  253.         {
  254.             //horizontal join
  255.             var yrangel = max(bspList[tleaf1,bsp.Ytop],bspList[tleaf2,bsp.Ytop]);
  256.             var yranger = min(bspList[tleaf1,bsp.Ybot],bspList[tleaf2,bsp.Ybot]);
  257.             var hally = irandom_range(yrangel,yranger)
  258.             var xleft = min(bspList[tleaf1,bsp.Xright],bspList[tleaf2,bsp.Xright]);
  259.             var xright = max(bspList[tleaf1,bsp.Xleft],bspList[tleaf2,bsp.Xleft]);
  260.             //create the hall
  261.             ds_grid_set_region(dungeon_map,xleft,hally,xright,hally,1)
  262.         }
  263.         //tick em off      
  264.         bspList[tleaf1,bsp.Joined] = true;
  265.         bspList[tleaf2,bsp.Joined] = true;
  266.         //add parent to worklist
  267.         ds_list_add(worklist,bspList[tleaf1,bsp.Parent]);
  268.        
  269.        
  270.     }
  271.     bspcount++;
  272. }
  273.  
  274.  
  275. //that's all the rooms partnered, now to join the meta-rooms
  276. //final step! go through the worklist ONCE more times, building hallways between segments.
  277. //Each metaroom is added to the worklist only after all its children have been joined
  278. while(ds_list_size(worklist) > 0)
  279. {
  280.     //always pull from bottom of list
  281.     var tleaf1 = worklist[|0];
  282.     var tleaf2 = bspList[tleaf1,bsp.Sibling];
  283.  
  284.     if (bspList[tleaf1,bsp.Joined] == false)
  285.     {        
  286.         if ((bspList[tleaf1,bsp.Xleft] == bspList[tleaf2,bsp.Xleft] && bspList[tleaf1,bsp.Xright] == bspList[tleaf2,bsp.Xright]))
  287.         {
  288.             //Vertical Join
  289.             //First thing: determine which rooms is on top
  290.             if (bspList[tleaf1,bsp.Ytop] < bspList[tleaf2,bsp.Ytop])
  291.             {
  292.                 var topleaf = tleaf1;
  293.                 var botleaf = tleaf2;
  294.             }
  295.             else if (bspList[tleaf1,bsp.Ytop] > bspList[tleaf2,bsp.Ytop])
  296.             {
  297.                 var topleaf = tleaf2;
  298.                 var botleaf = tleaf1;
  299.             }
  300.             //we want to join at the closest point, so move up from topleaf[ybot] and down from botleaf[ytop];
  301.             //there are no possible failure states yet, each will always have 1's somewhere            
  302.             var offset = 0
  303.             while ((offset < abs(bspList[topleaf,bsp.Ytop] - bspList[topleaf,bsp.Ybot])))
  304.             {
  305.                 //test both rows for '1's, end and record if they both have them
  306.                 //you idiot, this needs to be two tests
  307.                 var toptest = ds_grid_value_exists(dungeon_map, bspList[topleaf,bsp.Xleft], bspList[topleaf,bsp.Ybot] - offset, bspList[topleaf,bsp.Xright], bspList[topleaf,bsp.Ybot] - offset, 1);
  308.                 if (toptest == true )
  309.                 {
  310.                     var topy = bspList[topleaf,bsp.Ybot] - offset;
  311.                     break;
  312.                 }
  313.                 offset++
  314.             }
  315.             //now for boty you fucking moron
  316.             var offset = 0
  317.             while( offset < abs(bspList[botleaf,bsp.Ytop] - bspList[botleaf,bsp.Ybot]))
  318.             {
  319.                 var bottest = ds_grid_value_exists(dungeon_map, bspList[botleaf,bsp.Xleft], bspList[botleaf,bsp.Ytop] + offset, bspList[botleaf,bsp.Xright], bspList[botleaf,bsp.Ytop] + offset, 1);
  320.                 if (bottest == true)
  321.                 {
  322.                     var boty = bspList[botleaf,bsp.Ytop] + offset;
  323.                     break;
  324.                 }
  325.                 offset++;
  326.             }
  327.             //Now, using topy and boty as bounds, we search for columns where both have 1's present
  328.             var offset = 0
  329.             var columns = ds_list_create();
  330.             while (offset <= abs(bspList[topleaf,bsp.Xleft] - bspList[topleaf,bsp.Xright]))
  331.             {
  332.                 if(ds_grid_get_sum(dungeon_map, bspList[topleaf,bsp.Xleft] + offset, topy, bspList[topleaf,bsp.Xleft] + offset, boty) >= 2)
  333.                 //a leaf will never contribute more than 1, since we stopped at the first occupied cell.
  334.                 {
  335.                     if (bspList[topleaf,bsp.Xleft] + offset != 0)
  336.                     {
  337.                         ds_list_add(columns,bspList[topleaf,bsp.Xleft] + offset);
  338.                     }                        
  339.                 }
  340.                 offset ++                  
  341.             }
  342.             if (ds_list_size(columns) > 0)//we found at least one shared columnn. If we didnt, shit be zigzag OR WE BE DUMB!
  343.             {
  344.                 //select from the available columns
  345.                 var listsize = ds_list_size(columns);
  346.                 var listind = irandom_range(0,listsize - 1)
  347.                 var hallx  = columns[|listind];
  348.                 //create the hall
  349.                 ds_grid_set_region(dungeon_map,hallx,topy,hallx,boty,1)
  350.             }
  351.             else
  352.             {
  353.                 //also possible we had two ones that both have 1's at the Y offset, but do not have
  354.                 //viable columns at the same x-point.
  355.                 //in that case we need to move the offset? Or reconsider the whole way this works?
  356.                 //currently it doesn't try, so at least its obvious.
  357.                 //find some x values
  358.                 var offset = 0;
  359.                 while (offset <= abs(bspList[topleaf,bsp.Xleft] - bspList[topleaf,bsp.Xright]))
  360.                 {
  361.                 if(ds_grid_get(dungeon_map, bspList[topleaf,bsp.Xleft] + offset, topy) >= 1)
  362.                 {
  363.                     var topx = bspList[topleaf,bsp.Xleft] + offset;
  364.                     break; //right, that's the x value of our top leaf.  
  365.                 }
  366.                 offset ++                  
  367.                 }
  368.                 var offset = 0;
  369.                 while (offset <= abs(bspList[botleaf,bsp.Xleft] - bspList[botleaf,bsp.Xright]))
  370.                 {
  371.                 if(ds_grid_get(dungeon_map, bspList[botleaf,bsp.Xleft] + offset, boty) >= 1)
  372.                 {
  373.                     var botx = bspList[botleaf,bsp.Xleft] + offset;
  374.                     break; //right, that's the x value of our bottom leaf.  
  375.                 }
  376.                 offset ++                  
  377.                 }      
  378.                 if (botx < topx)
  379.                 {
  380.                     var rx = topx;
  381.                     var lx = botx
  382.                 }
  383.                 else
  384.                 {
  385.                     var lx = topx;
  386.                     var rx = botx
  387.                 }          
  388.                 //draw an L-shape?
  389.                 ds_grid_set_region(dungeon_map,rx,topy,rx,boty,1) //3 for debug
  390.                 ds_grid_set_region(dungeon_map,lx,boty,rx,boty,1) //3 for debug
  391.                
  392.                
  393.             }
  394.             ds_list_destroy(columns);
  395.            
  396.         }
  397.         else if ((bspList[tleaf1,bsp.Ytop] == bspList[tleaf2,bsp.Ytop] && bspList[tleaf1,bsp.Ybot] == bspList[tleaf2,bsp.Ybot]))//it must be horizontal and we can just do mins/maxs for days
  398.         {
  399.            
  400.             //HORIZONTAL Join (jesus, a typo in the first line)
  401.             //First thing: determine which room is on the left
  402.             if (bspList[tleaf1,bsp.Xleft] < bspList[tleaf2,bsp.Xleft])
  403.             {
  404.                 var lftleaf = tleaf1;
  405.                 var rgtleaf = tleaf2;
  406.             }
  407.             else if (bspList[tleaf1,bsp.Xleft] > bspList[tleaf2,bsp.Xleft])
  408.             {
  409.                 var lftleaf = tleaf2;
  410.                 var rgtleaf = tleaf1;
  411.             }
  412.             //we want to join at the closest point, so move right from lftleaf[xleft] and left from rgtleaf[xright];
  413.             //there are no possible failure states yet, each will always have 1's somewhere            
  414.             var offset = 0
  415.             while ((offset < abs(bspList[lftleaf,bsp.Xleft] - bspList[lftleaf,bsp.Xright])))
  416.             {
  417.                 //test both rows for '1's, end and record if they both have them
  418.                 //you idiot, this needs to be two tests
  419.                 var lfttest = ds_grid_value_exists(
  420.                 dungeon_map,
  421.                 bspList[lftleaf,bsp.Xright] - offset, bspList[lftleaf,bsp.Ytop], bspList[lftleaf,bsp.Xright] - offset, bspList[lftleaf,bsp.Ybot],1);
  422.                 if (lfttest == true )
  423.                 {
  424.                     var lftx = bspList[lftleaf,bsp.Xright] - offset;
  425.                     break;
  426.                 }
  427.                 offset++
  428.             }
  429.             //now for rgty you fucking moron
  430.             var offset = 0
  431.             while( offset < abs(bspList[rgtleaf,bsp.Xleft] - bspList[rgtleaf,bsp.Xright]))
  432.             {
  433.                 var rgttest = ds_grid_value_exists(dungeon_map, bspList[rgtleaf,bsp.Xleft] + offset,bspList[rgtleaf,bsp.Ytop],bspList[rgtleaf,bsp.Xleft] + offset,  bspList[rgtleaf,bsp.Ybot],  1);
  434.                 if (rgttest == true)
  435.                 {
  436.                     var rgtx = bspList[rgtleaf,bsp.Xleft] + offset;
  437.                     break;
  438.                 }
  439.                 offset++;
  440.             }
  441.             //Now, using lftx and rgtx as bounds, we search for rows where both have 1's present
  442.             var offset = 0
  443.             var rows = ds_list_create();
  444.             while (offset <= abs(bspList[lftleaf,bsp.Ytop] - bspList[lftleaf,bsp.Ybot]))
  445.             {
  446.                 if(ds_grid_get_sum(dungeon_map, lftx,bspList[lftleaf,bsp.Ytop] + offset,rgtx, bspList[lftleaf,bsp.Ytop] + offset) >= 2) //TODO: reverse the function arguments. Its easy they are named well.
  447.                 //a leaf will never contribute more than 1, since we stopped at the first occupied cell.
  448.                 {
  449.                     if (bspList[lftleaf,bsp.Ytop] + offset != 0) //probably don't need this. But it's lucky.
  450.                     {
  451.                         ds_list_add(rows,bspList[lftleaf,bsp.Ytop] + offset);
  452.                     }                        
  453.                 }
  454.                 offset ++                  
  455.             }
  456.             if (ds_list_size(rows) > 0)//we found at least one shared columnn. If we didnt, shit be zigzag OR WE BE DUMB!
  457.             {
  458.                 //select from the available columns
  459.                 var listsize = ds_list_size(rows);
  460.                 var listind = irandom_range(0,listsize - 1)
  461.                 var hally  = rows[|listind];
  462.                 //create the hall
  463.                 ds_grid_set_region(dungeon_map,lftx,hally,rgtx,hally,1)
  464.             }
  465.             else
  466.             {
  467.                 //zigzag join, brute force that sucker
  468.                 //find some y values
  469.                 var offset = 0;
  470.                 while (offset <= abs(bspList[lftleaf,bsp.Ytop] - bspList[lftleaf,bsp.Ybot]))
  471.                 {
  472.                 if(ds_grid_get(dungeon_map, lftx,bspList[lftleaf,bsp.Ytop] + offset) >= 1)
  473.                 {
  474.                     var lfty = bspList[lftleaf,bsp.Ytop] + offset;
  475.                     break; //right, that's the y value of our left leaf.  
  476.                 }
  477.                 offset ++                  
  478.                 }
  479.                 var offset = 0;
  480.                 while (offset <= abs(bspList[rgtleaf,bsp.Ytop] - bspList[rgtleaf,bsp.Ybot]))
  481.                 {
  482.                 if(ds_grid_get(dungeon_map, rgtx, bspList[rgtleaf,bsp.Ytop] + offset) >= 1)
  483.                 {
  484.                     var rgty = bspList[rgtleaf,bsp.Ytop] + offset;
  485.                     break; //right, that's the x value of our bottom leaf.  
  486.                 }
  487.                 offset ++                  
  488.                 }      
  489.                 if (rgty < lfty)
  490.                 {
  491.                     var ty = rgty;
  492.                     var by = lfty;
  493.                 }
  494.                 else
  495.                 {
  496.                     var by = rgty;
  497.                     var ty = lfty;
  498.                 }          
  499.                 //draw an L-shape?
  500.                 ds_grid_set_region(dungeon_map,rgtx,ty,rgtx,by,1) //3 for debug
  501.                 ds_grid_set_region(dungeon_map,lftx,by,rgtx,by,1) //3 for debug
  502.                
  503.             }
  504.             ds_list_destroy(rows);
  505.                        
  506.  
  507.         }
  508.         else
  509.         {
  510.             //zigzag join, this will suck. Wrong, this is detected elsewhere.
  511.         }
  512.             //tick em off      
  513.             bspList[tleaf1,bsp.Joined] = true;
  514.             bspList[tleaf2,bsp.Joined] = true;
  515.             //add parent to worklist
  516.             ds_list_add(worklist,bspList[tleaf1,bsp.Parent]);
  517.     }
  518.     else
  519.     {
  520.         ds_list_delete(worklist,0);
  521.     }                
  522. }
  523. //and spit out the ds_grid for Alex to use. Hi Alex!
  524. return dungeon_map;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement