]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - rogue/room.c
Avoid messing up the display when too many letters are guessed at once.
[bsdgames-darwin.git] / rogue / room.c
index 33b188cda9c7bb5589221a5b207ccf8395e2bdf5..7a75499ce3cc0b2eccd42b7dcb63dbfa4058de8d 100644 (file)
@@ -1,6 +1,8 @@
+/*     $NetBSD: room.c,v 1.14 2019/02/03 03:19:25 mrg Exp $    */
+
 /*
- * Copyright (c) 1988 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1988, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  * Timothy C. Stoehr.
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
  *
  * SUCH DAMAGE.
  */
 
+#include <sys/cdefs.h>
 #ifndef lint
-/*static char sccsid[] = "from: @(#)room.c     5.3 (Berkeley) 6/1/90";*/
-static char rcsid[] = "$Id: room.c,v 1.2 1993/08/01 18:52:16 mycroft Exp $";
+#if 0
+static char sccsid[] = "@(#)room.c     8.1 (Berkeley) 5/31/93";
+#else
+__RCSID("$NetBSD: room.c,v 1.14 2019/02/03 03:19:25 mrg Exp $");
+#endif
 #endif /* not lint */
 
 /*
@@ -54,52 +56,54 @@ static char rcsid[] = "$Id: room.c,v 1.2 1993/08/01 18:52:16 mycroft Exp $";
 #include "rogue.h"
 
 room rooms[MAXROOMS];
-boolean rooms_visited[MAXROOMS];
 
-extern short blind;
-extern boolean detect_monster, jump, passgo, no_skull, ask_quit;
-extern char *nick_name, *fruit, *save_file, *press_space;
+static boolean rooms_visited[MAXROOMS];
 
 #define NOPTS 7
-
-struct option {
-       char *prompt;
+static const struct option {
+       const char *prompt;
        boolean is_bool;
        char **strval;
        boolean *bval;
 } options[NOPTS] = {
        {
                "Show position only at end of run (\"jump\"): ",
-               1, (char **) 0, &jump
+               1, NULL, &jump
        },
        {
                "Follow turnings in passageways (\"passgo\"): ",
-               1, (char **) 0, &passgo
+               1, NULL, &passgo
        },
        {
                "Don't print skull when killed (\"noskull\" or \"notombstone\"): ",
-               1, (char **) 0, &no_skull
+               1, NULL, &no_skull
        },
        {
                "Ask player before saying 'Okay, bye-bye!' (\"askquit\"): ",
-               1, (char **) 0, &ask_quit
+               1, NULL, &ask_quit
        },
        {
                "Name (\"name\"): ",
-               0, &nick_name
+               0, &nick_name, NULL
        },
        {
                "Fruit (\"fruit\"): ",
-               0, &fruit
+               0, &fruit, NULL
        },
        {
                "Save file (\"file\"): ",
-               0, &save_file
+               0, &save_file, NULL
        }
 };
 
-light_up_room(rn)
-int rn;
+static boolean get_oth_room(short, short *, short *);
+static void opt_erase(int);
+static void opt_go(int);
+static void opt_show(int);
+static void visit_rooms(int);
+
+void
+light_up_room(int rn)
 {
        short i, j;
 
@@ -111,7 +115,8 @@ int rn;
                                if (dungeon[i][j] & MONSTER) {
                                        object *monster;
 
-                                       if (monster = object_at(&level_monsters, i, j)) {
+                                       if ((monster = object_at(
+                                           &level_monsters, i, j)) != NULL) {
                                                dungeon[monster->row][monster->col] &= (~MONSTER);
                                                monster->trail_char =
                                                        get_dungeon_char(monster->row, monster->col);
@@ -125,7 +130,8 @@ int rn;
        }
 }
 
-light_passage(row, col)
+void
+light_passage(int row, int col)
 {
        short i, j, i_end, j_end;
 
@@ -144,8 +150,8 @@ light_passage(row, col)
        }
 }
 
-darken_room(rn)
-short rn;
+void
+darken_room(short rn)
 {
        short i, j;
 
@@ -168,10 +174,10 @@ short rn;
        }
 }
 
-get_dungeon_char(row, col)
-register row, col;
+char
+get_dungeon_char(short row, short col)
 {
-       register unsigned short mask = dungeon[row][col];
+       unsigned short mask = dungeon[row][col];
 
        if (mask & MONSTER) {
                return(gmc_row_col(row, col));
@@ -216,8 +222,8 @@ register row, col;
        return(' ');
 }
 
-get_mask_char(mask)
-register unsigned short mask;
+char
+get_mask_char(unsigned short mask)
 {
                switch(mask) {
                case SCROL:
@@ -243,9 +249,8 @@ register unsigned short mask;
                }
 }
 
-gr_row_col(row, col, mask)
-short *row, *col;
-unsigned short mask;
+void
+gr_row_col(short *row, short *col, unsigned short mask)
 {
        short rn;
        short r, c;
@@ -264,7 +269,8 @@ unsigned short mask;
        *col = c;
 }
 
-gr_room()
+short
+gr_room(void)
 {
        short i;
 
@@ -275,13 +281,15 @@ gr_room()
        return(i);
 }
 
-party_objects(rn)
+short
+party_objects(int rn)
 {
        short i, j, nf = 0;
        object *obj;
        short n, N, row, col;
        boolean found;
 
+       row = col = 0;
        N = ((rooms[rn].bottom_row - rooms[rn].top_row) - 1) *
                ((rooms[rn].right_col - rooms[rn].left_col) - 1);
        n =  get_rand(5, 10);
@@ -307,8 +315,8 @@ party_objects(rn)
        return(nf);
 }
 
-get_room_number(row, col)
-register row, col;
+short
+get_room_number(int row, int col)
 {
        short i;
 
@@ -321,10 +329,12 @@ register row, col;
        return(NO_ROOM);
 }
 
-is_all_connected()
+boolean
+is_all_connected(void)
 {
        short i, starting_room;
 
+       starting_room = 0;
        for (i = 0; i < MAXROOMS; i++) {
                rooms_visited[i] = 0;
                if (rooms[i].is_room & (R_ROOM | R_MAZE)) {
@@ -342,8 +352,8 @@ is_all_connected()
        return(1);
 }
 
-visit_rooms(rn)
-int rn;
+static void
+visit_rooms(int rn)
 {
        short i;
        short oth_rn;
@@ -358,7 +368,8 @@ int rn;
        }
 }
 
-draw_magic_map()
+void
+draw_magic_map(void)
 {
        short i, j, ch, och;
        unsigned short mask = (HORWALL | VERTWALL | DOOR | TUNNEL | TRAP | STAIRS |
@@ -394,8 +405,11 @@ draw_magic_map()
                                        if (s & MONSTER) {
                                                object *monster;
 
-                                               if (monster = object_at(&level_monsters, i, j)) {
-                                                       monster->trail_char = ch;
+                                               if ((monster = object_at(
+                                                   &level_monsters, i, j))
+                                                   != NULL) {
+                                                       monster->trail_char =
+                                                           ch;
                                                }
                                        }
                                }
@@ -404,10 +418,8 @@ draw_magic_map()
        }
 }
 
-dr_course(monster, entering, row, col)
-object *monster;
-boolean entering;
-short row, col;
+void
+dr_course(object *monster, boolean entering, short row, short col)
 {
        short i, j, k, rn;
        short r, rr;
@@ -442,6 +454,8 @@ short row, col;
                        }
                }
                /* look for door to dead end */
+               if (rn == NO_ROOM)
+                       clean_up("dr_course:  monster not in room");
                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) &&
@@ -469,7 +483,7 @@ short row, col;
                /* no place to send monster */
                monster->trow = NO_ROOM;
        } else {                /* exiting room */
-               if (!get_oth_room(rn, &row, &col)) {
+               if (rn == NO_ROOM || !get_oth_room(rn, &row, &col)) {
                        monster->trow = NO_ROOM;
                } else {
                        monster->trow = row;
@@ -478,8 +492,8 @@ short row, col;
        }
 }
 
-get_oth_room(rn, row, col)
-short rn, *row, *col;
+static boolean
+get_oth_room(short rn, short *row, short *col)
 {
        short d = -1;
 
@@ -500,7 +514,8 @@ short rn, *row, *col;
        return(0);
 }
 
-edit_opts()
+void
+edit_opts(void)
 {
        char save[NOPTS+1][DCOLS];
        short i, j;
@@ -556,6 +571,7 @@ CH:
                                opt_go(++i);
                                break;
                        }
+                       /* FALLTHROUGH */
                default:
                        if (options[i].is_bool) {
                                sound_bell();
@@ -579,7 +595,12 @@ CH:
                                        ch = rgetchar();
                                } while ((ch != '\012') && (ch != '\015') && (ch != '\033'));
                                if (j != 0) {
-                                       (void) strcpy(*(options[i].strval), buf);
+                                       /*
+                                        * We rely on the option string being
+                                        * allocated to hold MAX_OPT_LEN+2
+                                        * bytes. This is arranged in init.c.
+                                        */
+                                       (void)strcpy(*(options[i].strval), buf);
                                }
                                opt_show(i);
                                goto CH;
@@ -598,11 +619,11 @@ CH:
        }
 }
 
-opt_show(i)
-int i;
+static void
+opt_show(int i)
 {
-       char *s;
-       struct option *opt = &options[i];
+       const char *s;
+       const struct option *opt = &options[i];
 
        opt_erase(i);
 
@@ -614,25 +635,26 @@ int i;
        addstr(s);
 }
 
-opt_erase(i)
-int i;
+static void
+opt_erase(int i)
 {
-       struct option *opt = &options[i];
+       const struct option *opt = &options[i];
 
        mvaddstr(i, 0, opt->prompt);
        clrtoeol();
 }
 
-opt_go(i)
-int i;
+static void
+opt_go(int i)
 {
        move(i, strlen(options[i].prompt));
 }
 
-do_shell()
+void
+do_shell(void)
 {
 #ifdef UNIX
-       char *sh;
+       const char *sh;
 
        md_ignore_signals();
        if (!(sh = md_getenv("SHELL"))) {