]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.shk.c
1 /* $NetBSD: hack.shk.c,v 1.8 2006/03/30 01:32:27 jnemeth Exp $ */
4 * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * - Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * - Neither the name of the Stichting Centrum voor Wiskunde en
20 * Informatica, nor the names of its contributors may be used to endorse or
21 * promote products derived from this software without specific prior
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
27 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
28 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
39 * All rights reserved.
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. The name of the author may not be used to endorse or promote products
50 * derived from this software without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
53 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
54 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
55 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
56 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
57 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
58 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
59 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
60 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
61 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 #include <sys/cdefs.h>
66 __RCSID("$NetBSD: hack.shk.c,v 1.8 2006/03/30 01:32:27 jnemeth Exp $");
74 static void setpaid(void);
75 static void addupbill(void);
76 static void findshk(int);
77 static struct bill_x
*onbill(struct obj
*);
78 static void pay(long, struct monst
*);
79 static int dopayobj(struct bill_x
*);
80 static int getprice(struct obj
*);
81 static int realhunger(void);
86 struct monst
*shopkeeper
= 0;
87 struct obj
*billobjs
= 0;
90 struct obj
*obj
, *merge
;
151 struct monst
*mtmp
, *mtmp2
;
161 #include "hack.mfndpos.h"
162 #include "def.mkroom.h"
163 #include "def.eshk.h"
165 #define ESHK(mon) ((struct eshk *)(&(mon->mextra[0])))
166 #define NOTANGRY(mon) mon->mpeaceful
167 #define ANGRY(mon) !NOTANGRY(mon)
170 * Descriptor of current shopkeeper. Note that the bill need not be
171 * per-shopkeeper, since it is valid only when in a shop.
173 static struct monst
*shopkeeper
= 0;
174 static struct bill_x
*bill
;
175 static int shlevel
= 0; /* level of this shopkeeper */
176 struct obj
*billobjs
; /* objects on bill with bp->useup */
177 /* only accessed here and by save & restore */
178 static long int total
; /* filled by addupbill() */
179 static long int followmsg
; /* last time of follow message */
182 invariants: obj->unpaid iff onbill(obj) [unless bp->useup]
183 obj->quan <= bp->bquan
187 const char shtypes
[] = { /* 8 shoptypes: 7 specialized, 1 mixed */
188 RING_SYM
, WAND_SYM
, WEAPON_SYM
, FOOD_SYM
, SCROLL_SYM
,
189 POTION_SYM
, ARMOR_SYM
, 0
192 static const char *const shopnam
[] = {
193 "engagement ring", "walking cane", "antique weapon",
194 "delicatessen", "second hand book", "liquor",
195 "used armor", "assorted antiques"
199 shkname(mtmp
) /* called in do_name.c */
202 return (ESHK(mtmp
)->shknam
);
206 shkdead(mtmp
) /* called in mon.c */
209 struct eshk
*eshk
= ESHK(mtmp
);
211 if (eshk
->shoplevel
== dlevel
)
212 rooms
[eshk
->shoproom
].rtype
= 0;
213 if (mtmp
== shopkeeper
) {
216 bill
= (struct bill_x
*) - 1000; /* dump core when
223 struct monst
*mtmp
, *mtmp2
;
225 if (mtmp
== shopkeeper
) {
227 bill
= &(ESHK(shopkeeper
)->bill
[0]);
233 { /* caller has checked that shopkeeper exists */
234 /* either we paid or left the shop or he just died */
237 for (obj
= invent
; obj
; obj
= obj
->nobj
)
239 for (obj
= fobj
; obj
; obj
= obj
->nobj
)
241 for (obj
= fcobj
; obj
; obj
= obj
->nobj
)
243 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
244 for (obj
= mtmp
->minvent
; obj
; obj
= obj
->nobj
)
246 for (mtmp
= fallen_down
; mtmp
; mtmp
= mtmp
->nmon
)
247 for (obj
= mtmp
->minvent
; obj
; obj
= obj
->nobj
)
249 while ((obj
= billobjs
) != NULL
) {
250 billobjs
= obj
->nobj
;
253 ESHK(shopkeeper
)->billct
= 0;
258 { /* delivers result in total */
259 /* caller has checked that shopkeeper exists */
260 int ct
= ESHK(shopkeeper
)->billct
;
261 struct bill_x
*bp
= bill
;
264 total
+= bp
->price
* bp
->bquan
;
272 int roomno
= inroom(u
.ux
, u
.uy
);
274 /* Did we just leave a shop? */
276 (u
.uinshop
!= roomno
+ 1 || shlevel
!= dlevel
|| !shopkeeper
)) {
278 if (ESHK(shopkeeper
)->billct
) {
279 if (inroom(shopkeeper
->mx
, shopkeeper
->my
)
280 == u
.uinshop
- 1) /* ab@unido */
281 pline("Somehow you escaped the shop without paying!");
283 pline("You stole for a total worth of %ld zorkmids.",
285 ESHK(shopkeeper
)->robbed
+= total
;
287 if ((rooms
[ESHK(shopkeeper
)->shoproom
].rtype
== GENERAL
)
289 ESHK(shopkeeper
)->following
= 1;
296 /* Did we just enter a zoo of some kind? */
298 int rt
= rooms
[roomno
].rtype
;
301 pline("Welcome to David's treasure zoo!");
302 } else if (rt
== SWAMP
) {
303 pline("It looks rather muddy down here.");
304 } else if (rt
== MORGUE
) {
306 pline("Go away! Go away!");
308 pline("You get an uncanny feeling ...");
312 rooms
[roomno
].rtype
= 0;
313 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
314 if (rt
!= ZOO
|| !rn2(3))
318 /* Did we just enter a shop? */
319 if (roomno
>= 0 && rooms
[roomno
].rtype
>= 8) {
320 if (shlevel
!= dlevel
|| !shopkeeper
321 || ESHK(shopkeeper
)->shoproom
!= roomno
)
324 rooms
[roomno
].rtype
= 0;
326 } else if (!u
.uinshop
) {
327 if (!ESHK(shopkeeper
)->visitct
||
328 strncmp(ESHK(shopkeeper
)->customer
, plname
, PL_NSIZ
)) {
330 /* He seems to be new here */
331 ESHK(shopkeeper
)->visitct
= 0;
332 ESHK(shopkeeper
)->following
= 0;
333 (void) strncpy(ESHK(shopkeeper
)->customer
, plname
, PL_NSIZ
);
334 NOTANGRY(shopkeeper
) = 1;
336 if (!ESHK(shopkeeper
)->following
) {
339 pline("Hello %s! Welcome%s to %s's %s shop!",
341 ESHK(shopkeeper
)->visitct
++ ? " again" : "",
343 shopnam
[rooms
[ESHK(shopkeeper
)->shoproom
].rtype
- 8]);
344 box
= carrying(ICE_BOX
);
345 pick
= carrying(PICK_AXE
);
347 if (dochug(shopkeeper
)) {
348 u
.uinshop
= 0; /* he died moving */
351 pline("Will you please leave your %s outside?",
352 (box
&& pick
) ? "box and pick-axe" :
353 box
? "box" : "pick-axe");
356 u
.uinshop
= roomno
+ 1;
367 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
368 if (mtmp
->isshk
&& ESHK(mtmp
)->shoproom
== roomno
369 && ESHK(mtmp
)->shoplevel
== dlevel
) {
371 bill
= &(ESHK(shopkeeper
)->bill
[0]);
373 if (ANGRY(shopkeeper
) &&
374 strncmp(ESHK(shopkeeper
)->customer
, plname
, PL_NSIZ
))
375 NOTANGRY(shopkeeper
) = 1;
377 * billobjs = 0; -- this is wrong if we save in a
381 * (and it is harmless to have too many things in
388 bill
= (struct bill_x
*) - 1000; /* dump core when referenced */
391 static struct bill_x
*
398 for (bp
= bill
; bp
< &bill
[ESHK(shopkeeper
)->billct
]; bp
++)
399 if (bp
->bo_id
== obj
->o_id
) {
401 pline("onbill: paid obj on bill?");
405 pline("onbill: unpaid obj not on bill?");
409 /* called with two args on merge */
412 struct obj
*obj
, *merge
;
414 struct bill_x
*bp
= onbill(obj
);
419 obj
->unpaid
= 0; /* only for doinvbill */
420 obj
->nobj
= billobjs
;
426 /* this used to be a rename */
427 impossible("obfree: not on bill??");
430 /* this was a merger */
431 bpm
->bquan
+= bp
->bquan
;
432 ESHK(shopkeeper
)->billct
--;
433 *bp
= bill
[ESHK(shopkeeper
)->billct
];
444 long robbed
= ESHK(shkp
)->robbed
;
453 ESHK(shkp
)->robbed
= robbed
;
467 for (shkp
= fmon
; shkp
; shkp
= shkp
->nmon
)
468 if (shkp
->isshk
&& dist(shkp
->mx
, shkp
->my
) < 3)
470 if (!shkp
&& u
.uinshop
&&
471 inroom(shopkeeper
->mx
, shopkeeper
->my
) == ESHK(shopkeeper
)->shoproom
)
475 pline("There is nobody here to receive your payment.");
478 ltmp
= ESHK(shkp
)->robbed
;
479 if (shkp
!= shopkeeper
&& NOTANGRY(shkp
)) {
481 pline("You do not owe %s anything.", monnam(shkp
));
482 } else if (!u
.ugold
) {
483 pline("You have no money.");
485 long ugold
= u
.ugold
;
487 if (u
.ugold
> ltmp
) {
488 pline("You give %s the %ld gold pieces he asked for.",
492 pline("You give %s all your gold.", monnam(shkp
));
495 if (ugold
< ltmp
/ 2) {
496 pline("Unfortunately, he doesn't look satisfied.");
498 ESHK(shkp
)->robbed
= 0;
499 ESHK(shkp
)->following
= 0;
500 if (ESHK(shkp
)->shoplevel
!= dlevel
) {
502 * For convenience's sake, let him
505 shkp
->minvent
= 0; /* %% */
513 if (!ESHK(shkp
)->billct
) {
514 pline("You do not owe %s anything.", monnam(shkp
));
516 pline("Moreover, you have no money.");
519 if (ESHK(shkp
)->robbed
) {
520 #define min(a,b) ((a<b)?a:b)
521 pline("But since his shop has been robbed recently,");
522 pline("you %srepay %s's expenses.",
523 (u
.ugold
< ESHK(shkp
)->robbed
) ? "partially " : "",
525 pay(min(u
.ugold
, ESHK(shkp
)->robbed
), shkp
);
526 ESHK(shkp
)->robbed
= 0;
530 pline("But in order to appease %s,",
531 amonnam(shkp
, "angry"));
532 if (u
.ugold
>= 1000) {
534 pline(" you give him 1000 gold pieces.");
537 pline(" you give him all your money.");
540 if (strncmp(ESHK(shkp
)->customer
, plname
, PL_NSIZ
)
542 pline("%s calms down.", Monnam(shkp
));
545 pline("%s is as angry as ever.",
550 if (shkp
!= shopkeeper
) {
551 impossible("dopay: not to shopkeeper?");
556 for (pass
= 0; pass
<= 1; pass
++) {
558 while (tmp
< ESHK(shopkeeper
)->billct
) {
560 if (!pass
&& !bp
->useup
) {
566 bill
[tmp
] = bill
[--ESHK(shopkeeper
)->billct
];
569 pline("Thank you for shopping in %s's %s store!",
571 shopnam
[rooms
[ESHK(shopkeeper
)->shoproom
].rtype
- 8]);
572 NOTANGRY(shopkeeper
) = 1;
576 /* return 1 if paid successfully */
577 /* 0 if not enough money */
578 /* -1 if object could not be found (but was paid) */
586 /* find the object on one of the lists */
590 impossible("Shopkeeper administration out of order.");
591 setpaid(); /* be nice to the player */
594 if (!obj
->unpaid
&& !bp
->useup
) {
595 impossible("Paid object on bill??");
599 ltmp
= bp
->price
* bp
->bquan
;
600 if (ANGRY(shopkeeper
))
602 if (u
.ugold
< ltmp
) {
603 pline("You don't have gold enough to pay %s.",
608 pay(ltmp
, shopkeeper
);
609 pline("You bought %s for %ld gold piece%s.",
610 doname(obj
), ltmp
, plur(ltmp
));
612 struct obj
*otmp
= billobjs
;
614 billobjs
= obj
->nobj
;
616 while (otmp
&& otmp
->nobj
!= obj
)
619 otmp
->nobj
= obj
->nobj
;
621 pline("Error in shopkeeper administration.");
628 /* routine called after dying (or quitting) with nonempty bill */
632 if (shlevel
== dlevel
&& shopkeeper
&& ESHK(shopkeeper
)->billct
) {
634 if (total
> u
.ugold
) {
635 shopkeeper
->mgold
+= u
.ugold
;
637 pline("%s comes and takes all your possessions.",
641 shopkeeper
->mgold
+= total
;
642 pline("%s comes and takes the %ld zorkmids you owed him.",
643 Monnam(shopkeeper
), total
);
645 setpaid(); /* in case we create bones */
649 /* find obj on one of the lists */
656 unsigned id
= bp
->bo_id
;
659 obj
= o_on(id
, billobjs
);
660 else if (!(obj
= o_on(id
, invent
)) &&
661 !(obj
= o_on(id
, fobj
)) &&
662 !(obj
= o_on(id
, fcobj
))) {
663 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
664 if ((obj
= o_on(id
, mtmp
->minvent
)) != NULL
)
666 for (mtmp
= fallen_down
; mtmp
; mtmp
= mtmp
->nmon
)
667 if ((obj
= o_on(id
, mtmp
->minvent
)) != NULL
)
673 /* called in hack.c when we pickup an object */
680 (u
.ux
== ESHK(shopkeeper
)->shk
.x
&& u
.uy
== ESHK(shopkeeper
)->shk
.y
) ||
681 (u
.ux
== ESHK(shopkeeper
)->shd
.x
&& u
.uy
== ESHK(shopkeeper
)->shd
.y
) ||
682 onbill(obj
) /* perhaps we threw it away earlier */
685 if (ESHK(shopkeeper
)->billct
== BILLSZ
) {
686 pline("You got that for free!");
689 bp
= &bill
[ESHK(shopkeeper
)->billct
];
690 bp
->bo_id
= obj
->o_id
;
691 bp
->bquan
= obj
->quan
;
693 bp
->price
= getprice(obj
);
694 ESHK(shopkeeper
)->billct
++;
700 struct obj
*obj
, *otmp
;
702 /* otmp has been split off from obj */
707 impossible("splitbill: not on bill?");
710 if (bp
->bquan
< otmp
->quan
) {
711 impossible("Negative quantity on bill??");
713 if (bp
->bquan
== otmp
->quan
) {
714 impossible("Zero quantity on bill??");
716 bp
->bquan
-= otmp
->quan
;
718 /* addtobill(otmp); */
719 if (ESHK(shopkeeper
)->billct
== BILLSZ
)
723 bp
= &bill
[ESHK(shopkeeper
)->billct
];
724 bp
->bo_id
= otmp
->o_id
;
725 bp
->bquan
= otmp
->quan
;
728 ESHK(shopkeeper
)->billct
++;
740 if (!inshop() || (u
.ux
== ESHK(shopkeeper
)->shk
.x
&& u
.uy
== ESHK(shopkeeper
)->shk
.y
) ||
741 (u
.ux
== ESHK(shopkeeper
)->shd
.x
&& u
.uy
== ESHK(shopkeeper
)->shd
.y
))
743 if ((bp
= onbill(obj
)) != 0) {
745 if (bp
->bquan
> obj
->quan
) {
748 bp
->bo_id
= otmp
->o_id
= flags
.ident
++;
749 otmp
->quan
= (bp
->bquan
-= obj
->quan
);
750 otmp
->owt
= 0; /* superfluous */
753 otmp
->nobj
= billobjs
;
757 ESHK(shopkeeper
)->billct
--;
758 *bp
= bill
[ESHK(shopkeeper
)->billct
];
762 pline("%s didn't notice.", Monnam(shopkeeper
));
766 /* he dropped something of his own - probably wants to sell it */
767 if (shopkeeper
->msleep
|| shopkeeper
->mfroz
||
768 inroom(shopkeeper
->mx
, shopkeeper
->my
) != ESHK(shopkeeper
)->shoproom
)
770 if (ESHK(shopkeeper
)->billct
== BILLSZ
||
771 ((tmp
= shtypes
[rooms
[ESHK(shopkeeper
)->shoproom
].rtype
- 8]) && tmp
!= obj
->olet
)
772 || strchr("_0", obj
->olet
)) {
773 pline("%s seems not interested.", Monnam(shopkeeper
));
776 ltmp
= getprice(obj
) * obj
->quan
;
777 if (ANGRY(shopkeeper
)) {
779 NOTANGRY(shopkeeper
) = 1;
782 if (ESHK(shopkeeper
)->robbed
) {
783 if ((ESHK(shopkeeper
)->robbed
-= ltmp
) < 0)
784 ESHK(shopkeeper
)->robbed
= 0;
785 pline("Thank you for your contribution to restock this recently plundered shop.");
788 if (ltmp
> shopkeeper
->mgold
)
789 ltmp
= shopkeeper
->mgold
;
790 pay(-ltmp
, shopkeeper
);
792 pline("%s gladly accepts %s but cannot pay you at present.",
793 Monnam(shopkeeper
), doname(obj
));
795 pline("You sold %s and got %ld gold piece%s.", doname(obj
), ltmp
,
801 int mode
; /* 0: deliver count 1: paged */
805 long totused
, thisused
;
812 for (bp
= bill
; bp
- bill
< ESHK(shopkeeper
)->billct
; bp
++)
814 ((obj
= bp_to_obj(bp
)) && obj
->quan
< bp
->bquan
))
819 impossible("doinvbill: no shopkeeper?");
823 if (page_line("Unpaid articles already used up:") || page_line(""))
827 for (bp
= bill
; bp
- bill
< ESHK(shopkeeper
)->billct
; bp
++) {
830 impossible("Bad shopkeeper administration.");
833 if (bp
->useup
|| bp
->bquan
> obj
->quan
) {
834 int cnt
, oquan
, uquan
;
837 uquan
= (bp
->useup
? bp
->bquan
: bp
->bquan
- oquan
);
838 thisused
= bp
->price
* uquan
;
840 obj
->quan
= uquan
; /* cheat doname */
841 (void) sprintf(buf
, "x - %s", doname(obj
));
842 obj
->quan
= oquan
; /* restore value */
843 for (cnt
= 0; buf
[cnt
]; cnt
++);
846 (void) sprintf(&buf
[cnt
], " %5ld zorkmids", thisused
);
851 (void) sprintf(buf
, "Total:%50ld zorkmids", totused
);
852 if (page_line("") || page_line(buf
))
872 tmp
= 10 * rnd((obj
->otyp
== EXPENSIVE_CAMERA
) ? 150 : 30);
883 if (obj
->otyp
== SCR_MAIL
)
891 tmp
= 10 * rnd(5 + (2000 / realhunger()));
898 if (ac
<= -10) /* probably impossible */
900 tmp
= 100 + ac
* ac
* rnd(10 + ac
);
903 if (obj
->otyp
< BOOMERANG
)
905 else if (obj
->otyp
== LONG_SWORD
||
906 obj
->otyp
== TWO_HANDED_SWORD
)
912 pline("Strange ..., carrying a chain?");
924 { /* not completely foolproof */
926 struct obj
*otmp
= invent
;
928 if (otmp
->olet
== FOOD_SYM
&& !otmp
->unpaid
)
929 tmp
+= objects
[otmp
->otyp
].nutrition
;
932 return ((tmp
<= 0) ? 1 : tmp
);
939 struct monst
*shkp
= shopkeeper
;
941 if (u
.uinshop
&& shkp
&& !shkp
->mfroz
&& !shkp
->msleep
&&
943 inroom(u
.ux
+ u
.dx
, u
.uy
+ u
.dy
) + 1 == u
.uinshop
&&
944 shkp
->mx
== ESHK(shkp
)->shk
.x
&& shkp
->my
== ESHK(shkp
)->shk
.y
&&
945 u
.ux
== ESHK(shkp
)->shd
.x
&& u
.uy
== ESHK(shkp
)->shd
.y
) {
946 pline("%s nimbly catches the %s.", Monnam(shkp
), xname(obj
));
947 obj
->nobj
= shkp
->minvent
;
955 * shk_move: return 1: he moved 0: he didnt -1: let m_move do it
962 const struct permonst
*mdat
= shkp
->data
;
963 xchar gx
, gy
, omx
, omy
, nx
, ny
, nix
, niy
;
967 schar shkroom
, chi
, chcnt
, cnt
;
968 boolean uondoor
= 0, satdoor
, avoid
= 0, badinv
;
976 if ((udist
= dist(omx
, omy
)) < 3) {
978 (void) hitu(shkp
, d(mdat
->damn
, mdat
->damd
) + 1);
981 if (ESHK(shkp
)->following
) {
982 if (strncmp(ESHK(shkp
)->customer
, plname
, PL_NSIZ
)) {
983 pline("Hello %s! I was looking for %s.",
984 plname
, ESHK(shkp
)->customer
);
985 ESHK(shkp
)->following
= 0;
988 if (!ESHK(shkp
)->robbed
) { /* impossible? */
989 ESHK(shkp
)->following
= 0;
992 if (moves
> followmsg
+ 4) {
993 pline("Hello %s! Didn't you forget to pay?",
1001 shkroom
= inroom(omx
, omy
);
1003 gx
= ESHK(shkp
)->shk
.x
;
1004 gy
= ESHK(shkp
)->shk
.y
;
1005 satdoor
= (gx
== omx
&& gy
== omy
);
1006 if (ESHK(shkp
)->following
|| ((z
= holetime()) >= 0 && z
* z
<= udist
)) {
1009 if (shkroom
< 0 || shkroom
!= inroom(u
.ux
, u
.uy
))
1011 return (-1); /* leave it to m_move */
1012 } else if (ANGRY(shkp
)) {
1013 long saveBlind
= Blind
;
1015 if (shkp
->mcansee
&& !Invis
&& cansee(omx
, omy
)) {
1022 #define GDIST(x,y) ((x-gx)*(x-gx)+(y-gy)*(y-gy))
1026 uondoor
= (u
.ux
== ESHK(shkp
)->shd
.x
&&
1027 u
.uy
== ESHK(shkp
)->shd
.y
);
1029 if (ESHK(shkp
)->billct
)
1030 pline("Hello %s! Will you please pay before leaving?",
1032 badinv
= (carrying(PICK_AXE
) || carrying(ICE_BOX
));
1033 if (satdoor
&& badinv
)
1037 avoid
= (u
.uinshop
&& dist(gx
, gy
) > 8);
1041 if (((!ESHK(shkp
)->robbed
&& !ESHK(shkp
)->billct
) || avoid
)
1042 && GDIST(omx
, omy
) < 3) {
1043 if (!badinv
&& !online(omx
, omy
))
1050 if (omx
== gx
&& omy
== gy
)
1058 cnt
= mfndpos(shkp
, poss
, info
, ALLOW_SSM
);
1059 if (avoid
&& uondoor
) { /* perhaps we cannot avoid him */
1060 for (i
= 0; i
< cnt
; i
++)
1061 if (!(info
[i
] & NOTONL
))
1069 for (i
= 0; i
< cnt
; i
++) {
1072 if (levl
[nx
][ny
].typ
== ROOM
1073 || shkroom
!= ESHK(shkp
)->shoproom
1074 || ESHK(shkp
)->following
) {
1076 /* cater for stupid compilers */
1079 if (uondoor
&& (ib
= sobj_at(ICE_BOX
, nx
, ny
))) {
1085 if (avoid
&& (info
[i
] & NOTONL
))
1087 if ((!appr
&& !rn2(++chcnt
)) ||
1089 (appr
&& (zz
= GDIST(nix
, niy
)) && zz
> GDIST(nx
, ny
))
1091 (appr
&& GDIST(nx
, ny
) < GDIST(nix
, niy
))
1100 if (nix
!= omx
|| niy
!= omy
) {
1101 if (info
[chi
] & ALLOW_M
) {
1102 mtmp
= m_at(nix
, niy
);
1104 panic("error in shk_move");
1105 if (hitmm(shkp
, mtmp
) == 1 && rn2(3) &&
1106 hitmm(mtmp
, shkp
) == 2)
1109 } else if (info
[chi
] & ALLOW_U
) {
1110 (void) hitu(shkp
, d(mdat
->damn
, mdat
->damd
) + 1);
1125 /* He is digging in the shop. */
1131 if (u
.utraptype
== TT_PIT
)
1132 pline("\"Be careful, sir, or you might fall through the floor.\"");
1134 pline("\"Please, do not damage the floor here.\"");
1135 } else if (dist(shopkeeper
->mx
, shopkeeper
->my
) < 3) {
1136 struct obj
*obj
, *obj2
;
1138 pline("%s grabs your backpack!", shkname(shopkeeper
));
1139 for (obj
= invent
; obj
; obj
= obj2
) {
1144 obj
->nobj
= shopkeeper
->minvent
;
1145 shopkeeper
->minvent
= obj
;
1154 online(int x
, int y
)
1156 return (x
== u
.ux
|| y
== u
.uy
||
1157 (x
- u
.ux
) * (x
- u
.ux
) == (y
- u
.uy
) * (y
- u
.uy
));
1160 /* Does this monster follow me downstairs? */
1165 return (mtmp
->mtame
|| strchr("1TVWZi&, ", mtmp
->data
->mlet
)
1167 || (mtmp
->isshk
&& ESHK(mtmp
)->following
)