-+-+-+-+-+-+-+-+ START OF PART 24 -+-+-+-+-+-+-+-+ X cave`5Bi1,i2`5D.fval := cur_floor.ftval; X cave`5Bi1,i2`5D.fopen := cur_floor.ftopen; X END; X for i1 := (y_height - 1) to (y_depth + 1) do X BEGIN X with cave`5Bi1,x_left-1`5D do X BEGIN X fval := rock_wall1.ftval; X fopen := rock_wall1.ftopen; X END; X with cave`5Bi1,x_right+1`5D do X BEGIN X fval := rock_wall1.ftval; X fopen := rock_wall1.ftopen; X END; X END; X for i1 := x_left to x_right do `20 X BEGIN X with cave`5By_height-1,i1`5D do X BEGIN X fval := rock_wall1.ftval; X fopen := rock_wall1.ftopen; X END; X with cave`5By_depth+1,i1`5D do X BEGIN X fval := rock_wall1.ftval; X fopen := rock_wall1.ftopen; X END; X END; X i0 := 2 + randint(9); X y_height := yval - 1; X y_depth := yval + 1; X x_left := xval - i0; X x_right := xval + i0; X for i1 := y_height to y_depth do X for i2 := x_left to x_right do X BEGIN X cave`5Bi1,i2`5D.fval := cur_floor.ftval; X cave`5Bi1,i2`5D.fopen := cur_floor.ftopen; X END; X for i1 := (y_height - 1) to (y_depth + 1) do X BEGIN X with cave`5Bi1,x_left-1`5D do X if (fval <> cur_floor.ftval) then X BEGIN X fval := rock_wall1.ftval; X fopen := rock_wall1.ftopen; X END; X with cave`5Bi1,x_right+1`5D do X if (fval <> cur_floor.ftval) then X BEGIN X fval := rock_wall1.ftval; X fopen := rock_wall1.ftopen; X END; X END; X for i1 := x_left to x_right do X BEGIN X with cave`5By_height-1,i1`5D do X if (fval <> cur_floor.ftval) then X BEGIN X fval := rock_wall1.ftval; X fopen := rock_wall1.ftopen; X END; X with cave`5By_depth+1,i1`5D do X if (fval <> cur_floor.ftval) then X BEGIN X fval := rock_wall1.ftval; X fopen := rock_wall1.ftopen; 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`20 X`20 X`7B Constructs a tunnel between two points `7D X procedure tunnel(row1,col1,row2,col2 : integer); 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`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; `20 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_level > randint(dun_unusual)) then X CASE randint(3) 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 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; `20 X alloc_level := trunc(dun_level/3); X if (alloc_level < 2) then X alloc_level := 2 X else if (alloc_level > 10) then X alloc_level := 10; X place_stairs(2,randint(2)+2,3); X place_stairs(1,randint(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 >= 25) AND `7BRequirements for entrance`7D X (dun_level = 50) ) `7Binto the black market store. - mwk V`7D X then 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`20 X place_trap(by,bx,3,0); X do_black_market; X bm_found := true X END X END X END; `20 X if (dun_level >= win_mon_appear) then place_win_monster; X END; X`20 X`20 X`7B Builds a store at a row,column coordinate `7D X procedure build_store(store_num,y,x,num_in_row : integer); X var `20 X yval,y_height,y_depth,xval,x_adjst,x_left,x_right,i1,i2,cur_pos : inte Vger; X BEGIN `20 X yval := (y-1)*10 + 6; X xval := (x-1)*(40-6*num_in_row) + (21-3*num_in_row); X`09 `7B this formula yields xval=(x-1)*22+11 if 3 stores in the row +-+-+-+-+-+-+-+- END OF PART 24 +-+-+-+-+-+-+-+-