-+-+-+-+-+-+-+-+ START OF PART 36 -+-+-+-+-+-+-+-+
X                END;
X          END;
X`7B Special features.`7D
X        CASE randint(4) of
X          1 :   BEGIN   `7B Large middle pillar  `7D
X                  for i1 := yval-1 to yval+1 do
X                    for i2 := xval-1 to xval+1 do
X                      cave`5Bi1,i2`5D.fval := 8;
X                END;
X          2 :   BEGIN   `7B Inner treasure vault `7D
X                  for i1 := yval-1 to yval+1 do
X                    BEGIN
X                      cave`5Bi1,xval-1`5D.fval   := 8;
X                      cave`5Bi1,xval+1`5D.fval   := 8;
X                    END;
X                  cave`5Byval-1,xval`5D.fval  := 8;
X                  cave`5Byval+1,xval`5D.fval  := 8;
X                  CASE randint(4) of    `7B Place a door  `7D
X                    1 : place_secret_door(yval-1,xval);
X                    2 : place_secret_door(yval+1,xval);
X                    3 : place_secret_door(yval,xval-1);
X                    4 : place_secret_door(yval,xval+1);
X                  END;
X`7B Place a treasure in the vault `7D
X                  place_object(yval,xval);
X`7B Let's gaurd the treasure well.`7D
X                  vault_monster(yval,xval,2+randint(2));
X`7B Traps naturally `7D
X                  vault_trap(yval,xval,4,4,1+randint(3));
X                END;
X          3 :   BEGIN
X                  if (randint(3) = 1) then
X                    BEGIN
X                      cave`5Byval-1,xval-2`5D.fval := 8;
X                      cave`5Byval+1,xval-2`5D.fval := 8;
X                      cave`5Byval-1,xval+2`5D.fval := 8;
X                      cave`5Byval-1,xval+2`5D.fval := 8;
X                      cave`5Byval-2,xval-1`5D.fval := 8;
X                      cave`5Byval-2,xval+1`5D.fval := 8;
X                      cave`5Byval+2,xval-1`5D.fval := 8;
X                      cave`5Byval+2,xval+1`5D.fval := 8;
X                      if (randint(3) = 1) then
X                        BEGIN
X                          place_secret_door(yval,xval-2);
X                          place_secret_door(yval,xval+2);
X                          place_secret_door(yval-2,xval);
X                          place_secret_door(yval+2,xval);
X                        END;
X                    END
X                  else if (randint(3) = 1) then
X                    BEGIN
X                      cave`5Byval  ,xval  `5D.fval := 8;
X                      cave`5Byval-1,xval  `5D.fval := 8;
X                      cave`5Byval+1,xval  `5D.fval := 8;
X                      cave`5Byval  ,xval-1`5D.fval := 8;
X                      cave`5Byval  ,xval+1`5D.fval := 8;
X                    END
X                  else if (randint(3) = 1) then
X                    cave`5Byval,xval`5D.fval := 8;
X                END;
X          4 :   ;
X        END;
X      END;
X
X`7BBuilds a room with a circular inner room. - RLG`7D`20
X    procedure build_type4(yval,xval : integer);
X      var
X        i5,i6 `09`09`09`09: integer;
X`09y_height,y_depth,x_left,x_right : integer;
X        cur_floor`09`09`09: floor_type;
X      BEGIN
X        if (dun_level <= randint(10)) then
X          cur_floor := lopen_floor      `7B Floor with light `7D
X        else
X          cur_floor := dopen_floor;     `7B Dark floor `7D
X        y_height := yval - 4;
X        y_depth  := yval + 4;
X        x_left   := xval - 11;
X        x_right  := xval + 11;
X        for i5 := y_height to y_depth do
X          for i6 := x_left to x_right do
X            begin
X              cave`5Bi5,i6`5D.fval  := cur_floor.ftval;
X              cave`5Bi5,i6`5D.fopen := cur_floor.ftopen;
X            end;
X`09for i5 := 1 to 9 do
X  `09    begin
X`09      i6 := i5-1;
X`09      cave`5Byval+circle`5Bi5`5D,xval+i6`5D.fval  := 8;
X`09      cave`5Byval-circle`5Bi5`5D,xval+i6`5D.fval  := 8;
X`09      cave`5Byval+circle`5Bi5`5D,xval-i6`5D.fval  := 8;
X`09      cave`5Byval-circle`5Bi5`5D,xval-i6`5D.fval  := 8;
X`09    end;
X`09vault_trap(yval,xval,2,4,2);
X`09random_object(yval,xval,2);
X`09vault_monster(yval,xval,3);
X     End;`20
X
X`7B Builds collapsed room  --jeb`7D
X    procedure build_type5(yval,xval : integer);
X       var`20
X        i1, i2`09`09`09`09: integer;
X`09y_height,y_depth,x_left,x_right : integer;
X        cur_floor`09`09`09: floor_type;
X
X      BEGIN `20
X        y_height := yval - 4;
X        y_depth  := yval + 4;
X        x_left   := xval - 11;
X        x_right  := xval + 11;
X        if (dun_level <= randint(10)) then
X          cur_floor := lopen_floor      `7B Floor with light `7D
X        else
X          cur_floor := dopen_floor;     `7B Dark floor `7D
X`09for i1 := y_height to y_depth do
X`09  for i2 := x_left   to x_right do
X`09    if (randint(4) > 1) then
X`09      begin
X`09        cave`5Bi1,i2`5D.fval  := cur_floor.ftval;
X`09        cave`5Bi1,i2`5D.fopen := cur_floor.ftopen;
X`09      end
X`09    else
X`09      begin
X                cave`5Bi1,i2`5D.fval  := 8;  `7Bnon-tunnelable rock`7D
X`09        cave`5Bi1,i2`5D.fopen := false;
X`09      end;
X`09vault_monster(yval,xval,5);
X`09vault_trap(yval,xval,3,10,5);
X`09random_object(yval,xval,5);
X      END;`20
X
X
X`7B Constructs a tunnel between two points `7D
X    procedure tunnel(row1,col1,row2,col2 : integer);
X
X      var
X        tmp_row,tmp_col,row_dir,col_dir,i1,i2,tmp   : integer;
X        tunstk: array `5B1..1000`5D of coords;
X        wallstk : array `5B1..1000`5D of coords;
X        tunptr,wallptr : integer;
X        stop_flag,door_flag : boolean;
X`20
X`7B Main procedure for Tunnel
X  Note: 9 is a temporary value `7D
X      BEGIN
X        stop_flag := false;
X        door_flag := false;
X        tunptr    := 0;
X        wallptr   := 0;
X        correct_dir(row_dir,col_dir,row1,col1,row2,col2);
X        repeat
X          if (randint(100) > dun_tun_chg) then
X            rand_dir(row_dir,col_dir,row1,col1,row2,col2,dun_tun_rnd);
X          tmp_row := row1 + row_dir;
X          tmp_col := col1 + col_dir;
X          while (not(in_bounds(tmp_row,tmp_col))) do
X            BEGIN
X              rand_dir(row_dir,col_dir,row1,col1,row2,col2,dun_tun_rnd);
X              tmp_row := row1 + row_dir;
X              tmp_col := col1 + col_dir;
X            END;
X          with cave`5Btmp_row,tmp_col`5D do
X            if (fval = rock_wall1.ftval) then
X              BEGIN
X                row1 := tmp_row;
X                col1 := tmp_col;
X                if (wallptr < 1000) then
X                  wallptr := wallptr + 1;
X                wallstk`5Bwallptr`5D.y := row1;
X                wallstk`5Bwallptr`5D.x := col1;
X                for i1 := row1-1 to row1+1 do
X                  for i2 := col1-1 to col1+1 do
X                    if (in_bounds(i1,i2)) then
X                      with cave`5Bi1,i2`5D do
X                        if (fval in wall_set) then
X                          fval := 9;
X              END
X            else if (fval = corr_floor1.ftval) then
X              BEGIN
X                row1 := tmp_row;
X                col1 := tmp_col;
X                if (not(door_flag)) then
X                  BEGIN
X                    if (doorptr <= 100) then
X                      BEGIN
X                        doorptr := doorptr + 1;
X                        doorstk`5Bdoorptr`5D.y := row1;
X                        doorstk`5Bdoorptr`5D.x := col1;
X                      END;
X                    door_flag := true;
X                  END;
X                if (randint(100) > dun_tun_con) then
X                  stop_flag := true;
X              END
X            else if (fval = 0) then
X              BEGIN
X                row1 := tmp_row;
X                col1 := tmp_col;
X                if (tunptr < 1000) then
X                  tunptr := tunptr + 1;
X                tunstk`5Btunptr`5D.y := row1;
X                tunstk`5Btunptr`5D.x := col1;
X                door_flag := false;
X              END
X            else if (fval <> 9) then
X              BEGIN
X                row1 := tmp_row;
X                col1 := tmp_col;
X              END;
X        until (((row1 = row2) and (col1 = col2)) or (stop_flag));
X        for i1 := 1 to tunptr do
X          BEGIN
X            cave`5Btunstk`5Bi1`5D.y,tunstk`5Bi1`5D.x`5D.fval  := corr_floor1
V.ftval;
X            cave`5Btunstk`5Bi1`5D.y,tunstk`5Bi1`5D.x`5D.fopen := corr_floor1
V.ftopen;
X          END;
X        for i1 := 1 to wallptr do
X          with cave`5Bwallstk`5Bi1`5D.y,wallstk`5Bi1`5D.x`5D do
X            if (fval = 9) then
X              BEGIN
X                if (randint(100) < dun_tun_pen) then
X                  place_door(wallstk`5Bi1`5D.y,wallstk`5Bi1`5D.x)
X                else
X                  BEGIN
X                    fval  := corr_floor2.ftval;
X                    fopen := corr_floor2.ftopen;
X                  END;
X              END;
X      END;
X`20
X`20
X`7B Places door at y,x position if at least 2 walls found `7D
X    procedure try_door(y,x : integer);
X`20
X      function next_to(y,x : integer) : boolean;
X        BEGIN
X          if (next_to8(y,x,`5B4,5,6`5D) > 2) then
X            if ((cave`5By-1,x`5D.fval in wall_set) and
X                (cave`5By+1,x`5D.fval in wall_set)) then
X              next_to := true
X            else if ((cave`5By,x-1`5D.fval in wall_set) and
X                     (cave`5By,x+1`5D.fval in wall_set)) then
X              next_to := true
X            else
X              next_to := false
X          else
X            next_to := false
X        END;
X`20
X      BEGIN
X        if (randint(100) > dun_tun_jct) then
X          if (cave`5By,x`5D.fval = corr_floor1.ftval) then
X            if (next_to(y,x)) then
X              place_door(y,x);
X      END;
X`20
X`20
X`7B Cave logic flow for generation of new dungeon `7D
X    procedure cave_gen;
X      type
X        spot_type = record
X            ENDx : integer;
X            ENDy : integer;
X        END;
X        room_type = array `5B1..20,1..20`5D of boolean;
X      var
X        room_map    : room_type;
X        i1,i2,i3,i4,y1,x1,y2,x2,pick1,pick2,row_rooms,col_rooms,
X        alloc_level,bx,by : integer;
X        yloc,xloc  : array `5B1..400`5D of worlint;
X        bm_found : boolean;
X`20
XBEGIN
X        seed := get_seed;
X        row_rooms := 2*trunc(cur_height/screen_height);
X        col_rooms := 2*trunc(cur_width /screen_width);
X        for i1 := 1 to row_rooms do
X          for i2 := 1 to col_rooms do
X            room_map`5Bi1,i2`5D := false;
X        for i1 := 1 to randnor(dun_roo_mea,2) do
X          room_map`5Brandint(row_rooms),randint(col_rooms)`5D := true;
X        i3 := 0;
X        for i1 := 1 to row_rooms do
X          for i2 := 1 to col_rooms do
X            if (room_map`5Bi1,i2`5D = true) then
X              BEGIN
X                i3 := i3 + 1;
X                yloc`5Bi3`5D := (i1-1)*(quart_height*2 + 1) + quart_height +
V 1;
X                xloc`5Bi3`5D := (i2-1)*(quart_width*2  + 1) + quart_width  +
V 1;
X                if (dun_power > randint(dun_unusual)) then
X                  CASE randint(5) of
X                    1 : build_type1(yloc`5Bi3`5D,xloc`5Bi3`5D);
X                    2 : build_type2(yloc`5Bi3`5D,xloc`5Bi3`5D);
X                    3 : build_type3(yloc`5Bi3`5D,xloc`5Bi3`5D);
X                    4 : build_type4(yloc`5Bi3`5D,xloc`5Bi3`5D);
X`09`09    5 : build_type5(yloc`5Bi3`5D,xloc`5Bi3`5D);
X                  END
X                else
X                  build_room(yloc`5Bi3`5D,xloc`5Bi3`5D);
X              END;
X        for i4 := 1 to i3 do
X          BEGIN
X            pick1 := randint(i3);
X            pick2 := randint(i3);
X            y1 := yloc`5Bpick1`5D;
X            x1 := xloc`5Bpick1`5D;
X            yloc`5Bpick1`5D := yloc`5Bpick2`5D;
X            xloc`5Bpick1`5D := xloc`5Bpick2`5D;
X            yloc`5Bpick2`5D := y1;
X            xloc`5Bpick2`5D := x1
X          END;
X        doorptr := 0;
X        for i4 := 1 to i3-1 do
X          BEGIN
X            y1 := yloc`5Bi4`5D;
X            x1 := xloc`5Bi4`5D;
X            y2 := yloc`5Bi4+1`5D;
X            x2 := xloc`5Bi4+1`5D;
X            tunnel(y2,x2,y1,x1)
X          END;
X        fill_cave(rock_wall1);
X        for i1 := 1 to dun_str_mag do
X          place_streamer(rock_wall2,dun_str_mc);
X        for i1 := 1 to dun_str_qua do
X          place_streamer(rock_wall3,dun_str_qc);
X       place_boundry;
X`7B Place intersection doors `7D
X        for i1 := 1 to doorptr do
X          BEGIN
X            try_door(doorstk`5Bi1`5D.y,doorstk`5Bi1`5D.x-1);
X            try_door(doorstk`5Bi1`5D.y,doorstk`5Bi1`5D.x+1);
X            try_door(doorstk`5Bi1`5D.y-1,doorstk`5Bi1`5D.x);
X            try_door(doorstk`5Bi1`5D.y+1,doorstk`5Bi1`5D.x);
X          END;
X`09alloc_level := dun_power div 3;
X        if (alloc_level < 2) then
X          alloc_level := 2
X        else if (alloc_level > 10) then
X          alloc_level := 10;
X         if (dun_level < townlist`5Btown_num`5D.max_depth) then
X`09   place_stairs(2,randint(3)+2,3);
X         place_stairs(1,randint(3)+2,3);
X         alloc_monster(`5B1,2`5D,(randint(8)+min_malloc_level+alloc_level),0
V,true);
X         alloc_object(`5B4`5D,3,randint(alloc_level));
X         alloc_object(`5B1,2`5D,5,randnor(treas_room_alloc,3));
X         alloc_object(`5B1,2,4`5D,5,randnor(treas_any_alloc,3));
X         alloc_object(`5B1,2,4`5D,4,randnor(treas_gold_alloc,3));
X         alloc_object(`5B1,2,4`5D,1,randint(alloc_level));
X         if ((py.misc.lev > 5) and (randint(5) = 1))
X         then`09`09`09`09`7BRequirement for BM to appear -mwk`7D
X           BEGIN
X             bm_found:=false;
X             while (NOT(bm_found)) do
X               BEGIN
X                 by := randint(max_height);
X                 bx := randint(max_width);
X                 if (cave`5Bby,bx`5D.fopen) then
X                   BEGIN
X                     place_trap(by,bx,3,0);
X                     do_black_market;
X                     bm_found := true
X                   END
X               END
X           END;
X      END;
X
X`7B Logic flow for generation of new *special* dungeons - 200,250 meters`7D
X
X    procedure special_cave_gen(number : integer);
X
X      var`20
X        alloc_level,i1,i2,rx,ry`09:`09integer;
X`09row_dir,col_dir`09`09:`09integer;
XBEGIN
X        seed := get_seed;`20
X`09case number of
X`09  1: Begin
X`09       for i1 := 1 to cur_height do
X`09         for i2 := 1 to cur_width do
X`09`09   begin
X`09`09     cave`5Bi1,i2`5D.pl := true;
X`09`09     if (randint(5) = 1) then`20
X`09`09       begin
+-+-+-+-+-+-+-+-  END  OF PART 36 +-+-+-+-+-+-+-+-
