-/* $NetBSD: hack.fight.c,v 1.4 1997/10/19 16:58:00 christos Exp $ */
+/* $NetBSD: hack.fight.c,v 1.12 2009/08/12 07:28:40 dholland Exp $ */
/*
- * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
+ * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
+ * Amsterdam
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - 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.
+ *
+ * - Neither the name of the Stichting Centrum voor Wiskunde en
+ * Informatica, nor the names of its contributors may be used to endorse or
+ * promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 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. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: hack.fight.c,v 1.4 1997/10/19 16:58:00 christos Exp $");
+__RCSID("$NetBSD: hack.fight.c,v 1.12 2009/08/12 07:28:40 dholland Exp $");
#endif /* not lint */
#include "hack.h"
static boolean far_noise;
static long noisetime;
+static void monstone(struct monst *);
+
/* hitmm returns 0 (miss), 1 (hit), or 2 (kill) */
int
-hitmm(magr, mdef)
- struct monst *magr, *mdef;
+hitmm(struct monst *magr, struct monst *mdef)
{
- struct permonst *pa = magr->data, *pd = mdef->data;
- int hit;
+ const struct permonst *pa = magr->data, *pd = mdef->data;
+ int didhit;
schar tmp;
boolean vis;
+
if (strchr("Eauy", pa->mlet))
return (0);
if (magr->mfroz)
if (mdef->msleep)
mdef->msleep = 0;
}
- hit = (tmp > rnd(20));
- if (hit)
+ didhit = (tmp > rnd(20));
+ if (didhit)
mdef->msleep = 0;
vis = (cansee(magr->mx, magr->my) && cansee(mdef->mx, mdef->my));
if (vis) {
seemimic(mdef);
if (magr->mimic)
seemimic(magr);
- (void) sprintf(buf, "%s %s", Monnam(magr),
- hit ? "hits" : "misses");
+ (void) snprintf(buf, sizeof(buf), "%s %s", Monnam(magr),
+ didhit ? "hits" : "misses");
pline("%s %s.", buf, monnam(mdef));
} else {
boolean far = (dist(magr->mx, magr->my) > 15);
far ? " in the distance" : "");
}
}
- if (hit) {
+ if (didhit) {
if (magr->data->mlet == 'c' && !magr->cham) {
magr->mhpmax += 3;
if (vis)
else if (mdef->mtame)
pline("You have a peculiarly sad feeling for a moment, then it passes.");
monstone(mdef);
- hit = 2;
+ didhit = 2;
} else if ((mdef->mhp -= d(pa->damn, pa->damd)) < 1) {
magr->mhpmax += 1 + rn2(pd->mlevel + 1);
if (magr->mtame && magr->mhpmax > 8 * pa->mlevel) {
else if (mdef->mtame)
pline("You have a sad feeling for a moment, then it passes.");
mondied(mdef);
- hit = 2;
+ didhit = 2;
}
}
- return (hit);
+ return (didhit);
}
/* drop (perhaps) a cadaver and remove monster */
void
-mondied(mdef)
- struct monst *mdef;
+mondied(struct monst *mdef)
{
- struct permonst *pd = mdef->data;
+ const struct permonst *pd = mdef->data;
if (letter(pd->mlet) && rn2(3)) {
(void) mkobj_at(pd->mlet, mdef->mx, mdef->my);
if (cansee(mdef->mx, mdef->my)) {
}
/* drop a rock and remove monster */
-void
-monstone(mdef)
- struct monst *mdef;
+static void
+monstone(struct monst *mdef)
{
if (strchr(mlarge, mdef->data->mlet))
mksobj_at(ENORMOUS_ROCK, mdef->mx, mdef->my);
int
-fightm(mtmp)
- struct monst *mtmp;
+fightm(struct monst *mtmp)
{
struct monst *mon;
for (mon = fmon; mon; mon = mon->nmon)
/* u is hit by sth, but not a monster */
int
-thitu(tlev, dam, name)
- int tlev, dam;
- char *name;
+thitu(int tlev, int dam, const char *name)
{
char buf[BUFSZ];
- setan(name, buf);
+
+ setan(name, buf, sizeof(buf));
if (u.uac + tlev <= rnd(20)) {
if (Blind)
pline("It misses.");
}
}
-char mlarge[] = "bCDdegIlmnoPSsTUwY',&";
+const char mlarge[] = "bCDdegIlmnoPSsTUwY',&";
+/* return TRUE if mon still alive */
boolean
-hmon(mon, obj, thrown) /* return TRUE if mon still alive */
- struct monst *mon;
- struct obj *obj;
- int thrown;
+hmon(struct monst *mon, struct obj *obj, int thrown)
{
int tmp;
boolean hittxt = FALSE;
freeinv(obj);
setworn((struct obj *) 0, obj->owornmask);
obfree(obj, (struct obj *) 0);
+ obj = NULL;
tmp++;
}
}
- if (mon->data->mlet == 'O' && obj->otyp == TWO_HANDED_SWORD &&
+ if (mon->data->mlet == 'O' && obj != NULL &&
+ obj->otyp == TWO_HANDED_SWORD &&
!strcmp(ONAME(obj), "Orcrist"))
tmp += rnd(10);
} else
mon->mfleetim += 10 * rnd(tmp);
}
if (!hittxt) {
- if (thrown)
+ if (thrown) {
/* this assumes that we cannot throw plural things */
+ if (obj == NULL)
+ panic("thrown non-object");
hit(xname(obj) /* or: objects[obj->otyp].oc_name */ ,
mon, exclam(tmp));
- else if (Blind)
+ } else if (Blind)
pline("You hit it.");
else
pline("You hit %s%s", monnam(mon), exclam(tmp));
/* try to attack; return FALSE if monster evaded */
/* u.dx and u.dy must be set */
int
-attack(mtmp)
- struct monst *mtmp;
+attack(struct monst *mtmp)
{
schar tmp;
boolean malive = TRUE;
- struct permonst *mdat;
+ const struct permonst *mdat;
mdat = mtmp->data;
u_wipe_engr(3); /* andrew@orca: prevent unlimited pick-axe