X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/00b8e31689c6400d8ad915067f021b8e246df989..a1069e498ca56abe42d4eac4a400365139b361cc:/hack/hack.dog.c diff --git a/hack/hack.dog.c b/hack/hack.dog.c index 5a8ebfb3..a76e7ffe 100644 --- a/hack/hack.dog.c +++ b/hack/hack.dog.c @@ -1,12 +1,69 @@ -/* $NetBSD: hack.dog.c,v 1.5 2001/03/25 20:43:59 jsm Exp $ */ +/* $NetBSD: hack.dog.c,v 1.12 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.dog.c,v 1.5 2001/03/25 20:43:59 jsm Exp $"); +__RCSID("$NetBSD: hack.dog.c,v 1.12 2011/08/07 06:03:45 dholland Exp $"); #endif /* not lint */ #include "hack.h" @@ -22,9 +79,11 @@ const struct permonst dog = const struct permonst la_dog = {"large dog", 'd', 6, 15, 4, 2, 4, sizeof(struct edog)}; +static void initedog(struct monst *); +static int dogfood(struct obj *); void -makedog() +makedog(void) { struct monst *mtmp = makemon(&li_dog, u.ux, u.uy); if (!mtmp) @@ -32,9 +91,8 @@ makedog() initedog(mtmp); } -void -initedog(mtmp) - struct monst *mtmp; +static void +initedog(struct monst *mtmp) { mtmp->mtame = mtmp->mpeaceful = 1; EDOG(mtmp)->hungrytime = 1000 + moves; @@ -51,7 +109,7 @@ struct monst *fallen_down = 0;/* monsters that fell through a trapdoor */ /* they will appear on the next level @ goes to, even if he goes up! */ void -losedogs() +losedogs(void) { struct monst *mtmp; while ((mtmp = mydogs) != NULL) { @@ -69,7 +127,7 @@ losedogs() } void -keepdogs() +keepdogs(void) { struct monst *mtmp; for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) @@ -86,8 +144,7 @@ keepdogs() } void -fall_down(mtmp) - struct monst *mtmp; +fall_down(struct monst *mtmp) { relmon(mtmp); mtmp->nmon = fallen_down; @@ -104,9 +161,8 @@ fall_down(mtmp) #define APPORT 4 #define POISON 5 #define UNDEF 6 -int -dogfood(obj) - struct obj *obj; +static int +dogfood(struct obj *obj) { switch (obj->olet) { case FOOD_SYM: @@ -121,7 +177,7 @@ dogfood(obj) default: if (!obj->cursed) return (APPORT); - /* fall into next case */ + /* FALLTHROUGH */ case BALL_SYM: case CHAIN_SYM: case ROCK_SYM: @@ -182,7 +238,7 @@ dog_move(struct monst *mtmp, int after) /* Note: if apport == 1 then our behaviour is independent of udist */ if (mtmp->minvent) { if (!rn2(udist) || !rn2((int) edog->apport)) - if (rn2(10) < edog->apport) { + if ((unsigned) rn2(10) < edog->apport) { relobj(mtmp, (int) mtmp->minvis); if (edog->apport > 1) edog->apport--; @@ -198,7 +254,7 @@ dog_move(struct monst *mtmp, int after) goto eatobj; } if (obj->owt < 10 * mtmp->data->mlevel) - if (rn2(20) < edog->apport + 3) + if ((unsigned) rn2(20) < edog->apport + 3) if (rn2(udist) || !rn2((int) edog->apport)) { freeobj(obj); unpobj(obj); @@ -234,7 +290,7 @@ dog_move(struct monst *mtmp, int after) } } else if (gtyp == UNDEF && dogroom >= 0 && uroom == dogroom && - !mtmp->minvent && edog->apport > rn2(8)) { + !mtmp->minvent && edog->apport > (unsigned)rn2(8)) { gx = obj->ox; gy = obj->oy; gtyp = APPORT; @@ -309,6 +365,8 @@ dog_move(struct monst *mtmp, int after) ny = poss[i].y; if (info[i] & ALLOW_M) { mtmp2 = m_at(nx, ny); + if (mtmp2 == NULL) + panic("error in dog_move"); if (mtmp2->data->mlevel >= mdat->mlevel + 2 || mtmp2->data->mlet == 'c') continue; @@ -414,25 +472,23 @@ newdogpos: /* return roomnumber or -1 */ int -inroom(x, y) - xchar x, y; +inroom(xchar x, xchar y) { #ifndef QUEST - struct mkroom *croom = &rooms[0]; - while (croom->hx >= 0) { - if (croom->hx >= x - 1 && croom->lx <= x + 1 && - croom->hy >= y - 1 && croom->ly <= y + 1) - return (croom - rooms); - croom++; + int pos = 0; + + while (rooms[pos].hx >= 0) { + if (rooms[pos].hx >= x - 1 && rooms[pos].lx <= x + 1 && + rooms[pos].hy >= y - 1 && rooms[pos].ly <= y + 1) + return pos; + pos++; } #endif /* QUEST */ return (-1); /* not in room or on door */ } int -tamedog(mtmp, obj) - struct monst *mtmp; - struct obj *obj; +tamedog(struct monst *mtmp, struct obj *obj) { struct monst *mtmp2;