1 /* $NetBSD: hack.shk.c,v 1.10 2009/06/07 20:13:18 dholland 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.10 2009/06/07 20:13:18 dholland 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 struct obj
*bp_to_obj(struct bill_x
*);
81 static int getprice(struct obj
*);
82 static int realhunger(void);
87 struct monst
*shopkeeper
= 0;
88 struct obj
*billobjs
= 0;
90 obfree(struct obj
*obj
, struct obj
*merge
)
103 addtobill(struct obj
*obj
)
107 subfrombill(struct obj
*obj
)
111 splitbill(struct obj
*o1
, struct obj
*o2
)
129 shkdead(struct monst
*m
)
133 shkcatch(struct obj
*obj
)
138 shk_move(struct monst
*m
)
143 replshk(struct monst
*mtmp
, struct monst
*mtmp2
)
147 shkname(struct monst
*m
)
153 #include "hack.mfndpos.h"
154 #include "def.mkroom.h"
155 #include "def.eshk.h"
157 #define ESHK(mon) ((struct eshk *)(&(mon->mextra[0])))
158 #define NOTANGRY(mon) mon->mpeaceful
159 #define ANGRY(mon) !NOTANGRY(mon)
162 * Descriptor of current shopkeeper. Note that the bill need not be
163 * per-shopkeeper, since it is valid only when in a shop.
165 static struct monst
*shopkeeper
= 0;
166 static struct bill_x
*bill
;
167 static int shlevel
= 0; /* level of this shopkeeper */
168 struct obj
*billobjs
; /* objects on bill with bp->useup */
169 /* only accessed here and by save & restore */
170 static long int total
; /* filled by addupbill() */
171 static long int followmsg
; /* last time of follow message */
174 invariants: obj->unpaid iff onbill(obj) [unless bp->useup]
175 obj->quan <= bp->bquan
179 const char shtypes
[] = { /* 8 shoptypes: 7 specialized, 1 mixed */
180 RING_SYM
, WAND_SYM
, WEAPON_SYM
, FOOD_SYM
, SCROLL_SYM
,
181 POTION_SYM
, ARMOR_SYM
, 0
184 static const char *const shopnam
[] = {
185 "engagement ring", "walking cane", "antique weapon",
186 "delicatessen", "second hand book", "liquor",
187 "used armor", "assorted antiques"
191 shkname(struct monst
*mtmp
) /* called in do_name.c */
193 return (ESHK(mtmp
)->shknam
);
197 shkdead(struct monst
*mtmp
) /* called in mon.c */
199 struct eshk
*eshk
= ESHK(mtmp
);
201 if (eshk
->shoplevel
== dlevel
)
202 rooms
[eshk
->shoproom
].rtype
= 0;
203 if (mtmp
== shopkeeper
) {
206 bill
= (struct bill_x
*) - 1000; /* dump core when
212 replshk(struct monst
*mtmp
, struct monst
*mtmp2
)
214 if (mtmp
== shopkeeper
) {
216 bill
= &(ESHK(shopkeeper
)->bill
[0]);
222 { /* caller has checked that shopkeeper exists */
223 /* either we paid or left the shop or he just died */
226 for (obj
= invent
; obj
; obj
= obj
->nobj
)
228 for (obj
= fobj
; obj
; obj
= obj
->nobj
)
230 for (obj
= fcobj
; obj
; obj
= obj
->nobj
)
232 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
233 for (obj
= mtmp
->minvent
; obj
; obj
= obj
->nobj
)
235 for (mtmp
= fallen_down
; mtmp
; mtmp
= mtmp
->nmon
)
236 for (obj
= mtmp
->minvent
; obj
; obj
= obj
->nobj
)
238 while ((obj
= billobjs
) != NULL
) {
239 billobjs
= obj
->nobj
;
242 ESHK(shopkeeper
)->billct
= 0;
247 { /* delivers result in total */
248 /* caller has checked that shopkeeper exists */
249 int ct
= ESHK(shopkeeper
)->billct
;
250 struct bill_x
*bp
= bill
;
253 total
+= bp
->price
* bp
->bquan
;
261 int roomno
= inroom(u
.ux
, u
.uy
);
263 /* Did we just leave a shop? */
265 (u
.uinshop
!= roomno
+ 1 || shlevel
!= dlevel
|| !shopkeeper
)) {
267 if (ESHK(shopkeeper
)->billct
) {
268 if (inroom(shopkeeper
->mx
, shopkeeper
->my
)
269 == u
.uinshop
- 1) /* ab@unido */
270 pline("Somehow you escaped the shop without paying!");
272 pline("You stole for a total worth of %ld zorkmids.",
274 ESHK(shopkeeper
)->robbed
+= total
;
276 if ((rooms
[ESHK(shopkeeper
)->shoproom
].rtype
== GENERAL
)
278 ESHK(shopkeeper
)->following
= 1;
285 /* Did we just enter a zoo of some kind? */
287 int rt
= rooms
[roomno
].rtype
;
290 pline("Welcome to David's treasure zoo!");
291 } else if (rt
== SWAMP
) {
292 pline("It looks rather muddy down here.");
293 } else if (rt
== MORGUE
) {
295 pline("Go away! Go away!");
297 pline("You get an uncanny feeling ...");
301 rooms
[roomno
].rtype
= 0;
302 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
303 if (rt
!= ZOO
|| !rn2(3))
307 /* Did we just enter a shop? */
308 if (roomno
>= 0 && rooms
[roomno
].rtype
>= 8) {
309 if (shlevel
!= dlevel
|| !shopkeeper
310 || ESHK(shopkeeper
)->shoproom
!= roomno
)
313 rooms
[roomno
].rtype
= 0;
315 } else if (!u
.uinshop
) {
316 if (!ESHK(shopkeeper
)->visitct
||
317 strncmp(ESHK(shopkeeper
)->customer
, plname
, PL_NSIZ
)) {
319 /* He seems to be new here */
320 ESHK(shopkeeper
)->visitct
= 0;
321 ESHK(shopkeeper
)->following
= 0;
322 (void) strncpy(ESHK(shopkeeper
)->customer
, plname
, PL_NSIZ
);
323 NOTANGRY(shopkeeper
) = 1;
325 if (!ESHK(shopkeeper
)->following
) {
328 pline("Hello %s! Welcome%s to %s's %s shop!",
330 ESHK(shopkeeper
)->visitct
++ ? " again" : "",
332 shopnam
[rooms
[ESHK(shopkeeper
)->shoproom
].rtype
- 8]);
333 box
= carrying(ICE_BOX
);
334 pick
= carrying(PICK_AXE
);
336 if (dochug(shopkeeper
)) {
337 u
.uinshop
= 0; /* he died moving */
340 pline("Will you please leave your %s outside?",
341 (box
&& pick
) ? "box and pick-axe" :
342 box
? "box" : "pick-axe");
345 u
.uinshop
= roomno
+ 1;
355 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
356 if (mtmp
->isshk
&& ESHK(mtmp
)->shoproom
== roomno
357 && ESHK(mtmp
)->shoplevel
== dlevel
) {
359 bill
= &(ESHK(shopkeeper
)->bill
[0]);
361 if (ANGRY(shopkeeper
) &&
362 strncmp(ESHK(shopkeeper
)->customer
, plname
, PL_NSIZ
))
363 NOTANGRY(shopkeeper
) = 1;
365 * billobjs = 0; -- this is wrong if we save in a
369 * (and it is harmless to have too many things in
376 bill
= (struct bill_x
*) - 1000; /* dump core when referenced */
379 static struct bill_x
*
380 onbill(struct obj
*obj
)
385 for (bp
= bill
; bp
< &bill
[ESHK(shopkeeper
)->billct
]; bp
++)
386 if (bp
->bo_id
== obj
->o_id
) {
388 pline("onbill: paid obj on bill?");
392 pline("onbill: unpaid obj not on bill?");
396 /* called with two args on merge */
398 obfree(struct obj
*obj
, struct obj
*merge
)
400 struct bill_x
*bp
= onbill(obj
);
405 obj
->unpaid
= 0; /* only for doinvbill */
406 obj
->nobj
= billobjs
;
412 /* this used to be a rename */
413 impossible("obfree: not on bill??");
416 /* this was a merger */
417 bpm
->bquan
+= bp
->bquan
;
418 ESHK(shopkeeper
)->billct
--;
419 *bp
= bill
[ESHK(shopkeeper
)->billct
];
426 pay(long tmp
, struct monst
*shkp
)
428 long robbed
= ESHK(shkp
)->robbed
;
437 ESHK(shkp
)->robbed
= robbed
;
451 for (shkp
= fmon
; shkp
; shkp
= shkp
->nmon
)
452 if (shkp
->isshk
&& dist(shkp
->mx
, shkp
->my
) < 3)
454 if (!shkp
&& u
.uinshop
&&
455 inroom(shopkeeper
->mx
, shopkeeper
->my
) == ESHK(shopkeeper
)->shoproom
)
459 pline("There is nobody here to receive your payment.");
462 ltmp
= ESHK(shkp
)->robbed
;
463 if (shkp
!= shopkeeper
&& NOTANGRY(shkp
)) {
465 pline("You do not owe %s anything.", monnam(shkp
));
466 } else if (!u
.ugold
) {
467 pline("You have no money.");
469 long ugold
= u
.ugold
;
471 if (u
.ugold
> ltmp
) {
472 pline("You give %s the %ld gold pieces he asked for.",
476 pline("You give %s all your gold.", monnam(shkp
));
479 if (ugold
< ltmp
/ 2) {
480 pline("Unfortunately, he doesn't look satisfied.");
482 ESHK(shkp
)->robbed
= 0;
483 ESHK(shkp
)->following
= 0;
484 if (ESHK(shkp
)->shoplevel
!= dlevel
) {
486 * For convenience's sake, let him
489 shkp
->minvent
= 0; /* %% */
497 if (!ESHK(shkp
)->billct
) {
498 pline("You do not owe %s anything.", monnam(shkp
));
500 pline("Moreover, you have no money.");
503 if (ESHK(shkp
)->robbed
) {
504 #define min(a,b) ((a<b)?a:b)
505 pline("But since his shop has been robbed recently,");
506 pline("you %srepay %s's expenses.",
507 (u
.ugold
< ESHK(shkp
)->robbed
) ? "partially " : "",
509 pay(min(u
.ugold
, ESHK(shkp
)->robbed
), shkp
);
510 ESHK(shkp
)->robbed
= 0;
514 pline("But in order to appease %s,",
515 amonnam(shkp
, "angry"));
516 if (u
.ugold
>= 1000) {
518 pline(" you give him 1000 gold pieces.");
521 pline(" you give him all your money.");
524 if (strncmp(ESHK(shkp
)->customer
, plname
, PL_NSIZ
)
526 pline("%s calms down.", Monnam(shkp
));
529 pline("%s is as angry as ever.",
534 if (shkp
!= shopkeeper
) {
535 impossible("dopay: not to shopkeeper?");
540 for (pass
= 0; pass
<= 1; pass
++) {
542 while (tmp
< ESHK(shopkeeper
)->billct
) {
544 if (!pass
&& !bp
->useup
) {
550 bill
[tmp
] = bill
[--ESHK(shopkeeper
)->billct
];
553 pline("Thank you for shopping in %s's %s store!",
555 shopnam
[rooms
[ESHK(shopkeeper
)->shoproom
].rtype
- 8]);
556 NOTANGRY(shopkeeper
) = 1;
560 /* return 1 if paid successfully */
561 /* 0 if not enough money */
562 /* -1 if object could not be found (but was paid) */
564 dopayobj(struct bill_x
*bp
)
569 /* find the object on one of the lists */
573 impossible("Shopkeeper administration out of order.");
574 setpaid(); /* be nice to the player */
577 if (!obj
->unpaid
&& !bp
->useup
) {
578 impossible("Paid object on bill??");
582 ltmp
= bp
->price
* bp
->bquan
;
583 if (ANGRY(shopkeeper
))
585 if (u
.ugold
< ltmp
) {
586 pline("You don't have gold enough to pay %s.",
591 pay(ltmp
, shopkeeper
);
592 pline("You bought %s for %ld gold piece%s.",
593 doname(obj
), ltmp
, plur(ltmp
));
595 struct obj
*otmp
= billobjs
;
597 billobjs
= obj
->nobj
;
599 while (otmp
&& otmp
->nobj
!= obj
)
602 otmp
->nobj
= obj
->nobj
;
604 pline("Error in shopkeeper administration.");
611 /* routine called after dying (or quitting) with nonempty bill */
615 if (shlevel
== dlevel
&& shopkeeper
&& ESHK(shopkeeper
)->billct
) {
617 if (total
> u
.ugold
) {
618 shopkeeper
->mgold
+= u
.ugold
;
620 pline("%s comes and takes all your possessions.",
624 shopkeeper
->mgold
+= total
;
625 pline("%s comes and takes the %ld zorkmids you owed him.",
626 Monnam(shopkeeper
), total
);
628 setpaid(); /* in case we create bones */
632 /* find obj on one of the lists */
634 bp_to_obj(struct bill_x
*bp
)
638 unsigned id
= bp
->bo_id
;
641 obj
= o_on(id
, billobjs
);
642 else if (!(obj
= o_on(id
, invent
)) &&
643 !(obj
= o_on(id
, fobj
)) &&
644 !(obj
= o_on(id
, fcobj
))) {
645 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
646 if ((obj
= o_on(id
, mtmp
->minvent
)) != NULL
)
648 for (mtmp
= fallen_down
; mtmp
; mtmp
= mtmp
->nmon
)
649 if ((obj
= o_on(id
, mtmp
->minvent
)) != NULL
)
655 /* called in hack.c when we pickup an object */
657 addtobill(struct obj
*obj
)
661 (u
.ux
== ESHK(shopkeeper
)->shk
.x
&& u
.uy
== ESHK(shopkeeper
)->shk
.y
) ||
662 (u
.ux
== ESHK(shopkeeper
)->shd
.x
&& u
.uy
== ESHK(shopkeeper
)->shd
.y
) ||
663 onbill(obj
) /* perhaps we threw it away earlier */
666 if (ESHK(shopkeeper
)->billct
== BILLSZ
) {
667 pline("You got that for free!");
670 bp
= &bill
[ESHK(shopkeeper
)->billct
];
671 bp
->bo_id
= obj
->o_id
;
672 bp
->bquan
= obj
->quan
;
674 bp
->price
= getprice(obj
);
675 ESHK(shopkeeper
)->billct
++;
680 splitbill(struct obj
*obj
, struct obj
*otmp
)
682 /* otmp has been split off from obj */
687 impossible("splitbill: not on bill?");
690 if (bp
->bquan
< otmp
->quan
) {
691 impossible("Negative quantity on bill??");
693 if (bp
->bquan
== otmp
->quan
) {
694 impossible("Zero quantity on bill??");
696 bp
->bquan
-= otmp
->quan
;
698 /* addtobill(otmp); */
699 if (ESHK(shopkeeper
)->billct
== BILLSZ
)
703 bp
= &bill
[ESHK(shopkeeper
)->billct
];
704 bp
->bo_id
= otmp
->o_id
;
705 bp
->bquan
= otmp
->quan
;
708 ESHK(shopkeeper
)->billct
++;
713 subfrombill(struct obj
*obj
)
719 if (!inshop() || (u
.ux
== ESHK(shopkeeper
)->shk
.x
&& u
.uy
== ESHK(shopkeeper
)->shk
.y
) ||
720 (u
.ux
== ESHK(shopkeeper
)->shd
.x
&& u
.uy
== ESHK(shopkeeper
)->shd
.y
))
722 if ((bp
= onbill(obj
)) != 0) {
724 if (bp
->bquan
> obj
->quan
) {
727 bp
->bo_id
= otmp
->o_id
= flags
.ident
++;
728 otmp
->quan
= (bp
->bquan
-= obj
->quan
);
729 otmp
->owt
= 0; /* superfluous */
732 otmp
->nobj
= billobjs
;
736 ESHK(shopkeeper
)->billct
--;
737 *bp
= bill
[ESHK(shopkeeper
)->billct
];
741 pline("%s didn't notice.", Monnam(shopkeeper
));
745 /* he dropped something of his own - probably wants to sell it */
746 if (shopkeeper
->msleep
|| shopkeeper
->mfroz
||
747 inroom(shopkeeper
->mx
, shopkeeper
->my
) != ESHK(shopkeeper
)->shoproom
)
749 if (ESHK(shopkeeper
)->billct
== BILLSZ
||
750 ((tmp
= shtypes
[rooms
[ESHK(shopkeeper
)->shoproom
].rtype
- 8]) && tmp
!= obj
->olet
)
751 || strchr("_0", obj
->olet
)) {
752 pline("%s seems not interested.", Monnam(shopkeeper
));
755 ltmp
= getprice(obj
) * obj
->quan
;
756 if (ANGRY(shopkeeper
)) {
758 NOTANGRY(shopkeeper
) = 1;
761 if (ESHK(shopkeeper
)->robbed
) {
762 if ((ESHK(shopkeeper
)->robbed
-= ltmp
) < 0)
763 ESHK(shopkeeper
)->robbed
= 0;
764 pline("Thank you for your contribution to restock this recently plundered shop.");
767 if (ltmp
> shopkeeper
->mgold
)
768 ltmp
= shopkeeper
->mgold
;
769 pay(-ltmp
, shopkeeper
);
771 pline("%s gladly accepts %s but cannot pay you at present.",
772 Monnam(shopkeeper
), doname(obj
));
774 pline("You sold %s and got %ld gold piece%s.", doname(obj
), ltmp
,
778 /* mode: 0: deliver count 1: paged */
784 long totused
, thisused
;
791 for (bp
= bill
; bp
- bill
< ESHK(shopkeeper
)->billct
; bp
++)
793 ((obj
= bp_to_obj(bp
)) && obj
->quan
< bp
->bquan
))
798 impossible("doinvbill: no shopkeeper?");
802 if (page_line("Unpaid articles already used up:") || page_line(""))
806 for (bp
= bill
; bp
- bill
< ESHK(shopkeeper
)->billct
; bp
++) {
809 impossible("Bad shopkeeper administration.");
812 if (bp
->useup
|| bp
->bquan
> obj
->quan
) {
813 int cnt
, oquan
, uquan
;
816 uquan
= (bp
->useup
? bp
->bquan
: bp
->bquan
- oquan
);
817 thisused
= bp
->price
* uquan
;
819 obj
->quan
= uquan
; /* cheat doname */
820 (void) snprintf(buf
, sizeof(buf
),
821 "x - %s", doname(obj
));
822 obj
->quan
= oquan
; /* restore value */
823 for (cnt
= 0; buf
[cnt
]; cnt
++);
826 (void) snprintf(buf
+cnt
, sizeof(buf
)-cnt
,
827 " %5ld zorkmids", thisused
);
832 (void) snprintf(buf
, sizeof(buf
), "Total:%50ld zorkmids", totused
);
833 if (page_line("") || page_line(buf
))
843 getprice(struct obj
*obj
)
852 tmp
= 10 * rnd((obj
->otyp
== EXPENSIVE_CAMERA
) ? 150 : 30);
863 if (obj
->otyp
== SCR_MAIL
)
871 tmp
= 10 * rnd(5 + (2000 / realhunger()));
878 if (ac
<= -10) /* probably impossible */
880 tmp
= 100 + ac
* ac
* rnd(10 + ac
);
883 if (obj
->otyp
< BOOMERANG
)
885 else if (obj
->otyp
== LONG_SWORD
||
886 obj
->otyp
== TWO_HANDED_SWORD
)
892 pline("Strange ..., carrying a chain?");
904 { /* not completely foolproof */
906 struct obj
*otmp
= invent
;
908 if (otmp
->olet
== FOOD_SYM
&& !otmp
->unpaid
)
909 tmp
+= objects
[otmp
->otyp
].nutrition
;
912 return ((tmp
<= 0) ? 1 : tmp
);
916 shkcatch(struct obj
*obj
)
918 struct monst
*shkp
= shopkeeper
;
920 if (u
.uinshop
&& shkp
&& !shkp
->mfroz
&& !shkp
->msleep
&&
922 inroom(u
.ux
+ u
.dx
, u
.uy
+ u
.dy
) + 1 == u
.uinshop
&&
923 shkp
->mx
== ESHK(shkp
)->shk
.x
&& shkp
->my
== ESHK(shkp
)->shk
.y
&&
924 u
.ux
== ESHK(shkp
)->shd
.x
&& u
.uy
== ESHK(shkp
)->shd
.y
) {
925 pline("%s nimbly catches the %s.", Monnam(shkp
), xname(obj
));
926 obj
->nobj
= shkp
->minvent
;
934 * shk_move: return 1: he moved 0: he didnt -1: let m_move do it
937 shk_move(struct monst
*shkp
)
940 const struct permonst
*mdat
= shkp
->data
;
941 xchar gx
, gy
, omx
, omy
, nx
, ny
, nix
, niy
;
945 schar shkroom
, chi
, chcnt
, cnt
;
946 boolean uondoor
= 0, satdoor
, avoid
= 0, badinv
;
954 if ((udist
= dist(omx
, omy
)) < 3) {
956 (void) hitu(shkp
, d(mdat
->damn
, mdat
->damd
) + 1);
959 if (ESHK(shkp
)->following
) {
960 if (strncmp(ESHK(shkp
)->customer
, plname
, PL_NSIZ
)) {
961 pline("Hello %s! I was looking for %s.",
962 plname
, ESHK(shkp
)->customer
);
963 ESHK(shkp
)->following
= 0;
966 if (!ESHK(shkp
)->robbed
) { /* impossible? */
967 ESHK(shkp
)->following
= 0;
970 if (moves
> followmsg
+ 4) {
971 pline("Hello %s! Didn't you forget to pay?",
979 shkroom
= inroom(omx
, omy
);
981 gx
= ESHK(shkp
)->shk
.x
;
982 gy
= ESHK(shkp
)->shk
.y
;
983 satdoor
= (gx
== omx
&& gy
== omy
);
984 if (ESHK(shkp
)->following
|| ((z
= holetime()) >= 0 && z
* z
<= udist
)) {
987 if (shkroom
< 0 || shkroom
!= inroom(u
.ux
, u
.uy
))
989 return (-1); /* leave it to m_move */
990 } else if (ANGRY(shkp
)) {
991 long saveBlind
= Blind
;
993 if (shkp
->mcansee
&& !Invis
&& cansee(omx
, omy
)) {
1000 #define GDIST(x,y) ((x-gx)*(x-gx)+(y-gy)*(y-gy))
1004 uondoor
= (u
.ux
== ESHK(shkp
)->shd
.x
&&
1005 u
.uy
== ESHK(shkp
)->shd
.y
);
1007 if (ESHK(shkp
)->billct
)
1008 pline("Hello %s! Will you please pay before leaving?",
1010 badinv
= (carrying(PICK_AXE
) || carrying(ICE_BOX
));
1011 if (satdoor
&& badinv
)
1015 avoid
= (u
.uinshop
&& dist(gx
, gy
) > 8);
1019 if (((!ESHK(shkp
)->robbed
&& !ESHK(shkp
)->billct
) || avoid
)
1020 && GDIST(omx
, omy
) < 3) {
1021 if (!badinv
&& !online(omx
, omy
))
1028 if (omx
== gx
&& omy
== gy
)
1036 cnt
= mfndpos(shkp
, poss
, info
, ALLOW_SSM
);
1037 if (avoid
&& uondoor
) { /* perhaps we cannot avoid him */
1038 for (i
= 0; i
< cnt
; i
++)
1039 if (!(info
[i
] & NOTONL
))
1047 for (i
= 0; i
< cnt
; i
++) {
1050 if (levl
[nx
][ny
].typ
== ROOM
1051 || shkroom
!= ESHK(shkp
)->shoproom
1052 || ESHK(shkp
)->following
) {
1054 /* cater for stupid compilers */
1057 if (uondoor
&& (ib
= sobj_at(ICE_BOX
, nx
, ny
))) {
1063 if (avoid
&& (info
[i
] & NOTONL
))
1065 if ((!appr
&& !rn2(++chcnt
)) ||
1067 (appr
&& (zz
= GDIST(nix
, niy
)) && zz
> GDIST(nx
, ny
))
1069 (appr
&& GDIST(nx
, ny
) < GDIST(nix
, niy
))
1078 if (nix
!= omx
|| niy
!= omy
) {
1079 if (info
[chi
] & ALLOW_M
) {
1080 mtmp
= m_at(nix
, niy
);
1082 panic("error in shk_move");
1083 if (hitmm(shkp
, mtmp
) == 1 && rn2(3) &&
1084 hitmm(mtmp
, shkp
) == 2)
1087 } else if (info
[chi
] & ALLOW_U
) {
1088 (void) hitu(shkp
, d(mdat
->damn
, mdat
->damd
) + 1);
1103 /* He is digging in the shop. */
1109 if (u
.utraptype
== TT_PIT
)
1110 pline("\"Be careful, sir, or you might fall through the floor.\"");
1112 pline("\"Please, do not damage the floor here.\"");
1113 } else if (dist(shopkeeper
->mx
, shopkeeper
->my
) < 3) {
1114 struct obj
*obj
, *obj2
;
1116 pline("%s grabs your backpack!", shkname(shopkeeper
));
1117 for (obj
= invent
; obj
; obj
= obj2
) {
1122 obj
->nobj
= shopkeeper
->minvent
;
1123 shopkeeper
->minvent
= obj
;
1132 online(int x
, int y
)
1134 return (x
== u
.ux
|| y
== u
.uy
||
1135 (x
- u
.ux
) * (x
- u
.ux
) == (y
- u
.uy
) * (y
- u
.uy
));
1138 /* Does this monster follow me downstairs? */
1140 follower(struct monst
*mtmp
)
1142 return (mtmp
->mtame
|| strchr("1TVWZi&, ", mtmp
->data
->mlet
)
1144 || (mtmp
->isshk
&& ESHK(mtmp
)->following
)