-/* $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.
*
#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 */
#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)) {
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++;
}
}
void
-rogue_hit(monster, force_hit)
- object *monster;
- boolean force_hit;
+rogue_hit(object *monster, boolean force_hit)
{
short damage, hit_chance;
}
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;
}
}
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);
}
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;
}
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) {
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;
}
long
-lget_number(s)
- char *s;
+lget_number(const char *s)
{
short i = 0;
long total = 0;
return(total);
}
-int
-to_hit(obj)
- object *obj;
+static int
+to_hit(const object *obj)
{
if (!obj) {
return(1);
return(get_number(obj->damage) + obj->hit_enchant);
}
-int
-damage_for_strength()
+static int
+damage_for_strength(void)
{
short 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;
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);
}
void
-fight(to_the_death)
- boolean to_the_death;
+fight(boolean to_the_death)
{
short ch, c, d;
short row, col;
while (!is_direction(ch = rgetchar(), &d)) {
sound_bell();
if (first_miss) {
- message("direction?", 0);
+ messagef(0, "direction?");
first_miss = 0;
}
}
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))) {
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;
}
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:
}
int
-get_hit_chance(weapon)
- object *weapon;
+get_hit_chance(const object *weapon)
{
short hit_chance;
}
int
-get_weapon_damage(weapon)
- object *weapon;
+get_weapon_damage(const object *weapon)
{
short damage;
}
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;
}
}