]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.shk.c
c24ecdc4ee6135f03955d34500fa02c0f73a42b3
1 /* $NetBSD: hack.shk.c,v 1.9 2009/06/07 18:30:39 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.9 2009/06/07 18:30:39 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 int getprice(struct obj
*);
81 static int realhunger(void);
86 struct monst
*shopkeeper
= 0;
87 struct obj
*billobjs
= 0;
89 obfree(struct obj
*obj
, struct obj
*merge
)
102 addtobill(struct obj
*obj
)
106 subfrombill(struct obj
*obj
)
110 splitbill(struct obj
*o1
, struct obj
*o2
)
128 shkdead(struct monst
*m
)
132 shkcatch(struct obj
*obj
)
137 shk_move(struct monst
*m
)
142 replshk(struct monst
*mtmp
, struct monst
*mtmp2
)
146 shkname(struct monst
*m
)
152 #include "hack.mfndpos.h"
153 #include "def.mkroom.h"
154 #include "def.eshk.h"
156 #define ESHK(mon) ((struct eshk *)(&(mon->mextra[0])))
157 #define NOTANGRY(mon) mon->mpeaceful
158 #define ANGRY(mon) !NOTANGRY(mon)
161 * Descriptor of current shopkeeper. Note that the bill need not be
162 * per-shopkeeper, since it is valid only when in a shop.
164 static struct monst
*shopkeeper
= 0;
165 static struct bill_x
*bill
;
166 static int shlevel
= 0; /* level of this shopkeeper */
167 struct obj
*billobjs
; /* objects on bill with bp->useup */
168 /* only accessed here and by save & restore */
169 static long int total
; /* filled by addupbill() */
170 static long int followmsg
; /* last time of follow message */
173 invariants: obj->unpaid iff onbill(obj) [unless bp->useup]
174 obj->quan <= bp->bquan
178 const char shtypes
[] = { /* 8 shoptypes: 7 specialized, 1 mixed */
179 RING_SYM
, WAND_SYM
, WEAPON_SYM
, FOOD_SYM
, SCROLL_SYM
,
180 POTION_SYM
, ARMOR_SYM
, 0
183 static const char *const shopnam
[] = {
184 "engagement ring", "walking cane", "antique weapon",
185 "delicatessen", "second hand book", "liquor",
186 "used armor", "assorted antiques"
190 shkname(struct monst
*mtmp
) /* called in do_name.c */
192 return (ESHK(mtmp
)->shknam
);
196 shkdead(struct monst
*mtmp
) /* called in mon.c */
198 struct eshk
*eshk
= ESHK(mtmp
);
200 if (eshk
->shoplevel
== dlevel
)
201 rooms
[eshk
->shoproom
].rtype
= 0;
202 if (mtmp
== shopkeeper
) {
205 bill
= (struct bill_x
*) - 1000; /* dump core when
211 replshk(struct monst
*mtmp
, struct monst
*mtmp2
)
213 if (mtmp
== shopkeeper
) {
215 bill
= &(ESHK(shopkeeper
)->bill
[0]);
221 { /* caller has checked that shopkeeper exists */
222 /* either we paid or left the shop or he just died */
225 for (obj
= invent
; obj
; obj
= obj
->nobj
)
227 for (obj
= fobj
; obj
; obj
= obj
->nobj
)
229 for (obj
= fcobj
; obj
; obj
= obj
->nobj
)
231 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
232 for (obj
= mtmp
->minvent
; obj
; obj
= obj
->nobj
)
234 for (mtmp
= fallen_down
; mtmp
; mtmp
= mtmp
->nmon
)
235 for (obj
= mtmp
->minvent
; obj
; obj
= obj
->nobj
)
237 while ((obj
= billobjs
) != NULL
) {
238 billobjs
= obj
->nobj
;
241 ESHK(shopkeeper
)->billct
= 0;
246 { /* delivers result in total */
247 /* caller has checked that shopkeeper exists */
248 int ct
= ESHK(shopkeeper
)->billct
;
249 struct bill_x
*bp
= bill
;
252 total
+= bp
->price
* bp
->bquan
;
260 int roomno
= inroom(u
.ux
, u
.uy
);
262 /* Did we just leave a shop? */
264 (u
.uinshop
!= roomno
+ 1 || shlevel
!= dlevel
|| !shopkeeper
)) {
266 if (ESHK(shopkeeper
)->billct
) {
267 if (inroom(shopkeeper
->mx
, shopkeeper
->my
)
268 == u
.uinshop
- 1) /* ab@unido */
269 pline("Somehow you escaped the shop without paying!");
271 pline("You stole for a total worth of %ld zorkmids.",
273 ESHK(shopkeeper
)->robbed
+= total
;
275 if ((rooms
[ESHK(shopkeeper
)->shoproom
].rtype
== GENERAL
)
277 ESHK(shopkeeper
)->following
= 1;
284 /* Did we just enter a zoo of some kind? */
286 int rt
= rooms
[roomno
].rtype
;
289 pline("Welcome to David's treasure zoo!");
290 } else if (rt
== SWAMP
) {
291 pline("It looks rather muddy down here.");
292 } else if (rt
== MORGUE
) {
294 pline("Go away! Go away!");
296 pline("You get an uncanny feeling ...");
300 rooms
[roomno
].rtype
= 0;
301 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
302 if (rt
!= ZOO
|| !rn2(3))
306 /* Did we just enter a shop? */
307 if (roomno
>= 0 && rooms
[roomno
].rtype
>= 8) {
308 if (shlevel
!= dlevel
|| !shopkeeper
309 || ESHK(shopkeeper
)->shoproom
!= roomno
)
312 rooms
[roomno
].rtype
= 0;
314 } else if (!u
.uinshop
) {
315 if (!ESHK(shopkeeper
)->visitct
||
316 strncmp(ESHK(shopkeeper
)->customer
, plname
, PL_NSIZ
)) {
318 /* He seems to be new here */
319 ESHK(shopkeeper
)->visitct
= 0;
320 ESHK(shopkeeper
)->following
= 0;
321 (void) strncpy(ESHK(shopkeeper
)->customer
, plname
, PL_NSIZ
);
322 NOTANGRY(shopkeeper
) = 1;
324 if (!ESHK(shopkeeper
)->following
) {
327 pline("Hello %s! Welcome%s to %s's %s shop!",
329 ESHK(shopkeeper
)->visitct
++ ? " again" : "",
331 shopnam
[rooms
[ESHK(shopkeeper
)->shoproom
].rtype
- 8]);
332 box
= carrying(ICE_BOX
);
333 pick
= carrying(PICK_AXE
);
335 if (dochug(shopkeeper
)) {
336 u
.uinshop
= 0; /* he died moving */
339 pline("Will you please leave your %s outside?",
340 (box
&& pick
) ? "box and pick-axe" :
341 box
? "box" : "pick-axe");
344 u
.uinshop
= roomno
+ 1;
354 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
355 if (mtmp
->isshk
&& ESHK(mtmp
)->shoproom
== roomno
356 && ESHK(mtmp
)->shoplevel
== dlevel
) {
358 bill
= &(ESHK(shopkeeper
)->bill
[0]);
360 if (ANGRY(shopkeeper
) &&
361 strncmp(ESHK(shopkeeper
)->customer
, plname
, PL_NSIZ
))
362 NOTANGRY(shopkeeper
) = 1;
364 * billobjs = 0; -- this is wrong if we save in a
368 * (and it is harmless to have too many things in
375 bill
= (struct bill_x
*) - 1000; /* dump core when referenced */
378 static struct bill_x
*
379 onbill(struct obj
*obj
)
384 for (bp
= bill
; bp
< &bill
[ESHK(shopkeeper
)->billct
]; bp
++)
385 if (bp
->bo_id
== obj
->o_id
) {
387 pline("onbill: paid obj on bill?");
391 pline("onbill: unpaid obj not on bill?");
395 /* called with two args on merge */
397 obfree(struct obj
*obj
, struct obj
*merge
)
399 struct bill_x
*bp
= onbill(obj
);
404 obj
->unpaid
= 0; /* only for doinvbill */
405 obj
->nobj
= billobjs
;
411 /* this used to be a rename */
412 impossible("obfree: not on bill??");
415 /* this was a merger */
416 bpm
->bquan
+= bp
->bquan
;
417 ESHK(shopkeeper
)->billct
--;
418 *bp
= bill
[ESHK(shopkeeper
)->billct
];
425 pay(long tmp
, struct monst
*shkp
)
427 long robbed
= ESHK(shkp
)->robbed
;
436 ESHK(shkp
)->robbed
= robbed
;
450 for (shkp
= fmon
; shkp
; shkp
= shkp
->nmon
)
451 if (shkp
->isshk
&& dist(shkp
->mx
, shkp
->my
) < 3)
453 if (!shkp
&& u
.uinshop
&&
454 inroom(shopkeeper
->mx
, shopkeeper
->my
) == ESHK(shopkeeper
)->shoproom
)
458 pline("There is nobody here to receive your payment.");
461 ltmp
= ESHK(shkp
)->robbed
;
462 if (shkp
!= shopkeeper
&& NOTANGRY(shkp
)) {
464 pline("You do not owe %s anything.", monnam(shkp
));
465 } else if (!u
.ugold
) {
466 pline("You have no money.");
468 long ugold
= u
.ugold
;
470 if (u
.ugold
> ltmp
) {
471 pline("You give %s the %ld gold pieces he asked for.",
475 pline("You give %s all your gold.", monnam(shkp
));
478 if (ugold
< ltmp
/ 2) {
479 pline("Unfortunately, he doesn't look satisfied.");
481 ESHK(shkp
)->robbed
= 0;
482 ESHK(shkp
)->following
= 0;
483 if (ESHK(shkp
)->shoplevel
!= dlevel
) {
485 * For convenience's sake, let him
488 shkp
->minvent
= 0; /* %% */
496 if (!ESHK(shkp
)->billct
) {
497 pline("You do not owe %s anything.", monnam(shkp
));
499 pline("Moreover, you have no money.");
502 if (ESHK(shkp
)->robbed
) {
503 #define min(a,b) ((a<b)?a:b)
504 pline("But since his shop has been robbed recently,");
505 pline("you %srepay %s's expenses.",
506 (u
.ugold
< ESHK(shkp
)->robbed
) ? "partially " : "",
508 pay(min(u
.ugold
, ESHK(shkp
)->robbed
), shkp
);
509 ESHK(shkp
)->robbed
= 0;
513 pline("But in order to appease %s,",
514 amonnam(shkp
, "angry"));
515 if (u
.ugold
>= 1000) {
517 pline(" you give him 1000 gold pieces.");
520 pline(" you give him all your money.");
523 if (strncmp(ESHK(shkp
)->customer
, plname
, PL_NSIZ
)
525 pline("%s calms down.", Monnam(shkp
));
528 pline("%s is as angry as ever.",
533 if (shkp
!= shopkeeper
) {
534 impossible("dopay: not to shopkeeper?");
539 for (pass
= 0; pass
<= 1; pass
++) {
541 while (tmp
< ESHK(shopkeeper
)->billct
) {
543 if (!pass
&& !bp
->useup
) {
549 bill
[tmp
] = bill
[--ESHK(shopkeeper
)->billct
];
552 pline("Thank you for shopping in %s's %s store!",
554 shopnam
[rooms
[ESHK(shopkeeper
)->shoproom
].rtype
- 8]);
555 NOTANGRY(shopkeeper
) = 1;
559 /* return 1 if paid successfully */
560 /* 0 if not enough money */
561 /* -1 if object could not be found (but was paid) */
563 dopayobj(struct bill_x
*bp
)
568 /* find the object on one of the lists */
572 impossible("Shopkeeper administration out of order.");
573 setpaid(); /* be nice to the player */
576 if (!obj
->unpaid
&& !bp
->useup
) {
577 impossible("Paid object on bill??");
581 ltmp
= bp
->price
* bp
->bquan
;
582 if (ANGRY(shopkeeper
))
584 if (u
.ugold
< ltmp
) {
585 pline("You don't have gold enough to pay %s.",
590 pay(ltmp
, shopkeeper
);
591 pline("You bought %s for %ld gold piece%s.",
592 doname(obj
), ltmp
, plur(ltmp
));
594 struct obj
*otmp
= billobjs
;
596 billobjs
= obj
->nobj
;
598 while (otmp
&& otmp
->nobj
!= obj
)
601 otmp
->nobj
= obj
->nobj
;
603 pline("Error in shopkeeper administration.");
610 /* routine called after dying (or quitting) with nonempty bill */
614 if (shlevel
== dlevel
&& shopkeeper
&& ESHK(shopkeeper
)->billct
) {
616 if (total
> u
.ugold
) {
617 shopkeeper
->mgold
+= u
.ugold
;
619 pline("%s comes and takes all your possessions.",
623 shopkeeper
->mgold
+= total
;
624 pline("%s comes and takes the %ld zorkmids you owed him.",
625 Monnam(shopkeeper
), total
);
627 setpaid(); /* in case we create bones */
631 /* find obj on one of the lists */
633 bp_to_obj(struct bill_x
*bp
)
637 unsigned id
= bp
->bo_id
;
640 obj
= o_on(id
, billobjs
);
641 else if (!(obj
= o_on(id
, invent
)) &&
642 !(obj
= o_on(id
, fobj
)) &&
643 !(obj
= o_on(id
, fcobj
))) {
644 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
645 if ((obj
= o_on(id
, mtmp
->minvent
)) != NULL
)
647 for (mtmp
= fallen_down
; mtmp
; mtmp
= mtmp
->nmon
)
648 if ((obj
= o_on(id
, mtmp
->minvent
)) != NULL
)
654 /* called in hack.c when we pickup an object */
656 addtobill(struct obj
*obj
)
660 (u
.ux
== ESHK(shopkeeper
)->shk
.x
&& u
.uy
== ESHK(shopkeeper
)->shk
.y
) ||
661 (u
.ux
== ESHK(shopkeeper
)->shd
.x
&& u
.uy
== ESHK(shopkeeper
)->shd
.y
) ||
662 onbill(obj
) /* perhaps we threw it away earlier */
665 if (ESHK(shopkeeper
)->billct
== BILLSZ
) {
666 pline("You got that for free!");
669 bp
= &bill
[ESHK(shopkeeper
)->billct
];
670 bp
->bo_id
= obj
->o_id
;
671 bp
->bquan
= obj
->quan
;
673 bp
->price
= getprice(obj
);
674 ESHK(shopkeeper
)->billct
++;
679 splitbill(struct obj
*obj
, struct obj
*otmp
)
681 /* otmp has been split off from obj */
686 impossible("splitbill: not on bill?");
689 if (bp
->bquan
< otmp
->quan
) {
690 impossible("Negative quantity on bill??");
692 if (bp
->bquan
== otmp
->quan
) {
693 impossible("Zero quantity on bill??");
695 bp
->bquan
-= otmp
->quan
;
697 /* addtobill(otmp); */
698 if (ESHK(shopkeeper
)->billct
== BILLSZ
)
702 bp
= &bill
[ESHK(shopkeeper
)->billct
];
703 bp
->bo_id
= otmp
->o_id
;
704 bp
->bquan
= otmp
->quan
;
707 ESHK(shopkeeper
)->billct
++;
712 subfrombill(struct obj
*obj
)
718 if (!inshop() || (u
.ux
== ESHK(shopkeeper
)->shk
.x
&& u
.uy
== ESHK(shopkeeper
)->shk
.y
) ||
719 (u
.ux
== ESHK(shopkeeper
)->shd
.x
&& u
.uy
== ESHK(shopkeeper
)->shd
.y
))
721 if ((bp
= onbill(obj
)) != 0) {
723 if (bp
->bquan
> obj
->quan
) {
726 bp
->bo_id
= otmp
->o_id
= flags
.ident
++;
727 otmp
->quan
= (bp
->bquan
-= obj
->quan
);
728 otmp
->owt
= 0; /* superfluous */
731 otmp
->nobj
= billobjs
;
735 ESHK(shopkeeper
)->billct
--;
736 *bp
= bill
[ESHK(shopkeeper
)->billct
];
740 pline("%s didn't notice.", Monnam(shopkeeper
));
744 /* he dropped something of his own - probably wants to sell it */
745 if (shopkeeper
->msleep
|| shopkeeper
->mfroz
||
746 inroom(shopkeeper
->mx
, shopkeeper
->my
) != ESHK(shopkeeper
)->shoproom
)
748 if (ESHK(shopkeeper
)->billct
== BILLSZ
||
749 ((tmp
= shtypes
[rooms
[ESHK(shopkeeper
)->shoproom
].rtype
- 8]) && tmp
!= obj
->olet
)
750 || strchr("_0", obj
->olet
)) {
751 pline("%s seems not interested.", Monnam(shopkeeper
));
754 ltmp
= getprice(obj
) * obj
->quan
;
755 if (ANGRY(shopkeeper
)) {
757 NOTANGRY(shopkeeper
) = 1;
760 if (ESHK(shopkeeper
)->robbed
) {
761 if ((ESHK(shopkeeper
)->robbed
-= ltmp
) < 0)
762 ESHK(shopkeeper
)->robbed
= 0;
763 pline("Thank you for your contribution to restock this recently plundered shop.");
766 if (ltmp
> shopkeeper
->mgold
)
767 ltmp
= shopkeeper
->mgold
;
768 pay(-ltmp
, shopkeeper
);
770 pline("%s gladly accepts %s but cannot pay you at present.",
771 Monnam(shopkeeper
), doname(obj
));
773 pline("You sold %s and got %ld gold piece%s.", doname(obj
), ltmp
,
777 /* mode: 0: deliver count 1: paged */
783 long totused
, thisused
;
790 for (bp
= bill
; bp
- bill
< ESHK(shopkeeper
)->billct
; bp
++)
792 ((obj
= bp_to_obj(bp
)) && obj
->quan
< bp
->bquan
))
797 impossible("doinvbill: no shopkeeper?");
801 if (page_line("Unpaid articles already used up:") || page_line(""))
805 for (bp
= bill
; bp
- bill
< ESHK(shopkeeper
)->billct
; bp
++) {
808 impossible("Bad shopkeeper administration.");
811 if (bp
->useup
|| bp
->bquan
> obj
->quan
) {
812 int cnt
, oquan
, uquan
;
815 uquan
= (bp
->useup
? bp
->bquan
: bp
->bquan
- oquan
);
816 thisused
= bp
->price
* uquan
;
818 obj
->quan
= uquan
; /* cheat doname */
819 (void) sprintf(buf
, "x - %s", doname(obj
));
820 obj
->quan
= oquan
; /* restore value */
821 for (cnt
= 0; buf
[cnt
]; cnt
++);
824 (void) sprintf(&buf
[cnt
], " %5ld zorkmids", thisused
);
829 (void) sprintf(buf
, "Total:%50ld zorkmids", totused
);
830 if (page_line("") || page_line(buf
))
840 getprice(struct obj
*obj
)
849 tmp
= 10 * rnd((obj
->otyp
== EXPENSIVE_CAMERA
) ? 150 : 30);
860 if (obj
->otyp
== SCR_MAIL
)
868 tmp
= 10 * rnd(5 + (2000 / realhunger()));
875 if (ac
<= -10) /* probably impossible */
877 tmp
= 100 + ac
* ac
* rnd(10 + ac
);
880 if (obj
->otyp
< BOOMERANG
)
882 else if (obj
->otyp
== LONG_SWORD
||
883 obj
->otyp
== TWO_HANDED_SWORD
)
889 pline("Strange ..., carrying a chain?");
901 { /* not completely foolproof */
903 struct obj
*otmp
= invent
;
905 if (otmp
->olet
== FOOD_SYM
&& !otmp
->unpaid
)
906 tmp
+= objects
[otmp
->otyp
].nutrition
;
909 return ((tmp
<= 0) ? 1 : tmp
);
913 shkcatch(struct obj
*obj
)
915 struct monst
*shkp
= shopkeeper
;
917 if (u
.uinshop
&& shkp
&& !shkp
->mfroz
&& !shkp
->msleep
&&
919 inroom(u
.ux
+ u
.dx
, u
.uy
+ u
.dy
) + 1 == u
.uinshop
&&
920 shkp
->mx
== ESHK(shkp
)->shk
.x
&& shkp
->my
== ESHK(shkp
)->shk
.y
&&
921 u
.ux
== ESHK(shkp
)->shd
.x
&& u
.uy
== ESHK(shkp
)->shd
.y
) {
922 pline("%s nimbly catches the %s.", Monnam(shkp
), xname(obj
));
923 obj
->nobj
= shkp
->minvent
;
931 * shk_move: return 1: he moved 0: he didnt -1: let m_move do it
934 shk_move(struct monst
*shkp
)
937 const struct permonst
*mdat
= shkp
->data
;
938 xchar gx
, gy
, omx
, omy
, nx
, ny
, nix
, niy
;
942 schar shkroom
, chi
, chcnt
, cnt
;
943 boolean uondoor
= 0, satdoor
, avoid
= 0, badinv
;
951 if ((udist
= dist(omx
, omy
)) < 3) {
953 (void) hitu(shkp
, d(mdat
->damn
, mdat
->damd
) + 1);
956 if (ESHK(shkp
)->following
) {
957 if (strncmp(ESHK(shkp
)->customer
, plname
, PL_NSIZ
)) {
958 pline("Hello %s! I was looking for %s.",
959 plname
, ESHK(shkp
)->customer
);
960 ESHK(shkp
)->following
= 0;
963 if (!ESHK(shkp
)->robbed
) { /* impossible? */
964 ESHK(shkp
)->following
= 0;
967 if (moves
> followmsg
+ 4) {
968 pline("Hello %s! Didn't you forget to pay?",
976 shkroom
= inroom(omx
, omy
);
978 gx
= ESHK(shkp
)->shk
.x
;
979 gy
= ESHK(shkp
)->shk
.y
;
980 satdoor
= (gx
== omx
&& gy
== omy
);
981 if (ESHK(shkp
)->following
|| ((z
= holetime()) >= 0 && z
* z
<= udist
)) {
984 if (shkroom
< 0 || shkroom
!= inroom(u
.ux
, u
.uy
))
986 return (-1); /* leave it to m_move */
987 } else if (ANGRY(shkp
)) {
988 long saveBlind
= Blind
;
990 if (shkp
->mcansee
&& !Invis
&& cansee(omx
, omy
)) {
997 #define GDIST(x,y) ((x-gx)*(x-gx)+(y-gy)*(y-gy))
1001 uondoor
= (u
.ux
== ESHK(shkp
)->shd
.x
&&
1002 u
.uy
== ESHK(shkp
)->shd
.y
);
1004 if (ESHK(shkp
)->billct
)
1005 pline("Hello %s! Will you please pay before leaving?",
1007 badinv
= (carrying(PICK_AXE
) || carrying(ICE_BOX
));
1008 if (satdoor
&& badinv
)
1012 avoid
= (u
.uinshop
&& dist(gx
, gy
) > 8);
1016 if (((!ESHK(shkp
)->robbed
&& !ESHK(shkp
)->billct
) || avoid
)
1017 && GDIST(omx
, omy
) < 3) {
1018 if (!badinv
&& !online(omx
, omy
))
1025 if (omx
== gx
&& omy
== gy
)
1033 cnt
= mfndpos(shkp
, poss
, info
, ALLOW_SSM
);
1034 if (avoid
&& uondoor
) { /* perhaps we cannot avoid him */
1035 for (i
= 0; i
< cnt
; i
++)
1036 if (!(info
[i
] & NOTONL
))
1044 for (i
= 0; i
< cnt
; i
++) {
1047 if (levl
[nx
][ny
].typ
== ROOM
1048 || shkroom
!= ESHK(shkp
)->shoproom
1049 || ESHK(shkp
)->following
) {
1051 /* cater for stupid compilers */
1054 if (uondoor
&& (ib
= sobj_at(ICE_BOX
, nx
, ny
))) {
1060 if (avoid
&& (info
[i
] & NOTONL
))
1062 if ((!appr
&& !rn2(++chcnt
)) ||
1064 (appr
&& (zz
= GDIST(nix
, niy
)) && zz
> GDIST(nx
, ny
))
1066 (appr
&& GDIST(nx
, ny
) < GDIST(nix
, niy
))
1075 if (nix
!= omx
|| niy
!= omy
) {
1076 if (info
[chi
] & ALLOW_M
) {
1077 mtmp
= m_at(nix
, niy
);
1079 panic("error in shk_move");
1080 if (hitmm(shkp
, mtmp
) == 1 && rn2(3) &&
1081 hitmm(mtmp
, shkp
) == 2)
1084 } else if (info
[chi
] & ALLOW_U
) {
1085 (void) hitu(shkp
, d(mdat
->damn
, mdat
->damd
) + 1);
1100 /* He is digging in the shop. */
1106 if (u
.utraptype
== TT_PIT
)
1107 pline("\"Be careful, sir, or you might fall through the floor.\"");
1109 pline("\"Please, do not damage the floor here.\"");
1110 } else if (dist(shopkeeper
->mx
, shopkeeper
->my
) < 3) {
1111 struct obj
*obj
, *obj2
;
1113 pline("%s grabs your backpack!", shkname(shopkeeper
));
1114 for (obj
= invent
; obj
; obj
= obj2
) {
1119 obj
->nobj
= shopkeeper
->minvent
;
1120 shopkeeper
->minvent
= obj
;
1129 online(int x
, int y
)
1131 return (x
== u
.ux
|| y
== u
.uy
||
1132 (x
- u
.ux
) * (x
- u
.ux
) == (y
- u
.uy
) * (y
- u
.uy
));
1135 /* Does this monster follow me downstairs? */
1137 follower(struct monst
*mtmp
)
1139 return (mtmp
->mtame
|| strchr("1TVWZi&, ", mtmp
->data
->mlet
)
1141 || (mtmp
->isshk
&& ESHK(mtmp
)->following
)