OSDN Git Service

f49f4e0a9be54958e87208355d8598219774cb84
[jnethack/source.git] / src / shk.c
1 /* NetHack 3.6  shk.c   $NHDT-Date: 1555201699 2019/04/14 00:28:19 $  $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.159 $ */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /*-Copyright (c) Robert Patrick Rankin, 2012. */
4 /* NetHack may be freely redistributed.  See license for details. */
5
6 /* JNetHack Copyright */
7 /* (c) Issei Numata, Naoki Hamada, Shigehiro Miyashita, 1994-2000  */
8 /* For 3.4-, Copyright (c) SHIRAKATA Kentaro, 2002-2019            */
9 /* JNetHack may be freely redistributed.  See license for details. */
10
11 #include "hack.h"
12
13 #define PAY_SOME 2
14 #define PAY_BUY 1
15 #define PAY_CANT 0 /* too poor */
16 #define PAY_SKIP (-1)
17 #define PAY_BROKE (-2)
18
19 STATIC_DCL void FDECL(makekops, (coord *));
20 STATIC_DCL void FDECL(call_kops, (struct monst *, BOOLEAN_P));
21 STATIC_DCL void FDECL(kops_gone, (BOOLEAN_P));
22
23 #define NOTANGRY(mon) ((mon)->mpeaceful)
24 #define ANGRY(mon) (!NOTANGRY(mon))
25 #define IS_SHOP(x) (rooms[x].rtype >= SHOPBASE)
26
27 #define muteshk(shkp)                       \
28     ((shkp)->msleeping || !(shkp)->mcanmove \
29      || (shkp)->data->msound <= MS_ANIMAL)
30
31 extern const struct shclass shtypes[]; /* defined in shknam.c */
32
33 STATIC_VAR NEARDATA long int followmsg; /* last time of follow message */
34 /*JP
35 STATIC_VAR const char and_its_contents[] = " and its contents";
36 */
37 STATIC_VAR const char and_its_contents[] = "\92\86\90g\82ð\8d\87\82í\82¹\82Ä";
38 #if 0 /*JP*/
39 STATIC_VAR const char the_contents_of[] = "the contents of ";
40 #endif
41
42 STATIC_DCL void FDECL(append_honorific, (char *));
43 STATIC_DCL long FDECL(addupbill, (struct monst *));
44 STATIC_DCL void FDECL(pacify_shk, (struct monst *));
45 STATIC_DCL struct bill_x *FDECL(onbill, (struct obj *, struct monst *,
46                                          BOOLEAN_P));
47 STATIC_DCL struct monst *FDECL(next_shkp, (struct monst *, BOOLEAN_P));
48 STATIC_DCL long FDECL(shop_debt, (struct eshk *));
49 STATIC_DCL char *FDECL(shk_owns, (char *, struct obj *));
50 STATIC_DCL char *FDECL(mon_owns, (char *, struct obj *));
51 STATIC_DCL void FDECL(clear_unpaid_obj, (struct monst *, struct obj *));
52 STATIC_DCL void FDECL(clear_unpaid, (struct monst *, struct obj *));
53 STATIC_DCL long FDECL(check_credit, (long, struct monst *));
54 STATIC_DCL void FDECL(pay, (long, struct monst *));
55 STATIC_DCL long FDECL(get_cost, (struct obj *, struct monst *));
56 STATIC_DCL long FDECL(set_cost, (struct obj *, struct monst *));
57 STATIC_DCL const char *FDECL(shk_embellish, (struct obj *, long));
58 STATIC_DCL long FDECL(cost_per_charge, (struct monst *, struct obj *,
59                                         BOOLEAN_P));
60 STATIC_DCL long FDECL(cheapest_item, (struct monst *));
61 STATIC_DCL int FDECL(dopayobj, (struct monst *, struct bill_x *,
62                                 struct obj **, int, BOOLEAN_P));
63 STATIC_DCL long FDECL(stolen_container, (struct obj *, struct monst *,
64                                          long, BOOLEAN_P));
65 STATIC_DCL long FDECL(getprice, (struct obj *, BOOLEAN_P));
66 STATIC_DCL void FDECL(shk_names_obj, (struct monst *, struct obj *,
67                                       const char *, long, const char *));
68 STATIC_DCL struct obj *FDECL(bp_to_obj, (struct bill_x *));
69 STATIC_DCL boolean FDECL(inherits, (struct monst *, int, int, BOOLEAN_P));
70 STATIC_DCL void FDECL(set_repo_loc, (struct monst *));
71 STATIC_DCL boolean NDECL(angry_shk_exists);
72 STATIC_DCL void FDECL(rile_shk, (struct monst *));
73 STATIC_DCL void FDECL(rouse_shk, (struct monst *, BOOLEAN_P));
74 STATIC_DCL void FDECL(remove_damage, (struct monst *, BOOLEAN_P));
75 STATIC_DCL void FDECL(sub_one_frombill, (struct obj *, struct monst *));
76 STATIC_DCL void FDECL(add_one_tobill, (struct obj *, BOOLEAN_P,
77                                        struct monst *));
78 STATIC_DCL void FDECL(dropped_container, (struct obj *, struct monst *,
79                                           BOOLEAN_P));
80 STATIC_DCL void FDECL(add_to_billobjs, (struct obj *));
81 STATIC_DCL void FDECL(bill_box_content, (struct obj *, BOOLEAN_P, BOOLEAN_P,
82                                          struct monst *));
83 STATIC_DCL boolean FDECL(rob_shop, (struct monst *));
84 STATIC_DCL void FDECL(deserted_shop, (char *));
85 STATIC_DCL boolean FDECL(special_stock, (struct obj *, struct monst *,
86                                          BOOLEAN_P));
87 #if 0 /*JP*//*\8eg\82í\82È\82¢*/
88 STATIC_DCL const char *FDECL(cad, (BOOLEAN_P));
89 #endif
90
91 /*
92         invariants: obj->unpaid iff onbill(obj) [unless bp->useup]
93                     obj->quan <= bp->bquan
94  */
95
96 /*JP
97 static const char *angrytexts[] = { "quite upset", "ticked off", "furious" };
98 */
99 static const char *angrytexts[] = { "\82©\82È\82è\93{\82Á\82½", "\95 \82ð\97§\82Ä\82½", "\8c\83\93{\82µ\82½" };
100
101 /*
102  *  Transfer money from inventory to monster when paying
103  *  shopkeepers, priests, oracle, succubus, and other demons.
104  *  Simple with only gold coins.
105  *  This routine will handle money changing when multiple
106  *  coin types is implemented, only appropriate
107  *  monsters will pay change.  (Peaceful shopkeepers, priests
108  *  and the oracle try to maintain goodwill while selling
109  *  their wares or services.  Angry monsters and all demons
110  *  will keep anything they get their hands on.
111  *  Returns the amount actually paid, so we can know
112  *  if the monster kept the change.
113  */
114 long
115 money2mon(mon, amount)
116 struct monst *mon;
117 long amount;
118 {
119     struct obj *ygold = findgold(invent);
120
121     if (amount <= 0) {
122         impossible("%s payment in money2mon!", amount ? "negative" : "zero");
123         return 0L;
124     }
125     if (!ygold || ygold->quan < amount) {
126         impossible("Paying without %s money?", ygold ? "enough" : "");
127         return 0L;
128     }
129
130     if (ygold->quan > amount)
131         ygold = splitobj(ygold, amount);
132     else if (ygold->owornmask)
133         remove_worn_item(ygold, FALSE); /* quiver */
134     freeinv(ygold);
135     add_to_minv(mon, ygold);
136     context.botl = 1;
137     return amount;
138 }
139
140 /*
141  *  Transfer money from monster to inventory.
142  *  Used when the shopkeeper pay for items, and when
143  *  the priest gives you money for an ale.
144  */
145 void
146 money2u(mon, amount)
147 struct monst *mon;
148 long amount;
149 {
150     struct obj *mongold = findgold(mon->minvent);
151
152     if (amount <= 0) {
153         impossible("%s payment in money2u!", amount ? "negative" : "zero");
154         return;
155     }
156     if (!mongold || mongold->quan < amount) {
157         impossible("%s paying without %s money?", a_monnam(mon),
158                    mongold ? "enough" : "");
159         return;
160     }
161
162     if (mongold->quan > amount)
163         mongold = splitobj(mongold, amount);
164     obj_extract_self(mongold);
165
166     if (!merge_choice(invent, mongold) && inv_cnt(FALSE) >= 52) {
167 /*JP
168         You("have no room for the money!");
169 */
170         You("\82¨\8bà\82ð\8e\9d\82Â\97]\97T\82ª\82È\82¢\81I");
171         dropy(mongold);
172     } else {
173         addinv(mongold);
174         context.botl = 1;
175     }
176 }
177
178 STATIC_OVL struct monst *
179 next_shkp(shkp, withbill)
180 register struct monst *shkp;
181 register boolean withbill;
182 {
183     for (; shkp; shkp = shkp->nmon) {
184         if (DEADMONSTER(shkp))
185             continue;
186         if (shkp->isshk && (ESHK(shkp)->billct || !withbill))
187             break;
188     }
189
190     if (shkp) {
191         if (NOTANGRY(shkp)) {
192             if (ESHK(shkp)->surcharge)
193                 pacify_shk(shkp);
194         } else {
195             if (!ESHK(shkp)->surcharge)
196                 rile_shk(shkp);
197         }
198     }
199     return shkp;
200 }
201
202 /* called in mon.c */
203 void
204 shkgone(mtmp)
205 struct monst *mtmp;
206 {
207     struct eshk *eshk = ESHK(mtmp);
208     struct mkroom *sroom = &rooms[eshk->shoproom - ROOMOFFSET];
209     struct obj *otmp;
210     char *p;
211     int sx, sy;
212
213     /* [BUG: some of this should be done on the shop level */
214     /*       even when the shk dies on a different level.] */
215     if (on_level(&eshk->shoplevel, &u.uz)) {
216         remove_damage(mtmp, TRUE);
217         sroom->resident = (struct monst *) 0;
218         if (!search_special(ANY_SHOP))
219             level.flags.has_shop = 0;
220
221         /* items on shop floor revert to ordinary objects */
222         for (sx = sroom->lx; sx <= sroom->hx; sx++)
223             for (sy = sroom->ly; sy <= sroom->hy; sy++)
224                 for (otmp = level.objects[sx][sy]; otmp;
225                      otmp = otmp->nexthere)
226                     otmp->no_charge = 0;
227
228         /* Make sure bill is set only when the
229            dead shk is the resident shk. */
230         if ((p = index(u.ushops, eshk->shoproom)) != 0) {
231             setpaid(mtmp);
232             eshk->bill_p = (struct bill_x *) 0;
233             /* remove eshk->shoproom from u.ushops */
234             do {
235                 *p = *(p + 1);
236             } while (*++p);
237         }
238     }
239 }
240
241 void
242 set_residency(shkp, zero_out)
243 register struct monst *shkp;
244 register boolean zero_out;
245 {
246     if (on_level(&(ESHK(shkp)->shoplevel), &u.uz))
247         rooms[ESHK(shkp)->shoproom - ROOMOFFSET].resident =
248             (zero_out) ? (struct monst *) 0 : shkp;
249 }
250
251 void
252 replshk(mtmp, mtmp2)
253 register struct monst *mtmp, *mtmp2;
254 {
255     rooms[ESHK(mtmp2)->shoproom - ROOMOFFSET].resident = mtmp2;
256     if (inhishop(mtmp) && *u.ushops == ESHK(mtmp)->shoproom) {
257         ESHK(mtmp2)->bill_p = &(ESHK(mtmp2)->bill[0]);
258     }
259 }
260
261 /* do shopkeeper specific structure munging -dlc */
262 void
263 restshk(shkp, ghostly)
264 struct monst *shkp;
265 boolean ghostly;
266 {
267     if (u.uz.dlevel) {
268         struct eshk *eshkp = ESHK(shkp);
269
270         if (eshkp->bill_p != (struct bill_x *) -1000)
271             eshkp->bill_p = &eshkp->bill[0];
272         /* shoplevel can change as dungeons move around */
273         /* savebones guarantees that non-homed shk's will be gone */
274         if (ghostly) {
275             assign_level(&eshkp->shoplevel, &u.uz);
276             if (ANGRY(shkp) && strncmpi(eshkp->customer, plname, PL_NSIZ))
277                 pacify_shk(shkp);
278         }
279     }
280 }
281
282 /* Clear the unpaid bit on a single object and its contents. */
283 STATIC_OVL void
284 clear_unpaid_obj(shkp, otmp)
285 struct monst *shkp;
286 struct obj *otmp;
287 {
288     if (Has_contents(otmp))
289         clear_unpaid(shkp, otmp->cobj);
290     if (onbill(otmp, shkp, TRUE))
291         otmp->unpaid = 0;
292 }
293
294 /* Clear the unpaid bit on all of the objects in the list. */
295 STATIC_OVL void
296 clear_unpaid(shkp, list)
297 struct monst *shkp;
298 struct obj *list;
299 {
300     while (list) {
301         clear_unpaid_obj(shkp, list);
302         list = list->nobj;
303     }
304 }
305
306 /* either you paid or left the shop or the shopkeeper died */
307 void
308 setpaid(shkp)
309 register struct monst *shkp;
310 {
311     register struct obj *obj;
312     register struct monst *mtmp;
313
314     clear_unpaid(shkp, invent);
315     clear_unpaid(shkp, fobj);
316     clear_unpaid(shkp, level.buriedobjlist);
317     if (thrownobj)
318         clear_unpaid_obj(shkp, thrownobj);
319     if (kickedobj)
320         clear_unpaid_obj(shkp, kickedobj);
321     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
322         clear_unpaid(shkp, mtmp->minvent);
323     for (mtmp = migrating_mons; mtmp; mtmp = mtmp->nmon)
324         clear_unpaid(shkp, mtmp->minvent);
325
326     while ((obj = billobjs) != 0) {
327         obj_extract_self(obj);
328         dealloc_obj(obj);
329     }
330     if (shkp) {
331         ESHK(shkp)->billct = 0;
332         ESHK(shkp)->credit = 0L;
333         ESHK(shkp)->debit = 0L;
334         ESHK(shkp)->loan = 0L;
335     }
336 }
337
338 STATIC_OVL long
339 addupbill(shkp)
340 register struct monst *shkp;
341 {
342     register int ct = ESHK(shkp)->billct;
343     register struct bill_x *bp = ESHK(shkp)->bill_p;
344     register long total = 0L;
345
346     while (ct--) {
347         total += bp->price * bp->bquan;
348         bp++;
349     }
350     return total;
351 }
352
353 STATIC_OVL void
354 call_kops(shkp, nearshop)
355 register struct monst *shkp;
356 register boolean nearshop;
357 {
358     /* Keystone Kops srt@ucla */
359     register boolean nokops;
360
361     if (!shkp)
362         return;
363
364     if (!Deaf)
365 /*JP
366         pline("An alarm sounds!");
367 */
368         pline("\8cx\95ñ\82ª\96Â\82è\82Ð\82Ñ\82¢\82½\81I");
369
370     nokops = ((mvitals[PM_KEYSTONE_KOP].mvflags & G_GONE)
371               && (mvitals[PM_KOP_SERGEANT].mvflags & G_GONE)
372               && (mvitals[PM_KOP_LIEUTENANT].mvflags & G_GONE)
373               && (mvitals[PM_KOP_KAPTAIN].mvflags & G_GONE));
374
375     if (!angry_guards(!!Deaf) && nokops) {
376         if (flags.verbose && !Deaf)
377 /*JP
378             pline("But no one seems to respond to it.");
379 */
380             pline("\82µ\82©\82µ\92N\82à\89\9e\93\9a\82µ\82È\82©\82Á\82½\81D");
381         return;
382     }
383
384     if (nokops)
385         return;
386
387     {
388         coord mm;
389
390         if (nearshop) {
391             /* Create swarm around you, if you merely "stepped out" */
392             if (flags.verbose)
393 /*JP
394                 pline_The("Keystone Kops appear!");
395 */
396                 pline("\8cx\94õ\88õ\82ª\8c»\82í\82ê\82½\81I");
397             mm.x = u.ux;
398             mm.y = u.uy;
399             makekops(&mm);
400             return;
401         }
402         if (flags.verbose)
403 /*JP
404             pline_The("Keystone Kops are after you!");
405 */
406             pline("\8cx\94õ\88õ\82ª\82¢\82é\81I");
407         /* Create swarm near down staircase (hinders return to level) */
408         mm.x = xdnstair;
409         mm.y = ydnstair;
410         makekops(&mm);
411         /* Create swarm near shopkeeper (hinders return to shop) */
412         mm.x = shkp->mx;
413         mm.y = shkp->my;
414         makekops(&mm);
415     }
416 }
417
418 /* x,y is strictly inside shop */
419 char
420 inside_shop(x, y)
421 register xchar x, y;
422 {
423     register char rno;
424
425     rno = levl[x][y].roomno;
426     if ((rno < ROOMOFFSET) || levl[x][y].edge || !IS_SHOP(rno - ROOMOFFSET))
427         rno = NO_ROOM;
428     return rno;
429 }
430
431 void
432 u_left_shop(leavestring, newlev)
433 char *leavestring;
434 boolean newlev;
435 {
436     struct monst *shkp;
437     struct eshk *eshkp;
438
439     /*
440      * IF player
441      * ((didn't leave outright) AND
442      *  ((he is now strictly-inside the shop) OR
443      *   (he wasn't strictly-inside last turn anyway)))
444      * THEN (there's nothing to do, so just return)
445      */
446     if (!*leavestring && (!levl[u.ux][u.uy].edge || levl[u.ux0][u.uy0].edge))
447         return;
448
449     shkp = shop_keeper(*u.ushops0);
450     if (!shkp || !inhishop(shkp))
451         return; /* shk died, teleported, changed levels... */
452
453     eshkp = ESHK(shkp);
454     if (!eshkp->billct && !eshkp->debit) /* bill is settled */
455         return;
456
457     if (!*leavestring && !muteshk(shkp)) {
458         /*
459          * Player just stepped onto shop-boundary (known from above logic).
460          * Try to intimidate him into paying his bill
461          */
462         if (!Deaf && !muteshk(shkp))
463 #if 0 /*JP:T*/
464             verbalize(NOTANGRY(shkp) ? "%s!  Please pay before leaving."
465                                  : "%s!  Don't you leave without paying!",
466                       plname);
467 #else
468             verbalize(NOTANGRY(shkp) ? "%s\82³\82ñ\81I\8bA\82é\91O\82É\81C\82¨\8bà\82ð\95¥\82Á\82Ä\82¢\82½\82¾\82¯\82Ü\82¹\82ñ\82©\81D"
469                                  : "%s\81I\8bA\82é\91O\82É\81C\8bà\82ð\95¥\82¦\81I",
470                       plname);
471 #endif
472         else
473 #if 0 /*JP*/
474             pline("%s %s that you need to pay before leaving%s",
475                   Shknam(shkp),
476                   NOTANGRY(shkp) ? "points out" : "makes it clear",
477                   NOTANGRY(shkp) ? "." : "!");
478 #else
479             pline("%s\82Í\81C\8bA\82é\91O\82É\8ex\95¥\82¢\82ð\82·\82é\95K\97v\82ª\82 \82é\82±\82Æ\82ð%s",
480                   Shknam(shkp),
481                   NOTANGRY(shkp) ? "\8ew\93E\82µ\82½\81D" : "\82Í\82Á\82«\82è\82³\82¹\82½\81I");
482 #endif
483         return;
484     }
485
486     if (rob_shop(shkp)) {
487         call_kops(shkp, (!newlev && levl[u.ux0][u.uy0].edge));
488     }
489 }
490
491 /* robbery from outside the shop via telekinesis or grappling hook */
492 void
493 remote_burglary(x, y)
494 xchar x, y;
495 {
496     struct monst *shkp;
497     struct eshk *eshkp;
498
499     shkp = shop_keeper(*in_rooms(x, y, SHOPBASE));
500     if (!shkp || !inhishop(shkp))
501         return; /* shk died, teleported, changed levels... */
502
503     eshkp = ESHK(shkp);
504     if (!eshkp->billct && !eshkp->debit) /* bill is settled */
505         return;
506
507     if (rob_shop(shkp)) {
508         /*[might want to set 2nd arg based on distance from shop doorway]*/
509         call_kops(shkp, FALSE);
510     }
511 }
512
513 /* shop merchandise has been taken; pay for it with any credit available;
514    return false if the debt is fully covered by credit, true otherwise */
515 STATIC_OVL boolean
516 rob_shop(shkp)
517 struct monst *shkp;
518 {
519     struct eshk *eshkp;
520     long total;
521
522     eshkp = ESHK(shkp);
523     rouse_shk(shkp, TRUE);
524     total = (addupbill(shkp) + eshkp->debit);
525     if (eshkp->credit >= total) {
526 #if 0 /*JP*/
527         Your("credit of %ld %s is used to cover your shopping bill.",
528 #else
529         Your("\97a\82¯\8bà\82©\82ç%ld%s\82ª\8a¨\92è\82Ì\8ex\95¥\82¢\82É\8eg\82í\82ê\82½\81D",
530 #endif
531              eshkp->credit, currency(eshkp->credit));
532         total = 0L; /* credit gets cleared by setpaid() */
533     } else {
534 /*JP
535         You("escaped the shop without paying!");
536 */
537         You("\8bà\82ð\95¥\82í\82¸\82É\93X\82©\82ç\93¦\82°\82½\81I");
538         total -= eshkp->credit;
539     }
540     setpaid(shkp);
541     if (!total)
542         return FALSE;
543
544     /* by this point, we know an actual robbery has taken place */
545     eshkp->robbed += total;
546 /*JP
547     You("stole %ld %s worth of merchandise.", total, currency(total));
548 */
549     You("\8eG\89Ý\82ð%ld%s\95ª\93\90\82ñ\82¾\81D", total, currency(total));
550     if (!Role_if(PM_ROGUE)) /* stealing is unlawful */
551         adjalign(-sgn(u.ualign.type));
552
553     hot_pursuit(shkp);
554     return TRUE;
555 }
556
557 /* give a message when entering an untended shop (caller has verified that) */
558 STATIC_OVL void
559 deserted_shop(enterstring)
560 /*const*/ char *enterstring;
561 {
562     struct monst *mtmp;
563     struct mkroom *r = &rooms[(int) *enterstring - ROOMOFFSET];
564     int x, y, m = 0, n = 0;
565
566     for (x = r->lx; x <= r->hx; ++x)
567         for (y = r->ly; y <= r->hy; ++y) {
568             if (x == u.ux && y == u.uy)
569                 continue;
570             if ((mtmp = m_at(x, y)) != 0) {
571                 ++n;
572                 if (sensemon(mtmp) || ((M_AP_TYPE(mtmp) == M_AP_NOTHING
573                                         || M_AP_TYPE(mtmp) == M_AP_MONSTER)
574                                        && canseemon(mtmp)))
575                     ++m;
576             }
577         }
578
579     if (Blind && !(Blind_telepat || Detect_monsters))
580         ++n; /* force feedback to be less specific */
581
582 #if 0 /*JP*/
583     pline("This shop %s %s.", (m < n) ? "seems to be" : "is",
584           !n ? "deserted" : "untended");
585 #else
586     pline("\93X\82Í%s%s\81D",
587           !n ? "\94p\9aÐ\82Æ\89»\82µ\82Ä\82¢\82é" : "\95ú\8aü\82³\82ê\82Ä\82¢\82é",
588           (m < n) ? "\82æ\82¤\82¾" : "");
589 #endif
590 }
591
592 void
593 u_entered_shop(enterstring)
594 char *enterstring;
595 {
596     register int rt;
597     register struct monst *shkp;
598     register struct eshk *eshkp;
599     static char empty_shops[5];
600
601     if (!*enterstring)
602         return;
603
604     if (!(shkp = shop_keeper(*enterstring))) {
605         if (!index(empty_shops, *enterstring)
606             && in_rooms(u.ux, u.uy, SHOPBASE)
607                    != in_rooms(u.ux0, u.uy0, SHOPBASE))
608             deserted_shop(enterstring);
609         Strcpy(empty_shops, u.ushops);
610         u.ushops[0] = '\0';
611         return;
612     }
613
614     eshkp = ESHK(shkp);
615
616     if (!inhishop(shkp)) {
617         /* dump core when referenced */
618         eshkp->bill_p = (struct bill_x *) -1000;
619         if (!index(empty_shops, *enterstring))
620             deserted_shop(enterstring);
621         Strcpy(empty_shops, u.ushops);
622         u.ushops[0] = '\0';
623         return;
624     }
625
626     eshkp->bill_p = &(eshkp->bill[0]);
627
628     if ((!eshkp->visitct || *eshkp->customer)
629         && strncmpi(eshkp->customer, plname, PL_NSIZ)) {
630         /* You seem to be new here */
631         eshkp->visitct = 0;
632         eshkp->following = 0;
633         (void) strncpy(eshkp->customer, plname, PL_NSIZ);
634         pacify_shk(shkp);
635     }
636
637     if (muteshk(shkp) || eshkp->following)
638         return; /* no dialog */
639
640     if (Invis) {
641 /*JP
642         pline("%s senses your presence.", Shknam(shkp));
643 */
644         pline("%s\82Í\82 \82È\82½\82Ì\91\8dÝ\82É\8bC\82ª\82Â\82¢\82½\81D", Shknam(shkp));
645         if (!Deaf && !muteshk(shkp))
646 /*JP
647         verbalize("Invisible customers are not welcome!");
648 */
649         verbalize("\93§\96¾\82È\82¨\8bq\82³\82ñ\82Æ\82Í\8a´\90S\82µ\82È\82¢\82È\81I");
650         else
651 #if 0 /*JP:T*/
652             pline("%s stands firm as if %s knows you are there.",
653                   Shknam(shkp), noit_mhe(shkp));
654 #else
655             pline("%s\82Í\81C\82Ü\82é\82Å\82 \82È\82½\82ª\82»\82±\82É\82¢\82é\82±\82Æ\82ð\92m\82Á\82Ä\82¢\82é\82©\82Ì\82æ\82¤\82É\97§\82¿\82Í\82¾\82©\82Á\82½\81D",
656                   Shknam(shkp));
657 #endif
658         return;
659     }
660
661     rt = rooms[*enterstring - ROOMOFFSET].rtype;
662
663     if (ANGRY(shkp)) {
664         if (!Deaf && !muteshk(shkp))
665 #if 0 /*JP:T*/
666             verbalize("So, %s, you dare return to %s %s?!", plname,
667                       s_suffix(shkname(shkp)), shtypes[rt - SHOPBASE].name);
668 #else
669             verbalize("%s\81I\82í\82´\82í\82´%s\82Ì%s\82É\96ß\82Á\82Ä\82«\82½\82Ì\82©\81H\81I", plname,
670                       shkname(shkp), shtypes[rt - SHOPBASE].name);
671 #endif
672         else
673 #if 0 /*JP:T*/
674             pline("%s seems %s over your return to %s %s!",
675                   Shknam(shkp), angrytexts[rn2(SIZE(angrytexts))],
676                   noit_mhis(shkp), shtypes[rt - SHOPBASE].name);
677 #else
678             pline("\82 \82È\82½\82ª%s\82É\96ß\82Á\82Ä\82«\82½\82Ì\82Å%s\82Í%s\82æ\82¤\82¾\81I",
679                   shtypes[rt - SHOPBASE].name,
680                   Shknam(shkp),
681                   angrytexts[rn2(SIZE(angrytexts))]);
682 #endif
683     } else if (eshkp->robbed) {
684         if (!Deaf)
685 #if 0 /*JP:T*/
686             pline("%s mutters imprecations against shoplifters.",
687                   Shknam(shkp));
688 #else
689             pline("%s\82Í\93D\96_\82ð\82Ì\82Ì\82µ\82Á\82½\81D",
690                   Shknam(shkp));
691 #endif
692         else
693             pline("%s is combing through %s inventory list.",
694                   Shknam(shkp), noit_mhis(shkp));
695     } else {
696         if (!Deaf && !muteshk(shkp))
697 #if 0 /*JP:T*/
698             verbalize("%s, %s!  Welcome%s to %s %s!", Hello(shkp), plname,
699                       eshkp->visitct++ ? " again" : "",
700                       s_suffix(shkname(shkp)), shtypes[rt - SHOPBASE].name);
701 #else
702             verbalize("%s\81I%s\82Ì%s\82É%s\81I", Hello(shkp),
703                       shkname(shkp), shtypes[rt - SHOPBASE].name,
704                       eshkp->visitct++ ? "\82Ü\82½\97\88\82Ü\82µ\82½\82Ë" : "\82æ\82¤\82±\82»");
705 #endif
706         else
707 #if 0 /*JP:T*/
708             You("enter %s %s%s!",
709                 s_suffix(shkname(shkp)),
710                 shtypes[rt - SHOPBASE].name,
711                 eshkp->visitct++ ? " again" : "");
712 #else
713             You("%s%s\82Ì%s\82ð\96K\82ê\82½\81I",
714                 eshkp->visitct++ ? "\8dÄ\82Ñ" : "",
715                 shkname(shkp),
716                 shtypes[rt - SHOPBASE].name);
717 #endif
718     }
719     /* can't do anything about blocking if teleported in */
720     if (!inside_shop(u.ux, u.uy)) {
721         boolean should_block;
722         int cnt;
723         const char *tool;
724         struct obj *pick = carrying(PICK_AXE),
725                    *mattock = carrying(DWARVISH_MATTOCK);
726
727         if (pick || mattock) {
728             cnt = 1;               /* so far */
729             if (pick && mattock) { /* carrying both types */
730 /*JP
731                 tool = "digging tool";
732 */
733                 tool = "\8c@\82é\93¹\8bï";
734                 cnt = 2; /* `more than 1' is all that matters */
735             } else if (pick) {
736 /*JP
737                 tool = "pick-axe";
738 */
739                 tool = "\82Â\82é\82Í\82µ";
740                 /* hack: `pick' already points somewhere into inventory */
741                 while ((pick = pick->nobj) != 0)
742                     if (pick->otyp == PICK_AXE)
743                         ++cnt;
744             } else { /* assert(mattock != 0) */
745 /*JP
746                 tool = "mattock";
747 */
748                 tool = "\82Â\82é\82Í\82µ";
749                 while ((mattock = mattock->nobj) != 0)
750                     if (mattock->otyp == DWARVISH_MATTOCK)
751                         ++cnt;
752                 /* [ALI] Shopkeeper identifies mattock(s) */
753                 if (!Blind)
754                     makeknown(DWARVISH_MATTOCK);
755             }
756             if (!Deaf && !muteshk(shkp))
757 #if 0 /*JP:T*/
758                 verbalize(NOTANGRY(shkp)
759                               ? "Will you please leave your %s%s outside?"
760                               : "Leave the %s%s outside.",
761                           tool, plur(cnt));
762 #else
763                 verbalize(NOTANGRY(shkp)
764                               ? "%s\82ð\8aO\82É\92u\82¢\82Ä\82«\82Ä\82¢\82½\82¾\82¯\82Ü\82¹\82ñ\82©\81H"
765                               : "%s\82ð\8aO\82Ö\92u\82¢\82Ä\82±\82¢\81I",
766                           tool);
767 #endif
768             else
769 #if 0 /*JP:T*/
770                 pline("%s %s to let you in with your %s%s.",
771                       Shknam(shkp),
772                       NOTANGRY(shkp) ? "is hesitant" : "refuses",
773                       tool, plur(cnt));
774 #else
775                 pline("%s\82Í\82 \82È\82½\82ª%s\82ð\8e\9d\82Á\82Ä\93ü\82é\82Ì%s\81D",
776                       Shknam(shkp),
777                       tool,
778                       NOTANGRY(shkp) ? "\82Í\8bC\82ª\82·\82·\82Ü\82È\82¢\82æ\82¤\82¾" : "\82ð\8b\91\94Û\82µ\82½");
779 #endif
780             should_block = TRUE;
781         } else if (u.usteed) {
782             if (!Deaf && !muteshk(shkp))
783 #if 0 /*JP:T*/
784                 verbalize(NOTANGRY(shkp) ? "Will you please leave %s outside?"
785                                      : "Leave %s outside.",
786                           y_monnam(u.usteed));
787 #else
788                 verbalize(NOTANGRY(shkp) ? "%s\82ð\8aO\82É\92u\82¢\82Ä\82«\82Ä\82¢\82½\82¾\82¯\82Ü\82¹\82ñ\82©\81H"
789                                      : "%s\82ð\8aO\82Ö\92u\82¢\82Ä\82±\82¢\81I",
790                           y_monnam(u.usteed));
791 #endif
792             else
793 #if 0 /*JP:T*/
794                 pline("%s %s to let you in while you're riding %s.",
795                       Shknam(shkp),
796                       NOTANGRY(shkp) ? "doesn't want" : "refuses",
797                       y_monnam(u.usteed));
798 #else
799                 pline("%s\82Í\82 \82È\82½\82ª%s\82É\8fæ\82Á\82½\82Ü\82Ü\82È\82Ì%s.",
800                       Shknam(shkp),
801                       y_monnam(u.usteed),
802                       NOTANGRY(shkp) ? "\82Í\96]\82Ü\82È\82¢\82æ\82¤\82¾" : "\82ð\8b\91\94Û\82µ\82½");
803 #endif
804             should_block = TRUE;
805         } else {
806             should_block =
807                 (Fast && (sobj_at(PICK_AXE, u.ux, u.uy)
808                           || sobj_at(DWARVISH_MATTOCK, u.ux, u.uy)));
809         }
810         if (should_block)
811             (void) dochug(shkp); /* shk gets extra move */
812     }
813     return;
814 }
815
816 /* called when removing a pick-axe or mattock from a container */
817 void
818 pick_pick(obj)
819 struct obj *obj;
820 {
821     struct monst *shkp;
822
823     if (obj->unpaid || !is_pick(obj))
824         return;
825     shkp = shop_keeper(*u.ushops);
826     if (shkp && inhishop(shkp)) {
827         static NEARDATA long pickmovetime = 0L;
828
829         /* if you bring a sack of N picks into a shop to sell,
830            don't repeat this N times when they're taken out */
831         if (moves != pickmovetime) {
832             if (!Deaf && !muteshk(shkp))
833 #if 0 /*JP*/
834                 verbalize("You sneaky %s!  Get out of here with that pick!",
835                       cad(FALSE));
836 #else
837                 verbalize("\82Ð\82«\82å\82¤\8eÒ\82ß\81I\82Â\82é\82Í\82µ\82ð\8e\9d\82Á\82Ä\8aO\82É\8fo\82ë\81I");
838 #endif
839             else
840 #if 0 /*JP*/
841                 pline("%s %s your pick!",
842                       Shknam(shkp),
843                       haseyes(shkp->data) ? "glares at"
844                                           : "is dismayed because of");
845 #else
846                 pline("%s\82Í\82Â\82é\82Í\82µ%s\81I",
847                       Shknam(shkp),
848                       haseyes(shkp->data) ? "\82ð\82É\82ç\82Ý\82Â\82¯\82½"
849                                           : "\82É\93®\97h\82µ\82Ä\82¢\82é");
850 #endif
851         }
852         pickmovetime = moves;
853     }
854 }
855
856 /*
857    Decide whether two unpaid items are mergable; caller is responsible for
858    making sure they're unpaid and the same type of object; we check the price
859    quoted by the shopkeeper and also that they both belong to the same shk.
860  */
861 boolean
862 same_price(obj1, obj2)
863 struct obj *obj1, *obj2;
864 {
865     register struct monst *shkp1, *shkp2;
866     struct bill_x *bp1 = 0, *bp2 = 0;
867     boolean are_mergable = FALSE;
868
869     /* look up the first object by finding shk whose bill it's on */
870     for (shkp1 = next_shkp(fmon, TRUE); shkp1;
871          shkp1 = next_shkp(shkp1->nmon, TRUE))
872         if ((bp1 = onbill(obj1, shkp1, TRUE)) != 0)
873             break;
874     /* second object is probably owned by same shk; if not, look harder */
875     if (shkp1 && (bp2 = onbill(obj2, shkp1, TRUE)) != 0) {
876         shkp2 = shkp1;
877     } else {
878         for (shkp2 = next_shkp(fmon, TRUE); shkp2;
879              shkp2 = next_shkp(shkp2->nmon, TRUE))
880             if ((bp2 = onbill(obj2, shkp2, TRUE)) != 0)
881                 break;
882     }
883
884     if (!bp1 || !bp2)
885         impossible("same_price: object wasn't on any bill!");
886     else
887         are_mergable = (shkp1 == shkp2 && bp1->price == bp2->price);
888     return are_mergable;
889 }
890
891 /*
892  * Figure out how much is owed to a given shopkeeper.
893  * At present, we ignore any amount robbed from the shop, to avoid
894  * turning the `$' command into a way to discover that the current
895  * level is bones data which has a shk on the warpath.
896  */
897 STATIC_OVL long
898 shop_debt(eshkp)
899 struct eshk *eshkp;
900 {
901     struct bill_x *bp;
902     int ct;
903     long debt = eshkp->debit;
904
905     for (bp = eshkp->bill_p, ct = eshkp->billct; ct > 0; bp++, ct--)
906         debt += bp->price * bp->bquan;
907     return debt;
908 }
909
910 /* called in response to the `$' command */
911 void
912 shopper_financial_report()
913 {
914     struct monst *shkp, *this_shkp = shop_keeper(inside_shop(u.ux, u.uy));
915     struct eshk *eshkp;
916     long amt;
917     int pass;
918
919     eshkp = this_shkp ? ESHK(this_shkp) : 0;
920     if (eshkp && !(eshkp->credit || shop_debt(eshkp))) {
921 /*JP
922         You("have no credit or debt in here.");
923 */
924         You("\97a\82¯\8bà\82à\8eØ\8bà\82à\82È\82¢\81D");
925         this_shkp = 0; /* skip first pass */
926     }
927
928     /* pass 0: report for the shop we're currently in, if any;
929        pass 1: report for all other shops on this level. */
930     for (pass = this_shkp ? 0 : 1; pass <= 1; pass++)
931         for (shkp = next_shkp(fmon, FALSE); shkp;
932              shkp = next_shkp(shkp->nmon, FALSE)) {
933             if ((shkp != this_shkp) ^ pass)
934                 continue;
935             eshkp = ESHK(shkp);
936             if ((amt = eshkp->credit) != 0)
937 #if 0 /*JP*/
938                 You("have %ld %s credit at %s %s.", amt, currency(amt),
939                     s_suffix(shkname(shkp)),
940                     shtypes[eshkp->shoptype - SHOPBASE].name);
941 #else
942                 You("%ld%s\82Ì\97a\82¯\8bà\82ª%s\82Ì%s\82É\82 \82é\81D", amt, currency(amt),
943                     shkname(shkp),
944                     shtypes[eshkp->shoptype - SHOPBASE].name);
945 #endif
946             else if (shkp == this_shkp)
947 /*JP
948                 You("have no credit in here.");
949 */
950                 You("\97a\82¯\8bà\82Í\82È\82¢\81D");
951             if ((amt = shop_debt(eshkp)) != 0)
952 /*JP
953                 You("owe %s %ld %s.", shkname(shkp), amt, currency(amt));
954 */
955                 You("%s\82É%ld%s\82Ì\8eØ\82è\82ª\82 \82é\81D", shkname(shkp), amt, currency(amt));
956             else if (shkp == this_shkp)
957 /*JP
958                 You("don't owe any money here.");
959 */
960                 pline("\82±\82Ì\93X\82É\8eØ\82è\82Í\82È\82¢\81D");
961         }
962 }
963
964 int
965 inhishop(mtmp)
966 register struct monst *mtmp;
967 {
968     struct eshk *eshkp = ESHK(mtmp);
969
970     return (index(in_rooms(mtmp->mx, mtmp->my, SHOPBASE), eshkp->shoproom)
971             && on_level(&eshkp->shoplevel, &u.uz));
972 }
973
974 struct monst *
975 shop_keeper(rmno)
976 char rmno;
977 {
978     struct monst *shkp;
979
980     shkp = (rmno >= ROOMOFFSET) ? rooms[rmno - ROOMOFFSET].resident : 0;
981     if (shkp) {
982         if (has_eshk(shkp)) {
983             if (NOTANGRY(shkp)) {
984                 if (ESHK(shkp)->surcharge)
985                     pacify_shk(shkp);
986             } else {
987                 if (!ESHK(shkp)->surcharge)
988                     rile_shk(shkp);
989             }
990         } else {
991             /* would have segfaulted on ESHK dereference previously */
992             impossible("%s? (rmno=%d, rtype=%d, mnum=%d, \"%s\")",
993                        shkp->isshk ? "shopkeeper career change"
994                                    : "shop resident not shopkeeper",
995                        (int) rmno,
996                        (int) rooms[rmno - ROOMOFFSET].rtype,
997                        shkp->mnum,
998                        /* [real shopkeeper name is kept in ESHK, not MNAME] */
999                        has_mname(shkp) ? MNAME(shkp) : "anonymous");
1000             /* not sure if this is appropriate, because it does nothing to
1001                correct the underlying rooms[].resident issue but... */
1002             return (struct monst *) 0;
1003         }
1004     }
1005     return shkp;
1006 }
1007
1008 boolean
1009 tended_shop(sroom)
1010 struct mkroom *sroom;
1011 {
1012     struct monst *mtmp = sroom->resident;
1013
1014     return !mtmp ? FALSE : (boolean) inhishop(mtmp);
1015 }
1016
1017 STATIC_OVL struct bill_x *
1018 onbill(obj, shkp, silent)
1019 struct obj *obj;
1020 struct monst *shkp;
1021 boolean silent;
1022 {
1023     if (shkp) {
1024         register struct bill_x *bp = ESHK(shkp)->bill_p;
1025         register int ct = ESHK(shkp)->billct;
1026
1027         while (--ct >= 0)
1028             if (bp->bo_id == obj->o_id) {
1029                 if (!obj->unpaid)
1030 /*JP
1031                     pline("onbill: paid obj on bill?");
1032 */
1033                     pline("\8a¨\92è\81F\95¥\82¤\81H");
1034                 return bp;
1035             } else
1036                 bp++;
1037     }
1038     if (obj->unpaid && !silent)
1039 /*JP
1040         pline("onbill: unpaid obj not on bill?");
1041 */
1042         pline("\8a¨\92è\81F\95¥\82í\82È\82¢\81H");
1043     return (struct bill_x *) 0;
1044 }
1045
1046 /* check whether an object or any of its contents belongs to a shop */
1047 boolean
1048 is_unpaid(obj)
1049 struct obj *obj;
1050 {
1051     return (boolean) (obj->unpaid
1052                       || (Has_contents(obj) && count_unpaid(obj->cobj)));
1053 }
1054
1055 /* Delete the contents of the given object. */
1056 void
1057 delete_contents(obj)
1058 register struct obj *obj;
1059 {
1060     register struct obj *curr;
1061
1062     while ((curr = obj->cobj) != 0) {
1063         obj_extract_self(curr);
1064         obfree(curr, (struct obj *) 0);
1065     }
1066 }
1067
1068 /* called with two args on merge */
1069 void
1070 obfree(obj, merge)
1071 register struct obj *obj, *merge;
1072 {
1073     register struct bill_x *bp;
1074     register struct bill_x *bpm;
1075     register struct monst *shkp;
1076
1077     if (obj->otyp == LEASH && obj->leashmon)
1078         o_unleash(obj);
1079     if (obj->oclass == FOOD_CLASS)
1080         food_disappears(obj);
1081     if (obj->oclass == SPBOOK_CLASS)
1082         book_disappears(obj);
1083     if (Has_contents(obj))
1084         delete_contents(obj);
1085     if (Is_container(obj))
1086         maybe_reset_pick(obj);
1087
1088     shkp = 0;
1089     if (obj->unpaid) {
1090         /* look for a shopkeeper who owns this object */
1091         for (shkp = next_shkp(fmon, TRUE); shkp;
1092              shkp = next_shkp(shkp->nmon, TRUE))
1093             if (onbill(obj, shkp, TRUE))
1094                 break;
1095     }
1096     /* sanity check, in case obj is on bill but not marked 'unpaid' */
1097     if (!shkp)
1098         shkp = shop_keeper(*u.ushops);
1099     /*
1100      * Note:  `shkp = shop_keeper(*u.ushops)' used to be
1101      *    unconditional.  But obfree() is used all over
1102      *    the place, so making its behavior be dependent
1103      *    upon player location doesn't make much sense.
1104      */
1105
1106     if ((bp = onbill(obj, shkp, FALSE)) != 0) {
1107         if (!merge) {
1108             bp->useup = 1;
1109             obj->unpaid = 0; /* only for doinvbill */
1110             add_to_billobjs(obj);
1111             return;
1112         }
1113         bpm = onbill(merge, shkp, FALSE);
1114         if (!bpm) {
1115             /* this used to be a rename */
1116             impossible("obfree: not on bill??");
1117             return;
1118         } else {
1119             /* this was a merger */
1120             bpm->bquan += bp->bquan;
1121             ESHK(shkp)->billct--;
1122 #ifdef DUMB
1123             {
1124                 /* DRS/NS 2.2.6 messes up -- Peter Kendell */
1125                 int indx = ESHK(shkp)->billct;
1126
1127                 *bp = ESHK(shkp)->bill_p[indx];
1128             }
1129 #else
1130             *bp = ESHK(shkp)->bill_p[ESHK(shkp)->billct];
1131 #endif
1132         }
1133     } else {
1134         /* not on bill; if the item is being merged away rather than
1135            just deleted and has a higher price adjustment than the stack
1136            being merged into, give the latter the former's obj->o_id so
1137            that the merged stack takes on higher price; matters if hero
1138            eventually buys them from a shop, but doesn't matter if hero
1139            owns them and intends to sell (unless he subsequently buys
1140            them back) or if no shopping activity ever involves them */
1141         if (merge && (oid_price_adjustment(obj, obj->o_id)
1142                       > oid_price_adjustment(merge, merge->o_id)))
1143             merge->o_id = obj->o_id;
1144     }
1145     if (obj->owornmask) {
1146         impossible("obfree: deleting worn obj (%d: %ld)", obj->otyp,
1147                    obj->owornmask);
1148         /* unfortunately at this point we don't know whether worn mask
1149            applied to hero or a monster or perhaps something bogus, so
1150            can't call remove_worn_item() to get <X>_off() side-effects */
1151         setnotworn(obj);
1152     }
1153     dealloc_obj(obj);
1154 }
1155
1156 STATIC_OVL long
1157 check_credit(tmp, shkp)
1158 long tmp;
1159 register struct monst *shkp;
1160 {
1161     long credit = ESHK(shkp)->credit;
1162
1163     if (credit == 0L) {
1164         ; /* nothing to do; just 'return tmp;' */
1165     } else if (credit >= tmp) {
1166 /*JP
1167         pline_The("price is deducted from your credit.");
1168 */
1169         pline("\91ã\8bà\82Í\97a\82¯\8bà\82©\82ç\8d·\82µ\88ø\82©\82ê\82½\81D");
1170         ESHK(shkp)->credit -= tmp;
1171         tmp = 0L;
1172     } else {
1173 /*JP
1174         pline_The("price is partially covered by your credit.");
1175 */
1176         pline("\91ã\8bà\82Ì\88ê\95\94\82Í\82 \82È\82½\82Ì\97a\82¯\8bà\82Å\95â\82í\82ê\82½\81D");
1177         ESHK(shkp)->credit = 0L;
1178         tmp -= credit;
1179     }
1180     return tmp;
1181 }
1182
1183 STATIC_OVL void
1184 pay(tmp, shkp)
1185 long tmp;
1186 register struct monst *shkp;
1187 {
1188     long robbed = ESHK(shkp)->robbed;
1189     long balance = ((tmp <= 0L) ? tmp : check_credit(tmp, shkp));
1190
1191     if (balance > 0)
1192         money2mon(shkp, balance);
1193     else if (balance < 0)
1194         money2u(shkp, -balance);
1195     context.botl = 1;
1196     if (robbed) {
1197         robbed -= tmp;
1198         if (robbed < 0)
1199             robbed = 0L;
1200         ESHK(shkp)->robbed = robbed;
1201     }
1202 }
1203
1204 /* return shkp to home position */
1205 void
1206 home_shk(shkp, killkops)
1207 register struct monst *shkp;
1208 register boolean killkops;
1209 {
1210     register xchar x = ESHK(shkp)->shk.x, y = ESHK(shkp)->shk.y;
1211
1212     (void) mnearto(shkp, x, y, TRUE);
1213     level.flags.has_shop = 1;
1214     if (killkops) {
1215         kops_gone(TRUE);
1216         pacify_guards();
1217     }
1218     after_shk_move(shkp);
1219 }
1220
1221 STATIC_OVL boolean
1222 angry_shk_exists()
1223 {
1224     register struct monst *shkp;
1225
1226     for (shkp = next_shkp(fmon, FALSE); shkp;
1227          shkp = next_shkp(shkp->nmon, FALSE))
1228         if (ANGRY(shkp))
1229             return TRUE;
1230     return FALSE;
1231 }
1232
1233 /* remove previously applied surcharge from all billed items */
1234 STATIC_OVL void
1235 pacify_shk(shkp)
1236 register struct monst *shkp;
1237 {
1238     NOTANGRY(shkp) = TRUE; /* make peaceful */
1239     if (ESHK(shkp)->surcharge) {
1240         register struct bill_x *bp = ESHK(shkp)->bill_p;
1241         register int ct = ESHK(shkp)->billct;
1242
1243         ESHK(shkp)->surcharge = FALSE;
1244         while (ct-- > 0) {
1245             register long reduction = (bp->price + 3L) / 4L;
1246             bp->price -= reduction; /* undo 33% increase */
1247             bp++;
1248         }
1249     }
1250 }
1251
1252 /* add aggravation surcharge to all billed items */
1253 STATIC_OVL void
1254 rile_shk(shkp)
1255 register struct monst *shkp;
1256 {
1257     NOTANGRY(shkp) = FALSE; /* make angry */
1258     if (!ESHK(shkp)->surcharge) {
1259         register struct bill_x *bp = ESHK(shkp)->bill_p;
1260         register int ct = ESHK(shkp)->billct;
1261
1262         ESHK(shkp)->surcharge = TRUE;
1263         while (ct-- > 0) {
1264             register long surcharge = (bp->price + 2L) / 3L;
1265             bp->price += surcharge;
1266             bp++;
1267         }
1268     }
1269 }
1270
1271 /* wakeup and/or unparalyze shopkeeper */
1272 STATIC_OVL void
1273 rouse_shk(shkp, verbosely)
1274 struct monst *shkp;
1275 boolean verbosely;
1276 {
1277     if (!shkp->mcanmove || shkp->msleeping) {
1278         /* greed induced recovery... */
1279         if (verbosely && canspotmon(shkp))
1280 #if 0 /*JP:T*/
1281             pline("%s %s.", Shknam(shkp),
1282                   shkp->msleeping ? "wakes up" : "can move again");
1283 #else
1284             pline("%s\82Í%s\81D", Monnam(shkp),
1285                   shkp->msleeping ? "\96Ú\82ª\8ao\82ß\82½" : "\82Ó\82½\82½\82Ñ\93®\82¯\82é\82æ\82¤\82É\82È\82Á\82½");
1286 #endif
1287         shkp->msleeping = 0;
1288         shkp->mfrozen = 0;
1289         shkp->mcanmove = 1;
1290     }
1291 }
1292
1293 void
1294 make_happy_shk(shkp, silentkops)
1295 register struct monst *shkp;
1296 register boolean silentkops;
1297 {
1298     boolean wasmad = ANGRY(shkp);
1299     struct eshk *eshkp = ESHK(shkp);
1300
1301     pacify_shk(shkp);
1302     eshkp->following = 0;
1303     eshkp->robbed = 0L;
1304     if (!Role_if(PM_ROGUE))
1305         adjalign(sgn(u.ualign.type));
1306     if (!inhishop(shkp)) {
1307         char shk_nam[BUFSZ];
1308         boolean vanished = canseemon(shkp);
1309
1310         Strcpy(shk_nam, shkname(shkp));
1311         if (on_level(&eshkp->shoplevel, &u.uz)) {
1312             home_shk(shkp, FALSE);
1313             /* didn't disappear if shk can still be seen */
1314             if (canseemon(shkp))
1315                 vanished = FALSE;
1316         } else {
1317             /* if sensed, does disappear regardless whether seen */
1318             if (sensemon(shkp))
1319                 vanished = TRUE;
1320             /* can't act as porter for the Amulet, even if shk
1321                happens to be going farther down rather than up */
1322             mdrop_special_objs(shkp);
1323             /* arrive near shop's door */
1324             migrate_to_level(shkp, ledger_no(&eshkp->shoplevel),
1325                              MIGR_APPROX_XY, &eshkp->shd);
1326             /* dismiss kops on that level when shk arrives */
1327             eshkp->dismiss_kops = TRUE;
1328         }
1329         if (vanished)
1330 /*JP
1331             pline("Satisfied, %s suddenly disappears!", shk_nam);
1332 */
1333             pline("%s\82Í\96\9e\91«\82·\82é\82Æ\81C\93Ë\91R\8fÁ\82¦\82½\81I", shk_nam);
1334     } else if (wasmad)
1335 /*JP
1336         pline("%s calms down.", Shknam(shkp));
1337 */
1338         pline("%s\82Í\97\8e\92\85\82¢\82½\81D", Shknam(shkp));
1339
1340     make_happy_shoppers(silentkops);
1341 }
1342
1343 /* called by make_happy_shk() and also by losedogs() for migrating shk */
1344 void
1345 make_happy_shoppers(silentkops)
1346 boolean silentkops;
1347 {
1348     if (!angry_shk_exists()) {
1349         kops_gone(silentkops);
1350         pacify_guards();
1351     }
1352 }
1353
1354 void
1355 hot_pursuit(shkp)
1356 register struct monst *shkp;
1357 {
1358     if (!shkp->isshk)
1359         return;
1360
1361     rile_shk(shkp);
1362     (void) strncpy(ESHK(shkp)->customer, plname, PL_NSIZ);
1363     ESHK(shkp)->following = 1;
1364 }
1365
1366 /* Used when the shkp is teleported or falls (ox == 0) out of his shop, or
1367    when the player is not on a costly_spot and he damages something inside
1368    the shop.  These conditions must be checked by the calling function. */
1369 /*ARGSUSED*/
1370 void
1371 make_angry_shk(shkp, ox, oy)
1372 struct monst *shkp;
1373 xchar ox UNUSED; /* <ox,oy> predate 'noit_Monnam()', let alone Shknam() */
1374 xchar oy UNUSED;
1375 {
1376     struct eshk *eshkp = ESHK(shkp);
1377
1378     /* all pending shop transactions are now "past due" */
1379     if (eshkp->billct || eshkp->debit || eshkp->loan || eshkp->credit) {
1380         eshkp->robbed += (addupbill(shkp) + eshkp->debit + eshkp->loan);
1381         eshkp->robbed -= eshkp->credit;
1382         if (eshkp->robbed < 0L)
1383             eshkp->robbed = 0L;
1384         /* billct, debit, loan, and credit will be cleared by setpaid */
1385         setpaid(shkp);
1386     }
1387
1388 /*JP
1389     pline("%s %s!", Shknam(shkp), !ANGRY(shkp) ? "gets angry" : "is furious");
1390 */
1391     pline("%s\82Í%s\81I", Shknam(shkp), !ANGRY(shkp) ? "\93{\82Á\82½" : "\93{\82è\8b\82Á\82½");
1392     hot_pursuit(shkp);
1393 }
1394
1395 STATIC_VAR const char
1396 /*JP
1397         no_money[] = "Moreover, you%s have no money.",
1398 */
1399         no_money[] = "\82µ\82©\82à\81C\82 \82È\82½\82Í\82¨\8bà\82ª\82È\82¢%s\81D",
1400 /*JP
1401         not_enough_money[] = "Besides, you don't have enough to interest %s.";
1402 */
1403         not_enough_money[] = "\82µ\82©\82à\81C\82 \82È\82½\82Í%s\82ª\8b»\96¡\82ð\8e\9d\82Â\82Ù\82Ç\82¨\8bà\82ð\8e\9d\82Á\82Ä\82¢\82È\82¢\81I";
1404
1405 /* delivers the cheapest item on the list */
1406 STATIC_OVL long
1407 cheapest_item(shkp)
1408 register struct monst *shkp;
1409 {
1410     register int ct = ESHK(shkp)->billct;
1411     register struct bill_x *bp = ESHK(shkp)->bill_p;
1412     register long gmin = (bp->price * bp->bquan);
1413
1414     while (ct--) {
1415         if (bp->price * bp->bquan < gmin)
1416             gmin = bp->price * bp->bquan;
1417         bp++;
1418     }
1419     return gmin;
1420 }
1421
1422 int
1423 dopay()
1424 {
1425     register struct eshk *eshkp;
1426     register struct monst *shkp;
1427     struct monst *nxtm, *resident;
1428     long ltmp;
1429     long umoney;
1430     int pass, tmp, sk = 0, seensk = 0;
1431     boolean paid = FALSE, stashed_gold = (hidden_gold() > 0L);
1432
1433     multi = 0;
1434
1435     /* Find how many shk's there are, how many are in
1436      * sight, and are you in a shop room with one.
1437      */
1438     nxtm = resident = 0;
1439     for (shkp = next_shkp(fmon, FALSE); shkp;
1440          shkp = next_shkp(shkp->nmon, FALSE)) {
1441         sk++;
1442         if (ANGRY(shkp) && distu(shkp->mx, shkp->my) <= 2)
1443             nxtm = shkp;
1444         if (canspotmon(shkp))
1445             seensk++;
1446         if (inhishop(shkp) && (*u.ushops == ESHK(shkp)->shoproom))
1447             resident = shkp;
1448     }
1449
1450     if (nxtm) {      /* Player should always appease an */
1451         shkp = nxtm; /* irate shk standing next to them. */
1452         goto proceed;
1453     }
1454
1455     if ((!sk && (!Blind || Blind_telepat)) || (!Blind && !seensk)) {
1456 /*JP
1457         There("appears to be no shopkeeper here to receive your payment.");
1458 */
1459         pline("\8ex\95¥\82¢\82ð\8eó\82¯\82Æ\82é\93X\8eå\82Í\82±\82±\82É\82Í\82¢\82È\82¢\82æ\82¤\82¾\81D");
1460         return 0;
1461     }
1462
1463     if (!seensk) {
1464 /*JP
1465         You_cant("see...");
1466 */
1467         You("\8c©\82é\82±\82Æ\82ª\82Å\82«\82È\82¢\81D\81D\81D");
1468         return 0;
1469     }
1470
1471     /* The usual case.  Allow paying at a distance when
1472      * inside a tended shop.  Should we change that?
1473      */
1474     if (sk == 1 && resident) {
1475         shkp = resident;
1476         goto proceed;
1477     }
1478
1479     if (seensk == 1) {
1480         for (shkp = next_shkp(fmon, FALSE); shkp;
1481              shkp = next_shkp(shkp->nmon, FALSE))
1482             if (canspotmon(shkp))
1483                 break;
1484         if (shkp != resident && distu(shkp->mx, shkp->my) > 2) {
1485 /*JP
1486             pline("%s is not near enough to receive your payment.",
1487 */
1488             pline("%s\82Í\89\93\82­\82É\82¢\82é\82Ì\82Å\8ex\95¥\82¦\82È\82¢\81D",
1489                   Shknam(shkp));
1490             return 0;
1491         }
1492     } else {
1493         struct monst *mtmp;
1494         coord cc;
1495         int cx, cy;
1496
1497 /*JP
1498         pline("Pay whom?");
1499 */
1500         pline("\92N\82É\95¥\82¤\81H");
1501         cc.x = u.ux;
1502         cc.y = u.uy;
1503 /*JP
1504         if (getpos(&cc, TRUE, "the creature you want to pay") < 0)
1505 */
1506         if (getpos(&cc, TRUE, "\8ex\95¥\82¢\82½\82¢\91\8a\8eè") < 0)
1507             return 0; /* player pressed ESC */
1508         cx = cc.x;
1509         cy = cc.y;
1510         if (cx < 0) {
1511 /*JP
1512             pline("Try again...");
1513 */
1514             pline("\82à\82¤\88ê\93x\81D\81D\81D");
1515             return 0;
1516         }
1517         if (u.ux == cx && u.uy == cy) {
1518 /*JP
1519             You("are generous to yourself.");
1520 */
1521             pline("\8e©\95ª\8e©\90g\82É\82È\82ñ\82Ä\8bC\91O\82Ì\82¢\82¢\82±\82Æ\81I");
1522             return 0;
1523         }
1524         mtmp = m_at(cx, cy);
1525         if (!cansee(cx, cy) && (!mtmp || !canspotmon(mtmp))) {
1526             You("can't %s anyone there.", !Blind ? "see" : "sense");
1527             return 0;
1528         }
1529         if (!mtmp) {
1530 /*JP
1531             There("is no one there to receive your payment.");
1532 */
1533             pline("\8ex\95¥\82¢\82ð\8eó\82¯\82Æ\82ê\82é\91\8a\8eè\82Í\82¢\82È\82¢\81D");
1534             return 0;
1535         }
1536         if (!mtmp->isshk) {
1537 /*JP
1538             pline("%s is not interested in your payment.", Monnam(mtmp));
1539 */
1540             pline("%s\82Í\8ex\95¥\82¢\82É\8b»\96¡\82ð\8e¦\82³\82È\82¢\81D", Monnam(mtmp));
1541             return 0;
1542         }
1543         if (mtmp != resident && distu(mtmp->mx, mtmp->my) > 2) {
1544 /*JP
1545             pline("%s is too far to receive your payment.", Shknam(mtmp));
1546 */
1547             pline("%s\82Í\8ex\95¥\82¢\82É\8b»\96¡\82ð\8e¦\82³\82È\82¢\81D", Shknam(mtmp));
1548             return 0;
1549         }
1550         shkp = mtmp;
1551     }
1552
1553     if (!shkp) {
1554         debugpline0("dopay: null shkp.");
1555         return 0;
1556     }
1557  proceed:
1558     eshkp = ESHK(shkp);
1559     ltmp = eshkp->robbed;
1560
1561     /* wake sleeping shk when someone who owes money offers payment */
1562     if (ltmp || eshkp->billct || eshkp->debit)
1563         rouse_shk(shkp, TRUE);
1564
1565     if (!shkp->mcanmove || shkp->msleeping) { /* still asleep/paralyzed */
1566 #if 0 /*JP:T*/
1567         pline("%s %s.", Shknam(shkp),
1568               rn2(2) ? "seems to be napping" : "doesn't respond");
1569 #else
1570         pline("%s\82Í%s\81D", Shknam(shkp),
1571               rn2(2) ? "\8b\8f\96°\82è\82ð\82µ\82Ä\82¢\82é\82æ\82¤\82¾" : "\94½\89\9e\82ª\82È\82¢");
1572 #endif
1573         return 0;
1574     }
1575
1576     if (shkp != resident && NOTANGRY(shkp)) {
1577         umoney = money_cnt(invent);
1578         if (!ltmp)
1579 /*JP
1580             You("do not owe %s anything.", shkname(shkp));
1581 */
1582             You("%s\82É\8eØ\82è\82Í\82È\82¢\81D", shkname(shkp));
1583         else if (!umoney) {
1584 /*JP
1585             You("%shave no money.", stashed_gold ? "seem to " : "");
1586 */
1587             You("\82¨\8bà\82ª\82È\82¢%s\81D", stashed_gold ? "\82æ\82¤\82¾" : "");
1588             if (stashed_gold)
1589 /*JP
1590                 pline("But you have some gold stashed away.");
1591 */
1592                 pline("\82µ\82©\82µ\81C\82 \82È\82½\82É\82Í\82¿\82å\82Á\82Á\82Æ\82µ\82½\83w\83\\83N\83\8a\82ª\82 \82é\81D");
1593         } else {
1594             if (umoney > ltmp) {
1595 #if 0 /*JP:T*/
1596                 You("give %s the %ld gold piece%s %s asked for.",
1597                     shkname(shkp), ltmp, plur(ltmp), noit_mhe(shkp));
1598 #else
1599                 You("%s\82É\96]\82Ý\92Ê\82è%ld\96\87\82Ì\8bà\89Ý\82ð\97^\82¦\82½\81D",
1600                     shkname(shkp), ltmp);
1601 #endif
1602                 pay(ltmp, shkp);
1603             } else {
1604 #if 0 /*JP:T*/
1605                 You("give %s all your%s gold.", shkname(shkp),
1606                     stashed_gold ? " openly kept" : "");
1607 #else
1608                 You("%s\82É%s\82¨\8bà\91S\95\94\82ð\97^\82¦\82½\81D", shkname(shkp),
1609                     stashed_gold ? "\8eè\8e\9d\82¿\82Ì" : "");
1610 #endif
1611                 pay(umoney, shkp);
1612                 if (stashed_gold)
1613 /*JP
1614                     pline("But you have hidden gold!");
1615 */
1616                     pline("\82µ\82©\82µ\81C\82 \82È\82½\82Í\83w\83\\83N\83\8a\82ª\82 \82é\81I");
1617             }
1618             if ((umoney < ltmp / 2L) || (umoney < ltmp && stashed_gold))
1619 /*JP
1620                 pline("Unfortunately, %s doesn't look satisfied.",
1621 */
1622                 pline("\8ec\94O\82È\82ª\82ç\81C%s\82Í\96\9e\91«\82µ\82Ä\82È\82¢\82æ\82¤\82¾\81D",
1623                       noit_mhe(shkp));
1624             else
1625                 make_happy_shk(shkp, FALSE);
1626         }
1627         return 1;
1628     }
1629
1630     /* ltmp is still eshkp->robbed here */
1631     if (!eshkp->billct && !eshkp->debit) {
1632         umoney = money_cnt(invent);
1633         if (!ltmp && NOTANGRY(shkp)) {
1634 /*JP
1635             You("do not owe %s anything.", shkname(shkp));
1636 */
1637             You("%s\82É\8eØ\82è\82Í\82È\82¢\81D", shkname(shkp));
1638             if (!umoney)
1639 /*JP
1640                 pline(no_money, stashed_gold ? " seem to" : "");
1641 */
1642                 pline(no_money, stashed_gold ? "\82æ\82¤\82¾" : "");
1643         } else if (ltmp) {
1644 /*JP
1645             pline("%s is after blood, not money!", shkname(shkp));
1646 */
1647             pline("%s\82Í\8c\8c\82Ü\82Ý\82ê\82¾\81D\82¨\8bà\82Ç\82±\82ë\82\82á\82È\82¢\81I", Monnam(shkp));
1648             if (umoney < ltmp / 2L || (umoney < ltmp && stashed_gold)) {
1649                 if (!umoney)
1650 /*JP
1651                     pline(no_money, stashed_gold ? " seem to" : "");
1652 */
1653                     pline(no_money, stashed_gold ? "\82æ\82¤\82¾" : "");
1654                 else
1655                     pline(not_enough_money, noit_mhim(shkp));
1656                 return 1;
1657             }
1658 /*JP
1659             pline("But since %s shop has been robbed recently,",
1660 */
1661             pline("\82µ\82©\82µ\81C%s\93X\82Í\8dÅ\8bß\93\90\82Ý\82É\82 \82Á\82½\82Ì\82Å\81C",
1662                   noit_mhis(shkp));
1663 #if 0 /*JP*/
1664             pline("you %scompensate %s for %s losses.",
1665                   (umoney < ltmp) ? "partially " : "", shkname(shkp),
1666                   noit_mhis(shkp));
1667 #else
1668             pline("%s\82Ì\91¹\8e¸%s\82ð\95â\93U\82µ\82½\81D", mhis(shkp),
1669                   (umoney < ltmp) ? "\82Ì\88ê\95\94" : "");
1670 #endif
1671             pay(umoney < ltmp ? umoney : ltmp, shkp);
1672             make_happy_shk(shkp, FALSE);
1673         } else {
1674             /* shopkeeper is angry, but has not been robbed --
1675              * door broken, attacked, etc. */
1676 /*JP
1677             pline("%s is after your hide, not your money!", Shknam(shkp));
1678 */
1679             pline("%s\82Í\82 \82È\82½\82Ì\96½\82ð\91_\82Á\82Ä\82¢\82é\81C\82¨\8bà\82Ç\82±\82ë\82\82á\82È\82¢\81I", Shknam(shkp));
1680             if (umoney < 1000L) {
1681                 if (!umoney)
1682 /*JP
1683                     pline(no_money, stashed_gold ? " seem to" : "");
1684 */
1685                     pline(no_money, stashed_gold ? "\82æ\82¤\82¾" : "");
1686                 else
1687                     pline(not_enough_money, noit_mhim(shkp));
1688                 return 1;
1689             }
1690 #if 0 /*JP:T*/
1691             You("try to appease %s by giving %s 1000 gold pieces.",
1692                 canspotmon(shkp)
1693                     ? x_monnam(shkp, ARTICLE_THE, "angry", 0, FALSE)
1694                     : shkname(shkp),
1695                 noit_mhim(shkp));
1696 #else
1697             You("\8bà\89Ý1000\96\87\82ð%s\82É\8eè\93n\82µ\82Ä\82È\82¾\82ß\82æ\82¤\82Æ\82µ\82½\81D",
1698                 canspotmon(shkp)
1699                     ? x_monnam(shkp, ARTICLE_THE, "\93{\82Á\82½", 0, FALSE)
1700                     : shkname(shkp));
1701 #endif
1702             pay(1000L, shkp);
1703             if (strncmp(eshkp->customer, plname, PL_NSIZ) || rn2(3))
1704                 make_happy_shk(shkp, FALSE);
1705             else
1706 /*JP
1707                 pline("But %s is as angry as ever.", shkname(shkp));
1708 */
1709                 pline("\82µ\82©\82µ%s\82Í\82Ü\82¾\93{\82Á\82Ä\82¢\82é\81D", shkname(shkp));
1710         }
1711         return 1;
1712     }
1713     if (shkp != resident) {
1714         impossible("dopay: not to shopkeeper?");
1715         if (resident)
1716             setpaid(resident);
1717         return 0;
1718     }
1719     /* pay debt, if any, first */
1720     if (eshkp->debit) {
1721         long dtmp = eshkp->debit;
1722         long loan = eshkp->loan;
1723         char sbuf[BUFSZ];
1724
1725         umoney = money_cnt(invent);
1726 #if 0 /*JP*//*\96\96\94ö\82É\89ñ\82·*/
1727         Sprintf(sbuf, "You owe %s %ld %s ", shkname(shkp), dtmp,
1728                 currency(dtmp));
1729 #endif
1730         if (loan) {
1731             if (loan == dtmp)
1732 /*JP
1733                 Strcat(sbuf, "you picked up in the store.");
1734 */
1735                         Strcpy(sbuf, "\93X\82Ì\92\86\82Å\8fE\82Á\82½\82à\82Ì\82É\91Î\82µ\82Ä\81C");
1736             else
1737 #if 0 /*JP*/
1738                 Strcat(sbuf,
1739                        "for gold picked up and the use of merchandise.");
1740 #else
1741                 Strcpy(sbuf,"\8fE\82Á\82½\82¨\8bà\82â\8eg\82Á\82½\8eG\89Ý\82É\91Î\82µ\82Ä\81C");
1742 #endif
1743         } else
1744 /*JP
1745             Strcat(sbuf, "for the use of merchandise.");
1746 */
1747             Strcpy(sbuf, "\8eg\82Á\82½\8eG\89Ý\82É\91Î\82µ\82Ä\81C");
1748 #if 1 /*JP*//*\8fã\82©\82ç\88Ú\93®*/
1749         Sprintf(eos(sbuf), "%s\82É%ld%s\82Ì\8eØ\82è\82ª\82 \82é\81D",
1750                 shkname(shkp), dtmp, currency(dtmp));
1751 #endif
1752         pline1(sbuf);
1753         if (umoney + eshkp->credit < dtmp) {
1754 #if 0 /*JP*/
1755             pline("But you don't%s have enough gold%s.",
1756                   stashed_gold ? " seem to" : "",
1757                   eshkp->credit ? " or credit" : "");
1758 #else
1759             pline("\82µ\82©\82µ\81C\82¨\8bà%s\91«\82è\82È\82¢%s\81D",
1760                   eshkp->credit ? "\82à\97a\82¯\8bà\82à" : "\82ª",
1761                   stashed_gold ? "\82æ\82¤\82¾" : "");
1762 #endif
1763             return 1;
1764         } else {
1765             if (eshkp->credit >= dtmp) {
1766                 eshkp->credit -= dtmp;
1767                 eshkp->debit = 0L;
1768                 eshkp->loan = 0L;
1769 /*JP
1770                 Your("debt is covered by your credit.");
1771 */
1772                 Your("\8eØ\8bà\82Í\97a\82¯\8bà\82Å\95â\82í\82ê\82½\81D");
1773             } else if (!eshkp->credit) {
1774                 money2mon(shkp, dtmp);
1775                 eshkp->debit = 0L;
1776                 eshkp->loan = 0L;
1777 /*JP
1778                 You("pay that debt.");
1779 */
1780                 You("\8eØ\8bà\82ð\95¥\82Á\82½\81D");
1781                 context.botl = 1;
1782             } else {
1783                 dtmp -= eshkp->credit;
1784                 eshkp->credit = 0L;
1785                 money2mon(shkp, dtmp);
1786                 eshkp->debit = 0L;
1787                 eshkp->loan = 0L;
1788 /*JP
1789                 pline("That debt is partially offset by your credit.");
1790 */
1791                 pline("\82»\82Ì\8eØ\8bà\82Í\88ê\95\94\97a\82¯\8bà\82Å\91\8a\8eE\82³\82ê\82½\81D");
1792 /*JP
1793                 You("pay the remainder.");
1794 */
1795                 You("\8ec\82è\82ð\95¥\82Á\82½\81D");
1796                 context.botl = 1;
1797             }
1798             paid = TRUE;
1799         }
1800     }
1801     /* now check items on bill */
1802     if (eshkp->billct) {
1803         register boolean itemize;
1804         int iprompt;
1805
1806         umoney = money_cnt(invent);
1807         if (!umoney && !eshkp->credit) {
1808 #if 0 /*JP*/
1809             You("%shave no money or credit%s.",
1810                 stashed_gold ? "seem to " : "", paid ? " left" : "");
1811 #else
1812             You("%s\82¨\8bà\82à\97a\82¯\8bà\82à\8e\9d\82Á\82Ä\82È\82¢%s\81D",
1813                 paid ? "\82à\82¤" : "", stashed_gold ? "\82æ\82¤\82¾" : "");
1814 #endif
1815             return 0;
1816         }
1817         if ((umoney + eshkp->credit) < cheapest_item(shkp)) {
1818 #if 0 /*JP*/
1819             You("don't have enough money to buy%s the item%s you picked.",
1820                 eshkp->billct > 1 ? " any of" : "", plur(eshkp->billct));
1821 #else
1822             pline("\8fE\82Á\82½\95i\95¨\82ð\94\83\82¤\82É\82Í\82¨\8bà\82ª\91«\82è\82È\82¢\81D");
1823 #endif
1824             if (stashed_gold)
1825 /*JP
1826                 pline("Maybe you have some gold stashed away?");
1827 */
1828                 You("\82Ç\82±\82©\82É\82¨\8bà\82ð\89B\82µ\82Ä\82¢\82é\82Ì\82©\82à\81H");
1829             return 0;
1830         }
1831
1832         /* this isn't quite right; it itemizes without asking if the
1833          * single item on the bill is partly used up and partly unpaid */
1834 /*JP
1835         iprompt = (eshkp->billct > 1 ? ynq("Itemized billing?") : 'y');
1836 */
1837         iprompt = (eshkp->billct > 1 ? ynq("\8cÂ\95Ê\82É\8a¨\92è\82µ\82Ü\82·\82©\81H") : 'y');
1838         itemize = (iprompt == 'y');
1839         if (iprompt == 'q')
1840             goto thanks;
1841
1842         for (pass = 0; pass <= 1; pass++) {
1843             tmp = 0;
1844             while (tmp < eshkp->billct) {
1845                 struct obj *otmp;
1846                 register struct bill_x *bp = &(eshkp->bill_p[tmp]);
1847
1848                 /* find the object on one of the lists */
1849                 if ((otmp = bp_to_obj(bp)) != 0) {
1850                     /* if completely used up, object quantity is stale;
1851                        restoring it to its original value here avoids
1852                        making the partly-used-up code more complicated */
1853                     if (bp->useup)
1854                         otmp->quan = bp->bquan;
1855                 } else {
1856                     impossible("Shopkeeper administration out of order.");
1857                     setpaid(shkp); /* be nice to the player */
1858                     return 1;
1859                 }
1860                 if (pass == bp->useup && otmp->quan == bp->bquan) {
1861                     /* pay for used-up items on first pass and others
1862                      * on second, so player will be stuck in the store
1863                      * less often; things which are partly used up
1864                      * are processed on both passes */
1865                     tmp++;
1866                 } else {
1867                     switch (dopayobj(shkp, bp, &otmp, pass, itemize)) {
1868                     case PAY_CANT:
1869                         return 1; /*break*/
1870                     case PAY_BROKE:
1871                         paid = TRUE;
1872                         goto thanks; /*break*/
1873                     case PAY_SKIP:
1874                         tmp++;
1875                         continue; /*break*/
1876                     case PAY_SOME:
1877                         paid = TRUE;
1878                         if (itemize)
1879                             bot();
1880                         continue; /*break*/
1881                     case PAY_BUY:
1882                         paid = TRUE;
1883                         break;
1884                     }
1885                     if (itemize)
1886                         bot();
1887                     *bp = eshkp->bill_p[--eshkp->billct];
1888                 }
1889             }
1890         }
1891  thanks:
1892         if (!itemize)
1893             update_inventory(); /* Done in dopayobj() if itemize. */
1894     }
1895     if (!ANGRY(shkp) && paid) {
1896         if (!Deaf && !muteshk(shkp))
1897 #if 0 /*JP:T*/
1898             verbalize("Thank you for shopping in %s %s!",
1899                       s_suffix(shkname(shkp)),
1900                       shtypes[eshkp->shoptype - SHOPBASE].name);
1901 #else
1902             verbalize("%s\82Ì%s\82Ö\82Ü\82½\82Ç\82¤\82¼\81I",
1903                       shkname(shkp),
1904                       shtypes[eshkp->shoptype - SHOPBASE].name);
1905 #endif
1906         else
1907 #if 0 /*JP:T*/
1908             pline("%s nods appreciatively at you for shopping in %s %s!",
1909                   Shknam(shkp), noit_mhis(shkp),
1910                   shtypes[eshkp->shoptype - SHOPBASE].name);
1911 #else
1912             pline("%s\82Í%s\82Å\82Ì\94\83\82¢\95¨\82É\8a´\8eÓ\82µ\82Ä\82¤\82È\82Ã\82¢\82½\81I",
1913                   Shknam(shkp),
1914                   shtypes[eshkp->shoptype - SHOPBASE].name);
1915 #endif
1916     }
1917     return 1;
1918 }
1919
1920 /* return 2 if used-up portion paid
1921  *        1 if paid successfully
1922  *        0 if not enough money
1923  *       -1 if skip this object
1924  *       -2 if no money/credit left
1925  */
1926 STATIC_OVL int
1927 dopayobj(shkp, bp, obj_p, which, itemize)
1928 register struct monst *shkp;
1929 register struct bill_x *bp;
1930 struct obj **obj_p;
1931 int which; /* 0 => used-up item, 1 => other (unpaid or lost) */
1932 boolean itemize;
1933 {
1934     register struct obj *obj = *obj_p;
1935     long ltmp, quan, save_quan;
1936     long umoney = money_cnt(invent);
1937     int buy;
1938     boolean stashed_gold = (hidden_gold() > 0L), consumed = (which == 0);
1939
1940     if (!obj->unpaid && !bp->useup) {
1941         impossible("Paid object on bill??");
1942         return PAY_BUY;
1943     }
1944     if (itemize && umoney + ESHK(shkp)->credit == 0L) {
1945 #if 0 /*JP*/
1946         You("%shave no money or credit left.",
1947             stashed_gold ? "seem to " : "");
1948 #else
1949         You("\82à\82¤\82¨\8bà\82à\97a\82¯\8bà\82à\82È\82¢%s\81D",
1950             stashed_gold ? "\82æ\82¤\82¾" : "");
1951 #endif
1952         return PAY_BROKE;
1953     }
1954     /* we may need to temporarily adjust the object, if part of the
1955        original quantity has been used up but part remains unpaid  */
1956     save_quan = obj->quan;
1957     if (consumed) {
1958         /* either completely used up (simple), or split needed */
1959         quan = bp->bquan;
1960         if (quan > obj->quan) /* difference is amount used up */
1961             quan -= obj->quan;
1962     } else {
1963         /* dealing with ordinary unpaid item */
1964         quan = obj->quan;
1965     }
1966     obj->quan = quan;        /* to be used by doname() */
1967     obj->unpaid = 0;         /* ditto */
1968     iflags.suppress_price++; /* affects containers */
1969     ltmp = bp->price * quan;
1970     buy = PAY_BUY; /* flag; if changed then return early */
1971
1972     if (itemize) {
1973         char qbuf[BUFSZ], qsfx[BUFSZ];
1974
1975 /*JP
1976         Sprintf(qsfx, " for %ld %s.  Pay?", ltmp, currency(ltmp));
1977 */
1978         Sprintf(qsfx, "\82Í%ld%s\82Å\82·.\94\83\82¢\82Ü\82·\82©\81H", ltmp, currency(ltmp));
1979 #if 0 /*JP*/
1980         (void) safe_qbuf(qbuf, (char *) 0, qsfx, obj,
1981                          (quan == 1L) ? Doname2 : doname, ansimpleoname,
1982                          (quan == 1L) ? "that" : "those");
1983 #else
1984         (void) safe_qbuf(qbuf, (char *) 0, qsfx, obj,
1985                          (quan == 1L) ? Doname2 : doname, ansimpleoname,
1986                          "\82»\82ê");
1987 #endif
1988         if (yn(qbuf) == 'n') {
1989             buy = PAY_SKIP;                         /* don't want to buy */
1990         } else if (quan < bp->bquan && !consumed) { /* partly used goods */
1991             obj->quan = bp->bquan - save_quan;      /* used up amount */
1992             if (!Deaf && !muteshk(shkp)) {
1993 #if 0 /*JP*/
1994                 verbalize("%s for the other %s before buying %s.",
1995                       ANGRY(shkp) ? "Pay" : "Please pay",
1996                       simpleonames(obj), /* short name suffices */
1997                       save_quan > 1L ? "these" : "this one");
1998 #else
1999                 verbalize("\82»\82ê\82ð\94\83\82¤\82Ü\82¦\82É\91¼\82Ì%s\82ð%s",
2000                       simpleonames(obj),
2001                       ANGRY(shkp) ? "\95¥\82¦\81I" : "\95¥\82Á\82Ä\82­\82¾\82³\82¢\81D");
2002 #endif
2003             } else {
2004 #if 0 /*JP*/
2005                 pline("%s %s%s your bill for the other %s first.",
2006                       Shknam(shkp),
2007                       ANGRY(shkp) ? "angrily " : "",
2008                       nolimbs(shkp->data) ? "motions to" : "points out",
2009                       simpleonames(obj));
2010 #else
2011                 pline("%s\82Í%s\91¼\82Ì%s\82Ì\82½\82ß\82Ì\8ex\95¥\82¢\82ð\90æ\82É\82·\82é\82æ\82¤\82É\91£\82µ\82½\81D",
2012                       Shknam(shkp),
2013                       ANGRY(shkp) ? "\93{\82Á\82Ä" : "",
2014                       simpleonames(obj));
2015 #endif
2016             }
2017             buy = PAY_SKIP; /* shk won't sell */
2018         }
2019     }
2020     if (buy == PAY_BUY && umoney + ESHK(shkp)->credit < ltmp) {
2021 #if 0 /*JP*/
2022         You("don't%s have gold%s enough to pay for %s.",
2023             stashed_gold ? " seem to" : "",
2024             (ESHK(shkp)->credit > 0L) ? " or credit" : "",
2025             thesimpleoname(obj));
2026 #else
2027         You("%s\82Ì\91ã\8bà\82ð\8ex\95¥\82¤\82¾\82¯\82Ì\82¨\8bà%s\8e\9d\82Á\82Ä\82È\82¢%s\81D",
2028             thesimpleoname(obj),
2029             (ESHK(shkp)->credit > 0L) ? "\82à\97a\82¯\8bà\82à" : "\82ð",
2030             stashed_gold ? "\82æ\82¤\82¾" : "");
2031 #endif
2032         buy = itemize ? PAY_SKIP : PAY_CANT;
2033     }
2034
2035     if (buy != PAY_BUY) {
2036         /* restore unpaid object to original state */
2037         obj->quan = save_quan;
2038         obj->unpaid = 1;
2039         iflags.suppress_price--;
2040         return buy;
2041     }
2042
2043     pay(ltmp, shkp);
2044 #if 0 /*JP*/
2045     shk_names_obj(shkp, obj,
2046                   consumed ? "paid for %s at a cost of %ld gold piece%s.%s"
2047                            : "bought %s for %ld gold piece%s.%s",
2048                   ltmp, "");
2049 #else
2050     shk_names_obj(shkp, obj,
2051                   consumed ? "%s\82É\8bà\89Ý%ld\96\87%s\82ð\8ex\95¥\82Á\82½\81D%s"
2052                            : "%s\82ð\8bà\89Ý%ld\96\87%s\82Å\94\83\82Á\82½\81D%s",
2053                   ltmp, "");
2054 #endif
2055     obj->quan = save_quan; /* restore original count */
2056     /* quan => amount just bought, save_quan => remaining unpaid count */
2057     if (consumed) {
2058         if (quan != bp->bquan) {
2059             /* eliminate used-up portion; remainder is still unpaid */
2060             bp->bquan = obj->quan;
2061             obj->unpaid = 1;
2062             bp->useup = 0;
2063             buy = PAY_SOME;
2064         } else { /* completely used-up, so get rid of it */
2065             obj_extract_self(obj);
2066             /* assert( obj == *obj_p ); */
2067             dealloc_obj(obj);
2068             *obj_p = 0; /* destroy pointer to freed object */
2069         }
2070     } else if (itemize)
2071         update_inventory(); /* Done just once in dopay() if !itemize. */
2072     iflags.suppress_price--;
2073     return buy;
2074 }
2075
2076 static struct repo { /* repossession context */
2077     struct monst *shopkeeper;
2078     coord location;
2079 } repo;
2080
2081 /* routine called after dying (or quitting) */
2082 boolean
2083 paybill(croaked, silently)
2084 int croaked; /* -1: escaped dungeon; 0: quit; 1: died */
2085 boolean silently; /* maybe avoid messages */
2086 {
2087     struct monst *mtmp, *mtmp2, *firstshk, *resident, *creditor, *hostile,
2088         *localshk;
2089     struct eshk *eshkp;
2090     boolean taken = FALSE, local;
2091     int numsk = 0;
2092
2093     /* if we escaped from the dungeon, shopkeepers can't reach us;
2094        shops don't occur on level 1, but this could happen if hero
2095        level teleports out of the dungeon and manages not to die */
2096     if (croaked < 0)
2097         return FALSE;
2098     /* [should probably also return false when dead hero has been
2099         petrified since shk shouldn't be able to grab inventory
2100         which has been shut inside a statue] */
2101
2102     /* this is where inventory will end up if any shk takes it */
2103     repo.location.x = repo.location.y = 0;
2104     repo.shopkeeper = 0;
2105
2106     /*
2107      * Scan all shopkeepers on the level, to prioritize them:
2108      * 1) keeper of shop hero is inside and who is owed money,
2109      * 2) keeper of shop hero is inside who isn't owed any money,
2110      * 3) other shk who is owed money, 4) other shk who is angry,
2111      * 5) any shk local to this level, and if none is found,
2112      * 6) first shk on monster list (last resort; unlikely, since
2113      * any nonlocal shk will probably be in the owed category
2114      * and almost certainly be in the angry category).
2115      */
2116     resident = creditor = hostile = localshk = (struct monst *) 0;
2117     for (mtmp = next_shkp(fmon, FALSE); mtmp;
2118          mtmp = next_shkp(mtmp2, FALSE)) {
2119         mtmp2 = mtmp->nmon;
2120         eshkp = ESHK(mtmp);
2121         local = on_level(&eshkp->shoplevel, &u.uz);
2122         if (local && index(u.ushops, eshkp->shoproom)) {
2123             /* inside this shk's shop [there might be more than one
2124                resident shk if hero is standing in a breech of a shared
2125                wall, so give priority to one who's also owed money] */
2126             if (!resident || eshkp->billct || eshkp->debit || eshkp->robbed)
2127                 resident = mtmp;
2128         } else if (eshkp->billct || eshkp->debit || eshkp->robbed) {
2129             /* owe this shopkeeper money (might also owe others) */
2130             if (!creditor)
2131                 creditor = mtmp;
2132         } else if (eshkp->following || ANGRY(mtmp)) {
2133             /* this shopkeeper is antagonistic (others might be too) */
2134             if (!hostile)
2135                 hostile = mtmp;
2136         } else if (local) {
2137             /* this shopkeeper's shop is on current level */
2138             if (!localshk)
2139                 localshk = mtmp;
2140         }
2141     }
2142
2143     /* give highest priority shopkeeper first crack */
2144     firstshk = resident ? resident
2145                         : creditor ? creditor
2146                                    : hostile ? hostile
2147                                              : localshk;
2148     if (firstshk) {
2149         numsk++;
2150         taken = inherits(firstshk, numsk, croaked, silently);
2151     }
2152
2153     /* now handle the rest */
2154     for (mtmp = next_shkp(fmon, FALSE); mtmp;
2155          mtmp = next_shkp(mtmp2, FALSE)) {
2156         mtmp2 = mtmp->nmon;
2157         eshkp = ESHK(mtmp);
2158         local = on_level(&eshkp->shoplevel, &u.uz);
2159         if (mtmp != firstshk) {
2160             numsk++;
2161             taken |= inherits(mtmp, numsk, croaked, silently);
2162         }
2163         /* for bones: we don't want a shopless shk around */
2164         if (!local)
2165             mongone(mtmp);
2166     }
2167     return taken;
2168 }
2169
2170 STATIC_OVL boolean
2171 inherits(shkp, numsk, croaked, silently)
2172 struct monst *shkp;
2173 int numsk;
2174 int croaked;
2175 boolean silently;
2176 {
2177     long loss = 0L;
2178     long umoney;
2179     struct eshk *eshkp = ESHK(shkp);
2180     boolean take = FALSE, taken = FALSE;
2181     unsigned save_minvis = shkp->minvis;
2182     int roomno = *u.ushops;
2183     char takes[BUFSZ];
2184
2185     /* not strictly consistent; affects messages and prevents next player
2186        (if bones are saved) from blundering into or being ambused by an
2187        invisible shopkeeper */
2188     shkp->minvis = 0;
2189     /* The simplifying principle is that first-come
2190        already took everything you had. */
2191     if (numsk > 1) {
2192         if (cansee(shkp->mx, shkp->my) && croaked && !silently) {
2193             takes[0] = '\0';
2194             if (has_head(shkp->data) && !rn2(2))
2195 #if 0 /*JP:T*/
2196                 Sprintf(takes, ", shakes %s %s,", noit_mhis(shkp),
2197                         mbodypart(shkp, HEAD));
2198 #else
2199                 Strcpy(takes, "\8eñ\82ð\90U\82è\81C");
2200 #endif
2201 #if 0 /*JP:T*/
2202             pline("%s %slooks at your corpse%s and %s.", Shknam(shkp),
2203                   (!shkp->mcanmove || shkp->msleeping) ? "wakes up, " : "",
2204                   takes, !inhishop(shkp) ? "disappears" : "sighs");
2205 #else
2206             pline("%s\82Í%s\82 \82È\82½\82Ì\8e\80\91Ì\82ð\8c©\82Ä%s%s\81D", Shknam(shkp),
2207                   (!shkp->mcanmove || shkp->msleeping) ? "\96Ú\82ð\82³\82Ü\82·\82Æ" : "",
2208                   takes, !inhishop(shkp) ? "\8ep\82ð\8fÁ\82µ\82½" : "\97­\91§\82ð\82Â\82¢\82½");
2209 #endif
2210         }
2211         rouse_shk(shkp, FALSE); /* wake shk for bones */
2212         taken = (roomno == eshkp->shoproom);
2213         goto skip;
2214     }
2215
2216     /* get one case out of the way: you die in the shop, the */
2217     /* shopkeeper is peaceful, nothing stolen, nothing owed. */
2218     if (roomno == eshkp->shoproom && inhishop(shkp) && !eshkp->billct
2219         && !eshkp->robbed && !eshkp->debit && NOTANGRY(shkp)
2220         && !eshkp->following && u.ugrave_arise < LOW_PM) {
2221         taken = (invent != 0);
2222         if (taken && !silently)
2223 /*JP
2224             pline("%s gratefully inherits all your possessions.",
2225 */
2226             pline("%s\82Í\82 \82È\82½\82Ì\8e\9d\82¿\95¨\82ð\82 \82è\82ª\82½\82­\8eó\82¯\82Æ\82Á\82½\81D",
2227                   Shknam(shkp));
2228         set_repo_loc(shkp);
2229         goto clear;
2230     }
2231
2232     if (eshkp->billct || eshkp->debit || eshkp->robbed) {
2233         if (roomno == eshkp->shoproom && inhishop(shkp))
2234             loss = addupbill(shkp) + eshkp->debit;
2235         if (loss < eshkp->robbed)
2236             loss = eshkp->robbed;
2237         take = TRUE;
2238     }
2239
2240     if (eshkp->following || ANGRY(shkp) || take) {
2241         if (!invent)
2242             goto skip;
2243         umoney = money_cnt(invent);
2244         takes[0] = '\0';
2245         if (!shkp->mcanmove || shkp->msleeping)
2246 /*JP
2247             Strcat(takes, "wakes up and ");
2248 */
2249             Strcat(takes, "\96Ú\82ª\82³\82ß\82é\82Æ\81C");
2250         if (distu(shkp->mx, shkp->my) > 2)
2251 /*JP
2252             Strcat(takes, "comes and ");
2253 */
2254             Strcat(takes, "\8bß\82Ã\82«\81C");
2255 #if 0 /*JP*/
2256         Strcat(takes, "takes");
2257 #endif
2258
2259         if (loss > umoney || !loss || roomno == eshkp->shoproom) {
2260             eshkp->robbed -= umoney;
2261             if (eshkp->robbed < 0L)
2262                 eshkp->robbed = 0L;
2263             if (umoney > 0L) {
2264                 money2mon(shkp, umoney);
2265                 context.botl = 1;
2266             }
2267             if (!silently)
2268 /*JP
2269                 pline("%s %s all your possessions.", Shknam(shkp), takes);
2270 */
2271                 pline("%s\82Í%s\82 \82È\82½\82Ì\8e\9d\82¿\95¨\82·\82×\82Ä\82ð\82à\82ç\82Á\82½\81D", Shknam(shkp), takes);
2272             taken = TRUE;
2273             /* where to put player's invent (after disclosure) */
2274             set_repo_loc(shkp);
2275         } else {
2276             money2mon(shkp, loss);
2277             context.botl = 1;
2278             if (!silently)
2279 #if 0 /*JP:T*/
2280                 pline("%s %s the %ld %s %sowed %s.", Shknam(shkp),
2281                       takes, loss, currency(loss),
2282                       strncmp(eshkp->customer, plname, PL_NSIZ) ? "" : "you ",
2283                       noit_mhim(shkp));
2284 #else
2285                 pline("%s\82Í%s%s\8eØ\82è\82Ä\82¢\82é%ld%s\82ð\8eó\82¯\82Æ\82Á\82½\81D", Shknam(shkp),
2286                       takes,
2287                       strncmp(eshkp->customer, plname, PL_NSIZ) ? "" : "\82 \82È\82½\82ª",
2288                       loss, currency(loss));
2289 #endif
2290             /* shopkeeper has now been paid in full */
2291             pacify_shk(shkp);
2292             eshkp->following = 0;
2293             eshkp->robbed = 0L;
2294         }
2295  skip:
2296         /* in case we create bones */
2297         rouse_shk(shkp, FALSE); /* wake up */
2298         if (!inhishop(shkp))
2299             home_shk(shkp, FALSE);
2300     }
2301  clear:
2302     shkp->minvis = save_minvis;
2303     setpaid(shkp);
2304     return taken;
2305 }
2306
2307 STATIC_OVL void
2308 set_repo_loc(shkp)
2309 struct monst *shkp;
2310 {
2311     register xchar ox, oy;
2312     struct eshk *eshkp = ESHK(shkp);
2313
2314     /* if you're not in this shk's shop room, or if you're in its doorway
2315         or entry spot, then your gear gets dumped all the way inside */
2316     if (*u.ushops != eshkp->shoproom || IS_DOOR(levl[u.ux][u.uy].typ)
2317         || (u.ux == eshkp->shk.x && u.uy == eshkp->shk.y)) {
2318         /* shk.x,shk.y is the position immediately in
2319          * front of the door -- move in one more space
2320          */
2321         ox = eshkp->shk.x;
2322         oy = eshkp->shk.y;
2323         ox += sgn(ox - eshkp->shd.x);
2324         oy += sgn(oy - eshkp->shd.y);
2325     } else { /* already inside this shk's shop */
2326         ox = u.ux;
2327         oy = u.uy;
2328     }
2329     /* finish_paybill will deposit invent here */
2330     repo.location.x = ox;
2331     repo.location.y = oy;
2332     repo.shopkeeper = shkp;
2333 }
2334
2335 /* called at game exit, after inventory disclosure but before making bones;
2336    shouldn't issue any messages */
2337 void
2338 finish_paybill()
2339 {
2340     struct monst *shkp = repo.shopkeeper;
2341     int ox = repo.location.x, oy = repo.location.y;
2342
2343 #if 0 /* don't bother */
2344     if (ox == 0 && oy == 0)
2345         impossible("finish_paybill: no location");
2346 #endif
2347     /* normally done by savebones(), but that's too late in this case */
2348     unleash_all();
2349     /* if hero has any gold left, take it into shopkeeper's possession */
2350     if (shkp) {
2351         long umoney = money_cnt(invent);
2352
2353         if (umoney)
2354             money2mon(shkp, umoney);
2355     }
2356     /* transfer rest of the character's inventory to the shop floor */
2357     drop_upon_death((struct monst *) 0, (struct obj *) 0, ox, oy);
2358 }
2359
2360 /* find obj on one of the lists */
2361 STATIC_OVL struct obj *
2362 bp_to_obj(bp)
2363 register struct bill_x *bp;
2364 {
2365     register struct obj *obj;
2366     register unsigned int id = bp->bo_id;
2367
2368     if (bp->useup)
2369         obj = o_on(id, billobjs);
2370     else
2371         obj = find_oid(id);
2372     return obj;
2373 }
2374
2375 /*
2376  * Look for o_id on all lists but billobj.  Return obj or NULL if not found.
2377  * Its OK for restore_timers() to call this function, there should not
2378  * be any timeouts on the billobjs chain.
2379  */
2380 struct obj *
2381 find_oid(id)
2382 unsigned id;
2383 {
2384     struct obj *obj;
2385     struct monst *mon, *mmtmp[3];
2386     int i;
2387
2388     /* first check various obj lists directly */
2389     if ((obj = o_on(id, invent)) != 0)
2390         return obj;
2391     if ((obj = o_on(id, fobj)) != 0)
2392         return obj;
2393     if ((obj = o_on(id, level.buriedobjlist)) != 0)
2394         return obj;
2395     if ((obj = o_on(id, migrating_objs)) != 0)
2396         return obj;
2397
2398     /* not found yet; check inventory for members of various monst lists */
2399     mmtmp[0] = fmon;
2400     mmtmp[1] = migrating_mons;
2401     mmtmp[2] = mydogs; /* for use during level changes */
2402     for (i = 0; i < 3; i++)
2403         for (mon = mmtmp[i]; mon; mon = mon->nmon)
2404             if ((obj = o_on(id, mon->minvent)) != 0)
2405                 return obj;
2406
2407     /* not found at all */
2408     return (struct obj *) 0;
2409 }
2410
2411 /* Returns the price of an arbitrary item in the shop,
2412    0 if the item doesn't belong to a shopkeeper or hero is not in the shop. */
2413 long
2414 get_cost_of_shop_item(obj, nochrg)
2415 register struct obj *obj;
2416 int *nochrg; /* alternate return value: 1: no charge, 0: shop owned,        */
2417 {            /* -1: not in a shop (so should't be formatted as "no charge") */
2418     struct monst *shkp;
2419     struct obj *top;
2420     xchar x, y;
2421     boolean freespot;
2422     long cost = 0L;
2423
2424     *nochrg = -1; /* assume 'not applicable' */
2425     if (*u.ushops && obj->oclass != COIN_CLASS
2426         && obj != uball && obj != uchain
2427         && get_obj_location(obj, &x, &y, CONTAINED_TOO)
2428         && *in_rooms(x, y, SHOPBASE) == *u.ushops
2429         && (shkp = shop_keeper(inside_shop(x, y))) != 0 && inhishop(shkp)) {
2430         for (top = obj; top->where == OBJ_CONTAINED; top = top->ocontainer)
2431             continue;
2432         freespot = (top->where == OBJ_FLOOR
2433                     && x == ESHK(shkp)->shk.x && y == ESHK(shkp)->shk.y);
2434         /* no_charge is only set for floor items inside shop proper;
2435            items on freespot are implicitly 'no charge' */
2436         *nochrg = (top->where == OBJ_FLOOR && (obj->no_charge || freespot));
2437
2438         if (carried(top) ? (int) obj->unpaid : !*nochrg)
2439             cost = obj->quan * get_cost(obj, shkp);
2440         if (Has_contents(obj) && !freespot)
2441             cost += contained_cost(obj, shkp, 0L, FALSE, TRUE);
2442     }
2443     return cost;
2444 }
2445
2446 /* decide whether to apply a surcharge (or hypothetically, a discount) to obj
2447    if it had ID number 'oid'; returns 1: increase, 0: normal, -1: decrease */
2448 int
2449 oid_price_adjustment(obj, oid)
2450 struct obj *obj;
2451 unsigned oid;
2452 {
2453     int res = 0, otyp = obj->otyp;
2454
2455     if (!(obj->dknown && objects[otyp].oc_name_known)
2456         && (obj->oclass != GEM_CLASS || objects[otyp].oc_material != GLASS)) {
2457         res = ((oid % 4) == 0); /* id%4 ==0 -> +1, ==1..3 -> 0 */
2458     }
2459     return res;
2460 }
2461
2462 /* calculate the value that the shk will charge for [one of] an object */
2463 STATIC_OVL long
2464 get_cost(obj, shkp)
2465 register struct obj *obj;
2466 register struct monst *shkp; /* if angry, impose a surcharge */
2467 {
2468     long tmp = getprice(obj, FALSE),
2469          /* used to perform a single calculation even when multiple
2470             adjustments (unID'd, dunce/tourist, charisma) are made */
2471         multiplier = 1L, divisor = 1L;
2472
2473     if (!tmp)
2474         tmp = 5L;
2475     /* shopkeeper may notice if the player isn't very knowledgeable -
2476        especially when gem prices are concerned */
2477     if (!obj->dknown || !objects[obj->otyp].oc_name_known) {
2478         if (obj->oclass == GEM_CLASS
2479             && objects[obj->otyp].oc_material == GLASS) {
2480             int i;
2481             /* get a value that's 'random' from game to game, but the
2482                same within the same game */
2483             boolean pseudorand =
2484                 (((int) ubirthday % obj->otyp) >= obj->otyp / 2);
2485
2486             /* all gems are priced high - real or not */
2487             switch (obj->otyp - LAST_GEM) {
2488             case 1: /* white */
2489                 i = pseudorand ? DIAMOND : OPAL;
2490                 break;
2491             case 2: /* blue */
2492                 i = pseudorand ? SAPPHIRE : AQUAMARINE;
2493                 break;
2494             case 3: /* red */
2495                 i = pseudorand ? RUBY : JASPER;
2496                 break;
2497             case 4: /* yellowish brown */
2498                 i = pseudorand ? AMBER : TOPAZ;
2499                 break;
2500             case 5: /* orange */
2501                 i = pseudorand ? JACINTH : AGATE;
2502                 break;
2503             case 6: /* yellow */
2504                 i = pseudorand ? CITRINE : CHRYSOBERYL;
2505                 break;
2506             case 7: /* black */
2507                 i = pseudorand ? BLACK_OPAL : JET;
2508                 break;
2509             case 8: /* green */
2510                 i = pseudorand ? EMERALD : JADE;
2511                 break;
2512             case 9: /* violet */
2513                 i = pseudorand ? AMETHYST : FLUORITE;
2514                 break;
2515             default:
2516                 impossible("bad glass gem %d?", obj->otyp);
2517                 i = STRANGE_OBJECT;
2518                 break;
2519             }
2520             tmp = (long) objects[i].oc_cost;
2521         } else if (oid_price_adjustment(obj, obj->o_id) > 0) {
2522             /* unid'd, arbitrarily impose surcharge: tmp *= 4/3 */
2523             multiplier *= 4L;
2524             divisor *= 3L;
2525         }
2526     }
2527     if (uarmh && uarmh->otyp == DUNCE_CAP)
2528         multiplier *= 4L, divisor *= 3L;
2529     else if ((Role_if(PM_TOURIST) && u.ulevel < (MAXULEV / 2))
2530              || (uarmu && !uarm && !uarmc)) /* touristy shirt visible */
2531         multiplier *= 4L, divisor *= 3L;
2532
2533     if (ACURR(A_CHA) > 18)
2534         divisor *= 2L;
2535     else if (ACURR(A_CHA) == 18)
2536         multiplier *= 2L, divisor *= 3L;
2537     else if (ACURR(A_CHA) >= 16)
2538         multiplier *= 3L, divisor *= 4L;
2539     else if (ACURR(A_CHA) <= 5)
2540         multiplier *= 2L;
2541     else if (ACURR(A_CHA) <= 7)
2542         multiplier *= 3L, divisor *= 2L;
2543     else if (ACURR(A_CHA) <= 10)
2544         multiplier *= 4L, divisor *= 3L;
2545
2546     /* tmp = (tmp * multiplier) / divisor [with roundoff tweak] */
2547     tmp *= multiplier;
2548     if (divisor > 1L) {
2549         /* tmp = (((tmp * 10) / divisor) + 5) / 10 */
2550         tmp *= 10L;
2551         tmp /= divisor;
2552         tmp += 5L;
2553         tmp /= 10L;
2554     }
2555
2556     if (tmp <= 0L)
2557         tmp = 1L;
2558     /* the artifact prices in artilist[] are also used as a score bonus;
2559        inflate their shop price here without affecting score calculation */
2560     if (obj->oartifact)
2561         tmp *= 4L;
2562
2563     /* anger surcharge should match rile_shk's, so we do it separately
2564        from the multiplier/divisor calculation */
2565     if (shkp && ESHK(shkp)->surcharge)
2566         tmp += (tmp + 2L) / 3L;
2567     return tmp;
2568 }
2569
2570 /* returns the price of a container's content.  the price
2571  * of the "top" container is added in the calling functions.
2572  * a different price quoted for selling as vs. buying.
2573  */
2574 long
2575 contained_cost(obj, shkp, price, usell, unpaid_only)
2576 struct obj *obj;
2577 struct monst *shkp;
2578 long price;
2579 boolean usell;
2580 boolean unpaid_only;
2581 {
2582     register struct obj *otmp, *top;
2583     xchar x, y;
2584     boolean on_floor, freespot;
2585
2586     for (top = obj; top->where == OBJ_CONTAINED; top = top->ocontainer)
2587         continue;
2588     /* pick_obj() removes item from floor, adds it to shop bill, then
2589        puts it in inventory; behave as if it is still on the floor
2590        during the add-to-bill portion of that situation */
2591     on_floor = (top->where == OBJ_FLOOR || top->where == OBJ_FREE);
2592     if (top->where == OBJ_FREE || !get_obj_location(top, &x, &y, 0))
2593         x = u.ux, y = u.uy;
2594     freespot = (on_floor && x == ESHK(shkp)->shk.x && y == ESHK(shkp)->shk.y);
2595
2596     /* price of contained objects; "top" container handled by caller */
2597     for (otmp = obj->cobj; otmp; otmp = otmp->nobj) {
2598         if (otmp->oclass == COIN_CLASS)
2599             continue;
2600
2601         if (usell) {
2602             if (saleable(shkp, otmp) && !otmp->unpaid
2603                 && otmp->oclass != BALL_CLASS
2604                 && !(otmp->oclass == FOOD_CLASS && otmp->oeaten)
2605                 && !(Is_candle(otmp)
2606                      && otmp->age < 20L * (long) objects[otmp->otyp].oc_cost))
2607                 price += set_cost(otmp, shkp);
2608         } else {
2609             /* no_charge is only set for floor items (including
2610                contents of floor containers) inside shop proper;
2611                items on freespot are implicitly 'no charge' */
2612             if (on_floor ? (!otmp->no_charge && !freespot)
2613                          : (otmp->unpaid || !unpaid_only))
2614                 price += get_cost(otmp, shkp) * otmp->quan;
2615         }
2616
2617         if (Has_contents(otmp))
2618             price = contained_cost(otmp, shkp, price, usell, unpaid_only);
2619     }
2620
2621     return price;
2622 }
2623
2624 /* count amount of gold inside container 'obj' and any nested containers */
2625 long
2626 contained_gold(obj)
2627 struct obj *obj;
2628 {
2629     register struct obj *otmp;
2630     register long value = 0L;
2631
2632     /* accumulate contained gold */
2633     for (otmp = obj->cobj; otmp; otmp = otmp->nobj)
2634         if (otmp->oclass == COIN_CLASS)
2635             value += otmp->quan;
2636         else if (Has_contents(otmp))
2637             value += contained_gold(otmp);
2638
2639     return value;
2640 }
2641
2642 STATIC_OVL void
2643 dropped_container(obj, shkp, sale)
2644 register struct obj *obj;
2645 register struct monst *shkp;
2646 register boolean sale;
2647 {
2648     register struct obj *otmp;
2649
2650     /* the "top" container is treated in the calling fn */
2651     for (otmp = obj->cobj; otmp; otmp = otmp->nobj) {
2652         if (otmp->oclass == COIN_CLASS)
2653             continue;
2654
2655         if (!otmp->unpaid && !(sale && saleable(shkp, otmp)))
2656             otmp->no_charge = 1;
2657
2658         if (Has_contents(otmp))
2659             dropped_container(otmp, shkp, sale);
2660     }
2661 }
2662
2663 void
2664 picked_container(obj)
2665 register struct obj *obj;
2666 {
2667     register struct obj *otmp;
2668
2669     /* the "top" container is treated in the calling fn */
2670     for (otmp = obj->cobj; otmp; otmp = otmp->nobj) {
2671         if (otmp->oclass == COIN_CLASS)
2672             continue;
2673
2674         if (otmp->no_charge)
2675             otmp->no_charge = 0;
2676
2677         if (Has_contents(otmp))
2678             picked_container(otmp);
2679     }
2680 }
2681
2682 STATIC_OVL boolean
2683 special_stock(obj, shkp, quietly)
2684 struct obj *obj;
2685 struct monst *shkp;
2686 boolean quietly;
2687 {
2688     /* for unique situations */
2689     if (ESHK(shkp)->shoptype == CANDLESHOP
2690         && obj->otyp == CANDELABRUM_OF_INVOCATION) {
2691         if (!quietly) {
2692             if (is_izchak(shkp, TRUE) && !u.uevent.invoked) {
2693                 if (Deaf || muteshk(shkp)) {
2694 #if 0 /*JP:T*/
2695                     pline("%s seems %s that you want to sell that.",
2696                           Shknam(shkp),
2697                           (obj->spe < 7) ? "horrified" : "concerned");
2698 #else
2699                     pline("%s\82Í\82 \82È\82½\82ª\82»\82ê\82ð\94\84\82ë\82¤\82Æ\82µ\82Ä\82¢\82é\82±\82Æ\82ð%s\82Ä\82¢\82é\82æ\82¤\82¾\81D",
2700                           Shknam(shkp),
2701                           (obj->spe < 7) ? "\8b°\82ê" : "\90S\94z\82µ");
2702 #endif
2703                 } else {
2704 /*JP
2705                 verbalize("No thanks, I'd hang onto that if I were you.");
2706 */
2707                 verbalize("\82¢\82â\81C\82¢\82ç\82È\82¢\81D\8e\84\82È\82ç\82»\82ê\82ð\8eè\95ú\82³\82È\82¢\82Ë\81D");
2708                     if (obj->spe < 7)
2709 #if 0 /*JP:T*/
2710                         verbalize(
2711                              "You'll need %d%s candle%s to go along with it.",
2712                                 (7 - obj->spe), (obj->spe > 0) ? " more" : "",
2713                                   plur(7 - obj->spe));
2714 #else
2715                         verbalize(
2716                              "\82»\82ê\82ð\8eg\82¤\82É\82Í%s%d\96{\82Ì\82ë\82¤\82»\82­\82ª\95K\97v\82¾\81D",
2717                               (obj->spe > 0) ? "\82 \82Æ" : "", (7 - obj->spe));
2718 #endif
2719                     /* [what if hero is already carrying enough candles?
2720                        should Izchak explain how to attach them instead?] */
2721                 }
2722             } else {
2723                 if (!Deaf && !muteshk(shkp))
2724 /*JP
2725                 verbalize("I won't stock that.  Take it out of here!");
2726 */
2727                 verbalize("\82»\82ê\82Í\8ed\93ü\82ê\82È\82¢\82æ\81D\8e\9d\82Á\82Ä\82¢\82«\82È\82³\82¢\81I");
2728                 else
2729 #if 0 /*JP:T*/
2730                     pline("%s shakes %s %s in refusal.",
2731                           Shknam(shkp), noit_mhis(shkp),
2732                           mbodypart(shkp, HEAD));
2733 #else
2734                     pline("%s\82Í%s\82ð\90U\82Á\82Ä\8b\91\94Û\82µ\82½\81D",
2735                           Shknam(shkp),
2736                           mbodypart(shkp, HEAD));
2737 #endif
2738             }
2739         }
2740         return TRUE;
2741     }
2742     return FALSE;
2743 }
2744
2745 /* calculate how much the shk will pay when buying [all of] an object */
2746 STATIC_OVL long
2747 set_cost(obj, shkp)
2748 register struct obj *obj;
2749 register struct monst *shkp;
2750 {
2751     long tmp = getprice(obj, TRUE) * obj->quan, multiplier = 1L, divisor = 1L;
2752
2753     if (uarmh && uarmh->otyp == DUNCE_CAP)
2754         divisor *= 3L;
2755     else if ((Role_if(PM_TOURIST) && u.ulevel < (MAXULEV / 2))
2756              || (uarmu && !uarm && !uarmc)) /* touristy shirt visible */
2757         divisor *= 3L;
2758     else
2759         divisor *= 2L;
2760
2761     /* shopkeeper may notice if the player isn't very knowledgeable -
2762        especially when gem prices are concerned */
2763     if (!obj->dknown || !objects[obj->otyp].oc_name_known) {
2764         if (obj->oclass == GEM_CLASS) {
2765             /* different shop keepers give different prices */
2766             if (objects[obj->otyp].oc_material == GEMSTONE
2767                 || objects[obj->otyp].oc_material == GLASS) {
2768                 tmp = (obj->otyp % (6 - shkp->m_id % 3));
2769                 tmp = (tmp + 3) * obj->quan;
2770             }
2771         } else if (tmp > 1L && !(shkp->m_id % 4))
2772             multiplier *= 3L, divisor *= 4L;
2773     }
2774
2775     if (tmp >= 1L) {
2776         /* [see get_cost()] */
2777         tmp *= multiplier;
2778         if (divisor > 1L) {
2779             tmp *= 10L;
2780             tmp /= divisor;
2781             tmp += 5L;
2782             tmp /= 10L;
2783         }
2784         /* avoid adjusting nonzero to zero */
2785         if (tmp < 1L)
2786             tmp = 1L;
2787     }
2788
2789     /* (no adjustment for angry shk here) */
2790     return tmp;
2791 }
2792
2793 /* unlike alter_cost() which operates on a specific item, identifying or
2794    forgetting a gem causes all unpaid gems of its type to change value */
2795 void
2796 gem_learned(oindx)
2797 int oindx;
2798 {
2799     struct obj *obj;
2800     struct monst *shkp;
2801     struct bill_x *bp;
2802     int ct;
2803
2804     /*
2805      * Unfortunately, shop bill doesn't have object type included,
2806      * just obj->oid for each unpaid stack, so we have to go through
2807      * every bill and every item on that bill and match up against
2808      * every unpaid stack on the level....
2809      *
2810      * Fortunately, there's no need to catch up when changing dungeon
2811      * levels even if we ID'd or forget some gems while gone from a
2812      * level.  There won't be any shop bills when arriving; they were
2813      * either paid before leaving or got treated as robbery and it's
2814      * too late to adjust pricing.
2815      */
2816     for (shkp = next_shkp(fmon, TRUE); shkp;
2817          shkp = next_shkp(shkp->nmon, TRUE)) {
2818         ct = ESHK(shkp)->billct;
2819         bp = ESHK(shkp)->bill;
2820         while (--ct >= 0) {
2821             obj = find_oid(bp->bo_id);
2822             if (!obj) /* shouldn't happen */
2823                 continue;
2824             if ((oindx != STRANGE_OBJECT) ? (obj->otyp == oindx)
2825                                           : (obj->oclass == GEM_CLASS))
2826                 bp->price = get_cost(obj, shkp);
2827             ++bp;
2828         }
2829     }
2830 }
2831
2832 /* called when an item's value has been enhanced; if it happens to be
2833    on any shop bill, update that bill to reflect the new higher price
2834    [if the new price drops for some reason, keep the old one in place] */
2835 void
2836 alter_cost(obj, amt)
2837 struct obj *obj;
2838 long amt; /* if 0, use regular shop pricing, otherwise force amount;
2839              if negative, use abs(amt) even if it's less than old cost */
2840 {
2841     struct bill_x *bp = 0;
2842     struct monst *shkp;
2843     long new_price;
2844
2845     for (shkp = next_shkp(fmon, TRUE); shkp; shkp = next_shkp(shkp, TRUE))
2846         if ((bp = onbill(obj, shkp, TRUE)) != 0) {
2847             new_price = !amt ? get_cost(obj, shkp) : (amt < 0L) ? -amt : amt;
2848             if (new_price > bp->price || amt < 0L) {
2849                 bp->price = new_price;
2850                 update_inventory();
2851             }
2852             break; /* done */
2853         }
2854     return;
2855 }
2856
2857 /* called from doinv(invent.c) for inventory of unpaid objects */
2858 long
2859 unpaid_cost(unp_obj, include_contents)
2860 struct obj *unp_obj; /* known to be unpaid or contain unpaid */
2861 boolean include_contents;
2862 {
2863     struct bill_x *bp = (struct bill_x *) 0;
2864     struct monst *shkp;
2865     long amt = 0L;
2866     xchar ox, oy;
2867
2868     if (!get_obj_location(unp_obj, &ox, &oy, BURIED_TOO | CONTAINED_TOO))
2869         ox = u.ux, oy = u.uy; /* (shouldn't happen) */
2870     if ((shkp = shop_keeper(*in_rooms(ox, oy, SHOPBASE))) != 0) {
2871         bp = onbill(unp_obj, shkp, TRUE);
2872     } else {
2873         /* didn't find shk?  try searching bills */
2874         for (shkp = next_shkp(fmon, TRUE); shkp;
2875              shkp = next_shkp(shkp->nmon, TRUE))
2876             if ((bp = onbill(unp_obj, shkp, TRUE)) != 0)
2877                 break;
2878     }
2879
2880     /* onbill() gave no message if unexpected problem occurred */
2881     if (!shkp || (unp_obj->unpaid && !bp)) {
2882         impossible("unpaid_cost: object wasn't on any bill.");
2883     } else {
2884         if (bp)
2885             amt = unp_obj->quan * bp->price;
2886         if (include_contents && Has_contents(unp_obj))
2887             amt = contained_cost(unp_obj, shkp, amt, FALSE, TRUE);
2888     }
2889     return amt;
2890 }
2891
2892 STATIC_OVL void
2893 add_one_tobill(obj, dummy, shkp)
2894 struct obj *obj;
2895 boolean dummy;
2896 struct monst *shkp;
2897 {
2898     struct eshk *eshkp;
2899     struct bill_x *bp;
2900     int bct;
2901
2902     if (!billable(&shkp, obj, *u.ushops, TRUE))
2903         return;
2904     eshkp = ESHK(shkp);
2905
2906     if (eshkp->billct == BILLSZ) {
2907 /*JP
2908         You("got that for free!");
2909 */
2910         You("\82»\82ê\82ð\82½\82¾\82Å\8eè\82É\93ü\82ê\82½\81I");
2911         return;
2912     }
2913
2914     /* normally bill_p gets set up whenever you enter the shop, but obj
2915        might be going onto the bill because hero just snagged it with
2916        a grappling hook from outside without ever having been inside */
2917     if (!eshkp->bill_p)
2918         eshkp->bill_p = &(eshkp->bill[0]);
2919
2920     bct = eshkp->billct;
2921     bp = &(eshkp->bill_p[bct]);
2922     bp->bo_id = obj->o_id;
2923     bp->bquan = obj->quan;
2924     if (dummy) {              /* a dummy object must be inserted into  */
2925         bp->useup = 1;        /* the billobjs chain here.  crucial for */
2926         add_to_billobjs(obj); /* eating floorfood in shop.  see eat.c  */
2927     } else
2928         bp->useup = 0;
2929     bp->price = get_cost(obj, shkp);
2930     eshkp->billct++;
2931     obj->unpaid = 1;
2932 }
2933
2934 STATIC_OVL void
2935 add_to_billobjs(obj)
2936 struct obj *obj;
2937 {
2938     if (obj->where != OBJ_FREE)
2939         panic("add_to_billobjs: obj not free");
2940     if (obj->timed)
2941         obj_stop_timers(obj);
2942
2943     obj->nobj = billobjs;
2944     billobjs = obj;
2945     obj->where = OBJ_ONBILL;
2946 }
2947
2948 /* recursive billing of objects within containers. */
2949 STATIC_OVL void
2950 bill_box_content(obj, ininv, dummy, shkp)
2951 register struct obj *obj;
2952 register boolean ininv, dummy;
2953 register struct monst *shkp;
2954 {
2955     register struct obj *otmp;
2956
2957     if (SchroedingersBox(obj))
2958         return;
2959     for (otmp = obj->cobj; otmp; otmp = otmp->nobj) {
2960         if (otmp->oclass == COIN_CLASS)
2961             continue;
2962
2963         /* the "top" box is added in addtobill() */
2964         if (!otmp->no_charge)
2965             add_one_tobill(otmp, dummy, shkp);
2966         if (Has_contents(otmp))
2967             bill_box_content(otmp, ininv, dummy, shkp);
2968     }
2969 }
2970
2971 /* shopkeeper tells you what you bought or sold, sometimes partly IDing it */
2972 STATIC_OVL void
2973 shk_names_obj(shkp, obj, fmt, amt, arg)
2974 struct monst *shkp;
2975 struct obj *obj;
2976 const char *fmt; /* "%s %ld %s %s", doname(obj), amt, plur(amt), arg */
2977 long amt;
2978 const char *arg;
2979 {
2980 #if 0 /*JP*/
2981     char *obj_name, fmtbuf[BUFSZ];
2982 #else
2983     char *obj_name;
2984 #endif
2985     boolean was_unknown = !obj->dknown;
2986
2987     obj->dknown = TRUE;
2988     /* Use real name for ordinary weapons/armor, and spell-less
2989      * scrolls/books (that is, blank and mail), but only if the
2990      * object is within the shk's area of interest/expertise.
2991      */
2992     if (!objects[obj->otyp].oc_magic && saleable(shkp, obj)
2993         && (obj->oclass == WEAPON_CLASS || obj->oclass == ARMOR_CLASS
2994             || obj->oclass == SCROLL_CLASS || obj->oclass == SPBOOK_CLASS
2995             || obj->otyp == MIRROR)) {
2996         was_unknown |= !objects[obj->otyp].oc_name_known;
2997         makeknown(obj->otyp);
2998     }
2999     obj_name = doname(obj);
3000     /* Use an alternate message when extra information is being provided */
3001 #if 0 /*JP*//*\93ú\96{\8cê\82Å\82Í\93¯\82\88µ\82¢*/
3002     if (was_unknown) {
3003         Sprintf(fmtbuf, "%%s; you %s", fmt);
3004         obj_name[0] = highc(obj_name[0]);
3005         pline(fmtbuf, obj_name, (obj->quan > 1L) ? "them" : "it", amt,
3006               plur(amt), arg);
3007     } else {
3008         You(fmt, obj_name, amt, plur(amt), arg);
3009     }
3010 #else
3011     You(fmt, obj_name, amt, "", arg);
3012 #endif
3013 }
3014
3015 /* decide whether a shopkeeper thinks an item belongs to her */
3016 boolean
3017 billable(shkpp, obj, roomno, reset_nocharge)
3018 struct monst **shkpp; /* in: non-null if shk has been validated; out: shk */
3019 struct obj *obj;
3020 char roomno;
3021 boolean reset_nocharge;
3022 {
3023     struct monst *shkp = *shkpp;
3024
3025     /* if caller hasn't supplied a shopkeeper, look one up now */
3026     if (!shkp) {
3027         if (!roomno)
3028             return FALSE;
3029         shkp = shop_keeper(roomno);
3030         if (!shkp || !inhishop(shkp))
3031             return FALSE;
3032         *shkpp = shkp;
3033     }
3034     /* perhaps we threw it away earlier */
3035     if (onbill(obj, shkp, FALSE)
3036         || (obj->oclass == FOOD_CLASS && obj->oeaten))
3037         return FALSE;
3038     /* outer container might be marked no_charge but still have contents
3039        which should be charged for; clear no_charge when picking things up */
3040     if (obj->no_charge) {
3041         if (!Has_contents(obj) || (contained_gold(obj) == 0L
3042                                    && contained_cost(obj, shkp, 0L, FALSE,
3043                                                      !reset_nocharge) == 0L))
3044             shkp = 0; /* not billable */
3045         if (reset_nocharge && !shkp && obj->oclass != COIN_CLASS) {
3046             obj->no_charge = 0;
3047             if (Has_contents(obj))
3048                 picked_container(obj); /* clear no_charge */
3049         }
3050     }
3051     return shkp ? TRUE : FALSE;
3052 }
3053
3054 void
3055 addtobill(obj, ininv, dummy, silent)
3056 struct obj *obj;
3057 boolean ininv, dummy, silent;
3058 {
3059     struct monst *shkp = 0;
3060     long ltmp, cltmp, gltmp;
3061     int contentscount;
3062     boolean container;
3063
3064     if (!billable(&shkp, obj, *u.ushops, TRUE))
3065         return;
3066
3067     if (obj->oclass == COIN_CLASS) {
3068         costly_gold(obj->ox, obj->oy, obj->quan);
3069         return;
3070     } else if (ESHK(shkp)->billct == BILLSZ) {
3071         if (!silent)
3072 /*JP
3073             You("got that for free!");
3074 */
3075             You("\82»\82ê\82ð\82½\82¾\82Å\8eè\82É\93ü\82ê\82½\81I");
3076         return;
3077     }
3078
3079     ltmp = cltmp = gltmp = 0L;
3080     container = Has_contents(obj);
3081
3082     if (!obj->no_charge)
3083         ltmp = get_cost(obj, shkp);
3084
3085     if (obj->no_charge && !container) {
3086         obj->no_charge = 0;
3087         return;
3088     }
3089
3090     if (container) {
3091         cltmp = contained_cost(obj, shkp, cltmp, FALSE, FALSE);
3092         gltmp = contained_gold(obj);
3093
3094         if (ltmp)
3095             add_one_tobill(obj, dummy, shkp);
3096         if (cltmp)
3097             bill_box_content(obj, ininv, dummy, shkp);
3098         picked_container(obj); /* reset contained obj->no_charge */
3099
3100         ltmp += cltmp;
3101
3102         if (gltmp) {
3103             costly_gold(obj->ox, obj->oy, gltmp);
3104             if (!ltmp)
3105                 return;
3106         }
3107
3108         if (obj->no_charge)
3109             obj->no_charge = 0;
3110         contentscount = count_unpaid(obj->cobj);
3111     } else { /* !container */
3112         add_one_tobill(obj, dummy, shkp);
3113         contentscount = 0;
3114     }
3115
3116     if (!Deaf && !muteshk(shkp) && !silent) {
3117         char buf[BUFSZ];
3118
3119         if (!ltmp) {
3120 /*JP
3121             pline("%s has no interest in %s.", Shknam(shkp), the(xname(obj)));
3122 */
3123             pline("%s\82Í%s\82É\8b»\96¡\82ð\8e¦\82³\82È\82¢\81D", Shknam(shkp), the(xname(obj)));
3124             return;
3125         }
3126         if (!ininv) {
3127 #if 0 /*JP*/
3128             pline("%s will cost you %ld %s%s.", The(xname(obj)), ltmp,
3129                   currency(ltmp), (obj->quan > 1L) ? " each" : "");
3130 #else
3131             pline("%s\82Í%s\82½\82Á\82½\82Ì%ld%s\82¾\81D", xname(obj),
3132                   (obj->quan > 1L) ? "\88ê\82Â" : "", ltmp, currency(ltmp));
3133 #endif
3134         } else {
3135             long save_quan = obj->quan;
3136
3137 #if 0 /*JP*/
3138             Strcpy(buf, "\"For you, ");
3139             if (ANGRY(shkp)) {
3140                 Strcat(buf, "scum;");
3141             } else {
3142                 append_honorific(buf);
3143                 Strcat(buf, "; only");
3144             }
3145 #else
3146             Strcpy(buf, "\81u");
3147             if (ANGRY(shkp)) {
3148                 Strcat(buf, "\82±\82Ì\83N\83\\82Á\82½\82ê\81C");
3149             } else {
3150                 append_honorific(buf);
3151                 Strcat(buf, "\81C");
3152             }
3153 #endif
3154             obj->quan = 1L; /* fool xname() into giving singular */
3155 #if 0 /*JP*/
3156             pline("%s %ld %s %s %s%s.\"", buf, ltmp, currency(ltmp),
3157                   (save_quan > 1L) ? "per"
3158                                    : (contentscount && !obj->unpaid)
3159                                        ? "for the contents of this"
3160                                        : "for this",
3161                   xname(obj),
3162                   (contentscount && obj->unpaid) ? and_its_contents : "");
3163 #else
3164             pline("%s%s%s\82½\82Á\82½\82Ì%ld%s\82¾\81D\81v", buf, xname(obj),
3165                   (save_quan > 1L) ? "\82Í\88ê\82Â" : (contentscount && !obj->unpaid)
3166                                                  ? "\82Ì\92\86\90g\82Í"
3167                                                  : "\82Í",
3168                   ltmp, currency(ltmp));
3169 #endif
3170             obj->quan = save_quan;
3171         }
3172     } else if (!silent) {
3173         if (ltmp)
3174 #if 0 /*JP*/
3175             pline_The("list price of %s%s%s is %ld %s%s.",
3176                       (contentscount && !obj->unpaid) ? the_contents_of : "",
3177                       the(xname(obj)),
3178                       (contentscount && obj->unpaid) ? and_its_contents : "",
3179                       ltmp, currency(ltmp), (obj->quan > 1L) ? " each" : "");
3180 #else
3181             pline_The("%s%s%s%s\82½\82Á\82½\82Ì%ld%s\82¾.",
3182                       the(xname(obj)),
3183                       (contentscount && !obj->unpaid) ? "\82Ì\92\86\90g\82Í" : "",
3184                       (contentscount && obj->unpaid) ? and_its_contents : "",
3185                       (obj->quan > 1L) ? "\82»\82ê\82¼\82ê" : "", ltmp, currency(ltmp));
3186 #endif
3187         else
3188 /*JP
3189             pline("%s does not notice.", Shknam(shkp));
3190 */
3191             pline("%s\82Í\8bC\82ª\82Â\82¢\82Ä\82¢\82È\82¢\81D", Shknam(shkp));
3192     }
3193 }
3194
3195 void
3196 append_honorific(buf)
3197 char *buf;
3198 {
3199     /* (chooses among [0]..[3] normally; [1]..[4] after the
3200        Wizard has been killed or invocation ritual performed) */
3201 #if 0 /*JP:T*/
3202     static const char *const honored[] = { "good", "honored", "most gracious",
3203                                            "esteemed",
3204                                            "most renowned and sacred" };
3205 #else
3206     static const char *const honored[] = {
3207         "\82â\82\9f", "\82â\82\9f\81C\96¼\97_\82 \82é", "\82â\82\9f\81C\8fã\95i\82È",
3208         "\82â\82\9f\81C\91¸\8ch\82·\82é",
3209         "\82â\82\9f\81C\8d\82\96¼\82Å\90_\90¹\82È"
3210         };
3211 #endif
3212
3213     Strcat(buf, honored[rn2(SIZE(honored) - 1) + u.uevent.udemigod]);
3214 #if 0 /*JP*//*\93ú\96{\8cê\82Å\82Í\82»\82±\82Ü\82Å\82µ\82È\82¢*/
3215     if (is_vampire(youmonst.data))
3216         Strcat(buf, (flags.female) ? " dark lady" : " dark lord");
3217     else if (is_elf(youmonst.data))
3218         Strcat(buf, (flags.female) ? " hiril" : " hir");
3219     else
3220 #endif
3221 #if 0 /*JP*/
3222         Strcat(buf, !is_human(youmonst.data) ? " creature"
3223                                              : (flags.female) ? " lady"
3224                                                               : " sir");
3225 #else
3226         Strcat(buf, !is_human(youmonst.data) ? "\90\95¨\82³\82ñ"
3227                                              : (flags.female) ? "\82¨\8fì\82³\82ñ"
3228                                                               : "\92U\93ß\82³\82ñ");
3229 #endif
3230 }
3231
3232 void
3233 splitbill(obj, otmp)
3234 register struct obj *obj, *otmp;
3235 {
3236     /* otmp has been split off from obj */
3237     register struct bill_x *bp;
3238     register long tmp;
3239     register struct monst *shkp = shop_keeper(*u.ushops);
3240
3241     if (!shkp || !inhishop(shkp)) {
3242         impossible("splitbill: no resident shopkeeper??");
3243         return;
3244     }
3245     bp = onbill(obj, shkp, FALSE);
3246     if (!bp) {
3247         impossible("splitbill: not on bill?");
3248         return;
3249     }
3250     if (bp->bquan < otmp->quan) {
3251         impossible("Negative quantity on bill??");
3252     }
3253     if (bp->bquan == otmp->quan) {
3254         impossible("Zero quantity on bill??");
3255     }
3256     bp->bquan -= otmp->quan;
3257
3258     if (ESHK(shkp)->billct == BILLSZ)
3259         otmp->unpaid = 0;
3260     else {
3261         tmp = bp->price;
3262         bp = &(ESHK(shkp)->bill_p[ESHK(shkp)->billct]);
3263         bp->bo_id = otmp->o_id;
3264         bp->bquan = otmp->quan;
3265         bp->useup = 0;
3266         bp->price = tmp;
3267         ESHK(shkp)->billct++;
3268     }
3269 }
3270
3271 STATIC_OVL void
3272 sub_one_frombill(obj, shkp)
3273 register struct obj *obj;
3274 register struct monst *shkp;
3275 {
3276     register struct bill_x *bp;
3277
3278     if ((bp = onbill(obj, shkp, FALSE)) != 0) {
3279         register struct obj *otmp;
3280
3281         obj->unpaid = 0;
3282         if (bp->bquan > obj->quan) {
3283             otmp = newobj();
3284             *otmp = *obj;
3285             otmp->oextra = (struct oextra *) 0;
3286             bp->bo_id = otmp->o_id = context.ident++;
3287             otmp->where = OBJ_FREE;
3288             otmp->quan = (bp->bquan -= obj->quan);
3289             otmp->owt = 0; /* superfluous */
3290             bp->useup = 1;
3291             add_to_billobjs(otmp);
3292             return;
3293         }
3294         ESHK(shkp)->billct--;
3295 #ifdef DUMB
3296         {
3297             /* DRS/NS 2.2.6 messes up -- Peter Kendell */
3298             int indx = ESHK(shkp)->billct;
3299
3300             *bp = ESHK(shkp)->bill_p[indx];
3301         }
3302 #else
3303         *bp = ESHK(shkp)->bill_p[ESHK(shkp)->billct];
3304 #endif
3305         return;
3306     } else if (obj->unpaid) {
3307         impossible("sub_one_frombill: unpaid object not on bill");
3308         obj->unpaid = 0;
3309     }
3310 }
3311
3312 /* recursive check of unpaid objects within nested containers. */
3313 void
3314 subfrombill(obj, shkp)
3315 register struct obj *obj;
3316 register struct monst *shkp;
3317 {
3318     register struct obj *otmp;
3319
3320     sub_one_frombill(obj, shkp);
3321
3322     if (Has_contents(obj))
3323         for (otmp = obj->cobj; otmp; otmp = otmp->nobj) {
3324             if (otmp->oclass == COIN_CLASS)
3325                 continue;
3326
3327             if (Has_contents(otmp))
3328                 subfrombill(otmp, shkp);
3329             else
3330                 sub_one_frombill(otmp, shkp);
3331         }
3332 }
3333
3334 STATIC_OVL long
3335 stolen_container(obj, shkp, price, ininv)
3336 struct obj *obj;
3337 struct monst *shkp;
3338 long price;
3339 boolean ininv;
3340 {
3341     struct obj *otmp;
3342     struct bill_x *bp;
3343     long billamt;
3344
3345     /* the price of contained objects; caller handles top container */
3346     for (otmp = obj->cobj; otmp; otmp = otmp->nobj) {
3347         if (otmp->oclass == COIN_CLASS)
3348             continue;
3349         billamt = 0L;
3350         if (!billable(&shkp, otmp, ESHK(shkp)->shoproom, TRUE)) {
3351             /* billable() returns false for objects already on bill */
3352             if ((bp = onbill(otmp, shkp, FALSE)) == 0)
3353                 continue;
3354             /* this assumes that we're being called by stolen_value()
3355                (or by a recursive call to self on behalf of it) where
3356                the cost of this object is about to be added to shop
3357                debt in place of having it remain on the current bill */
3358             billamt = bp->bquan * bp->price;
3359             sub_one_frombill(otmp, shkp); /* avoid double billing */
3360         }
3361
3362         if (billamt)
3363             price += billamt;
3364         else if (ininv ? otmp->unpaid : !otmp->no_charge)
3365             price += otmp->quan * get_cost(otmp, shkp);
3366
3367         if (Has_contents(otmp))
3368             price = stolen_container(otmp, shkp, price, ininv);
3369     }
3370
3371     return price;
3372 }
3373
3374 long
3375 stolen_value(obj, x, y, peaceful, silent)
3376 struct obj *obj;
3377 xchar x, y;
3378 boolean peaceful, silent;
3379 {
3380     long value = 0L, gvalue = 0L, billamt = 0L;
3381     char roomno = *in_rooms(x, y, SHOPBASE);
3382     struct bill_x *bp;
3383     struct monst *shkp = 0;
3384     boolean was_unpaid;
3385     long c_count = 0L, u_count = 0L;
3386
3387     /* gather information for message(s) prior to manipulating bill */
3388     was_unpaid = obj->unpaid ? TRUE : FALSE;
3389     if (Has_contents(obj)) {
3390         c_count = count_contents(obj, TRUE, FALSE, TRUE);
3391         u_count = count_contents(obj, TRUE, FALSE, FALSE);
3392     }
3393
3394     if (!billable(&shkp, obj, roomno, FALSE)) {
3395         /* things already on the bill yield a not-billable result, so
3396            we need to check bill before deciding that shk doesn't care */
3397         if ((bp = onbill(obj, shkp, FALSE)) != 0) {
3398             /* shk does care; take obj off bill to avoid double billing */
3399             billamt = bp->bquan * bp->price;
3400             sub_one_frombill(obj, shkp);
3401         }
3402         if (!bp && !u_count)
3403             return 0L;
3404     }
3405
3406     if (obj->oclass == COIN_CLASS) {
3407         gvalue += obj->quan;
3408     } else {
3409         if (billamt)
3410             value += billamt;
3411         else if (!obj->no_charge)
3412             value += obj->quan * get_cost(obj, shkp);
3413
3414         if (Has_contents(obj)) {
3415             boolean ininv =
3416                 (obj->where == OBJ_INVENT || obj->where == OBJ_FREE);
3417
3418             value += stolen_container(obj, shkp, 0L, ininv);
3419             if (!ininv)
3420                 gvalue += contained_gold(obj);
3421         }
3422     }
3423
3424     if (gvalue + value == 0L)
3425         return 0L;
3426
3427     value += gvalue;
3428
3429     if (peaceful) {
3430         boolean credit_use = !!ESHK(shkp)->credit;
3431
3432         value = check_credit(value, shkp);
3433         /* 'peaceful' affects general treatment, but doesn't affect
3434          * the fact that other code expects that all charges after the
3435          * shopkeeper is angry are included in robbed, not debit */
3436         if (ANGRY(shkp))
3437             ESHK(shkp)->robbed += value;
3438         else
3439             ESHK(shkp)->debit += value;
3440
3441         if (!silent) {
3442             char buf[BUFSZ];
3443             const char *still = "";
3444
3445             if (credit_use) {
3446                 if (ESHK(shkp)->credit) {
3447 #if 0 /*JP*/
3448                     You("have %ld %s credit remaining.", ESHK(shkp)->credit,
3449                         currency(ESHK(shkp)->credit));
3450 #else
3451                     You("%ld%s\82Ì\97a\82¯\8bà\82ª\8ec\82Á\82Ä\82¢\82é\81D", ESHK(shkp)->credit,
3452                         currency(ESHK(shkp)->credit));
3453 #endif
3454                     return value;
3455                 } else if (!value) {
3456 /*JP
3457                     You("have no credit remaining.");
3458 */
3459                     pline("\97a\82¯\8bà\82Í\82È\82­\82È\82Á\82½\81D");
3460                     return 0;
3461                 }
3462 /*JP
3463                 still = "still ";
3464 */
3465                 still = "\82³\82ç\82É";
3466             }
3467 #if 0 /*JP:T*/
3468             Sprintf(buf, "%sowe %s %ld %s", still, shkname(shkp),
3469                     value, currency(value));
3470 #else
3471             Sprintf(buf, "%s%s\82É%ld%s\82Ì\8eØ\82è\82ð\82Â\82­\82Á\82½", still, shkname(shkp),
3472                     value, currency(value));
3473 #endif
3474             if (u_count) /* u_count > 0 implies Has_contents(obj) */
3475                 Sprintf(eos(buf), " for %s%sits contents",
3476                         was_unpaid ? "it and " : "",
3477                         (c_count > u_count) ? "some of " : "");
3478             else if (obj->oclass != COIN_CLASS)
3479                 Sprintf(eos(buf), " for %s",
3480                         (obj->quan > 1L) ? "them" : "it");
3481
3482 #if 0 /*JP*/
3483             You("%s!", buf); /* "You owe <shk> N zorkmids for it!" */
3484 #else
3485             You("%s\81I", buf); /* "You owe <shk> N zorkmids for it!" */
3486 #endif
3487         }
3488     } else {
3489         ESHK(shkp)->robbed += value;
3490
3491         if (!silent) {
3492             if (canseemon(shkp)) {
3493 #if 0 /*JP*/
3494                 Norep("%s booms: \"%s, you are a thief!\"",
3495                       Shknam(shkp), plname);
3496 #else
3497                 Norep("%s\82Í\8b©\82ñ\82¾\81F\81u%s\81C\91Ò\82Ä\81I\82±\82Ì\82Ç\82ë\82Ú\82¤\82ß\81I\81v",
3498                       Shknam(shkp), plname);
3499 #endif
3500             } else
3501 /*JP
3502                 Norep("You hear a scream, \"Thief!\"");
3503 */
3504                 Norep("\8bà\90Ø\82è\90º\82ð\95·\82¢\82½\81C\81u\91Ò\82Ä\81I\82±\82Ì\82Ç\82ë\82Ú\82¤\82ß\81I\81v");
3505         }
3506         hot_pursuit(shkp);
3507         (void) angry_guards(FALSE);
3508     }
3509     return value;
3510 }
3511
3512 /* auto-response flag for/from "sell foo?" 'a' => 'y', 'q' => 'n' */
3513 static char sell_response = 'a';
3514 static int sell_how = SELL_NORMAL;
3515 /* can't just use sell_response='y' for auto_credit because the 'a' response
3516    shouldn't carry over from ordinary selling to credit selling */
3517 static boolean auto_credit = FALSE;
3518
3519 void
3520 sellobj_state(deliberate)
3521 int deliberate;
3522 {
3523     /* If we're deliberately dropping something, there's no automatic
3524        response to the shopkeeper's "want to sell" query; however, if we
3525        accidentally drop anything, the shk will buy it/them without asking.
3526        This retains the old pre-query risk that slippery fingers while in
3527        shops entailed:  you drop it, you've lost it.
3528      */
3529     sell_response = (deliberate != SELL_NORMAL) ? '\0' : 'a';
3530     sell_how = deliberate;
3531     auto_credit = FALSE;
3532 }
3533
3534 void
3535 sellobj(obj, x, y)
3536 register struct obj *obj;
3537 xchar x, y;
3538 {
3539     register struct monst *shkp;
3540     register struct eshk *eshkp;
3541     long ltmp = 0L, cltmp = 0L, gltmp = 0L, offer, shkmoney;
3542     boolean saleitem, cgold = FALSE, container = Has_contents(obj);
3543     boolean isgold = (obj->oclass == COIN_CLASS);
3544     boolean only_partially_your_contents = FALSE;
3545
3546     if (!*u.ushops) /* do cheapest exclusion test first */
3547         return;
3548     if (!(shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) || !inhishop(shkp))
3549         return;
3550     if (!costly_spot(x, y))
3551         return;
3552
3553     if (obj->unpaid && !container && !isgold) {
3554         sub_one_frombill(obj, shkp);
3555         return;
3556     }
3557     if (container) {
3558         /* find the price of content before subfrombill */
3559         cltmp = contained_cost(obj, shkp, cltmp, TRUE, FALSE);
3560         /* find the value of contained gold */
3561         gltmp += contained_gold(obj);
3562         cgold = (gltmp > 0L);
3563     }
3564
3565     saleitem = saleable(shkp, obj);
3566     if (!isgold && !obj->unpaid && saleitem)
3567         ltmp = set_cost(obj, shkp);
3568
3569     offer = ltmp + cltmp;
3570
3571     /* get one case out of the way: nothing to sell, and no gold */
3572     if (!(isgold || cgold)
3573         && ((offer + gltmp) == 0L || sell_how == SELL_DONTSELL)) {
3574         boolean unpaid = is_unpaid(obj);
3575
3576         if (container) {
3577             dropped_container(obj, shkp, FALSE);
3578             if (!obj->unpaid)
3579                 obj->no_charge = 1;
3580             if (unpaid)
3581                 subfrombill(obj, shkp);
3582         } else
3583             obj->no_charge = 1;
3584
3585         if (!unpaid && (sell_how != SELL_DONTSELL)
3586             && !special_stock(obj, shkp, FALSE))
3587 /*JP
3588             pline("%s seems uninterested.", Shknam(shkp));
3589 */
3590             pline("%s\82Í\8b»\96¡\82ª\82È\82¢\82æ\82¤\82¾\81D", Shknam(shkp));
3591         return;
3592     }
3593
3594     /* you dropped something of your own - probably want to sell it */
3595     rouse_shk(shkp, TRUE); /* wake up sleeping or paralyzed shk */
3596     eshkp = ESHK(shkp);
3597
3598     if (ANGRY(shkp)) { /* they become shop-objects, no pay */
3599         if (!Deaf && !muteshk(shkp))
3600 /*JP
3601             verbalize("Thank you, scum!");
3602 */
3603             verbalize("\82 \82è\82ª\82Æ\82æ\81C\82±\82Ì\83N\83\\82Á\82½\82ê\81I");
3604         else
3605 /*JP
3606             pline("%s smirks with satisfaction.", Shknam(shkp));
3607 */
3608             pline("%s\82Í\96\9e\91«\82µ\82Ä\8dì\82è\8fÎ\82¢\82ð\95\82\82©\82×\82½\81D", Shknam(shkp));
3609         subfrombill(obj, shkp);
3610         return;
3611     }
3612
3613     if (eshkp->robbed) { /* shkp is not angry? */
3614         if (isgold)
3615             offer = obj->quan;
3616         else if (cgold)
3617             offer += cgold;
3618         if ((eshkp->robbed -= offer < 0L))
3619             eshkp->robbed = 0L;
3620         if (offer && !Deaf && !muteshk(shkp))
3621             verbalize(
3622 /*JP
3623   "Thank you for your contribution to restock this recently plundered shop.");
3624 */
3625   "\8añ\91¡\82ð\82Ç\82¤\82à\82 \82è\82ª\82Æ\82¤\81D\8dÅ\8bß\93\90\82Ý\82É\82 \82Á\82Ä\8eQ\82Á\82Ä\82½\82ñ\82¾\81D");
3626         subfrombill(obj, shkp);
3627         return;
3628     }
3629
3630     if (isgold || cgold) {
3631         if (!cgold)
3632             gltmp = obj->quan;
3633
3634         if (eshkp->debit >= gltmp) {
3635             if (eshkp->loan) { /* you carry shop's gold */
3636                 if (eshkp->loan >= gltmp)
3637                     eshkp->loan -= gltmp;
3638                 else
3639                     eshkp->loan = 0L;
3640             }
3641             eshkp->debit -= gltmp;
3642 /*JP
3643             Your("debt is %spaid off.", eshkp->debit ? "partially " : "");
3644 */
3645             Your("\8eØ\8bà\82Í%s\8ex\95¥\82í\82ê\82½\81D", eshkp->debit ? "\88ê\95\94" : "");
3646         } else {
3647             long delta = gltmp - eshkp->debit;
3648
3649             eshkp->credit += delta;
3650             if (eshkp->debit) {
3651                 eshkp->debit = 0L;
3652                 eshkp->loan = 0L;
3653 /*JP
3654                 Your("debt is paid off.");
3655 */
3656                 Your("\8eØ\8bà\82Í\8ex\95¥\82í\82ê\82½\81D");
3657             }
3658             if (eshkp->credit == delta)
3659 #if 0 /*JP*/
3660                 You("have established %ld %s credit.", delta,
3661                     currency(delta));
3662 #else
3663                 pline("%ld%s\82ð\97a\82¯\82½\81D", delta,
3664                       currency(delta));
3665 #endif
3666             else
3667 #if 0 /*JP*/
3668                 pline("%ld %s added to your credit; total is now %ld %s.",
3669                       delta, currency(delta), eshkp->credit,
3670                       currency(eshkp->credit));
3671 #else
3672                 pline("\97a\82¯\8bà\82É%ld%s\92Ç\89Á\82³\82ê\82½; \8d\87\8cv\82Í%ld%s\82É\82È\82Á\82½\81D.",
3673                       delta, currency(delta), eshkp->credit,
3674                       currency(eshkp->credit));
3675 #endif
3676         }
3677
3678         if (!offer || sell_how == SELL_DONTSELL) {
3679             if (!isgold) {
3680                 if (container)
3681                     dropped_container(obj, shkp, FALSE);
3682                 if (!obj->unpaid)
3683                     obj->no_charge = 1;
3684                 subfrombill(obj, shkp);
3685             }
3686             return;
3687         }
3688     }
3689
3690     if ((!saleitem && !(container && cltmp > 0L)) || eshkp->billct == BILLSZ
3691         || obj->oclass == BALL_CLASS || obj->oclass == CHAIN_CLASS
3692         || offer == 0L || (obj->oclass == FOOD_CLASS && obj->oeaten)
3693         || (Is_candle(obj)
3694             && obj->age < 20L * (long) objects[obj->otyp].oc_cost)) {
3695 #if 0 /*JP:T*/
3696         pline("%s seems uninterested%s.", Shknam(shkp),
3697               cgold ? " in the rest" : "");
3698 #else
3699         pline("%s\82Í%s\8b»\96¡\82ª\82È\82¢\82æ\82¤\82¾\81D", Shknam(shkp),
3700               cgold ? "\8ec\82è\95¨\82É\82Í" : "");
3701 #endif
3702         if (container)
3703             dropped_container(obj, shkp, FALSE);
3704         obj->no_charge = 1;
3705         return;
3706     }
3707
3708     shkmoney = money_cnt(shkp->minvent);
3709     if (!shkmoney) {
3710         char c, qbuf[BUFSZ];
3711 #if 1 /*JP*/
3712         char qsfx[BUFSZ];
3713 #endif
3714         long tmpcr = ((offer * 9L) / 10L) + (offer <= 1L);
3715
3716         if (sell_how == SELL_NORMAL || auto_credit) {
3717             c = sell_response = 'y';
3718         } else if (sell_response != 'n') {
3719 /*JP
3720             pline("%s cannot pay you at present.", Shknam(shkp));
3721 */
3722             pline("%s\82Í\8d¡\82Ì\82Æ\82±\82ë\82Í\8ex\95¥\82¦\82È\82¢\81D", Shknam(shkp));
3723 #if 0 /*JP*/
3724             Sprintf(qbuf, "Will you accept %ld %s in credit for ", tmpcr,
3725                     currency(tmpcr));
3726             c = ynaq(safe_qbuf(qbuf, qbuf, "?", obj, doname, thesimpleoname,
3727                                (obj->quan == 1L) ? "that" : "those"));
3728 #else
3729             Sprintf(qsfx, "\82É\82Â\82¢\82Ä%ld%s\82Ì\97a\82¯\8bà\82ð\8eó\82¯\82¢\82ê\82Ü\82·\82©\81H", tmpcr,
3730                     currency(tmpcr));
3731             c = ynaq(safe_qbuf(qbuf, "", qsfx, obj, doname, thesimpleoname,
3732                                "\82»\82ê"));
3733 #endif
3734             if (c == 'a') {
3735                 c = 'y';
3736                 auto_credit = TRUE;
3737             }
3738         } else /* previously specified "quit" */
3739             c = 'n';
3740
3741         if (c == 'y') {
3742 #if 0 /*JP*/
3743             shk_names_obj(
3744                 shkp, obj,
3745                 (sell_how != SELL_NORMAL)
3746                     ? "traded %s for %ld zorkmid%s in %scredit."
3747                     : "relinquish %s and acquire %ld zorkmid%s in %scredit.",
3748                 tmpcr, (eshkp->credit > 0L) ? "additional " : "");
3749 #else
3750             shk_names_obj(
3751                 shkp, obj,
3752                 (sell_how != SELL_NORMAL)
3753                     ? "%s\82ð\8bà\89Ý%ld\96\87\95ª\82Ì\97a\82¯\8bà\82Å\8eó\82¯\82Æ\82Á\82½%s\81D"
3754                     : "%s\82ð\93n\82µ\81C\8bà\89Ý%ld\96\87\95ª\82Ì\97a\82¯\8bà\82ð\93¾\82½%s\81D",
3755                 tmpcr, "");
3756 #endif
3757             eshkp->credit += tmpcr;
3758             subfrombill(obj, shkp);
3759         } else {
3760             if (c == 'q')
3761                 sell_response = 'n';
3762             if (container)
3763                 dropped_container(obj, shkp, FALSE);
3764             if (!obj->unpaid)
3765                 obj->no_charge = 1;
3766             subfrombill(obj, shkp);
3767         }
3768     } else {
3769         char qbuf[BUFSZ], qsfx[BUFSZ];
3770 #if 0 /*JP*/
3771         boolean short_funds = (offer > shkmoney), one;
3772 #else
3773         boolean short_funds = (offer > shkmoney);
3774 #endif
3775
3776         if (short_funds)
3777             offer = shkmoney;
3778         if (!sell_response) {
3779             long yourc = 0L, shksc;
3780
3781             if (container) {
3782                 /* number of items owned by shk */
3783                 shksc = count_contents(obj, TRUE, TRUE, FALSE);
3784                 /* number of items owned by you (total - shksc) */
3785                 yourc = count_contents(obj, TRUE, TRUE, TRUE) - shksc;
3786                 only_partially_your_contents = shksc && yourc;
3787             }
3788             /*
3789                "<shk> offers * for ..." query formatting.
3790                Normal item(s):
3791                 "... your <object>.  Sell it?"
3792                 "... your <objects>.  Sell them?"
3793                A container is either owned by the hero, or already
3794                owned by the shk (!ltmp), or the shk isn't interested
3795                in buying it (also !ltmp).  It's either empty (!cltmp)
3796                or it has contents owned by the hero or it has some
3797                contents owned by the hero and others by the shk.
3798                (The case where it has contents already entirely owned
3799                by the shk is treated the same was if it were empty
3800                since the hero isn't selling any of those contents.)
3801                Your container:
3802                 "... your <empty bag>.  Sell it?"
3803                 "... your <bag> and its contents.  Sell them?"
3804                 "... your <bag> and item inside.  Sell them?"
3805                 "... your <bag> and items inside.  Sell them?"
3806                Shk's container:
3807                 "... your item in the <bag>.  Sell it?"
3808                 "... your items in the <bag>.  Sell them?"
3809              */
3810 #if 0 /*JP*/
3811             Sprintf(qbuf, "%s offers%s %ld gold piece%s for %s%s ",
3812                     Shknam(shkp), short_funds ? " only" : "", offer,
3813                     plur(offer),
3814                     (cltmp && !ltmp)
3815                         ? ((yourc == 1L) ? "your item in " : "your items in ")
3816                         : "",
3817                     obj->unpaid ? "the" : "your");
3818             one = obj->unpaid ? (yourc == 1L) : (obj->quan == 1L && !cltmp);
3819             Sprintf(qsfx, "%s.  Sell %s?",
3820                     (cltmp && ltmp)
3821                         ? (only_partially_your_contents
3822                                ? ((yourc == 1L) ? " and item inside"
3823                                                 : " and items inside")
3824                                : and_its_contents)
3825                         : "",
3826                     one ? "it" : "them");
3827             (void) safe_qbuf(qbuf, qbuf, qsfx, obj, xname, simpleonames,
3828                              one ? "that" : "those");
3829 #else
3830             Sprintf(qbuf,
3831                     "%s\82Í\82 \82È\82½\82Ì", Monnam(shkp));
3832             Sprintf(qsfx,
3833                     "%s\82É%ld\82Ì\92l%s\81D\94\84\82è\82Ü\82·\82©\81H",
3834                     (!ltmp && cltmp) ? "\82Ì\92\86\90g" : "",
3835                     offer, 
3836                     short_funds ? "\82µ\82©\82Â\82¯\82È\82©\82Á\82½" : "\82ð\82Â\82¯\82½");
3837             (void) safe_qbuf(qbuf, qbuf, qsfx, obj, xname, simpleonames,
3838                              "\82»\82ê");
3839 #endif
3840         } else
3841             qbuf[0] = '\0'; /* just to pacify lint */
3842
3843         switch (sell_response ? sell_response : ynaq(qbuf)) {
3844         case 'q':
3845             sell_response = 'n';
3846             /*FALLTHRU*/
3847         case 'n':
3848             if (container)
3849                 dropped_container(obj, shkp, FALSE);
3850             if (!obj->unpaid)
3851                 obj->no_charge = 1;
3852             subfrombill(obj, shkp);
3853             break;
3854         case 'a':
3855             sell_response = 'y';
3856             /*FALLTHRU*/
3857         case 'y':
3858             if (container)
3859                 dropped_container(obj, shkp, TRUE);
3860             if (!obj->unpaid && !saleitem)
3861                 obj->no_charge = 1;
3862             subfrombill(obj, shkp);
3863             pay(-offer, shkp);
3864 #if 0 /*JP*/
3865             shk_names_obj(shkp, obj,
3866                           (sell_how != SELL_NORMAL)
3867                            ? ((!ltmp && cltmp && only_partially_your_contents)
3868                          ? "sold some items inside %s for %ld gold piece%s.%s"
3869                          : "sold %s for %ld gold piece%s.%s")
3870             : "relinquish %s and receive %ld gold piece%s in compensation.%s",
3871                           offer, "");
3872 #else
3873             shk_names_obj(shkp, obj,
3874                           (sell_how != SELL_NORMAL)
3875                            ? ((!ltmp && cltmp && only_partially_your_contents)
3876                          ? "%s\82Ì\92\86\90g\82ð\8bà\89Ý%ld\96\87\82Å\94\84\82Á\82½%s\81D%s"
3877                          : "%s\82ð\8bà\89Ý%ld\96\87\82Å\94\84\82Á\82½%s\81D%s")
3878             : "%s\82ð\93n\82µ\81C\8bà\89Ý%ld\96\87\82Ì\91ã\8f\9e\82ð\8eó\82¯\82Æ\82Á\82½%s\81D%s",
3879                           offer, "");
3880 #endif
3881             break;
3882         default:
3883             impossible("invalid sell response");
3884         }
3885     }
3886 }
3887
3888 int
3889 doinvbill(mode)
3890 int mode; /* 0: deliver count 1: paged */
3891 {
3892 #ifdef __SASC
3893     void sasc_bug(struct obj *, unsigned);
3894 #endif
3895     struct monst *shkp;
3896     struct eshk *eshkp;
3897     struct bill_x *bp, *end_bp;
3898     struct obj *obj;
3899     long totused;
3900     char *buf_p;
3901     winid datawin;
3902
3903     shkp = shop_keeper(*u.ushops);
3904     if (!shkp || !inhishop(shkp)) {
3905         if (mode != 0)
3906             impossible("doinvbill: no shopkeeper?");
3907         return 0;
3908     }
3909     eshkp = ESHK(shkp);
3910
3911     if (mode == 0) {
3912         /* count expended items, so that the `I' command can decide
3913            whether to include 'x' in its prompt string */
3914         int cnt = !eshkp->debit ? 0 : 1;
3915
3916         for (bp = eshkp->bill_p, end_bp = &eshkp->bill_p[eshkp->billct];
3917              bp < end_bp; bp++)
3918             if (bp->useup
3919                 || ((obj = bp_to_obj(bp)) != 0 && obj->quan < bp->bquan))
3920                 cnt++;
3921         return cnt;
3922     }
3923
3924     datawin = create_nhwindow(NHW_MENU);
3925 /*JP
3926     putstr(datawin, 0, "Unpaid articles already used up:");
3927 */
3928     putstr(datawin, 0, "\82·\82Å\82É\8eg\82Á\82Ä\82µ\82Ü\82Á\82½\96¢\95¥\82Ì\95i\96Ú\81F");
3929     putstr(datawin, 0, "");
3930
3931     totused = 0L;
3932     for (bp = eshkp->bill_p, end_bp = &eshkp->bill_p[eshkp->billct];
3933          bp < end_bp; bp++) {
3934         obj = bp_to_obj(bp);
3935         if (!obj) {
3936             impossible("Bad shopkeeper administration.");
3937             goto quit;
3938         }
3939         if (bp->useup || bp->bquan > obj->quan) {
3940             long oquan, uquan, thisused;
3941
3942             oquan = obj->quan;
3943             uquan = (bp->useup ? bp->bquan : bp->bquan - oquan);
3944             thisused = bp->price * uquan;
3945             totused += thisused;
3946             iflags.suppress_price++; /* suppress "(unpaid)" suffix */
3947             /* Why 'x'?  To match `I x', more or less. */
3948             buf_p = xprname(obj, (char *) 0, 'x', FALSE, thisused, uquan);
3949             iflags.suppress_price--;
3950             putstr(datawin, 0, buf_p);
3951         }
3952     }
3953     if (eshkp->debit) {
3954         /* additional shop debt which has no itemization available */
3955         if (totused)
3956             putstr(datawin, 0, "");
3957         totused += eshkp->debit;
3958 #if 0 /*JP*/
3959         buf_p = xprname((struct obj *) 0, "usage charges and/or other fees",
3960                         GOLD_SYM, FALSE, eshkp->debit, 0L);
3961 #else
3962         buf_p = xprname((struct obj *) 0, "\8eg\97p\97¿\82Ü\82½\82Í\91¼\82Ì\8eè\90\94\97¿",
3963                         GOLD_SYM, FALSE, eshkp->debit, 0L);
3964 #endif
3965         putstr(datawin, 0, buf_p);
3966     }
3967 /*JP
3968     buf_p = xprname((struct obj *) 0, "Total:", '*', FALSE, totused, 0L);
3969 */
3970     buf_p = xprname((struct obj *) 0, "\8d\87\8cv\81F", '*', FALSE, totused, 0L);
3971     putstr(datawin, 0, "");
3972     putstr(datawin, 0, buf_p);
3973     display_nhwindow(datawin, FALSE);
3974  quit:
3975     destroy_nhwindow(datawin);
3976     return 0;
3977 }
3978
3979 STATIC_OVL long
3980 getprice(obj, shk_buying)
3981 register struct obj *obj;
3982 boolean shk_buying;
3983 {
3984     register long tmp = (long) objects[obj->otyp].oc_cost;
3985
3986     if (obj->oartifact) {
3987         tmp = arti_cost(obj);
3988         if (shk_buying)
3989             tmp /= 4;
3990     }
3991     switch (obj->oclass) {
3992     case FOOD_CLASS:
3993         /* simpler hunger check, (2-4)*cost */
3994         if (u.uhs >= HUNGRY && !shk_buying)
3995             tmp *= (long) u.uhs;
3996         if (obj->oeaten)
3997             tmp = 0L;
3998         break;
3999     case WAND_CLASS:
4000         if (obj->spe == -1)
4001             tmp = 0L;
4002         break;
4003     case POTION_CLASS:
4004         if (obj->otyp == POT_WATER && !obj->blessed && !obj->cursed)
4005             tmp = 0L;
4006         break;
4007     case ARMOR_CLASS:
4008     case WEAPON_CLASS:
4009         if (obj->spe > 0)
4010             tmp += 10L * (long) obj->spe;
4011         break;
4012     case TOOL_CLASS:
4013         if (Is_candle(obj)
4014             && obj->age < 20L * (long) objects[obj->otyp].oc_cost)
4015             tmp /= 2L;
4016         break;
4017     }
4018     return tmp;
4019 }
4020
4021 /* shk catches thrown pick-axe */
4022 struct monst *
4023 shkcatch(obj, x, y)
4024 register struct obj *obj;
4025 register xchar x, y;
4026 {
4027     register struct monst *shkp;
4028
4029     if (!(shkp = shop_keeper(inside_shop(x, y))) || !inhishop(shkp))
4030         return 0;
4031
4032     if (shkp->mcanmove && !shkp->msleeping
4033         && (*u.ushops != ESHK(shkp)->shoproom || !inside_shop(u.ux, u.uy))
4034         && dist2(shkp->mx, shkp->my, x, y) < 3
4035         /* if it is the shk's pos, you hit and anger him */
4036         && (shkp->mx != x || shkp->my != y)) {
4037         if (mnearto(shkp, x, y, TRUE) == 2 && !Deaf && !muteshk(shkp))
4038 /*JP
4039             verbalize("Out of my way, scum!");
4040 */
4041                     verbalize("\82Ç\82¯\81C\83N\83\\82Á\82½\82ê\81I");
4042         if (cansee(x, y)) {
4043 #if 0 /*JP:T*/
4044             pline("%s nimbly%s catches %s.", Shknam(shkp),
4045                   (x == shkp->mx && y == shkp->my) ? "" : " reaches over and",
4046                   the(xname(obj)));
4047 #else
4048             pline("%s\82Í\82·\82Î\82â\82­%s%s\82ð\82Â\82©\82Ü\82¦\82½\81D", Shknam(shkp),
4049                   (x == shkp->mx && y == shkp->my) ? "" : "\8bß\82Ã\82¢\82Ä",
4050                   xname(obj));
4051 #endif
4052             if (!canspotmon(shkp))
4053                 map_invisible(x, y);
4054             delay_output();
4055             mark_synch();
4056         }
4057         subfrombill(obj, shkp);
4058         (void) mpickobj(shkp, obj);
4059         return shkp;
4060     }
4061     return (struct monst *) 0;
4062 }
4063
4064 void
4065 add_damage(x, y, cost)
4066 register xchar x, y;
4067 long cost;
4068 {
4069     struct damage *tmp_dam;
4070     char *shops;
4071
4072     if (IS_DOOR(levl[x][y].typ)) {
4073         struct monst *mtmp;
4074
4075         /* Don't schedule for repair unless it's a real shop entrance */
4076         for (shops = in_rooms(x, y, SHOPBASE); *shops; shops++)
4077             if ((mtmp = shop_keeper(*shops)) != 0
4078                 && x == ESHK(mtmp)->shd.x && y == ESHK(mtmp)->shd.y)
4079                 break;
4080         if (!*shops)
4081             return;
4082     }
4083     for (tmp_dam = level.damagelist; tmp_dam; tmp_dam = tmp_dam->next)
4084         if (tmp_dam->place.x == x && tmp_dam->place.y == y) {
4085             tmp_dam->cost += cost;
4086             tmp_dam->when = monstermoves; /* needed by pay_for_damage() */
4087             return;
4088         }
4089     tmp_dam = (struct damage *) alloc((unsigned) sizeof *tmp_dam);
4090     (void) memset((genericptr_t) tmp_dam, 0, sizeof *tmp_dam);
4091     tmp_dam->when = monstermoves;
4092     tmp_dam->place.x = x;
4093     tmp_dam->place.y = y;
4094     tmp_dam->cost = cost;
4095     tmp_dam->typ = levl[x][y].typ;
4096     tmp_dam->next = level.damagelist;
4097     level.damagelist = tmp_dam;
4098     /* If player saw damage, display as a wall forever */
4099     if (cansee(x, y))
4100         levl[x][y].seenv = SVALL;
4101 }
4102
4103 /*
4104  * Do something about damage. Either (!croaked) try to repair it, or
4105  * (croaked) just discard damage structs for non-shared locations, since
4106  * they'll never get repaired. Assume that shared locations will get
4107  * repaired eventually by the other shopkeeper(s). This might be an erroneous
4108  * assumption (they might all be dead too), but we have no reasonable way of
4109  * telling that.
4110  */
4111 STATIC_OVL
4112 void
4113 remove_damage(shkp, croaked)
4114 struct monst *shkp;
4115 boolean croaked;
4116 {
4117     struct damage *tmp_dam, *tmp2_dam;
4118     struct obj *shk_inv = shkp->minvent;
4119     boolean did_repair = FALSE, saw_door = FALSE, saw_floor = FALSE,
4120             stop_picking = FALSE, doorway_trap = FALSE, skip_msg = FALSE;
4121     int saw_walls = 0, saw_untrap = 0, feedback;
4122     char trapmsg[BUFSZ];
4123
4124     feedback = !croaked; /* 1 => give feedback, 0 => don't or already did */
4125     tmp_dam = level.damagelist;
4126     tmp2_dam = 0;
4127     while (tmp_dam) {
4128         register xchar x = tmp_dam->place.x, y = tmp_dam->place.y;
4129         char shops[5];
4130         int disposition;
4131         unsigned old_doormask = 0;
4132
4133         disposition = 0;
4134         Strcpy(shops, in_rooms(x, y, SHOPBASE));
4135         if (index(shops, ESHK(shkp)->shoproom)) {
4136             if (IS_DOOR(levl[x][y].typ))
4137                 old_doormask = levl[x][y].doormask;
4138
4139             if (croaked) {
4140                 disposition = (shops[1]) ? 0 : 1;
4141             } else if (stop_picking) {
4142                 disposition = repair_damage(shkp, tmp_dam, &feedback, FALSE);
4143             } else {
4144                 /* Defer the stop_occupation() until after repair msgs */
4145                 if (closed_door(x, y))
4146                     stop_picking = picking_at(x, y);
4147                 disposition = repair_damage(shkp, tmp_dam, &feedback, FALSE);
4148                 if (!disposition)
4149                     stop_picking = FALSE;
4150             }
4151         }
4152
4153         if (!disposition) {
4154             tmp2_dam = tmp_dam;
4155             tmp_dam = tmp_dam->next;
4156             continue;
4157         }
4158
4159         if (disposition > 1) {
4160             did_repair = TRUE;
4161             if (cansee(x, y)) {
4162                 if (IS_WALL(levl[x][y].typ)) {
4163                     saw_walls++;
4164                 } else if (IS_DOOR(levl[x][y].typ)
4165                            /* an existing door here implies trap removal */
4166                            && !(old_doormask & (D_ISOPEN | D_CLOSED))) {
4167                     saw_door = TRUE;
4168                 } else if (disposition == 3) { /* untrapped */
4169                     saw_untrap++;
4170                     if (IS_DOOR(levl[x][y].typ))
4171                         doorway_trap = TRUE;
4172                 } else {
4173                     saw_floor = TRUE;
4174                 }
4175             }
4176         }
4177
4178         tmp_dam = tmp_dam->next;
4179         if (!tmp2_dam) {
4180             free((genericptr_t) level.damagelist);
4181             level.damagelist = tmp_dam;
4182         } else {
4183             free((genericptr_t) tmp2_dam->next);
4184             tmp2_dam->next = tmp_dam;
4185         }
4186     }
4187     if (!did_repair)
4188         return;
4189
4190     trapmsg[0] = '\0'; /* not just lint suppression... */
4191     shk_inv = (shkp->minvent != shk_inv) ? shkp->minvent : 0;
4192     if (saw_untrap == 1 && shk_inv
4193         && (shk_inv->otyp == BEARTRAP || shk_inv->otyp == LAND_MINE)
4194         && canseemon(shkp)) {
4195         pline("%s untraps %s.", Shknam(shkp), ansimpleoname(shk_inv));
4196         /* we've already reported this trap (and know it's the only one) */
4197         saw_untrap = 0;
4198         skip_msg = !(saw_walls || saw_door || saw_floor);
4199     } else if (saw_untrap) {
4200 #if 0 /*JP*/
4201         Sprintf(trapmsg, "%s trap%s",
4202                 (saw_untrap > 3) ? "several" : (saw_untrap > 1) ? "some"
4203                                                                 : "a",
4204                 plur(saw_untrap));
4205         Sprintf(eos(trapmsg), " %s", vtense(trapmsg, "are"));
4206         Sprintf(eos(trapmsg), " removed from the %s",
4207                 (doorway_trap && saw_untrap == 1) ? "doorway" : "floor");
4208 #else
4209         Sprintf(trapmsg, "%sã©\82ª%s\82©\82ç\8fÁ\82¦",
4210                 (saw_untrap > 3) ? "\82 \82¿\82±\82¿\82Ì" : (saw_untrap > 1) ? "\89½\83J\8f\8a\82Ì"
4211                                                                    : "",
4212                 (doorway_trap && saw_untrap == 1) ? "\94à" : "\8f°");
4213 #endif
4214     }
4215
4216     if (skip_msg) {
4217         ; /* already gave an untrap message which covered the only repair */
4218     } else if (saw_walls) {
4219 #if 0 /*JP*/
4220         char wallbuf[BUFSZ];
4221
4222         Sprintf(wallbuf, "section%s", plur(saw_walls));
4223         pline("Suddenly, %s %s of wall %s up!",
4224               (saw_walls == 1) ? "a" : (saw_walls <= 3) ? "some" : "several",
4225               wallbuf, vtense(wallbuf, "close"));
4226 #else
4227         pline("\93Ë\91R\81C\95Ç\82ª%s\95Â\82Ü\82Á\82½\81I",
4228               (saw_walls == 1) ? "" : (saw_walls <= 3) ? "\89½\89Ó\8f\8a\82©" : "\82 \82¿\82±\82¿\82Å");
4229 #endif
4230
4231         if (saw_door)
4232 /*JP
4233             pline_The("shop door reappears!");
4234 */
4235             pline("\93X\82Ì\94à\82ª\82Ü\82½\8c»\82í\82ê\82½\81I");
4236         if (saw_floor)
4237 /*JP
4238             pline_The("floor is repaired!");
4239 */
4240             pline("\8f°\82Í\8fC\95\9c\82³\82ê\82½\81I");
4241         if (saw_untrap)
4242 /*JP
4243             pline("%s!", upstart(trapmsg));
4244 */
4245             pline("%s\82½\81I", trapmsg);
4246     } else {
4247         if (saw_door || saw_floor || saw_untrap)
4248 #if 0 /*JP:T*/
4249             pline("Suddenly, %s%s%s%s%s!",
4250                   saw_door ? "the shop door reappears" : "",
4251                   (saw_door && saw_floor) ? " and " : "",
4252                   saw_floor ? "the floor damage is gone" : "",
4253                   ((saw_door || saw_floor) && *trapmsg) ? " and " : "",
4254                   trapmsg);
4255 #else
4256             pline("\93Ë\91R\81C%s%s%s%s%s\82½!",
4257                   saw_door ? "\93X\82Ì\94à\82ª\82Ü\82½\8c»\82í\82ê" : "",
4258                   (saw_door && saw_floor) ? "\81C" : "",
4259                   saw_floor ? "\8f°\82Ì\8f\9d\82ª\8fC\95\9c\82³\82ê" : "",
4260                   ((saw_door || saw_floor) && *trapmsg) ? "\81C" : "",
4261                   trapmsg);
4262 #endif
4263         /* FIXME:
4264          *  these messages aren't right if the unseen repairs were only
4265          *  for trap removal (except for hole and possibly trap door).
4266          */
4267         else if (inside_shop(u.ux, u.uy) == ESHK(shkp)->shoproom)
4268 /*JP
4269             You_feel("more claustrophobic than before.");
4270 */
4271             You("\91O\82æ\82è\95Â\8f\8a\8b°\95|\8fÇ\8bC\96¡\82É\82È\82Á\82½\81D");
4272         else if (!Deaf && !rn2(10))
4273 /*JP
4274             Norep("The dungeon acoustics noticeably change.");
4275 */
4276             Norep("\96À\8b{\82Ì\89¹\8b¿\82Í\82¢\82¿\82\82é\82µ\82­\95Ï\82Á\82½\81D");
4277     }
4278     if (stop_picking)
4279         stop_occupation();
4280 }
4281
4282 /*
4283  * 0: repair postponed, 1: silent repair (no messages), 2: normal repair
4284  * 3: untrap
4285  */
4286 int
4287 repair_damage(shkp, tmp_dam, once, catchup)
4288 struct monst *shkp;
4289 struct damage *tmp_dam;
4290 int *once;
4291 boolean catchup; /* restoring a level */
4292 {
4293     xchar x, y;
4294     xchar litter[9];
4295     struct monst *mtmp;
4296     struct obj *otmp;
4297     struct trap *ttmp;
4298     int i, k, ix, iy, disposition = 1;
4299
4300     if ((monstermoves - tmp_dam->when) < REPAIR_DELAY)
4301         return 0;
4302     if (shkp->msleeping || !shkp->mcanmove || ESHK(shkp)->following)
4303         return 0;
4304     x = tmp_dam->place.x;
4305     y = tmp_dam->place.y;
4306     if (!IS_ROOM(tmp_dam->typ)) {
4307         if ((x == u.ux && y == u.uy && !Passes_walls)
4308             || (x == shkp->mx && y == shkp->my)
4309             || ((mtmp = m_at(x, y)) != 0 && !passes_walls(mtmp->data)))
4310             return 0;
4311     }
4312     ttmp = t_at(x, y);
4313     if (ttmp && x == u.ux && y == u.uy && !Passes_walls)
4314         return 0;
4315
4316     if (once && *once) {
4317         boolean shk_closeby = (distu(shkp->mx, shkp->my)
4318                                <= (BOLT_LIM / 2) * (BOLT_LIM / 2));
4319
4320         /* this is suboptimal if we eventually give a "shk untraps"
4321            message for the only repair, but perhaps the shop repair
4322            incantation means that shk's untrap attempt will never fail */
4323         if (canseemon(shkp))
4324             pline("%s whispers %s.", Shknam(shkp),
4325                   shk_closeby ? "an incantation" : "something");
4326         else if (!Deaf && shk_closeby)
4327             You_hear("someone muttering an incantation.");
4328         *once = 0;
4329     }
4330     if (ttmp) {
4331         if ((ttmp->ttyp == LANDMINE || ttmp->ttyp == BEAR_TRAP)
4332             && dist2(x, y, shkp->mx, shkp->my) <= 2) {
4333             /* convert to an object */
4334             otmp = mksobj((ttmp->ttyp == LANDMINE) ? LAND_MINE : BEARTRAP,
4335                           TRUE, FALSE);
4336             otmp->quan = 1L;
4337             otmp->owt = weight(otmp);
4338             (void) mpickobj(shkp, otmp);
4339         }
4340         deltrap(ttmp);
4341         if (cansee(x, y))
4342             newsym(x, y);
4343         if (!catchup)
4344             disposition = 3;
4345     }
4346     if (IS_ROOM(tmp_dam->typ)
4347         || (tmp_dam->typ == levl[x][y].typ
4348             && (!IS_DOOR(tmp_dam->typ) || levl[x][y].doormask > D_BROKEN)))
4349         /* no terrain fix necessary (trap removal or manually repaired) */
4350         return disposition;
4351
4352     /* door or wall repair; trap, if any, is now gone;
4353        restore original terrain type and move any items away */
4354     levl[x][y].typ = tmp_dam->typ;
4355     if (IS_DOOR(tmp_dam->typ))
4356         levl[x][y].doormask = D_CLOSED; /* arbitrary */
4357
4358     (void) memset((genericptr_t) litter, 0, sizeof litter);
4359 #define NEED_UPDATE 1
4360 #define OPEN 2
4361 #define INSHOP 4
4362 #define horiz(i) ((i % 3) - 1)
4363 #define vert(i) ((i / 3) - 1)
4364     k = 0; /* number of adjacent shop spots */
4365     if (level.objects[x][y] && !IS_ROOM(levl[x][y].typ)) {
4366         for (i = 0; i < 9; i++) {
4367             ix = x + horiz(i);
4368             iy = y + vert(i);
4369             if (i == 4 || !isok(ix, iy) || !ZAP_POS(levl[ix][iy].typ))
4370                 continue;
4371             litter[i] = OPEN;
4372             if (inside_shop(ix, iy) == ESHK(shkp)->shoproom) {
4373                 litter[i] |= INSHOP;
4374                 ++k;
4375             }
4376         }
4377     }
4378     /* placement below assumes there is always at least one adjacent
4379        spot; the 'k' check guards against getting stuck in an infinite
4380        loop if some irregularly shaped room breaks that assumption */
4381     if (k > 0) {
4382         /* Scatter objects haphazardly into the shop */
4383         if (Punished && !u.uswallow
4384             && ((uchain->ox == x && uchain->oy == y)
4385                 || (uball->ox == x && uball->oy == y))) {
4386             /*
4387              * Either the ball or chain is in the repair location.
4388              * Take the easy way out and put ball&chain under hero.
4389              *
4390              * FIXME: message should be reworded; this might be the
4391              * shop's doorway rather than a wall, there might be some
4392              * other stuff here which isn't junk, and "your junk" has
4393              * a slang connotation which could be applicable if hero
4394              * has Passes_walls ability.
4395              */
4396             if (!Deaf && !muteshk(shkp))
4397 /*JP
4398                 verbalize("Get your junk out of my wall!");
4399 */
4400                 verbalize("\82»\82Ì\83K\83\89\83N\83^\82ð\8aO\82É\8e\9d\82Á\82Ä\8ds\82«\82È\81I");
4401             unplacebc(); /* pick 'em up */
4402             placebc();   /* put 'em down */
4403         }
4404         while ((otmp = level.objects[x][y]) != 0)
4405             /* Don't mess w/ boulders -- just merge into wall */
4406             if (otmp->otyp == BOULDER || otmp->otyp == ROCK) {
4407                 obj_extract_self(otmp);
4408                 obfree(otmp, (struct obj *) 0);
4409             } else {
4410                 int trylimit = 50;
4411
4412                 /* otmp must be moved otherwise level.objects[x][y] will
4413                    never become Null and while-loop won't terminate */
4414                 do {
4415                     i = rn2(9);
4416                 } while (--trylimit && !(litter[i] & INSHOP));
4417                 if ((litter[i] & (OPEN | INSHOP)) != 0) {
4418                     ix = x + horiz(i);
4419                     iy = y + vert(i);
4420                 } else {
4421                     /* we know shk isn't at <x,y> because repair
4422                        is deferred in that situation */
4423                     ix = shkp->mx;
4424                     iy = shkp->my;
4425                 }
4426                 remove_object(otmp);
4427                 place_object(otmp, ix, iy);
4428                 litter[i] |= NEED_UPDATE;
4429             }
4430     }
4431     if (catchup)
4432         return 1; /* repair occurred while off level so no messages */
4433
4434     block_point(x, y);
4435     if (cansee(x, y)) {
4436         if (IS_WALL(tmp_dam->typ))
4437             /* player sees actual repair process, so KNOWS it's a wall */
4438             levl[x][y].seenv = SVALL;
4439         newsym(x, y);
4440     }
4441     for (i = 0; i < 9; i++)
4442         if (litter[i] & NEED_UPDATE)
4443             newsym(x + horiz(i), y + vert(i));
4444
4445     if (disposition < 3)
4446         disposition = 2;
4447     return disposition;
4448 #undef NEED_UPDATE
4449 #undef OPEN
4450 #undef INSHOP
4451 #undef vert
4452 #undef horiz
4453 }
4454
4455 /*
4456  * shk_move: return 1: moved  0: didn't  -1: let m_move do it  -2: died
4457  */
4458 int
4459 shk_move(shkp)
4460 struct monst *shkp;
4461 {
4462     xchar gx, gy, omx, omy;
4463     int udist;
4464     schar appr;
4465     struct eshk *eshkp = ESHK(shkp);
4466     int z;
4467     boolean uondoor = FALSE, satdoor, avoid = FALSE, badinv;
4468
4469     omx = shkp->mx;
4470     omy = shkp->my;
4471
4472     if (inhishop(shkp))
4473         remove_damage(shkp, FALSE);
4474
4475     if ((udist = distu(omx, omy)) < 3 && (shkp->data != &mons[PM_GRID_BUG]
4476                                           || (omx == u.ux || omy == u.uy))) {
4477         if (ANGRY(shkp) || (Conflict && !resist(shkp, RING_CLASS, 0, 0))) {
4478             if (Displaced)
4479 /*JP
4480                 Your("displaced image doesn't fool %s!", shkname(shkp));
4481 */
4482                 pline("%s\82Í\82 \82È\82½\82Ì\8c\89e\82É\82¾\82Ü\82³\82ê\82È\82©\82Á\82½\81I", shkname(shkp));
4483             (void) mattacku(shkp);
4484             return 0;
4485         }
4486         if (eshkp->following) {
4487             if (strncmp(eshkp->customer, plname, PL_NSIZ)) {
4488                 if (!Deaf && !muteshk(shkp))
4489 #if 0 /*JP:T*/
4490                     verbalize("%s, %s!  I was looking for %s.", Hello(shkp),
4491                               plname, eshkp->customer);
4492 #else
4493                     verbalize("%s\81I\82í\82½\82µ\82Í%s\82ð\92T\82µ\82Ä\82¢\82Ü\82·\81D", Hello(shkp),
4494                               eshkp->customer);
4495 #endif
4496                 eshkp->following = 0;
4497                 return 0;
4498             }
4499             if (moves > followmsg + 4) {
4500                 if (!Deaf && !muteshk(shkp))
4501 #if 0 /*JP:T*/
4502                     verbalize("%s, %s!  Didn't you forget to pay?",
4503                               Hello(shkp), plname);
4504 #else
4505                     verbalize("%s\81I\8ex\95¥\82¢\82ð\96Y\82ê\82Ä\82¢\82Ü\82¹\82ñ\82©\81H",
4506                               Hello(shkp));
4507 #endif
4508                 else
4509 #if 0 /*JP:T*/
4510                     pline("%s holds out %s upturned %s.",
4511                           Shknam(shkp), noit_mhis(shkp),
4512                           mbodypart(shkp, HAND));
4513 #else
4514                     pline("%s\82Í%s\82ð\8fã\82É\8cü\82¯\82Ä\8d·\82µ\8fo\82µ\82½\81D",
4515                           Shknam(shkp),
4516                           mbodypart(shkp, HAND));
4517 #endif
4518                 followmsg = moves;
4519                 if (!rn2(9)) {
4520 #if 0 /*JP:T*/
4521                     pline("%s doesn't like customers who don't pay.",
4522                           Shknam(shkp));
4523 #else
4524                     pline("%s\82Í\8bà\82ð\95¥\82í\82È\82¢\8bq\82ª\8c\99\82¢\82Ý\82½\82¢\82¾\81D",
4525                           Shknam(shkp));
4526 #endif
4527                     rile_shk(shkp);
4528                 }
4529             }
4530             if (udist < 2)
4531                 return 0;
4532         }
4533     }
4534
4535     appr = 1;
4536     gx = eshkp->shk.x;
4537     gy = eshkp->shk.y;
4538     satdoor = (gx == omx && gy == omy);
4539     if (eshkp->following || ((z = holetime()) >= 0 && z * z <= udist)) {
4540         /* [This distance check used to apply regardless of
4541             whether the shk was following, but that resulted in
4542             m_move() sometimes taking the shk out of the shop if
4543             the player had fenced him in with boulders or traps.
4544             Such voluntary abandonment left unpaid objects in
4545             invent, triggering billing impossibilities on the
4546             next level once the character fell through the hole.] */
4547         if (udist > 4 && eshkp->following && !eshkp->billct)
4548             return -1; /* leave it to m_move */
4549         gx = u.ux;
4550         gy = u.uy;
4551     } else if (ANGRY(shkp)) {
4552         /* Move towards the hero if the shopkeeper can see him. */
4553         if (shkp->mcansee && m_canseeu(shkp)) {
4554             gx = u.ux;
4555             gy = u.uy;
4556         }
4557         avoid = FALSE;
4558     } else {
4559 #define GDIST(x, y) (dist2(x, y, gx, gy))
4560         if (Invis || u.usteed) {
4561             avoid = FALSE;
4562         } else {
4563             uondoor = (u.ux == eshkp->shd.x && u.uy == eshkp->shd.y);
4564             if (uondoor) {
4565                 badinv =
4566                     (carrying(PICK_AXE) || carrying(DWARVISH_MATTOCK)
4567                      || (Fast && (sobj_at(PICK_AXE, u.ux, u.uy)
4568                                   || sobj_at(DWARVISH_MATTOCK, u.ux, u.uy))));
4569                 if (satdoor && badinv)
4570                     return 0;
4571                 avoid = !badinv;
4572             } else {
4573                 avoid = (*u.ushops && distu(gx, gy) > 8);
4574                 badinv = FALSE;
4575             }
4576
4577             if (((!eshkp->robbed && !eshkp->billct && !eshkp->debit) || avoid)
4578                 && GDIST(omx, omy) < 3) {
4579                 if (!badinv && !onlineu(omx, omy))
4580                     return 0;
4581                 if (satdoor)
4582                     appr = gx = gy = 0;
4583             }
4584         }
4585     }
4586
4587     z = move_special(shkp, inhishop(shkp), appr, uondoor, avoid, omx, omy, gx,
4588                      gy);
4589     if (z > 0)
4590         after_shk_move(shkp);
4591
4592     return z;
4593 }
4594
4595 /* called after shopkeeper moves, in case themove causes re-entry into shop */
4596 void
4597 after_shk_move(shkp)
4598 struct monst *shkp;
4599 {
4600     struct eshk *eshkp = ESHK(shkp);
4601
4602     if (eshkp->bill_p == (struct bill_x *) -1000 && inhishop(shkp)) {
4603         /* reset bill_p, need to re-calc player's occupancy too */
4604         eshkp->bill_p = &eshkp->bill[0];
4605         check_special_room(FALSE);
4606     }
4607 }
4608
4609 /* for use in levl_follower (mondata.c) */
4610 boolean
4611 is_fshk(mtmp)
4612 register struct monst *mtmp;
4613 {
4614     return (boolean) (mtmp->isshk && ESHK(mtmp)->following);
4615 }
4616
4617 /* You are digging in the shop. */
4618 void
4619 shopdig(fall)
4620 register int fall;
4621 {
4622     register struct monst *shkp = shop_keeper(*u.ushops);
4623     int lang;
4624 /*JP
4625     const char *grabs = "grabs";
4626 */
4627     const char *grabs = "\82Â\82©\82ñ\82¾";
4628
4629     if (!shkp)
4630         return;
4631
4632     /* 0 == can't speak, 1 == makes animal noises, 2 == speaks */
4633     lang = 0;
4634     if (shkp->msleeping || !shkp->mcanmove || is_silent(shkp->data))
4635         ; /* lang stays 0 */
4636     else if (shkp->data->msound <= MS_ANIMAL)
4637         lang = 1;
4638     else if (shkp->data->msound >= MS_HUMANOID)
4639         lang = 2;
4640
4641     if (!inhishop(shkp)) {
4642         if (Role_if(PM_KNIGHT)) {
4643 /*JP
4644             You_feel("like a common thief.");
4645 */
4646             You("\93D\96_\93¯\91R\82È\8bC\82ª\82µ\82½\81D");
4647             adjalign(-sgn(u.ualign.type));
4648         }
4649         return;
4650     }
4651
4652     if (!fall) {
4653         if (lang == 2) {
4654             if (!Deaf && !muteshk(shkp)) {
4655                 if (u.utraptype == TT_PIT)
4656 #if 0 /*JP*/
4657                     verbalize(
4658                         "Be careful, %s, or you might fall through the floor.",
4659                         flags.female ? "madam" : "sir");
4660 #else
4661                     verbalize(
4662                         "\92\8d\88Ó\82µ\82Ä\82­\82¾\82³\82¢%s\81C\8f°\82©\82ç\97\8e\82¿\82Ü\82·\82æ\81D",
4663                         flags.female ? "\82¨\8fì\82³\82ñ" : "\82¨\8bq\82³\82ñ");
4664 #endif
4665                 else
4666 #if 0 /*JP*/
4667                     verbalize("%s, do not damage the floor here!",
4668                         flags.female ? "Madam" : "Sir");
4669 #else
4670                     verbalize("%s\81C\8f°\82É\8f\9d\82ð\82Â\82¯\82È\82¢\82Å\82­\82¾\82³\82¢\81I",
4671                         flags.female ? "\82¨\8fì\82³\82ñ" : "\82¨\8bq\82³\82ñ");
4672 #endif
4673             }
4674         }
4675         if (Role_if(PM_KNIGHT)) {
4676 /*JP
4677             You_feel("like a common thief.");
4678 */
4679             You("\93D\96_\93¯\91R\82È\8bC\82ª\82µ\82½\81D");
4680             adjalign(-sgn(u.ualign.type));
4681         }
4682     } else if (!um_dist(shkp->mx, shkp->my, 5)
4683                && !shkp->msleeping && shkp->mcanmove
4684                && (ESHK(shkp)->billct || ESHK(shkp)->debit)) {
4685         register struct obj *obj, *obj2;
4686
4687         if (nolimbs(shkp->data)) {
4688 /*JP
4689             grabs = "knocks off";
4690 */
4691             grabs = "\92@\82«\97\8e\82µ\82½";
4692 #if 0
4693             /* This is what should happen, but for balance
4694              * reasons, it isn't currently.
4695              */
4696             if (lang == 2)
4697                 pline("%s curses %s inability to grab your backpack!",
4698                       Shknam(shkp), noit_mhim(shkp));
4699             rile_shk(shkp);
4700             return;
4701 #endif
4702         }
4703         if (distu(shkp->mx, shkp->my) > 2) {
4704             mnexto(shkp);
4705             /* for some reason the shopkeeper can't come next to you */
4706             if (distu(shkp->mx, shkp->my) > 2) {
4707                 if (lang == 2)
4708
4709 /*JP
4710                     pline("%s curses you in anger and frustration!",
4711 */
4712                     pline("\93{\82è\82Å\95s\96\9e\82Ì\82½\82Ü\82Á\82Ä\82¢\82é%s\82Í\82 \82È\82½\82ð\8eô\82Á\82½\81I",
4713                           Shknam(shkp));
4714                 else if (lang == 1)
4715                     growl(shkp);
4716                 rile_shk(shkp);
4717                 return;
4718             } else
4719 #if 0 /*JP:T*/
4720                 pline("%s %s, and %s your backpack!", Shknam(shkp),
4721                       makeplural(locomotion(shkp->data, "leap")), grabs);
4722 #else
4723                 pline("%s\82Í\94ò\82Ñ\82Â\82¢\82Ä\81C\82 \82È\82½\82Ì\94w\95\89\82¢\91Ü\82ð%s\81I", Shknam(shkp),
4724                       grabs);
4725 #endif
4726         } else
4727 /*JP
4728             pline("%s %s your backpack!", Shknam(shkp), grabs);
4729 */
4730             pline("%s\82Í\82 \82È\82½\82Ì\94w\95\89\82¢\91Ü\82ð%s\81I", Shknam(shkp), grabs);
4731
4732         for (obj = invent; obj; obj = obj2) {
4733             obj2 = obj->nobj;
4734             if ((obj->owornmask & ~(W_SWAPWEP | W_QUIVER)) != 0
4735                 || (obj == uswapwep && u.twoweap)
4736                 || (obj->otyp == LEASH && obj->leashmon))
4737                 continue;
4738             if (obj == current_wand)
4739                 continue;
4740             setnotworn(obj);
4741             freeinv(obj);
4742             subfrombill(obj, shkp);
4743             (void) add_to_minv(shkp, obj); /* may free obj */
4744         }
4745     }
4746 }
4747
4748 STATIC_OVL void
4749 makekops(mm)
4750 coord *mm;
4751 {
4752     static const short k_mndx[4] = { PM_KEYSTONE_KOP, PM_KOP_SERGEANT,
4753                                      PM_KOP_LIEUTENANT, PM_KOP_KAPTAIN };
4754     int k_cnt[4], cnt, mndx, k;
4755
4756     k_cnt[0] = cnt = abs(depth(&u.uz)) + rnd(5);
4757     k_cnt[1] = (cnt / 3) + 1; /* at least one sarge */
4758     k_cnt[2] = (cnt / 6);     /* maybe a lieutenant */
4759     k_cnt[3] = (cnt / 9);     /* and maybe a kaptain */
4760
4761     for (k = 0; k < 4; k++) {
4762         if ((cnt = k_cnt[k]) == 0)
4763             break;
4764         mndx = k_mndx[k];
4765         if (mvitals[mndx].mvflags & G_GONE)
4766             continue;
4767
4768         while (cnt--)
4769             if (enexto(mm, mm->x, mm->y, &mons[mndx]))
4770                 (void) makemon(&mons[mndx], mm->x, mm->y, NO_MM_FLAGS);
4771     }
4772 }
4773
4774 void
4775 pay_for_damage(dmgstr, cant_mollify)
4776 const char *dmgstr;
4777 boolean cant_mollify;
4778 {
4779     register struct monst *shkp = (struct monst *) 0;
4780     char shops_affected[5];
4781     boolean uinshp = (*u.ushops != '\0');
4782     char qbuf[80];
4783     xchar x, y;
4784 #if 0 /*JP*/
4785     boolean dugwall = (!strcmp(dmgstr, "dig into")    /* wand */
4786                        || !strcmp(dmgstr, "damage")); /* pick-axe */
4787 #else
4788     boolean ni_wo = !strcmp(dmgstr, "\8c\8a\82ð\82 \82¯\82é");              /* wand */
4789     boolean dugwall = (ni_wo || !strcmp(dmgstr, "\8f\9d\82Â\82¯\82é")); /* pick-axe */
4790 #endif
4791     boolean animal, pursue;
4792     struct damage *tmp_dam, *appear_here = 0;
4793     long cost_of_damage = 0L;
4794     unsigned int nearest_shk = (ROWNO * ROWNO) + (COLNO * COLNO),
4795                  nearest_damage = nearest_shk;
4796     int picks = 0;
4797
4798     for (tmp_dam = level.damagelist; tmp_dam; tmp_dam = tmp_dam->next) {
4799         char *shp;
4800
4801         if (tmp_dam->when != monstermoves || !tmp_dam->cost)
4802             continue;
4803         cost_of_damage += tmp_dam->cost;
4804         Strcpy(shops_affected,
4805                in_rooms(tmp_dam->place.x, tmp_dam->place.y, SHOPBASE));
4806         for (shp = shops_affected; *shp; shp++) {
4807             struct monst *tmp_shk;
4808             unsigned int shk_distance;
4809
4810             if (!(tmp_shk = shop_keeper(*shp)))
4811                 continue;
4812             if (tmp_shk == shkp) {
4813                 unsigned int damage_distance =
4814                     distu(tmp_dam->place.x, tmp_dam->place.y);
4815
4816                 if (damage_distance < nearest_damage) {
4817                     nearest_damage = damage_distance;
4818                     appear_here = tmp_dam;
4819                 }
4820                 continue;
4821             }
4822             if (!inhishop(tmp_shk))
4823                 continue;
4824             shk_distance = distu(tmp_shk->mx, tmp_shk->my);
4825             if (shk_distance > nearest_shk)
4826                 continue;
4827             if ((shk_distance == nearest_shk) && picks) {
4828                 if (rn2(++picks))
4829                     continue;
4830             } else
4831                 picks = 1;
4832             shkp = tmp_shk;
4833             nearest_shk = shk_distance;
4834             appear_here = tmp_dam;
4835             nearest_damage = distu(tmp_dam->place.x, tmp_dam->place.y);
4836         }
4837     }
4838
4839     if (!cost_of_damage || !shkp)
4840         return;
4841
4842     animal = (shkp->data->msound <= MS_ANIMAL);
4843     pursue = FALSE;
4844     x = appear_here->place.x;
4845     y = appear_here->place.y;
4846
4847     /* not the best introduction to the shk... */
4848     (void) strncpy(ESHK(shkp)->customer, plname, PL_NSIZ);
4849
4850     /* if the shk is already on the war path, be sure it's all out */
4851     if (ANGRY(shkp) || ESHK(shkp)->following) {
4852         hot_pursuit(shkp);
4853         return;
4854     }
4855
4856     /* if the shk is not in their shop.. */
4857     if (!*in_rooms(shkp->mx, shkp->my, SHOPBASE)) {
4858         if (!cansee(shkp->mx, shkp->my))
4859             return;
4860         pursue = TRUE;
4861         goto getcad;
4862     }
4863
4864     if (uinshp) {
4865         if (um_dist(shkp->mx, shkp->my, 1)
4866             && !um_dist(shkp->mx, shkp->my, 3)) {
4867 /*JP
4868             pline("%s leaps towards you!", Shknam(shkp));
4869 */
4870             pline("%s\82Í\82 \82È\82½\82É\94ò\82Ñ\82©\82©\82Á\82½\81I", Shknam(shkp));
4871             mnexto(shkp);
4872         }
4873         pursue = um_dist(shkp->mx, shkp->my, 1);
4874         if (pursue)
4875             goto getcad;
4876     } else {
4877         /*
4878          * Make shkp show up at the door.  Effect:  If there is a monster
4879          * in the doorway, have the hero hear the shopkeeper yell a bit,
4880          * pause, then have the shopkeeper appear at the door, having
4881          * yanked the hapless critter out of the way.
4882          */
4883         if (MON_AT(x, y)) {
4884             if (!animal) {
4885                 if (!Deaf && !muteshk(shkp)) {
4886 /*JP
4887                 You_hear("an angry voice:");
4888 */
4889                 You("\93{\82è\82Ì\90º\82ð\95·\82¢\82½\81F");
4890 /*JP
4891                 verbalize("Out of my way, scum!");
4892 */
4893                 verbalize("\82Ç\82¯\81I\83N\83\\82Á\82½\82ê\81I");
4894                 }
4895                 wait_synch();
4896 #if defined(UNIX) || defined(VMS)
4897 #if defined(SYSV) || defined(ULTRIX) || defined(VMS)
4898                 (void)
4899 #endif
4900                     sleep(1);
4901 #endif
4902             } else {
4903                 growl(shkp);
4904             }
4905         }
4906         (void) mnearto(shkp, x, y, TRUE);
4907     }
4908
4909     if ((um_dist(x, y, 1) && !uinshp) || cant_mollify
4910         || (money_cnt(invent) + ESHK(shkp)->credit) < cost_of_damage
4911         || !rn2(50)) {
4912  getcad:
4913         if (muteshk(shkp)) {
4914             if (animal && shkp->mcanmove && !shkp->msleeping)
4915                 yelp(shkp);
4916         } else if (pursue || uinshp || !um_dist(x, y, 1)) {
4917             if (!Deaf)
4918 #if 0 /*JP*/
4919                 verbalize("How dare you %s my %s?", dmgstr,
4920                           dugwall ? "shop" : "door");
4921 #else
4922                 verbalize("\82Ç\82¤\82µ\82Ä%s%s%s\82è\82µ\82½\82ñ\82¾\81H",
4923                           dugwall ? "\93X" : "\94à",
4924                           ni_wo ? "\82É" : "\82ð",
4925                           jpast(dmgstr));
4926 #endif
4927             else
4928 #if 0 /*JP:T*/
4929                 pline("%s is %s that you decided to %s %s %s!",
4930                       Shknam(shkp), angrytexts[rn2(SIZE(angrytexts))],
4931                       dmgstr, noit_mhis(shkp), dugwall ? "shop" : "door");
4932 #else
4933                 pline("%s\82Í\82 \82È\82½\82ª%s\82ð%s\82±\82Æ\82É\91Î\82µ\82Ä%s\81I",
4934                       Shknam(shkp),
4935                       dugwall ? "\93X" : "\94à", dmgstr,
4936                       angrytexts[rn2(SIZE(angrytexts))]);
4937 #endif
4938         } else {
4939             if (!Deaf) {
4940 /*JP
4941                 pline("%s shouts:", Shknam(shkp));
4942 */
4943                 pline("%s\82Í\82³\82¯\82ñ\82¾\81F", Shknam(shkp));
4944 #if 0 /*JP*/
4945                 verbalize("Who dared %s my %s?", dmgstr,
4946                           dugwall ? "shop" : "door");
4947 #else
4948                 verbalize("\92N\82ª%s%s%s\82è\82µ\82½\82ñ\82¾\82ë\82¤\81H",
4949                           dugwall ? "\93X" : "\94à",
4950                           ni_wo ? "\82É" : "\82ð",
4951                           jpast(dmgstr));
4952 #endif
4953             } else {
4954 #if 0 /*JP:T*/
4955                 pline("%s is %s that someone decided to %s %s %s!",
4956                       Shknam(shkp), angrytexts[rn2(SIZE(angrytexts))],
4957                       dmgstr, noit_mhis(shkp), dugwall ? "shop" : "door");
4958 #else
4959                 pline("%s\82Í\92N\82©\82ª%s\82ð%s\82±\82Æ\82É\91Î\82µ\82Ä%s\81I",
4960                       Shknam(shkp),
4961                       dugwall ? "\93X" : "\94à", dmgstr,
4962                       angrytexts[rn2(SIZE(angrytexts))]);
4963 #endif
4964             }
4965         }
4966         hot_pursuit(shkp);
4967         return;
4968     }
4969
4970     if (Invis)
4971 /*JP
4972         Your("invisibility does not fool %s!", shkname(shkp));
4973 */
4974         pline("%s\82Í\93§\96¾\82È\82 \82È\82½\82É\82¾\82Ü\82³\82ê\82È\82©\82Á\82½\81I", shkname(shkp));
4975 #if 0 /*JP*/
4976     Sprintf(qbuf, "%sYou did %ld %s worth of damage!%s  Pay?",
4977             !animal ? cad(TRUE) : "", cost_of_damage,
4978             currency(cost_of_damage), !animal ? "\"" : "");
4979 #else
4980     Sprintf(qbuf,"\81u\82¨\82¢\81I%ld%s\82Ì\91¹\8aQ\82¾\81I\81v\95¥\82¢\82Ü\82·\82©\81H",
4981             cost_of_damage, currency(cost_of_damage));
4982 #endif
4983     if (yn(qbuf) != 'n') {
4984         cost_of_damage = check_credit(cost_of_damage, shkp);
4985         if (cost_of_damage > 0L) {
4986             money2mon(shkp, cost_of_damage);
4987             context.botl = 1;
4988         }
4989 /*JP
4990         pline("Mollified, %s accepts your restitution.", shkname(shkp));
4991 */
4992         pline("%s\82Í\81C\8a´\8fî\82ð\82â\82í\82ç\82°\94\85\8f\9e\8bà\82ð\8eó\82¯\82Æ\82Á\82½\81D", shkname(shkp));
4993         /* move shk back to his home loc */
4994         home_shk(shkp, FALSE);
4995         pacify_shk(shkp);
4996     } else {
4997         if (!animal) {
4998             if (!Deaf && !muteshk(shkp))
4999 /*JP
5000             verbalize("Oh, yes!  You'll pay!");
5001 */
5002             verbalize("\82³\82 \81C\95¥\82¤\82ñ\82¾\81I");
5003             else
5004 #if 0 /*JP*/
5005                 pline("%s lunges %s %s toward your %s!",
5006                       Shknam(shkp), noit_mhis(shkp),
5007                       mbodypart(shkp, HAND), body_part(NECK));
5008 #else
5009                 pline("%s\82Í%s\82ð\82 \82È\82½\82Ì%s\82É\93Ë\82«\8fo\82µ\82½\81I",
5010                       Shknam(shkp),
5011                       mbodypart(shkp, HAND),
5012                       body_part(NECK));
5013 #endif
5014         } else
5015             growl(shkp);
5016         hot_pursuit(shkp);
5017         adjalign(-sgn(u.ualign.type));
5018     }
5019 }
5020
5021 /* called in dokick.c when we kick an object that might be in a store */
5022 boolean
5023 costly_spot(x, y)
5024 register xchar x, y;
5025 {
5026     struct monst *shkp;
5027     struct eshk *eshkp;
5028
5029     if (!level.flags.has_shop)
5030         return FALSE;
5031     shkp = shop_keeper(*in_rooms(x, y, SHOPBASE));
5032     if (!shkp || !inhishop(shkp))
5033         return FALSE;
5034     eshkp = ESHK(shkp);
5035     return  (boolean) (inside_shop(x, y)
5036                        && !(x == eshkp->shk.x && y == eshkp->shk.y));
5037 }
5038
5039 /* called by dotalk(sounds.c) when #chatting; returns obj if location
5040    contains shop goods and shopkeeper is willing & able to speak */
5041 struct obj *
5042 shop_object(x, y)
5043 register xchar x, y;
5044 {
5045     register struct obj *otmp;
5046     register struct monst *shkp;
5047
5048     if (!(shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) || !inhishop(shkp))
5049         return (struct obj *) 0;
5050
5051     for (otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere)
5052         if (otmp->oclass != COIN_CLASS)
5053             break;
5054     /* note: otmp might have ->no_charge set, but that's ok */
5055     return (otmp && costly_spot(x, y)
5056             && NOTANGRY(shkp) && shkp->mcanmove && !shkp->msleeping)
5057                ? otmp
5058                : (struct obj *) 0;
5059 }
5060
5061 /* give price quotes for all objects linked to this one (ie, on this spot) */
5062 void
5063 price_quote(first_obj)
5064 register struct obj *first_obj;
5065 {
5066     register struct obj *otmp;
5067     char buf[BUFSZ], price[40];
5068     long cost = 0L;
5069     int cnt = 0;
5070     boolean contentsonly = FALSE;
5071     winid tmpwin;
5072     struct monst *shkp = shop_keeper(inside_shop(u.ux, u.uy));
5073
5074     tmpwin = create_nhwindow(NHW_MENU);
5075 /*JP
5076     putstr(tmpwin, 0, "Fine goods for sale:");
5077 */
5078     putstr(tmpwin, 0, "\94\84\82è\82É\82Å\82Ä\82¢\82é\82·\82Î\82ç\82µ\82¢\8f¤\95i\81F");
5079     putstr(tmpwin, 0, "");
5080     for (otmp = first_obj; otmp; otmp = otmp->nexthere) {
5081         if (otmp->oclass == COIN_CLASS)
5082             continue;
5083         cost = (otmp->no_charge || otmp == uball || otmp == uchain) ? 0L
5084                  : get_cost(otmp, shkp);
5085         contentsonly = !cost;
5086         if (Has_contents(otmp))
5087             cost += contained_cost(otmp, shkp, 0L, FALSE, FALSE);
5088         if (!cost) {
5089 /*JP
5090             Strcpy(price, "no charge");
5091 */
5092             Strcpy(price, "\96³\97¿");
5093             contentsonly = FALSE;
5094         } else {
5095 #if 0 /*JP*/
5096             Sprintf(price, "%ld %s%s", cost, currency(cost),
5097                     (otmp->quan) > 1L ? " each" : "");
5098 #else
5099             Sprintf(price, "%s%ld%s", 
5100                     otmp->quan > 1L ? "\82»\82ê\82¼\82ê" : "", cost, currency(cost));
5101 #endif
5102         }
5103 #if 0 /*JP*/
5104         Sprintf(buf, "%s%s, %s", contentsonly ? the_contents_of : "",
5105                 doname(otmp), price);
5106 #else
5107         Sprintf(buf, "%s%s\81C%s", doname(otmp),
5108                 contentsonly ? "\82Ì\92\86\90g" : "", price);
5109 #endif
5110         putstr(tmpwin, 0, buf), cnt++;
5111     }
5112     if (cnt > 1) {
5113         display_nhwindow(tmpwin, TRUE);
5114     } else if (cnt == 1) {
5115         if (!cost) {
5116             /* "<doname(obj)>, no charge" */
5117 #if 0 /*JP*/
5118             pline("%s!", upstart(buf)); /* buf still contains the string */
5119 #else
5120             pline("%s\81I", buf); /* buf still contains the string */
5121 #endif
5122         } else {
5123             /* print cost in slightly different format, so can't reuse buf;
5124                cost and contentsonly are already set up */
5125 #if 0 /*JP*/
5126             Sprintf(buf, "%s%s", contentsonly ? the_contents_of : "",
5127                     doname(first_obj));
5128 #else
5129             Sprintf(buf, "%s%s", doname(first_obj),
5130                     contentsonly ? "\82Ì\92\86\90g" : "");
5131 #endif
5132 #if 0 /*JP*/
5133             pline("%s, price %ld %s%s%s", upstart(buf), cost, currency(cost),
5134                   (first_obj->quan > 1L) ? " each" : "",
5135                   contentsonly ? "." : shk_embellish(first_obj, cost));
5136 #else
5137             pline("%s%s\82Í%s%ld%s\82¾\81D", 
5138                   shk_embellish(first_obj, cost), buf,
5139                   first_obj->quan > 1L ? "\82»\82ê\82¼\82ê" : "",
5140                   cost, currency(cost));
5141 #endif
5142         }
5143     }
5144     destroy_nhwindow(tmpwin);
5145 }
5146
5147 /*JP
5148  \93X\8eå\82Ì\94\84\82è\95\8bå\81B\89p\8cê\82Å\82Í\96\96\94ö\82É\95t\82­\82ª\93ú\96{\8cê\82Å\82Í\90æ\93ª\82É\95t\82­\81B
5149  \92¼\8cã\82É\83A\83C\83e\83\80\96¼\82ª\97\88\82é\82Ì\82Å\81A\83A\83C\83e\83\80\82É\91Î\82·\82é\8c`\97e\82Å\82à\93Æ\97§\82µ\82½\95\82Å\82à\97Ç\82¢\81B
5150  */
5151 STATIC_OVL const char *
5152 shk_embellish(itm, cost)
5153 register struct obj *itm;
5154 long cost;
5155 {
5156     if (!rn2(3)) {
5157         register int o, choice = rn2(5);
5158
5159         if (choice == 0)
5160             choice = (cost < 100L ? 1 : cost < 500L ? 2 : 3);
5161         switch (choice) {
5162         case 4:
5163             if (cost < 10L)
5164                 break;
5165             else
5166                 o = itm->oclass;
5167             if (o == FOOD_CLASS)
5168 /*JP
5169                 return ", gourmets' delight!";
5170 */
5171                 return "\83O\83\8b\83\81\82ª\8b\83\82¢\82Ä\8aì\82Ô";
5172             if (objects[itm->otyp].oc_name_known
5173                     ? objects[itm->otyp].oc_magic
5174                     : (o == AMULET_CLASS || o == RING_CLASS || o == WAND_CLASS
5175                        || o == POTION_CLASS || o == SCROLL_CLASS
5176                        || o == SPBOOK_CLASS))
5177 /*JP
5178                 return ", painstakingly developed!";
5179 */
5180                 return "\88ê\8b\89\82Ì\96\82\97Í\82ð\94é\82ß\82½";
5181 /*JP
5182             return ", superb craftsmanship!";
5183 */
5184             return "\88ê\97¬\90E\90l\82Ì\8dì\82Á\82½";
5185         case 3:
5186 /*JP
5187             return ", finest quality.";
5188 */
5189             return "\8dÅ\8d\82\82Ì\95i\8e¿\82ð\8cÖ\82é";
5190         case 2:
5191 /*JP
5192             return ", an excellent choice.";
5193 */
5194             return "\82³\82·\82ª\82¨\8bq\82³\82ñ\96Ú\82ª\8d\82\82¢\81I";
5195         case 1:
5196 /*JP
5197             return ", a real bargain.";
5198 */
5199             return "\96{\93ú\82Ì\96Ú\8bÊ\8f¤\95i\81I";
5200         default:
5201             break;
5202         }
5203     } else if (itm->oartifact) {
5204 /*JP
5205         return ", one of a kind!";
5206 */
5207         return "\82±\82ê\82Í\90¢\8aE\82É\82Ü\82½\82Æ\82È\82¢\81I";
5208     }
5209 /*JP
5210     return ".";
5211 */
5212     return "";
5213 }
5214
5215 /* First 4 supplied by Ronen and Tamar, remainder by development team */
5216 const char *Izchak_speaks[] = {
5217 /*JP
5218     "%s says: 'These shopping malls give me a headache.'",
5219 */
5220     "%s\9eH\82­\81w\82±\82ê\82ç\83V\83\87\83b\83s\83\93\83O\8aX\82Í\93ª\92É\82Ì\83^\83l\82¾\81D\81x",
5221 /*JP
5222     "%s says: 'Slow down.  Think clearly.'",
5223 */
5224     "%s\9eH\82­\81w\97\8e\82¿\92\85\82¢\82Ä\81C\96¾\9dð\82É\8dl\82¦\82æ\81D\81x",
5225 /*JP
5226     "%s says: 'You need to take things one at a time.'",
5227 */
5228     "%s\9eH\82­\81w\88ê\93x\82É\88ê\8cÂ\82¸\82Â\8eæ\82é\95K\97v\82ª\82 \82é\81D\81x",
5229 /*JP
5230     "%s says: 'I don't like poofy coffee... give me Columbian Supremo.'",
5231 */
5232     "%s\9eH\82­\81w\83z\83\82\82Á\82Û\82¢\83R\81[\83q\82Í\8dD\82«\82\82á\82È\82¢\81D\81D\81D\83R\83\8d\83\93\83r\83A\83\93\81E\83X\83v\83\8c\83\82\82ð\82½\82Ì\82Þ\81D\81x",
5233 /*JP
5234     "%s says that getting the devteam's agreement on anything is difficult.",
5235 */
5236     "\8aJ\94­\83`\81[\83\80\82É\89½\82ç\82©\82Ì\8b¦\92è\82ð\8b\81\82ß\82é\82±\82Æ\82Í\8d¢\93ï\82¾\82Æ%s\82Í\8fq\82×\82½\81D",
5237 /*JP
5238     "%s says that he has noticed those who serve their deity will prosper.",
5239 */
5240     "%s\82Í\90_\82É\8ed\82¦\82Ä\82¢\82é\82â\82Â\82Í\90¬\8c÷\82µ\82Ä\82¢\82é\82Æ\8fq\82×\82½\81D",
5241 /*JP
5242     "%s says: 'Don't try to steal from me - I have friends in high places!'",
5243 */
5244     "%s\9eH\82­\81w\8e\84\82©\82ç\93\90\82à\82¤\82È\82ñ\82Ä\8ev\82í\82È\82¢\82±\82Æ\82¾\81D\8fã\82Ì\95û\82É\92m\82è\8d\87\82¢\82ª\82¢\82é\82ñ\82¾\82©\82ç\81D\81x",
5245 /*JP
5246     "%s says: 'You may well need something from this shop in the future.'",
5247 */
5248     "%s\9eH\82­\81w\8f«\97\88\82±\82Ì\93X\82Ì\89½\82©\82ª\95K\97v\82Æ\82È\82é\82¾\82ë\82¤\81x",
5249 /*JP
5250     "%s comments about the Valley of the Dead as being a gateway."
5251 */
5252     "%s\82Í\8e\80\82Ì\92J\82Í\83Q\81[\83g\83E\83F\83C\82¾\82ë\82¤\82Æ\83R\83\81\83\93\83g\82ð\8fq\82×\82½\81D"
5253 };
5254
5255 void
5256 shk_chat(shkp)
5257 struct monst *shkp;
5258 {
5259     struct eshk *eshk;
5260     long shkmoney;
5261
5262     if (!shkp->isshk) {
5263         /* The monster type is shopkeeper, but this monster is
5264            not actually a shk, which could happen if someone
5265            wishes for a shopkeeper statue and then animates it.
5266            (Note: shkname() would be "" in a case like this.) */
5267 #if 0 /*JP*/
5268         pline("%s asks whether you've seen any untended shops recently.",
5269 #else
5270         pline("%s\82Í\8dÅ\8bß\82Ç\82±\82©\82É\93X\88õ\82Ì\82¢\82È\82¢\93X\82Í\82È\82¢\82©\82Æ\82½\82¸\82Ë\82½\81D",
5271 #endif
5272               Monnam(shkp));
5273         /* [Perhaps we ought to check whether this conversation
5274            is taking place inside an untended shop, but a shopless
5275            shk can probably be expected to be rather disoriented.] */
5276         return;
5277     }
5278
5279     eshk = ESHK(shkp);
5280     if (ANGRY(shkp)) {
5281 #if 0 /*JP:T*/
5282         pline("%s %s how much %s dislikes %s customers.",
5283               Shknam(shkp),
5284               (!Deaf && !muteshk(shkp)) ? "mentions" : "indicates",
5285               noit_mhe(shkp), eshk->robbed ? "non-paying" : "rude");
5286 #else
5287         pline("%s\82Í%s\8bq\82Í\91å\8c\99\82¢\82¾\82Æ%s\81D",
5288               Shknam(shkp),
5289               eshk->robbed ? "\8bà\82ð\8ex\95¥\82í\82È\82¢" : "\96³\97ç\82È",
5290               (!Deaf && !muteshk(shkp)) ? "\8c¾\82Á\82½" : "\8e¦\82µ\82½");
5291 #endif
5292     } else if (eshk->following) {
5293         if (strncmp(eshk->customer, plname, PL_NSIZ)) {
5294             if (!Deaf && !muteshk(shkp))
5295 #if 0 /*JP:T*/
5296                 verbalize("%s %s!  I was looking for %s.",
5297                       Hello(shkp), plname, eshk->customer);
5298 #else
5299                 verbalize("%s\81I\8e\84\82Í%s\82ð\92T\82µ\82Ä\82¢\82Ü\82·\81D",
5300                       Hello(shkp), eshk->customer);
5301 #endif
5302             eshk->following = 0;
5303         } else {
5304             if (!Deaf && !muteshk(shkp))
5305 #if 0 /*JP:T*/
5306                 verbalize("%s %s!  Didn't you forget to pay?",
5307                           Hello(shkp), plname);
5308 #else
5309                 verbalize("%s\81I\8ex\95¥\82¢\82ð\96Y\82ê\82Ä\82¢\82Ü\82¹\82ñ\82©\81H", 
5310                           Hello(shkp));
5311 #endif
5312             else
5313 #if 0 /*JP*/
5314                 pline("%s taps you on the %s.",
5315                       Shknam(shkp), body_part(ARM));
5316 #else
5317                 pline("%s\82Í\82 \82È\82½\82Ì%s\82ð\8cy\82­\82½\82½\82¢\82½\81D",
5318                       Shknam(shkp), body_part(ARM));
5319 #endif
5320         }
5321     } else if (eshk->billct) {
5322         register long total = addupbill(shkp) + eshk->debit;
5323
5324 #if 0 /*JP:T*/
5325         pline("%s %s that your bill comes to %ld %s.",
5326               Shknam(shkp),
5327               (!Deaf && !muteshk(shkp)) ? "says" : "indicates",
5328               total, currency(total));
5329 #else
5330         pline("%s\82Í\8a¨\92è\82ª%ld%s\82É\82È\82é\82Æ%s\81D",
5331               Shknam(shkp),
5332               total, currency(total),
5333               (!Deaf && !muteshk(shkp)) ? "\8c¾\82Á\82½" : "\8e¦\82µ\82½");
5334 #endif
5335     } else if (eshk->debit) {
5336 #if 0 /*JP*/
5337         pline("%s %s that you owe %s %ld %s.",
5338               Shknam(shkp),
5339               (!Deaf && !muteshk(shkp)) ? "reminds you" : "indicates",
5340               noit_mhim(shkp), eshk->debit, currency(eshk->debit));
5341 #else
5342         pline("\82 \82È\82½\82Í%s\82É%ld%s\82Ì\8eØ\82è\82ª\82 \82é\82±\82Æ\82ð\8ev\82¢\82¾\82µ\82½\81D",
5343               Shknam(shkp), eshk->debit, currency(eshk->debit));
5344 #endif
5345     } else if (eshk->credit) {
5346 #if 0 /*JP:T*/
5347         pline("%s encourages you to use your %ld %s of credit.",
5348               Shknam(shkp), eshk->credit, currency(eshk->credit));
5349 #else
5350         pline("%s\82Í%ld%s\82Ì\97a\82¯\8bà\82ð\8eg\82¤\82æ\82¤\8a©\82ß\82½\81D",
5351               Shknam(shkp), eshk->credit, currency(eshk->credit));
5352 #endif
5353     } else if (eshk->robbed) {
5354 #if 0 /*JP:T*/
5355         pline("%s %s about a recent robbery.",
5356               Shknam(shkp),
5357               (!Deaf && !muteshk(shkp)) ? "complains" : "indicates concern");
5358 #else
5359         pline("%s\82Í\8dÅ\8bß\82Ì\8b­\93\90\82É\82Â\82¢\82Ä%s\81D",
5360               Shknam(shkp),
5361               (!Deaf && !muteshk(shkp)) ? "\8bð\92s\82ð\82±\82Ú\82µ\82½" : "\8c\9c\94O\82ð\8e¦\82µ\82½");
5362 #endif
5363     } else if ((shkmoney = money_cnt(shkp->minvent)) < 50L) {
5364 #if 0 /*JP*/
5365         pline("%s %s that business is bad.",
5366               Shknam(shkp),
5367               (!Deaf && !muteshk(shkp)) ? "complains" : "indicates");
5368 #else
5369         pline("%s\82Í\8f¤\94\84\82ª\8e|\82­\82¢\82Á\82Ä\82È\82¢\82Æ%s\81D",
5370               Shknam(shkp),
5371               (!Deaf && !muteshk(shkp)) ? "\8bð\92s\82ð\82±\82Ú\82µ\82½" : "\8e¦\82µ\82½");
5372 #endif
5373     } else if (shkmoney > 4000) {
5374 #if 0 /*JP:T*/
5375         pline("%s %s that business is good.",
5376               Shknam(shkp),
5377               (!Deaf && !muteshk(shkp)) ? "says" : "indicates");
5378 #else
5379         pline("%s\82Í\8f¤\94\84\82ª\8e|\82­\82¢\82Á\82Ä\82¢\82é\82Æ%s\81D",
5380               Shknam(shkp),
5381               (!Deaf && !muteshk(shkp)) ? "\8c¾\82Á\82½" : "\8e¦\82µ\82½");
5382 #endif
5383     } else if (is_izchak(shkp, FALSE)) {
5384         if (!Deaf && !muteshk(shkp))
5385             pline(Izchak_speaks[rn2(SIZE(Izchak_speaks))], shkname(shkp));
5386     } else {
5387         if (!Deaf && !muteshk(shkp))
5388 /*JP
5389             pline("%s talks about the problem of shoplifters.", Shknam(shkp));
5390 */
5391             pline("%s\82Í\96\9c\88ø\82Ì\96â\91è\82É\82Â\82¢\82Ä\98b\82µ\82½\81D", Shknam(shkp));
5392     }
5393 }
5394
5395 STATIC_OVL void
5396 kops_gone(silent)
5397 boolean silent;
5398 {
5399     register int cnt = 0;
5400     register struct monst *mtmp, *mtmp2;
5401
5402     for (mtmp = fmon; mtmp; mtmp = mtmp2) {
5403         mtmp2 = mtmp->nmon;
5404         if (mtmp->data->mlet == S_KOP) {
5405             if (canspotmon(mtmp))
5406                 cnt++;
5407             mongone(mtmp);
5408         }
5409     }
5410     if (cnt && !silent)
5411 #if 0 /*JP*/
5412         pline_The("Kop%s (disappointed) vanish%s into thin air.",
5413                   plur(cnt), (cnt == 1) ? "es" : "");
5414 #else
5415         pline("\8cx\8a¯\82Í(\82ª\82Á\82©\82è\82µ\82Ä)\8ep\82ð\8fÁ\82µ\82½\81D");
5416 #endif
5417 }
5418
5419 STATIC_OVL long
5420 cost_per_charge(shkp, otmp, altusage)
5421 struct monst *shkp;
5422 struct obj *otmp;
5423 boolean altusage; /* some items have an "alternate" use with different cost */
5424 {
5425     long tmp = 0L;
5426
5427     if (!shkp || !inhishop(shkp))
5428         return 0L; /* insurance */
5429     tmp = get_cost(otmp, shkp);
5430
5431     /* The idea is to make the exhaustive use of an unpaid item
5432      * more expensive than buying it outright.
5433      */
5434     if (otmp->otyp == MAGIC_LAMP) { /* 1 */
5435         /* normal use (ie, as light source) of a magic lamp never
5436            degrades its value, but not charging anything would make
5437            identification too easy; charge an amount comparable to
5438            what is charged for an ordinary lamp (don't bother with
5439            angry shk surcharge) */
5440         if (!altusage)
5441             tmp = (long) objects[OIL_LAMP].oc_cost;
5442         else
5443             tmp += tmp / 3L;                 /* djinni is being released */
5444     } else if (otmp->otyp == MAGIC_MARKER) { /* 70 - 100 */
5445         /* No way to determine in advance how many charges will be
5446          * wasted.  So, arbitrarily, one half of the price per use.
5447          */
5448         tmp /= 2L;
5449     } else if (otmp->otyp == BAG_OF_TRICKS /* 1 - 20 */
5450                || otmp->otyp == HORN_OF_PLENTY) {
5451         /* altusage: emptying of all the contents at once */
5452         if (!altusage)
5453             tmp /= 5L;
5454     } else if (otmp->otyp == CRYSTAL_BALL               /* 1 - 5 */
5455                || otmp->otyp == OIL_LAMP                /* 1 - 10 */
5456                || otmp->otyp == BRASS_LANTERN
5457                || (otmp->otyp >= MAGIC_FLUTE
5458                    && otmp->otyp <= DRUM_OF_EARTHQUAKE) /* 5 - 9 */
5459                || otmp->oclass == WAND_CLASS) {         /* 3 - 11 */
5460         if (otmp->spe > 1)
5461             tmp /= 4L;
5462     } else if (otmp->oclass == SPBOOK_CLASS) {
5463         tmp -= tmp / 5L;
5464     } else if (otmp->otyp == CAN_OF_GREASE || otmp->otyp == TINNING_KIT
5465                || otmp->otyp == EXPENSIVE_CAMERA) {
5466         tmp /= 10L;
5467     } else if (otmp->otyp == POT_OIL) {
5468         tmp /= 5L;
5469     }
5470     return tmp;
5471 }
5472
5473 /* Charge the player for partial use of an unpaid object.
5474  *
5475  * Note that bill_dummy_object() should be used instead
5476  * when an object is completely used.
5477  */
5478 void
5479 check_unpaid_usage(otmp, altusage)
5480 struct obj *otmp;
5481 boolean altusage;
5482 {
5483     struct monst *shkp;
5484     const char *fmt, *arg1, *arg2;
5485     char buf[BUFSZ];
5486     long tmp;
5487
5488     if (!otmp->unpaid || !*u.ushops
5489         || (otmp->spe <= 0 && objects[otmp->otyp].oc_charged))
5490         return;
5491     if (!(shkp = shop_keeper(*u.ushops)) || !inhishop(shkp))
5492         return;
5493     if ((tmp = cost_per_charge(shkp, otmp, altusage)) == 0L)
5494         return;
5495
5496     arg1 = arg2 = "";
5497     if (otmp->oclass == SPBOOK_CLASS) {
5498 /*JP
5499         fmt = "%sYou owe%s %ld %s.";
5500 */
5501         fmt = "%s%s%ld%s\82Ì\8eØ\82è\82¾\81D";
5502 /*JP
5503         Sprintf(buf, "This is no free library, %s!  ", cad(FALSE));
5504 */
5505         Strcpy(buf, "\82¨\82¢\81I\82±\82±\82Í\90}\8f\91\8aÙ\82\82á\82È\82¢\81I");
5506         arg1 = rn2(2) ? buf : "";
5507 /*JP
5508         arg2 = ESHK(shkp)->debit > 0L ? " an additional" : "";
5509 */
5510         arg2 = ESHK(shkp)->debit > 0L ? "\82³\82ç\82É\8c¾\82¦\82Î" : "";
5511     } else if (otmp->otyp == POT_OIL) {
5512 /*JP
5513         fmt = "%s%sThat will cost you %ld %s (Yendorian Fuel Tax).";
5514 */
5515         fmt = "%s%s\92l\92i\82Í%ld%s(\83C\83F\83\93\83_\81[\94R\97¿\90Å)\82¾\81D";
5516     } else if (altusage && (otmp->otyp == BAG_OF_TRICKS
5517                             || otmp->otyp == HORN_OF_PLENTY)) {
5518 /*JP
5519         fmt = "%s%sEmptying that will cost you %ld %s.";
5520 */
5521         fmt = "%s%s\82»\82ê\82Ì\8eg\97p\97¿\82Í%ld%s\82¾\81D";
5522         if (!rn2(3))
5523 /*JP
5524             arg1 = "Whoa!  ";
5525 */
5526             arg1 = "\82¤\82í\81I";
5527         if (!rn2(3))
5528 /*JP
5529             arg1 = "Watch it!  ";
5530 */
5531             arg1 = "\8bC\82ð\82Â\82¯\82ë\81I";
5532     } else {
5533 /*JP
5534         fmt = "%s%sUsage fee, %ld %s.";
5535 */
5536         fmt = "%s%s\8eg\97p\97¿\82Í\81C%ld%s\82¾\81D";
5537         if (!rn2(3))
5538 /*JP
5539             arg1 = "Hey!  ";
5540 */
5541             arg1 = "\82¨\82¢\81I";
5542         if (!rn2(3))
5543 /*JP
5544             arg2 = "Ahem.  ";
5545 */
5546             arg2 = "\83S\83z\83\93\81D";
5547     }
5548
5549     if (!Deaf && !muteshk(shkp)) {
5550         verbalize(fmt, arg1, arg2, tmp, currency(tmp));
5551         exercise(A_WIS, TRUE); /* you just got info */
5552     }
5553     ESHK(shkp)->debit += tmp;
5554 }
5555
5556 /* for using charges of unpaid objects "used in the normal manner" */
5557 void
5558 check_unpaid(otmp)
5559 struct obj *otmp;
5560 {
5561     check_unpaid_usage(otmp, FALSE); /* normal item use */
5562 }
5563
5564 void
5565 costly_gold(x, y, amount)
5566 register xchar x, y;
5567 register long amount;
5568 {
5569     register long delta;
5570     register struct monst *shkp;
5571     register struct eshk *eshkp;
5572
5573     if (!costly_spot(x, y))
5574         return;
5575     /* shkp now guaranteed to exist by costly_spot() */
5576     shkp = shop_keeper(*in_rooms(x, y, SHOPBASE));
5577
5578     eshkp = ESHK(shkp);
5579     if (eshkp->credit >= amount) {
5580         if (eshkp->credit > amount)
5581 /*JP
5582             Your("credit is reduced by %ld %s.", amount, currency(amount));
5583 */
5584             Your("\97a\82¯\8bà\82Í%ld%s\8c¸\82Á\82½\81D", amount, currency(amount));
5585         else
5586 /*JP
5587             Your("credit is erased.");
5588 */
5589             Your("\97a\82¯\8bà\82Í\92 \8fÁ\82µ\82É\82È\82Á\82½\81D");
5590         eshkp->credit -= amount;
5591     } else {
5592         delta = amount - eshkp->credit;
5593         if (eshkp->credit)
5594 /*JP
5595             Your("credit is erased.");
5596 */
5597             Your("\97a\82¯\8bà\82Í\92 \8fÁ\82µ\82É\82È\82Á\82½\81D");
5598         if (eshkp->debit)
5599 /*JP
5600             Your("debt increases by %ld %s.", delta, currency(delta));
5601 */
5602             Your("\8eØ\8bà\82Í%ld%s\91\9d\82¦\82½\81D", delta, currency(delta));
5603         else
5604 /*JP
5605             You("owe %s %ld %s.", shkname(shkp), delta, currency(delta));
5606 */
5607             You("%s\82É%ld%s\82Ì\8eØ\82è\82ð\82Â\82­\82Á\82½\81D", shkname(shkp), delta, currency(delta));
5608         eshkp->debit += delta;
5609         eshkp->loan += delta;
5610         eshkp->credit = 0L;
5611     }
5612 }
5613
5614 /* used in domove to block diagonal shop-exit */
5615 /* x,y should always be a door */
5616 boolean
5617 block_door(x, y)
5618 register xchar x, y;
5619 {
5620     register int roomno = *in_rooms(x, y, SHOPBASE);
5621     register struct monst *shkp;
5622
5623     if (roomno < 0 || !IS_SHOP(roomno))
5624         return FALSE;
5625     if (!IS_DOOR(levl[x][y].typ))
5626         return FALSE;
5627     if (roomno != *u.ushops)
5628         return FALSE;
5629
5630     if (!(shkp = shop_keeper((char) roomno)) || !inhishop(shkp))
5631         return FALSE;
5632
5633     if (shkp->mx == ESHK(shkp)->shk.x && shkp->my == ESHK(shkp)->shk.y
5634         /* Actually, the shk should be made to block _any_
5635          * door, including a door the player digs, if the
5636          * shk is within a 'jumping' distance.
5637          */
5638         && ESHK(shkp)->shd.x == x
5639         && ESHK(shkp)->shd.y == y
5640         && shkp->mcanmove && !shkp->msleeping
5641         && (ESHK(shkp)->debit || ESHK(shkp)->billct || ESHK(shkp)->robbed)) {
5642 #if 0 /*JP*/
5643         pline("%s%s blocks your way!", Shknam(shkp),
5644               Invis ? " senses your motion and" : "");
5645 #else
5646         pline("%s\82Í%s\82 \82È\82½\82Ì\91O\82É\97§\82¿\82Ó\82³\82ª\82Á\82½\81I", Shknam(shkp),
5647               Invis ? "\93®\82«\82ð\8a´\82\82Æ\82è\81C" : "");
5648 #endif
5649         return TRUE;
5650     }
5651     return FALSE;
5652 }
5653
5654 /* used in domove to block diagonal shop-entry;
5655    u.ux, u.uy should always be a door */
5656 boolean
5657 block_entry(x, y)
5658 register xchar x, y;
5659 {
5660     register xchar sx, sy;
5661     register int roomno;
5662     register struct monst *shkp;
5663
5664     if (!(IS_DOOR(levl[u.ux][u.uy].typ)
5665           && levl[u.ux][u.uy].doormask == D_BROKEN))
5666         return FALSE;
5667
5668     roomno = *in_rooms(x, y, SHOPBASE);
5669     if (roomno < 0 || !IS_SHOP(roomno))
5670         return FALSE;
5671     if (!(shkp = shop_keeper((char) roomno)) || !inhishop(shkp))
5672         return FALSE;
5673
5674     if (ESHK(shkp)->shd.x != u.ux || ESHK(shkp)->shd.y != u.uy)
5675         return FALSE;
5676
5677     sx = ESHK(shkp)->shk.x;
5678     sy = ESHK(shkp)->shk.y;
5679
5680     if (shkp->mx == sx && shkp->my == sy && shkp->mcanmove && !shkp->msleeping
5681         && (x == sx - 1 || x == sx + 1 || y == sy - 1 || y == sy + 1)
5682         && (Invis || carrying(PICK_AXE) || carrying(DWARVISH_MATTOCK)
5683             || u.usteed)) {
5684 #if 0 /*JP:T*/
5685         pline("%s%s blocks your way!", Shknam(shkp),
5686               Invis ? " senses your motion and" : "");
5687 #else
5688         pline("%s%s\82 \82È\82½\82Ì\91O\82É\97§\82¿\82Ó\82³\82ª\82Á\82½\81I", Shknam(shkp),
5689               Invis ? "\93®\82«\82ð\8a´\82\82Æ\82è\81C" : "");
5690 #endif
5691         return TRUE;
5692     }
5693     return FALSE;
5694 }
5695
5696 /* "your " or "Foobar's " (note the trailing space) */
5697 /* \81u\82 \82È\82½\82Ì\81v\82©\81uFoobar\82Ì\81v(\96\96\94ö\82É\8bó\94\92\82Í\95s\97v) */
5698 char *
5699 shk_your(buf, obj)
5700 char *buf;
5701 struct obj *obj;
5702 {
5703     if (!shk_owns(buf, obj) && !mon_owns(buf, obj))
5704         Strcpy(buf, the_your[carried(obj) ? 1 : 0]);
5705 /*JP
5706     return strcat(buf, " ");
5707 */
5708     return buf;
5709 }
5710
5711 char *
5712 Shk_Your(buf, obj)
5713 char *buf;
5714 struct obj *obj;
5715 {
5716     (void) shk_your(buf, obj);
5717 #if 0 /*JP*/
5718     *buf = highc(*buf);
5719 #endif
5720     return buf;
5721 }
5722
5723 STATIC_OVL char *
5724 shk_owns(buf, obj)
5725 char *buf;
5726 struct obj *obj;
5727 {
5728     struct monst *shkp;
5729     xchar x, y;
5730
5731     if (get_obj_location(obj, &x, &y, 0)
5732         && (obj->unpaid || (obj->where == OBJ_FLOOR && !obj->no_charge
5733                             && costly_spot(x, y)))) {
5734         shkp = shop_keeper(inside_shop(x, y));
5735 #if 0 /*JP*/
5736         return strcpy(buf, shkp ? s_suffix(shkname(shkp)) : the_your[0]);
5737 #else
5738         if (shkp) {
5739             strcpy(buf, shkname(shkp));
5740             strcat(buf, "\82Ì");
5741         } else {
5742             strcpy(buf, "");
5743         }
5744         return buf;
5745 #endif
5746     }
5747     return (char *) 0;
5748 }
5749
5750 STATIC_OVL char *
5751 mon_owns(buf, obj)
5752 char *buf;
5753 struct obj *obj;
5754 {
5755     if (obj->where == OBJ_MINVENT)
5756 #if 0 /*JP*/
5757         return strcpy(buf, s_suffix(y_monnam(obj->ocarry)));
5758 #else
5759         {
5760             strcpy(buf, mon_nam(obj->ocarry));
5761             strcat(buf, "\82Ì");
5762             return buf;
5763         }
5764 #endif
5765     return (char *) 0;
5766 }
5767
5768 #if 0 /*JP*//*\97\90\96\\82É\8cÄ\82Ñ\82©\82¯\82é\82Æ\82«\82Ì\93ñ\90l\8fÌ\81B\93ú\96{\8cê\82Å\82Í\81u\82¨\82¢\81v\82Å\8dÏ\82Þ\82Ì\82Å\8eg\82í\82È\82¢*/
5769 STATIC_OVL const char *
5770 cad(altusage)
5771 boolean altusage; /* used as a verbalized exclamation:  \"Cad! ...\" */
5772 {
5773     const char *res = 0;
5774
5775     switch (is_demon(youmonst.data) ? 3 : poly_gender()) {
5776     case 0:
5777         res = "cad";
5778         break;
5779     case 1:
5780         res = "minx";
5781         break;
5782     case 2:
5783         res = "beast";
5784         break;
5785     case 3:
5786         res = "fiend";
5787         break;
5788     default:
5789         impossible("cad: unknown gender");
5790         res = "thing";
5791         break;
5792     }
5793     if (altusage) {
5794         char *cadbuf = mon_nam(&youmonst); /* snag an output buffer */
5795
5796         /* alternate usage adds a leading double quote and trailing
5797            exclamation point plus sentence separating spaces */
5798         Sprintf(cadbuf, "\"%s!  ", res);
5799         cadbuf[1] = highc(cadbuf[1]);
5800         res = cadbuf;
5801     }
5802     return res;
5803 }
5804 #endif /*JP*/
5805
5806 #ifdef __SASC
5807 void
5808 sasc_bug(struct obj *op, unsigned x)
5809 {
5810     op->unpaid = x;
5811 }
5812 #endif
5813
5814 /*shk.c*/