]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - rogue/room.c
1 /* $NetBSD: room.c,v 1.5 1998/09/11 14:11:57 hubertf 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
39 #include <sys/cdefs.h>
42 static char sccsid
[] = "@(#)room.c 8.1 (Berkeley) 5/31/93";
44 __RCSID("$NetBSD: room.c,v 1.5 1998/09/11 14:11:57 hubertf Exp $");
51 * This source herein may be modified and/or distributed by anybody who
52 * so desires, with the following restrictions:
53 * 1.) No portion of this notice shall be removed.
54 * 2.) Credit shall not be taken for the creation of this source.
55 * 3.) This code is not to be traded, sold, or used for personal
63 boolean rooms_visited
[MAXROOMS
];
74 "Show position only at end of run (\"jump\"): ",
78 "Follow turnings in passageways (\"passgo\"): ",
79 1, (char **) 0, &passgo
82 "Don't print skull when killed (\"noskull\" or \"notombstone\"): ",
83 1, (char **) 0, &no_skull
86 "Ask player before saying 'Okay, bye-bye!' (\"askquit\"): ",
87 1, (char **) 0, &ask_quit
94 "Fruit (\"fruit\"): ",
98 "Save file (\"file\"): ",
110 for (i
= rooms
[rn
].top_row
;
111 i
<= rooms
[rn
].bottom_row
; i
++) {
112 for (j
= rooms
[rn
].left_col
;
113 j
<= rooms
[rn
].right_col
; j
++) {
114 if (dungeon
[i
][j
] & MONSTER
) {
117 if ((monster
= object_at(
118 &level_monsters
, i
, j
)) != NULL
) {
119 dungeon
[monster
->row
][monster
->col
] &= (~MONSTER
);
120 monster
->trail_char
=
121 get_dungeon_char(monster
->row
, monster
->col
);
122 dungeon
[monster
->row
][monster
->col
] |= MONSTER
;
125 mvaddch(i
, j
, get_dungeon_char(i
, j
));
128 mvaddch(rogue
.row
, rogue
.col
, rogue
.fchar
);
133 light_passage(row
, col
)
136 short i
, j
, i_end
, j_end
;
141 i_end
= (row
< (DROWS
-2)) ? 1 : 0;
142 j_end
= (col
< (DCOLS
-1)) ? 1 : 0;
144 for (i
= ((row
> MIN_ROW
) ? -1 : 0); i
<= i_end
; i
++) {
145 for (j
= ((col
> 0) ? -1 : 0); j
<= j_end
; j
++) {
146 if (can_move(row
, col
, row
+i
, col
+j
)) {
147 mvaddch(row
+i
, col
+j
, get_dungeon_char(row
+i
, col
+j
));
159 for (i
= rooms
[rn
].top_row
+ 1; i
< rooms
[rn
].bottom_row
; i
++) {
160 for (j
= rooms
[rn
].left_col
+ 1; j
< rooms
[rn
].right_col
; j
++) {
164 if (!(dungeon
[i
][j
] & (OBJECT
| STAIRS
)) &&
165 !(detect_monster
&& (dungeon
[i
][j
] & MONSTER
))) {
166 if (!imitating(i
, j
)) {
169 if ((dungeon
[i
][j
] & TRAP
) && (!(dungeon
[i
][j
] & HIDDEN
))) {
179 get_dungeon_char(row
, col
)
182 unsigned short mask
= dungeon
[row
][col
];
184 if (mask
& MONSTER
) {
185 return(gmc_row_col(row
, col
));
190 obj
= object_at(&level_objects
, row
, col
);
191 return(get_mask_char(obj
->what_is
));
193 if (mask
& (TUNNEL
| STAIRS
| HORWALL
| VERTWALL
| FLOOR
| DOOR
)) {
194 if ((mask
& (TUNNEL
| STAIRS
)) && (!(mask
& HIDDEN
))) {
195 return(((mask
& STAIRS
) ? '%' : '#'));
197 if (mask
& HORWALL
) {
200 if (mask
& VERTWALL
) {
205 if (!(dungeon
[row
][col
] & HIDDEN
)) {
213 if (((col
> 0) && (dungeon
[row
][col
-1] & HORWALL
)) ||
214 ((col
< (DCOLS
-1)) && (dungeon
[row
][col
+1] & HORWALL
))) {
251 return('~'); /* unknown, something is wrong */
256 gr_row_col(row
, col
, mask
)
264 r
= get_rand(MIN_ROW
, DROWS
-2);
265 c
= get_rand(0, DCOLS
-1);
266 rn
= get_room_number(r
, c
);
267 } while ((rn
== NO_ROOM
) ||
268 (!(dungeon
[r
][c
] & mask
)) ||
269 (dungeon
[r
][c
] & (~mask
)) ||
270 (!(rooms
[rn
].is_room
& (R_ROOM
| R_MAZE
))) ||
271 ((r
== rogue
.row
) && (c
== rogue
.col
)));
283 i
= get_rand(0, MAXROOMS
-1);
284 } while (!(rooms
[i
].is_room
& (R_ROOM
| R_MAZE
)));
295 short n
, N
, row
, col
;
299 N
= ((rooms
[rn
].bottom_row
- rooms
[rn
].top_row
) - 1) *
300 ((rooms
[rn
].right_col
- rooms
[rn
].left_col
) - 1);
305 for (i
= 0; i
< n
; i
++) {
306 for (j
= found
= 0; ((!found
) && (j
< 250)); j
++) {
307 row
= get_rand(rooms
[rn
].top_row
+1,
308 rooms
[rn
].bottom_row
-1);
309 col
= get_rand(rooms
[rn
].left_col
+1,
310 rooms
[rn
].right_col
-1);
311 if ((dungeon
[row
][col
] == FLOOR
) || (dungeon
[row
][col
] == TUNNEL
)) {
317 place_at(obj
, row
, col
);
325 get_room_number(row
, col
)
330 for (i
= 0; i
< MAXROOMS
; i
++) {
331 if ((row
>= rooms
[i
].top_row
) && (row
<= rooms
[i
].bottom_row
) &&
332 (col
>= rooms
[i
].left_col
) && (col
<= rooms
[i
].right_col
)) {
342 short i
, starting_room
;
345 for (i
= 0; i
< MAXROOMS
; i
++) {
346 rooms_visited
[i
] = 0;
347 if (rooms
[i
].is_room
& (R_ROOM
| R_MAZE
)) {
352 visit_rooms(starting_room
);
354 for (i
= 0; i
< MAXROOMS
; i
++) {
355 if ((rooms
[i
].is_room
& (R_ROOM
| R_MAZE
)) && (!rooms_visited
[i
])) {
369 rooms_visited
[rn
] = 1;
371 for (i
= 0; i
< 4; i
++) {
372 oth_rn
= rooms
[rn
].doors
[i
].oth_room
;
373 if ((oth_rn
>= 0) && (!rooms_visited
[oth_rn
])) {
383 unsigned short mask
= (HORWALL
| VERTWALL
| DOOR
| TUNNEL
| TRAP
| STAIRS
|
387 for (i
= 0; i
< DROWS
; i
++) {
388 for (j
= 0; j
< DCOLS
; j
++) {
391 if (((ch
= mvinch(i
, j
)) == ' ') ||
392 ((ch
>= 'A') && (ch
<= 'Z')) || (s
& (TRAP
| HIDDEN
))) {
394 dungeon
[i
][j
] &= (~HIDDEN
);
397 } else if (s
& VERTWALL
) {
399 } else if (s
& DOOR
) {
401 } else if (s
& TRAP
) {
403 } else if (s
& STAIRS
) {
405 } else if (s
& TUNNEL
) {
410 if ((!(s
& MONSTER
)) || (och
== ' ')) {
416 if ((monster
= object_at(
417 &level_monsters
, i
, j
))
419 monster
->trail_char
=
430 dr_course(monster
, entering
, row
, col
)
441 if (mon_sees(monster
, rogue
.row
, rogue
.col
)) {
442 monster
->trow
= NO_ROOM
;
445 rn
= get_room_number(row
, col
);
447 if (entering
) { /* entering room */
448 /* look for door to some other room */
449 r
= get_rand(0, MAXROOMS
-1);
450 for (i
= 0; i
< MAXROOMS
; i
++) {
451 rr
= (r
+ i
) % MAXROOMS
;
452 if ((!(rooms
[rr
].is_room
& (R_ROOM
| R_MAZE
))) || (rr
== rn
)) {
455 for (k
= 0; k
< 4; k
++) {
456 if (rooms
[rr
].doors
[k
].oth_room
== rn
) {
457 monster
->trow
= rooms
[rr
].doors
[k
].oth_row
;
458 monster
->tcol
= rooms
[rr
].doors
[k
].oth_col
;
459 if ((monster
->trow
== row
) &&
460 (monster
->tcol
== col
)) {
467 /* look for door to dead end */
468 for (i
= rooms
[rn
].top_row
; i
<= rooms
[rn
].bottom_row
; i
++) {
469 for (j
= rooms
[rn
].left_col
; j
<= rooms
[rn
].right_col
; j
++) {
470 if ((i
!= monster
->row
) && (j
!= monster
->col
) &&
471 (dungeon
[i
][j
] & DOOR
)) {
478 /* return monster to room that he came from */
479 for (i
= 0; i
< MAXROOMS
; i
++) {
480 for (j
= 0; j
< 4; j
++) {
481 if (rooms
[i
].doors
[j
].oth_room
== rn
) {
482 for (k
= 0; k
< 4; k
++) {
483 if (rooms
[rn
].doors
[k
].oth_room
== i
) {
484 monster
->trow
= rooms
[rn
].doors
[k
].oth_row
;
485 monster
->tcol
= rooms
[rn
].doors
[k
].oth_col
;
492 /* no place to send monster */
493 monster
->trow
= NO_ROOM
;
494 } else { /* exiting room */
495 if (!get_oth_room(rn
, &row
, &col
)) {
496 monster
->trow
= NO_ROOM
;
505 get_oth_room(rn
, row
, col
)
506 short rn
, *row
, *col
;
510 if (*row
== rooms
[rn
].top_row
) {
512 } else if (*row
== rooms
[rn
].bottom_row
) {
514 } else if (*col
== rooms
[rn
].left_col
) {
516 } else if (*col
== rooms
[rn
].right_col
) {
519 if ((d
!= -1) && (rooms
[rn
].doors
[d
].oth_room
>= 0)) {
520 *row
= rooms
[rn
].doors
[d
].oth_row
;
521 *col
= rooms
[rn
].doors
[d
].oth_col
;
530 char save
[NOPTS
+1][DCOLS
];
534 char buf
[MAX_OPT_LEN
+ 2];
536 for (i
= 0; i
< NOPTS
+1; i
++) {
537 for (j
= 0; j
< DCOLS
; j
++) {
538 save
[i
][j
] = mvinch(i
, j
);
557 if (i
== (NOPTS
- 1)) {
558 mvaddstr(NOPTS
, 0, press_space
);
578 if (options
[i
].is_bool
) {
579 *(options
[i
].bval
) = (((ch
== 't') || (ch
== 'T')) ? 1 : 0);
585 if (options
[i
].is_bool
) {
590 if ((ch
== '\010') || ((ch
>= ' ') && (ch
<= '~'))) {
593 if ((ch
>= ' ') && (ch
<= '~') && (j
< MAX_OPT_LEN
)) {
597 } else if ((ch
== '\010') && (j
> 0)) {
599 move(i
, j
+ strlen(options
[i
].prompt
));
601 move(i
, j
+ strlen(options
[i
].prompt
));
605 } while ((ch
!= '\012') && (ch
!= '\015') && (ch
!= '\033'));
607 (void) strcpy(*(options
[i
].strval
), buf
);
618 for (i
= 0; i
< NOPTS
+1; i
++) {
620 for (j
= 0; j
< DCOLS
; j
++) {
631 struct option
*opt
= &options
[i
];
636 s
= *(opt
->bval
) ? "True" : "False";
647 struct option
*opt
= &options
[i
];
649 mvaddstr(i
, 0, opt
->prompt
);
657 move(i
, strlen(options
[i
].prompt
));
667 if (!(sh
= md_getenv("SHELL"))) {
673 printf("\nCreating new shell...\n");