summaryrefslogtreecommitdiffstats
path: root/rogue/hit.c
diff options
context:
space:
mode:
Diffstat (limited to 'rogue/hit.c')
-rw-r--r--rogue/hit.c58
1 files changed, 35 insertions, 23 deletions
diff --git a/rogue/hit.c b/rogue/hit.c
index 33db6447..6bc74437 100644
--- a/rogue/hit.c
+++ b/rogue/hit.c
@@ -1,4 +1,4 @@
-/* $NetBSD: hit.c,v 1.7 2003/08/07 09:37:37 agc Exp $ */
+/* $NetBSD: hit.c,v 1.8 2007/12/27 23:52:59 dholland Exp $ */
/*
* Copyright (c) 1988, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)hit.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: hit.c,v 1.7 2003/08/07 09:37:37 agc Exp $");
+__RCSID("$NetBSD: hit.c,v 1.8 2007/12/27 23:52:59 dholland Exp $");
#endif
#endif /* not lint */
@@ -56,7 +56,7 @@ __RCSID("$NetBSD: hit.c,v 1.7 2003/08/07 09:37:37 agc Exp $");
#include "rogue.h"
object *fight_monster = 0;
-char hit_message[80] = "";
+char hit_message[HIT_MESSAGE_SIZE] = "";
void
mon_hit(monster)
@@ -86,16 +86,13 @@ 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)) {
@@ -139,7 +136,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;
}
@@ -152,7 +150,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);
@@ -186,9 +185,20 @@ get_damage(ds, r)
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) {
@@ -197,9 +207,6 @@ get_damage(ds, r)
total += d;
}
}
- if (ds[i] == '/') {
- i++;
- }
}
return(total);
}
@@ -208,7 +215,7 @@ int
get_w_damage(obj)
const object *obj;
{
- char new_damage[12];
+ char new_damage[32];
int tmp_to_hit, tmp_damage;
int i = 0;
@@ -216,10 +223,16 @@ get_w_damage(obj)
return(-1);
}
tmp_to_hit = get_number(obj->damage) + obj->hit_enchant;
- while (obj->damage[i++] != 'd') ;
+ 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", tmp_to_hit, tmp_damage);
+ snprintf(new_damage, sizeof(new_damage), "%dd%d",
+ tmp_to_hit, tmp_damage);
return(get_damage(new_damage, 1));
}
@@ -312,8 +325,7 @@ mon_damage(monster, damage)
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);
@@ -341,7 +353,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;
}
}
@@ -355,7 +367,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))) {
@@ -465,7 +477,7 @@ s_con_mon(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;
}
}