]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - rogue/level.c
1 /* $NetBSD: level.c,v 1.3 1995/04/22 10:27:37 cgd Exp $ */
4 * Copyright (c) 1988, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 static char sccsid
[] = "@(#)level.c 8.1 (Berkeley) 5/31/93";
43 static char rcsid
[] = "$NetBSD: level.c,v 1.3 1995/04/22 10:27:37 cgd Exp $";
50 * This source herein may be modified and/or distributed by anybody who
51 * so desires, with the following restrictions:
52 * 1.) No portion of this notice shall be removed.
53 * 2.) Credit shall not be taken for the creation of this source.
54 * 3.) This code is not to be traded, sold, or used for personal
61 #define swap(x,y) {t = x; x = y; y = t;}
66 char *new_level_message
= 0;
67 short party_room
= NO_ROOM
;
70 long level_points
[MAX_EXP_LEVEL
] = {
94 short random_rooms
[MAXROOMS
] = {3, 7, 5, 2, 0, 6, 1, 4, 8};
96 extern boolean being_held
, wizard
, detect_monster
;
97 extern boolean see_invisible
;
98 extern short bear_trap
, levitate
, extra_hp
, less_hp
, cur_room
;
103 short must_1
, must_2
, must_3
;
106 if (cur_level
< LAST_DUNGEON
) {
109 if (cur_level
> max_level
) {
110 max_level
= cur_level
;
112 must_1
= get_rand(0, 5);
146 if (rand_percent(8)) {
149 big_room
= ((party_room
!= NO_ROOM
) && rand_percent(1));
151 make_room(BIG_ROOM
, 0, 0, 0);
153 for (i
= 0; i
< MAXROOMS
; i
++) {
154 make_room(i
, must_1
, must_2
, must_3
);
162 for (j
= 0; j
< MAXROOMS
; j
++) {
166 if (i
< (MAXROOMS
-1)) {
167 (void) connect_rooms(i
, i
+1);
169 if (i
< (MAXROOMS
-3)) {
170 (void) connect_rooms(i
, i
+3);
172 if (i
< (MAXROOMS
-2)) {
173 if (rooms
[i
+1].is_room
& R_NOTHING
) {
174 if (connect_rooms(i
, i
+2)) {
175 rooms
[i
+1].is_room
= R_CROSS
;
179 if (i
< (MAXROOMS
-6)) {
180 if (rooms
[i
+3].is_room
& R_NOTHING
) {
181 if (connect_rooms(i
, i
+6)) {
182 rooms
[i
+3].is_room
= R_CROSS
;
186 if (is_all_connected()) {
192 if (!has_amulet() && (cur_level
>= AMULET_LEVEL
)) {
197 make_room(rn
, r1
, r2
, r3
)
198 short rn
, r1
, r2
, r3
;
200 short left_col
, right_col
, top_row
, bottom_row
;
202 short row_offset
, col_offset
;
246 bottom_row
= DROWS
- 2;
252 bottom_row
= DROWS
- 2;
258 bottom_row
= DROWS
- 2;
261 top_row
= get_rand(MIN_ROW
, MIN_ROW
+5);
262 bottom_row
= get_rand(DROWS
-7, DROWS
-2);
263 left_col
= get_rand(0, 10);;
264 right_col
= get_rand(DCOLS
-11, DCOLS
-1);
268 height
= get_rand(4, (bottom_row
- top_row
+ 1));
269 width
= get_rand(7, (right_col
- left_col
- 2));
271 row_offset
= get_rand(0, ((bottom_row
- top_row
) - height
+ 1));
272 col_offset
= get_rand(0, ((right_col
- left_col
) - width
+ 1));
274 top_row
+= row_offset
;
275 bottom_row
= top_row
+ height
- 1;
277 left_col
+= col_offset
;
278 right_col
= left_col
+ width
- 1;
280 if ((rn
!= r1
) && (rn
!= r2
) && (rn
!= r3
) && rand_percent(40)) {
284 rooms
[rn
].is_room
= R_ROOM
;
286 for (i
= top_row
; i
<= bottom_row
; i
++) {
287 for (j
= left_col
; j
<= right_col
; j
++) {
288 if ((i
== top_row
) || (i
== bottom_row
)) {
290 } else if ( ((i
!= top_row
) && (i
!= bottom_row
)) &&
291 ((j
== left_col
) || (j
== right_col
))) {
300 rooms
[rn
].top_row
= top_row
;
301 rooms
[rn
].bottom_row
= bottom_row
;
302 rooms
[rn
].left_col
= left_col
;
303 rooms
[rn
].right_col
= right_col
;
306 connect_rooms(room1
, room2
)
309 short row1
, col1
, row2
, col2
, dir
;
311 if ((!(rooms
[room1
].is_room
& (R_ROOM
| R_MAZE
))) ||
312 (!(rooms
[room2
].is_room
& (R_ROOM
| R_MAZE
)))) {
315 if (same_row(room1
, room2
) &&
316 (rooms
[room1
].left_col
> rooms
[room2
].right_col
)) {
317 put_door(&rooms
[room1
], LEFT
, &row1
, &col1
);
318 put_door(&rooms
[room2
], RIGHT
, &row2
, &col2
);
320 } else if (same_row(room1
, room2
) &&
321 (rooms
[room2
].left_col
> rooms
[room1
].right_col
)) {
322 put_door(&rooms
[room1
], RIGHT
, &row1
, &col1
);
323 put_door(&rooms
[room2
], LEFT
, &row2
, &col2
);
325 } else if (same_col(room1
, room2
) &&
326 (rooms
[room1
].top_row
> rooms
[room2
].bottom_row
)) {
327 put_door(&rooms
[room1
], UPWARD
, &row1
, &col1
);
328 put_door(&rooms
[room2
], DOWN
, &row2
, &col2
);
330 } else if (same_col(room1
, room2
) &&
331 (rooms
[room2
].top_row
> rooms
[room1
].bottom_row
)) {
332 put_door(&rooms
[room1
], DOWN
, &row1
, &col1
);
333 put_door(&rooms
[room2
], UPWARD
, &row2
, &col2
);
340 draw_simple_passage(row1
, col1
, row2
, col2
, dir
);
341 } while (rand_percent(4));
343 rooms
[room1
].doors
[dir
/2].oth_room
= room2
;
344 rooms
[room1
].doors
[dir
/2].oth_row
= row2
;
345 rooms
[room1
].doors
[dir
/2].oth_col
= col2
;
347 rooms
[room2
].doors
[(((dir
+4)%DIRS
)/2)].oth_room
= room1
;
348 rooms
[room2
].doors
[(((dir
+4)%DIRS
)/2)].oth_row
= row1
;
349 rooms
[room2
].doors
[(((dir
+4)%DIRS
)/2)].oth_col
= col1
;
357 for (i
= 0; i
< MAXROOMS
; i
++) {
358 rooms
[i
].is_room
= R_NOTHING
;
359 for (j
= 0; j
< 4; j
++) {
360 rooms
[i
].doors
[j
].oth_room
= NO_ROOM
;
364 for (i
= 0; i
< MAX_TRAPS
; i
++) {
365 traps
[i
].trap_type
= NO_TRAP
;
367 for (i
= 0; i
< DROWS
; i
++) {
368 for (j
= 0; j
< DCOLS
; j
++) {
369 dungeon
[i
][j
] = NOTHING
;
372 detect_monster
= see_invisible
= 0;
373 being_held
= bear_trap
= 0;
374 party_room
= NO_ROOM
;
375 rogue
.row
= rogue
.col
= -1;
379 put_door(rm
, dir
, row
, col
)
386 wall_width
= (rm
->is_room
& R_MAZE
) ? 0 : 1;
391 *row
= ((dir
== UPWARD
) ? rm
->top_row
: rm
->bottom_row
);
393 *col
= get_rand(rm
->left_col
+wall_width
,
394 rm
->right_col
-wall_width
);
395 } while (!(dungeon
[*row
][*col
] & (HORWALL
| TUNNEL
)));
399 *col
= (dir
== LEFT
) ? rm
->left_col
: rm
->right_col
;
401 *row
= get_rand(rm
->top_row
+wall_width
,
402 rm
->bottom_row
-wall_width
);
403 } while (!(dungeon
[*row
][*col
] & (VERTWALL
| TUNNEL
)));
406 if (rm
->is_room
& R_ROOM
) {
407 dungeon
[*row
][*col
] = DOOR
;
409 if ((cur_level
> 2) && rand_percent(HIDE_PERCENT
)) {
410 dungeon
[*row
][*col
] |= HIDDEN
;
412 rm
->doors
[dir
/2].door_row
= *row
;
413 rm
->doors
[dir
/2].door_col
= *col
;
416 draw_simple_passage(row1
, col1
, row2
, col2
, dir
)
417 short row1
, col1
, row2
, col2
, dir
;
421 if ((dir
== LEFT
) || (dir
== RIGHT
)) {
426 middle
= get_rand(col1
+1, col2
-1);
427 for (i
= col1
+1; i
!= middle
; i
++) {
428 dungeon
[row1
][i
] = TUNNEL
;
430 for (i
= row1
; i
!= row2
; i
+= (row1
> row2
) ? -1 : 1) {
431 dungeon
[i
][middle
] = TUNNEL
;
433 for (i
= middle
; i
!= col2
; i
++) {
434 dungeon
[row2
][i
] = TUNNEL
;
441 middle
= get_rand(row1
+1, row2
-1);
442 for (i
= row1
+1; i
!= middle
; i
++) {
443 dungeon
[i
][col1
] = TUNNEL
;
445 for (i
= col1
; i
!= col2
; i
+= (col1
> col2
) ? -1 : 1) {
446 dungeon
[middle
][i
] = TUNNEL
;
448 for (i
= middle
; i
!= row2
; i
++) {
449 dungeon
[i
][col2
] = TUNNEL
;
452 if (rand_percent(HIDE_PERCENT
)) {
453 hide_boxed_passage(row1
, col1
, row2
, col2
, 1);
457 same_row(room1
, room2
)
459 return((room1
/ 3) == (room2
/ 3));
462 same_col(room1
, room2
)
464 return((room1
% 3) == (room2
% 3));
474 start
= get_rand(0, (MAXROOMS
-1));
475 maze_percent
= (cur_level
* 5) / 4;
477 if (cur_level
> 15) {
478 maze_percent
+= cur_level
;
480 for (i
= 0; i
< MAXROOMS
; i
++) {
481 j
= ((start
+ i
) % MAXROOMS
);
482 if (rooms
[j
].is_room
& R_NOTHING
) {
483 if (rand_percent(maze_percent
)) {
484 rooms
[j
].is_room
= R_MAZE
;
485 make_maze(get_rand(rooms
[j
].top_row
+1, rooms
[j
].bottom_row
-1),
486 get_rand(rooms
[j
].left_col
+1, rooms
[j
].right_col
-1),
487 rooms
[j
].top_row
, rooms
[j
].bottom_row
,
488 rooms
[j
].left_col
, rooms
[j
].right_col
);
489 hide_boxed_passage(rooms
[j
].top_row
, rooms
[j
].left_col
,
490 rooms
[j
].bottom_row
, rooms
[j
].right_col
,
506 for (i
= 0; i
< MAXROOMS
; i
++) {
507 rn
= random_rooms
[i
];
508 if ((rooms
[rn
].is_room
& R_NOTHING
) ||
509 ((rooms
[rn
].is_room
& R_CROSS
) && coin_toss())) {
513 if (r_de
!= NO_ROOM
) {
518 fill_it(rn
, do_rec_de
)
522 short i
, tunnel_dir
, door_dir
, drow
, dcol
;
523 short target_room
, rooms_found
= 0;
525 static short offsets
[4] = {-1, 1, 3, -3};
526 boolean did_this
= 0;
528 for (i
= 0; i
< 10; i
++) {
529 srow
= get_rand(0, 3);
530 scol
= get_rand(0, 3);
532 offsets
[srow
] = offsets
[scol
];
535 for (i
= 0; i
< 4; i
++) {
537 target_room
= rn
+ offsets
[i
];
539 if (((target_room
< 0) || (target_room
>= MAXROOMS
)) ||
540 (!(same_row(rn
,target_room
) || same_col(rn
,target_room
))) ||
541 (!(rooms
[target_room
].is_room
& (R_ROOM
| R_MAZE
)))) {
544 if (same_row(rn
, target_room
)) {
545 tunnel_dir
= (rooms
[rn
].left_col
< rooms
[target_room
].left_col
) ?
548 tunnel_dir
= (rooms
[rn
].top_row
< rooms
[target_room
].top_row
) ?
551 door_dir
= ((tunnel_dir
+ 4) % DIRS
);
552 if (rooms
[target_room
].doors
[door_dir
/2].oth_room
!= NO_ROOM
) {
555 if (((!do_rec_de
) || did_this
) ||
556 (!mask_room(rn
, &srow
, &scol
, TUNNEL
))) {
557 srow
= (rooms
[rn
].top_row
+ rooms
[rn
].bottom_row
) / 2;
558 scol
= (rooms
[rn
].left_col
+ rooms
[rn
].right_col
) / 2;
560 put_door(&rooms
[target_room
], door_dir
, &drow
, &dcol
);
562 draw_simple_passage(srow
, scol
, drow
, dcol
, tunnel_dir
);
563 rooms
[rn
].is_room
= R_DEADEND
;
564 dungeon
[srow
][scol
] = TUNNEL
;
566 if ((i
< 3) && (!did_this
)) {
572 if ((rooms_found
< 2) && do_rec_de
) {
573 recursive_deadend(rn
, offsets
, srow
, scol
);
579 recursive_deadend(rn
, offsets
, srow
, scol
)
585 short drow
, dcol
, tunnel_dir
;
587 rooms
[rn
].is_room
= R_DEADEND
;
588 dungeon
[srow
][scol
] = TUNNEL
;
590 for (i
= 0; i
< 4; i
++) {
591 de
= rn
+ offsets
[i
];
592 if (((de
< 0) || (de
>= MAXROOMS
)) ||
593 (!(same_row(rn
, de
) || same_col(rn
, de
)))) {
596 if (!(rooms
[de
].is_room
& R_NOTHING
)) {
599 drow
= (rooms
[de
].top_row
+ rooms
[de
].bottom_row
) / 2;
600 dcol
= (rooms
[de
].left_col
+ rooms
[de
].right_col
) / 2;
601 if (same_row(rn
, de
)) {
602 tunnel_dir
= (rooms
[rn
].left_col
< rooms
[de
].left_col
) ?
605 tunnel_dir
= (rooms
[rn
].top_row
< rooms
[de
].top_row
) ?
608 draw_simple_passage(srow
, scol
, drow
, dcol
, tunnel_dir
);
610 recursive_deadend(de
, offsets
, drow
, dcol
);
615 mask_room(rn
, row
, col
, mask
)
622 for (i
= rooms
[rn
].top_row
; i
<= rooms
[rn
].bottom_row
; i
++) {
623 for (j
= rooms
[rn
].left_col
; j
<= rooms
[rn
].right_col
; j
++) {
624 if (dungeon
[i
][j
] & mask
) {
634 make_maze(r
, c
, tr
, br
, lc
, rc
)
635 short r
, c
, tr
, br
, lc
, rc
;
645 dungeon
[r
][c
] = TUNNEL
;
647 if (rand_percent(20)) {
648 for (i
= 0; i
< 10; i
++) {
654 swap(dirs
[t1
], dirs
[t2
]);
657 for (i
= 0; i
< 4; i
++) {
661 (dungeon
[r
-1][c
] != TUNNEL
) &&
662 (dungeon
[r
-1][c
-1] != TUNNEL
) &&
663 (dungeon
[r
-1][c
+1] != TUNNEL
) &&
664 (dungeon
[r
-2][c
] != TUNNEL
)) {
665 make_maze((r
-1), c
, tr
, br
, lc
, rc
);
670 (dungeon
[r
+1][c
] != TUNNEL
) &&
671 (dungeon
[r
+1][c
-1] != TUNNEL
) &&
672 (dungeon
[r
+1][c
+1] != TUNNEL
) &&
673 (dungeon
[r
+2][c
] != TUNNEL
)) {
674 make_maze((r
+1), c
, tr
, br
, lc
, rc
);
679 (dungeon
[r
][c
-1] != TUNNEL
) &&
680 (dungeon
[r
-1][c
-1] != TUNNEL
) &&
681 (dungeon
[r
+1][c
-1] != TUNNEL
) &&
682 (dungeon
[r
][c
-2] != TUNNEL
)) {
683 make_maze(r
, (c
-1), tr
, br
, lc
, rc
);
688 (dungeon
[r
][c
+1] != TUNNEL
) &&
689 (dungeon
[r
-1][c
+1] != TUNNEL
) &&
690 (dungeon
[r
+1][c
+1] != TUNNEL
) &&
691 (dungeon
[r
][c
+2] != TUNNEL
)) {
692 make_maze(r
, (c
+1), tr
, br
, lc
, rc
);
699 hide_boxed_passage(row1
, col1
, row2
, col2
, n
)
700 short row1
, col1
, row2
, col2
, n
;
703 short row
, col
, row_cut
, col_cut
;
716 if ((w
>= 5) || (h
>= 5)) {
717 row_cut
= ((h
>= 2) ? 1 : 0);
718 col_cut
= ((w
>= 2) ? 1 : 0);
720 for (i
= 0; i
< n
; i
++) {
721 for (j
= 0; j
< 10; j
++) {
722 row
= get_rand(row1
+ row_cut
, row2
- row_cut
);
723 col
= get_rand(col1
+ col_cut
, col2
- col_cut
);
724 if (dungeon
[row
][col
] == TUNNEL
) {
725 dungeon
[row
][col
] |= HIDDEN
;
735 short nr
; /* try not to put in this room */
737 short rn
= nr
, misses
;
740 for (misses
= 0; ((misses
< 2) && (rn
== nr
)); misses
++) {
741 gr_row_col(&row
, &col
, (FLOOR
| TUNNEL
| OBJECT
| STAIRS
));
742 rn
= get_room_number(row
, col
);
747 if (dungeon
[rogue
.row
][rogue
.col
] & TUNNEL
) {
752 if (cur_room
!= PASSAGE
) {
753 light_up_room(cur_room
);
755 light_passage(rogue
.row
, rogue
.col
);
757 rn
= get_room_number(rogue
.row
, rogue
.col
);
758 wake_room(rn
, 1, rogue
.row
, rogue
.col
);
759 if (new_level_message
) {
760 message(new_level_message
, 0);
761 new_level_message
= 0;
763 mvaddch(rogue
.row
, rogue
.col
, rogue
.fchar
);
771 if (dungeon
[rogue
.row
][rogue
.col
] & STAIRS
) {
773 message("you're floating in the air!", 0);
778 message("I see no way down", 0);
785 if (!(dungeon
[rogue
.row
][rogue
.col
] & STAIRS
)) {
786 message("I see no way up", 0);
790 message("your way is magically blocked", 0);
794 new_level_message
= "you feel a wrenching sensation in your gut";
795 if (cur_level
== 1) {
804 add_exp(e
, promotion
)
812 rogue
.exp_points
+= e
;
814 if (rogue
.exp_points
>= level_points
[rogue
.exp
-1]) {
815 new_exp
= get_exp_level(rogue
.exp_points
);
816 if (rogue
.exp_points
> MAX_EXP
) {
817 rogue
.exp_points
= MAX_EXP
+ 1;
819 for (i
= rogue
.exp
+1; i
<= new_exp
; i
++) {
820 sprintf(mbuf
, "welcome to level %d", i
);
824 rogue
.hp_current
+= hp
;
828 print_stats(STAT_HP
| STAT_EXP
);
831 print_stats(STAT_EXP
);
840 for (i
= 0; i
< (MAX_EXP_LEVEL
- 1); i
++) {
841 if (level_points
[i
] > e
) {
852 hp
= (wizard
? 10 : get_rand(3, 10));
860 float effective_average
;
862 if (rogue
.exp
== 1) {
863 real_average
= effective_average
= 0.00;
865 real_average
= (float)
866 ((rogue
.hp_max
- extra_hp
- INIT_HP
) + less_hp
) / (rogue
.exp
- 1);
867 effective_average
= (float) (rogue
.hp_max
- INIT_HP
) / (rogue
.exp
- 1);
870 sprintf(mbuf
, "R-Hp: %.2f, E-Hp: %.2f (!: %d, V: %d)", real_average
,
871 effective_average
, extra_hp
, less_hp
);
880 for (i
= 0; i
< (3 * MAXROOMS
); i
++) {
882 x
= get_rand(0, (MAXROOMS
-1));
883 y
= get_rand(0, (MAXROOMS
-1));
885 swap(random_rooms
[x
], random_rooms
[y
]);