]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - rogue/monster.c
Fix merge conflicts
[bsdgames-darwin.git] / rogue / monster.c
index 176ac756923af3b32526afe7db3466ae6fee654e..1d644f65bbf1d2db40f3f8a9a9bbedbe79655e9b 100644 (file)
@@ -1,4 +1,4 @@
-/*     $NetBSD: monster.c,v 1.3 1995/04/22 10:27:45 cgd Exp $  */
+/*     $NetBSD: monster.c,v 1.17 2013/08/11 03:44:27 dholland Exp $    */
 
 /*
  * Copyright (c) 1988, 1993
  * 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
 #if 0
 static char sccsid[] = "@(#)monster.c  8.1 (Berkeley) 5/31/93";
 #else
-static char rcsid[] = "$NetBSD: monster.c,v 1.3 1995/04/22 10:27:45 cgd Exp $";
+__RCSID("$NetBSD: monster.c,v 1.17 2013/08/11 03:44:27 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -61,7 +58,7 @@ static char rcsid[] = "$NetBSD: monster.c,v 1.3 1995/04/22 10:27:45 cgd Exp $";
 object level_monsters;
 boolean mon_disappeared;
 
-char *m_names[] = {
+const char *const m_names[] = {
        "aquator",
        "bat",
        "centaur",
@@ -90,46 +87,51 @@ char *m_names[] = {
        "zombie"
 };
 
-object mon_tab[MONSTERS] = {
-       {(ASLEEP|WAKENS|WANDERS|RUSTS),"0d0",25,'A',20,9,18,100,0,0,0,0,0},
-       {(ASLEEP|WANDERS|FLITS|FLIES),"1d3",10,'B',2,1,8,60,0,0,0,0,0},
-       {(ASLEEP|WANDERS),"3d3/2d5",32,'C',15,7,16,85,0,10,0,0,0},
-       {(ASLEEP|WAKENS|FLAMES),"4d6/4d9",145,'D',5000,21,126,100,0,90,0,0,0},
-       {(ASLEEP|WAKENS),"1d3",11,'E',2,1,7,65,0,0,0,0,0},
-       {(HOLDS|STATIONARY),"5d5",73,'F',91,12,126,80,0,0,0,0,0},
+#define FILL 0,0,0,0,0,0,0,0,0,0,0,0,0,NULL
+
+static object mon_tab[MONSTERS] = {
+       {(ASLEEP|WAKENS|WANDERS|RUSTS),"0d0",25,'A',20,9,18,100,0,0, FILL},
+       {(ASLEEP|WANDERS|FLITS|FLIES),"1d3",10,'B',2,1,8,60,0,0, FILL},
+       {(ASLEEP|WANDERS),"3d3/2d5",32,'C',15,7,16,85,0,10, FILL},
+       {(ASLEEP|WAKENS|FLAMES),"4d6/4d9",145,'D',5000,21,126,100,0,90, FILL},
+       {(ASLEEP|WAKENS),"1d3",11,'E',2,1,7,65,0,0, FILL},
+       {(HOLDS|STATIONARY),"5d5",73,'F',91,12,126,80,0,0, FILL},
        {(ASLEEP|WAKENS|WANDERS|FLIES),"5d5/5d5",115,'G',
-                       2000,20,126,85,0,10,0,0,0},
-       {(ASLEEP|WAKENS|WANDERS),"1d3/1d2",15,'H',3,1,10,67,0,0,0,0,0},
-       {(ASLEEP|FREEZES),"0d0",15,'I',5,2,11,68,0,0,0,0,0},
-       {(ASLEEP|WANDERS),"3d10/4d5",132,'J',3000,21,126,100,0,0,0,0,0},
-       {(ASLEEP|WAKENS|WANDERS|FLIES),"1d4",10,'K',2,1,6,60,0,0,0,0,0},
-       {(ASLEEP|STEALS_GOLD),"0d0",25,'L',21,6,16,75,0,0,0,0,0},
+                       2000,20,126,85,0,10, FILL},
+       {(ASLEEP|WAKENS|WANDERS),"1d3/1d2",15,'H',3,1,10,67,0,0, FILL},
+       {(ASLEEP|FREEZES),"0d0",15,'I',5,2,11,68,0,0, FILL},
+       {(ASLEEP|WANDERS),"3d10/4d5",132,'J',3000,21,126,100,0,0, FILL},
+       {(ASLEEP|WAKENS|WANDERS|FLIES),"1d4",10,'K',2,1,6,60,0,0, FILL},
+       {(ASLEEP|STEALS_GOLD),"0d0",25,'L',21,6,16,75,0,0, FILL},
        {(ASLEEP|WAKENS|WANDERS|CONFUSES),"4d4/3d7",97,'M',
-                       250,18,126,85,0,25,0,0,0},
-       {(ASLEEP|STEALS_ITEM),"0d0",25,'N',39,10,19,75,0,100,0,0,0},
-       {(ASLEEP|WANDERS|WAKENS|SEEKS_GOLD),"1d6",25,'O',5,4,13,70,0,10,0,0,0},
-       {(ASLEEP|INVISIBLE|WANDERS|FLITS),"5d4",76,'P',120,15,24,80,0,50,0,0,0},
-       {(ASLEEP|WAKENS|WANDERS),"3d5",30,'Q',20,8,17,78,0,20,0,0,0},
-       {(ASLEEP|WAKENS|WANDERS|STINGS),"2d5",19,'R',10,3,12,70,0,0,0,0,0},
-       {(ASLEEP|WAKENS|WANDERS),"1d3",8,'S',2,1,9,50,0,0,0,0,0},
-       {(ASLEEP|WAKENS|WANDERS),"4d6/1d4",75,'T',125,13,22,75,0,33,0,0,0},
+                       250,18,126,85,0,25, FILL},
+       {(ASLEEP|STEALS_ITEM),"0d0",25,'N',39,10,19,75,0,100, FILL},
+       {(ASLEEP|WANDERS|WAKENS|SEEKS_GOLD),"1d6",25,'O',5,4,13,70,0,10, FILL},
+       {(ASLEEP|INVISIBLE|WANDERS|FLITS),"5d4",76,'P',120,15,24,80,0,50, FILL},
+       {(ASLEEP|WAKENS|WANDERS),"3d5",30,'Q',20,8,17,78,0,20, FILL},
+       {(ASLEEP|WAKENS|WANDERS|STINGS),"2d5",19,'R',10,3,12,70,0,0, FILL},
+       {(ASLEEP|WAKENS|WANDERS),"1d3",8,'S',2,1,9,50,0,0, FILL},
+       {(ASLEEP|WAKENS|WANDERS),"4d6/1d4",75,'T',125,13,22,75,0,33, FILL},
        {(ASLEEP|WAKENS|WANDERS),"4d10",90,'U',
-                       200,17,26,85,0,33,0,0,0},
+                       200,17,26,85,0,33, FILL},
        {(ASLEEP|WAKENS|WANDERS|DRAINS_LIFE),"1d14/1d4",55,'V',
-                       350,19,126,85,0,18,0,0,0},
-       {(ASLEEP|WANDERS|DROPS_LEVEL),"2d8",45,'W',55,14,23,75,0,0,0,0,0},
-       {(ASLEEP|IMITATES),"4d6",42,'X',110,16,25,75,0,0,0,0,0},
-       {(ASLEEP|WANDERS),"3d6",35,'Y',50,11,20,80,0,20,0,0,0},
-       {(ASLEEP|WAKENS|WANDERS),"1d7",21,'Z',8,5,14,69,0,0,0,0,0}
+                       350,19,126,85,0,18, FILL},
+       {(ASLEEP|WANDERS|DROPS_LEVEL),"2d8",45,'W',55,14,23,75,0,0, FILL},
+       {(ASLEEP|IMITATES),"4d6",42,'X',110,16,25,75,0,0, FILL},
+       {(ASLEEP|WANDERS),"3d6",35,'Y',50,11,20,80,0,20, FILL},
+       {(ASLEEP|WAKENS|WANDERS),"1d7",21,'Z',8,5,14,69,0,0, FILL}
 };
 
-extern short cur_level;
-extern short cur_room, party_room;
-extern short blind, halluc, haste_self;
-extern boolean detect_monster, see_invisible, r_see_invisible;
-extern short stealthy;
+static void aim_monster(object *);
+static int flit(object *);
+static int move_confused(object *);
+static int mtry(object *, short, short);
+static int no_room_for_monster(int);
+static void put_m_at(short, short, object *);
+static int rogue_is_around(int, int);
 
-put_mons()
+void
+put_mons(void)
 {
        short i;
        short n;
@@ -139,7 +141,7 @@ put_mons()
        n = get_rand(4, 6);
 
        for (i = 0; i < n; i++) {
-               monster = gr_monster((object *) 0, 0);
+               monster = gr_monster(NULL, 0);
                if ((monster->m_flags & WANDERS) && coin_toss()) {
                        wake_up(monster);
                }
@@ -149,9 +151,7 @@ put_mons()
 }
 
 object *
-gr_monster(monster, mn)
-register object *monster;
-register mn;
+gr_monster(object *monster, int mn)
 {
        if (!monster) {
                monster = alloc_object();
@@ -175,9 +175,10 @@ register mn;
        return(monster);
 }
 
-mv_mons()
+void
+mv_mons(void)
 {
-       register object *monster, *next_monster;
+       object *monster, *next_monster, *test_mons;
        boolean flew;
 
        if (haste_self % 2) {
@@ -216,18 +217,29 @@ mv_mons()
                if (!(flew && mon_can_go(monster, rogue.row, rogue.col))) {
                        mv_1_monster(monster, rogue.row, rogue.col);
                }
-NM:            monster = next_monster;
+NM:            test_mons = level_monsters.next_monster;
+               monster = NULL;
+               while (test_mons)
+               {
+                       if (next_monster == test_mons)
+                       {
+                               monster = next_monster;
+                               break;
+                       }
+                       test_mons = test_mons -> next_monster;
+               }
        }
 }
 
-party_monsters(rn, n)
-int rn, n;
+void
+party_monsters(int rn, int n)
 {
        short i, j;
        short row, col;
        object *monster;
        boolean found;
 
+       row = col = 0;
        n += n;
 
        for (i = 0; i < MONSTERS; i++) {
@@ -248,7 +260,7 @@ int rn, n;
                        }
                }
                if (found) {
-                       monster = gr_monster((object *) 0, 0);
+                       monster = gr_monster((object *)0, 0);
                        if (!(monster->m_flags & IMITATES)) {
                                monster->m_flags |= WAKENS;
                        }
@@ -260,12 +272,12 @@ int rn, n;
        }
 }
 
-gmc_row_col(row, col)
-register row, col;
+char
+gmc_row_col(int row, int col)
 {
-       register object *monster;
+       object *monster;
 
-       if (monster = object_at(&level_monsters, row, col)) {
+       if ((monster = object_at(&level_monsters, row, col)) != NULL) {
                if ((!(detect_monster || see_invisible || r_see_invisible) &&
                        (monster->m_flags & INVISIBLE)) || blind) {
                        return(monster->trail_char);
@@ -279,8 +291,8 @@ register row, col;
        }
 }
 
-gmc(monster)
-object *monster;
+char
+gmc(object *monster)
 {
        if ((!(detect_monster || see_invisible || r_see_invisible) &&
                (monster->m_flags & INVISIBLE))
@@ -293,9 +305,8 @@ object *monster;
        return(monster->m_char);
 }
 
-mv_1_monster(monster, row, col)
-register object *monster;
-short row, col;
+void
+mv_1_monster(object *monster, short row, short col)
 {
        short i, n;
        boolean tried[6];
@@ -432,9 +443,8 @@ O:
        }
 }
 
-mtry(monster, row, col)
-register object *monster;
-register short row, col;
+static int
+mtry(object *monster, short row, short col)
 {
        if (mon_can_go(monster, row, col)) {
                move_mon_to(monster, row, col);
@@ -443,12 +453,11 @@ register short row, col;
        return(0);
 }
 
-move_mon_to(monster, row, col)
-register object *monster;
-register short row, col;
+void
+move_mon_to(object *monster, short row, short col)
 {
        short c;
-       register mrow, mcol;
+       int mrow, mcol;
 
        mrow = monster->row;
        mcol = monster->col;
@@ -493,9 +502,8 @@ register short row, col;
        }
 }
 
-mon_can_go(monster, row, col)
-register object *monster;
-register short row, col;
+int
+mon_can_go(const object *monster, short row, short col)
 {
        object *obj;
        short dr, dc;
@@ -534,18 +542,16 @@ register short row, col;
        return(1);
 }
 
-wake_up(monster)
-object *monster;
+void
+wake_up(object *monster)
 {
        if (!(monster->m_flags & NAPPING)) {
                monster->m_flags &= (~(ASLEEP | IMITATES | WAKENS));
        }
 }
 
-wake_room(rn, entering, row, col)
-short rn;
-boolean entering;
-short row, col;
+void
+wake_room(short rn, boolean entering, short row, short col)
 {
        object *monster;
        short wake_percent;
@@ -578,9 +584,8 @@ short row, col;
        }
 }
 
-char *
-mon_name(monster)
-object *monster;
+const char *
+mon_name(const object *monster)
 {
        short ch;
 
@@ -596,8 +601,8 @@ object *monster;
        return(m_names[ch]);
 }
 
-rogue_is_around(row, col)
-register row, col;
+static int
+rogue_is_around(int row, int col)
 {
        short rdif, cdif, retval;
 
@@ -608,14 +613,17 @@ register row, col;
        return(retval);
 }
 
-wanderer()
+void
+wanderer(void)
 {
        object *monster;
        short row, col, i;
        boolean found = 0;
 
+       monster = NULL;         /* XXXGCC -Wuninitialized [powerpc] */
+
        for (i = 0; ((i < 15) && (!found)); i++) {
-               monster = gr_monster((object *) 0, 0);
+               monster = gr_monster(NULL, 0);
                if (!(monster->m_flags & (WAKENS | WANDERS))) {
                        free_object(monster);
                } else {
@@ -638,7 +646,8 @@ wanderer()
        }
 }
 
-show_monsters()
+void
+show_monsters(void)
 {
        object *monster;
 
@@ -659,7 +668,8 @@ show_monsters()
        }
 }
 
-create_monster()
+void
+create_monster(void)
 {
        short row, col;
        short i;
@@ -671,7 +681,7 @@ create_monster()
 
        for (i = 0; i < 9; i++) {
                rand_around(i, &row, &col);
-               if (((row == rogue.row) && (col = rogue.col)) ||
+               if (((row == rogue.row) && (col == rogue.col)) ||
                                (row < MIN_ROW) || (row > (DROWS-2)) ||
                                (col < 0) || (col > (DCOLS-1))) {
                        continue;
@@ -683,35 +693,36 @@ create_monster()
                }
        }
        if (found) {
-               monster = gr_monster((object *) 0, 0);
+               monster = gr_monster((object *)0, 0);
                put_m_at(row, col, monster);
                mvaddch(row, col, gmc(monster));
                if (monster->m_flags & (WANDERS | WAKENS)) {
                        wake_up(monster);
                }
        } else {
-               message("you hear a faint cry of anguish in the distance", 0);
+               messagef(0, "you hear a faint cry of anguish in the distance");
        }
 }
 
-put_m_at(row, col, monster)
-short row, col;
-object *monster;
+static void
+put_m_at(short row, short col, object *monster)
 {
        monster->row = row;
        monster->col = col;
        dungeon[row][col] |= MONSTER;
        monster->trail_char = mvinch(row, col);
-       (void) add_to_pack(monster, &level_monsters, 0);
+       (void)add_to_pack(monster, &level_monsters, 0);
        aim_monster(monster);
 }
 
-aim_monster(monster)
-object *monster;
+static void
+aim_monster(object *monster)
 {
        short i, rn, d, r;
 
        rn = get_room_number(monster->row, monster->col);
+       if (rn == NO_ROOM)
+               clean_up("aim_monster: monster not in room");
        r = get_rand(0, 12);
 
        for (i = 0; i < 4; i++) {
@@ -724,10 +735,10 @@ object *monster;
        }
 }
 
-rogue_can_see(row, col)
-register row, col;
+int
+rogue_can_see(int row, int col)
 {
-       register retval;
+       int retval;
 
        retval = !blind &&
                        (((get_room_number(row, col) == cur_room) &&
@@ -737,8 +748,8 @@ register row, col;
        return(retval);
 }
 
-move_confused(monster)
-object *monster;
+static int
+move_confused(object *monster)
 {
        short i, row, col;
 
@@ -767,8 +778,8 @@ object *monster;
        return(0);
 }
 
-flit(monster)
-object *monster;
+static int
+flit(object *monster)
 {
        short i, row, col;
 
@@ -793,18 +804,19 @@ object *monster;
        return(1);
 }
 
-gr_obj_char()
+char
+gr_obj_char(void)
 {
        short r;
-       char *rs = "%!?]=/):*";
+       const char *rs = "%!?]=/):*";
 
        r = get_rand(0, 8);
 
        return(rs[r]);
 }
 
-no_room_for_monster(rn)
-int rn;
+static int
+no_room_for_monster(int rn)
 {
        short i, j;
 
@@ -818,11 +830,12 @@ int rn;
        return(1);
 }
 
-aggravate()
+void
+aggravate(void)
 {
        object *monster;
 
-       message("you hear a high pitched humming noise", 0);
+       messagef(0, "you hear a high pitched humming noise");
 
        monster = level_monsters.next_monster;
 
@@ -837,8 +850,7 @@ aggravate()
 }
 
 boolean
-mon_sees(monster, row, col)
-object *monster;
+mon_sees(const object *monster, int row, int col)
 {
        short rn, rdif, cdif, retval;
 
@@ -856,7 +868,8 @@ object *monster;
        return(retval);
 }
 
-mv_aquatars()
+void
+mv_aquatars(void)
 {
        object *monster;