]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - rogue/object.c
properly terminate after using strncpy().
[bsdgames-darwin.git] / rogue / object.c
index 874af97a1da2020e0bcc4d5e73f6304a9efefc46..9897ec6ad476614f2edf8aff6375b89601cac8d6 100644 (file)
@@ -1,4 +1,4 @@
-/*     $NetBSD: object.c,v 1.7 1998/09/11 14:09:27 hubertf Exp $       */
+/*     $NetBSD: object.c,v 1.14 2009/08/12 08:44:45 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.
  *
@@ -41,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)object.c   8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: object.c,v 1.7 1998/09/11 14:09:27 hubertf Exp $");
+__RCSID("$NetBSD: object.c,v 1.14 2009/08/12 08:44:45 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -62,8 +58,9 @@ __RCSID("$NetBSD: object.c,v 1.7 1998/09/11 14:09:27 hubertf Exp $");
 object level_objects;
 unsigned short dungeon[DROWS][DCOLS];
 short foods = 0;
-object *free_list = (object *) 0;
-char *fruit = (char *) 0;
+char *fruit = NULL;
+
+static object *free_list = NULL;
 
 fighter rogue = {
        INIT_AW,        /* armor */
@@ -84,36 +81,36 @@ fighter rogue = {
 };
 
 struct id id_potions[POTIONS] = {
-{100, "blue \0                           ", "of increase strength ", 0},
-{250, "red \0                            ", "of restore strength ", 0},
-{100, "green \0                          ", "of healing ", 0},
-{200, "grey \0                           ", "of extra healing ", 0},
- {10, "brown \0                          ", "of poison ", 0},
-{300, "clear \0                          ", "of raise level ", 0},
- {10, "pink \0                           ", "of blindness ", 0},
- {25, "white \0                          ", "of hallucination ", 0},
-{100, "purple \0                         ", "of detect monster ", 0},
-{100, "black \0                          ", "of detect things ", 0},
- {10, "yellow \0                         ", "of confusion ", 0},
- {80, "plaid \0                          ", "of levitation ", 0},
-{150, "burgundy \0                       ", "of haste self ", 0},
-{145, "beige \0                          ", "of see invisible ", 0}
+{100, "blue ",     "of increase strength ", 0},
+{250, "red ",      "of restore strength ", 0},
+{100, "green ",    "of healing ", 0},
+{200, "grey ",     "of extra healing ", 0},
+ {10, "brown ",    "of poison ", 0},
+{300, "clear ",    "of raise level ", 0},
+ {10, "pink ",     "of blindness ", 0},
+ {25, "white ",    "of hallucination ", 0},
+{100, "purple ",   "of detect monster ", 0},
+{100, "black ",    "of detect things ", 0},
+ {10, "yellow ",   "of confusion ", 0},
+ {80, "plaid ",    "of levitation ", 0},
+{150, "burgundy ", "of haste self ", 0},
+{145, "beige ",    "of see invisible ", 0}
 };
 
 struct id id_scrolls[SCROLS] = {
-{505, "                                   ", "of protect armor ", 0},
-{200, "                                   ", "of hold monster ", 0},
-{235, "                                   ", "of enchant weapon ", 0},
-{235, "                                   ", "of enchant armor ", 0},
-{175, "                                   ", "of identify ", 0},
-{190, "                                   ", "of teleportation ", 0},
- {25, "                                   ", "of sleep ", 0},
-{610, "                                   ", "of scare monster ", 0},
-{210, "                                   ", "of remove curse ", 0},
- {80, "                                   ", "of create monster ",0},
- {25, "                                   ", "of aggravate monster ",0},
-{180, "                                   ", "of magic mapping ", 0},
- {90, "                                   ", "of confuse monster ", 0}
+{505, "", "of protect armor ", 0},
+{200, "", "of hold monster ", 0},
+{235, "", "of enchant weapon ", 0},
+{235, "", "of enchant armor ", 0},
+{175, "", "of identify ", 0},
+{190, "", "of teleportation ", 0},
+ {25, "", "of sleep ", 0},
+{610, "", "of scare monster ", 0},
+{210, "", "of remove curse ", 0},
+ {80, "", "of create monster ",0},
+ {25, "", "of aggravate monster ",0},
+{180, "", "of magic mapping ", 0},
+ {90, "", "of confuse monster ", 0}
 };
 
 struct id id_weapons[WEAPONS] = {
@@ -138,35 +135,46 @@ struct id id_armors[ARMORS] = {
 };
 
 struct id id_wands[WANDS] = {
-        {25, "                                 ", "of teleport away ",0},
-        {50, "                                 ", "of slow monster ", 0},
-         {8, "                                 ", "of invisibility ",0},
-        {55, "                                 ", "of polymorph ",0},
-         {2, "                                 ", "of haste monster ",0},
-        {20, "                                 ", "of magic missile ",0},
-        {20, "                                 ", "of cancellation ",0},
-         {0, "                                 ", "of do nothing ",0},
-        {35, "                                 ", "of drain life ",0},
-        {20, "                                 ", "of cold ",0},
-        {20, "                                 ", "of fire ",0}
+        {25, "", "of teleport away ",0},
+        {50, "", "of slow monster ", 0},
+         {8, "", "of invisibility ",0},
+        {55, "", "of polymorph ",0},
+         {2, "", "of haste monster ",0},
+        {20, "", "of magic missile ",0},
+        {20, "", "of cancellation ",0},
+         {0, "", "of do nothing ",0},
+        {35, "", "of drain life ",0},
+        {20, "", "of cold ",0},
+        {20, "", "of fire ",0}
 };
 
 struct id id_rings[RINGS] = {
-        {250, "                                 ", "of stealth ",0},
-        {100, "                                 ", "of teleportation ", 0},
-        {255, "                                 ", "of regeneration ",0},
-        {295, "                                 ", "of slow digestion ",0},
-        {200, "                                 ", "of add strength ",0},
-        {250, "                                 ", "of sustain strength ",0},
-        {250, "                                 ", "of dexterity ",0},
-         {25, "                                 ", "of adornment ",0},
-        {300, "                                 ", "of see invisible ",0},
-        {290, "                                 ", "of maintain armor ",0},
-        {270, "                                 ", "of searching ",0},
+        {250, "", "of stealth ",0},
+        {100, "", "of teleportation ", 0},
+        {255, "", "of regeneration ",0},
+        {295, "", "of slow digestion ",0},
+        {200, "", "of add strength ",0},
+        {250, "", "of sustain strength ",0},
+        {250, "", "of dexterity ",0},
+         {25, "", "of adornment ",0},
+        {300, "", "of see invisible ",0},
+        {290, "", "of maintain armor ",0},
+        {270, "", "of searching ",0},
 };
 
+static void gr_armor(object *);
+static void gr_potion(object *);
+static void gr_scroll(object *);
+static void gr_wand(object *);
+static void gr_weapon(object *, int);
+static unsigned short gr_what_is(void);
+static void make_party(void);
+static void plant_gold(short, short, boolean);
+static void put_gold(void);
+static void rand_place(object *);
+
 void
-put_objects()
+put_objects(void)
 {
        short i, n;
        object *obj;
@@ -188,8 +196,8 @@ put_objects()
        put_gold();
 }
 
-void
-put_gold()
+static void
+put_gold(void)
 {
        short i, j;
        short row,col;
@@ -218,10 +226,8 @@ put_gold()
        }
 }
 
-void
-plant_gold(row, col, is_maze)
-       short row, col;
-       boolean is_maze;
+static void
+plant_gold(short row, short col, boolean is_maze)
 {
        object *obj;
 
@@ -233,26 +239,22 @@ plant_gold(row, col, is_maze)
                obj->quantity += obj->quantity / 2;
        }
        dungeon[row][col] |= OBJECT;
-       (void) add_to_pack(obj, &level_objects, 0);
+       (void)add_to_pack(obj, &level_objects, 0);
 }
 
 void
-place_at(obj, row, col)
-       object *obj;
-       int row, col;
+place_at(object *obj, int row, int col)
 {
        obj->row = row;
        obj->col = col;
        dungeon[row][col] |= OBJECT;
-       (void) add_to_pack(obj, &level_objects, 0);
+       (void)add_to_pack(obj, &level_objects, 0);
 }
 
 object *
-object_at(pack, row, col)
-       object *pack;
-       short row, col;
+object_at(object *pack, short row, short col)
 {
-       object *obj = (object *) 0;
+       object *obj = NULL;
 
        if (dungeon[row][col] & (MONSTER | OBJECT)) {
                obj = pack->next_object;
@@ -261,15 +263,14 @@ object_at(pack, row, col)
                        obj = obj->next_object;
                }
                if (!obj) {
-                       message("object_at(): inconsistent", 1);
+                       messagef(1, "object_at(): inconsistent");
                }
        }
        return(obj);
 }
 
 object *
-get_letter_object(ch)
-       int ch;
+get_letter_object(int ch)
 {
        object *obj;
 
@@ -282,8 +283,7 @@ get_letter_object(ch)
 }
 
 void
-free_stuff(objlist)
-       object *objlist;
+free_stuff(object *objlist)
 {
        object *obj;
 
@@ -295,11 +295,10 @@ free_stuff(objlist)
        }
 }
 
-char *
-name_of(obj)
-       object *obj;
+const char *
+name_of(const object *obj)
 {
-       char *retstring;
+       const char *retstring;
 
        switch(obj->what_is) {
        case SCROL:
@@ -353,7 +352,7 @@ name_of(obj)
 }
 
 object *
-gr_object()
+gr_object(void)
 {
        object *obj;
 
@@ -391,8 +390,8 @@ gr_object()
        return(obj);
 }
 
-unsigned short
-gr_what_is()
+static unsigned short
+gr_what_is(void)
 {
        short percent;
        unsigned short what_is;
@@ -417,9 +416,8 @@ gr_what_is()
        return(what_is);
 }
 
-void
-gr_scroll(obj)
-       object *obj;
+static void
+gr_scroll(object *obj)
 {
        short percent;
 
@@ -456,9 +454,8 @@ gr_scroll(obj)
        }
 }
 
-void
-gr_potion(obj)
-       object *obj;
+static void
+gr_potion(object *obj)
 {
        short percent;
 
@@ -497,10 +494,8 @@ gr_potion(obj)
        }
 }
 
-void
-gr_weapon(obj, assign_wk)
-       object *obj;
-       int assign_wk;
+static void
+gr_weapon(object *obj, int assign_wk)
 {
        short percent;
        short i;
@@ -511,7 +506,7 @@ gr_weapon(obj, assign_wk)
                obj->which_kind = get_rand(0, (WEAPONS - 1));
        }
        if ((obj->which_kind == ARROW) || (obj->which_kind == DAGGER) ||
-               (obj->which_kind == SHURIKEN) | (obj->which_kind == DART)) {
+               (obj->which_kind == SHURIKEN) || (obj->which_kind == DART)) {
                obj->quantity = get_rand(3, 15);
                obj->quiver = get_rand(0, 126);
        } else {
@@ -563,9 +558,8 @@ gr_weapon(obj, assign_wk)
        }
 }
 
-void
-gr_armor(obj)
-       object *obj;
+static void
+gr_armor(object *obj)
 {
        short percent;
        short blessing;
@@ -590,9 +584,8 @@ gr_armor(obj)
        }
 }
 
-void
-gr_wand(obj)
-       object *obj;
+static void
+gr_wand(object *obj)
 {
        obj->what_is = WAND;
        obj->which_kind = get_rand(0, (WANDS - 1));
@@ -600,9 +593,7 @@ gr_wand(obj)
 }
 
 void
-get_food(obj, force_ration)
-       object *obj;
-       boolean force_ration;
+get_food(object *obj, boolean force_ration)
 {
        obj->what_is = FOOD;
 
@@ -614,7 +605,7 @@ get_food(obj, force_ration)
 }
 
 void
-put_stairs()
+put_stairs(void)
 {
        short row, col;
 
@@ -623,8 +614,7 @@ put_stairs()
 }
 
 int
-get_armor_class(obj)
-       object *obj;
+get_armor_class(const object *obj)
 {
        if (obj) {
                return(obj->class + obj->d_enchant);
@@ -633,16 +623,17 @@ get_armor_class(obj)
 }
 
 object *
-alloc_object()
+alloc_object(void)
 {
        object *obj;
 
        if (free_list) {
                obj = free_list;
                free_list = free_list->next_object;
-       } else if (!(obj = (object *) md_malloc(sizeof(object)))) {
-                       message("cannot allocate object, saving game", 0);
+       } else if (!(obj = md_malloc(sizeof(object)))) {
+                       messagef(0, "cannot allocate object, saving game");
                        save_into_file(error_file);
+                       clean_up("alloc_object:  save failed");
        }
        obj->quantity = 1;
        obj->ichar = 'L';
@@ -654,15 +645,14 @@ alloc_object()
 }
 
 void
-free_object(obj)
-       object *obj;
+free_object(object *obj)
 {
        obj->next_object = free_list;
        free_list = obj;
 }
 
-void
-make_party()
+static void
+make_party(void)
 {
        short n;
 
@@ -675,7 +665,7 @@ make_party()
 }
 
 void
-show_objects()
+show_objects(void)
 {
        object *obj;
        short mc, rc, row, col;
@@ -707,14 +697,14 @@ show_objects()
 
        while (monster) {
                if (monster->m_flags & IMITATES) {
-                       mvaddch(monster->row, monster->col, (int) monster->disguise);
+                       mvaddch(monster->row, monster->col, (int)monster->disguise);
                }
                monster = monster->next_monster;
        }
 }
 
 void
-put_amulet()
+put_amulet(void)
 {
        object *obj;
 
@@ -723,9 +713,8 @@ put_amulet()
        rand_place(obj);
 }
 
-void
-rand_place(obj)
-       object *obj;
+static void
+rand_place(object *obj)
 {
        short row, col;
 
@@ -734,18 +723,18 @@ rand_place(obj)
 }
 
 void
-c_object_for_wizard()
+c_object_for_wizard(void)
 {
        short ch, max, wk;
        object *obj;
        char buf[80];
 
        max = 0;
-       if (pack_count((object *) 0) >= MAX_PACK_COUNT) {
-               message("pack full", 0);
+       if (pack_count(NULL) >= MAX_PACK_COUNT) {
+               messagef(0, "pack full");
                return;
        }
-       message("type of object?", 0);
+       messagef(0, "type of object?");
 
        while (r_index("!?:)]=/,\033", (ch = rgetchar()), 0) == -1) {
                sound_bell();
@@ -791,10 +780,10 @@ c_object_for_wizard()
        }
        if ((ch != ',') && (ch != ':')) {
 GIL:
-               if (get_input_line("which kind?", "", buf, "", 0, 1)) {
+               if (get_input_line("which kind?", "", buf, sizeof(buf), "", 0, 1)) {
                        wk = get_number(buf);
                        if ((wk >= 0) && (wk <= max)) {
-                               obj->which_kind = (unsigned short) wk;
+                               obj->which_kind = wk;
                                if (obj->what_is == RING) {
                                        gr_ring(obj, 0);
                                }
@@ -807,7 +796,7 @@ GIL:
                        return;
                }
        }
-       get_desc(obj, buf);
-       message(buf, 0);
-       (void) add_to_pack(obj, &rogue.pack, 1);
+       get_desc(obj, buf, sizeof(buf));
+       messagef(0, "%s", buf);
+       (void)add_to_pack(obj, &rogue.pack, 1);
 }