]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - rogue/level.c
2 * Copyright (c) 1988 The Regents of the University of California.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 static char sccsid
[] = "@(#)level.c 5.3 (Berkeley) 6/1/90";
44 * This source herein may be modified and/or distributed by anybody who
45 * so desires, with the following restrictions:
46 * 1.) No portion of this notice shall be removed.
47 * 2.) Credit shall not be taken for the creation of this source.
48 * 3.) This code is not to be traded, sold, or used for personal
55 #define swap(x,y) {t = x; x = y; y = t;}
60 char *new_level_message
= 0;
61 short party_room
= NO_ROOM
;
64 long level_points
[MAX_EXP_LEVEL
] = {
88 short random_rooms
[MAXROOMS
] = {3, 7, 5, 2, 0, 6, 1, 4, 8};
90 extern boolean being_held
, wizard
, detect_monster
;
91 extern boolean see_invisible
;
92 extern short bear_trap
, levitate
, extra_hp
, less_hp
, cur_room
;
97 short must_1
, must_2
, must_3
;
100 if (cur_level
< LAST_DUNGEON
) {
103 if (cur_level
> max_level
) {
104 max_level
= cur_level
;
106 must_1
= get_rand(0, 5);
140 if (rand_percent(8)) {
143 big_room
= ((party_room
!= NO_ROOM
) && rand_percent(1));
145 make_room(BIG_ROOM
, 0, 0, 0);
147 for (i
= 0; i
< MAXROOMS
; i
++) {
148 make_room(i
, must_1
, must_2
, must_3
);
156 for (j
= 0; j
< MAXROOMS
; j
++) {
160 if (i
< (MAXROOMS
-1)) {
161 (void) connect_rooms(i
, i
+1);
163 if (i
< (MAXROOMS
-3)) {
164 (void) connect_rooms(i
, i
+3);
166 if (i
< (MAXROOMS
-2)) {
167 if (rooms
[i
+1].is_room
& R_NOTHING
) {
168 if (connect_rooms(i
, i
+2)) {
169 rooms
[i
+1].is_room
= R_CROSS
;
173 if (i
< (MAXROOMS
-6)) {
174 if (rooms
[i
+3].is_room
& R_NOTHING
) {
175 if (connect_rooms(i
, i
+6)) {
176 rooms
[i
+3].is_room
= R_CROSS
;
180 if (is_all_connected()) {
186 if (!has_amulet() && (cur_level
>= AMULET_LEVEL
)) {
191 make_room(rn
, r1
, r2
, r3
)
192 short rn
, r1
, r2
, r3
;
194 short left_col
, right_col
, top_row
, bottom_row
;
196 short row_offset
, col_offset
;
240 bottom_row
= DROWS
- 2;
246 bottom_row
= DROWS
- 2;
252 bottom_row
= DROWS
- 2;
255 top_row
= get_rand(MIN_ROW
, MIN_ROW
+5);
256 bottom_row
= get_rand(DROWS
-7, DROWS
-2);
257 left_col
= get_rand(0, 10);;
258 right_col
= get_rand(DCOLS
-11, DCOLS
-1);
262 height
= get_rand(4, (bottom_row
- top_row
+ 1));
263 width
= get_rand(7, (right_col
- left_col
- 2));
265 row_offset
= get_rand(0, ((bottom_row
- top_row
) - height
+ 1));
266 col_offset
= get_rand(0, ((right_col
- left_col
) - width
+ 1));
268 top_row
+= row_offset
;
269 bottom_row
= top_row
+ height
- 1;
271 left_col
+= col_offset
;
272 right_col
= left_col
+ width
- 1;
274 if ((rn
!= r1
) && (rn
!= r2
) && (rn
!= r3
) && rand_percent(40)) {
278 rooms
[rn
].is_room
= R_ROOM
;
280 for (i
= top_row
; i
<= bottom_row
; i
++) {
281 for (j
= left_col
; j
<= right_col
; j
++) {
282 if ((i
== top_row
) || (i
== bottom_row
)) {
284 } else if ( ((i
!= top_row
) && (i
!= bottom_row
)) &&
285 ((j
== left_col
) || (j
== right_col
))) {
294 rooms
[rn
].top_row
= top_row
;
295 rooms
[rn
].bottom_row
= bottom_row
;
296 rooms
[rn
].left_col
= left_col
;
297 rooms
[rn
].right_col
= right_col
;
300 connect_rooms(room1
, room2
)
303 short row1
, col1
, row2
, col2
, dir
;
305 if ((!(rooms
[room1
].is_room
& (R_ROOM
| R_MAZE
))) ||
306 (!(rooms
[room2
].is_room
& (R_ROOM
| R_MAZE
)))) {
309 if (same_row(room1
, room2
) &&
310 (rooms
[room1
].left_col
> rooms
[room2
].right_col
)) {
311 put_door(&rooms
[room1
], LEFT
, &row1
, &col1
);
312 put_door(&rooms
[room2
], RIGHT
, &row2
, &col2
);
314 } else if (same_row(room1
, room2
) &&
315 (rooms
[room2
].left_col
> rooms
[room1
].right_col
)) {
316 put_door(&rooms
[room1
], RIGHT
, &row1
, &col1
);
317 put_door(&rooms
[room2
], LEFT
, &row2
, &col2
);
319 } else if (same_col(room1
, room2
) &&
320 (rooms
[room1
].top_row
> rooms
[room2
].bottom_row
)) {
321 put_door(&rooms
[room1
], UPWARD
, &row1
, &col1
);
322 put_door(&rooms
[room2
], DOWN
, &row2
, &col2
);
324 } else if (same_col(room1
, room2
) &&
325 (rooms
[room2
].top_row
> rooms
[room1
].bottom_row
)) {
326 put_door(&rooms
[room1
], DOWN
, &row1
, &col1
);
327 put_door(&rooms
[room2
], UPWARD
, &row2
, &col2
);
334 draw_simple_passage(row1
, col1
, row2
, col2
, dir
);
335 } while (rand_percent(4));
337 rooms
[room1
].doors
[dir
/2].oth_room
= room2
;
338 rooms
[room1
].doors
[dir
/2].oth_row
= row2
;
339 rooms
[room1
].doors
[dir
/2].oth_col
= col2
;
341 rooms
[room2
].doors
[(((dir
+4)%DIRS
)/2)].oth_room
= room1
;
342 rooms
[room2
].doors
[(((dir
+4)%DIRS
)/2)].oth_row
= row1
;
343 rooms
[room2
].doors
[(((dir
+4)%DIRS
)/2)].oth_col
= col1
;
351 for (i
= 0; i
< MAXROOMS
; i
++) {
352 rooms
[i
].is_room
= R_NOTHING
;
353 for (j
= 0; j
< 4; j
++) {
354 rooms
[i
].doors
[j
].oth_room
= NO_ROOM
;
358 for (i
= 0; i
< MAX_TRAPS
; i
++) {
359 traps
[i
].trap_type
= NO_TRAP
;
361 for (i
= 0; i
< DROWS
; i
++) {
362 for (j
= 0; j
< DCOLS
; j
++) {
363 dungeon
[i
][j
] = NOTHING
;
366 detect_monster
= see_invisible
= 0;
367 being_held
= bear_trap
= 0;
368 party_room
= NO_ROOM
;
369 rogue
.row
= rogue
.col
= -1;
373 put_door(rm
, dir
, row
, col
)
380 wall_width
= (rm
->is_room
& R_MAZE
) ? 0 : 1;
385 *row
= ((dir
== UPWARD
) ? rm
->top_row
: rm
->bottom_row
);
387 *col
= get_rand(rm
->left_col
+wall_width
,
388 rm
->right_col
-wall_width
);
389 } while (!(dungeon
[*row
][*col
] & (HORWALL
| TUNNEL
)));
393 *col
= (dir
== LEFT
) ? rm
->left_col
: rm
->right_col
;
395 *row
= get_rand(rm
->top_row
+wall_width
,
396 rm
->bottom_row
-wall_width
);
397 } while (!(dungeon
[*row
][*col
] & (VERTWALL
| TUNNEL
)));
400 if (rm
->is_room
& R_ROOM
) {
401 dungeon
[*row
][*col
] = DOOR
;
403 if ((cur_level
> 2) && rand_percent(HIDE_PERCENT
)) {
404 dungeon
[*row
][*col
] |= HIDDEN
;
406 rm
->doors
[dir
/2].door_row
= *row
;
407 rm
->doors
[dir
/2].door_col
= *col
;
410 draw_simple_passage(row1
, col1
, row2
, col2
, dir
)
411 short row1
, col1
, row2
, col2
, dir
;
415 if ((dir
== LEFT
) || (dir
== RIGHT
)) {
420 middle
= get_rand(col1
+1, col2
-1);
421 for (i
= col1
+1; i
!= middle
; i
++) {
422 dungeon
[row1
][i
] = TUNNEL
;
424 for (i
= row1
; i
!= row2
; i
+= (row1
> row2
) ? -1 : 1) {
425 dungeon
[i
][middle
] = TUNNEL
;
427 for (i
= middle
; i
!= col2
; i
++) {
428 dungeon
[row2
][i
] = TUNNEL
;
435 middle
= get_rand(row1
+1, row2
-1);
436 for (i
= row1
+1; i
!= middle
; i
++) {
437 dungeon
[i
][col1
] = TUNNEL
;
439 for (i
= col1
; i
!= col2
; i
+= (col1
> col2
) ? -1 : 1) {
440 dungeon
[middle
][i
] = TUNNEL
;
442 for (i
= middle
; i
!= row2
; i
++) {
443 dungeon
[i
][col2
] = TUNNEL
;
446 if (rand_percent(HIDE_PERCENT
)) {
447 hide_boxed_passage(row1
, col1
, row2
, col2
, 1);
451 same_row(room1
, room2
)
453 return((room1
/ 3) == (room2
/ 3));
456 same_col(room1
, room2
)
458 return((room1
% 3) == (room2
% 3));
468 start
= get_rand(0, (MAXROOMS
-1));
469 maze_percent
= (cur_level
* 5) / 4;
471 if (cur_level
> 15) {
472 maze_percent
+= cur_level
;
474 for (i
= 0; i
< MAXROOMS
; i
++) {
475 j
= ((start
+ i
) % MAXROOMS
);
476 if (rooms
[j
].is_room
& R_NOTHING
) {
477 if (rand_percent(maze_percent
)) {
478 rooms
[j
].is_room
= R_MAZE
;
479 make_maze(get_rand(rooms
[j
].top_row
+1, rooms
[j
].bottom_row
-1),
480 get_rand(rooms
[j
].left_col
+1, rooms
[j
].right_col
-1),
481 rooms
[j
].top_row
, rooms
[j
].bottom_row
,
482 rooms
[j
].left_col
, rooms
[j
].right_col
);
483 hide_boxed_passage(rooms
[j
].top_row
, rooms
[j
].left_col
,
484 rooms
[j
].bottom_row
, rooms
[j
].right_col
,
500 for (i
= 0; i
< MAXROOMS
; i
++) {
501 rn
= random_rooms
[i
];
502 if ((rooms
[rn
].is_room
& R_NOTHING
) ||
503 ((rooms
[rn
].is_room
& R_CROSS
) && coin_toss())) {
507 if (r_de
!= NO_ROOM
) {
512 fill_it(rn
, do_rec_de
)
516 short i
, tunnel_dir
, door_dir
, drow
, dcol
;
517 short target_room
, rooms_found
= 0;
519 static short offsets
[4] = {-1, 1, 3, -3};
520 boolean did_this
= 0;
522 for (i
= 0; i
< 10; i
++) {
523 srow
= get_rand(0, 3);
524 scol
= get_rand(0, 3);
526 offsets
[srow
] = offsets
[scol
];
529 for (i
= 0; i
< 4; i
++) {
531 target_room
= rn
+ offsets
[i
];
533 if (((target_room
< 0) || (target_room
>= MAXROOMS
)) ||
534 (!(same_row(rn
,target_room
) || same_col(rn
,target_room
))) ||
535 (!(rooms
[target_room
].is_room
& (R_ROOM
| R_MAZE
)))) {
538 if (same_row(rn
, target_room
)) {
539 tunnel_dir
= (rooms
[rn
].left_col
< rooms
[target_room
].left_col
) ?
542 tunnel_dir
= (rooms
[rn
].top_row
< rooms
[target_room
].top_row
) ?
545 door_dir
= ((tunnel_dir
+ 4) % DIRS
);
546 if (rooms
[target_room
].doors
[door_dir
/2].oth_room
!= NO_ROOM
) {
549 if (((!do_rec_de
) || did_this
) ||
550 (!mask_room(rn
, &srow
, &scol
, TUNNEL
))) {
551 srow
= (rooms
[rn
].top_row
+ rooms
[rn
].bottom_row
) / 2;
552 scol
= (rooms
[rn
].left_col
+ rooms
[rn
].right_col
) / 2;
554 put_door(&rooms
[target_room
], door_dir
, &drow
, &dcol
);
556 draw_simple_passage(srow
, scol
, drow
, dcol
, tunnel_dir
);
557 rooms
[rn
].is_room
= R_DEADEND
;
558 dungeon
[srow
][scol
] = TUNNEL
;
560 if ((i
< 3) && (!did_this
)) {
566 if ((rooms_found
< 2) && do_rec_de
) {
567 recursive_deadend(rn
, offsets
, srow
, scol
);
573 recursive_deadend(rn
, offsets
, srow
, scol
)
579 short drow
, dcol
, tunnel_dir
;
581 rooms
[rn
].is_room
= R_DEADEND
;
582 dungeon
[srow
][scol
] = TUNNEL
;
584 for (i
= 0; i
< 4; i
++) {
585 de
= rn
+ offsets
[i
];
586 if (((de
< 0) || (de
>= MAXROOMS
)) ||
587 (!(same_row(rn
, de
) || same_col(rn
, de
)))) {
590 if (!(rooms
[de
].is_room
& R_NOTHING
)) {
593 drow
= (rooms
[de
].top_row
+ rooms
[de
].bottom_row
) / 2;
594 dcol
= (rooms
[de
].left_col
+ rooms
[de
].right_col
) / 2;
595 if (same_row(rn
, de
)) {
596 tunnel_dir
= (rooms
[rn
].left_col
< rooms
[de
].left_col
) ?
599 tunnel_dir
= (rooms
[rn
].top_row
< rooms
[de
].top_row
) ?
602 draw_simple_passage(srow
, scol
, drow
, dcol
, tunnel_dir
);
604 recursive_deadend(de
, offsets
, drow
, dcol
);
609 mask_room(rn
, row
, col
, mask
)
616 for (i
= rooms
[rn
].top_row
; i
<= rooms
[rn
].bottom_row
; i
++) {
617 for (j
= rooms
[rn
].left_col
; j
<= rooms
[rn
].right_col
; j
++) {
618 if (dungeon
[i
][j
] & mask
) {
628 make_maze(r
, c
, tr
, br
, lc
, rc
)
629 short r
, c
, tr
, br
, lc
, rc
;
639 dungeon
[r
][c
] = TUNNEL
;
641 if (rand_percent(20)) {
642 for (i
= 0; i
< 10; i
++) {
648 swap(dirs
[t1
], dirs
[t2
]);
651 for (i
= 0; i
< 4; i
++) {
655 (dungeon
[r
-1][c
] != TUNNEL
) &&
656 (dungeon
[r
-1][c
-1] != TUNNEL
) &&
657 (dungeon
[r
-1][c
+1] != TUNNEL
) &&
658 (dungeon
[r
-2][c
] != TUNNEL
)) {
659 make_maze((r
-1), c
, tr
, br
, lc
, rc
);
664 (dungeon
[r
+1][c
] != TUNNEL
) &&
665 (dungeon
[r
+1][c
-1] != TUNNEL
) &&
666 (dungeon
[r
+1][c
+1] != TUNNEL
) &&
667 (dungeon
[r
+2][c
] != TUNNEL
)) {
668 make_maze((r
+1), c
, tr
, br
, lc
, rc
);
673 (dungeon
[r
][c
-1] != TUNNEL
) &&
674 (dungeon
[r
-1][c
-1] != TUNNEL
) &&
675 (dungeon
[r
+1][c
-1] != TUNNEL
) &&
676 (dungeon
[r
][c
-2] != TUNNEL
)) {
677 make_maze(r
, (c
-1), tr
, br
, lc
, rc
);
682 (dungeon
[r
][c
+1] != TUNNEL
) &&
683 (dungeon
[r
-1][c
+1] != TUNNEL
) &&
684 (dungeon
[r
+1][c
+1] != TUNNEL
) &&
685 (dungeon
[r
][c
+2] != TUNNEL
)) {
686 make_maze(r
, (c
+1), tr
, br
, lc
, rc
);
693 hide_boxed_passage(row1
, col1
, row2
, col2
, n
)
694 short row1
, col1
, row2
, col2
, n
;
697 short row
, col
, row_cut
, col_cut
;
710 if ((w
>= 5) || (h
>= 5)) {
711 row_cut
= ((h
>= 2) ? 1 : 0);
712 col_cut
= ((w
>= 2) ? 1 : 0);
714 for (i
= 0; i
< n
; i
++) {
715 for (j
= 0; j
< 10; j
++) {
716 row
= get_rand(row1
+ row_cut
, row2
- row_cut
);
717 col
= get_rand(col1
+ col_cut
, col2
- col_cut
);
718 if (dungeon
[row
][col
] == TUNNEL
) {
719 dungeon
[row
][col
] |= HIDDEN
;
729 short nr
; /* try not to put in this room */
731 short rn
= nr
, misses
;
734 for (misses
= 0; ((misses
< 2) && (rn
== nr
)); misses
++) {
735 gr_row_col(&row
, &col
, (FLOOR
| TUNNEL
| OBJECT
| STAIRS
));
736 rn
= get_room_number(row
, col
);
741 if (dungeon
[rogue
.row
][rogue
.col
] & TUNNEL
) {
746 if (cur_room
!= PASSAGE
) {
747 light_up_room(cur_room
);
749 light_passage(rogue
.row
, rogue
.col
);
751 rn
= get_room_number(rogue
.row
, rogue
.col
);
752 wake_room(rn
, 1, rogue
.row
, rogue
.col
);
753 if (new_level_message
) {
754 message(new_level_message
, 0);
755 new_level_message
= 0;
757 mvaddch(rogue
.row
, rogue
.col
, rogue
.fchar
);
765 if (dungeon
[rogue
.row
][rogue
.col
] & STAIRS
) {
767 message("you're floating in the air!", 0);
772 message("I see no way down", 0);
779 if (!(dungeon
[rogue
.row
][rogue
.col
] & STAIRS
)) {
780 message("I see no way up", 0);
784 message("your way is magically blocked", 0);
788 new_level_message
= "you feel a wrenching sensation in your gut";
789 if (cur_level
== 1) {
798 add_exp(e
, promotion
)
806 rogue
.exp_points
+= e
;
808 if (rogue
.exp_points
>= level_points
[rogue
.exp
-1]) {
809 new_exp
= get_exp_level(rogue
.exp_points
);
810 if (rogue
.exp_points
> MAX_EXP
) {
811 rogue
.exp_points
= MAX_EXP
+ 1;
813 for (i
= rogue
.exp
+1; i
<= new_exp
; i
++) {
814 sprintf(mbuf
, "welcome to level %d", i
);
818 rogue
.hp_current
+= hp
;
822 print_stats(STAT_HP
| STAT_EXP
);
825 print_stats(STAT_EXP
);
834 for (i
= 0; i
< (MAX_EXP_LEVEL
- 1); i
++) {
835 if (level_points
[i
] > e
) {
846 hp
= (wizard
? 10 : get_rand(3, 10));
854 float effective_average
;
856 if (rogue
.exp
== 1) {
857 real_average
= effective_average
= 0.00;
859 real_average
= (float)
860 ((rogue
.hp_max
- extra_hp
- INIT_HP
) + less_hp
) / (rogue
.exp
- 1);
861 effective_average
= (float) (rogue
.hp_max
- INIT_HP
) / (rogue
.exp
- 1);
864 sprintf(mbuf
, "R-Hp: %.2f, E-Hp: %.2f (!: %d, V: %d)", real_average
,
865 effective_average
, extra_hp
, less_hp
);
874 for (i
= 0; i
< (3 * MAXROOMS
); i
++) {
876 x
= get_rand(0, (MAXROOMS
-1));
877 y
= get_rand(0, (MAXROOMS
-1));
879 swap(random_rooms
[x
], random_rooms
[y
]);