* Copyright (c) 1988 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)room.c 5.3 (Berkeley) %G%";
* This source herein may be modified and/or distributed by anybody who
* so desires, with the following restrictions:
* 1.) No portion of this notice shall be removed.
* 2.) Credit shall not be taken for the creation of this source.
* 3.) This code is not to be traded, sold, or used for personal
boolean rooms_visited
[MAXROOMS
];
extern boolean detect_monster
, jump
, passgo
, no_skull
, ask_quit
;
extern char *nick_name
, *fruit
, *save_file
, *press_space
;
"Show position only at end of run (\"jump\"): ",
"Follow turnings in passageways (\"passgo\"): ",
"Don't print skull when killed (\"noskull\" or \"notombstone\"): ",
1, (char **) 0, &no_skull
"Ask player before saying 'Okay, bye-bye!' (\"askquit\"): ",
1, (char **) 0, &ask_quit
"Save file (\"file\"): ",
for (i
= rooms
[rn
].top_row
;
i
<= rooms
[rn
].bottom_row
; i
++) {
for (j
= rooms
[rn
].left_col
;
j
<= rooms
[rn
].right_col
; j
++) {
if (dungeon
[i
][j
] & MONSTER
) {
if (monster
= object_at(&level_monsters
, i
, j
)) {
dungeon
[monster
->row
][monster
->col
] &= (~MONSTER
);
get_dungeon_char(monster
->row
, monster
->col
);
dungeon
[monster
->row
][monster
->col
] |= MONSTER
;
mvaddch(i
, j
, get_dungeon_char(i
, j
));
mvaddch(rogue
.row
, rogue
.col
, rogue
.fchar
);
short i
, j
, i_end
, j_end
;
i_end
= (row
< (DROWS
-2)) ? 1 : 0;
j_end
= (col
< (DCOLS
-1)) ? 1 : 0;
for (i
= ((row
> MIN_ROW
) ? -1 : 0); i
<= i_end
; i
++) {
for (j
= ((col
> 0) ? -1 : 0); j
<= j_end
; j
++) {
if (can_move(row
, col
, row
+i
, col
+j
)) {
mvaddch(row
+i
, col
+j
, get_dungeon_char(row
+i
, col
+j
));
for (i
= rooms
[rn
].top_row
+ 1; i
< rooms
[rn
].bottom_row
; i
++) {
for (j
= rooms
[rn
].left_col
+ 1; j
< rooms
[rn
].right_col
; j
++) {
if (!(dungeon
[i
][j
] & (OBJECT
| STAIRS
)) &&
!(detect_monster
&& (dungeon
[i
][j
] & MONSTER
))) {
if ((dungeon
[i
][j
] & TRAP
) && (!(dungeon
[i
][j
] & HIDDEN
))) {
get_dungeon_char(row
, col
)
register unsigned short mask
= dungeon
[row
][col
];
return(gmc_row_col(row
, col
));
obj
= object_at(&level_objects
, row
, col
);
return(get_mask_char(obj
->what_is
));
if (mask
& (TUNNEL
| STAIRS
| HORWALL
| VERTWALL
| FLOOR
| DOOR
)) {
if ((mask
& (TUNNEL
| STAIRS
)) && (!(mask
& HIDDEN
))) {
return(((mask
& STAIRS
) ? '%' : '#'));
if (!(dungeon
[row
][col
] & HIDDEN
)) {
if (((col
> 0) && (dungeon
[row
][col
-1] & HORWALL
)) ||
((col
< (DCOLS
-1)) && (dungeon
[row
][col
+1] & HORWALL
))) {
register unsigned short mask
;
return('~'); /* unknown, something is wrong */
gr_row_col(row
, col
, mask
)
r
= get_rand(MIN_ROW
, DROWS
-2);
c
= get_rand(0, DCOLS
-1);
rn
= get_room_number(r
, c
);
} while ((rn
== NO_ROOM
) ||
(!(dungeon
[r
][c
] & mask
)) ||
(dungeon
[r
][c
] & (~mask
)) ||
(!(rooms
[rn
].is_room
& (R_ROOM
| R_MAZE
))) ||
((r
== rogue
.row
) && (c
== rogue
.col
)));
i
= get_rand(0, MAXROOMS
-1);
} while (!(rooms
[i
].is_room
& (R_ROOM
| R_MAZE
)));
N
= ((rooms
[rn
].bottom_row
- rooms
[rn
].top_row
) - 1) *
((rooms
[rn
].right_col
- rooms
[rn
].left_col
) - 1);
for (i
= 0; i
< n
; i
++) {
for (j
= found
= 0; ((!found
) && (j
< 250)); j
++) {
row
= get_rand(rooms
[rn
].top_row
+1,
col
= get_rand(rooms
[rn
].left_col
+1,
if ((dungeon
[row
][col
] == FLOOR
) || (dungeon
[row
][col
] == TUNNEL
)) {
get_room_number(row
, col
)
for (i
= 0; i
< MAXROOMS
; i
++) {
if ((row
>= rooms
[i
].top_row
) && (row
<= rooms
[i
].bottom_row
) &&
(col
>= rooms
[i
].left_col
) && (col
<= rooms
[i
].right_col
)) {
for (i
= 0; i
< MAXROOMS
; i
++) {
if (rooms
[i
].is_room
& (R_ROOM
| R_MAZE
)) {
visit_rooms(starting_room
);
for (i
= 0; i
< MAXROOMS
; i
++) {
if ((rooms
[i
].is_room
& (R_ROOM
| R_MAZE
)) && (!rooms_visited
[i
])) {
for (i
= 0; i
< 4; i
++) {
oth_rn
= rooms
[rn
].doors
[i
].oth_room
;
if ((oth_rn
>= 0) && (!rooms_visited
[oth_rn
])) {
unsigned short mask
= (HORWALL
| VERTWALL
| DOOR
| TUNNEL
| TRAP
| STAIRS
|
for (i
= 0; i
< DROWS
; i
++) {
for (j
= 0; j
< DCOLS
; j
++) {
if (((ch
= mvinch(i
, j
)) == ' ') ||
((ch
>= 'A') && (ch
<= 'Z')) || (s
& (TRAP
| HIDDEN
))) {
dungeon
[i
][j
] &= (~HIDDEN
);
} else if (s
& VERTWALL
) {
if ((!(s
& MONSTER
)) || (och
== ' ')) {
if (monster
= object_at(&level_monsters
, i
, j
)) {
monster
->trail_char
= ch
;
dr_course(monster
, entering
, row
, col
)
if (mon_sees(monster
, rogue
.row
, rogue
.col
)) {
rn
= get_room_number(row
, col
);
if (entering
) { /* entering room */
/* look for door to some other room */
r
= get_rand(0, MAXROOMS
-1);
for (i
= 0; i
< MAXROOMS
; i
++) {
if ((!(rooms
[rr
].is_room
& (R_ROOM
| R_MAZE
))) || (rr
== rn
)) {
for (k
= 0; k
< 4; k
++) {
if (rooms
[rr
].doors
[k
].oth_room
== rn
) {
monster
->trow
= rooms
[rr
].doors
[k
].oth_row
;
monster
->tcol
= rooms
[rr
].doors
[k
].oth_col
;
if ((monster
->trow
== row
) &&
(monster
->tcol
== col
)) {
/* look for door to dead end */
for (i
= rooms
[rn
].top_row
; i
<= rooms
[rn
].bottom_row
; i
++) {
for (j
= rooms
[rn
].left_col
; j
<= rooms
[rn
].right_col
; j
++) {
if ((i
!= monster
->row
) && (j
!= monster
->col
) &&
(dungeon
[i
][j
] & DOOR
)) {
/* return monster to room that he came from */
for (i
= 0; i
< MAXROOMS
; i
++) {
for (j
= 0; j
< 4; j
++) {
if (rooms
[i
].doors
[j
].oth_room
== rn
) {
for (k
= 0; k
< 4; k
++) {
if (rooms
[rn
].doors
[k
].oth_room
== i
) {
monster
->trow
= rooms
[rn
].doors
[k
].oth_row
;
monster
->tcol
= rooms
[rn
].doors
[k
].oth_col
;
/* no place to send monster */
} else { /* exiting room */
if (!get_oth_room(rn
, &row
, &col
)) {
get_oth_room(rn
, row
, col
)
if (*row
== rooms
[rn
].top_row
) {
} else if (*row
== rooms
[rn
].bottom_row
) {
} else if (*col
== rooms
[rn
].left_col
) {
} else if (*col
== rooms
[rn
].right_col
) {
if ((d
!= -1) && (rooms
[rn
].doors
[d
].oth_room
>= 0)) {
*row
= rooms
[rn
].doors
[d
].oth_row
;
*col
= rooms
[rn
].doors
[d
].oth_col
;
char save
[NOPTS
+1][DCOLS
];
char buf
[MAX_OPT_LEN
+ 2];
for (i
= 0; i
< NOPTS
+1; i
++) {
for (j
= 0; j
< DCOLS
; j
++) {
save
[i
][j
] = mvinch(i
, j
);
mvaddstr(NOPTS
, 0, press_space
);
if (options
[i
].is_bool
) {
*(options
[i
].bval
) = (((ch
== 't') || (ch
== 'T')) ? 1 : 0);
if (options
[i
].is_bool
) {
if ((ch
== '\010') || ((ch
>= ' ') && (ch
<= '~'))) {
if ((ch
>= ' ') && (ch
<= '~') && (j
< MAX_OPT_LEN
)) {
} else if ((ch
== '\010') && (j
> 0)) {
move(i
, j
+ strlen(options
[i
].prompt
));
move(i
, j
+ strlen(options
[i
].prompt
));
} while ((ch
!= '\012') && (ch
!= '\015') && (ch
!= '\033'));
(void) strcpy(*(options
[i
].strval
), buf
);
for (i
= 0; i
< NOPTS
+1; i
++) {
for (j
= 0; j
< DCOLS
; j
++) {
struct option
*opt
= &options
[i
];
s
= *(opt
->bval
) ? "True" : "False";
struct option
*opt
= &options
[i
];
mvaddstr(i
, 0, opt
->prompt
);
move(i
, strlen(options
[i
].prompt
));
if (!(sh
= md_getenv("SHELL"))) {
printf("\nCreating new shell...\n");