]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - rogue/hit.c
countmail: remove outdated comments
[bsdgames-darwin.git] / rogue / hit.c
index b83e6c596e0293539bef1498909751acc444c77d..9d27c1fece7be22533a92b8f01d98ab3ec166070 100644 (file)
@@ -1,6 +1,8 @@
+/*     $NetBSD: hit.c,v 1.10 2008/01/14 03:50:01 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[] = "@(#)hit.c      5.3 (Berkeley) 6/1/90";
+#if 0
+static char sccsid[] = "@(#)hit.c      8.1 (Berkeley) 5/31/93";
+#else
+__RCSID("$NetBSD: hit.c,v 1.10 2008/01/14 03:50:01 dholland Exp $");
+#endif
 #endif /* not lint */
 
 /*
@@ -52,18 +55,18 @@ static char sccsid[] = "@(#)hit.c   5.3 (Berkeley) 6/1/90";
 
 #include "rogue.h"
 
-object *fight_monster = 0;
-char hit_message[80] = "";
+static int damage_for_strength(void);
+static int get_w_damage(const object *);
+static int to_hit(const object *);
 
-extern short halluc, blind, cur_level;
-extern short add_strength, ring_exp, r_rings;
-extern boolean being_held, interrupted, wizard, con_mon;
+static object *fight_monster = NULL;
+char hit_message[HIT_MESSAGE_SIZE] = "";
 
-mon_hit(monster)
-register object *monster;
+void
+mon_hit(object *monster)
 {
        short damage, hit_chance;
-       char *mn;
+       const char *mn;
        float minus;
 
        if (fight_monster && (monster != fight_monster)) {
@@ -86,26 +89,24 @@ register object *monster;
 
        if (!rand_percent(hit_chance)) {
                if (!fight_monster) {
-                       sprintf(hit_message + strlen(hit_message), "the %s misses", mn);
-                       message(hit_message, 1);
+                       messagef(1, "%sthe %s misses", hit_message, mn);
                        hit_message[0] = 0;
                }
                return;
        }
        if (!fight_monster) {
-               sprintf(hit_message + strlen(hit_message), "the %s hit", mn);
-               message(hit_message, 1);
+               messagef(1, "%sthe %s hit", hit_message, mn);
                hit_message[0] = 0;
        }
        if (!(monster->m_flags & STATIONARY)) {
                damage = get_damage(monster->m_damage, 1);
                if (cur_level >= (AMULET_LEVEL * 2)) {
-                       minus = (float) ((AMULET_LEVEL * 2) - cur_level);
+                       minus = (float)((AMULET_LEVEL * 2) - cur_level);
                } else {
-                       minus = (float) get_armor_class(rogue.armor) * 3.00;
-                       minus = minus/100.00 * (float) damage;
+                       minus = (float)get_armor_class(rogue.armor) * 3.00;
+                       minus = minus/100.00 * (float)damage;
                }
-               damage -= (short) minus;
+               damage -= (short)minus;
        } else {
                damage = monster->stationary_damage++;
        }
@@ -120,9 +121,8 @@ register object *monster;
        }
 }
 
-rogue_hit(monster, force_hit)
-register object *monster;
-boolean force_hit;
+void
+rogue_hit(object *monster, boolean force_hit)
 {
        short damage, hit_chance;
 
@@ -137,7 +137,8 @@ boolean force_hit;
                }
                if (!rand_percent(hit_chance)) {
                        if (!fight_monster) {
-                               (void) strcpy(hit_message, "you miss  ");
+                               (void)strlcpy(hit_message, "you miss  ",
+                                              sizeof(hit_message));
                        }
                        goto RET;
                }
@@ -150,7 +151,8 @@ boolean force_hit;
                }
                if (mon_damage(monster, damage)) {      /* still alive? */
                        if (!fight_monster) {
-                               (void) strcpy(hit_message, "you hit  ");
+                               (void)strlcpy(hit_message, "you hit  ",
+                                              sizeof(hit_message));
                        }
                }
 RET:   check_gold_seeker(monster);
@@ -158,10 +160,8 @@ RET:       check_gold_seeker(monster);
        }
 }
 
-rogue_damage(d, monster, other)
-short d;
-object *monster;
-short other;
+void
+rogue_damage(short d, object *monster, short other)
 {
        if (d >= rogue.hp_current) {
                rogue.hp_current = 0;
@@ -174,17 +174,27 @@ short other;
        }
 }
 
-get_damage(ds, r)
-char *ds;
-boolean r;
+int
+get_damage(const char *ds, boolean r)
 {
-       register i = 0, j, n, d, total = 0;
+       int i = 0, j, n, d, total = 0;
 
        while (ds[i]) {
                n = get_number(ds+i);
-               while (ds[i++] != 'd') ;
+               while ((ds[i] != 'd') && ds[i]) {
+                       i++;
+               }
+               if (ds[i] == 'd') {
+                       i++;
+               }
+
                d = get_number(ds+i);
-               while ((ds[i] != '/') && ds[i]) i++;
+               while ((ds[i] != '/') && ds[i]) {
+                       i++;
+               }
+               if (ds[i] == '/') {
+                       i++;
+               }
 
                for (j = 0; j < n; j++) {
                        if (r) {
@@ -193,37 +203,40 @@ boolean r;
                                total += d;
                        }
                }
-               if (ds[i] == '/') {
-                       i++;
-               }
        }
        return(total);
 }
 
-get_w_damage(obj)
-object *obj;
+static int
+get_w_damage(const object *obj)
 {
-       char new_damage[12];
-       register to_hit, damage;
-       register i = 0;
+       char new_damage[32];
+       int tmp_to_hit, tmp_damage;
+       int i = 0;
 
        if ((!obj) || (obj->what_is != WEAPON)) {
                return(-1);
        }
-       to_hit = get_number(obj->damage) + obj->hit_enchant;
-       while (obj->damage[i++] != 'd') ;
-       damage = get_number(obj->damage + i) + obj->d_enchant;
+       tmp_to_hit = get_number(obj->damage) + obj->hit_enchant;
+       while ((obj->damage[i] != 'd') && obj->damage[i]) {
+               i++;
+       }
+       if (obj->damage[i] == 'd') {
+               i++;
+       }
+       tmp_damage = get_number(obj->damage + i) + obj->d_enchant;
 
-       sprintf(new_damage, "%dd%d", to_hit, damage);
+       snprintf(new_damage, sizeof(new_damage), "%dd%d",
+               tmp_to_hit, tmp_damage);
 
        return(get_damage(new_damage, 1));
 }
 
-get_number(s)
-register char *s;
+int
+get_number(const char *s)
 {
-       register i = 0;
-       register total = 0;
+       int i = 0;
+       int total = 0;
 
        while ((s[i] >= '0') && (s[i] <= '9')) {
                total = (10 * total) + (s[i] - '0');
@@ -233,8 +246,7 @@ register char *s;
 }
 
 long
-lget_number(s)
-char *s;
+lget_number(const char *s)
 {
        short i = 0;
        long total = 0;
@@ -246,8 +258,8 @@ char *s;
        return(total);
 }
 
-to_hit(obj)
-object *obj;
+static int
+to_hit(const object *obj)
 {
        if (!obj) {
                return(1);
@@ -255,7 +267,8 @@ object *obj;
        return(get_number(obj->damage) + obj->hit_enchant);
 }
 
-damage_for_strength()
+static int
+damage_for_strength(void)
 {
        short strength;
 
@@ -285,11 +298,10 @@ damage_for_strength()
        return(8);
 }
 
-mon_damage(monster, damage)
-object *monster;
-short damage;
+int
+mon_damage(object *monster, short damage)
 {
-       char *mn;
+       const char *mn;
        short row, col;
 
        monster->hp_to_kill -= damage;
@@ -298,13 +310,12 @@ short damage;
                row = monster->row;
                col = monster->col;
                dungeon[row][col] &= ~MONSTER;
-               mvaddch(row, col, (int) get_dungeon_char(row, col));
+               mvaddch(row, col, get_dungeon_char(row, col));
 
                fight_monster = 0;
                cough_up(monster);
                mn = mon_name(monster);
-               sprintf(hit_message+strlen(hit_message), "defeated the %s", mn);
-               message(hit_message, 1);
+               messagef(1, "%sdefeated the %s", hit_message, mn);
                hit_message[0] = 0;
                add_exp(monster->kill_exp, 1);
                take_from_pack(monster, &level_monsters);
@@ -318,8 +329,8 @@ short damage;
        return(1);
 }
 
-fight(to_the_death)
-boolean to_the_death;
+void
+fight(boolean to_the_death)
 {
        short ch, c, d;
        short row, col;
@@ -327,10 +338,11 @@ boolean to_the_death;
        short possible_damage;
        object *monster;
 
+       ch = 0;
        while (!is_direction(ch = rgetchar(), &d)) {
                sound_bell();
                if (first_miss) {
-                       message("direction?", 0);
+                       messagef(0, "direction?");
                        first_miss = 0;
                }
        }
@@ -344,7 +356,7 @@ boolean to_the_death;
        c = mvinch(row, col);
        if (((c < 'A') || (c > 'Z')) ||
                (!can_move(rogue.row, rogue.col, row, col))) {
-               message("I see no monster there", 0);
+               messagef(0, "I see no monster there");
                return;
        }
        if (!(fight_monster = object_at(&level_monsters, row, col))) {
@@ -356,7 +368,7 @@ boolean to_the_death;
                possible_damage = fight_monster->stationary_damage - 1;
        }
        while (fight_monster) {
-               (void) one_move_rogue(ch, 0);
+               (void)one_move_rogue(ch, 0);
                if (((!to_the_death) && (rogue.hp_current <= possible_damage)) ||
                        interrupted || (!(dungeon[row][col] & MONSTER))) {
                        fight_monster = 0;
@@ -369,10 +381,8 @@ boolean to_the_death;
        }
 }
 
-get_dir_rc(dir, row, col, allow_off_screen)
-short dir;
-short *row, *col;
-short allow_off_screen;
+void
+get_dir_rc(short dir, short *row, short *col, short allow_off_screen)
 {
        switch(dir) {
        case LEFT:
@@ -422,8 +432,8 @@ short allow_off_screen;
        }
 }
 
-get_hit_chance(weapon)
-object *weapon;
+int
+get_hit_chance(const object *weapon)
 {
        short hit_chance;
 
@@ -433,8 +443,8 @@ object *weapon;
        return(hit_chance);
 }
 
-get_weapon_damage(weapon)
-object *weapon;
+int
+get_weapon_damage(const object *weapon)
 {
        short damage;
 
@@ -444,13 +454,13 @@ object *weapon;
        return(damage);
 }
 
-s_con_mon(monster)
-object *monster;
+void
+s_con_mon(object *monster)
 {
        if (con_mon) {
                monster->m_flags |= CONFUSED;
                monster->moves_confused += get_rand(12, 22);
-               message("the monster appears confused", 0);
+               messagef(0, "the monster appears confused");
                con_mon = 0;
        }
 }