]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - rogue/hit.c
I was disappointed that someone wrote disappointed with two 's', so I fixed it.
[bsdgames-darwin.git] / rogue / hit.c
index e796f4ad70307f5e886b73f7de68cab82abe2516..9d27c1fece7be22533a92b8f01d98ab3ec166070 100644 (file)
@@ -1,4 +1,4 @@
-/*     $NetBSD: hit.c,v 1.4 1997/10/12 11:45:05 lukem Exp $    */
+/*     $NetBSD: hit.c,v 1.10 2008/01/14 03:50:01 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[] = "@(#)hit.c      8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: hit.c,v 1.4 1997/10/12 11:45:05 lukem Exp $");
+__RCSID("$NetBSD: hit.c,v 1.10 2008/01/14 03:50:01 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -59,15 +55,18 @@ __RCSID("$NetBSD: hit.c,v 1.4 1997/10/12 11:45:05 lukem Exp $");
 
 #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 *);
+
+static object *fight_monster = NULL;
+char hit_message[HIT_MESSAGE_SIZE] = "";
 
 void
-mon_hit(monster)
-       object *monster;
+mon_hit(object *monster)
 {
        short damage, hit_chance;
-       char *mn;
+       const char *mn;
        float minus;
 
        if (fight_monster && (monster != fight_monster)) {
@@ -90,27 +89,24 @@ mon_hit(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++;
        }
@@ -126,9 +122,7 @@ mon_hit(monster)
 }
 
 void
-rogue_hit(monster, force_hit)
-       object *monster;
-       boolean force_hit;
+rogue_hit(object *monster, boolean force_hit)
 {
        short damage, hit_chance;
 
@@ -143,7 +137,8 @@ rogue_hit(monster, 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;
                }
@@ -156,7 +151,8 @@ rogue_hit(monster, 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);
@@ -165,10 +161,7 @@ RET:       check_gold_seeker(monster);
 }
 
 void
-rogue_damage(d, monster, other)
-       short d;
-       object *monster;
-       short other;
+rogue_damage(short d, object *monster, short other)
 {
        if (d >= rogue.hp_current) {
                rogue.hp_current = 0;
@@ -182,17 +175,26 @@ rogue_damage(d, monster, other)
 }
 
 int
-get_damage(ds, r)
-       char *ds;
-       boolean r;
+get_damage(const char *ds, boolean r)
 {
        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) {
@@ -201,36 +203,37 @@ get_damage(ds, r)
                                total += d;
                        }
                }
-               if (ds[i] == '/') {
-                       i++;
-               }
        }
        return(total);
 }
 
-int
-get_w_damage(obj)
-       object *obj;
+static int
+get_w_damage(const object *obj)
 {
-       char new_damage[12];
-       int to_hit, damage;
+       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));
 }
 
 int
-get_number(s)
-       char *s;
+get_number(const char *s)
 {
        int i = 0;
        int total = 0;
@@ -243,8 +246,7 @@ get_number(s)
 }
 
 long
-lget_number(s)
-       char *s;
+lget_number(const char *s)
 {
        short i = 0;
        long total = 0;
@@ -256,9 +258,8 @@ lget_number(s)
        return(total);
 }
 
-int
-to_hit(obj)
-       object *obj;
+static int
+to_hit(const object *obj)
 {
        if (!obj) {
                return(1);
@@ -266,8 +267,8 @@ to_hit(obj)
        return(get_number(obj->damage) + obj->hit_enchant);
 }
 
-int
-damage_for_strength()
+static int
+damage_for_strength(void)
 {
        short strength;
 
@@ -298,11 +299,9 @@ damage_for_strength()
 }
 
 int
-mon_damage(monster, damage)
-       object *monster;
-       short damage;
+mon_damage(object *monster, short damage)
 {
-       char *mn;
+       const char *mn;
        short row, col;
 
        monster->hp_to_kill -= damage;
@@ -311,13 +310,12 @@ mon_damage(monster, 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);
@@ -332,8 +330,7 @@ mon_damage(monster, damage)
 }
 
 void
-fight(to_the_death)
-       boolean to_the_death;
+fight(boolean to_the_death)
 {
        short ch, c, d;
        short row, col;
@@ -345,7 +342,7 @@ fight(to_the_death)
        while (!is_direction(ch = rgetchar(), &d)) {
                sound_bell();
                if (first_miss) {
-                       message("direction?", 0);
+                       messagef(0, "direction?");
                        first_miss = 0;
                }
        }
@@ -359,7 +356,7 @@ fight(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))) {
@@ -371,7 +368,7 @@ fight(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;
@@ -385,10 +382,7 @@ fight(to_the_death)
 }
 
 void
-get_dir_rc(dir, row, col, allow_off_screen)
-       short dir;
-       short *row, *col;
-       short allow_off_screen;
+get_dir_rc(short dir, short *row, short *col, short allow_off_screen)
 {
        switch(dir) {
        case LEFT:
@@ -439,8 +433,7 @@ get_dir_rc(dir, row, col, allow_off_screen)
 }
 
 int
-get_hit_chance(weapon)
-       object *weapon;
+get_hit_chance(const object *weapon)
 {
        short hit_chance;
 
@@ -451,8 +444,7 @@ get_hit_chance(weapon)
 }
 
 int
-get_weapon_damage(weapon)
-       object *weapon;
+get_weapon_damage(const object *weapon)
 {
        short damage;
 
@@ -463,13 +455,12 @@ get_weapon_damage(weapon)
 }
 
 void
-s_con_mon(monster)
-       object *monster;
+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;
        }
 }