X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/00b8e31689c6400d8ad915067f021b8e246df989..4c2fca22580ba0ae4ec901cca158c5e228494265:/hack/hack.shk.c diff --git a/hack/hack.shk.c b/hack/hack.shk.c index 16634e18..7fa85b74 100644 --- a/hack/hack.shk.c +++ b/hack/hack.shk.c @@ -1,12 +1,69 @@ -/* $NetBSD: hack.shk.c,v 1.5 2001/03/25 20:44:02 jsm Exp $ */ +/* $NetBSD: hack.shk.c,v 1.14 2012/06/19 05:46:08 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.shk.c,v 1.5 2001/03/25 20:44:02 jsm Exp $"); +__RCSID("$NetBSD: hack.shk.c,v 1.14 2012/06/19 05:46:08 dholland Exp $"); #endif /* not lint */ #include @@ -14,14 +71,15 @@ __RCSID("$NetBSD: hack.shk.c,v 1.5 2001/03/25 20:44:02 jsm Exp $"); #include "extern.h" #ifndef QUEST -static void setpaid __P((void)); -static void addupbill __P((void)); -static void findshk __P((int)); -static struct bill_x *onbill __P((struct obj *)); -static void pay __P((long, struct monst *)); -static int dopayobj __P((struct bill_x *)); -static int getprice __P((struct obj *)); -static int realhunger __P((void)); +static void setpaid(void); +static void addupbill(void); +static void findshk(int); +static struct bill_x *onbill(struct obj *); +static void pay(long, struct monst *); +static int dopayobj(struct bill_x *); +static struct obj *bp_to_obj(struct bill_x *); +static int getprice(struct obj *); +static int realhunger(void); #endif #ifdef QUEST @@ -29,73 +87,64 @@ int shlevel = 0; struct monst *shopkeeper = 0; struct obj *billobjs = 0; void -obfree(obj, merge) - struct obj *obj, *merge; +obfree(struct obj *obj, struct obj *merge) { - free((char *) obj); + free(obj); } int -inshop() { +inshop(void) { return (0); } void -shopdig(n) - int n; +shopdig(int n) { } void -addtobill(obj) - struct obj *obj; +addtobill(struct obj *obj) { } void -subfrombill(obj) - struct obj *obj; +subfrombill(struct obj *obj) { } void -splitbill(o1, o2) - struct obj *o1, *o2; +splitbill(struct obj *o1, struct obj *o2) { } int -dopay() { +dopay(void) +{ return (0); } void -paybill() +paybill(void) { } int -doinvbill(n) - int n; +doinvbill(int n) { return (0); } void -shkdead(m) - struct monst *m; +shkdead(struct monst *m) { } int -shkcatch(obj) - struct obj *obj; +shkcatch(struct obj *obj) { return (0); } int -shk_move(m) - struct monst *m; +shk_move(struct monst *m) { return (0); } void -replshk(mtmp, mtmp2) - struct monst *mtmp, *mtmp2; +replshk(struct monst *mtmp, struct monst *mtmp2) { } -char *shkname(m) - struct monst *m; +char * +shkname(struct monst *m) { return (""); } @@ -139,15 +188,13 @@ static const char *const shopnam[] = { }; char * -shkname(mtmp) /* called in do_name.c */ - struct monst *mtmp; +shkname(struct monst *mtmp) /* called in do_name.c */ { return (ESHK(mtmp)->shknam); } void -shkdead(mtmp) /* called in mon.c */ - struct monst *mtmp; +shkdead(struct monst *mtmp) /* called in mon.c */ { struct eshk *eshk = ESHK(mtmp); @@ -162,8 +209,7 @@ shkdead(mtmp) /* called in mon.c */ } void -replshk(mtmp, mtmp2) - struct monst *mtmp, *mtmp2; +replshk(struct monst *mtmp, struct monst *mtmp2) { if (mtmp == shopkeeper) { shopkeeper = mtmp2; @@ -172,7 +218,7 @@ replshk(mtmp, mtmp2) } static void -setpaid() +setpaid(void) { /* caller has checked that shopkeeper exists */ /* either we paid or left the shop or he just died */ struct obj *obj; @@ -191,13 +237,13 @@ setpaid() obj->unpaid = 0; while ((obj = billobjs) != NULL) { billobjs = obj->nobj; - free((char *) obj); + free(obj); } ESHK(shopkeeper)->billct = 0; } static void -addupbill() +addupbill(void) { /* delivers result in total */ /* caller has checked that shopkeeper exists */ int ct = ESHK(shopkeeper)->billct; @@ -210,7 +256,7 @@ addupbill() } int -inshop() +inshop(void) { int roomno = inroom(u.ux, u.uy); @@ -303,8 +349,7 @@ inshop() } static void -findshk(roomno) - int roomno; +findshk(int roomno) { struct monst *mtmp; for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) @@ -332,8 +377,7 @@ findshk(roomno) } static struct bill_x * -onbill(obj) - struct obj *obj; +onbill(struct obj *obj) { struct bill_x *bp; if (!shopkeeper) @@ -351,8 +395,7 @@ onbill(obj) /* called with two args on merge */ void -obfree(obj, merge) - struct obj *obj, *merge; +obfree(struct obj *obj, struct obj *merge) { struct bill_x *bp = onbill(obj); struct bill_x *bpm; @@ -376,13 +419,11 @@ obfree(obj, merge) *bp = bill[ESHK(shopkeeper)->billct]; } } - free((char *) obj); + free(obj); } static void -pay(tmp, shkp) - long tmp; - struct monst *shkp; +pay(long tmp, struct monst *shkp) { long robbed = ESHK(shkp)->robbed; @@ -398,7 +439,7 @@ pay(tmp, shkp) } int -dopay() +dopay(void) { long ltmp; struct bill_x *bp; @@ -520,8 +561,7 @@ dopay() /* 0 if not enough money */ /* -1 if object could not be found (but was paid) */ static int -dopayobj(bp) - struct bill_x *bp; +dopayobj(struct bill_x *bp) { struct obj *obj; long ltmp; @@ -563,14 +603,14 @@ dopayobj(bp) else pline("Error in shopkeeper administration."); } - free((char *) obj); + free(obj); } return (1); } /* routine called after dying (or quitting) with nonempty bill */ void -paybill() +paybill(void) { if (shlevel == dlevel && shopkeeper && ESHK(shopkeeper)->billct) { addupbill(); @@ -590,9 +630,8 @@ paybill() } /* find obj on one of the lists */ -struct obj * -bp_to_obj(bp) - struct bill_x *bp; +static struct obj * +bp_to_obj(struct bill_x *bp) { struct obj *obj; struct monst *mtmp; @@ -615,8 +654,7 @@ bp_to_obj(bp) /* called in hack.c when we pickup an object */ void -addtobill(obj) - struct obj *obj; +addtobill(struct obj *obj) { struct bill_x *bp; if (!inshop() || @@ -639,8 +677,7 @@ addtobill(obj) } void -splitbill(obj, otmp) - struct obj *obj, *otmp; +splitbill(struct obj *obj, struct obj *otmp) { /* otmp has been split off from obj */ struct bill_x *bp; @@ -673,8 +710,7 @@ splitbill(obj, otmp) } void -subfrombill(obj) - struct obj *obj; +subfrombill(struct obj *obj) { long ltmp; int tmp; @@ -739,9 +775,9 @@ subfrombill(obj) plur(ltmp)); } +/* mode: 0: deliver count 1: paged */ int -doinvbill(mode) - int mode; /* 0: deliver count 1: paged */ +doinvbill(int mode) { struct bill_x *bp; struct obj *obj; @@ -781,17 +817,19 @@ doinvbill(mode) thisused = bp->price * uquan; totused += thisused; obj->quan = uquan; /* cheat doname */ - (void) sprintf(buf, "x - %s", doname(obj)); + (void) snprintf(buf, sizeof(buf), + "x - %s", doname(obj)); obj->quan = oquan; /* restore value */ for (cnt = 0; buf[cnt]; cnt++); while (cnt < 50) buf[cnt++] = ' '; - (void) sprintf(&buf[cnt], " %5ld zorkmids", thisused); + (void) snprintf(buf+cnt, sizeof(buf)-cnt, + " %5ld zorkmids", thisused); if (page_line(buf)) goto quit; } } - (void) sprintf(buf, "Total:%50ld zorkmids", totused); + (void) snprintf(buf, sizeof(buf), "Total:%50ld zorkmids", totused); if (page_line("") || page_line(buf)) goto quit; set_pager(1); @@ -802,8 +840,7 @@ quit: } static int -getprice(obj) - struct obj *obj; +getprice(struct obj *obj) { int tmp, ac; @@ -853,6 +890,7 @@ getprice(obj) break; case CHAIN_SYM: pline("Strange ..., carrying a chain?"); + /* FALLTHROUGH */ case BALL_SYM: tmp = 10; break; @@ -863,7 +901,7 @@ getprice(obj) } static int -realhunger() +realhunger(void) { /* not completely foolproof */ int tmp = u.uhunger; struct obj *otmp = invent; @@ -876,8 +914,7 @@ realhunger() } int -shkcatch(obj) - struct obj *obj; +shkcatch(struct obj *obj) { struct monst *shkp = shopkeeper; @@ -898,8 +935,7 @@ shkcatch(obj) * shk_move: return 1: he moved 0: he didnt -1: let m_move do it */ int -shk_move(shkp) - struct monst *shkp; +shk_move(struct monst *shkp) { struct monst *mtmp; const struct permonst *mdat = shkp->data; @@ -1043,6 +1079,8 @@ notonl_ok: if (nix != omx || niy != omy) { if (info[chi] & ALLOW_M) { mtmp = m_at(nix, niy); + if (mtmp == NULL) + panic("error in shk_move"); if (hitmm(shkp, mtmp) == 1 && rn2(3) && hitmm(mtmp, shkp) == 2) return (2); @@ -1065,8 +1103,7 @@ notonl_ok: /* He is digging in the shop. */ void -shopdig(fall) - int fall; +shopdig(int fall) { if (!fall) { if (u.utraptype == TT_PIT) @@ -1100,8 +1137,7 @@ online(int x, int y) /* Does this monster follow me downstairs? */ int -follower(mtmp) - struct monst *mtmp; +follower(struct monst *mtmp) { return (mtmp->mtame || strchr("1TVWZi&, ", mtmp->data->mlet) #ifndef QUEST