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. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * @(#)room.c 8.1 (Berkeley) 5/31/93
33 * $FreeBSD: src/games/rogue/room.c,v 1.7 1999/11/30 03:49:26 billf Exp $
34 * $DragonFly: src/games/rogue/room.c,v 1.3 2006/09/02 19:31:07 pavalos Exp $
40 * This source herein may be modified and/or distributed by anybody who
41 * so desires, with the following restrictions:
42 * 1.) No portion of this notice shall be removed.
43 * 2.) Credit shall not be taken for the creation of this source.
44 * 3.) This code is not to be traded, sold, or used for personal
52 boolean rooms_visited[MAXROOMS];
55 extern boolean detect_monster, jump, passgo, no_skull, ask_quit, flush;
56 extern char *nick_name, *fruit, *save_file, *press_space;
67 "Flush typeahead during battle (\"flush\"): ",
71 "Show position only at end of run (\"jump\"): ",
75 "Follow turnings in passageways (\"passgo\"): ",
79 "Don't print skull when killed (\"noskull\" or \"notombstone\"): ",
83 "Ask player before saying 'Okay, bye-bye!' (\"askquit\"): ",
91 "Fruit (\"fruit\"): ",
95 "Save file (\"file\"): ",
100 static boolean get_oth_room(short, short *, short *);
101 static void opt_erase(int);
102 static void opt_go(int);
103 static void opt_show(int);
104 static void visit_rooms(int);
107 light_up_room(int rn)
112 for (i = rooms[rn].top_row;
113 i <= rooms[rn].bottom_row; i++) {
114 for (j = rooms[rn].left_col;
115 j <= rooms[rn].right_col; j++) {
116 if (dungeon[i][j] & MONSTER) {
119 if ((monster = object_at(&level_monsters, i, j))) {
120 dungeon[monster->row][monster->col] &= (~MONSTER);
121 monster->trail_char =
122 get_dungeon_char(monster->row, monster->col);
123 dungeon[monster->row][monster->col] |= MONSTER;
126 mvaddch(i, j, get_dungeon_char(i, j));
129 mvaddch(rogue.row, rogue.col, rogue.fchar);
134 light_passage(int row, int 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));
154 darken_room(short rn)
158 for (i = rooms[rn].top_row + 1; i < rooms[rn].bottom_row; i++) {
159 for (j = rooms[rn].left_col + 1; j < rooms[rn].right_col; j++) {
163 if (!(dungeon[i][j] & (OBJECT | STAIRS)) &&
164 !(detect_monster && (dungeon[i][j] & MONSTER))) {
165 if (!imitating(i, j)) {
168 if ((dungeon[i][j] & TRAP) && (!(dungeon[i][j] & HIDDEN))) {
178 get_dungeon_char(int row, int col)
180 unsigned short mask = dungeon[row][col];
182 if (mask & MONSTER) {
183 return(gmc_row_col(row, col));
188 obj = object_at(&level_objects, row, col);
189 return(get_mask_char(obj->what_is));
191 if (mask & (TUNNEL | STAIRS | HORWALL | VERTWALL | FLOOR | DOOR)) {
192 if ((mask & (TUNNEL| STAIRS)) && (!(mask & HIDDEN))) {
193 return(((mask & STAIRS) ? '%' : '#'));
195 if (mask & HORWALL) {
198 if (mask & VERTWALL) {
203 if (!(dungeon[row][col] & HIDDEN)) {
211 if (((col > 0) && (dungeon[row][col-1] & HORWALL)) ||
212 ((col < (DCOLS-1)) && (dungeon[row][col+1] & HORWALL))) {
226 get_mask_char(unsigned short mask)
248 return('~'); /* unknown, something is wrong */
253 gr_row_col(short *row, short *col, unsigned short mask)
259 r = get_rand(MIN_ROW, DROWS-2);
260 c = get_rand(0, DCOLS-1);
261 rn = get_room_number(r, c);
262 } while ((rn == NO_ROOM) ||
263 (!(dungeon[r][c] & mask)) ||
264 (dungeon[r][c] & (~mask)) ||
265 (!(rooms[rn].is_room & (R_ROOM | R_MAZE))) ||
266 ((r == rogue.row) && (c == rogue.col)));
278 i = get_rand(0, MAXROOMS-1);
279 } while (!(rooms[i].is_room & (R_ROOM | R_MAZE)));
285 party_objects(short rn)
289 short n, N, row, col;
292 N = ((rooms[rn].bottom_row - rooms[rn].top_row) - 1) *
293 ((rooms[rn].right_col - rooms[rn].left_col) - 1);
298 for (i = 0; i < n; i++) {
299 for (j = found = 0; ((!found) && (j < 250)); j++) {
300 row = get_rand(rooms[rn].top_row+1,
301 rooms[rn].bottom_row-1);
302 col = get_rand(rooms[rn].left_col+1,
303 rooms[rn].right_col-1);
304 if ((dungeon[row][col] == FLOOR) || (dungeon[row][col] == TUNNEL)) {
310 place_at(obj, row, col);
318 get_room_number(int row, int col)
322 for (i = 0; i < MAXROOMS; i++) {
323 if ((row >= rooms[i].top_row) && (row <= rooms[i].bottom_row) &&
324 (col >= rooms[i].left_col) && (col <= rooms[i].right_col)) {
332 is_all_connected(void)
334 short i, starting_room;
337 for (i = 0; i < MAXROOMS; i++) {
338 rooms_visited[i] = 0;
339 if (rooms[i].is_room & (R_ROOM | R_MAZE)) {
344 visit_rooms(starting_room);
346 for (i = 0; i < MAXROOMS; i++) {
347 if ((rooms[i].is_room & (R_ROOM | R_MAZE)) && (!rooms_visited[i])) {
360 rooms_visited[rn] = 1;
362 for (i = 0; i < 4; i++) {
363 oth_rn = rooms[rn].doors[i].oth_room;
364 if ((oth_rn >= 0) && (!rooms_visited[oth_rn])) {
374 unsigned short mask = (HORWALL | VERTWALL | DOOR | TUNNEL | TRAP | STAIRS |
378 for (i = 0; i < DROWS; i++) {
379 for (j = 0; j < DCOLS; j++) {
382 if (((ch = mvinch(i, j)) == ' ') ||
383 ((ch >= 'A') && (ch <= 'Z')) || (s & (TRAP | HIDDEN))) {
385 dungeon[i][j] &= (~HIDDEN);
388 } else if (s & VERTWALL) {
390 } else if (s & DOOR) {
392 } else if (s & TRAP) {
394 } else if (s & STAIRS) {
396 } else if (s & TUNNEL) {
401 if ((!(s & MONSTER)) || (och == ' ')) {
407 if ((monster = object_at(&level_monsters, i, j))) {
408 monster->trail_char = ch;
418 dr_course(object *monster, boolean entering, short row, short col)
426 if (mon_sees(monster, rogue.row, rogue.col)) {
427 monster->trow = NO_ROOM;
430 rn = get_room_number(row, col);
432 if (entering) { /* entering room */
433 /* look for door to some other room */
434 r = get_rand(0, MAXROOMS-1);
435 for (i = 0; i < MAXROOMS; i++) {
436 rr = (r + i) % MAXROOMS;
437 if ((!(rooms[rr].is_room & (R_ROOM | R_MAZE))) || (rr == rn)) {
440 for (k = 0; k < 4; k++) {
441 if (rooms[rr].doors[k].oth_room == rn) {
442 monster->trow = rooms[rr].doors[k].oth_row;
443 monster->tcol = rooms[rr].doors[k].oth_col;
444 if ((monster->trow == row) &&
445 (monster->tcol == col)) {
452 /* look for door to dead end */
453 for (i = rooms[rn].top_row; i <= rooms[rn].bottom_row; i++) {
454 for (j = rooms[rn].left_col; j <= rooms[rn].right_col; j++) {
455 if ((i != monster->row) && (j != monster->col) &&
456 (dungeon[i][j] & DOOR)) {
463 /* return monster to room that he came from */
464 for (i = 0; i < MAXROOMS; i++) {
465 for (j = 0; j < 4; j++) {
466 if (rooms[i].doors[j].oth_room == rn) {
467 for (k = 0; k < 4; k++) {
468 if (rooms[rn].doors[k].oth_room == i) {
469 monster->trow = rooms[rn].doors[k].oth_row;
470 monster->tcol = rooms[rn].doors[k].oth_col;
477 /* no place to send monster */
478 monster->trow = NO_ROOM;
479 } else { /* exiting room */
480 if (!get_oth_room(rn, &row, &col)) {
481 monster->trow = NO_ROOM;
490 get_oth_room(short rn, short *row, short *col)
494 if (*row == rooms[rn].top_row) {
496 } else if (*row == rooms[rn].bottom_row) {
498 } else if (*col == rooms[rn].left_col) {
500 } else if (*col == rooms[rn].right_col) {
503 if ((d != -1) && (rooms[rn].doors[d].oth_room >= 0)) {
504 *row = rooms[rn].doors[d].oth_row;
505 *col = rooms[rn].doors[d].oth_col;
514 char save[NOPTS+1][DCOLS];
518 char buf[MAX_OPT_LEN + 2];
520 for (i = 0; i < NOPTS+1; i++) {
521 for (j = 0; j < DCOLS; j++) {
522 save[i][j] = mvinch(i, j);
541 if (i == (NOPTS - 1)) {
542 mvaddstr(NOPTS, 0, press_space);
562 if (options[i].is_bool) {
563 *(options[i].bval) = (((ch == 't') || (ch == 'T')) ? 1 : 0);
569 if (options[i].is_bool) {
574 if ((ch == '\010') || ((ch >= ' ') && (ch <= '~'))) {
577 if ((ch >= ' ') && (ch <= '~') && (j < MAX_OPT_LEN)) {
581 } else if ((ch == '\010') && (j > 0)) {
583 move(i, j + strlen(options[i].prompt));
585 move(i, j + strlen(options[i].prompt));
589 } while ((ch != '\012') && (ch != '\015') && (ch != '\033'));
591 strcpy(*(options[i].strval), buf);
602 for (i = 0; i < NOPTS+1; i++) {
604 for (j = 0; j < DCOLS; j++) {
614 struct option *opt = &options[i];
619 s = *(opt->bval) ? "True" : "False";
629 struct option *opt = &options[i];
631 mvaddstr(i, 0, opt->prompt);
638 move(i, strlen(options[i].prompt));
648 if (!(sh = md_getenv("SHELL"))) {
654 printf("\nCreating new shell...\n");