]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - rogue/use.c
Remove is_hex_str() (trying to guess if a number was hex or not). It is not
[bsdgames-darwin.git] / rogue / use.c
index cc5149401fc1b49594009dfa9332e1f78a3b5e0e..8371a6f0f5a302f9e00f3e277331b056574c828e 100644 (file)
@@ -1,6 +1,8 @@
+/*     $NetBSD: use.c,v 1.10 2009/08/12 08:44:45 dholland 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: @(#)use.c      5.3 (Berkeley) 6/1/90";*/
-static char rcsid[] = "$Id: use.c,v 1.2 1993/08/01 18:52:08 mycroft Exp $";
+#if 0
+static char sccsid[] = "@(#)use.c      8.1 (Berkeley) 5/31/93";
+#else
+__RCSID("$NetBSD: use.c,v 1.10 2009/08/12 08:44:45 dholland Exp $");
+#endif
 #endif /* not lint */
 
 /*
@@ -62,20 +64,21 @@ boolean see_invisible = 0;
 short extra_hp = 0;
 boolean detect_monster = 0;
 boolean con_mon = 0;
-char *strange_feeling = "you have a strange feeling for a moment, then it passes";
 
-extern short bear_trap;
-extern char hunger_str[];
-extern short cur_room;
-extern long level_points[];
-extern boolean being_held;
-extern char *fruit, *you_can_move_again;
-extern boolean sustain_strength;
+static const char strange_feeling[] = 
+       "you have a strange feeling for a moment, then it passes";
+
+static const char *get_ench_color(void);
+static void go_blind(void);
+static void hold_monster(void);
+static void idntfy(void);
+static void potion_heal(int);
+static void uncurse_all(void);
 
-quaff()
+void
+quaff(void)
 {
        short ch;
-       char buf[80];
        object *obj;
 
        ch = pack_letter("quaff what?", POTION);
@@ -84,17 +87,16 @@ quaff()
                return;
        }
        if (!(obj = get_letter_object(ch))) {
-               message("no such item.", 0);
+               messagef(0, "no such item.");
                return;
        }
        if (obj->what_is != POTION) {
-               message("you can't drink that", 0);
+               messagef(0, "you can't drink that");
                return;
        }
        switch(obj->which_kind) {
                case INCREASE_STRENGTH:
-                       message("you feel stronger now, what bulging muscles!",
-                       0);
+                       messagef(0, "you feel stronger now, what bulging muscles!");
                        rogue.str_current++;
                        if (rogue.str_current > rogue.str_max) {
                                rogue.str_max = rogue.str_current;
@@ -102,14 +104,14 @@ quaff()
                        break;
                case RESTORE_STRENGTH:
                        rogue.str_current = rogue.str_max;
-                       message("this tastes great, you feel warm all over", 0);
+                       messagef(0, "this tastes great, you feel warm all over");
                        break;
                case HEALING:
-                       message("you begin to feel better", 0);
+                       messagef(0, "you begin to feel better");
                        potion_heal(0);
                        break;
                case EXTRA_HEALING:
-                       message("you begin to feel much better", 0);
+                       messagef(0, "you begin to feel much better");
                        potion_heal(1);
                        break;
                case POISON:
@@ -119,27 +121,27 @@ quaff()
                                        rogue.str_current = 1;
                                }
                        }
-                       message("you feel very sick now", 0);
+                       messagef(0, "you feel very sick now");
                        if (halluc) {
                                unhallucinate();
                        }
                        break;
                case RAISE_LEVEL:
                        rogue.exp_points = level_points[rogue.exp - 1];
-                       message("you suddenly feel much more skillful", 0);
+                       messagef(0, "you suddenly feel much more skillful");
                        add_exp(1, 1);
                        break;
                case BLINDNESS:
                        go_blind();
                        break;
                case HALLUCINATION:
-                       message("oh wow, everything seems so cosmic", 0);
+                       messagef(0, "oh wow, everything seems so cosmic");
                        halluc += get_rand(500, 800);
                        break;
                case DETECT_MONSTER:
                        show_monsters();
                        if (!(level_monsters.next_monster)) {
-                               message(strange_feeling, 0);
+                               messagef(0, "%s", strange_feeling);
                        }
                        break;
                case DETECT_OBJECTS:
@@ -148,29 +150,29 @@ quaff()
                                        show_objects();
                                }
                        } else {
-                               message(strange_feeling, 0);
+                               messagef(0, "%s", strange_feeling);
                        }
                        break;
                case CONFUSION:
-                       message((halluc ? "what a trippy feeling" :
-                       "you feel confused"), 0);
+                       messagef(0, (halluc ? "what a trippy feeling" :
+                       "you feel confused"));
                        cnfs();
                        break;
                case LEVITATION:
-                       message("you start to float in the air", 0);
+                       messagef(0, "you start to float in the air");
                        levitate += get_rand(15, 30);
                        being_held = bear_trap = 0;
                        break;
                case HASTE_SELF:
-                       message("you feel yourself moving much faster", 0);
+                       messagef(0, "you feel yourself moving much faster");
                        haste_self += get_rand(11, 21);
                        if (!(haste_self % 2)) {
                                haste_self++;
                        }
                        break;
                case SEE_INVISIBLE:
-                       sprintf(buf, "hmm, this potion tastes like %sjuice", fruit);
-                       message(buf, 0);
+                       messagef(0, "hmm, this potion tastes like %sjuice",
+                                fruit);
                        if (blind) {
                                unblind();
                        }
@@ -185,11 +187,11 @@ quaff()
        vanish(obj, 1, &rogue.pack);
 }
 
-read_scroll()
+void
+read_scroll(void)
 {
        short ch;
        object *obj;
-       char msg[DCOLS];
 
        ch = pack_letter("read what?", SCROL);
 
@@ -197,17 +199,16 @@ read_scroll()
                return;
        }
        if (!(obj = get_letter_object(ch))) {
-               message("no such item.", 0);
+               messagef(0, "no such item.");
                return;
        }
        if (obj->what_is != SCROL) {
-               message("you can't read that", 0);
+               messagef(0, "you can't read that");
                return;
        }
        switch(obj->which_kind) {
                case SCARE_MONSTER:
-                       message("you hear a maniacal laughter in the distance",
-                       0);
+                       messagef(0, "you hear a maniacal laughter in the distance");
                        break;
                case HOLD_MONSTER:
                        hold_monster();
@@ -215,11 +216,10 @@ read_scroll()
                case ENCH_WEAPON:
                        if (rogue.weapon) {
                                if (rogue.weapon->what_is == WEAPON) {
-                                       sprintf(msg, "your %sglow%s %sfor a moment",
-                                       name_of(rogue.weapon),
-                                       ((rogue.weapon->quantity <= 1) ? "s" : ""),
-                                       get_ench_color());
-                                       message(msg, 0);
+                                       messagef(0, "your %sglow%s %sfor a moment",
+                                               name_of(rogue.weapon),
+                                               ((rogue.weapon->quantity <= 1) ? "s" : ""),
+                                               get_ench_color());
                                        if (coin_toss()) {
                                                rogue.weapon->hit_enchant++;
                                        } else {
@@ -228,23 +228,22 @@ read_scroll()
                                }
                                rogue.weapon->is_cursed = 0;
                        } else {
-                               message("your hands tingle", 0);
+                               messagef(0, "your hands tingle");
                        }
                        break;
                case ENCH_ARMOR:
                        if (rogue.armor) {
-                               sprintf(msg, "your armor glows %sfor a moment",
-                               get_ench_color());
-                               message(msg, 0);
+                               messagef(0, "your armor glows %sfor a moment",
+                                       get_ench_color());
                                rogue.armor->d_enchant++;
                                rogue.armor->is_cursed = 0;
                                print_stats(STAT_ARMOR);
                        } else {
-                               message("your skin crawls", 0);
+                               messagef(0, "your skin crawls");
                        }
                        break;
                case IDENTIFY:
-                       message("this is a scroll of identify", 0);
+                       messagef(0, "this is a scroll of identify");
                        obj->identified = 1;
                        id_scrolls[obj->which_kind].id_status = IDENTIFIED;
                        idntfy();
@@ -253,22 +252,22 @@ read_scroll()
                        tele();
                        break;
                case SLEEP:
-                       message("you fall asleep", 0);
+                       messagef(0, "you fall asleep");
                        take_a_nap();
                        break;
                case PROTECT_ARMOR:
                        if (rogue.armor) {
-                               message( "your armor is covered by a shimmering gold shield",0);
+                               messagef(0, "your armor is covered by a shimmering gold shield");
                                rogue.armor->is_protected = 1;
                                rogue.armor->is_cursed = 0;
                        } else {
-                               message("your acne seems to have disappeared", 0);
+                               messagef(0, "your acne seems to have disappeared");
                        }
                        break;
                case REMOVE_CURSE:
-                               message((!halluc) ?
+                               messagef(0, (!halluc) ?
                                        "you feel as though someone is watching over you" :
-                                       "you feel in touch with the universal oneness", 0);
+                                       "you feel in touch with the universal oneness");
                        uncurse_all();
                        break;
                case CREATE_MONSTER:
@@ -278,13 +277,13 @@ read_scroll()
                        aggravate();
                        break;
                case MAGIC_MAPPING:
-                       message("this scroll seems to have a map on it", 0);
+                       messagef(0, "this scroll seems to have a map on it");
                        draw_magic_map();
                        break;
                case CON_MON:
                        con_mon = 1;
-                       sprintf(msg, "your hands glow %sfor a moment", get_ench_color());
-                       message(msg, 0);
+                       messagef(0, "your hands glow %sfor a moment",
+                                get_ench_color());
                        break;
        }
        if (id_scrolls[obj->which_kind].id_status != CALLED) {
@@ -297,10 +296,8 @@ read_scroll()
  *  arrow (or whatever) in the quiver.  It will only decrement the count.
  */
 
-vanish(obj, rm, pack)
-object *obj;
-short rm;
-object *pack;
+void
+vanish(object *obj, short rm, object *pack)
 {
        if (obj->quantity > 1) {
                obj->quantity--;
@@ -316,11 +313,12 @@ object *pack;
                free_object(obj);
        }
        if (rm) {
-               (void) reg_move();
+               (void)reg_move();
        }
 }
 
-potion_heal(extra)
+static void
+potion_heal(int extra)
 {
        float ratio;
        short add;
@@ -344,7 +342,7 @@ potion_heal(extra)
                if (extra) {
                        ratio += ratio;
                }
-               add = (short)(ratio * ((float)rogue.hp_max - rogue.hp_current));
+               add = (short)(ratio * (rogue.hp_max - rogue.hp_current));
                rogue.hp_current += add;
                if (rogue.hp_current > rogue.hp_max) {
                        rogue.hp_current = rogue.hp_max;
@@ -354,7 +352,7 @@ potion_heal(extra)
                unblind();
        }
        if (confused && extra) {
-                       unconfuse();
+               unconfuse();
        } else if (confused) {
                confused = (confused / 2) + 1;
        }
@@ -365,7 +363,8 @@ potion_heal(extra)
        }
 }
 
-idntfy()
+static void
+idntfy(void)
 {
        short ch;
        object *obj;
@@ -378,8 +377,8 @@ AGAIN:
                return;
        }
        if (!(obj = get_letter_object(ch))) {
-               message("no such item, try again", 0);
-               message("", 0);
+               messagef(0, "no such item, try again");
+               messagef(0, "%s", "");  /* gcc objects to just "" */
                check_message();
                goto AGAIN;
        }
@@ -388,16 +387,16 @@ AGAIN:
                id_table = get_id_table(obj);
                id_table[obj->which_kind].id_status = IDENTIFIED;
        }
-       get_desc(obj, desc);
-       message(desc, 0);
+       get_desc(obj, desc, sizeof(desc));
+       messagef(0, "%s", desc);
 }
 
-eat()
+void
+eat(void)
 {
        short ch;
        short moves;
        object *obj;
-       char buf[70];
 
        ch = pack_letter("eat what?", FOOD);
 
@@ -405,24 +404,23 @@ eat()
                return;
        }
        if (!(obj = get_letter_object(ch))) {
-               message("no such item.", 0);
+               messagef(0, "no such item.");
                return;
        }
        if (obj->what_is != FOOD) {
-               message("you can't eat that", 0);
+               messagef(0, "you can't eat that");
                return;
        }
        if ((obj->which_kind == FRUIT) || rand_percent(60)) {
                moves = get_rand(950, 1150);
                if (obj->which_kind == RATION) {
-                       message("yum, that tasted good", 0);
+                       messagef(0, "yum, that tasted good");
                } else {
-                       sprintf(buf, "my, that was a yummy %s", fruit);
-                       message(buf, 0);
+                       messagef(0, "my, that was a yummy %s", fruit);
                }
        } else {
                moves = get_rand(750, 950);
-               message("yuk, that food tasted awful", 0);
+               messagef(0, "yuk, that food tasted awful");
                add_exp(2, 1);
        }
        rogue.moves_left /= 3;
@@ -433,7 +431,8 @@ eat()
        vanish(obj, 1, &rogue.pack);
 }
 
-hold_monster()
+static void
+hold_monster(void)
 {
        short i, j;
        short mcount = 0;
@@ -457,15 +456,16 @@ hold_monster()
                }
        }
        if (mcount == 0) {
-               message("you feel a strange sense of loss", 0);
+               messagef(0, "you feel a strange sense of loss");
        } else if (mcount == 1) {
-               message("the monster freezes", 0);
+               messagef(0, "the monster freezes");
        } else {
-               message("the monsters around you freeze", 0);
+               messagef(0, "the monsters around you freeze");
        }
 }
 
-tele()
+void
+tele(void)
 {
        mvaddch(rogue.row, rogue.col, get_dungeon_char(rogue.row, rogue.col));
 
@@ -477,7 +477,8 @@ tele()
        bear_trap = 0;
 }
 
-hallucinate()
+void
+hallucinate(void)
 {
        object *obj, *monster;
        short ch;
@@ -506,17 +507,19 @@ hallucinate()
        }
 }
 
-unhallucinate()
+void
+unhallucinate(void)
 {
        halluc = 0;
        relight();
-       message("everything looks SO boring now", 1);
+       messagef(1, "everything looks SO boring now");
 }
 
-unblind()
+void
+unblind(void)
 {
        blind = 0;
-       message("the veil of darkness lifts", 1);
+       messagef(1, "the veil of darkness lifts");
        relight();
        if (halluc) {
                hallucinate();
@@ -526,7 +529,8 @@ unblind()
        }
 }
 
-relight()
+void
+relight(void)
 {
        if (cur_room == PASSAGE) {
                light_passage(rogue.row, rogue.col);
@@ -536,7 +540,8 @@ relight()
        mvaddch(rogue.row, rogue.col, rogue.fchar);
 }
 
-take_a_nap()
+void
+take_a_nap(void)
 {
        short i;
 
@@ -547,15 +552,16 @@ take_a_nap()
                mv_mons();
        }
        md_sleep(1);
-       message(you_can_move_again, 0);
+       messagef(0, "%s", you_can_move_again);
 }
 
-go_blind()
+static void
+go_blind(void)
 {
        short i, j;
 
        if (!blind) {
-               message("a cloak of darkness falls around you", 0);
+               messagef(0, "a cloak of darkness falls around you");
        }
        blind += get_rand(500, 800);
 
@@ -581,32 +587,32 @@ go_blind()
        mvaddch(rogue.row, rogue.col, rogue.fchar);
 }
 
-char *
-get_ench_color()
+static const char *
+get_ench_color(void)
 {
        if (halluc) {
                return(id_potions[get_rand(0, POTIONS-1)].title);
        } else if (con_mon) {
                return("red ");
-       } 
+       }
        return("blue ");
 }
 
-cnfs()
+void
+cnfs(void)
 {
        confused += get_rand(12, 22);
 }
 
-unconfuse()
+void
+unconfuse(void)
 {
-       char msg[80];
-
        confused = 0;
-       sprintf(msg, "you feel less %s now", (halluc ? "trippy" : "confused"));
-       message(msg, 1);
+       messagef(1, "you feel less %s now", (halluc ? "trippy" : "confused"));
 }
 
-uncurse_all()
+static void
+uncurse_all(void)
 {
        object *obj;