]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - rogue/room.c
1 /* $NetBSD: room.c,v 1.10 2007/12/27 23:53:01 dholland 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. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/cdefs.h>
38 static char sccsid
[] = "@(#)room.c 8.1 (Berkeley) 5/31/93";
40 __RCSID("$NetBSD: room.c,v 1.10 2007/12/27 23:53:01 dholland Exp $");
47 * This source herein may be modified and/or distributed by anybody who
48 * so desires, with the following restrictions:
49 * 1.) No portion of this notice shall be removed.
50 * 2.) Credit shall not be taken for the creation of this source.
51 * 3.) This code is not to be traded, sold, or used for personal
59 boolean rooms_visited
[MAXROOMS
];
70 "Show position only at end of run (\"jump\"): ",
74 "Follow turnings in passageways (\"passgo\"): ",
75 1, (char **) 0, &passgo
78 "Don't print skull when killed (\"noskull\" or \"notombstone\"): ",
79 1, (char **) 0, &no_skull
82 "Ask player before saying 'Okay, bye-bye!' (\"askquit\"): ",
83 1, (char **) 0, &ask_quit
87 0, &nick_name
, (boolean
*) 0
90 "Fruit (\"fruit\"): ",
91 0, &fruit
, (boolean
*) 0
94 "Save file (\"file\"): ",
95 0, &save_file
, (boolean
*) 0
106 for (i
= rooms
[rn
].top_row
;
107 i
<= rooms
[rn
].bottom_row
; i
++) {
108 for (j
= rooms
[rn
].left_col
;
109 j
<= rooms
[rn
].right_col
; j
++) {
110 if (dungeon
[i
][j
] & MONSTER
) {
113 if ((monster
= object_at(
114 &level_monsters
, i
, j
)) != NULL
) {
115 dungeon
[monster
->row
][monster
->col
] &= (~MONSTER
);
116 monster
->trail_char
=
117 get_dungeon_char(monster
->row
, monster
->col
);
118 dungeon
[monster
->row
][monster
->col
] |= MONSTER
;
121 mvaddch(i
, j
, get_dungeon_char(i
, j
));
124 mvaddch(rogue
.row
, rogue
.col
, rogue
.fchar
);
129 light_passage(row
, col
)
132 short i
, j
, i_end
, j_end
;
137 i_end
= (row
< (DROWS
-2)) ? 1 : 0;
138 j_end
= (col
< (DCOLS
-1)) ? 1 : 0;
140 for (i
= ((row
> MIN_ROW
) ? -1 : 0); i
<= i_end
; i
++) {
141 for (j
= ((col
> 0) ? -1 : 0); j
<= j_end
; j
++) {
142 if (can_move(row
, col
, row
+i
, col
+j
)) {
143 mvaddch(row
+i
, col
+j
, get_dungeon_char(row
+i
, col
+j
));
155 for (i
= rooms
[rn
].top_row
+ 1; i
< rooms
[rn
].bottom_row
; i
++) {
156 for (j
= rooms
[rn
].left_col
+ 1; j
< rooms
[rn
].right_col
; j
++) {
160 if (!(dungeon
[i
][j
] & (OBJECT
| STAIRS
)) &&
161 !(detect_monster
&& (dungeon
[i
][j
] & MONSTER
))) {
162 if (!imitating(i
, j
)) {
165 if ((dungeon
[i
][j
] & TRAP
) && (!(dungeon
[i
][j
] & HIDDEN
))) {
175 get_dungeon_char(row
, col
)
178 unsigned short mask
= dungeon
[row
][col
];
180 if (mask
& MONSTER
) {
181 return(gmc_row_col(row
, col
));
186 obj
= object_at(&level_objects
, row
, col
);
187 return(get_mask_char(obj
->what_is
));
189 if (mask
& (TUNNEL
| STAIRS
| HORWALL
| VERTWALL
| FLOOR
| DOOR
)) {
190 if ((mask
& (TUNNEL
| STAIRS
)) && (!(mask
& HIDDEN
))) {
191 return(((mask
& STAIRS
) ? '%' : '#'));
193 if (mask
& HORWALL
) {
196 if (mask
& VERTWALL
) {
201 if (!(dungeon
[row
][col
] & HIDDEN
)) {
209 if (((col
> 0) && (dungeon
[row
][col
-1] & HORWALL
)) ||
210 ((col
< (DCOLS
-1)) && (dungeon
[row
][col
+1] & HORWALL
))) {
247 return('~'); /* unknown, something is wrong */
252 gr_row_col(row
, col
, mask
)
260 r
= get_rand(MIN_ROW
, DROWS
-2);
261 c
= get_rand(0, DCOLS
-1);
262 rn
= get_room_number(r
, c
);
263 } while ((rn
== NO_ROOM
) ||
264 (!(dungeon
[r
][c
] & mask
)) ||
265 (dungeon
[r
][c
] & (~mask
)) ||
266 (!(rooms
[rn
].is_room
& (R_ROOM
| R_MAZE
))) ||
267 ((r
== rogue
.row
) && (c
== rogue
.col
)));
279 i
= get_rand(0, MAXROOMS
-1);
280 } while (!(rooms
[i
].is_room
& (R_ROOM
| R_MAZE
)));
291 short n
, N
, row
, col
;
295 N
= ((rooms
[rn
].bottom_row
- rooms
[rn
].top_row
) - 1) *
296 ((rooms
[rn
].right_col
- rooms
[rn
].left_col
) - 1);
301 for (i
= 0; i
< n
; i
++) {
302 for (j
= found
= 0; ((!found
) && (j
< 250)); j
++) {
303 row
= get_rand(rooms
[rn
].top_row
+1,
304 rooms
[rn
].bottom_row
-1);
305 col
= get_rand(rooms
[rn
].left_col
+1,
306 rooms
[rn
].right_col
-1);
307 if ((dungeon
[row
][col
] == FLOOR
) || (dungeon
[row
][col
] == TUNNEL
)) {
313 place_at(obj
, row
, col
);
321 get_room_number(row
, col
)
326 for (i
= 0; i
< MAXROOMS
; i
++) {
327 if ((row
>= rooms
[i
].top_row
) && (row
<= rooms
[i
].bottom_row
) &&
328 (col
>= rooms
[i
].left_col
) && (col
<= rooms
[i
].right_col
)) {
338 short i
, starting_room
;
341 for (i
= 0; i
< MAXROOMS
; i
++) {
342 rooms_visited
[i
] = 0;
343 if (rooms
[i
].is_room
& (R_ROOM
| R_MAZE
)) {
348 visit_rooms(starting_room
);
350 for (i
= 0; i
< MAXROOMS
; i
++) {
351 if ((rooms
[i
].is_room
& (R_ROOM
| R_MAZE
)) && (!rooms_visited
[i
])) {
365 rooms_visited
[rn
] = 1;
367 for (i
= 0; i
< 4; i
++) {
368 oth_rn
= rooms
[rn
].doors
[i
].oth_room
;
369 if ((oth_rn
>= 0) && (!rooms_visited
[oth_rn
])) {
379 unsigned short mask
= (HORWALL
| VERTWALL
| DOOR
| TUNNEL
| TRAP
| STAIRS
|
383 for (i
= 0; i
< DROWS
; i
++) {
384 for (j
= 0; j
< DCOLS
; j
++) {
387 if (((ch
= mvinch(i
, j
)) == ' ') ||
388 ((ch
>= 'A') && (ch
<= 'Z')) || (s
& (TRAP
| HIDDEN
))) {
390 dungeon
[i
][j
] &= (~HIDDEN
);
393 } else if (s
& VERTWALL
) {
395 } else if (s
& DOOR
) {
397 } else if (s
& TRAP
) {
399 } else if (s
& STAIRS
) {
401 } else if (s
& TUNNEL
) {
406 if ((!(s
& MONSTER
)) || (och
== ' ')) {
412 if ((monster
= object_at(
413 &level_monsters
, i
, j
))
415 monster
->trail_char
=
426 dr_course(monster
, entering
, row
, col
)
437 if (mon_sees(monster
, rogue
.row
, rogue
.col
)) {
438 monster
->trow
= NO_ROOM
;
441 rn
= get_room_number(row
, col
);
443 if (entering
) { /* entering room */
444 /* look for door to some other room */
445 r
= get_rand(0, MAXROOMS
-1);
446 for (i
= 0; i
< MAXROOMS
; i
++) {
447 rr
= (r
+ i
) % MAXROOMS
;
448 if ((!(rooms
[rr
].is_room
& (R_ROOM
| R_MAZE
))) || (rr
== rn
)) {
451 for (k
= 0; k
< 4; k
++) {
452 if (rooms
[rr
].doors
[k
].oth_room
== rn
) {
453 monster
->trow
= rooms
[rr
].doors
[k
].oth_row
;
454 monster
->tcol
= rooms
[rr
].doors
[k
].oth_col
;
455 if ((monster
->trow
== row
) &&
456 (monster
->tcol
== col
)) {
463 /* look for door to dead end */
465 clean_up("dr_course: monster not in room");
466 for (i
= rooms
[rn
].top_row
; i
<= rooms
[rn
].bottom_row
; i
++) {
467 for (j
= rooms
[rn
].left_col
; j
<= rooms
[rn
].right_col
; j
++) {
468 if ((i
!= monster
->row
) && (j
!= monster
->col
) &&
469 (dungeon
[i
][j
] & DOOR
)) {
476 /* return monster to room that he came from */
477 for (i
= 0; i
< MAXROOMS
; i
++) {
478 for (j
= 0; j
< 4; j
++) {
479 if (rooms
[i
].doors
[j
].oth_room
== rn
) {
480 for (k
= 0; k
< 4; k
++) {
481 if (rooms
[rn
].doors
[k
].oth_room
== i
) {
482 monster
->trow
= rooms
[rn
].doors
[k
].oth_row
;
483 monster
->tcol
= rooms
[rn
].doors
[k
].oth_col
;
490 /* no place to send monster */
491 monster
->trow
= NO_ROOM
;
492 } else { /* exiting room */
493 if (rn
== NO_ROOM
|| !get_oth_room(rn
, &row
, &col
)) {
494 monster
->trow
= NO_ROOM
;
503 get_oth_room(rn
, row
, col
)
504 short rn
, *row
, *col
;
508 if (*row
== rooms
[rn
].top_row
) {
510 } else if (*row
== rooms
[rn
].bottom_row
) {
512 } else if (*col
== rooms
[rn
].left_col
) {
514 } else if (*col
== rooms
[rn
].right_col
) {
517 if ((d
!= -1) && (rooms
[rn
].doors
[d
].oth_room
>= 0)) {
518 *row
= rooms
[rn
].doors
[d
].oth_row
;
519 *col
= rooms
[rn
].doors
[d
].oth_col
;
528 char save
[NOPTS
+1][DCOLS
];
532 char buf
[MAX_OPT_LEN
+ 2];
534 for (i
= 0; i
< NOPTS
+1; i
++) {
535 for (j
= 0; j
< DCOLS
; j
++) {
536 save
[i
][j
] = mvinch(i
, j
);
555 if (i
== (NOPTS
- 1)) {
556 mvaddstr(NOPTS
, 0, press_space
);
576 if (options
[i
].is_bool
) {
577 *(options
[i
].bval
) = (((ch
== 't') || (ch
== 'T')) ? 1 : 0);
583 if (options
[i
].is_bool
) {
588 if ((ch
== '\010') || ((ch
>= ' ') && (ch
<= '~'))) {
591 if ((ch
>= ' ') && (ch
<= '~') && (j
< MAX_OPT_LEN
)) {
595 } else if ((ch
== '\010') && (j
> 0)) {
597 move(i
, j
+ strlen(options
[i
].prompt
));
599 move(i
, j
+ strlen(options
[i
].prompt
));
603 } while ((ch
!= '\012') && (ch
!= '\015') && (ch
!= '\033'));
606 * We rely on the option string being
607 * allocated to hold MAX_OPT_LEN+2
608 * bytes. This is arranged in init.c.
610 (void) strcpy(*(options
[i
].strval
), buf
);
621 for (i
= 0; i
< NOPTS
+1; i
++) {
623 for (j
= 0; j
< DCOLS
; j
++) {
634 const struct option
*opt
= &options
[i
];
639 s
= *(opt
->bval
) ? "True" : "False";
650 const struct option
*opt
= &options
[i
];
652 mvaddstr(i
, 0, opt
->prompt
);
660 move(i
, strlen(options
[i
].prompt
));
670 if (!(sh
= md_getenv("SHELL"))) {
676 printf("\nCreating new shell...\n");