2004-01-27 23:30:28 +03:00
|
|
|
/* $NetBSD: hack.shk.c,v 1.7 2004/01/27 20:30:29 jsm Exp $ */
|
1997-10-19 20:56:41 +04:00
|
|
|
|
1993-08-02 21:18:41 +04:00
|
|
|
/*
|
2003-04-02 22:36:33 +04:00
|
|
|
* 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.
|
1993-08-02 21:18:41 +04:00
|
|
|
*/
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-08-02 21:18:41 +04:00
|
|
|
#ifndef lint
|
2004-01-27 23:30:28 +03:00
|
|
|
__RCSID("$NetBSD: hack.shk.c,v 1.7 2004/01/27 20:30:29 jsm Exp $");
|
1997-10-19 20:56:41 +04:00
|
|
|
#endif /* not lint */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
#include <stdlib.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include "hack.h"
|
1997-10-19 20:56:41 +04:00
|
|
|
#include "extern.h"
|
|
|
|
|
|
|
|
#ifndef QUEST
|
2004-01-27 23:30:28 +03:00
|
|
|
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 int getprice(struct obj *);
|
|
|
|
static int realhunger(void);
|
1997-10-19 20:56:41 +04:00
|
|
|
#endif
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifdef QUEST
|
1997-10-19 20:56:41 +04:00
|
|
|
int shlevel = 0;
|
|
|
|
struct monst *shopkeeper = 0;
|
|
|
|
struct obj *billobjs = 0;
|
|
|
|
void
|
|
|
|
obfree(obj, merge)
|
|
|
|
struct obj *obj, *merge;
|
|
|
|
{
|
1993-03-21 12:45:37 +03:00
|
|
|
free((char *) obj);
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
int
|
|
|
|
inshop() {
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
void
|
|
|
|
shopdig(n)
|
|
|
|
int n;
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void
|
|
|
|
addtobill(obj)
|
|
|
|
struct obj *obj;
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void
|
|
|
|
subfrombill(obj)
|
|
|
|
struct obj *obj;
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void
|
|
|
|
splitbill(o1, o2)
|
|
|
|
struct obj *o1, *o2;
|
|
|
|
{
|
|
|
|
}
|
|
|
|
int
|
|
|
|
dopay() {
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
void
|
|
|
|
paybill()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
int
|
|
|
|
doinvbill(n)
|
|
|
|
int n;
|
|
|
|
{
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
void
|
|
|
|
shkdead(m)
|
|
|
|
struct monst *m;
|
|
|
|
{
|
|
|
|
}
|
|
|
|
int
|
|
|
|
shkcatch(obj)
|
|
|
|
struct obj *obj;
|
|
|
|
{
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
int
|
|
|
|
shk_move(m)
|
|
|
|
struct monst *m;
|
|
|
|
{
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
void
|
|
|
|
replshk(mtmp, mtmp2)
|
|
|
|
struct monst *mtmp, *mtmp2;
|
|
|
|
{
|
|
|
|
}
|
|
|
|
char *shkname(m)
|
|
|
|
struct monst *m;
|
|
|
|
{
|
|
|
|
return ("");
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* QUEST */
|
1993-03-21 12:45:37 +03:00
|
|
|
#include "hack.mfndpos.h"
|
|
|
|
#include "def.mkroom.h"
|
|
|
|
#include "def.eshk.h"
|
|
|
|
|
|
|
|
#define ESHK(mon) ((struct eshk *)(&(mon->mextra[0])))
|
|
|
|
#define NOTANGRY(mon) mon->mpeaceful
|
|
|
|
#define ANGRY(mon) !NOTANGRY(mon)
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
/*
|
|
|
|
* Descriptor of current shopkeeper. Note that the bill need not be
|
|
|
|
* per-shopkeeper, since it is valid only when in a shop.
|
|
|
|
*/
|
1993-03-21 12:45:37 +03:00
|
|
|
static struct monst *shopkeeper = 0;
|
|
|
|
static struct bill_x *bill;
|
1997-10-19 20:56:41 +04:00
|
|
|
static int shlevel = 0; /* level of this shopkeeper */
|
|
|
|
struct obj *billobjs; /* objects on bill with bp->useup */
|
|
|
|
/* only accessed here and by save & restore */
|
1993-03-21 12:45:37 +03:00
|
|
|
static long int total; /* filled by addupbill() */
|
|
|
|
static long int followmsg; /* last time of follow message */
|
|
|
|
|
|
|
|
/*
|
|
|
|
invariants: obj->unpaid iff onbill(obj) [unless bp->useup]
|
|
|
|
obj->quan <= bp->bquan
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2001-03-26 00:43:58 +04:00
|
|
|
const char shtypes[] = { /* 8 shoptypes: 7 specialized, 1 mixed */
|
1993-03-21 12:45:37 +03:00
|
|
|
RING_SYM, WAND_SYM, WEAPON_SYM, FOOD_SYM, SCROLL_SYM,
|
|
|
|
POTION_SYM, ARMOR_SYM, 0
|
|
|
|
};
|
|
|
|
|
2001-03-26 00:43:58 +04:00
|
|
|
static const char *const shopnam[] = {
|
1993-03-21 12:45:37 +03:00
|
|
|
"engagement ring", "walking cane", "antique weapon",
|
|
|
|
"delicatessen", "second hand book", "liquor",
|
|
|
|
"used armor", "assorted antiques"
|
|
|
|
};
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
char *
|
|
|
|
shkname(mtmp) /* called in do_name.c */
|
|
|
|
struct monst *mtmp;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
return (ESHK(mtmp)->shknam);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
|
|
|
shkdead(mtmp) /* called in mon.c */
|
|
|
|
struct monst *mtmp;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
struct eshk *eshk = ESHK(mtmp);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
if (eshk->shoplevel == dlevel)
|
1993-03-21 12:45:37 +03:00
|
|
|
rooms[eshk->shoproom].rtype = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (mtmp == shopkeeper) {
|
1993-03-21 12:45:37 +03:00
|
|
|
setpaid();
|
|
|
|
shopkeeper = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
bill = (struct bill_x *) - 1000; /* dump core when
|
|
|
|
* referenced */
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
|
|
|
replshk(mtmp, mtmp2)
|
|
|
|
struct monst *mtmp, *mtmp2;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
if (mtmp == shopkeeper) {
|
1993-03-21 12:45:37 +03:00
|
|
|
shopkeeper = mtmp2;
|
|
|
|
bill = &(ESHK(shopkeeper)->bill[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1997-10-19 20:56:41 +04:00
|
|
|
setpaid()
|
|
|
|
{ /* caller has checked that shopkeeper exists */
|
|
|
|
/* either we paid or left the shop or he just died */
|
|
|
|
struct obj *obj;
|
|
|
|
struct monst *mtmp;
|
|
|
|
for (obj = invent; obj; obj = obj->nobj)
|
1993-03-21 12:45:37 +03:00
|
|
|
obj->unpaid = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
for (obj = fobj; obj; obj = obj->nobj)
|
1993-03-21 12:45:37 +03:00
|
|
|
obj->unpaid = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
for (obj = fcobj; obj; obj = obj->nobj)
|
1993-03-21 12:45:37 +03:00
|
|
|
obj->unpaid = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
|
|
|
|
for (obj = mtmp->minvent; obj; obj = obj->nobj)
|
1993-03-21 12:45:37 +03:00
|
|
|
obj->unpaid = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
for (mtmp = fallen_down; mtmp; mtmp = mtmp->nmon)
|
|
|
|
for (obj = mtmp->minvent; obj; obj = obj->nobj)
|
1993-03-21 12:45:37 +03:00
|
|
|
obj->unpaid = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
while ((obj = billobjs) != NULL) {
|
1993-03-21 12:45:37 +03:00
|
|
|
billobjs = obj->nobj;
|
|
|
|
free((char *) obj);
|
|
|
|
}
|
|
|
|
ESHK(shopkeeper)->billct = 0;
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
static void
|
|
|
|
addupbill()
|
|
|
|
{ /* delivers result in total */
|
|
|
|
/* caller has checked that shopkeeper exists */
|
|
|
|
int ct = ESHK(shopkeeper)->billct;
|
|
|
|
struct bill_x *bp = bill;
|
1993-03-21 12:45:37 +03:00
|
|
|
total = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
while (ct--) {
|
1993-03-21 12:45:37 +03:00
|
|
|
total += bp->price * bp->bquan;
|
|
|
|
bp++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
int
|
|
|
|
inshop()
|
|
|
|
{
|
|
|
|
int roomno = inroom(u.ux, u.uy);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/* Did we just leave a shop? */
|
1997-10-19 20:56:41 +04:00
|
|
|
if (u.uinshop &&
|
1993-03-21 12:45:37 +03:00
|
|
|
(u.uinshop != roomno + 1 || shlevel != dlevel || !shopkeeper)) {
|
1997-10-19 20:56:41 +04:00
|
|
|
if (shopkeeper) {
|
|
|
|
if (ESHK(shopkeeper)->billct) {
|
|
|
|
if (inroom(shopkeeper->mx, shopkeeper->my)
|
|
|
|
== u.uinshop - 1) /* ab@unido */
|
|
|
|
pline("Somehow you escaped the shop without paying!");
|
|
|
|
addupbill();
|
|
|
|
pline("You stole for a total worth of %ld zorkmids.",
|
|
|
|
total);
|
|
|
|
ESHK(shopkeeper)->robbed += total;
|
|
|
|
setpaid();
|
|
|
|
if ((rooms[ESHK(shopkeeper)->shoproom].rtype == GENERAL)
|
|
|
|
== (rn2(3) == 0))
|
|
|
|
ESHK(shopkeeper)->following = 1;
|
|
|
|
}
|
|
|
|
shopkeeper = 0;
|
|
|
|
shlevel = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
u.uinshop = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
/* Did we just enter a zoo of some kind? */
|
1997-10-19 20:56:41 +04:00
|
|
|
if (roomno >= 0) {
|
|
|
|
int rt = rooms[roomno].rtype;
|
|
|
|
struct monst *mtmp;
|
|
|
|
if (rt == ZOO) {
|
1993-03-21 12:45:37 +03:00
|
|
|
pline("Welcome to David's treasure zoo!");
|
1997-10-19 20:56:41 +04:00
|
|
|
} else if (rt == SWAMP) {
|
1993-03-21 12:45:37 +03:00
|
|
|
pline("It looks rather muddy down here.");
|
1997-10-19 20:56:41 +04:00
|
|
|
} else if (rt == MORGUE) {
|
|
|
|
if (midnight())
|
1993-03-21 12:45:37 +03:00
|
|
|
pline("Go away! Go away!");
|
|
|
|
else
|
|
|
|
pline("You get an uncanny feeling ...");
|
|
|
|
} else
|
|
|
|
rt = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (rt != 0) {
|
1993-03-21 12:45:37 +03:00
|
|
|
rooms[roomno].rtype = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
|
|
|
|
if (rt != ZOO || !rn2(3))
|
1993-03-21 12:45:37 +03:00
|
|
|
mtmp->msleep = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Did we just enter a shop? */
|
1997-10-19 20:56:41 +04:00
|
|
|
if (roomno >= 0 && rooms[roomno].rtype >= 8) {
|
|
|
|
if (shlevel != dlevel || !shopkeeper
|
|
|
|
|| ESHK(shopkeeper)->shoproom != roomno)
|
|
|
|
findshk(roomno);
|
|
|
|
if (!shopkeeper) {
|
|
|
|
rooms[roomno].rtype = 0;
|
|
|
|
u.uinshop = 0;
|
|
|
|
} else if (!u.uinshop) {
|
|
|
|
if (!ESHK(shopkeeper)->visitct ||
|
|
|
|
strncmp(ESHK(shopkeeper)->customer, plname, PL_NSIZ)) {
|
|
|
|
|
|
|
|
/* He seems to be new here */
|
|
|
|
ESHK(shopkeeper)->visitct = 0;
|
|
|
|
ESHK(shopkeeper)->following = 0;
|
|
|
|
(void) strncpy(ESHK(shopkeeper)->customer, plname, PL_NSIZ);
|
|
|
|
NOTANGRY(shopkeeper) = 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!ESHK(shopkeeper)->following) {
|
|
|
|
boolean box, pick;
|
|
|
|
|
|
|
|
pline("Hello %s! Welcome%s to %s's %s shop!",
|
|
|
|
plname,
|
|
|
|
ESHK(shopkeeper)->visitct++ ? " again" : "",
|
|
|
|
shkname(shopkeeper),
|
|
|
|
shopnam[rooms[ESHK(shopkeeper)->shoproom].rtype - 8]);
|
|
|
|
box = carrying(ICE_BOX);
|
|
|
|
pick = carrying(PICK_AXE);
|
|
|
|
if (box || pick) {
|
|
|
|
if (dochug(shopkeeper)) {
|
|
|
|
u.uinshop = 0; /* he died moving */
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
pline("Will you please leave your %s outside?",
|
|
|
|
(box && pick) ? "box and pick-axe" :
|
|
|
|
box ? "box" : "pick-axe");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
u.uinshop = roomno + 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
return (u.uinshop);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
findshk(roomno)
|
1997-10-19 20:56:41 +04:00
|
|
|
int roomno;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
struct monst *mtmp;
|
|
|
|
for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
|
|
|
|
if (mtmp->isshk && ESHK(mtmp)->shoproom == roomno
|
|
|
|
&& ESHK(mtmp)->shoplevel == dlevel) {
|
|
|
|
shopkeeper = mtmp;
|
|
|
|
bill = &(ESHK(shopkeeper)->bill[0]);
|
|
|
|
shlevel = dlevel;
|
|
|
|
if (ANGRY(shopkeeper) &&
|
|
|
|
strncmp(ESHK(shopkeeper)->customer, plname, PL_NSIZ))
|
|
|
|
NOTANGRY(shopkeeper) = 1;
|
|
|
|
/*
|
|
|
|
* billobjs = 0; -- this is wrong if we save in a
|
|
|
|
* shop
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* (and it is harmless to have too many things in
|
|
|
|
* billobjs)
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
shopkeeper = 0;
|
|
|
|
shlevel = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
bill = (struct bill_x *) - 1000; /* dump core when referenced */
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct bill_x *
|
1997-10-19 20:56:41 +04:00
|
|
|
onbill(obj)
|
|
|
|
struct obj *obj;
|
|
|
|
{
|
|
|
|
struct bill_x *bp;
|
|
|
|
if (!shopkeeper)
|
|
|
|
return (0);
|
|
|
|
for (bp = bill; bp < &bill[ESHK(shopkeeper)->billct]; bp++)
|
|
|
|
if (bp->bo_id == obj->o_id) {
|
|
|
|
if (!obj->unpaid)
|
|
|
|
pline("onbill: paid obj on bill?");
|
|
|
|
return (bp);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (obj->unpaid)
|
|
|
|
pline("onbill: unpaid obj not on bill?");
|
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* called with two args on merge */
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
|
|
|
obfree(obj, merge)
|
|
|
|
struct obj *obj, *merge;
|
|
|
|
{
|
|
|
|
struct bill_x *bp = onbill(obj);
|
|
|
|
struct bill_x *bpm;
|
|
|
|
if (bp) {
|
|
|
|
if (!merge) {
|
1993-03-21 12:45:37 +03:00
|
|
|
bp->useup = 1;
|
|
|
|
obj->unpaid = 0; /* only for doinvbill */
|
|
|
|
obj->nobj = billobjs;
|
|
|
|
billobjs = obj;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bpm = onbill(merge);
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!bpm) {
|
1993-03-21 12:45:37 +03:00
|
|
|
/* this used to be a rename */
|
|
|
|
impossible("obfree: not on bill??");
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
/* this was a merger */
|
|
|
|
bpm->bquan += bp->bquan;
|
|
|
|
ESHK(shopkeeper)->billct--;
|
|
|
|
*bp = bill[ESHK(shopkeeper)->billct];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free((char *) obj);
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
static void
|
|
|
|
pay(tmp, shkp)
|
|
|
|
long tmp;
|
|
|
|
struct monst *shkp;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
long robbed = ESHK(shkp)->robbed;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
u.ugold -= tmp;
|
|
|
|
shkp->mgold += tmp;
|
|
|
|
flags.botl = 1;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (robbed) {
|
1993-03-21 12:45:37 +03:00
|
|
|
robbed -= tmp;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (robbed < 0)
|
|
|
|
robbed = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
ESHK(shkp)->robbed = robbed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
int
|
|
|
|
dopay()
|
|
|
|
{
|
|
|
|
long ltmp;
|
|
|
|
struct bill_x *bp;
|
|
|
|
struct monst *shkp;
|
|
|
|
int pass, tmp;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
multi = 0;
|
|
|
|
(void) inshop();
|
1997-10-19 20:56:41 +04:00
|
|
|
for (shkp = fmon; shkp; shkp = shkp->nmon)
|
|
|
|
if (shkp->isshk && dist(shkp->mx, shkp->my) < 3)
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!shkp && u.uinshop &&
|
|
|
|
inroom(shopkeeper->mx, shopkeeper->my) == ESHK(shopkeeper)->shoproom)
|
1993-03-21 12:45:37 +03:00
|
|
|
shkp = shopkeeper;
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!shkp) {
|
1993-03-21 12:45:37 +03:00
|
|
|
pline("There is nobody here to receive your payment.");
|
1997-10-19 20:56:41 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
ltmp = ESHK(shkp)->robbed;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (shkp != shopkeeper && NOTANGRY(shkp)) {
|
|
|
|
if (!ltmp) {
|
1993-03-21 12:45:37 +03:00
|
|
|
pline("You do not owe %s anything.", monnam(shkp));
|
1997-10-19 20:56:41 +04:00
|
|
|
} else if (!u.ugold) {
|
1993-03-21 12:45:37 +03:00
|
|
|
pline("You have no money.");
|
|
|
|
} else {
|
1997-10-19 20:56:41 +04:00
|
|
|
long ugold = u.ugold;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
if (u.ugold > ltmp) {
|
|
|
|
pline("You give %s the %ld gold pieces he asked for.",
|
|
|
|
monnam(shkp), ltmp);
|
|
|
|
pay(ltmp, shkp);
|
|
|
|
} else {
|
|
|
|
pline("You give %s all your gold.", monnam(shkp));
|
|
|
|
pay(u.ugold, shkp);
|
|
|
|
}
|
|
|
|
if (ugold < ltmp / 2) {
|
|
|
|
pline("Unfortunately, he doesn't look satisfied.");
|
|
|
|
} else {
|
|
|
|
ESHK(shkp)->robbed = 0;
|
|
|
|
ESHK(shkp)->following = 0;
|
|
|
|
if (ESHK(shkp)->shoplevel != dlevel) {
|
|
|
|
/*
|
|
|
|
* For convenience's sake, let him
|
|
|
|
* disappear
|
|
|
|
*/
|
|
|
|
shkp->minvent = 0; /* %% */
|
|
|
|
shkp->mgold = 0;
|
|
|
|
mondead(shkp);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!ESHK(shkp)->billct) {
|
1993-03-21 12:45:37 +03:00
|
|
|
pline("You do not owe %s anything.", monnam(shkp));
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!u.ugold) {
|
1993-03-21 12:45:37 +03:00
|
|
|
pline("Moreover, you have no money.");
|
1997-10-19 20:56:41 +04:00
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (ESHK(shkp)->robbed) {
|
1993-03-21 12:45:37 +03:00
|
|
|
#define min(a,b) ((a<b)?a:b)
|
1997-10-19 20:56:41 +04:00
|
|
|
pline("But since his shop has been robbed recently,");
|
|
|
|
pline("you %srepay %s's expenses.",
|
|
|
|
(u.ugold < ESHK(shkp)->robbed) ? "partially " : "",
|
|
|
|
monnam(shkp));
|
|
|
|
pay(min(u.ugold, ESHK(shkp)->robbed), shkp);
|
|
|
|
ESHK(shkp)->robbed = 0;
|
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (ANGRY(shkp)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
pline("But in order to appease %s,",
|
1997-10-19 20:56:41 +04:00
|
|
|
amonnam(shkp, "angry"));
|
|
|
|
if (u.ugold >= 1000) {
|
1993-03-21 12:45:37 +03:00
|
|
|
ltmp = 1000;
|
|
|
|
pline(" you give him 1000 gold pieces.");
|
|
|
|
} else {
|
|
|
|
ltmp = u.ugold;
|
|
|
|
pline(" you give him all your money.");
|
|
|
|
}
|
|
|
|
pay(ltmp, shkp);
|
1997-10-19 20:56:41 +04:00
|
|
|
if (strncmp(ESHK(shkp)->customer, plname, PL_NSIZ)
|
|
|
|
|| rn2(3)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
pline("%s calms down.", Monnam(shkp));
|
|
|
|
NOTANGRY(shkp) = 1;
|
1997-10-19 20:56:41 +04:00
|
|
|
} else
|
|
|
|
pline("%s is as angry as ever.",
|
|
|
|
Monnam(shkp));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (shkp != shopkeeper) {
|
1993-03-21 12:45:37 +03:00
|
|
|
impossible("dopay: not to shopkeeper?");
|
1997-10-19 20:56:41 +04:00
|
|
|
if (shopkeeper)
|
|
|
|
setpaid();
|
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
for (pass = 0; pass <= 1; pass++) {
|
1993-03-21 12:45:37 +03:00
|
|
|
tmp = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
while (tmp < ESHK(shopkeeper)->billct) {
|
1993-03-21 12:45:37 +03:00
|
|
|
bp = &bill[tmp];
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!pass && !bp->useup) {
|
1993-03-21 12:45:37 +03:00
|
|
|
tmp++;
|
|
|
|
continue;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!dopayobj(bp))
|
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
bill[tmp] = bill[--ESHK(shopkeeper)->billct];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pline("Thank you for shopping in %s's %s store!",
|
1997-10-19 20:56:41 +04:00
|
|
|
shkname(shopkeeper),
|
|
|
|
shopnam[rooms[ESHK(shopkeeper)->shoproom].rtype - 8]);
|
1993-03-21 12:45:37 +03:00
|
|
|
NOTANGRY(shopkeeper) = 1;
|
1997-10-19 20:56:41 +04:00
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* return 1 if paid successfully */
|
1997-10-19 20:56:41 +04:00
|
|
|
/* 0 if not enough money */
|
|
|
|
/* -1 if object could not be found (but was paid) */
|
|
|
|
static int
|
|
|
|
dopayobj(bp)
|
|
|
|
struct bill_x *bp;
|
|
|
|
{
|
|
|
|
struct obj *obj;
|
|
|
|
long ltmp;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/* find the object on one of the lists */
|
|
|
|
obj = bp_to_obj(bp);
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!obj) {
|
1993-03-21 12:45:37 +03:00
|
|
|
impossible("Shopkeeper administration out of order.");
|
|
|
|
setpaid(); /* be nice to the player */
|
1997-10-19 20:56:41 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!obj->unpaid && !bp->useup) {
|
1993-03-21 12:45:37 +03:00
|
|
|
impossible("Paid object on bill??");
|
1997-10-19 20:56:41 +04:00
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
obj->unpaid = 0;
|
|
|
|
ltmp = bp->price * bp->bquan;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (ANGRY(shopkeeper))
|
|
|
|
ltmp += ltmp / 3;
|
|
|
|
if (u.ugold < ltmp) {
|
1993-03-21 12:45:37 +03:00
|
|
|
pline("You don't have gold enough to pay %s.",
|
1997-10-19 20:56:41 +04:00
|
|
|
doname(obj));
|
1993-03-21 12:45:37 +03:00
|
|
|
obj->unpaid = 1;
|
1997-10-19 20:56:41 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
pay(ltmp, shopkeeper);
|
|
|
|
pline("You bought %s for %ld gold piece%s.",
|
1997-10-19 20:56:41 +04:00
|
|
|
doname(obj), ltmp, plur(ltmp));
|
|
|
|
if (bp->useup) {
|
|
|
|
struct obj *otmp = billobjs;
|
|
|
|
if (obj == billobjs)
|
1993-03-21 12:45:37 +03:00
|
|
|
billobjs = obj->nobj;
|
|
|
|
else {
|
1997-10-19 20:56:41 +04:00
|
|
|
while (otmp && otmp->nobj != obj)
|
|
|
|
otmp = otmp->nobj;
|
|
|
|
if (otmp)
|
|
|
|
otmp->nobj = obj->nobj;
|
|
|
|
else
|
|
|
|
pline("Error in shopkeeper administration.");
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
free((char *) obj);
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* routine called after dying (or quitting) with nonempty bill */
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
|
|
|
paybill()
|
|
|
|
{
|
|
|
|
if (shlevel == dlevel && shopkeeper && ESHK(shopkeeper)->billct) {
|
1993-03-21 12:45:37 +03:00
|
|
|
addupbill();
|
1997-10-19 20:56:41 +04:00
|
|
|
if (total > u.ugold) {
|
1993-03-21 12:45:37 +03:00
|
|
|
shopkeeper->mgold += u.ugold;
|
|
|
|
u.ugold = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
pline("%s comes and takes all your possessions.",
|
|
|
|
Monnam(shopkeeper));
|
1993-03-21 12:45:37 +03:00
|
|
|
} else {
|
|
|
|
u.ugold -= total;
|
|
|
|
shopkeeper->mgold += total;
|
1997-10-19 20:56:41 +04:00
|
|
|
pline("%s comes and takes the %ld zorkmids you owed him.",
|
|
|
|
Monnam(shopkeeper), total);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
setpaid(); /* in case we create bones */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find obj on one of the lists */
|
1997-10-19 20:56:41 +04:00
|
|
|
struct obj *
|
1993-03-21 12:45:37 +03:00
|
|
|
bp_to_obj(bp)
|
1997-10-19 20:56:41 +04:00
|
|
|
struct bill_x *bp;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
struct obj *obj;
|
|
|
|
struct monst *mtmp;
|
|
|
|
unsigned id = bp->bo_id;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
if (bp->useup)
|
1993-03-21 12:45:37 +03:00
|
|
|
obj = o_on(id, billobjs);
|
1997-10-19 20:56:41 +04:00
|
|
|
else if (!(obj = o_on(id, invent)) &&
|
|
|
|
!(obj = o_on(id, fobj)) &&
|
|
|
|
!(obj = o_on(id, fcobj))) {
|
|
|
|
for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
|
|
|
|
if ((obj = o_on(id, mtmp->minvent)) != NULL)
|
|
|
|
break;
|
|
|
|
for (mtmp = fallen_down; mtmp; mtmp = mtmp->nmon)
|
|
|
|
if ((obj = o_on(id, mtmp->minvent)) != NULL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (obj);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* called in hack.c when we pickup an object */
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
|
|
|
addtobill(obj)
|
|
|
|
struct obj *obj;
|
|
|
|
{
|
|
|
|
struct bill_x *bp;
|
|
|
|
if (!inshop() ||
|
|
|
|
(u.ux == ESHK(shopkeeper)->shk.x && u.uy == ESHK(shopkeeper)->shk.y) ||
|
|
|
|
(u.ux == ESHK(shopkeeper)->shd.x && u.uy == ESHK(shopkeeper)->shd.y) ||
|
|
|
|
onbill(obj) /* perhaps we threw it away earlier */
|
|
|
|
)
|
|
|
|
return;
|
|
|
|
if (ESHK(shopkeeper)->billct == BILLSZ) {
|
1993-03-21 12:45:37 +03:00
|
|
|
pline("You got that for free!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bp = &bill[ESHK(shopkeeper)->billct];
|
|
|
|
bp->bo_id = obj->o_id;
|
|
|
|
bp->bquan = obj->quan;
|
|
|
|
bp->useup = 0;
|
|
|
|
bp->price = getprice(obj);
|
|
|
|
ESHK(shopkeeper)->billct++;
|
|
|
|
obj->unpaid = 1;
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
|
|
|
splitbill(obj, otmp)
|
|
|
|
struct obj *obj, *otmp;
|
|
|
|
{
|
1993-03-21 12:45:37 +03:00
|
|
|
/* otmp has been split off from obj */
|
1997-10-19 20:56:41 +04:00
|
|
|
struct bill_x *bp;
|
|
|
|
int tmp;
|
1993-03-21 12:45:37 +03:00
|
|
|
bp = onbill(obj);
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!bp) {
|
1993-03-21 12:45:37 +03:00
|
|
|
impossible("splitbill: not on bill?");
|
|
|
|
return;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (bp->bquan < otmp->quan) {
|
1993-03-21 12:45:37 +03:00
|
|
|
impossible("Negative quantity on bill??");
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (bp->bquan == otmp->quan) {
|
1993-03-21 12:45:37 +03:00
|
|
|
impossible("Zero quantity on bill??");
|
|
|
|
}
|
|
|
|
bp->bquan -= otmp->quan;
|
|
|
|
|
|
|
|
/* addtobill(otmp); */
|
1997-10-19 20:56:41 +04:00
|
|
|
if (ESHK(shopkeeper)->billct == BILLSZ)
|
|
|
|
otmp->unpaid = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
else {
|
|
|
|
tmp = bp->price;
|
|
|
|
bp = &bill[ESHK(shopkeeper)->billct];
|
|
|
|
bp->bo_id = otmp->o_id;
|
|
|
|
bp->bquan = otmp->quan;
|
|
|
|
bp->useup = 0;
|
|
|
|
bp->price = tmp;
|
|
|
|
ESHK(shopkeeper)->billct++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
|
|
|
subfrombill(obj)
|
|
|
|
struct obj *obj;
|
|
|
|
{
|
|
|
|
long ltmp;
|
|
|
|
int tmp;
|
|
|
|
struct obj *otmp;
|
|
|
|
struct bill_x *bp;
|
|
|
|
if (!inshop() || (u.ux == ESHK(shopkeeper)->shk.x && u.uy == ESHK(shopkeeper)->shk.y) ||
|
|
|
|
(u.ux == ESHK(shopkeeper)->shd.x && u.uy == ESHK(shopkeeper)->shd.y))
|
1993-03-21 12:45:37 +03:00
|
|
|
return;
|
1997-10-19 20:56:41 +04:00
|
|
|
if ((bp = onbill(obj)) != 0) {
|
1993-03-21 12:45:37 +03:00
|
|
|
obj->unpaid = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (bp->bquan > obj->quan) {
|
1993-03-21 12:45:37 +03:00
|
|
|
otmp = newobj(0);
|
|
|
|
*otmp = *obj;
|
|
|
|
bp->bo_id = otmp->o_id = flags.ident++;
|
|
|
|
otmp->quan = (bp->bquan -= obj->quan);
|
|
|
|
otmp->owt = 0; /* superfluous */
|
|
|
|
otmp->onamelth = 0;
|
|
|
|
bp->useup = 1;
|
|
|
|
otmp->nobj = billobjs;
|
|
|
|
billobjs = otmp;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ESHK(shopkeeper)->billct--;
|
|
|
|
*bp = bill[ESHK(shopkeeper)->billct];
|
|
|
|
return;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (obj->unpaid) {
|
1993-03-21 12:45:37 +03:00
|
|
|
pline("%s didn't notice.", Monnam(shopkeeper));
|
|
|
|
obj->unpaid = 0;
|
|
|
|
return; /* %% */
|
|
|
|
}
|
|
|
|
/* he dropped something of his own - probably wants to sell it */
|
1997-10-19 20:56:41 +04:00
|
|
|
if (shopkeeper->msleep || shopkeeper->mfroz ||
|
|
|
|
inroom(shopkeeper->mx, shopkeeper->my) != ESHK(shopkeeper)->shoproom)
|
1993-03-21 12:45:37 +03:00
|
|
|
return;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (ESHK(shopkeeper)->billct == BILLSZ ||
|
|
|
|
((tmp = shtypes[rooms[ESHK(shopkeeper)->shoproom].rtype - 8]) && tmp != obj->olet)
|
|
|
|
|| strchr("_0", obj->olet)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
pline("%s seems not interested.", Monnam(shopkeeper));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ltmp = getprice(obj) * obj->quan;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (ANGRY(shopkeeper)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
ltmp /= 3;
|
|
|
|
NOTANGRY(shopkeeper) = 1;
|
1997-10-19 20:56:41 +04:00
|
|
|
} else
|
|
|
|
ltmp /= 2;
|
|
|
|
if (ESHK(shopkeeper)->robbed) {
|
|
|
|
if ((ESHK(shopkeeper)->robbed -= ltmp) < 0)
|
1993-03-21 12:45:37 +03:00
|
|
|
ESHK(shopkeeper)->robbed = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
pline("Thank you for your contribution to restock this recently plundered shop.");
|
1993-03-21 12:45:37 +03:00
|
|
|
return;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (ltmp > shopkeeper->mgold)
|
1993-03-21 12:45:37 +03:00
|
|
|
ltmp = shopkeeper->mgold;
|
|
|
|
pay(-ltmp, shopkeeper);
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!ltmp)
|
|
|
|
pline("%s gladly accepts %s but cannot pay you at present.",
|
|
|
|
Monnam(shopkeeper), doname(obj));
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
1997-10-19 20:56:41 +04:00
|
|
|
pline("You sold %s and got %ld gold piece%s.", doname(obj), ltmp,
|
|
|
|
plur(ltmp));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
doinvbill(mode)
|
1997-10-19 20:56:41 +04:00
|
|
|
int mode; /* 0: deliver count 1: paged */
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
struct bill_x *bp;
|
|
|
|
struct obj *obj;
|
|
|
|
long totused, thisused;
|
|
|
|
char buf[BUFSZ];
|
|
|
|
|
|
|
|
if (mode == 0) {
|
|
|
|
int cnt = 0;
|
|
|
|
|
|
|
|
if (shopkeeper)
|
|
|
|
for (bp = bill; bp - bill < ESHK(shopkeeper)->billct; bp++)
|
|
|
|
if (bp->useup ||
|
|
|
|
((obj = bp_to_obj(bp)) && obj->quan < bp->bquan))
|
|
|
|
cnt++;
|
|
|
|
return (cnt);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!shopkeeper) {
|
1993-03-21 12:45:37 +03:00
|
|
|
impossible("doinvbill: no shopkeeper?");
|
1997-10-19 20:56:41 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
set_pager(0);
|
1997-10-19 20:56:41 +04:00
|
|
|
if (page_line("Unpaid articles already used up:") || page_line(""))
|
|
|
|
goto quit;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
totused = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
for (bp = bill; bp - bill < ESHK(shopkeeper)->billct; bp++) {
|
|
|
|
obj = bp_to_obj(bp);
|
|
|
|
if (!obj) {
|
|
|
|
impossible("Bad shopkeeper administration.");
|
1993-03-21 12:45:37 +03:00
|
|
|
goto quit;
|
1997-10-19 20:56:41 +04:00
|
|
|
}
|
|
|
|
if (bp->useup || bp->bquan > obj->quan) {
|
|
|
|
int cnt, oquan, uquan;
|
|
|
|
|
|
|
|
oquan = obj->quan;
|
|
|
|
uquan = (bp->useup ? bp->bquan : bp->bquan - oquan);
|
|
|
|
thisused = bp->price * uquan;
|
|
|
|
totused += thisused;
|
|
|
|
obj->quan = uquan; /* cheat doname */
|
|
|
|
(void) sprintf(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);
|
|
|
|
if (page_line(buf))
|
|
|
|
goto quit;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
(void) sprintf(buf, "Total:%50ld zorkmids", totused);
|
1997-10-19 20:56:41 +04:00
|
|
|
if (page_line("") || page_line(buf))
|
1993-03-21 12:45:37 +03:00
|
|
|
goto quit;
|
|
|
|
set_pager(1);
|
1997-10-19 20:56:41 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
quit:
|
|
|
|
set_pager(2);
|
1997-10-19 20:56:41 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
static int
|
|
|
|
getprice(obj)
|
|
|
|
struct obj *obj;
|
|
|
|
{
|
|
|
|
int tmp, ac;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
switch (obj->olet) {
|
1993-03-21 12:45:37 +03:00
|
|
|
case AMULET_SYM:
|
1997-10-19 20:56:41 +04:00
|
|
|
tmp = 10 * rnd(500);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case TOOL_SYM:
|
1997-10-19 20:56:41 +04:00
|
|
|
tmp = 10 * rnd((obj->otyp == EXPENSIVE_CAMERA) ? 150 : 30);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case RING_SYM:
|
1997-10-19 20:56:41 +04:00
|
|
|
tmp = 10 * rnd(100);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case WAND_SYM:
|
1997-10-19 20:56:41 +04:00
|
|
|
tmp = 10 * rnd(100);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case SCROLL_SYM:
|
1997-10-19 20:56:41 +04:00
|
|
|
tmp = 10 * rnd(50);
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifdef MAIL
|
1997-10-19 20:56:41 +04:00
|
|
|
if (obj->otyp == SCR_MAIL)
|
1993-03-21 12:45:37 +03:00
|
|
|
tmp = rnd(5);
|
1997-10-19 20:56:41 +04:00
|
|
|
#endif /* MAIL */
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case POTION_SYM:
|
1997-10-19 20:56:41 +04:00
|
|
|
tmp = 10 * rnd(50);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case FOOD_SYM:
|
1997-10-19 20:56:41 +04:00
|
|
|
tmp = 10 * rnd(5 + (2000 / realhunger()));
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case GEM_SYM:
|
1997-10-19 20:56:41 +04:00
|
|
|
tmp = 10 * rnd(20);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case ARMOR_SYM:
|
|
|
|
ac = ARM_BONUS(obj);
|
1997-10-19 20:56:41 +04:00
|
|
|
if (ac <= -10) /* probably impossible */
|
1993-03-21 12:45:37 +03:00
|
|
|
ac = -9;
|
1997-10-19 20:56:41 +04:00
|
|
|
tmp = 100 + ac * ac * rnd(10 + ac);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case WEAPON_SYM:
|
1997-10-19 20:56:41 +04:00
|
|
|
if (obj->otyp < BOOMERANG)
|
|
|
|
tmp = 5 * rnd(10);
|
|
|
|
else if (obj->otyp == LONG_SWORD ||
|
|
|
|
obj->otyp == TWO_HANDED_SWORD)
|
|
|
|
tmp = 10 * rnd(150);
|
|
|
|
else
|
|
|
|
tmp = 10 * rnd(75);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case CHAIN_SYM:
|
|
|
|
pline("Strange ..., carrying a chain?");
|
|
|
|
case BALL_SYM:
|
|
|
|
tmp = 10;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
tmp = 10000;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
return (tmp);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
static int
|
|
|
|
realhunger()
|
|
|
|
{ /* not completely foolproof */
|
|
|
|
int tmp = u.uhunger;
|
|
|
|
struct obj *otmp = invent;
|
|
|
|
while (otmp) {
|
|
|
|
if (otmp->olet == FOOD_SYM && !otmp->unpaid)
|
1993-03-21 12:45:37 +03:00
|
|
|
tmp += objects[otmp->otyp].nutrition;
|
|
|
|
otmp = otmp->nobj;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
return ((tmp <= 0) ? 1 : tmp);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
shkcatch(obj)
|
1997-10-19 20:56:41 +04:00
|
|
|
struct obj *obj;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
struct monst *shkp = shopkeeper;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
if (u.uinshop && shkp && !shkp->mfroz && !shkp->msleep &&
|
1993-03-21 12:45:37 +03:00
|
|
|
u.dx && u.dy &&
|
1997-10-19 20:56:41 +04:00
|
|
|
inroom(u.ux + u.dx, u.uy + u.dy) + 1 == u.uinshop &&
|
1993-03-21 12:45:37 +03:00
|
|
|
shkp->mx == ESHK(shkp)->shk.x && shkp->my == ESHK(shkp)->shk.y &&
|
|
|
|
u.ux == ESHK(shkp)->shd.x && u.uy == ESHK(shkp)->shd.y) {
|
|
|
|
pline("%s nimbly catches the %s.", Monnam(shkp), xname(obj));
|
|
|
|
obj->nobj = shkp->minvent;
|
|
|
|
shkp->minvent = obj;
|
1997-10-19 20:56:41 +04:00
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* shk_move: return 1: he moved 0: he didnt -1: let m_move do it
|
|
|
|
*/
|
1997-10-19 20:56:41 +04:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
shk_move(shkp)
|
1997-10-19 20:56:41 +04:00
|
|
|
struct monst *shkp;
|
|
|
|
{
|
|
|
|
struct monst *mtmp;
|
2001-03-26 00:43:58 +04:00
|
|
|
const struct permonst *mdat = shkp->data;
|
1997-10-19 20:56:41 +04:00
|
|
|
xchar gx, gy, omx, omy, nx, ny, nix, niy;
|
|
|
|
schar appr, i;
|
|
|
|
int udist;
|
|
|
|
int z;
|
|
|
|
schar shkroom, chi, chcnt, cnt;
|
|
|
|
boolean uondoor = 0, satdoor, avoid = 0, badinv;
|
|
|
|
coord poss[9];
|
|
|
|
int info[9];
|
|
|
|
struct obj *ib = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
omx = shkp->mx;
|
|
|
|
omy = shkp->my;
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
if ((udist = dist(omx, omy)) < 3) {
|
|
|
|
if (ANGRY(shkp)) {
|
|
|
|
(void) hitu(shkp, d(mdat->damn, mdat->damd) + 1);
|
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (ESHK(shkp)->following) {
|
|
|
|
if (strncmp(ESHK(shkp)->customer, plname, PL_NSIZ)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
pline("Hello %s! I was looking for %s.",
|
1997-10-19 20:56:41 +04:00
|
|
|
plname, ESHK(shkp)->customer);
|
1993-03-21 12:45:37 +03:00
|
|
|
ESHK(shkp)->following = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!ESHK(shkp)->robbed) { /* impossible? */
|
1993-03-21 12:45:37 +03:00
|
|
|
ESHK(shkp)->following = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (moves > followmsg + 4) {
|
1993-03-21 12:45:37 +03:00
|
|
|
pline("Hello %s! Didn't you forget to pay?",
|
1997-10-19 20:56:41 +04:00
|
|
|
plname);
|
1993-03-21 12:45:37 +03:00
|
|
|
followmsg = moves;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (udist < 2)
|
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
shkroom = inroom(omx, omy);
|
1993-03-21 12:45:37 +03:00
|
|
|
appr = 1;
|
|
|
|
gx = ESHK(shkp)->shk.x;
|
|
|
|
gy = ESHK(shkp)->shk.y;
|
|
|
|
satdoor = (gx == omx && gy == omy);
|
1997-10-19 20:56:41 +04:00
|
|
|
if (ESHK(shkp)->following || ((z = holetime()) >= 0 && z * z <= udist)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
gx = u.ux;
|
|
|
|
gy = u.uy;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (shkroom < 0 || shkroom != inroom(u.ux, u.uy))
|
|
|
|
if (udist > 4)
|
|
|
|
return (-1); /* leave it to m_move */
|
|
|
|
} else if (ANGRY(shkp)) {
|
|
|
|
long saveBlind = Blind;
|
1993-03-21 12:45:37 +03:00
|
|
|
Blind = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (shkp->mcansee && !Invis && cansee(omx, omy)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
gx = u.ux;
|
|
|
|
gy = u.uy;
|
|
|
|
}
|
|
|
|
Blind = saveBlind;
|
|
|
|
avoid = FALSE;
|
|
|
|
} else {
|
|
|
|
#define GDIST(x,y) ((x-gx)*(x-gx)+(y-gy)*(y-gy))
|
1997-10-19 20:56:41 +04:00
|
|
|
if (Invis)
|
|
|
|
avoid = FALSE;
|
1993-03-21 12:45:37 +03:00
|
|
|
else {
|
1997-10-19 20:56:41 +04:00
|
|
|
uondoor = (u.ux == ESHK(shkp)->shd.x &&
|
|
|
|
u.uy == ESHK(shkp)->shd.y);
|
|
|
|
if (uondoor) {
|
|
|
|
if (ESHK(shkp)->billct)
|
|
|
|
pline("Hello %s! Will you please pay before leaving?",
|
|
|
|
plname);
|
|
|
|
badinv = (carrying(PICK_AXE) || carrying(ICE_BOX));
|
|
|
|
if (satdoor && badinv)
|
|
|
|
return (0);
|
|
|
|
avoid = !badinv;
|
|
|
|
} else {
|
|
|
|
avoid = (u.uinshop && dist(gx, gy) > 8);
|
|
|
|
badinv = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (((!ESHK(shkp)->robbed && !ESHK(shkp)->billct) || avoid)
|
|
|
|
&& GDIST(omx, omy) < 3) {
|
|
|
|
if (!badinv && !online(omx, omy))
|
|
|
|
return (0);
|
|
|
|
if (satdoor)
|
|
|
|
appr = gx = gy = 0;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (omx == gx && omy == gy)
|
|
|
|
return (0);
|
|
|
|
if (shkp->mconf) {
|
1993-03-21 12:45:37 +03:00
|
|
|
avoid = FALSE;
|
|
|
|
appr = 0;
|
|
|
|
}
|
|
|
|
nix = omx;
|
|
|
|
niy = omy;
|
1997-10-19 20:56:41 +04:00
|
|
|
cnt = mfndpos(shkp, poss, info, ALLOW_SSM);
|
|
|
|
if (avoid && uondoor) { /* perhaps we cannot avoid him */
|
|
|
|
for (i = 0; i < cnt; i++)
|
|
|
|
if (!(info[i] & NOTONL))
|
|
|
|
goto notonl_ok;
|
1993-03-21 12:45:37 +03:00
|
|
|
avoid = FALSE;
|
1997-10-19 20:56:41 +04:00
|
|
|
notonl_ok:
|
1993-03-21 12:45:37 +03:00
|
|
|
;
|
|
|
|
}
|
|
|
|
chi = -1;
|
|
|
|
chcnt = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
for (i = 0; i < cnt; i++) {
|
1993-03-21 12:45:37 +03:00
|
|
|
nx = poss[i].x;
|
|
|
|
ny = poss[i].y;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (levl[nx][ny].typ == ROOM
|
|
|
|
|| shkroom != ESHK(shkp)->shoproom
|
|
|
|
|| ESHK(shkp)->following) {
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifdef STUPID
|
1997-10-19 20:56:41 +04:00
|
|
|
/* cater for stupid compilers */
|
|
|
|
int zz;
|
|
|
|
#endif /* STUPID */
|
|
|
|
if (uondoor && (ib = sobj_at(ICE_BOX, nx, ny))) {
|
|
|
|
nix = nx;
|
|
|
|
niy = ny;
|
|
|
|
chi = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (avoid && (info[i] & NOTONL))
|
|
|
|
continue;
|
|
|
|
if ((!appr && !rn2(++chcnt)) ||
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifdef STUPID
|
1997-10-19 20:56:41 +04:00
|
|
|
(appr && (zz = GDIST(nix, niy)) && zz > GDIST(nx, ny))
|
1993-03-21 12:45:37 +03:00
|
|
|
#else
|
1997-10-19 20:56:41 +04:00
|
|
|
(appr && GDIST(nx, ny) < GDIST(nix, niy))
|
|
|
|
#endif /* STUPID */
|
|
|
|
) {
|
|
|
|
nix = nx;
|
|
|
|
niy = ny;
|
|
|
|
chi = i;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (nix != omx || niy != omy) {
|
|
|
|
if (info[chi] & ALLOW_M) {
|
|
|
|
mtmp = m_at(nix, niy);
|
|
|
|
if (hitmm(shkp, mtmp) == 1 && rn2(3) &&
|
|
|
|
hitmm(mtmp, shkp) == 2)
|
|
|
|
return (2);
|
|
|
|
return (0);
|
|
|
|
} else if (info[chi] & ALLOW_U) {
|
|
|
|
(void) hitu(shkp, d(mdat->damn, mdat->damd) + 1);
|
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
shkp->mx = nix;
|
|
|
|
shkp->my = niy;
|
|
|
|
pmon(shkp);
|
1997-10-19 20:56:41 +04:00
|
|
|
if (ib) {
|
1993-03-21 12:45:37 +03:00
|
|
|
freeobj(ib);
|
|
|
|
mpickobj(shkp, ib);
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* He is digging in the shop. */
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
shopdig(fall)
|
1997-10-19 20:56:41 +04:00
|
|
|
int fall;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!fall) {
|
|
|
|
if (u.utraptype == TT_PIT)
|
|
|
|
pline("\"Be careful, sir, or you might fall through the floor.\"");
|
|
|
|
else
|
|
|
|
pline("\"Please, do not damage the floor here.\"");
|
|
|
|
} else if (dist(shopkeeper->mx, shopkeeper->my) < 3) {
|
|
|
|
struct obj *obj, *obj2;
|
|
|
|
|
|
|
|
pline("%s grabs your backpack!", shkname(shopkeeper));
|
|
|
|
for (obj = invent; obj; obj = obj2) {
|
|
|
|
obj2 = obj->nobj;
|
|
|
|
if (obj->owornmask)
|
|
|
|
continue;
|
|
|
|
freeinv(obj);
|
|
|
|
obj->nobj = shopkeeper->minvent;
|
|
|
|
shopkeeper->minvent = obj;
|
|
|
|
if (obj->unpaid)
|
|
|
|
subfrombill(obj);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
#endif /* QUEST */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
int
|
2001-03-26 00:43:58 +04:00
|
|
|
online(int x, int y)
|
1997-10-19 20:56:41 +04:00
|
|
|
{
|
|
|
|
return (x == u.ux || y == u.uy ||
|
|
|
|
(x - u.ux) * (x - u.ux) == (y - u.uy) * (y - u.uy));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Does this monster follow me downstairs? */
|
1997-10-19 20:56:41 +04:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
follower(mtmp)
|
1997-10-19 20:56:41 +04:00
|
|
|
struct monst *mtmp;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
return (mtmp->mtame || strchr("1TVWZi&, ", mtmp->data->mlet)
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef QUEST
|
|
|
|
|| (mtmp->isshk && ESHK(mtmp)->following)
|
1997-10-19 20:56:41 +04:00
|
|
|
#endif /* QUEST */
|
1993-03-21 12:45:37 +03:00
|
|
|
);
|
|
|
|
}
|