2 * Copyright (c) 1988, 1993
3 * The Regents of the University of California. All rights reserved.
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
36 * @(#)room.c 8.1 (Berkeley) 5/31/93
37 * $FreeBSD: src/games/rogue/room.c,v 1.7 1999/11/30 03:49:26 billf Exp $
38 * $DragonFly: src/games/rogue/room.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
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
56 boolean rooms_visited[MAXROOMS];
59 extern boolean detect_monster, jump, passgo, no_skull, ask_quit, flush;
60 extern char *nick_name, *fruit, *save_file, *press_space;
71 "Flush typeahead during battle (\"flush\"): ",
72 1, (char **) 0, &flush
75 "Show position only at end of run (\"jump\"): ",
79 "Follow turnings in passageways (\"passgo\"): ",
80 1, (char **) 0, &passgo
83 "Don't print skull when killed (\"noskull\" or \"notombstone\"): ",
84 1, (char **) 0, &no_skull
87 "Ask player before saying 'Okay, bye-bye!' (\"askquit\"): ",
88 1, (char **) 0, &ask_quit
95 "Fruit (\"fruit\"): ",
99 "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(&level_monsters, i, j)) {
118 dungeon[monster->row][monster->col] &= (~MONSTER);
119 monster->trail_char =
120 get_dungeon_char(monster->row, monster->col);
121 dungeon[monster->row][monster->col] |= MONSTER;
124 mvaddch(i, j, get_dungeon_char(i, j));
127 mvaddch(rogue.row, rogue.col, rogue.fchar);
131 light_passage(row, col)
134 short i, j, i_end, j_end;
139 i_end = (row < (DROWS-2)) ? 1 : 0;
140 j_end = (col < (DCOLS-1)) ? 1 : 0;
142 for (i = ((row > MIN_ROW) ? -1 : 0); i <= i_end; i++) {
143 for (j = ((col > 0) ? -1 : 0); j <= j_end; j++) {
144 if (can_move(row, col, row+i, col+j)) {
145 mvaddch(row+i, col+j, get_dungeon_char(row+i, col+j));
156 for (i = rooms[rn].top_row + 1; i < rooms[rn].bottom_row; i++) {
157 for (j = rooms[rn].left_col + 1; j < rooms[rn].right_col; j++) {
161 if (!(dungeon[i][j] & (OBJECT | STAIRS)) &&
162 !(detect_monster && (dungeon[i][j] & MONSTER))) {
163 if (!imitating(i, j)) {
166 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))) {
246 return('~'); /* unknown, something is wrong */
250 gr_row_col(row, col, mask)
258 r = get_rand(MIN_ROW, DROWS-2);
259 c = get_rand(0, DCOLS-1);
260 rn = get_room_number(r, c);
261 } while ((rn == NO_ROOM) ||
262 (!(dungeon[r][c] & mask)) ||
263 (dungeon[r][c] & (~mask)) ||
264 (!(rooms[rn].is_room & (R_ROOM | R_MAZE))) ||
265 ((r == rogue.row) && (c == rogue.col)));
276 i = get_rand(0, MAXROOMS-1);
277 } while (!(rooms[i].is_room & (R_ROOM | R_MAZE)));
286 short n, N, row, col;
289 N = ((rooms[rn].bottom_row - rooms[rn].top_row) - 1) *
290 ((rooms[rn].right_col - rooms[rn].left_col) - 1);
295 for (i = 0; i < n; i++) {
296 for (j = found = 0; ((!found) && (j < 250)); j++) {
297 row = get_rand(rooms[rn].top_row+1,
298 rooms[rn].bottom_row-1);
299 col = get_rand(rooms[rn].left_col+1,
300 rooms[rn].right_col-1);
301 if ((dungeon[row][col] == FLOOR) || (dungeon[row][col] == TUNNEL)) {
307 place_at(obj, row, col);
314 get_room_number(row, col)
319 for (i = 0; i < MAXROOMS; i++) {
320 if ((row >= rooms[i].top_row) && (row <= rooms[i].bottom_row) &&
321 (col >= rooms[i].left_col) && (col <= rooms[i].right_col)) {
330 short i, starting_room;
332 for (i = 0; i < MAXROOMS; i++) {
333 rooms_visited[i] = 0;
334 if (rooms[i].is_room & (R_ROOM | R_MAZE)) {
339 visit_rooms(starting_room);
341 for (i = 0; i < MAXROOMS; i++) {
342 if ((rooms[i].is_room & (R_ROOM | R_MAZE)) && (!rooms_visited[i])) {
355 rooms_visited[rn] = 1;
357 for (i = 0; i < 4; i++) {
358 oth_rn = rooms[rn].doors[i].oth_room;
359 if ((oth_rn >= 0) && (!rooms_visited[oth_rn])) {
368 unsigned short mask = (HORWALL | VERTWALL | DOOR | TUNNEL | TRAP | STAIRS |
372 for (i = 0; i < DROWS; i++) {
373 for (j = 0; j < DCOLS; j++) {
376 if (((ch = mvinch(i, j)) == ' ') ||
377 ((ch >= 'A') && (ch <= 'Z')) || (s & (TRAP | HIDDEN))) {
379 dungeon[i][j] &= (~HIDDEN);
382 } else if (s & VERTWALL) {
384 } else if (s & DOOR) {
386 } else if (s & TRAP) {
388 } else if (s & STAIRS) {
390 } else if (s & TUNNEL) {
395 if ((!(s & MONSTER)) || (och == ' ')) {
401 if (monster = object_at(&level_monsters, i, j)) {
402 monster->trail_char = ch;
411 dr_course(monster, entering, row, col)
422 if (mon_sees(monster, rogue.row, rogue.col)) {
423 monster->trow = NO_ROOM;
426 rn = get_room_number(row, col);
428 if (entering) { /* entering room */
429 /* look for door to some other room */
430 r = get_rand(0, MAXROOMS-1);
431 for (i = 0; i < MAXROOMS; i++) {
432 rr = (r + i) % MAXROOMS;
433 if ((!(rooms[rr].is_room & (R_ROOM | R_MAZE))) || (rr == rn)) {
436 for (k = 0; k < 4; k++) {
437 if (rooms[rr].doors[k].oth_room == rn) {
438 monster->trow = rooms[rr].doors[k].oth_row;
439 monster->tcol = rooms[rr].doors[k].oth_col;
440 if ((monster->trow == row) &&
441 (monster->tcol == col)) {
448 /* look for door to dead end */
449 for (i = rooms[rn].top_row; i <= rooms[rn].bottom_row; i++) {
450 for (j = rooms[rn].left_col; j <= rooms[rn].right_col; j++) {
451 if ((i != monster->row) && (j != monster->col) &&
452 (dungeon[i][j] & DOOR)) {
459 /* return monster to room that he came from */
460 for (i = 0; i < MAXROOMS; i++) {
461 for (j = 0; j < 4; j++) {
462 if (rooms[i].doors[j].oth_room == rn) {
463 for (k = 0; k < 4; k++) {
464 if (rooms[rn].doors[k].oth_room == i) {
465 monster->trow = rooms[rn].doors[k].oth_row;
466 monster->tcol = rooms[rn].doors[k].oth_col;
473 /* no place to send monster */
474 monster->trow = NO_ROOM;
475 } else { /* exiting room */
476 if (!get_oth_room(rn, &row, &col)) {
477 monster->trow = NO_ROOM;
485 get_oth_room(rn, row, col)
486 short rn, *row, *col;
490 if (*row == rooms[rn].top_row) {
492 } else if (*row == rooms[rn].bottom_row) {
494 } else if (*col == rooms[rn].left_col) {
496 } else if (*col == rooms[rn].right_col) {
499 if ((d != -1) && (rooms[rn].doors[d].oth_room >= 0)) {
500 *row = rooms[rn].doors[d].oth_row;
501 *col = rooms[rn].doors[d].oth_col;
509 char save[NOPTS+1][DCOLS];
513 char buf[MAX_OPT_LEN + 2];
515 for (i = 0; i < NOPTS+1; i++) {
516 for (j = 0; j < DCOLS; j++) {
517 save[i][j] = mvinch(i, j);
536 if (i == (NOPTS - 1)) {
537 mvaddstr(NOPTS, 0, press_space);
557 if (options[i].is_bool) {
558 *(options[i].bval) = (((ch == 't') || (ch == 'T')) ? 1 : 0);
564 if (options[i].is_bool) {
569 if ((ch == '\010') || ((ch >= ' ') && (ch <= '~'))) {
572 if ((ch >= ' ') && (ch <= '~') && (j < MAX_OPT_LEN)) {
576 } else if ((ch == '\010') && (j > 0)) {
578 move(i, j + strlen(options[i].prompt));
580 move(i, j + strlen(options[i].prompt));
584 } while ((ch != '\012') && (ch != '\015') && (ch != '\033'));
586 (void) strcpy(*(options[i].strval), buf);
597 for (i = 0; i < NOPTS+1; i++) {
599 for (j = 0; j < DCOLS; j++) {
609 struct option *opt = &options[i];
614 s = *(opt->bval) ? "True" : "False";
624 struct option *opt = &options[i];
626 mvaddstr(i, 0, opt->prompt);
633 move(i, strlen(options[i].prompt));
642 if (!(sh = md_getenv("SHELL"))) {
648 printf("\nCreating new shell...\n");