X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/84e7d0704483ce39bbdeacd5e676168db6fa664f..d83ae3073815d24b7f25631da96992bf92984230:/hack/hack.mon.c diff --git a/hack/hack.mon.c b/hack/hack.mon.c index df37d3a9..8dd587ec 100644 --- a/hack/hack.mon.c +++ b/hack/hack.mon.c @@ -1,12 +1,69 @@ -/* $NetBSD: hack.mon.c,v 1.4 1997/10/19 16:58:34 christos Exp $ */ +/* $NetBSD: hack.mon.c,v 1.14 2011/08/07 06:03:45 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 + * 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 #ifndef lint -__RCSID("$NetBSD: hack.mon.c,v 1.4 1997/10/19 16:58:34 christos Exp $"); +__RCSID("$NetBSD: hack.mon.c,v 1.14 2011/08/07 06:03:45 dholland Exp $"); #endif /* not lint */ #include @@ -14,19 +71,22 @@ __RCSID("$NetBSD: hack.mon.c,v 1.4 1997/10/19 16:58:34 christos Exp $"); #include "extern.h" #include "hack.mfndpos.h" -#ifndef NULL -#define NULL (char *) 0 -#endif +static int warnlevel; /* used by movemon and dochugw */ +static long lastwarntime; +static int lastwarnlev; -int warnlevel; /* used by movemon and dochugw */ -long lastwarntime; -int lastwarnlev; -char *warnings[] = { +static const char *const warnings[] = { "white", "pink", "red", "ruby", "purple", "black" }; +static int dochugw(struct monst *); +static void mpickgold(struct monst *); +static void mpickgems(struct monst *); +static void dmonsfree(void); +static int ishuman(struct monst *); + void -movemon() +movemon(void) { struct monst *mtmp; int fr; @@ -93,7 +153,7 @@ next_mon: warnlevel = SIZE(warnings) - 1; if (warnlevel >= 0) if (warnlevel > lastwarnlev || moves > lastwarntime + 5) { - char *rr; + const char *rr; switch (Warning & (LEFT_RING | RIGHT_RING)) { case LEFT_RING: rr = "Your left ring glows"; @@ -116,9 +176,7 @@ next_mon: } void -justswld(mtmp, name) - struct monst *mtmp; - char *name; +justswld(struct monst *mtmp, const char *name) { mtmp->mx = u.ux; @@ -134,10 +192,7 @@ justswld(mtmp, name) } void -youswld(mtmp, dam, die, name) - struct monst *mtmp; - int dam, die; - char *name; +youswld(struct monst *mtmp, int dam, unsigned int die, const char *name) { if (mtmp != u.ustuck) return; @@ -154,15 +209,15 @@ youswld(mtmp, dam, die, name) #endif } -int -dochugw(mtmp) - struct monst *mtmp; +static int +dochugw(struct monst *mtmp) { int x = mtmp->mx; int y = mtmp->my; - int d = dochug(mtmp); + int dead = dochug(mtmp); int dd; - if (!d) /* monster still alive */ + + if (!dead) /* monster still alive */ if (Warning) if (!mtmp->mpeaceful) if (mtmp->data->mlevel > warnlevel) @@ -170,15 +225,14 @@ dochugw(mtmp) if (dd < 100) if (!canseemon(mtmp)) warnlevel = mtmp->data->mlevel; - return (d); + return (dead); } /* returns 1 if monster died moving, 0 otherwise */ int -dochug(mtmp) - struct monst *mtmp; +dochug(struct monst *mtmp) { - struct permonst *mdat; + const struct permonst *mdat; int tmp = 0, nearby, scared; if (mtmp->cham && !rn2(6)) @@ -260,8 +314,7 @@ dochug(mtmp) } int -m_move(mtmp, after) - struct monst *mtmp; +m_move(struct monst *mtmp, int after) { struct monst *mtmp2; int nx, ny, omx, omy, appr, nearer, cnt, i, j; @@ -444,6 +497,8 @@ nxti: ; if (mmoved) { if (info[chi] & ALLOW_M) { mtmp2 = m_at(nix, niy); + if (mtmp2 == NULL) + panic("error in m_move"); if (hitmm(mtmp, mtmp2) == 1 && rn2(4) && hitmm(mtmp2, mtmp) == 2) return (2); @@ -488,9 +543,8 @@ postmov: return (mmoved); } -void -mpickgold(mtmp) - struct monst *mtmp; +static void +mpickgold(struct monst *mtmp) { struct gold *gold; while ((gold = g_at(mtmp->mx, mtmp->my)) != NULL) { @@ -501,9 +555,8 @@ mpickgold(mtmp) } } -void -mpickgems(mtmp) - struct monst *mtmp; +static void +mpickgems(struct monst *mtmp) { struct obj *otmp; for (otmp = fobj; otmp; otmp = otmp->nobj) @@ -520,10 +573,7 @@ mpickgems(mtmp) /* return number of acceptable neighbour positions */ int -mfndpos(mon, poss, info, flag) - struct monst *mon; - coord poss[9]; - int info[9], flag; +mfndpos(struct monst *mon, coord poss[9], int info[9], int flag) { int x, y, nx, ny, cnt = 0, ntyp; struct monst *mtmp; @@ -615,15 +665,13 @@ nexttry: /* eels prefer the water, but if there is no } int -dist(x, y) - int x, y; +dist(int x, int y) { return ((x - u.ux) * (x - u.ux) + (y - u.uy) * (y - u.uy)); } void -poisoned(string, pname) - char *string, *pname; +poisoned(const char *string, const char *pname) { int i; @@ -651,8 +699,7 @@ poisoned(string, pname) } void -mondead(mtmp) - struct monst *mtmp; +mondead(struct monst *mtmp) { relobj(mtmp, 1); unpmon(mtmp); @@ -671,8 +718,7 @@ mondead(mtmp) /* called when monster is moved to larger structure */ void -replmon(mtmp, mtmp2) - struct monst *mtmp, *mtmp2; +replmon(struct monst *mtmp, struct monst *mtmp2) { relmon(mtmp); monfree(mtmp); @@ -687,8 +733,7 @@ replmon(mtmp, mtmp2) } void -relmon(mon) - struct monst *mon; +relmon(struct monst *mon) { struct monst *mtmp; @@ -704,30 +749,28 @@ relmon(mon) * we do not free monsters immediately, in order to have their name available * shortly after their demise */ -struct monst *fdmon; /* chain of dead monsters, need not to be +static struct monst *fdmon; /* chain of dead monsters, need not to be * saved */ void -monfree(mtmp) - struct monst *mtmp; +monfree(struct monst *mtmp) { mtmp->nmon = fdmon; fdmon = mtmp; } -void -dmonsfree() +static void +dmonsfree(void) { struct monst *mtmp; while ((mtmp = fdmon) != NULL) { fdmon = mtmp->nmon; - free((char *) mtmp); + free(mtmp); } } void -unstuck(mtmp) - struct monst *mtmp; +unstuck(struct monst *mtmp) { if (u.ustuck == mtmp) { if (u.uswallow) { @@ -742,14 +785,13 @@ unstuck(mtmp) } void -killed(mtmp) - struct monst *mtmp; +killed(struct monst *mtmp) { #ifdef lint #define NEW_SCORING #endif /* lint */ int tmp, nk, x, y; - struct permonst *mdat; + const struct permonst *mdat; if (mtmp->cham) mtmp->data = PM_CHAMELEON; @@ -806,6 +848,7 @@ killed(mtmp) { int ul = u.ulevel; int ml = mdat->mlevel; + int tmp2; if (ul < 14) /* points are given based on present and * future level */ @@ -869,8 +912,7 @@ killed(mtmp) } void -kludge(str, arg) - char *str, *arg; +kludge(const char *str, const char *arg) { if (Blind) { if (*str == '%') @@ -882,7 +924,7 @@ kludge(str, arg) } void -rescham() +rescham(void) { /* force all chameleons to become normal */ struct monst *mtmp; @@ -893,11 +935,10 @@ rescham() } } -int -newcham(mtmp, mdat) /* make a chameleon look like a new monster */ +/* make a chameleon look like a new monster */ /* returns 1 if the monster actually changed */ - struct monst *mtmp; - struct permonst *mdat; +int +newcham(struct monst *mtmp, const struct permonst *mdat) { int mhp, hpn, hpd; @@ -938,10 +979,9 @@ newcham(mtmp, mdat) /* make a chameleon look like a new monster */ return (1); } +/* Make monster mtmp next to you (if possible) */ void -mnexto(mtmp) /* Make monster mtmp next to you (if - * possible) */ - struct monst *mtmp; +mnexto(struct monst *mtmp) { coord mm; mm = enexto(u.ux, u.uy); @@ -950,16 +990,14 @@ mnexto(mtmp) /* Make monster mtmp next to you (if pmon(mtmp); } -int -ishuman(mtmp) - struct monst *mtmp; +static int +ishuman(struct monst *mtmp) { return (mtmp->data->mlet == '@'); } void -setmangry(mtmp) - struct monst *mtmp; +setmangry(struct monst *mtmp) { if (!mtmp->mpeaceful) return; @@ -975,8 +1013,7 @@ setmangry(mtmp) * object */ int -canseemon(mtmp) - struct monst *mtmp; +canseemon(struct monst *mtmp) { return ((!mtmp->minvis || See_invisible) && (!mtmp->mhide || !o_at(mtmp->mx, mtmp->my))