* Copyright (c) 1988 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
static char sccsid
[] = "@(#)level.c 5.3 (Berkeley) 6/1/90";
* This source herein may be modified and/or distributed by anybody who
* so desires, with the following restrictions:
* 1.) No portion of this notice shall be removed.
* 2.) Credit shall not be taken for the creation of this source.
* 3.) This code is not to be traded, sold, or used for personal
#define swap(x,y) {t = x; x = y; y = t;}
char *new_level_message
= 0;
short party_room
= NO_ROOM
;
long level_points
[MAX_EXP_LEVEL
] = {
short random_rooms
[MAXROOMS
] = {3, 7, 5, 2, 0, 6, 1, 4, 8};
extern boolean being_held
, wizard
, detect_monster
;
extern boolean see_invisible
;
extern short bear_trap
, levitate
, extra_hp
, less_hp
, cur_room
;
short must_1
, must_2
, must_3
;
if (cur_level
< LAST_DUNGEON
) {
if (cur_level
> max_level
) {
big_room
= ((party_room
!= NO_ROOM
) && rand_percent(1));
make_room(BIG_ROOM
, 0, 0, 0);
for (i
= 0; i
< MAXROOMS
; i
++) {
make_room(i
, must_1
, must_2
, must_3
);
for (j
= 0; j
< MAXROOMS
; j
++) {
(void) connect_rooms(i
, i
+1);
(void) connect_rooms(i
, i
+3);
if (rooms
[i
+1].is_room
& R_NOTHING
) {
if (connect_rooms(i
, i
+2)) {
rooms
[i
+1].is_room
= R_CROSS
;
if (rooms
[i
+3].is_room
& R_NOTHING
) {
if (connect_rooms(i
, i
+6)) {
rooms
[i
+3].is_room
= R_CROSS
;
if (is_all_connected()) {
if (!has_amulet() && (cur_level
>= AMULET_LEVEL
)) {
make_room(rn
, r1
, r2
, r3
)
short left_col
, right_col
, top_row
, bottom_row
;
short row_offset
, col_offset
;
top_row
= get_rand(MIN_ROW
, MIN_ROW
+5);
bottom_row
= get_rand(DROWS
-7, DROWS
-2);
left_col
= get_rand(0, 10);;
right_col
= get_rand(DCOLS
-11, DCOLS
-1);
height
= get_rand(4, (bottom_row
- top_row
+ 1));
width
= get_rand(7, (right_col
- left_col
- 2));
row_offset
= get_rand(0, ((bottom_row
- top_row
) - height
+ 1));
col_offset
= get_rand(0, ((right_col
- left_col
) - width
+ 1));
bottom_row
= top_row
+ height
- 1;
right_col
= left_col
+ width
- 1;
if ((rn
!= r1
) && (rn
!= r2
) && (rn
!= r3
) && rand_percent(40)) {
rooms
[rn
].is_room
= R_ROOM
;
for (i
= top_row
; i
<= bottom_row
; i
++) {
for (j
= left_col
; j
<= right_col
; j
++) {
if ((i
== top_row
) || (i
== bottom_row
)) {
} else if ( ((i
!= top_row
) && (i
!= bottom_row
)) &&
((j
== left_col
) || (j
== right_col
))) {
rooms
[rn
].top_row
= top_row
;
rooms
[rn
].bottom_row
= bottom_row
;
rooms
[rn
].left_col
= left_col
;
rooms
[rn
].right_col
= right_col
;
connect_rooms(room1
, room2
)
short row1
, col1
, row2
, col2
, dir
;
if ((!(rooms
[room1
].is_room
& (R_ROOM
| R_MAZE
))) ||
(!(rooms
[room2
].is_room
& (R_ROOM
| R_MAZE
)))) {
if (same_row(room1
, room2
) &&
(rooms
[room1
].left_col
> rooms
[room2
].right_col
)) {
put_door(&rooms
[room1
], LEFT
, &row1
, &col1
);
put_door(&rooms
[room2
], RIGHT
, &row2
, &col2
);
} else if (same_row(room1
, room2
) &&
(rooms
[room2
].left_col
> rooms
[room1
].right_col
)) {
put_door(&rooms
[room1
], RIGHT
, &row1
, &col1
);
put_door(&rooms
[room2
], LEFT
, &row2
, &col2
);
} else if (same_col(room1
, room2
) &&
(rooms
[room1
].top_row
> rooms
[room2
].bottom_row
)) {
put_door(&rooms
[room1
], UPWARD
, &row1
, &col1
);
put_door(&rooms
[room2
], DOWN
, &row2
, &col2
);
} else if (same_col(room1
, room2
) &&
(rooms
[room2
].top_row
> rooms
[room1
].bottom_row
)) {
put_door(&rooms
[room1
], DOWN
, &row1
, &col1
);
put_door(&rooms
[room2
], UPWARD
, &row2
, &col2
);
draw_simple_passage(row1
, col1
, row2
, col2
, dir
);
} while (rand_percent(4));
rooms
[room1
].doors
[dir
/2].oth_room
= room2
;
rooms
[room1
].doors
[dir
/2].oth_row
= row2
;
rooms
[room1
].doors
[dir
/2].oth_col
= col2
;
rooms
[room2
].doors
[(((dir
+4)%DIRS
)/2)].oth_room
= room1
;
rooms
[room2
].doors
[(((dir
+4)%DIRS
)/2)].oth_row
= row1
;
rooms
[room2
].doors
[(((dir
+4)%DIRS
)/2)].oth_col
= col1
;
for (i
= 0; i
< MAXROOMS
; i
++) {
rooms
[i
].is_room
= R_NOTHING
;
for (j
= 0; j
< 4; j
++) {
rooms
[i
].doors
[j
].oth_room
= NO_ROOM
;
for (i
= 0; i
< MAX_TRAPS
; i
++) {
traps
[i
].trap_type
= NO_TRAP
;
for (i
= 0; i
< DROWS
; i
++) {
for (j
= 0; j
< DCOLS
; j
++) {
detect_monster
= see_invisible
= 0;
being_held
= bear_trap
= 0;
rogue
.row
= rogue
.col
= -1;
put_door(rm
, dir
, row
, col
)
wall_width
= (rm
->is_room
& R_MAZE
) ? 0 : 1;
*row
= ((dir
== UPWARD
) ? rm
->top_row
: rm
->bottom_row
);
*col
= get_rand(rm
->left_col
+wall_width
,
rm
->right_col
-wall_width
);
} while (!(dungeon
[*row
][*col
] & (HORWALL
| TUNNEL
)));
*col
= (dir
== LEFT
) ? rm
->left_col
: rm
->right_col
;
*row
= get_rand(rm
->top_row
+wall_width
,
rm
->bottom_row
-wall_width
);
} while (!(dungeon
[*row
][*col
] & (VERTWALL
| TUNNEL
)));
if (rm
->is_room
& R_ROOM
) {
dungeon
[*row
][*col
] = DOOR
;
if ((cur_level
> 2) && rand_percent(HIDE_PERCENT
)) {
dungeon
[*row
][*col
] |= HIDDEN
;
rm
->doors
[dir
/2].door_row
= *row
;
rm
->doors
[dir
/2].door_col
= *col
;
draw_simple_passage(row1
, col1
, row2
, col2
, dir
)
short row1
, col1
, row2
, col2
, dir
;
if ((dir
== LEFT
) || (dir
== RIGHT
)) {
middle
= get_rand(col1
+1, col2
-1);
for (i
= col1
+1; i
!= middle
; i
++) {
dungeon
[row1
][i
] = TUNNEL
;
for (i
= row1
; i
!= row2
; i
+= (row1
> row2
) ? -1 : 1) {
dungeon
[i
][middle
] = TUNNEL
;
for (i
= middle
; i
!= col2
; i
++) {
dungeon
[row2
][i
] = TUNNEL
;
middle
= get_rand(row1
+1, row2
-1);
for (i
= row1
+1; i
!= middle
; i
++) {
dungeon
[i
][col1
] = TUNNEL
;
for (i
= col1
; i
!= col2
; i
+= (col1
> col2
) ? -1 : 1) {
dungeon
[middle
][i
] = TUNNEL
;
for (i
= middle
; i
!= row2
; i
++) {
dungeon
[i
][col2
] = TUNNEL
;
if (rand_percent(HIDE_PERCENT
)) {
hide_boxed_passage(row1
, col1
, row2
, col2
, 1);
return((room1
/ 3) == (room2
/ 3));
return((room1
% 3) == (room2
% 3));
start
= get_rand(0, (MAXROOMS
-1));
maze_percent
= (cur_level
* 5) / 4;
maze_percent
+= cur_level
;
for (i
= 0; i
< MAXROOMS
; i
++) {
j
= ((start
+ i
) % MAXROOMS
);
if (rooms
[j
].is_room
& R_NOTHING
) {
if (rand_percent(maze_percent
)) {
rooms
[j
].is_room
= R_MAZE
;
make_maze(get_rand(rooms
[j
].top_row
+1, rooms
[j
].bottom_row
-1),
get_rand(rooms
[j
].left_col
+1, rooms
[j
].right_col
-1),
rooms
[j
].top_row
, rooms
[j
].bottom_row
,
rooms
[j
].left_col
, rooms
[j
].right_col
);
hide_boxed_passage(rooms
[j
].top_row
, rooms
[j
].left_col
,
rooms
[j
].bottom_row
, rooms
[j
].right_col
,
for (i
= 0; i
< MAXROOMS
; i
++) {
if ((rooms
[rn
].is_room
& R_NOTHING
) ||
((rooms
[rn
].is_room
& R_CROSS
) && coin_toss())) {
short i
, tunnel_dir
, door_dir
, drow
, dcol
;
short target_room
, rooms_found
= 0;
static short offsets
[4] = {-1, 1, 3, -3};
for (i
= 0; i
< 10; i
++) {
offsets
[srow
] = offsets
[scol
];
for (i
= 0; i
< 4; i
++) {
target_room
= rn
+ offsets
[i
];
if (((target_room
< 0) || (target_room
>= MAXROOMS
)) ||
(!(same_row(rn
,target_room
) || same_col(rn
,target_room
))) ||
(!(rooms
[target_room
].is_room
& (R_ROOM
| R_MAZE
)))) {
if (same_row(rn
, target_room
)) {
tunnel_dir
= (rooms
[rn
].left_col
< rooms
[target_room
].left_col
) ?
tunnel_dir
= (rooms
[rn
].top_row
< rooms
[target_room
].top_row
) ?
door_dir
= ((tunnel_dir
+ 4) % DIRS
);
if (rooms
[target_room
].doors
[door_dir
/2].oth_room
!= NO_ROOM
) {
if (((!do_rec_de
) || did_this
) ||
(!mask_room(rn
, &srow
, &scol
, TUNNEL
))) {
srow
= (rooms
[rn
].top_row
+ rooms
[rn
].bottom_row
) / 2;
scol
= (rooms
[rn
].left_col
+ rooms
[rn
].right_col
) / 2;
put_door(&rooms
[target_room
], door_dir
, &drow
, &dcol
);
draw_simple_passage(srow
, scol
, drow
, dcol
, tunnel_dir
);
rooms
[rn
].is_room
= R_DEADEND
;
dungeon
[srow
][scol
] = TUNNEL
;
if ((i
< 3) && (!did_this
)) {
if ((rooms_found
< 2) && do_rec_de
) {
recursive_deadend(rn
, offsets
, srow
, scol
);
recursive_deadend(rn
, offsets
, srow
, scol
)
short drow
, dcol
, tunnel_dir
;
rooms
[rn
].is_room
= R_DEADEND
;
dungeon
[srow
][scol
] = TUNNEL
;
for (i
= 0; i
< 4; i
++) {
if (((de
< 0) || (de
>= MAXROOMS
)) ||
(!(same_row(rn
, de
) || same_col(rn
, de
)))) {
if (!(rooms
[de
].is_room
& R_NOTHING
)) {
drow
= (rooms
[de
].top_row
+ rooms
[de
].bottom_row
) / 2;
dcol
= (rooms
[de
].left_col
+ rooms
[de
].right_col
) / 2;
tunnel_dir
= (rooms
[rn
].left_col
< rooms
[de
].left_col
) ?
tunnel_dir
= (rooms
[rn
].top_row
< rooms
[de
].top_row
) ?
draw_simple_passage(srow
, scol
, drow
, dcol
, tunnel_dir
);
recursive_deadend(de
, offsets
, drow
, dcol
);
mask_room(rn
, row
, col
, mask
)
for (i
= rooms
[rn
].top_row
; i
<= rooms
[rn
].bottom_row
; i
++) {
for (j
= rooms
[rn
].left_col
; j
<= rooms
[rn
].right_col
; j
++) {
if (dungeon
[i
][j
] & mask
) {
make_maze(r
, c
, tr
, br
, lc
, rc
)
short r
, c
, tr
, br
, lc
, rc
;
for (i
= 0; i
< 10; i
++) {
swap(dirs
[t1
], dirs
[t2
]);
for (i
= 0; i
< 4; i
++) {
(dungeon
[r
-1][c
] != TUNNEL
) &&
(dungeon
[r
-1][c
-1] != TUNNEL
) &&
(dungeon
[r
-1][c
+1] != TUNNEL
) &&
(dungeon
[r
-2][c
] != TUNNEL
)) {
make_maze((r
-1), c
, tr
, br
, lc
, rc
);
(dungeon
[r
+1][c
] != TUNNEL
) &&
(dungeon
[r
+1][c
-1] != TUNNEL
) &&
(dungeon
[r
+1][c
+1] != TUNNEL
) &&
(dungeon
[r
+2][c
] != TUNNEL
)) {
make_maze((r
+1), c
, tr
, br
, lc
, rc
);
(dungeon
[r
][c
-1] != TUNNEL
) &&
(dungeon
[r
-1][c
-1] != TUNNEL
) &&
(dungeon
[r
+1][c
-1] != TUNNEL
) &&
(dungeon
[r
][c
-2] != TUNNEL
)) {
make_maze(r
, (c
-1), tr
, br
, lc
, rc
);
(dungeon
[r
][c
+1] != TUNNEL
) &&
(dungeon
[r
-1][c
+1] != TUNNEL
) &&
(dungeon
[r
+1][c
+1] != TUNNEL
) &&
(dungeon
[r
][c
+2] != TUNNEL
)) {
make_maze(r
, (c
+1), tr
, br
, lc
, rc
);
hide_boxed_passage(row1
, col1
, row2
, col2
, n
)
short row1
, col1
, row2
, col2
, n
;
short row
, col
, row_cut
, col_cut
;
if ((w
>= 5) || (h
>= 5)) {
row_cut
= ((h
>= 2) ? 1 : 0);
col_cut
= ((w
>= 2) ? 1 : 0);
for (i
= 0; i
< n
; i
++) {
for (j
= 0; j
< 10; j
++) {
row
= get_rand(row1
+ row_cut
, row2
- row_cut
);
col
= get_rand(col1
+ col_cut
, col2
- col_cut
);
if (dungeon
[row
][col
] == TUNNEL
) {
dungeon
[row
][col
] |= HIDDEN
;
short nr
; /* try not to put in this room */
for (misses
= 0; ((misses
< 2) && (rn
== nr
)); misses
++) {
gr_row_col(&row
, &col
, (FLOOR
| TUNNEL
| OBJECT
| STAIRS
));
rn
= get_room_number(row
, col
);
if (dungeon
[rogue
.row
][rogue
.col
] & TUNNEL
) {
if (cur_room
!= PASSAGE
) {
light_passage(rogue
.row
, rogue
.col
);
rn
= get_room_number(rogue
.row
, rogue
.col
);
wake_room(rn
, 1, rogue
.row
, rogue
.col
);
message(new_level_message
, 0);
mvaddch(rogue
.row
, rogue
.col
, rogue
.fchar
);
if (dungeon
[rogue
.row
][rogue
.col
] & STAIRS
) {
message("you're floating in the air!", 0);
message("I see no way down", 0);
if (!(dungeon
[rogue
.row
][rogue
.col
] & STAIRS
)) {
message("I see no way up", 0);
message("your way is magically blocked", 0);
new_level_message
= "you feel a wrenching sensation in your gut";
if (rogue
.exp_points
>= level_points
[rogue
.exp
-1]) {
new_exp
= get_exp_level(rogue
.exp_points
);
if (rogue
.exp_points
> MAX_EXP
) {
rogue
.exp_points
= MAX_EXP
+ 1;
for (i
= rogue
.exp
+1; i
<= new_exp
; i
++) {
sprintf(mbuf
, "welcome to level %d", i
);
print_stats(STAT_HP
| STAT_EXP
);
for (i
= 0; i
< (MAX_EXP_LEVEL
- 1); i
++) {
if (level_points
[i
] > e
) {
hp
= (wizard
? 10 : get_rand(3, 10));
real_average
= effective_average
= 0.00;
((rogue
.hp_max
- extra_hp
- INIT_HP
) + less_hp
) / (rogue
.exp
- 1);
effective_average
= (float) (rogue
.hp_max
- INIT_HP
) / (rogue
.exp
- 1);
sprintf(mbuf
, "R-Hp: %.2f, E-Hp: %.2f (!: %d, V: %d)", real_average
,
effective_average
, extra_hp
, less_hp
);
for (i
= 0; i
< (3 * MAXROOMS
); i
++) {
x
= get_rand(0, (MAXROOMS
-1));
y
= get_rand(0, (MAXROOMS
-1));
swap(random_rooms
[x
], random_rooms
[y
]);