OSDN Git Service

add translation
[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 /*JP
1527             You("can't %s anyone there.", !Blind ? "see" : "sense");
1528 */
1529             You("\82±\82±\82É\82Í\92N\82à%s\82È\82¢\81D", !Blind ? "\8c©\82¦" : "\8a´\82\82ç\82ê");
1530             return 0;
1531         }
1532         if (!mtmp) {
1533 /*JP
1534             There("is no one there to receive your payment.");
1535 */
1536             pline("\8ex\95¥\82¢\82ð\8eó\82¯\82Æ\82ê\82é\91\8a\8eè\82Í\82¢\82È\82¢\81D");
1537             return 0;
1538         }
1539         if (!mtmp->isshk) {
1540 /*JP
1541             pline("%s is not interested in your payment.", Monnam(mtmp));
1542 */
1543             pline("%s\82Í\8ex\95¥\82¢\82É\8b»\96¡\82ð\8e¦\82³\82È\82¢\81D", Monnam(mtmp));
1544             return 0;
1545         }
1546         if (mtmp != resident && distu(mtmp->mx, mtmp->my) > 2) {
1547 /*JP
1548             pline("%s is too far to receive your payment.", Shknam(mtmp));
1549 */
1550             pline("%s\82Í\8ex\95¥\82¢\82É\8b»\96¡\82ð\8e¦\82³\82È\82¢\81D", Shknam(mtmp));
1551             return 0;
1552         }
1553         shkp = mtmp;
1554     }
1555
1556     if (!shkp) {
1557         debugpline0("dopay: null shkp.");
1558         return 0;
1559     }
1560  proceed:
1561     eshkp = ESHK(shkp);
1562     ltmp = eshkp->robbed;
1563
1564     /* wake sleeping shk when someone who owes money offers payment */
1565     if (ltmp || eshkp->billct || eshkp->debit)
1566         rouse_shk(shkp, TRUE);
1567
1568     if (!shkp->mcanmove || shkp->msleeping) { /* still asleep/paralyzed */
1569 #if 0 /*JP:T*/
1570         pline("%s %s.", Shknam(shkp),
1571               rn2(2) ? "seems to be napping" : "doesn't respond");
1572 #else
1573         pline("%s\82Í%s\81D", Shknam(shkp),
1574               rn2(2) ? "\8b\8f\96°\82è\82ð\82µ\82Ä\82¢\82é\82æ\82¤\82¾" : "\94½\89\9e\82ª\82È\82¢");
1575 #endif
1576         return 0;
1577     }
1578
1579     if (shkp != resident && NOTANGRY(shkp)) {
1580         umoney = money_cnt(invent);
1581         if (!ltmp)
1582 /*JP
1583             You("do not owe %s anything.", shkname(shkp));
1584 */
1585             You("%s\82É\8eØ\82è\82Í\82È\82¢\81D", shkname(shkp));
1586         else if (!umoney) {
1587 /*JP
1588             You("%shave no money.", stashed_gold ? "seem to " : "");
1589 */
1590             You("\82¨\8bà\82ª\82È\82¢%s\81D", stashed_gold ? "\82æ\82¤\82¾" : "");
1591             if (stashed_gold)
1592 /*JP
1593                 pline("But you have some gold stashed away.");
1594 */
1595                 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");
1596         } else {
1597             if (umoney > ltmp) {
1598 #if 0 /*JP:T*/
1599                 You("give %s the %ld gold piece%s %s asked for.",
1600                     shkname(shkp), ltmp, plur(ltmp), noit_mhe(shkp));
1601 #else
1602                 You("%s\82É\96]\82Ý\92Ê\82è%ld\96\87\82Ì\8bà\89Ý\82ð\97^\82¦\82½\81D",
1603                     shkname(shkp), ltmp);
1604 #endif
1605                 pay(ltmp, shkp);
1606             } else {
1607 #if 0 /*JP:T*/
1608                 You("give %s all your%s gold.", shkname(shkp),
1609                     stashed_gold ? " openly kept" : "");
1610 #else
1611                 You("%s\82É%s\82¨\8bà\91S\95\94\82ð\97^\82¦\82½\81D", shkname(shkp),
1612                     stashed_gold ? "\8eè\8e\9d\82¿\82Ì" : "");
1613 #endif
1614                 pay(umoney, shkp);
1615                 if (stashed_gold)
1616 /*JP
1617                     pline("But you have hidden gold!");
1618 */
1619                     pline("\82µ\82©\82µ\81C\82 \82È\82½\82Í\83w\83\\83N\83\8a\82ª\82 \82é\81I");
1620             }
1621             if ((umoney < ltmp / 2L) || (umoney < ltmp && stashed_gold))
1622 /*JP
1623                 pline("Unfortunately, %s doesn't look satisfied.",
1624 */
1625                 pline("\8ec\94O\82È\82ª\82ç\81C%s\82Í\96\9e\91«\82µ\82Ä\82È\82¢\82æ\82¤\82¾\81D",
1626                       noit_mhe(shkp));
1627             else
1628                 make_happy_shk(shkp, FALSE);
1629         }
1630         return 1;
1631     }
1632
1633     /* ltmp is still eshkp->robbed here */
1634     if (!eshkp->billct && !eshkp->debit) {
1635         umoney = money_cnt(invent);
1636         if (!ltmp && NOTANGRY(shkp)) {
1637 /*JP
1638             You("do not owe %s anything.", shkname(shkp));
1639 */
1640             You("%s\82É\8eØ\82è\82Í\82È\82¢\81D", shkname(shkp));
1641             if (!umoney)
1642 /*JP
1643                 pline(no_money, stashed_gold ? " seem to" : "");
1644 */
1645                 pline(no_money, stashed_gold ? "\82æ\82¤\82¾" : "");
1646         } else if (ltmp) {
1647 /*JP
1648             pline("%s is after blood, not money!", shkname(shkp));
1649 */
1650             pline("%s\82Í\8c\8c\82Ü\82Ý\82ê\82¾\81D\82¨\8bà\82Ç\82±\82ë\82\82á\82È\82¢\81I", Monnam(shkp));
1651             if (umoney < ltmp / 2L || (umoney < ltmp && stashed_gold)) {
1652                 if (!umoney)
1653 /*JP
1654                     pline(no_money, stashed_gold ? " seem to" : "");
1655 */
1656                     pline(no_money, stashed_gold ? "\82æ\82¤\82¾" : "");
1657                 else
1658                     pline(not_enough_money, noit_mhim(shkp));
1659                 return 1;
1660             }
1661 /*JP
1662             pline("But since %s shop has been robbed recently,",
1663 */
1664             pline("\82µ\82©\82µ\81C%s\93X\82Í\8dÅ\8bß\93\90\82Ý\82É\82 \82Á\82½\82Ì\82Å\81C",
1665                   noit_mhis(shkp));
1666 #if 0 /*JP*/
1667             pline("you %scompensate %s for %s losses.",
1668                   (umoney < ltmp) ? "partially " : "", shkname(shkp),
1669                   noit_mhis(shkp));
1670 #else
1671             pline("%s\82Ì\91¹\8e¸%s\82ð\95â\93U\82µ\82½\81D", mhis(shkp),
1672                   (umoney < ltmp) ? "\82Ì\88ê\95\94" : "");
1673 #endif
1674             pay(umoney < ltmp ? umoney : ltmp, shkp);
1675             make_happy_shk(shkp, FALSE);
1676         } else {
1677             /* shopkeeper is angry, but has not been robbed --
1678              * door broken, attacked, etc. */
1679 /*JP
1680             pline("%s is after your hide, not your money!", Shknam(shkp));
1681 */
1682             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));
1683             if (umoney < 1000L) {
1684                 if (!umoney)
1685 /*JP
1686                     pline(no_money, stashed_gold ? " seem to" : "");
1687 */
1688                     pline(no_money, stashed_gold ? "\82æ\82¤\82¾" : "");
1689                 else
1690                     pline(not_enough_money, noit_mhim(shkp));
1691                 return 1;
1692             }
1693 #if 0 /*JP:T*/
1694             You("try to appease %s by giving %s 1000 gold pieces.",
1695                 canspotmon(shkp)
1696                     ? x_monnam(shkp, ARTICLE_THE, "angry", 0, FALSE)
1697                     : shkname(shkp),
1698                 noit_mhim(shkp));
1699 #else
1700             You("\8bà\89Ý1000\96\87\82ð%s\82É\8eè\93n\82µ\82Ä\82È\82¾\82ß\82æ\82¤\82Æ\82µ\82½\81D",
1701                 canspotmon(shkp)
1702                     ? x_monnam(shkp, ARTICLE_THE, "\93{\82Á\82½", 0, FALSE)
1703                     : shkname(shkp));
1704 #endif
1705             pay(1000L, shkp);
1706             if (strncmp(eshkp->customer, plname, PL_NSIZ) || rn2(3))
1707                 make_happy_shk(shkp, FALSE);
1708             else
1709 /*JP
1710                 pline("But %s is as angry as ever.", shkname(shkp));
1711 */
1712                 pline("\82µ\82©\82µ%s\82Í\82Ü\82¾\93{\82Á\82Ä\82¢\82é\81D", shkname(shkp));
1713         }
1714         return 1;
1715     }
1716     if (shkp != resident) {
1717         impossible("dopay: not to shopkeeper?");
1718         if (resident)
1719             setpaid(resident);
1720         return 0;
1721     }
1722     /* pay debt, if any, first */
1723     if (eshkp->debit) {
1724         long dtmp = eshkp->debit;
1725         long loan = eshkp->loan;
1726         char sbuf[BUFSZ];
1727
1728         umoney = money_cnt(invent);
1729 #if 0 /*JP*//*\96\96\94ö\82É\89ñ\82·*/
1730         Sprintf(sbuf, "You owe %s %ld %s ", shkname(shkp), dtmp,
1731                 currency(dtmp));
1732 #endif
1733         if (loan) {
1734             if (loan == dtmp)
1735 /*JP
1736                 Strcat(sbuf, "you picked up in the store.");
1737 */
1738                 Strcpy(sbuf, "\93X\82Ì\92\86\82Å\8fE\82Á\82½\82à\82Ì\82É\91Î\82µ\82Ä\81C");
1739             else
1740 #if 0 /*JP*/
1741                 Strcat(sbuf,
1742                        "for gold picked up and the use of merchandise.");
1743 #else
1744                 Strcpy(sbuf,"\8fE\82Á\82½\82¨\8bà\82â\8eg\82Á\82½\8eG\89Ý\82É\91Î\82µ\82Ä\81C");
1745 #endif
1746         } else
1747 /*JP
1748             Strcat(sbuf, "for the use of merchandise.");
1749 */
1750             Strcpy(sbuf, "\8eg\82Á\82½\8eG\89Ý\82É\91Î\82µ\82Ä\81C");
1751 #if 1 /*JP*//*\8fã\82©\82ç\88Ú\93®*/
1752         Sprintf(eos(sbuf), "%s\82É%ld%s\82Ì\8eØ\82è\82ª\82 \82é\81D",
1753                 shkname(shkp), dtmp, currency(dtmp));
1754 #endif
1755         pline1(sbuf);
1756         if (umoney + eshkp->credit < dtmp) {
1757 #if 0 /*JP*/
1758             pline("But you don't%s have enough gold%s.",
1759                   stashed_gold ? " seem to" : "",
1760                   eshkp->credit ? " or credit" : "");
1761 #else
1762             pline("\82µ\82©\82µ\81C\82¨\8bà%s\91«\82è\82È\82¢%s\81D",
1763                   eshkp->credit ? "\82à\97a\82¯\8bà\82à" : "\82ª",
1764                   stashed_gold ? "\82æ\82¤\82¾" : "");
1765 #endif
1766             return 1;
1767         } else {
1768             if (eshkp->credit >= dtmp) {
1769                 eshkp->credit -= dtmp;
1770                 eshkp->debit = 0L;
1771                 eshkp->loan = 0L;
1772 /*JP
1773                 Your("debt is covered by your credit.");
1774 */
1775                 Your("\8eØ\8bà\82Í\97a\82¯\8bà\82Å\95â\82í\82ê\82½\81D");
1776             } else if (!eshkp->credit) {
1777                 money2mon(shkp, dtmp);
1778                 eshkp->debit = 0L;
1779                 eshkp->loan = 0L;
1780 /*JP
1781                 You("pay that debt.");
1782 */
1783                 You("\8eØ\8bà\82ð\95¥\82Á\82½\81D");
1784                 context.botl = 1;
1785             } else {
1786                 dtmp -= eshkp->credit;
1787                 eshkp->credit = 0L;
1788                 money2mon(shkp, dtmp);
1789                 eshkp->debit = 0L;
1790                 eshkp->loan = 0L;
1791 /*JP
1792                 pline("That debt is partially offset by your credit.");
1793 */
1794                 pline("\82»\82Ì\8eØ\8bà\82Í\88ê\95\94\97a\82¯\8bà\82Å\91\8a\8eE\82³\82ê\82½\81D");
1795 /*JP
1796                 You("pay the remainder.");
1797 */
1798                 You("\8ec\82è\82ð\95¥\82Á\82½\81D");
1799                 context.botl = 1;
1800             }
1801             paid = TRUE;
1802         }
1803     }
1804     /* now check items on bill */
1805     if (eshkp->billct) {
1806         register boolean itemize;
1807         int iprompt;
1808
1809         umoney = money_cnt(invent);
1810         if (!umoney && !eshkp->credit) {
1811 #if 0 /*JP*/
1812             You("%shave no money or credit%s.",
1813                 stashed_gold ? "seem to " : "", paid ? " left" : "");
1814 #else
1815             You("%s\82¨\8bà\82à\97a\82¯\8bà\82à\8e\9d\82Á\82Ä\82È\82¢%s\81D",
1816                 paid ? "\82à\82¤" : "", stashed_gold ? "\82æ\82¤\82¾" : "");
1817 #endif
1818             return 0;
1819         }
1820         if ((umoney + eshkp->credit) < cheapest_item(shkp)) {
1821 #if 0 /*JP*/
1822             You("don't have enough money to buy%s the item%s you picked.",
1823                 eshkp->billct > 1 ? " any of" : "", plur(eshkp->billct));
1824 #else
1825             pline("\8fE\82Á\82½\95i\95¨\82ð\94\83\82¤\82É\82Í\82¨\8bà\82ª\91«\82è\82È\82¢\81D");
1826 #endif
1827             if (stashed_gold)
1828 /*JP
1829                 pline("Maybe you have some gold stashed away?");
1830 */
1831                 You("\82Ç\82±\82©\82É\82¨\8bà\82ð\89B\82µ\82Ä\82¢\82é\82Ì\82©\82à\81H");
1832             return 0;
1833         }
1834
1835         /* this isn't quite right; it itemizes without asking if the
1836          * single item on the bill is partly used up and partly unpaid */
1837 /*JP
1838         iprompt = (eshkp->billct > 1 ? ynq("Itemized billing?") : 'y');
1839 */
1840         iprompt = (eshkp->billct > 1 ? ynq("\8cÂ\95Ê\82É\8a¨\92è\82µ\82Ü\82·\82©\81H") : 'y');
1841         itemize = (iprompt == 'y');
1842         if (iprompt == 'q')
1843             goto thanks;
1844
1845         for (pass = 0; pass <= 1; pass++) {
1846             tmp = 0;
1847             while (tmp < eshkp->billct) {
1848                 struct obj *otmp;
1849                 register struct bill_x *bp = &(eshkp->bill_p[tmp]);
1850
1851                 /* find the object on one of the lists */
1852                 if ((otmp = bp_to_obj(bp)) != 0) {
1853                     /* if completely used up, object quantity is stale;
1854                        restoring it to its original value here avoids
1855                        making the partly-used-up code more complicated */
1856                     if (bp->useup)
1857                         otmp->quan = bp->bquan;
1858                 } else {
1859                     impossible("Shopkeeper administration out of order.");
1860                     setpaid(shkp); /* be nice to the player */
1861                     return 1;
1862                 }
1863                 if (pass == bp->useup && otmp->quan == bp->bquan) {
1864                     /* pay for used-up items on first pass and others
1865                      * on second, so player will be stuck in the store
1866                      * less often; things which are partly used up
1867                      * are processed on both passes */
1868                     tmp++;
1869                 } else {
1870                     switch (dopayobj(shkp, bp, &otmp, pass, itemize)) {
1871                     case PAY_CANT:
1872                         return 1; /*break*/
1873                     case PAY_BROKE:
1874                         paid = TRUE;
1875                         goto thanks; /*break*/
1876                     case PAY_SKIP:
1877                         tmp++;
1878                         continue; /*break*/
1879                     case PAY_SOME:
1880                         paid = TRUE;
1881                         if (itemize)
1882                             bot();
1883                         continue; /*break*/
1884                     case PAY_BUY:
1885                         paid = TRUE;
1886                         break;
1887                     }
1888                     if (itemize)
1889                         bot();
1890                     *bp = eshkp->bill_p[--eshkp->billct];
1891                 }
1892             }
1893         }
1894  thanks:
1895         if (!itemize)
1896             update_inventory(); /* Done in dopayobj() if itemize. */
1897     }
1898     if (!ANGRY(shkp) && paid) {
1899         if (!Deaf && !muteshk(shkp))
1900 #if 0 /*JP:T*/
1901             verbalize("Thank you for shopping in %s %s!",
1902                       s_suffix(shkname(shkp)),
1903                       shtypes[eshkp->shoptype - SHOPBASE].name);
1904 #else
1905             verbalize("%s\82Ì%s\82Ö\82Ü\82½\82Ç\82¤\82¼\81I",
1906                       shkname(shkp),
1907                       shtypes[eshkp->shoptype - SHOPBASE].name);
1908 #endif
1909         else
1910 #if 0 /*JP:T*/
1911             pline("%s nods appreciatively at you for shopping in %s %s!",
1912                   Shknam(shkp), noit_mhis(shkp),
1913                   shtypes[eshkp->shoptype - SHOPBASE].name);
1914 #else
1915             pline("%s\82Í%s\82Å\82Ì\94\83\82¢\95¨\82É\8a´\8eÓ\82µ\82Ä\82¤\82È\82Ã\82¢\82½\81I",
1916                   Shknam(shkp),
1917                   shtypes[eshkp->shoptype - SHOPBASE].name);
1918 #endif
1919     }
1920     return 1;
1921 }
1922
1923 /* return 2 if used-up portion paid
1924  *        1 if paid successfully
1925  *        0 if not enough money
1926  *       -1 if skip this object
1927  *       -2 if no money/credit left
1928  */
1929 STATIC_OVL int
1930 dopayobj(shkp, bp, obj_p, which, itemize)
1931 register struct monst *shkp;
1932 register struct bill_x *bp;
1933 struct obj **obj_p;
1934 int which; /* 0 => used-up item, 1 => other (unpaid or lost) */
1935 boolean itemize;
1936 {
1937     register struct obj *obj = *obj_p;
1938     long ltmp, quan, save_quan;
1939     long umoney = money_cnt(invent);
1940     int buy;
1941     boolean stashed_gold = (hidden_gold() > 0L), consumed = (which == 0);
1942
1943     if (!obj->unpaid && !bp->useup) {
1944         impossible("Paid object on bill??");
1945         return PAY_BUY;
1946     }
1947     if (itemize && umoney + ESHK(shkp)->credit == 0L) {
1948 #if 0 /*JP*/
1949         You("%shave no money or credit left.",
1950             stashed_gold ? "seem to " : "");
1951 #else
1952         You("\82à\82¤\82¨\8bà\82à\97a\82¯\8bà\82à\82È\82¢%s\81D",
1953             stashed_gold ? "\82æ\82¤\82¾" : "");
1954 #endif
1955         return PAY_BROKE;
1956     }
1957     /* we may need to temporarily adjust the object, if part of the
1958        original quantity has been used up but part remains unpaid  */
1959     save_quan = obj->quan;
1960     if (consumed) {
1961         /* either completely used up (simple), or split needed */
1962         quan = bp->bquan;
1963         if (quan > obj->quan) /* difference is amount used up */
1964             quan -= obj->quan;
1965     } else {
1966         /* dealing with ordinary unpaid item */
1967         quan = obj->quan;
1968     }
1969     obj->quan = quan;        /* to be used by doname() */
1970     obj->unpaid = 0;         /* ditto */
1971     iflags.suppress_price++; /* affects containers */
1972     ltmp = bp->price * quan;
1973     buy = PAY_BUY; /* flag; if changed then return early */
1974
1975     if (itemize) {
1976         char qbuf[BUFSZ], qsfx[BUFSZ];
1977
1978 /*JP
1979         Sprintf(qsfx, " for %ld %s.  Pay?", ltmp, currency(ltmp));
1980 */
1981         Sprintf(qsfx, "\82Í%ld%s\82Å\82·.\94\83\82¢\82Ü\82·\82©\81H", ltmp, currency(ltmp));
1982 #if 0 /*JP*/
1983         (void) safe_qbuf(qbuf, (char *) 0, qsfx, obj,
1984                          (quan == 1L) ? Doname2 : doname, ansimpleoname,
1985                          (quan == 1L) ? "that" : "those");
1986 #else
1987         (void) safe_qbuf(qbuf, (char *) 0, qsfx, obj,
1988                          (quan == 1L) ? Doname2 : doname, ansimpleoname,
1989                          "\82»\82ê");
1990 #endif
1991         if (yn(qbuf) == 'n') {
1992             buy = PAY_SKIP;                         /* don't want to buy */
1993         } else if (quan < bp->bquan && !consumed) { /* partly used goods */
1994             obj->quan = bp->bquan - save_quan;      /* used up amount */
1995             if (!Deaf && !muteshk(shkp)) {
1996 #if 0 /*JP*/
1997                 verbalize("%s for the other %s before buying %s.",
1998                       ANGRY(shkp) ? "Pay" : "Please pay",
1999                       simpleonames(obj), /* short name suffices */
2000                       save_quan > 1L ? "these" : "this one");
2001 #else
2002                 verbalize("\82»\82ê\82ð\94\83\82¤\82Ü\82¦\82É\91¼\82Ì%s\82ð%s",
2003                       simpleonames(obj),
2004                       ANGRY(shkp) ? "\95¥\82¦\81I" : "\95¥\82Á\82Ä\82­\82¾\82³\82¢\81D");
2005 #endif
2006             } else {
2007 #if 0 /*JP*/
2008                 pline("%s %s%s your bill for the other %s first.",
2009                       Shknam(shkp),
2010                       ANGRY(shkp) ? "angrily " : "",
2011                       nolimbs(shkp->data) ? "motions to" : "points out",
2012                       simpleonames(obj));
2013 #else
2014                 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",
2015                       Shknam(shkp),
2016                       ANGRY(shkp) ? "\93{\82Á\82Ä" : "",
2017                       simpleonames(obj));
2018 #endif
2019             }
2020             buy = PAY_SKIP; /* shk won't sell */
2021         }
2022     }
2023     if (buy == PAY_BUY && umoney + ESHK(shkp)->credit < ltmp) {
2024 #if 0 /*JP*/
2025         You("don't%s have gold%s enough to pay for %s.",
2026             stashed_gold ? " seem to" : "",
2027             (ESHK(shkp)->credit > 0L) ? " or credit" : "",
2028             thesimpleoname(obj));
2029 #else
2030         You("%s\82Ì\91ã\8bà\82ð\8ex\95¥\82¤\82¾\82¯\82Ì\82¨\8bà%s\8e\9d\82Á\82Ä\82È\82¢%s\81D",
2031             thesimpleoname(obj),
2032             (ESHK(shkp)->credit > 0L) ? "\82à\97a\82¯\8bà\82à" : "\82ð",
2033             stashed_gold ? "\82æ\82¤\82¾" : "");
2034 #endif
2035         buy = itemize ? PAY_SKIP : PAY_CANT;
2036     }
2037
2038     if (buy != PAY_BUY) {
2039         /* restore unpaid object to original state */
2040         obj->quan = save_quan;
2041         obj->unpaid = 1;
2042         iflags.suppress_price--;
2043         return buy;
2044     }
2045
2046     pay(ltmp, shkp);
2047 #if 0 /*JP*/
2048     shk_names_obj(shkp, obj,
2049                   consumed ? "paid for %s at a cost of %ld gold piece%s.%s"
2050                            : "bought %s for %ld gold piece%s.%s",
2051                   ltmp, "");
2052 #else
2053     shk_names_obj(shkp, obj,
2054                   consumed ? "%s\82É\8bà\89Ý%ld\96\87%s\82ð\8ex\95¥\82Á\82½\81D%s"
2055                            : "%s\82ð\8bà\89Ý%ld\96\87%s\82Å\94\83\82Á\82½\81D%s",
2056                   ltmp, "");
2057 #endif
2058     obj->quan = save_quan; /* restore original count */
2059     /* quan => amount just bought, save_quan => remaining unpaid count */
2060     if (consumed) {
2061         if (quan != bp->bquan) {
2062             /* eliminate used-up portion; remainder is still unpaid */
2063             bp->bquan = obj->quan;
2064             obj->unpaid = 1;
2065             bp->useup = 0;
2066             buy = PAY_SOME;
2067         } else { /* completely used-up, so get rid of it */
2068             obj_extract_self(obj);
2069             /* assert( obj == *obj_p ); */
2070             dealloc_obj(obj);
2071             *obj_p = 0; /* destroy pointer to freed object */
2072         }
2073     } else if (itemize)
2074         update_inventory(); /* Done just once in dopay() if !itemize. */
2075     iflags.suppress_price--;
2076     return buy;
2077 }
2078
2079 static struct repo { /* repossession context */
2080     struct monst *shopkeeper;
2081     coord location;
2082 } repo;
2083
2084 /* routine called after dying (or quitting) */
2085 boolean
2086 paybill(croaked, silently)
2087 int croaked; /* -1: escaped dungeon; 0: quit; 1: died */
2088 boolean silently; /* maybe avoid messages */
2089 {
2090     struct monst *mtmp, *mtmp2, *firstshk, *resident, *creditor, *hostile,
2091         *localshk;
2092     struct eshk *eshkp;
2093     boolean taken = FALSE, local;
2094     int numsk = 0;
2095
2096     /* if we escaped from the dungeon, shopkeepers can't reach us;
2097        shops don't occur on level 1, but this could happen if hero
2098        level teleports out of the dungeon and manages not to die */
2099     if (croaked < 0)
2100         return FALSE;
2101     /* [should probably also return false when dead hero has been
2102         petrified since shk shouldn't be able to grab inventory
2103         which has been shut inside a statue] */
2104
2105     /* this is where inventory will end up if any shk takes it */
2106     repo.location.x = repo.location.y = 0;
2107     repo.shopkeeper = 0;
2108
2109     /*
2110      * Scan all shopkeepers on the level, to prioritize them:
2111      * 1) keeper of shop hero is inside and who is owed money,
2112      * 2) keeper of shop hero is inside who isn't owed any money,
2113      * 3) other shk who is owed money, 4) other shk who is angry,
2114      * 5) any shk local to this level, and if none is found,
2115      * 6) first shk on monster list (last resort; unlikely, since
2116      * any nonlocal shk will probably be in the owed category
2117      * and almost certainly be in the angry category).
2118      */
2119     resident = creditor = hostile = localshk = (struct monst *) 0;
2120     for (mtmp = next_shkp(fmon, FALSE); mtmp;
2121          mtmp = next_shkp(mtmp2, FALSE)) {
2122         mtmp2 = mtmp->nmon;
2123         eshkp = ESHK(mtmp);
2124         local = on_level(&eshkp->shoplevel, &u.uz);
2125         if (local && index(u.ushops, eshkp->shoproom)) {
2126             /* inside this shk's shop [there might be more than one
2127                resident shk if hero is standing in a breech of a shared
2128                wall, so give priority to one who's also owed money] */
2129             if (!resident || eshkp->billct || eshkp->debit || eshkp->robbed)
2130                 resident = mtmp;
2131         } else if (eshkp->billct || eshkp->debit || eshkp->robbed) {
2132             /* owe this shopkeeper money (might also owe others) */
2133             if (!creditor)
2134                 creditor = mtmp;
2135         } else if (eshkp->following || ANGRY(mtmp)) {
2136             /* this shopkeeper is antagonistic (others might be too) */
2137             if (!hostile)
2138                 hostile = mtmp;
2139         } else if (local) {
2140             /* this shopkeeper's shop is on current level */
2141             if (!localshk)
2142                 localshk = mtmp;
2143         }
2144     }
2145
2146     /* give highest priority shopkeeper first crack */
2147     firstshk = resident ? resident
2148                         : creditor ? creditor
2149                                    : hostile ? hostile
2150                                              : localshk;
2151     if (firstshk) {
2152         numsk++;
2153         taken = inherits(firstshk, numsk, croaked, silently);
2154     }
2155
2156     /* now handle the rest */
2157     for (mtmp = next_shkp(fmon, FALSE); mtmp;
2158          mtmp = next_shkp(mtmp2, FALSE)) {
2159         mtmp2 = mtmp->nmon;
2160         eshkp = ESHK(mtmp);
2161         local = on_level(&eshkp->shoplevel, &u.uz);
2162         if (mtmp != firstshk) {
2163             numsk++;
2164             taken |= inherits(mtmp, numsk, croaked, silently);
2165         }
2166         /* for bones: we don't want a shopless shk around */
2167         if (!local)
2168             mongone(mtmp);
2169     }
2170     return taken;
2171 }
2172
2173 STATIC_OVL boolean
2174 inherits(shkp, numsk, croaked, silently)
2175 struct monst *shkp;
2176 int numsk;
2177 int croaked;
2178 boolean silently;
2179 {
2180     long loss = 0L;
2181     long umoney;
2182     struct eshk *eshkp = ESHK(shkp);
2183     boolean take = FALSE, taken = FALSE;
2184     unsigned save_minvis = shkp->minvis;
2185     int roomno = *u.ushops;
2186     char takes[BUFSZ];
2187
2188     /* not strictly consistent; affects messages and prevents next player
2189        (if bones are saved) from blundering into or being ambused by an
2190        invisible shopkeeper */
2191     shkp->minvis = 0;
2192     /* The simplifying principle is that first-come
2193        already took everything you had. */
2194     if (numsk > 1) {
2195         if (cansee(shkp->mx, shkp->my) && croaked && !silently) {
2196             takes[0] = '\0';
2197             if (has_head(shkp->data) && !rn2(2))
2198 #if 0 /*JP:T*/
2199                 Sprintf(takes, ", shakes %s %s,", noit_mhis(shkp),
2200                         mbodypart(shkp, HEAD));
2201 #else
2202                 Strcpy(takes, "\8eñ\82ð\90U\82è\81C");
2203 #endif
2204 #if 0 /*JP:T*/
2205             pline("%s %slooks at your corpse%s and %s.", Shknam(shkp),
2206                   (!shkp->mcanmove || shkp->msleeping) ? "wakes up, " : "",
2207                   takes, !inhishop(shkp) ? "disappears" : "sighs");
2208 #else
2209             pline("%s\82Í%s\82 \82È\82½\82Ì\8e\80\91Ì\82ð\8c©\82Ä%s%s\81D", Shknam(shkp),
2210                   (!shkp->mcanmove || shkp->msleeping) ? "\96Ú\82ð\82³\82Ü\82·\82Æ" : "",
2211                   takes, !inhishop(shkp) ? "\8ep\82ð\8fÁ\82µ\82½" : "\97­\91§\82ð\82Â\82¢\82½");
2212 #endif
2213         }
2214         rouse_shk(shkp, FALSE); /* wake shk for bones */
2215         taken = (roomno == eshkp->shoproom);
2216         goto skip;
2217     }
2218
2219     /* get one case out of the way: you die in the shop, the */
2220     /* shopkeeper is peaceful, nothing stolen, nothing owed. */
2221     if (roomno == eshkp->shoproom && inhishop(shkp) && !eshkp->billct
2222         && !eshkp->robbed && !eshkp->debit && NOTANGRY(shkp)
2223         && !eshkp->following && u.ugrave_arise < LOW_PM) {
2224         taken = (invent != 0);
2225         if (taken && !silently)
2226 /*JP
2227             pline("%s gratefully inherits all your possessions.",
2228 */
2229             pline("%s\82Í\82 \82È\82½\82Ì\8e\9d\82¿\95¨\82ð\82 \82è\82ª\82½\82­\8eó\82¯\82Æ\82Á\82½\81D",
2230                   Shknam(shkp));
2231         set_repo_loc(shkp);
2232         goto clear;
2233     }
2234
2235     if (eshkp->billct || eshkp->debit || eshkp->robbed) {
2236         if (roomno == eshkp->shoproom && inhishop(shkp))
2237             loss = addupbill(shkp) + eshkp->debit;
2238         if (loss < eshkp->robbed)
2239             loss = eshkp->robbed;
2240         take = TRUE;
2241     }
2242
2243     if (eshkp->following || ANGRY(shkp) || take) {
2244         if (!invent)
2245             goto skip;
2246         umoney = money_cnt(invent);
2247         takes[0] = '\0';
2248         if (!shkp->mcanmove || shkp->msleeping)
2249 /*JP
2250             Strcat(takes, "wakes up and ");
2251 */
2252             Strcat(takes, "\96Ú\82ª\82³\82ß\82é\82Æ\81C");
2253         if (distu(shkp->mx, shkp->my) > 2)
2254 /*JP
2255             Strcat(takes, "comes and ");
2256 */
2257             Strcat(takes, "\8bß\82Ã\82«\81C");
2258 #if 0 /*JP*/
2259         Strcat(takes, "takes");
2260 #endif
2261
2262         if (loss > umoney || !loss || roomno == eshkp->shoproom) {
2263             eshkp->robbed -= umoney;
2264             if (eshkp->robbed < 0L)
2265                 eshkp->robbed = 0L;
2266             if (umoney > 0L) {
2267                 money2mon(shkp, umoney);
2268                 context.botl = 1;
2269             }
2270             if (!silently)
2271 /*JP
2272                 pline("%s %s all your possessions.", Shknam(shkp), takes);
2273 */
2274                 pline("%s\82Í%s\82 \82È\82½\82Ì\8e\9d\82¿\95¨\82·\82×\82Ä\82ð\82à\82ç\82Á\82½\81D", Shknam(shkp), takes);
2275             taken = TRUE;
2276             /* where to put player's invent (after disclosure) */
2277             set_repo_loc(shkp);
2278         } else {
2279             money2mon(shkp, loss);
2280             context.botl = 1;
2281             if (!silently)
2282 #if 0 /*JP:T*/
2283                 pline("%s %s the %ld %s %sowed %s.", Shknam(shkp),
2284                       takes, loss, currency(loss),
2285                       strncmp(eshkp->customer, plname, PL_NSIZ) ? "" : "you ",
2286                       noit_mhim(shkp));
2287 #else
2288                 pline("%s\82Í%s%s\8eØ\82è\82Ä\82¢\82é%ld%s\82ð\8eó\82¯\82Æ\82Á\82½\81D", Shknam(shkp),
2289                       takes,
2290                       strncmp(eshkp->customer, plname, PL_NSIZ) ? "" : "\82 \82È\82½\82ª",
2291                       loss, currency(loss));
2292 #endif
2293             /* shopkeeper has now been paid in full */
2294             pacify_shk(shkp);
2295             eshkp->following = 0;
2296             eshkp->robbed = 0L;
2297         }
2298  skip:
2299         /* in case we create bones */
2300         rouse_shk(shkp, FALSE); /* wake up */
2301         if (!inhishop(shkp))
2302             home_shk(shkp, FALSE);
2303     }
2304  clear:
2305     shkp->minvis = save_minvis;
2306     setpaid(shkp);
2307     return taken;
2308 }
2309
2310 STATIC_OVL void
2311 set_repo_loc(shkp)
2312 struct monst *shkp;
2313 {
2314     register xchar ox, oy;
2315     struct eshk *eshkp = ESHK(shkp);
2316
2317     /* if you're not in this shk's shop room, or if you're in its doorway
2318         or entry spot, then your gear gets dumped all the way inside */
2319     if (*u.ushops != eshkp->shoproom || IS_DOOR(levl[u.ux][u.uy].typ)
2320         || (u.ux == eshkp->shk.x && u.uy == eshkp->shk.y)) {
2321         /* shk.x,shk.y is the position immediately in
2322          * front of the door -- move in one more space
2323          */
2324         ox = eshkp->shk.x;
2325         oy = eshkp->shk.y;
2326         ox += sgn(ox - eshkp->shd.x);
2327         oy += sgn(oy - eshkp->shd.y);
2328     } else { /* already inside this shk's shop */
2329         ox = u.ux;
2330         oy = u.uy;
2331     }
2332     /* finish_paybill will deposit invent here */
2333     repo.location.x = ox;
2334     repo.location.y = oy;
2335     repo.shopkeeper = shkp;
2336 }
2337
2338 /* called at game exit, after inventory disclosure but before making bones;
2339    shouldn't issue any messages */
2340 void
2341 finish_paybill()
2342 {
2343     struct monst *shkp = repo.shopkeeper;
2344     int ox = repo.location.x, oy = repo.location.y;
2345
2346 #if 0 /* don't bother */
2347     if (ox == 0 && oy == 0)
2348         impossible("finish_paybill: no location");
2349 #endif
2350     /* normally done by savebones(), but that's too late in this case */
2351     unleash_all();
2352     /* if hero has any gold left, take it into shopkeeper's possession */
2353     if (shkp) {
2354         long umoney = money_cnt(invent);
2355
2356         if (umoney)
2357             money2mon(shkp, umoney);
2358     }
2359     /* transfer rest of the character's inventory to the shop floor */
2360     drop_upon_death((struct monst *) 0, (struct obj *) 0, ox, oy);
2361 }
2362
2363 /* find obj on one of the lists */
2364 STATIC_OVL struct obj *
2365 bp_to_obj(bp)
2366 register struct bill_x *bp;
2367 {
2368     register struct obj *obj;
2369     register unsigned int id = bp->bo_id;
2370
2371     if (bp->useup)
2372         obj = o_on(id, billobjs);
2373     else
2374         obj = find_oid(id);
2375     return obj;
2376 }
2377
2378 /*
2379  * Look for o_id on all lists but billobj.  Return obj or NULL if not found.
2380  * Its OK for restore_timers() to call this function, there should not
2381  * be any timeouts on the billobjs chain.
2382  */
2383 struct obj *
2384 find_oid(id)
2385 unsigned id;
2386 {
2387     struct obj *obj;
2388     struct monst *mon, *mmtmp[3];
2389     int i;
2390
2391     /* first check various obj lists directly */
2392     if ((obj = o_on(id, invent)) != 0)
2393         return obj;
2394     if ((obj = o_on(id, fobj)) != 0)
2395         return obj;
2396     if ((obj = o_on(id, level.buriedobjlist)) != 0)
2397         return obj;
2398     if ((obj = o_on(id, migrating_objs)) != 0)
2399         return obj;
2400
2401     /* not found yet; check inventory for members of various monst lists */
2402     mmtmp[0] = fmon;
2403     mmtmp[1] = migrating_mons;
2404     mmtmp[2] = mydogs; /* for use during level changes */
2405     for (i = 0; i < 3; i++)
2406         for (mon = mmtmp[i]; mon; mon = mon->nmon)
2407             if ((obj = o_on(id, mon->minvent)) != 0)
2408                 return obj;
2409
2410     /* not found at all */
2411     return (struct obj *) 0;
2412 }
2413
2414 /* Returns the price of an arbitrary item in the shop,
2415    0 if the item doesn't belong to a shopkeeper or hero is not in the shop. */
2416 long
2417 get_cost_of_shop_item(obj, nochrg)
2418 register struct obj *obj;
2419 int *nochrg; /* alternate return value: 1: no charge, 0: shop owned,        */
2420 {            /* -1: not in a shop (so should't be formatted as "no charge") */
2421     struct monst *shkp;
2422     struct obj *top;
2423     xchar x, y;
2424     boolean freespot;
2425     long cost = 0L;
2426
2427     *nochrg = -1; /* assume 'not applicable' */
2428     if (*u.ushops && obj->oclass != COIN_CLASS
2429         && obj != uball && obj != uchain
2430         && get_obj_location(obj, &x, &y, CONTAINED_TOO)
2431         && *in_rooms(x, y, SHOPBASE) == *u.ushops
2432         && (shkp = shop_keeper(inside_shop(x, y))) != 0 && inhishop(shkp)) {
2433         for (top = obj; top->where == OBJ_CONTAINED; top = top->ocontainer)
2434             continue;
2435         freespot = (top->where == OBJ_FLOOR
2436                     && x == ESHK(shkp)->shk.x && y == ESHK(shkp)->shk.y);
2437         /* no_charge is only set for floor items inside shop proper;
2438            items on freespot are implicitly 'no charge' */
2439         *nochrg = (top->where == OBJ_FLOOR && (obj->no_charge || freespot));
2440
2441         if (carried(top) ? (int) obj->unpaid : !*nochrg)
2442             cost = obj->quan * get_cost(obj, shkp);
2443         if (Has_contents(obj) && !freespot)
2444             cost += contained_cost(obj, shkp, 0L, FALSE, TRUE);
2445     }
2446     return cost;
2447 }
2448
2449 /* decide whether to apply a surcharge (or hypothetically, a discount) to obj
2450    if it had ID number 'oid'; returns 1: increase, 0: normal, -1: decrease */
2451 int
2452 oid_price_adjustment(obj, oid)
2453 struct obj *obj;
2454 unsigned oid;
2455 {
2456     int res = 0, otyp = obj->otyp;
2457
2458     if (!(obj->dknown && objects[otyp].oc_name_known)
2459         && (obj->oclass != GEM_CLASS || objects[otyp].oc_material != GLASS)) {
2460         res = ((oid % 4) == 0); /* id%4 ==0 -> +1, ==1..3 -> 0 */
2461     }
2462     return res;
2463 }
2464
2465 /* calculate the value that the shk will charge for [one of] an object */
2466 STATIC_OVL long
2467 get_cost(obj, shkp)
2468 register struct obj *obj;
2469 register struct monst *shkp; /* if angry, impose a surcharge */
2470 {
2471     long tmp = getprice(obj, FALSE),
2472          /* used to perform a single calculation even when multiple
2473             adjustments (unID'd, dunce/tourist, charisma) are made */
2474         multiplier = 1L, divisor = 1L;
2475
2476     if (!tmp)
2477         tmp = 5L;
2478     /* shopkeeper may notice if the player isn't very knowledgeable -
2479        especially when gem prices are concerned */
2480     if (!obj->dknown || !objects[obj->otyp].oc_name_known) {
2481         if (obj->oclass == GEM_CLASS
2482             && objects[obj->otyp].oc_material == GLASS) {
2483             int i;
2484             /* get a value that's 'random' from game to game, but the
2485                same within the same game */
2486             boolean pseudorand =
2487                 (((int) ubirthday % obj->otyp) >= obj->otyp / 2);
2488
2489             /* all gems are priced high - real or not */
2490             switch (obj->otyp - LAST_GEM) {
2491             case 1: /* white */
2492                 i = pseudorand ? DIAMOND : OPAL;
2493                 break;
2494             case 2: /* blue */
2495                 i = pseudorand ? SAPPHIRE : AQUAMARINE;
2496                 break;
2497             case 3: /* red */
2498                 i = pseudorand ? RUBY : JASPER;
2499                 break;
2500             case 4: /* yellowish brown */
2501                 i = pseudorand ? AMBER : TOPAZ;
2502                 break;
2503             case 5: /* orange */
2504                 i = pseudorand ? JACINTH : AGATE;
2505                 break;
2506             case 6: /* yellow */
2507                 i = pseudorand ? CITRINE : CHRYSOBERYL;
2508                 break;
2509             case 7: /* black */
2510                 i = pseudorand ? BLACK_OPAL : JET;
2511                 break;
2512             case 8: /* green */
2513                 i = pseudorand ? EMERALD : JADE;
2514                 break;
2515             case 9: /* violet */
2516                 i = pseudorand ? AMETHYST : FLUORITE;
2517                 break;
2518             default:
2519                 impossible("bad glass gem %d?", obj->otyp);
2520                 i = STRANGE_OBJECT;
2521                 break;
2522             }
2523             tmp = (long) objects[i].oc_cost;
2524         } else if (oid_price_adjustment(obj, obj->o_id) > 0) {
2525             /* unid'd, arbitrarily impose surcharge: tmp *= 4/3 */
2526             multiplier *= 4L;
2527             divisor *= 3L;
2528         }
2529     }
2530     if (uarmh && uarmh->otyp == DUNCE_CAP)
2531         multiplier *= 4L, divisor *= 3L;
2532     else if ((Role_if(PM_TOURIST) && u.ulevel < (MAXULEV / 2))
2533              || (uarmu && !uarm && !uarmc)) /* touristy shirt visible */
2534         multiplier *= 4L, divisor *= 3L;
2535
2536     if (ACURR(A_CHA) > 18)
2537         divisor *= 2L;
2538     else if (ACURR(A_CHA) == 18)
2539         multiplier *= 2L, divisor *= 3L;
2540     else if (ACURR(A_CHA) >= 16)
2541         multiplier *= 3L, divisor *= 4L;
2542     else if (ACURR(A_CHA) <= 5)
2543         multiplier *= 2L;
2544     else if (ACURR(A_CHA) <= 7)
2545         multiplier *= 3L, divisor *= 2L;
2546     else if (ACURR(A_CHA) <= 10)
2547         multiplier *= 4L, divisor *= 3L;
2548
2549     /* tmp = (tmp * multiplier) / divisor [with roundoff tweak] */
2550     tmp *= multiplier;
2551     if (divisor > 1L) {
2552         /* tmp = (((tmp * 10) / divisor) + 5) / 10 */
2553         tmp *= 10L;
2554         tmp /= divisor;
2555         tmp += 5L;
2556         tmp /= 10L;
2557     }
2558
2559     if (tmp <= 0L)
2560         tmp = 1L;
2561     /* the artifact prices in artilist[] are also used as a score bonus;
2562        inflate their shop price here without affecting score calculation */
2563     if (obj->oartifact)
2564         tmp *= 4L;
2565
2566     /* anger surcharge should match rile_shk's, so we do it separately
2567        from the multiplier/divisor calculation */
2568     if (shkp && ESHK(shkp)->surcharge)
2569         tmp += (tmp + 2L) / 3L;
2570     return tmp;
2571 }
2572
2573 /* returns the price of a container's content.  the price
2574  * of the "top" container is added in the calling functions.
2575  * a different price quoted for selling as vs. buying.
2576  */
2577 long
2578 contained_cost(obj, shkp, price, usell, unpaid_only)
2579 struct obj *obj;
2580 struct monst *shkp;
2581 long price;
2582 boolean usell;
2583 boolean unpaid_only;
2584 {
2585     register struct obj *otmp, *top;
2586     xchar x, y;
2587     boolean on_floor, freespot;
2588
2589     for (top = obj; top->where == OBJ_CONTAINED; top = top->ocontainer)
2590         continue;
2591     /* pick_obj() removes item from floor, adds it to shop bill, then
2592        puts it in inventory; behave as if it is still on the floor
2593        during the add-to-bill portion of that situation */
2594     on_floor = (top->where == OBJ_FLOOR || top->where == OBJ_FREE);
2595     if (top->where == OBJ_FREE || !get_obj_location(top, &x, &y, 0))
2596         x = u.ux, y = u.uy;
2597     freespot = (on_floor && x == ESHK(shkp)->shk.x && y == ESHK(shkp)->shk.y);
2598
2599     /* price of contained objects; "top" container handled by caller */
2600     for (otmp = obj->cobj; otmp; otmp = otmp->nobj) {
2601         if (otmp->oclass == COIN_CLASS)
2602             continue;
2603
2604         if (usell) {
2605             if (saleable(shkp, otmp) && !otmp->unpaid
2606                 && otmp->oclass != BALL_CLASS
2607                 && !(otmp->oclass == FOOD_CLASS && otmp->oeaten)
2608                 && !(Is_candle(otmp)
2609                      && otmp->age < 20L * (long) objects[otmp->otyp].oc_cost))
2610                 price += set_cost(otmp, shkp);
2611         } else {
2612             /* no_charge is only set for floor items (including
2613                contents of floor containers) inside shop proper;
2614                items on freespot are implicitly 'no charge' */
2615             if (on_floor ? (!otmp->no_charge && !freespot)
2616                          : (otmp->unpaid || !unpaid_only))
2617                 price += get_cost(otmp, shkp) * otmp->quan;
2618         }
2619
2620         if (Has_contents(otmp))
2621             price = contained_cost(otmp, shkp, price, usell, unpaid_only);
2622     }
2623
2624     return price;
2625 }
2626
2627 /* count amount of gold inside container 'obj' and any nested containers */
2628 long
2629 contained_gold(obj)
2630 struct obj *obj;
2631 {
2632     register struct obj *otmp;
2633     register long value = 0L;
2634
2635     /* accumulate contained gold */
2636     for (otmp = obj->cobj; otmp; otmp = otmp->nobj)
2637         if (otmp->oclass == COIN_CLASS)
2638             value += otmp->quan;
2639         else if (Has_contents(otmp))
2640             value += contained_gold(otmp);
2641
2642     return value;
2643 }
2644
2645 STATIC_OVL void
2646 dropped_container(obj, shkp, sale)
2647 register struct obj *obj;
2648 register struct monst *shkp;
2649 register boolean sale;
2650 {
2651     register struct obj *otmp;
2652
2653     /* the "top" container is treated in the calling fn */
2654     for (otmp = obj->cobj; otmp; otmp = otmp->nobj) {
2655         if (otmp->oclass == COIN_CLASS)
2656             continue;
2657
2658         if (!otmp->unpaid && !(sale && saleable(shkp, otmp)))
2659             otmp->no_charge = 1;
2660
2661         if (Has_contents(otmp))
2662             dropped_container(otmp, shkp, sale);
2663     }
2664 }
2665
2666 void
2667 picked_container(obj)
2668 register struct obj *obj;
2669 {
2670     register struct obj *otmp;
2671
2672     /* the "top" container is treated in the calling fn */
2673     for (otmp = obj->cobj; otmp; otmp = otmp->nobj) {
2674         if (otmp->oclass == COIN_CLASS)
2675             continue;
2676
2677         if (otmp->no_charge)
2678             otmp->no_charge = 0;
2679
2680         if (Has_contents(otmp))
2681             picked_container(otmp);
2682     }
2683 }
2684
2685 STATIC_OVL boolean
2686 special_stock(obj, shkp, quietly)
2687 struct obj *obj;
2688 struct monst *shkp;
2689 boolean quietly;
2690 {
2691     /* for unique situations */
2692     if (ESHK(shkp)->shoptype == CANDLESHOP
2693         && obj->otyp == CANDELABRUM_OF_INVOCATION) {
2694         if (!quietly) {
2695             if (is_izchak(shkp, TRUE) && !u.uevent.invoked) {
2696                 if (Deaf || muteshk(shkp)) {
2697 #if 0 /*JP:T*/
2698                     pline("%s seems %s that you want to sell that.",
2699                           Shknam(shkp),
2700                           (obj->spe < 7) ? "horrified" : "concerned");
2701 #else
2702                     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",
2703                           Shknam(shkp),
2704                           (obj->spe < 7) ? "\8b°\82ê" : "\90S\94z\82µ");
2705 #endif
2706                 } else {
2707 /*JP
2708                 verbalize("No thanks, I'd hang onto that if I were you.");
2709 */
2710                 verbalize("\82¢\82â\81C\82¢\82ç\82È\82¢\81D\8e\84\82È\82ç\82»\82ê\82ð\8eè\95ú\82³\82È\82¢\82Ë\81D");
2711                     if (obj->spe < 7)
2712 #if 0 /*JP:T*/
2713                         verbalize(
2714                              "You'll need %d%s candle%s to go along with it.",
2715                                 (7 - obj->spe), (obj->spe > 0) ? " more" : "",
2716                                   plur(7 - obj->spe));
2717 #else
2718                         verbalize(
2719                              "\82»\82ê\82ð\8eg\82¤\82É\82Í%s%d\96{\82Ì\82ë\82¤\82»\82­\82ª\95K\97v\82¾\81D",
2720                               (obj->spe > 0) ? "\82 \82Æ" : "", (7 - obj->spe));
2721 #endif
2722                     /* [what if hero is already carrying enough candles?
2723                        should Izchak explain how to attach them instead?] */
2724                 }
2725             } else {
2726                 if (!Deaf && !muteshk(shkp))
2727 /*JP
2728                 verbalize("I won't stock that.  Take it out of here!");
2729 */
2730                 verbalize("\82»\82ê\82Í\8ed\93ü\82ê\82È\82¢\82æ\81D\8e\9d\82Á\82Ä\82¢\82«\82È\82³\82¢\81I");
2731                 else
2732 #if 0 /*JP:T*/
2733                     pline("%s shakes %s %s in refusal.",
2734                           Shknam(shkp), noit_mhis(shkp),
2735                           mbodypart(shkp, HEAD));
2736 #else
2737                     pline("%s\82Í%s\82ð\90U\82Á\82Ä\8b\91\94Û\82µ\82½\81D",
2738                           Shknam(shkp),
2739                           mbodypart(shkp, HEAD));
2740 #endif
2741             }
2742         }
2743         return TRUE;
2744     }
2745     return FALSE;
2746 }
2747
2748 /* calculate how much the shk will pay when buying [all of] an object */
2749 STATIC_OVL long
2750 set_cost(obj, shkp)
2751 register struct obj *obj;
2752 register struct monst *shkp;
2753 {
2754     long tmp = getprice(obj, TRUE) * obj->quan, multiplier = 1L, divisor = 1L;
2755
2756     if (uarmh && uarmh->otyp == DUNCE_CAP)
2757         divisor *= 3L;
2758     else if ((Role_if(PM_TOURIST) && u.ulevel < (MAXULEV / 2))
2759              || (uarmu && !uarm && !uarmc)) /* touristy shirt visible */
2760         divisor *= 3L;
2761     else
2762         divisor *= 2L;
2763
2764     /* shopkeeper may notice if the player isn't very knowledgeable -
2765        especially when gem prices are concerned */
2766     if (!obj->dknown || !objects[obj->otyp].oc_name_known) {
2767         if (obj->oclass == GEM_CLASS) {
2768             /* different shop keepers give different prices */
2769             if (objects[obj->otyp].oc_material == GEMSTONE
2770                 || objects[obj->otyp].oc_material == GLASS) {
2771                 tmp = (obj->otyp % (6 - shkp->m_id % 3));
2772                 tmp = (tmp + 3) * obj->quan;
2773             }
2774         } else if (tmp > 1L && !(shkp->m_id % 4))
2775             multiplier *= 3L, divisor *= 4L;
2776     }
2777
2778     if (tmp >= 1L) {
2779         /* [see get_cost()] */
2780         tmp *= multiplier;
2781         if (divisor > 1L) {
2782             tmp *= 10L;
2783             tmp /= divisor;
2784             tmp += 5L;
2785             tmp /= 10L;
2786         }
2787         /* avoid adjusting nonzero to zero */
2788         if (tmp < 1L)
2789             tmp = 1L;
2790     }
2791
2792     /* (no adjustment for angry shk here) */
2793     return tmp;
2794 }
2795
2796 /* unlike alter_cost() which operates on a specific item, identifying or
2797    forgetting a gem causes all unpaid gems of its type to change value */
2798 void
2799 gem_learned(oindx)
2800 int oindx;
2801 {
2802     struct obj *obj;
2803     struct monst *shkp;
2804     struct bill_x *bp;
2805     int ct;
2806
2807     /*
2808      * Unfortunately, shop bill doesn't have object type included,
2809      * just obj->oid for each unpaid stack, so we have to go through
2810      * every bill and every item on that bill and match up against
2811      * every unpaid stack on the level....
2812      *
2813      * Fortunately, there's no need to catch up when changing dungeon
2814      * levels even if we ID'd or forget some gems while gone from a
2815      * level.  There won't be any shop bills when arriving; they were
2816      * either paid before leaving or got treated as robbery and it's
2817      * too late to adjust pricing.
2818      */
2819     for (shkp = next_shkp(fmon, TRUE); shkp;
2820          shkp = next_shkp(shkp->nmon, TRUE)) {
2821         ct = ESHK(shkp)->billct;
2822         bp = ESHK(shkp)->bill;
2823         while (--ct >= 0) {
2824             obj = find_oid(bp->bo_id);
2825             if (!obj) /* shouldn't happen */
2826                 continue;
2827             if ((oindx != STRANGE_OBJECT) ? (obj->otyp == oindx)
2828                                           : (obj->oclass == GEM_CLASS))
2829                 bp->price = get_cost(obj, shkp);
2830             ++bp;
2831         }
2832     }
2833 }
2834
2835 /* called when an item's value has been enhanced; if it happens to be
2836    on any shop bill, update that bill to reflect the new higher price
2837    [if the new price drops for some reason, keep the old one in place] */
2838 void
2839 alter_cost(obj, amt)
2840 struct obj *obj;
2841 long amt; /* if 0, use regular shop pricing, otherwise force amount;
2842              if negative, use abs(amt) even if it's less than old cost */
2843 {
2844     struct bill_x *bp = 0;
2845     struct monst *shkp;
2846     long new_price;
2847
2848     for (shkp = next_shkp(fmon, TRUE); shkp; shkp = next_shkp(shkp, TRUE))
2849         if ((bp = onbill(obj, shkp, TRUE)) != 0) {
2850             new_price = !amt ? get_cost(obj, shkp) : (amt < 0L) ? -amt : amt;
2851             if (new_price > bp->price || amt < 0L) {
2852                 bp->price = new_price;
2853                 update_inventory();
2854             }
2855             break; /* done */
2856         }
2857     return;
2858 }
2859
2860 /* called from doinv(invent.c) for inventory of unpaid objects */
2861 long
2862 unpaid_cost(unp_obj, include_contents)
2863 struct obj *unp_obj; /* known to be unpaid or contain unpaid */
2864 boolean include_contents;
2865 {
2866     struct bill_x *bp = (struct bill_x *) 0;
2867     struct monst *shkp;
2868     long amt = 0L;
2869     xchar ox, oy;
2870
2871     if (!get_obj_location(unp_obj, &ox, &oy, BURIED_TOO | CONTAINED_TOO))
2872         ox = u.ux, oy = u.uy; /* (shouldn't happen) */
2873     if ((shkp = shop_keeper(*in_rooms(ox, oy, SHOPBASE))) != 0) {
2874         bp = onbill(unp_obj, shkp, TRUE);
2875     } else {
2876         /* didn't find shk?  try searching bills */
2877         for (shkp = next_shkp(fmon, TRUE); shkp;
2878              shkp = next_shkp(shkp->nmon, TRUE))
2879             if ((bp = onbill(unp_obj, shkp, TRUE)) != 0)
2880                 break;
2881     }
2882
2883     /* onbill() gave no message if unexpected problem occurred */
2884     if (!shkp || (unp_obj->unpaid && !bp)) {
2885         impossible("unpaid_cost: object wasn't on any bill.");
2886     } else {
2887         if (bp)
2888             amt = unp_obj->quan * bp->price;
2889         if (include_contents && Has_contents(unp_obj))
2890             amt = contained_cost(unp_obj, shkp, amt, FALSE, TRUE);
2891     }
2892     return amt;
2893 }
2894
2895 STATIC_OVL void
2896 add_one_tobill(obj, dummy, shkp)
2897 struct obj *obj;
2898 boolean dummy;
2899 struct monst *shkp;
2900 {
2901     struct eshk *eshkp;
2902     struct bill_x *bp;
2903     int bct;
2904
2905     if (!billable(&shkp, obj, *u.ushops, TRUE))
2906         return;
2907     eshkp = ESHK(shkp);
2908
2909     if (eshkp->billct == BILLSZ) {
2910 /*JP
2911         You("got that for free!");
2912 */
2913         You("\82»\82ê\82ð\82½\82¾\82Å\8eè\82É\93ü\82ê\82½\81I");
2914         return;
2915     }
2916
2917     /* normally bill_p gets set up whenever you enter the shop, but obj
2918        might be going onto the bill because hero just snagged it with
2919        a grappling hook from outside without ever having been inside */
2920     if (!eshkp->bill_p)
2921         eshkp->bill_p = &(eshkp->bill[0]);
2922
2923     bct = eshkp->billct;
2924     bp = &(eshkp->bill_p[bct]);
2925     bp->bo_id = obj->o_id;
2926     bp->bquan = obj->quan;
2927     if (dummy) {              /* a dummy object must be inserted into  */
2928         bp->useup = 1;        /* the billobjs chain here.  crucial for */
2929         add_to_billobjs(obj); /* eating floorfood in shop.  see eat.c  */
2930     } else
2931         bp->useup = 0;
2932     bp->price = get_cost(obj, shkp);
2933     eshkp->billct++;
2934     obj->unpaid = 1;
2935 }
2936
2937 STATIC_OVL void
2938 add_to_billobjs(obj)
2939 struct obj *obj;
2940 {
2941     if (obj->where != OBJ_FREE)
2942         panic("add_to_billobjs: obj not free");
2943     if (obj->timed)
2944         obj_stop_timers(obj);
2945
2946     obj->nobj = billobjs;
2947     billobjs = obj;
2948     obj->where = OBJ_ONBILL;
2949 }
2950
2951 /* recursive billing of objects within containers. */
2952 STATIC_OVL void
2953 bill_box_content(obj, ininv, dummy, shkp)
2954 register struct obj *obj;
2955 register boolean ininv, dummy;
2956 register struct monst *shkp;
2957 {
2958     register struct obj *otmp;
2959
2960     if (SchroedingersBox(obj))
2961         return;
2962     for (otmp = obj->cobj; otmp; otmp = otmp->nobj) {
2963         if (otmp->oclass == COIN_CLASS)
2964             continue;
2965
2966         /* the "top" box is added in addtobill() */
2967         if (!otmp->no_charge)
2968             add_one_tobill(otmp, dummy, shkp);
2969         if (Has_contents(otmp))
2970             bill_box_content(otmp, ininv, dummy, shkp);
2971     }
2972 }
2973
2974 /* shopkeeper tells you what you bought or sold, sometimes partly IDing it */
2975 STATIC_OVL void
2976 shk_names_obj(shkp, obj, fmt, amt, arg)
2977 struct monst *shkp;
2978 struct obj *obj;
2979 const char *fmt; /* "%s %ld %s %s", doname(obj), amt, plur(amt), arg */
2980 long amt;
2981 const char *arg;
2982 {
2983 #if 0 /*JP*/
2984     char *obj_name, fmtbuf[BUFSZ];
2985 #else
2986     char *obj_name;
2987 #endif
2988     boolean was_unknown = !obj->dknown;
2989
2990     obj->dknown = TRUE;
2991     /* Use real name for ordinary weapons/armor, and spell-less
2992      * scrolls/books (that is, blank and mail), but only if the
2993      * object is within the shk's area of interest/expertise.
2994      */
2995     if (!objects[obj->otyp].oc_magic && saleable(shkp, obj)
2996         && (obj->oclass == WEAPON_CLASS || obj->oclass == ARMOR_CLASS
2997             || obj->oclass == SCROLL_CLASS || obj->oclass == SPBOOK_CLASS
2998             || obj->otyp == MIRROR)) {
2999         was_unknown |= !objects[obj->otyp].oc_name_known;
3000         makeknown(obj->otyp);
3001     }
3002     obj_name = doname(obj);
3003     /* Use an alternate message when extra information is being provided */
3004 #if 0 /*JP*//*\93ú\96{\8cê\82Å\82Í\93¯\82\88µ\82¢*/
3005     if (was_unknown) {
3006         Sprintf(fmtbuf, "%%s; you %s", fmt);
3007         obj_name[0] = highc(obj_name[0]);
3008         pline(fmtbuf, obj_name, (obj->quan > 1L) ? "them" : "it", amt,
3009               plur(amt), arg);
3010     } else {
3011         You(fmt, obj_name, amt, plur(amt), arg);
3012     }
3013 #else
3014     You(fmt, obj_name, amt, "", arg);
3015 #endif
3016 }
3017
3018 /* decide whether a shopkeeper thinks an item belongs to her */
3019 boolean
3020 billable(shkpp, obj, roomno, reset_nocharge)
3021 struct monst **shkpp; /* in: non-null if shk has been validated; out: shk */
3022 struct obj *obj;
3023 char roomno;
3024 boolean reset_nocharge;
3025 {
3026     struct monst *shkp = *shkpp;
3027
3028     /* if caller hasn't supplied a shopkeeper, look one up now */
3029     if (!shkp) {
3030         if (!roomno)
3031             return FALSE;
3032         shkp = shop_keeper(roomno);
3033         if (!shkp || !inhishop(shkp))
3034             return FALSE;
3035         *shkpp = shkp;
3036     }
3037     /* perhaps we threw it away earlier */
3038     if (onbill(obj, shkp, FALSE)
3039         || (obj->oclass == FOOD_CLASS && obj->oeaten))
3040         return FALSE;
3041     /* outer container might be marked no_charge but still have contents
3042        which should be charged for; clear no_charge when picking things up */
3043     if (obj->no_charge) {
3044         if (!Has_contents(obj) || (contained_gold(obj) == 0L
3045                                    && contained_cost(obj, shkp, 0L, FALSE,
3046                                                      !reset_nocharge) == 0L))
3047             shkp = 0; /* not billable */
3048         if (reset_nocharge && !shkp && obj->oclass != COIN_CLASS) {
3049             obj->no_charge = 0;
3050             if (Has_contents(obj))
3051                 picked_container(obj); /* clear no_charge */
3052         }
3053     }
3054     return shkp ? TRUE : FALSE;
3055 }
3056
3057 void
3058 addtobill(obj, ininv, dummy, silent)
3059 struct obj *obj;
3060 boolean ininv, dummy, silent;
3061 {
3062     struct monst *shkp = 0;
3063     long ltmp, cltmp, gltmp;
3064     int contentscount;
3065     boolean container;
3066
3067     if (!billable(&shkp, obj, *u.ushops, TRUE))
3068         return;
3069
3070     if (obj->oclass == COIN_CLASS) {
3071         costly_gold(obj->ox, obj->oy, obj->quan);
3072         return;
3073     } else if (ESHK(shkp)->billct == BILLSZ) {
3074         if (!silent)
3075 /*JP
3076             You("got that for free!");
3077 */
3078             You("\82»\82ê\82ð\82½\82¾\82Å\8eè\82É\93ü\82ê\82½\81I");
3079         return;
3080     }
3081
3082     ltmp = cltmp = gltmp = 0L;
3083     container = Has_contents(obj);
3084
3085     if (!obj->no_charge)
3086         ltmp = get_cost(obj, shkp);
3087
3088     if (obj->no_charge && !container) {
3089         obj->no_charge = 0;
3090         return;
3091     }
3092
3093     if (container) {
3094         cltmp = contained_cost(obj, shkp, cltmp, FALSE, FALSE);
3095         gltmp = contained_gold(obj);
3096
3097         if (ltmp)
3098             add_one_tobill(obj, dummy, shkp);
3099         if (cltmp)
3100             bill_box_content(obj, ininv, dummy, shkp);
3101         picked_container(obj); /* reset contained obj->no_charge */
3102
3103         ltmp += cltmp;
3104
3105         if (gltmp) {
3106             costly_gold(obj->ox, obj->oy, gltmp);
3107             if (!ltmp)
3108                 return;
3109         }
3110
3111         if (obj->no_charge)
3112             obj->no_charge = 0;
3113         contentscount = count_unpaid(obj->cobj);
3114     } else { /* !container */
3115         add_one_tobill(obj, dummy, shkp);
3116         contentscount = 0;
3117     }
3118
3119     if (!Deaf && !muteshk(shkp) && !silent) {
3120         char buf[BUFSZ];
3121
3122         if (!ltmp) {
3123 /*JP
3124             pline("%s has no interest in %s.", Shknam(shkp), the(xname(obj)));
3125 */
3126             pline("%s\82Í%s\82É\8b»\96¡\82ð\8e¦\82³\82È\82¢\81D", Shknam(shkp), the(xname(obj)));
3127             return;
3128         }
3129         if (!ininv) {
3130 #if 0 /*JP*/
3131             pline("%s will cost you %ld %s%s.", The(xname(obj)), ltmp,
3132                   currency(ltmp), (obj->quan > 1L) ? " each" : "");
3133 #else
3134             pline("%s\82Í%s\82½\82Á\82½\82Ì%ld%s\82¾\81D", xname(obj),
3135                   (obj->quan > 1L) ? "\88ê\82Â" : "", ltmp, currency(ltmp));
3136 #endif
3137         } else {
3138             long save_quan = obj->quan;
3139
3140 #if 0 /*JP*/
3141             Strcpy(buf, "\"For you, ");
3142             if (ANGRY(shkp)) {
3143                 Strcat(buf, "scum;");
3144             } else {
3145                 append_honorific(buf);
3146                 Strcat(buf, "; only");
3147             }
3148 #else
3149             Strcpy(buf, "\81u");
3150             if (ANGRY(shkp)) {
3151                 Strcat(buf, "\82±\82Ì\83N\83\\82Á\82½\82ê\81C");
3152             } else {
3153                 append_honorific(buf);
3154                 Strcat(buf, "\81C");
3155             }
3156 #endif
3157             obj->quan = 1L; /* fool xname() into giving singular */
3158 #if 0 /*JP*/
3159             pline("%s %ld %s %s %s%s.\"", buf, ltmp, currency(ltmp),
3160                   (save_quan > 1L) ? "per"
3161                                    : (contentscount && !obj->unpaid)
3162                                        ? "for the contents of this"
3163                                        : "for this",
3164                   xname(obj),
3165                   (contentscount && obj->unpaid) ? and_its_contents : "");
3166 #else
3167             pline("%s%s%s\82½\82Á\82½\82Ì%ld%s\82¾\81D\81v", buf, xname(obj),
3168                   (save_quan > 1L) ? "\82Í\88ê\82Â" : (contentscount && !obj->unpaid)
3169                                                  ? "\82Ì\92\86\90g\82Í"
3170                                                  : "\82Í",
3171                   ltmp, currency(ltmp));
3172 #endif
3173             obj->quan = save_quan;
3174         }
3175     } else if (!silent) {
3176         if (ltmp)
3177 #if 0 /*JP*/
3178             pline_The("list price of %s%s%s is %ld %s%s.",
3179                       (contentscount && !obj->unpaid) ? the_contents_of : "",
3180                       the(xname(obj)),
3181                       (contentscount && obj->unpaid) ? and_its_contents : "",
3182                       ltmp, currency(ltmp), (obj->quan > 1L) ? " each" : "");
3183 #else
3184             pline_The("%s%s%s%s\82½\82Á\82½\82Ì%ld%s\82¾.",
3185                       the(xname(obj)),
3186                       (contentscount && !obj->unpaid) ? "\82Ì\92\86\90g\82Í" : "",
3187                       (contentscount && obj->unpaid) ? and_its_contents : "",
3188                       (obj->quan > 1L) ? "\82»\82ê\82¼\82ê" : "", ltmp, currency(ltmp));
3189 #endif
3190         else
3191 /*JP
3192             pline("%s does not notice.", Shknam(shkp));
3193 */
3194             pline("%s\82Í\8bC\82ª\82Â\82¢\82Ä\82¢\82È\82¢\81D", Shknam(shkp));
3195     }
3196 }
3197
3198 void
3199 append_honorific(buf)
3200 char *buf;
3201 {
3202     /* (chooses among [0]..[3] normally; [1]..[4] after the
3203        Wizard has been killed or invocation ritual performed) */
3204 #if 0 /*JP:T*/
3205     static const char *const honored[] = { "good", "honored", "most gracious",
3206                                            "esteemed",
3207                                            "most renowned and sacred" };
3208 #else
3209     static const char *const honored[] = {
3210         "\82â\82\9f", "\82â\82\9f\81C\96¼\97_\82 \82é", "\82â\82\9f\81C\8fã\95i\82È",
3211         "\82â\82\9f\81C\91¸\8ch\82·\82é",
3212         "\82â\82\9f\81C\8d\82\96¼\82Å\90_\90¹\82È"
3213         };
3214 #endif
3215
3216     Strcat(buf, honored[rn2(SIZE(honored) - 1) + u.uevent.udemigod]);
3217 #if 0 /*JP*//*\93ú\96{\8cê\82Å\82Í\82»\82±\82Ü\82Å\82µ\82È\82¢*/
3218     if (is_vampire(youmonst.data))
3219         Strcat(buf, (flags.female) ? " dark lady" : " dark lord");
3220     else if (is_elf(youmonst.data))
3221         Strcat(buf, (flags.female) ? " hiril" : " hir");
3222     else
3223 #endif
3224 #if 0 /*JP*/
3225         Strcat(buf, !is_human(youmonst.data) ? " creature"
3226                                              : (flags.female) ? " lady"
3227                                                               : " sir");
3228 #else
3229         Strcat(buf, !is_human(youmonst.data) ? "\90\95¨\82³\82ñ"
3230                                              : (flags.female) ? "\82¨\8fì\82³\82ñ"
3231                                                               : "\92U\93ß\82³\82ñ");
3232 #endif
3233 }
3234
3235 void
3236 splitbill(obj, otmp)
3237 register struct obj *obj, *otmp;
3238 {
3239     /* otmp has been split off from obj */
3240     register struct bill_x *bp;
3241     register long tmp;
3242     register struct monst *shkp = shop_keeper(*u.ushops);
3243
3244     if (!shkp || !inhishop(shkp)) {
3245         impossible("splitbill: no resident shopkeeper??");
3246         return;
3247     }
3248     bp = onbill(obj, shkp, FALSE);
3249     if (!bp) {
3250         impossible("splitbill: not on bill?");
3251         return;
3252     }
3253     if (bp->bquan < otmp->quan) {
3254         impossible("Negative quantity on bill??");
3255     }
3256     if (bp->bquan == otmp->quan) {
3257         impossible("Zero quantity on bill??");
3258     }
3259     bp->bquan -= otmp->quan;
3260
3261     if (ESHK(shkp)->billct == BILLSZ)
3262         otmp->unpaid = 0;
3263     else {
3264         tmp = bp->price;
3265         bp = &(ESHK(shkp)->bill_p[ESHK(shkp)->billct]);
3266         bp->bo_id = otmp->o_id;
3267         bp->bquan = otmp->quan;
3268         bp->useup = 0;
3269         bp->price = tmp;
3270         ESHK(shkp)->billct++;
3271     }
3272 }
3273
3274 STATIC_OVL void
3275 sub_one_frombill(obj, shkp)
3276 register struct obj *obj;
3277 register struct monst *shkp;
3278 {
3279     register struct bill_x *bp;
3280
3281     if ((bp = onbill(obj, shkp, FALSE)) != 0) {
3282         register struct obj *otmp;
3283
3284         obj->unpaid = 0;
3285         if (bp->bquan > obj->quan) {
3286             otmp = newobj();
3287             *otmp = *obj;
3288             otmp->oextra = (struct oextra *) 0;
3289             bp->bo_id = otmp->o_id = context.ident++;
3290             otmp->where = OBJ_FREE;
3291             otmp->quan = (bp->bquan -= obj->quan);
3292             otmp->owt = 0; /* superfluous */
3293             bp->useup = 1;
3294             add_to_billobjs(otmp);
3295             return;
3296         }
3297         ESHK(shkp)->billct--;
3298 #ifdef DUMB
3299         {
3300             /* DRS/NS 2.2.6 messes up -- Peter Kendell */
3301             int indx = ESHK(shkp)->billct;
3302
3303             *bp = ESHK(shkp)->bill_p[indx];
3304         }
3305 #else
3306         *bp = ESHK(shkp)->bill_p[ESHK(shkp)->billct];
3307 #endif
3308         return;
3309     } else if (obj->unpaid) {
3310         impossible("sub_one_frombill: unpaid object not on bill");
3311         obj->unpaid = 0;
3312     }
3313 }
3314
3315 /* recursive check of unpaid objects within nested containers. */
3316 void
3317 subfrombill(obj, shkp)
3318 register struct obj *obj;
3319 register struct monst *shkp;
3320 {
3321     register struct obj *otmp;
3322
3323     sub_one_frombill(obj, shkp);
3324
3325     if (Has_contents(obj))
3326         for (otmp = obj->cobj; otmp; otmp = otmp->nobj) {
3327             if (otmp->oclass == COIN_CLASS)
3328                 continue;
3329
3330             if (Has_contents(otmp))
3331                 subfrombill(otmp, shkp);
3332             else
3333                 sub_one_frombill(otmp, shkp);
3334         }
3335 }
3336
3337 STATIC_OVL long
3338 stolen_container(obj, shkp, price, ininv)
3339 struct obj *obj;
3340 struct monst *shkp;
3341 long price;
3342 boolean ininv;
3343 {
3344     struct obj *otmp;
3345     struct bill_x *bp;
3346     long billamt;
3347
3348     /* the price of contained objects; caller handles top container */
3349     for (otmp = obj->cobj; otmp; otmp = otmp->nobj) {
3350         if (otmp->oclass == COIN_CLASS)
3351             continue;
3352         billamt = 0L;
3353         if (!billable(&shkp, otmp, ESHK(shkp)->shoproom, TRUE)) {
3354             /* billable() returns false for objects already on bill */
3355             if ((bp = onbill(otmp, shkp, FALSE)) == 0)
3356                 continue;
3357             /* this assumes that we're being called by stolen_value()
3358                (or by a recursive call to self on behalf of it) where
3359                the cost of this object is about to be added to shop
3360                debt in place of having it remain on the current bill */
3361             billamt = bp->bquan * bp->price;
3362             sub_one_frombill(otmp, shkp); /* avoid double billing */
3363         }
3364
3365         if (billamt)
3366             price += billamt;
3367         else if (ininv ? otmp->unpaid : !otmp->no_charge)
3368             price += otmp->quan * get_cost(otmp, shkp);
3369
3370         if (Has_contents(otmp))
3371             price = stolen_container(otmp, shkp, price, ininv);
3372     }
3373
3374     return price;
3375 }
3376
3377 long
3378 stolen_value(obj, x, y, peaceful, silent)
3379 struct obj *obj;
3380 xchar x, y;
3381 boolean peaceful, silent;
3382 {
3383     long value = 0L, gvalue = 0L, billamt = 0L;
3384     char roomno = *in_rooms(x, y, SHOPBASE);
3385     struct bill_x *bp;
3386     struct monst *shkp = 0;
3387     boolean was_unpaid;
3388     long c_count = 0L, u_count = 0L;
3389
3390     /* gather information for message(s) prior to manipulating bill */
3391     was_unpaid = obj->unpaid ? TRUE : FALSE;
3392     if (Has_contents(obj)) {
3393         c_count = count_contents(obj, TRUE, FALSE, TRUE);
3394         u_count = count_contents(obj, TRUE, FALSE, FALSE);
3395     }
3396
3397     if (!billable(&shkp, obj, roomno, FALSE)) {
3398         /* things already on the bill yield a not-billable result, so
3399            we need to check bill before deciding that shk doesn't care */
3400         if ((bp = onbill(obj, shkp, FALSE)) != 0) {
3401             /* shk does care; take obj off bill to avoid double billing */
3402             billamt = bp->bquan * bp->price;
3403             sub_one_frombill(obj, shkp);
3404         }
3405         if (!bp && !u_count)
3406             return 0L;
3407     }
3408
3409     if (obj->oclass == COIN_CLASS) {
3410         gvalue += obj->quan;
3411     } else {
3412         if (billamt)
3413             value += billamt;
3414         else if (!obj->no_charge)
3415             value += obj->quan * get_cost(obj, shkp);
3416
3417         if (Has_contents(obj)) {
3418             boolean ininv =
3419                 (obj->where == OBJ_INVENT || obj->where == OBJ_FREE);
3420
3421             value += stolen_container(obj, shkp, 0L, ininv);
3422             if (!ininv)
3423                 gvalue += contained_gold(obj);
3424         }
3425     }
3426
3427     if (gvalue + value == 0L)
3428         return 0L;
3429
3430     value += gvalue;
3431
3432     if (peaceful) {
3433         boolean credit_use = !!ESHK(shkp)->credit;
3434
3435         value = check_credit(value, shkp);
3436         /* 'peaceful' affects general treatment, but doesn't affect
3437          * the fact that other code expects that all charges after the
3438          * shopkeeper is angry are included in robbed, not debit */
3439         if (ANGRY(shkp))
3440             ESHK(shkp)->robbed += value;
3441         else
3442             ESHK(shkp)->debit += value;
3443
3444         if (!silent) {
3445             char buf[BUFSZ];
3446             const char *still = "";
3447
3448             if (credit_use) {
3449                 if (ESHK(shkp)->credit) {
3450 #if 0 /*JP*/
3451                     You("have %ld %s credit remaining.", ESHK(shkp)->credit,
3452                         currency(ESHK(shkp)->credit));
3453 #else
3454                     You("%ld%s\82Ì\97a\82¯\8bà\82ª\8ec\82Á\82Ä\82¢\82é\81D", ESHK(shkp)->credit,
3455                         currency(ESHK(shkp)->credit));
3456 #endif
3457                     return value;
3458                 } else if (!value) {
3459 /*JP
3460                     You("have no credit remaining.");
3461 */
3462                     pline("\97a\82¯\8bà\82Í\82È\82­\82È\82Á\82½\81D");
3463                     return 0;
3464                 }
3465 /*JP
3466                 still = "still ";
3467 */
3468                 still = "\82³\82ç\82É";
3469             }
3470 #if 0 /*JP*/
3471             Sprintf(buf, "%sowe %s %ld %s", still, shkname(shkp),
3472                     value, currency(value));
3473             if (u_count) /* u_count > 0 implies Has_contents(obj) */
3474                 Sprintf(eos(buf), " for %s%sits contents",
3475                         was_unpaid ? "it and " : "",
3476                         (c_count > u_count) ? "some of " : "");
3477             else if (obj->oclass != COIN_CLASS)
3478                 Sprintf(eos(buf), " for %s",
3479                         (obj->quan > 1L) ? "them" : "it");
3480 #else
3481             Sprintf(buf, "%s%s\82É%ld%s\82Ì\8eØ\82è\82ð\82Â\82­\82Á\82½", still, shkname(shkp),
3482                     value, currency(value));
3483 #endif
3484
3485 #if 0 /*JP*/
3486             You("%s!", buf); /* "You owe <shk> N zorkmids for it!" */
3487 #else
3488             You("%s\81I", buf); /* "You owe <shk> N zorkmids for it!" */
3489 #endif
3490         }
3491     } else {
3492         ESHK(shkp)->robbed += value;
3493
3494         if (!silent) {
3495             if (canseemon(shkp)) {
3496 #if 0 /*JP*/
3497                 Norep("%s booms: \"%s, you are a thief!\"",
3498                       Shknam(shkp), plname);
3499 #else
3500                 Norep("%s\82Í\8b©\82ñ\82¾\81F\81u%s\81C\91Ò\82Ä\81I\82±\82Ì\82Ç\82ë\82Ú\82¤\82ß\81I\81v",
3501                       Shknam(shkp), plname);
3502 #endif
3503             } else
3504 /*JP
3505                 Norep("You hear a scream, \"Thief!\"");
3506 */
3507                 Norep("\8bà\90Ø\82è\90º\82ð\95·\82¢\82½\81C\81u\91Ò\82Ä\81I\82±\82Ì\82Ç\82ë\82Ú\82¤\82ß\81I\81v");
3508         }
3509         hot_pursuit(shkp);
3510         (void) angry_guards(FALSE);
3511     }
3512     return value;
3513 }
3514
3515 /* auto-response flag for/from "sell foo?" 'a' => 'y', 'q' => 'n' */
3516 static char sell_response = 'a';
3517 static int sell_how = SELL_NORMAL;
3518 /* can't just use sell_response='y' for auto_credit because the 'a' response
3519    shouldn't carry over from ordinary selling to credit selling */
3520 static boolean auto_credit = FALSE;
3521
3522 void
3523 sellobj_state(deliberate)
3524 int deliberate;
3525 {
3526     /* If we're deliberately dropping something, there's no automatic
3527        response to the shopkeeper's "want to sell" query; however, if we
3528        accidentally drop anything, the shk will buy it/them without asking.
3529        This retains the old pre-query risk that slippery fingers while in
3530        shops entailed:  you drop it, you've lost it.
3531      */
3532     sell_response = (deliberate != SELL_NORMAL) ? '\0' : 'a';
3533     sell_how = deliberate;
3534     auto_credit = FALSE;
3535 }
3536
3537 void
3538 sellobj(obj, x, y)
3539 register struct obj *obj;
3540 xchar x, y;
3541 {
3542     register struct monst *shkp;
3543     register struct eshk *eshkp;
3544     long ltmp = 0L, cltmp = 0L, gltmp = 0L, offer, shkmoney;
3545     boolean saleitem, cgold = FALSE, container = Has_contents(obj);
3546     boolean isgold = (obj->oclass == COIN_CLASS);
3547     boolean only_partially_your_contents = FALSE;
3548
3549     if (!*u.ushops) /* do cheapest exclusion test first */
3550         return;
3551     if (!(shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) || !inhishop(shkp))
3552         return;
3553     if (!costly_spot(x, y))
3554         return;
3555
3556     if (obj->unpaid && !container && !isgold) {
3557         sub_one_frombill(obj, shkp);
3558         return;
3559     }
3560     if (container) {
3561         /* find the price of content before subfrombill */
3562         cltmp = contained_cost(obj, shkp, cltmp, TRUE, FALSE);
3563         /* find the value of contained gold */
3564         gltmp += contained_gold(obj);
3565         cgold = (gltmp > 0L);
3566     }
3567
3568     saleitem = saleable(shkp, obj);
3569     if (!isgold && !obj->unpaid && saleitem)
3570         ltmp = set_cost(obj, shkp);
3571
3572     offer = ltmp + cltmp;
3573
3574     /* get one case out of the way: nothing to sell, and no gold */
3575     if (!(isgold || cgold)
3576         && ((offer + gltmp) == 0L || sell_how == SELL_DONTSELL)) {
3577         boolean unpaid = is_unpaid(obj);
3578
3579         if (container) {
3580             dropped_container(obj, shkp, FALSE);
3581             if (!obj->unpaid)
3582                 obj->no_charge = 1;
3583             if (unpaid)
3584                 subfrombill(obj, shkp);
3585         } else
3586             obj->no_charge = 1;
3587
3588         if (!unpaid && (sell_how != SELL_DONTSELL)
3589             && !special_stock(obj, shkp, FALSE))
3590 /*JP
3591             pline("%s seems uninterested.", Shknam(shkp));
3592 */
3593             pline("%s\82Í\8b»\96¡\82ª\82È\82¢\82æ\82¤\82¾\81D", Shknam(shkp));
3594         return;
3595     }
3596
3597     /* you dropped something of your own - probably want to sell it */
3598     rouse_shk(shkp, TRUE); /* wake up sleeping or paralyzed shk */
3599     eshkp = ESHK(shkp);
3600
3601     if (ANGRY(shkp)) { /* they become shop-objects, no pay */
3602         if (!Deaf && !muteshk(shkp))
3603 /*JP
3604             verbalize("Thank you, scum!");
3605 */
3606             verbalize("\82 \82è\82ª\82Æ\82æ\81C\82±\82Ì\83N\83\\82Á\82½\82ê\81I");
3607         else
3608 /*JP
3609             pline("%s smirks with satisfaction.", Shknam(shkp));
3610 */
3611             pline("%s\82Í\96\9e\91«\82µ\82Ä\8dì\82è\8fÎ\82¢\82ð\95\82\82©\82×\82½\81D", Shknam(shkp));
3612         subfrombill(obj, shkp);
3613         return;
3614     }
3615
3616     if (eshkp->robbed) { /* shkp is not angry? */
3617         if (isgold)
3618             offer = obj->quan;
3619         else if (cgold)
3620             offer += cgold;
3621         if ((eshkp->robbed -= offer < 0L))
3622             eshkp->robbed = 0L;
3623         if (offer && !Deaf && !muteshk(shkp))
3624             verbalize(
3625 /*JP
3626   "Thank you for your contribution to restock this recently plundered shop.");
3627 */
3628   "\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");
3629         subfrombill(obj, shkp);
3630         return;
3631     }
3632
3633     if (isgold || cgold) {
3634         if (!cgold)
3635             gltmp = obj->quan;
3636
3637         if (eshkp->debit >= gltmp) {
3638             if (eshkp->loan) { /* you carry shop's gold */
3639                 if (eshkp->loan >= gltmp)
3640                     eshkp->loan -= gltmp;
3641                 else
3642                     eshkp->loan = 0L;
3643             }
3644             eshkp->debit -= gltmp;
3645 /*JP
3646             Your("debt is %spaid off.", eshkp->debit ? "partially " : "");
3647 */
3648             Your("\8eØ\8bà\82Í%s\8ex\95¥\82í\82ê\82½\81D", eshkp->debit ? "\88ê\95\94" : "");
3649         } else {
3650             long delta = gltmp - eshkp->debit;
3651
3652             eshkp->credit += delta;
3653             if (eshkp->debit) {
3654                 eshkp->debit = 0L;
3655                 eshkp->loan = 0L;
3656 /*JP
3657                 Your("debt is paid off.");
3658 */
3659                 Your("\8eØ\8bà\82Í\8ex\95¥\82í\82ê\82½\81D");
3660             }
3661             if (eshkp->credit == delta)
3662 #if 0 /*JP*/
3663                 You("have established %ld %s credit.", delta,
3664                     currency(delta));
3665 #else
3666                 pline("%ld%s\82ð\97a\82¯\82½\81D", delta,
3667                       currency(delta));
3668 #endif
3669             else
3670 #if 0 /*JP*/
3671                 pline("%ld %s added to your credit; total is now %ld %s.",
3672                       delta, currency(delta), eshkp->credit,
3673                       currency(eshkp->credit));
3674 #else
3675                 pline("\97a\82¯\8bà\82É%ld%s\92Ç\89Á\82³\82ê\82½; \8d\87\8cv\82Í%ld%s\82É\82È\82Á\82½\81D.",
3676                       delta, currency(delta), eshkp->credit,
3677                       currency(eshkp->credit));
3678 #endif
3679         }
3680
3681         if (!offer || sell_how == SELL_DONTSELL) {
3682             if (!isgold) {
3683                 if (container)
3684                     dropped_container(obj, shkp, FALSE);
3685                 if (!obj->unpaid)
3686                     obj->no_charge = 1;
3687                 subfrombill(obj, shkp);
3688             }
3689             return;
3690         }
3691     }
3692
3693     if ((!saleitem && !(container && cltmp > 0L)) || eshkp->billct == BILLSZ
3694         || obj->oclass == BALL_CLASS || obj->oclass == CHAIN_CLASS
3695         || offer == 0L || (obj->oclass == FOOD_CLASS && obj->oeaten)
3696         || (Is_candle(obj)
3697             && obj->age < 20L * (long) objects[obj->otyp].oc_cost)) {
3698 #if 0 /*JP:T*/
3699         pline("%s seems uninterested%s.", Shknam(shkp),
3700               cgold ? " in the rest" : "");
3701 #else
3702         pline("%s\82Í%s\8b»\96¡\82ª\82È\82¢\82æ\82¤\82¾\81D", Shknam(shkp),
3703               cgold ? "\8ec\82è\95¨\82É\82Í" : "");
3704 #endif
3705         if (container)
3706             dropped_container(obj, shkp, FALSE);
3707         obj->no_charge = 1;
3708         return;
3709     }
3710
3711     shkmoney = money_cnt(shkp->minvent);
3712     if (!shkmoney) {
3713         char c, qbuf[BUFSZ];
3714 #if 1 /*JP*/
3715         char qsfx[BUFSZ];
3716 #endif
3717         long tmpcr = ((offer * 9L) / 10L) + (offer <= 1L);
3718
3719         if (sell_how == SELL_NORMAL || auto_credit) {
3720             c = sell_response = 'y';
3721         } else if (sell_response != 'n') {
3722 /*JP
3723             pline("%s cannot pay you at present.", Shknam(shkp));
3724 */
3725             pline("%s\82Í\8d¡\82Ì\82Æ\82±\82ë\82Í\8ex\95¥\82¦\82È\82¢\81D", Shknam(shkp));
3726 #if 0 /*JP*/
3727             Sprintf(qbuf, "Will you accept %ld %s in credit for ", tmpcr,
3728                     currency(tmpcr));
3729             c = ynaq(safe_qbuf(qbuf, qbuf, "?", obj, doname, thesimpleoname,
3730                                (obj->quan == 1L) ? "that" : "those"));
3731 #else
3732             Sprintf(qsfx, "\82É\82Â\82¢\82Ä%ld%s\82Ì\97a\82¯\8bà\82ð\8eó\82¯\82¢\82ê\82Ü\82·\82©\81H", tmpcr,
3733                     currency(tmpcr));
3734             c = ynaq(safe_qbuf(qbuf, "", qsfx, obj, doname, thesimpleoname,
3735                                "\82»\82ê"));
3736 #endif
3737             if (c == 'a') {
3738                 c = 'y';
3739                 auto_credit = TRUE;
3740             }
3741         } else /* previously specified "quit" */
3742             c = 'n';
3743
3744         if (c == 'y') {
3745 #if 0 /*JP*/
3746             shk_names_obj(
3747                 shkp, obj,
3748                 (sell_how != SELL_NORMAL)
3749                     ? "traded %s for %ld zorkmid%s in %scredit."
3750                     : "relinquish %s and acquire %ld zorkmid%s in %scredit.",
3751                 tmpcr, (eshkp->credit > 0L) ? "additional " : "");
3752 #else
3753             shk_names_obj(
3754                 shkp, obj,
3755                 (sell_how != SELL_NORMAL)
3756                     ? "%s\82ð\8bà\89Ý%ld\96\87\95ª\82Ì\97a\82¯\8bà\82Å\8eó\82¯\82Æ\82Á\82½%s\81D"
3757                     : "%s\82ð\93n\82µ\81C\8bà\89Ý%ld\96\87\95ª\82Ì\97a\82¯\8bà\82ð\93¾\82½%s\81D",
3758                 tmpcr, "");
3759 #endif
3760             eshkp->credit += tmpcr;
3761             subfrombill(obj, shkp);
3762         } else {
3763             if (c == 'q')
3764                 sell_response = 'n';
3765             if (container)
3766                 dropped_container(obj, shkp, FALSE);
3767             if (!obj->unpaid)
3768                 obj->no_charge = 1;
3769             subfrombill(obj, shkp);
3770         }
3771     } else {
3772         char qbuf[BUFSZ], qsfx[BUFSZ];
3773 #if 0 /*JP*/
3774         boolean short_funds = (offer > shkmoney), one;
3775 #else
3776         boolean short_funds = (offer > shkmoney);
3777 #endif
3778
3779         if (short_funds)
3780             offer = shkmoney;
3781         if (!sell_response) {
3782             long yourc = 0L, shksc;
3783
3784             if (container) {
3785                 /* number of items owned by shk */
3786                 shksc = count_contents(obj, TRUE, TRUE, FALSE);
3787                 /* number of items owned by you (total - shksc) */
3788                 yourc = count_contents(obj, TRUE, TRUE, TRUE) - shksc;
3789                 only_partially_your_contents = shksc && yourc;
3790             }
3791             /*
3792                "<shk> offers * for ..." query formatting.
3793                Normal item(s):
3794                 "... your <object>.  Sell it?"
3795                 "... your <objects>.  Sell them?"
3796                A container is either owned by the hero, or already
3797                owned by the shk (!ltmp), or the shk isn't interested
3798                in buying it (also !ltmp).  It's either empty (!cltmp)
3799                or it has contents owned by the hero or it has some
3800                contents owned by the hero and others by the shk.
3801                (The case where it has contents already entirely owned
3802                by the shk is treated the same was if it were empty
3803                since the hero isn't selling any of those contents.)
3804                Your container:
3805                 "... your <empty bag>.  Sell it?"
3806                 "... your <bag> and its contents.  Sell them?"
3807                 "... your <bag> and item inside.  Sell them?"
3808                 "... your <bag> and items inside.  Sell them?"
3809                Shk's container:
3810                 "... your item in the <bag>.  Sell it?"
3811                 "... your items in the <bag>.  Sell them?"
3812              */
3813 #if 0 /*JP*/
3814             Sprintf(qbuf, "%s offers%s %ld gold piece%s for %s%s ",
3815                     Shknam(shkp), short_funds ? " only" : "", offer,
3816                     plur(offer),
3817                     (cltmp && !ltmp)
3818                         ? ((yourc == 1L) ? "your item in " : "your items in ")
3819                         : "",
3820                     obj->unpaid ? "the" : "your");
3821             one = obj->unpaid ? (yourc == 1L) : (obj->quan == 1L && !cltmp);
3822             Sprintf(qsfx, "%s.  Sell %s?",
3823                     (cltmp && ltmp)
3824                         ? (only_partially_your_contents
3825                                ? ((yourc == 1L) ? " and item inside"
3826                                                 : " and items inside")
3827                                : and_its_contents)
3828                         : "",
3829                     one ? "it" : "them");
3830             (void) safe_qbuf(qbuf, qbuf, qsfx, obj, xname, simpleonames,
3831                              one ? "that" : "those");
3832 #else
3833             Sprintf(qbuf,
3834                     "%s\82Í\82 \82È\82½\82Ì", Monnam(shkp));
3835             Sprintf(qsfx,
3836                     "%s\82É%ld\82Ì\92l%s\81D\94\84\82è\82Ü\82·\82©\81H",
3837                     (!ltmp && cltmp) ? "\82Ì\92\86\90g" : "",
3838                     offer, 
3839                     short_funds ? "\82µ\82©\82Â\82¯\82È\82©\82Á\82½" : "\82ð\82Â\82¯\82½");
3840             (void) safe_qbuf(qbuf, qbuf, qsfx, obj, xname, simpleonames,
3841                              "\82»\82ê");
3842 #endif
3843         } else
3844             qbuf[0] = '\0'; /* just to pacify lint */
3845
3846         switch (sell_response ? sell_response : ynaq(qbuf)) {
3847         case 'q':
3848             sell_response = 'n';
3849             /*FALLTHRU*/
3850         case 'n':
3851             if (container)
3852                 dropped_container(obj, shkp, FALSE);
3853             if (!obj->unpaid)
3854                 obj->no_charge = 1;
3855             subfrombill(obj, shkp);
3856             break;
3857         case 'a':
3858             sell_response = 'y';
3859             /*FALLTHRU*/
3860         case 'y':
3861             if (container)
3862                 dropped_container(obj, shkp, TRUE);
3863             if (!obj->unpaid && !saleitem)
3864                 obj->no_charge = 1;
3865             subfrombill(obj, shkp);
3866             pay(-offer, shkp);
3867 #if 0 /*JP*/
3868             shk_names_obj(shkp, obj,
3869                           (sell_how != SELL_NORMAL)
3870                            ? ((!ltmp && cltmp && only_partially_your_contents)
3871                          ? "sold some items inside %s for %ld gold piece%s.%s"
3872                          : "sold %s for %ld gold piece%s.%s")
3873             : "relinquish %s and receive %ld gold piece%s in compensation.%s",
3874                           offer, "");
3875 #else
3876             shk_names_obj(shkp, obj,
3877                           (sell_how != SELL_NORMAL)
3878                            ? ((!ltmp && cltmp && only_partially_your_contents)
3879                          ? "%s\82Ì\92\86\90g\82ð\8bà\89Ý%ld\96\87\82Å\94\84\82Á\82½%s\81D%s"
3880                          : "%s\82ð\8bà\89Ý%ld\96\87\82Å\94\84\82Á\82½%s\81D%s")
3881             : "%s\82ð\93n\82µ\81C\8bà\89Ý%ld\96\87\82Ì\91ã\8f\9e\82ð\8eó\82¯\82Æ\82Á\82½%s\81D%s",
3882                           offer, "");
3883 #endif
3884             break;
3885         default:
3886             impossible("invalid sell response");
3887         }
3888     }
3889 }
3890
3891 int
3892 doinvbill(mode)
3893 int mode; /* 0: deliver count 1: paged */
3894 {
3895 #ifdef __SASC
3896     void sasc_bug(struct obj *, unsigned);
3897 #endif
3898     struct monst *shkp;
3899     struct eshk *eshkp;
3900     struct bill_x *bp, *end_bp;
3901     struct obj *obj;
3902     long totused;
3903     char *buf_p;
3904     winid datawin;
3905
3906     shkp = shop_keeper(*u.ushops);
3907     if (!shkp || !inhishop(shkp)) {
3908         if (mode != 0)
3909             impossible("doinvbill: no shopkeeper?");
3910         return 0;
3911     }
3912     eshkp = ESHK(shkp);
3913
3914     if (mode == 0) {
3915         /* count expended items, so that the `I' command can decide
3916            whether to include 'x' in its prompt string */
3917         int cnt = !eshkp->debit ? 0 : 1;
3918
3919         for (bp = eshkp->bill_p, end_bp = &eshkp->bill_p[eshkp->billct];
3920              bp < end_bp; bp++)
3921             if (bp->useup
3922                 || ((obj = bp_to_obj(bp)) != 0 && obj->quan < bp->bquan))
3923                 cnt++;
3924         return cnt;
3925     }
3926
3927     datawin = create_nhwindow(NHW_MENU);
3928 /*JP
3929     putstr(datawin, 0, "Unpaid articles already used up:");
3930 */
3931     putstr(datawin, 0, "\82·\82Å\82É\8eg\82Á\82Ä\82µ\82Ü\82Á\82½\96¢\95¥\82Ì\95i\96Ú\81F");
3932     putstr(datawin, 0, "");
3933
3934     totused = 0L;
3935     for (bp = eshkp->bill_p, end_bp = &eshkp->bill_p[eshkp->billct];
3936          bp < end_bp; bp++) {
3937         obj = bp_to_obj(bp);
3938         if (!obj) {
3939             impossible("Bad shopkeeper administration.");
3940             goto quit;
3941         }
3942         if (bp->useup || bp->bquan > obj->quan) {
3943             long oquan, uquan, thisused;
3944
3945             oquan = obj->quan;
3946             uquan = (bp->useup ? bp->bquan : bp->bquan - oquan);
3947             thisused = bp->price * uquan;
3948             totused += thisused;
3949             iflags.suppress_price++; /* suppress "(unpaid)" suffix */
3950             /* Why 'x'?  To match `I x', more or less. */
3951             buf_p = xprname(obj, (char *) 0, 'x', FALSE, thisused, uquan);
3952             iflags.suppress_price--;
3953             putstr(datawin, 0, buf_p);
3954         }
3955     }
3956     if (eshkp->debit) {
3957         /* additional shop debt which has no itemization available */
3958         if (totused)
3959             putstr(datawin, 0, "");
3960         totused += eshkp->debit;
3961 #if 0 /*JP*/
3962         buf_p = xprname((struct obj *) 0, "usage charges and/or other fees",
3963                         GOLD_SYM, FALSE, eshkp->debit, 0L);
3964 #else
3965         buf_p = xprname((struct obj *) 0, "\8eg\97p\97¿\82Ü\82½\82Í\91¼\82Ì\8eè\90\94\97¿",
3966                         GOLD_SYM, FALSE, eshkp->debit, 0L);
3967 #endif
3968         putstr(datawin, 0, buf_p);
3969     }
3970 /*JP
3971     buf_p = xprname((struct obj *) 0, "Total:", '*', FALSE, totused, 0L);
3972 */
3973     buf_p = xprname((struct obj *) 0, "\8d\87\8cv\81F", '*', FALSE, totused, 0L);
3974     putstr(datawin, 0, "");
3975     putstr(datawin, 0, buf_p);
3976     display_nhwindow(datawin, FALSE);
3977  quit:
3978     destroy_nhwindow(datawin);
3979     return 0;
3980 }
3981
3982 STATIC_OVL long
3983 getprice(obj, shk_buying)
3984 register struct obj *obj;
3985 boolean shk_buying;
3986 {
3987     register long tmp = (long) objects[obj->otyp].oc_cost;
3988
3989     if (obj->oartifact) {
3990         tmp = arti_cost(obj);
3991         if (shk_buying)
3992             tmp /= 4;
3993     }
3994     switch (obj->oclass) {
3995     case FOOD_CLASS:
3996         /* simpler hunger check, (2-4)*cost */
3997         if (u.uhs >= HUNGRY && !shk_buying)
3998             tmp *= (long) u.uhs;
3999         if (obj->oeaten)
4000             tmp = 0L;
4001         break;
4002     case WAND_CLASS:
4003         if (obj->spe == -1)
4004             tmp = 0L;
4005         break;
4006     case POTION_CLASS:
4007         if (obj->otyp == POT_WATER && !obj->blessed && !obj->cursed)
4008             tmp = 0L;
4009         break;
4010     case ARMOR_CLASS:
4011     case WEAPON_CLASS:
4012         if (obj->spe > 0)
4013             tmp += 10L * (long) obj->spe;
4014         break;
4015     case TOOL_CLASS:
4016         if (Is_candle(obj)
4017             && obj->age < 20L * (long) objects[obj->otyp].oc_cost)
4018             tmp /= 2L;
4019         break;
4020     }
4021     return tmp;
4022 }
4023
4024 /* shk catches thrown pick-axe */
4025 struct monst *
4026 shkcatch(obj, x, y)
4027 register struct obj *obj;
4028 register xchar x, y;
4029 {
4030     register struct monst *shkp;
4031
4032     if (!(shkp = shop_keeper(inside_shop(x, y))) || !inhishop(shkp))
4033         return 0;
4034
4035     if (shkp->mcanmove && !shkp->msleeping
4036         && (*u.ushops != ESHK(shkp)->shoproom || !inside_shop(u.ux, u.uy))
4037         && dist2(shkp->mx, shkp->my, x, y) < 3
4038         /* if it is the shk's pos, you hit and anger him */
4039         && (shkp->mx != x || shkp->my != y)) {
4040         if (mnearto(shkp, x, y, TRUE) == 2 && !Deaf && !muteshk(shkp))
4041 /*JP
4042             verbalize("Out of my way, scum!");
4043 */
4044             verbalize("\82Ç\82¯\81C\83N\83\\82Á\82½\82ê\81I");
4045         if (cansee(x, y)) {
4046 #if 0 /*JP:T*/
4047             pline("%s nimbly%s catches %s.", Shknam(shkp),
4048                   (x == shkp->mx && y == shkp->my) ? "" : " reaches over and",
4049                   the(xname(obj)));
4050 #else
4051             pline("%s\82Í\82·\82Î\82â\82­%s%s\82ð\82Â\82©\82Ü\82¦\82½\81D", Shknam(shkp),
4052                   (x == shkp->mx && y == shkp->my) ? "" : "\8bß\82Ã\82¢\82Ä",
4053                   xname(obj));
4054 #endif
4055             if (!canspotmon(shkp))
4056                 map_invisible(x, y);
4057             delay_output();
4058             mark_synch();
4059         }
4060         subfrombill(obj, shkp);
4061         (void) mpickobj(shkp, obj);
4062         return shkp;
4063     }
4064     return (struct monst *) 0;
4065 }
4066
4067 void
4068 add_damage(x, y, cost)
4069 register xchar x, y;
4070 long cost;
4071 {
4072     struct damage *tmp_dam;
4073     char *shops;
4074
4075     if (IS_DOOR(levl[x][y].typ)) {
4076         struct monst *mtmp;
4077
4078         /* Don't schedule for repair unless it's a real shop entrance */
4079         for (shops = in_rooms(x, y, SHOPBASE); *shops; shops++)
4080             if ((mtmp = shop_keeper(*shops)) != 0
4081                 && x == ESHK(mtmp)->shd.x && y == ESHK(mtmp)->shd.y)
4082                 break;
4083         if (!*shops)
4084             return;
4085     }
4086     for (tmp_dam = level.damagelist; tmp_dam; tmp_dam = tmp_dam->next)
4087         if (tmp_dam->place.x == x && tmp_dam->place.y == y) {
4088             tmp_dam->cost += cost;
4089             tmp_dam->when = monstermoves; /* needed by pay_for_damage() */
4090             return;
4091         }
4092     tmp_dam = (struct damage *) alloc((unsigned) sizeof *tmp_dam);
4093     (void) memset((genericptr_t) tmp_dam, 0, sizeof *tmp_dam);
4094     tmp_dam->when = monstermoves;
4095     tmp_dam->place.x = x;
4096     tmp_dam->place.y = y;
4097     tmp_dam->cost = cost;
4098     tmp_dam->typ = levl[x][y].typ;
4099     tmp_dam->next = level.damagelist;
4100     level.damagelist = tmp_dam;
4101     /* If player saw damage, display as a wall forever */
4102     if (cansee(x, y))
4103         levl[x][y].seenv = SVALL;
4104 }
4105
4106 /*
4107  * Do something about damage. Either (!croaked) try to repair it, or
4108  * (croaked) just discard damage structs for non-shared locations, since
4109  * they'll never get repaired. Assume that shared locations will get
4110  * repaired eventually by the other shopkeeper(s). This might be an erroneous
4111  * assumption (they might all be dead too), but we have no reasonable way of
4112  * telling that.
4113  */
4114 STATIC_OVL
4115 void
4116 remove_damage(shkp, croaked)
4117 struct monst *shkp;
4118 boolean croaked;
4119 {
4120     struct damage *tmp_dam, *tmp2_dam;
4121     struct obj *shk_inv = shkp->minvent;
4122     boolean did_repair = FALSE, saw_door = FALSE, saw_floor = FALSE,
4123             stop_picking = FALSE, doorway_trap = FALSE, skip_msg = FALSE;
4124     int saw_walls = 0, saw_untrap = 0, feedback;
4125     char trapmsg[BUFSZ];
4126
4127     feedback = !croaked; /* 1 => give feedback, 0 => don't or already did */
4128     tmp_dam = level.damagelist;
4129     tmp2_dam = 0;
4130     while (tmp_dam) {
4131         register xchar x = tmp_dam->place.x, y = tmp_dam->place.y;
4132         char shops[5];
4133         int disposition;
4134         unsigned old_doormask = 0;
4135
4136         disposition = 0;
4137         Strcpy(shops, in_rooms(x, y, SHOPBASE));
4138         if (index(shops, ESHK(shkp)->shoproom)) {
4139             if (IS_DOOR(levl[x][y].typ))
4140                 old_doormask = levl[x][y].doormask;
4141
4142             if (croaked) {
4143                 disposition = (shops[1]) ? 0 : 1;
4144             } else if (stop_picking) {
4145                 disposition = repair_damage(shkp, tmp_dam, &feedback, FALSE);
4146             } else {
4147                 /* Defer the stop_occupation() until after repair msgs */
4148                 if (closed_door(x, y))
4149                     stop_picking = picking_at(x, y);
4150                 disposition = repair_damage(shkp, tmp_dam, &feedback, FALSE);
4151                 if (!disposition)
4152                     stop_picking = FALSE;
4153             }
4154         }
4155
4156         if (!disposition) {
4157             tmp2_dam = tmp_dam;
4158             tmp_dam = tmp_dam->next;
4159             continue;
4160         }
4161
4162         if (disposition > 1) {
4163             did_repair = TRUE;
4164             if (cansee(x, y)) {
4165                 if (IS_WALL(levl[x][y].typ)) {
4166                     saw_walls++;
4167                 } else if (IS_DOOR(levl[x][y].typ)
4168                            /* an existing door here implies trap removal */
4169                            && !(old_doormask & (D_ISOPEN | D_CLOSED))) {
4170                     saw_door = TRUE;
4171                 } else if (disposition == 3) { /* untrapped */
4172                     saw_untrap++;
4173                     if (IS_DOOR(levl[x][y].typ))
4174                         doorway_trap = TRUE;
4175                 } else {
4176                     saw_floor = TRUE;
4177                 }
4178             }
4179         }
4180
4181         tmp_dam = tmp_dam->next;
4182         if (!tmp2_dam) {
4183             free((genericptr_t) level.damagelist);
4184             level.damagelist = tmp_dam;
4185         } else {
4186             free((genericptr_t) tmp2_dam->next);
4187             tmp2_dam->next = tmp_dam;
4188         }
4189     }
4190     if (!did_repair)
4191         return;
4192
4193     trapmsg[0] = '\0'; /* not just lint suppression... */
4194     shk_inv = (shkp->minvent != shk_inv) ? shkp->minvent : 0;
4195     if (saw_untrap == 1 && shk_inv
4196         && (shk_inv->otyp == BEARTRAP || shk_inv->otyp == LAND_MINE)
4197         && canseemon(shkp)) {
4198         pline("%s untraps %s.", Shknam(shkp), ansimpleoname(shk_inv));
4199         /* we've already reported this trap (and know it's the only one) */
4200         saw_untrap = 0;
4201         skip_msg = !(saw_walls || saw_door || saw_floor);
4202     } else if (saw_untrap) {
4203 #if 0 /*JP*/
4204         Sprintf(trapmsg, "%s trap%s",
4205                 (saw_untrap > 3) ? "several" : (saw_untrap > 1) ? "some"
4206                                                                 : "a",
4207                 plur(saw_untrap));
4208         Sprintf(eos(trapmsg), " %s", vtense(trapmsg, "are"));
4209         Sprintf(eos(trapmsg), " removed from the %s",
4210                 (doorway_trap && saw_untrap == 1) ? "doorway" : "floor");
4211 #else
4212         Sprintf(trapmsg, "%sã©\82ª%s\82©\82ç\8fÁ\82¦",
4213                 (saw_untrap > 3) ? "\82 \82¿\82±\82¿\82Ì" : (saw_untrap > 1) ? "\89½\83J\8f\8a\82Ì"
4214                                                                    : "",
4215                 (doorway_trap && saw_untrap == 1) ? "\94à" : "\8f°");
4216 #endif
4217     }
4218
4219     if (skip_msg) {
4220         ; /* already gave an untrap message which covered the only repair */
4221     } else if (saw_walls) {
4222 #if 0 /*JP*/
4223         char wallbuf[BUFSZ];
4224
4225         Sprintf(wallbuf, "section%s", plur(saw_walls));
4226         pline("Suddenly, %s %s of wall %s up!",
4227               (saw_walls == 1) ? "a" : (saw_walls <= 3) ? "some" : "several",
4228               wallbuf, vtense(wallbuf, "close"));
4229 #else
4230         pline("\93Ë\91R\81C\95Ç\82ª%s\95Â\82Ü\82Á\82½\81I",
4231               (saw_walls == 1) ? "" : (saw_walls <= 3) ? "\89½\89Ó\8f\8a\82©" : "\82 \82¿\82±\82¿\82Å");
4232 #endif
4233
4234         if (saw_door)
4235 /*JP
4236             pline_The("shop door reappears!");
4237 */
4238             pline("\93X\82Ì\94à\82ª\82Ü\82½\8c»\82í\82ê\82½\81I");
4239         if (saw_floor)
4240 /*JP
4241             pline_The("floor is repaired!");
4242 */
4243             pline("\8f°\82Í\8fC\95\9c\82³\82ê\82½\81I");
4244         if (saw_untrap)
4245 /*JP
4246             pline("%s!", upstart(trapmsg));
4247 */
4248             pline("%s\82½\81I", trapmsg);
4249     } else {
4250         if (saw_door || saw_floor || saw_untrap)
4251 #if 0 /*JP:T*/
4252             pline("Suddenly, %s%s%s%s%s!",
4253                   saw_door ? "the shop door reappears" : "",
4254                   (saw_door && saw_floor) ? " and " : "",
4255                   saw_floor ? "the floor damage is gone" : "",
4256                   ((saw_door || saw_floor) && *trapmsg) ? " and " : "",
4257                   trapmsg);
4258 #else
4259             pline("\93Ë\91R\81C%s%s%s%s%s\82½!",
4260                   saw_door ? "\93X\82Ì\94à\82ª\82Ü\82½\8c»\82í\82ê" : "",
4261                   (saw_door && saw_floor) ? "\81C" : "",
4262                   saw_floor ? "\8f°\82Ì\8f\9d\82ª\8fC\95\9c\82³\82ê" : "",
4263                   ((saw_door || saw_floor) && *trapmsg) ? "\81C" : "",
4264                   trapmsg);
4265 #endif
4266         /* FIXME:
4267          *  these messages aren't right if the unseen repairs were only
4268          *  for trap removal (except for hole and possibly trap door).
4269          */
4270         else if (inside_shop(u.ux, u.uy) == ESHK(shkp)->shoproom)
4271 /*JP
4272             You_feel("more claustrophobic than before.");
4273 */
4274             You("\91O\82æ\82è\95Â\8f\8a\8b°\95|\8fÇ\8bC\96¡\82É\82È\82Á\82½\81D");
4275         else if (!Deaf && !rn2(10))
4276 /*JP
4277             Norep("The dungeon acoustics noticeably change.");
4278 */
4279             Norep("\96À\8b{\82Ì\89¹\8b¿\82Í\82¢\82¿\82\82é\82µ\82­\95Ï\82Á\82½\81D");
4280     }
4281     if (stop_picking)
4282         stop_occupation();
4283 }
4284
4285 /*
4286  * 0: repair postponed, 1: silent repair (no messages), 2: normal repair
4287  * 3: untrap
4288  */
4289 int
4290 repair_damage(shkp, tmp_dam, once, catchup)
4291 struct monst *shkp;
4292 struct damage *tmp_dam;
4293 int *once;
4294 boolean catchup; /* restoring a level */
4295 {
4296     xchar x, y;
4297     xchar litter[9];
4298     struct monst *mtmp;
4299     struct obj *otmp;
4300     struct trap *ttmp;
4301     int i, k, ix, iy, disposition = 1;
4302
4303     if ((monstermoves - tmp_dam->when) < REPAIR_DELAY)
4304         return 0;
4305     if (shkp->msleeping || !shkp->mcanmove || ESHK(shkp)->following)
4306         return 0;
4307     x = tmp_dam->place.x;
4308     y = tmp_dam->place.y;
4309     if (!IS_ROOM(tmp_dam->typ)) {
4310         if ((x == u.ux && y == u.uy && !Passes_walls)
4311             || (x == shkp->mx && y == shkp->my)
4312             || ((mtmp = m_at(x, y)) != 0 && !passes_walls(mtmp->data)))
4313             return 0;
4314     }
4315     ttmp = t_at(x, y);
4316     if (ttmp && x == u.ux && y == u.uy && !Passes_walls)
4317         return 0;
4318
4319     if (once && *once) {
4320         boolean shk_closeby = (distu(shkp->mx, shkp->my)
4321                                <= (BOLT_LIM / 2) * (BOLT_LIM / 2));
4322
4323         /* this is suboptimal if we eventually give a "shk untraps"
4324            message for the only repair, but perhaps the shop repair
4325            incantation means that shk's untrap attempt will never fail */
4326         if (canseemon(shkp))
4327 #if 0 /*JP*/
4328             pline("%s whispers %s.", Shknam(shkp),
4329                   shk_closeby ? "an incantation" : "something");
4330 #else
4331             pline("%s\82Í%s\82ð\82³\82³\82â\82¢\82½\81D", Shknam(shkp),
4332                   shk_closeby ? "\8eô\95¶" : "\89½\82©");
4333 #endif
4334         else if (!Deaf && shk_closeby)
4335 /*JP
4336             You_hear("someone muttering an incantation.");
4337 */
4338             You_hear("\92N\82©\82ª\8eô\95\82ð\82Â\82Ô\82â\82¢\82Ä\82¢\82é\82Ì\82ð\95·\82¢\82½\81D");
4339         *once = 0;
4340     }
4341     if (ttmp) {
4342         if ((ttmp->ttyp == LANDMINE || ttmp->ttyp == BEAR_TRAP)
4343             && dist2(x, y, shkp->mx, shkp->my) <= 2) {
4344             /* convert to an object */
4345             otmp = mksobj((ttmp->ttyp == LANDMINE) ? LAND_MINE : BEARTRAP,
4346                           TRUE, FALSE);
4347             otmp->quan = 1L;
4348             otmp->owt = weight(otmp);
4349             (void) mpickobj(shkp, otmp);
4350         }
4351         deltrap(ttmp);
4352         if (cansee(x, y))
4353             newsym(x, y);
4354         if (!catchup)
4355             disposition = 3;
4356     }
4357     if (IS_ROOM(tmp_dam->typ)
4358         || (tmp_dam->typ == levl[x][y].typ
4359             && (!IS_DOOR(tmp_dam->typ) || levl[x][y].doormask > D_BROKEN)))
4360         /* no terrain fix necessary (trap removal or manually repaired) */
4361         return disposition;
4362
4363     /* door or wall repair; trap, if any, is now gone;
4364        restore original terrain type and move any items away */
4365     levl[x][y].typ = tmp_dam->typ;
4366     if (IS_DOOR(tmp_dam->typ))
4367         levl[x][y].doormask = D_CLOSED; /* arbitrary */
4368
4369     (void) memset((genericptr_t) litter, 0, sizeof litter);
4370 #define NEED_UPDATE 1
4371 #define OPEN 2
4372 #define INSHOP 4
4373 #define horiz(i) ((i % 3) - 1)
4374 #define vert(i) ((i / 3) - 1)
4375     k = 0; /* number of adjacent shop spots */
4376     if (level.objects[x][y] && !IS_ROOM(levl[x][y].typ)) {
4377         for (i = 0; i < 9; i++) {
4378             ix = x + horiz(i);
4379             iy = y + vert(i);
4380             if (i == 4 || !isok(ix, iy) || !ZAP_POS(levl[ix][iy].typ))
4381                 continue;
4382             litter[i] = OPEN;
4383             if (inside_shop(ix, iy) == ESHK(shkp)->shoproom) {
4384                 litter[i] |= INSHOP;
4385                 ++k;
4386             }
4387         }
4388     }
4389     /* placement below assumes there is always at least one adjacent
4390        spot; the 'k' check guards against getting stuck in an infinite
4391        loop if some irregularly shaped room breaks that assumption */
4392     if (k > 0) {
4393         /* Scatter objects haphazardly into the shop */
4394         if (Punished && !u.uswallow
4395             && ((uchain->ox == x && uchain->oy == y)
4396                 || (uball->ox == x && uball->oy == y))) {
4397             /*
4398              * Either the ball or chain is in the repair location.
4399              * Take the easy way out and put ball&chain under hero.
4400              *
4401              * FIXME: message should be reworded; this might be the
4402              * shop's doorway rather than a wall, there might be some
4403              * other stuff here which isn't junk, and "your junk" has
4404              * a slang connotation which could be applicable if hero
4405              * has Passes_walls ability.
4406              */
4407             if (!Deaf && !muteshk(shkp))
4408 /*JP
4409                 verbalize("Get your junk out of my wall!");
4410 */
4411                 verbalize("\82»\82Ì\83K\83\89\83N\83^\82ð\8aO\82É\8e\9d\82Á\82Ä\8ds\82«\82È\81I");
4412             unplacebc(); /* pick 'em up */
4413             placebc();   /* put 'em down */
4414         }
4415         while ((otmp = level.objects[x][y]) != 0)
4416             /* Don't mess w/ boulders -- just merge into wall */
4417             if (otmp->otyp == BOULDER || otmp->otyp == ROCK) {
4418                 obj_extract_self(otmp);
4419                 obfree(otmp, (struct obj *) 0);
4420             } else {
4421                 int trylimit = 50;
4422
4423                 /* otmp must be moved otherwise level.objects[x][y] will
4424                    never become Null and while-loop won't terminate */
4425                 do {
4426                     i = rn2(9);
4427                 } while (--trylimit && !(litter[i] & INSHOP));
4428                 if ((litter[i] & (OPEN | INSHOP)) != 0) {
4429                     ix = x + horiz(i);
4430                     iy = y + vert(i);
4431                 } else {
4432                     /* we know shk isn't at <x,y> because repair
4433                        is deferred in that situation */
4434                     ix = shkp->mx;
4435                     iy = shkp->my;
4436                 }
4437                 remove_object(otmp);
4438                 place_object(otmp, ix, iy);
4439                 litter[i] |= NEED_UPDATE;
4440             }
4441     }
4442     if (catchup)
4443         return 1; /* repair occurred while off level so no messages */
4444
4445     block_point(x, y);
4446     if (cansee(x, y)) {
4447         if (IS_WALL(tmp_dam->typ))
4448             /* player sees actual repair process, so KNOWS it's a wall */
4449             levl[x][y].seenv = SVALL;
4450         newsym(x, y);
4451     }
4452     for (i = 0; i < 9; i++)
4453         if (litter[i] & NEED_UPDATE)
4454             newsym(x + horiz(i), y + vert(i));
4455
4456     if (disposition < 3)
4457         disposition = 2;
4458     return disposition;
4459 #undef NEED_UPDATE
4460 #undef OPEN
4461 #undef INSHOP
4462 #undef vert
4463 #undef horiz
4464 }
4465
4466 /*
4467  * shk_move: return 1: moved  0: didn't  -1: let m_move do it  -2: died
4468  */
4469 int
4470 shk_move(shkp)
4471 struct monst *shkp;
4472 {
4473     xchar gx, gy, omx, omy;
4474     int udist;
4475     schar appr;
4476     struct eshk *eshkp = ESHK(shkp);
4477     int z;
4478     boolean uondoor = FALSE, satdoor, avoid = FALSE, badinv;
4479
4480     omx = shkp->mx;
4481     omy = shkp->my;
4482
4483     if (inhishop(shkp))
4484         remove_damage(shkp, FALSE);
4485
4486     if ((udist = distu(omx, omy)) < 3 && (shkp->data != &mons[PM_GRID_BUG]
4487                                           || (omx == u.ux || omy == u.uy))) {
4488         if (ANGRY(shkp) || (Conflict && !resist(shkp, RING_CLASS, 0, 0))) {
4489             if (Displaced)
4490 /*JP
4491                 Your("displaced image doesn't fool %s!", shkname(shkp));
4492 */
4493                 pline("%s\82Í\82 \82È\82½\82Ì\8c\89e\82É\82¾\82Ü\82³\82ê\82È\82©\82Á\82½\81I", shkname(shkp));
4494             (void) mattacku(shkp);
4495             return 0;
4496         }
4497         if (eshkp->following) {
4498             if (strncmp(eshkp->customer, plname, PL_NSIZ)) {
4499                 if (!Deaf && !muteshk(shkp))
4500 #if 0 /*JP:T*/
4501                     verbalize("%s, %s!  I was looking for %s.", Hello(shkp),
4502                               plname, eshkp->customer);
4503 #else
4504                     verbalize("%s\81I\82í\82½\82µ\82Í%s\82ð\92T\82µ\82Ä\82¢\82Ü\82·\81D", Hello(shkp),
4505                               eshkp->customer);
4506 #endif
4507                 eshkp->following = 0;
4508                 return 0;
4509             }
4510             if (moves > followmsg + 4) {
4511                 if (!Deaf && !muteshk(shkp))
4512 #if 0 /*JP:T*/
4513                     verbalize("%s, %s!  Didn't you forget to pay?",
4514                               Hello(shkp), plname);
4515 #else
4516                     verbalize("%s\81I\8ex\95¥\82¢\82ð\96Y\82ê\82Ä\82¢\82Ü\82¹\82ñ\82©\81H",
4517                               Hello(shkp));
4518 #endif
4519                 else
4520 #if 0 /*JP:T*/
4521                     pline("%s holds out %s upturned %s.",
4522                           Shknam(shkp), noit_mhis(shkp),
4523                           mbodypart(shkp, HAND));
4524 #else
4525                     pline("%s\82Í%s\82ð\8fã\82É\8cü\82¯\82Ä\8d·\82µ\8fo\82µ\82½\81D",
4526                           Shknam(shkp),
4527                           mbodypart(shkp, HAND));
4528 #endif
4529                 followmsg = moves;
4530                 if (!rn2(9)) {
4531 #if 0 /*JP:T*/
4532                     pline("%s doesn't like customers who don't pay.",
4533                           Shknam(shkp));
4534 #else
4535                     pline("%s\82Í\8bà\82ð\95¥\82í\82È\82¢\8bq\82ª\8c\99\82¢\82Ý\82½\82¢\82¾\81D",
4536                           Shknam(shkp));
4537 #endif
4538                     rile_shk(shkp);
4539                 }
4540             }
4541             if (udist < 2)
4542                 return 0;
4543         }
4544     }
4545
4546     appr = 1;
4547     gx = eshkp->shk.x;
4548     gy = eshkp->shk.y;
4549     satdoor = (gx == omx && gy == omy);
4550     if (eshkp->following || ((z = holetime()) >= 0 && z * z <= udist)) {
4551         /* [This distance check used to apply regardless of
4552             whether the shk was following, but that resulted in
4553             m_move() sometimes taking the shk out of the shop if
4554             the player had fenced him in with boulders or traps.
4555             Such voluntary abandonment left unpaid objects in
4556             invent, triggering billing impossibilities on the
4557             next level once the character fell through the hole.] */
4558         if (udist > 4 && eshkp->following && !eshkp->billct)
4559             return -1; /* leave it to m_move */
4560         gx = u.ux;
4561         gy = u.uy;
4562     } else if (ANGRY(shkp)) {
4563         /* Move towards the hero if the shopkeeper can see him. */
4564         if (shkp->mcansee && m_canseeu(shkp)) {
4565             gx = u.ux;
4566             gy = u.uy;
4567         }
4568         avoid = FALSE;
4569     } else {
4570 #define GDIST(x, y) (dist2(x, y, gx, gy))
4571         if (Invis || u.usteed) {
4572             avoid = FALSE;
4573         } else {
4574             uondoor = (u.ux == eshkp->shd.x && u.uy == eshkp->shd.y);
4575             if (uondoor) {
4576                 badinv =
4577                     (carrying(PICK_AXE) || carrying(DWARVISH_MATTOCK)
4578                      || (Fast && (sobj_at(PICK_AXE, u.ux, u.uy)
4579                                   || sobj_at(DWARVISH_MATTOCK, u.ux, u.uy))));
4580                 if (satdoor && badinv)
4581                     return 0;
4582                 avoid = !badinv;
4583             } else {
4584                 avoid = (*u.ushops && distu(gx, gy) > 8);
4585                 badinv = FALSE;
4586             }
4587
4588             if (((!eshkp->robbed && !eshkp->billct && !eshkp->debit) || avoid)
4589                 && GDIST(omx, omy) < 3) {
4590                 if (!badinv && !onlineu(omx, omy))
4591                     return 0;
4592                 if (satdoor)
4593                     appr = gx = gy = 0;
4594             }
4595         }
4596     }
4597
4598     z = move_special(shkp, inhishop(shkp), appr, uondoor, avoid, omx, omy, gx,
4599                      gy);
4600     if (z > 0)
4601         after_shk_move(shkp);
4602
4603     return z;
4604 }
4605
4606 /* called after shopkeeper moves, in case themove causes re-entry into shop */
4607 void
4608 after_shk_move(shkp)
4609 struct monst *shkp;
4610 {
4611     struct eshk *eshkp = ESHK(shkp);
4612
4613     if (eshkp->bill_p == (struct bill_x *) -1000 && inhishop(shkp)) {
4614         /* reset bill_p, need to re-calc player's occupancy too */
4615         eshkp->bill_p = &eshkp->bill[0];
4616         check_special_room(FALSE);
4617     }
4618 }
4619
4620 /* for use in levl_follower (mondata.c) */
4621 boolean
4622 is_fshk(mtmp)
4623 register struct monst *mtmp;
4624 {
4625     return (boolean) (mtmp->isshk && ESHK(mtmp)->following);
4626 }
4627
4628 /* You are digging in the shop. */
4629 void
4630 shopdig(fall)
4631 register int fall;
4632 {
4633     register struct monst *shkp = shop_keeper(*u.ushops);
4634     int lang;
4635 /*JP
4636     const char *grabs = "grabs";
4637 */
4638     const char *grabs = "\82Â\82©\82ñ\82¾";
4639
4640     if (!shkp)
4641         return;
4642
4643     /* 0 == can't speak, 1 == makes animal noises, 2 == speaks */
4644     lang = 0;
4645     if (shkp->msleeping || !shkp->mcanmove || is_silent(shkp->data))
4646         ; /* lang stays 0 */
4647     else if (shkp->data->msound <= MS_ANIMAL)
4648         lang = 1;
4649     else if (shkp->data->msound >= MS_HUMANOID)
4650         lang = 2;
4651
4652     if (!inhishop(shkp)) {
4653         if (Role_if(PM_KNIGHT)) {
4654 /*JP
4655             You_feel("like a common thief.");
4656 */
4657             You("\93D\96_\93¯\91R\82È\8bC\82ª\82µ\82½\81D");
4658             adjalign(-sgn(u.ualign.type));
4659         }
4660         return;
4661     }
4662
4663     if (!fall) {
4664         if (lang == 2) {
4665             if (!Deaf && !muteshk(shkp)) {
4666                 if (u.utraptype == TT_PIT)
4667 #if 0 /*JP*/
4668                     verbalize(
4669                         "Be careful, %s, or you might fall through the floor.",
4670                         flags.female ? "madam" : "sir");
4671 #else
4672                     verbalize(
4673                         "\92\8d\88Ó\82µ\82Ä\82­\82¾\82³\82¢%s\81C\8f°\82©\82ç\97\8e\82¿\82Ü\82·\82æ\81D",
4674                         flags.female ? "\82¨\8fì\82³\82ñ" : "\82¨\8bq\82³\82ñ");
4675 #endif
4676                 else
4677 #if 0 /*JP*/
4678                     verbalize("%s, do not damage the floor here!",
4679                         flags.female ? "Madam" : "Sir");
4680 #else
4681                     verbalize("%s\81C\8f°\82É\8f\9d\82ð\82Â\82¯\82È\82¢\82Å\82­\82¾\82³\82¢\81I",
4682                         flags.female ? "\82¨\8fì\82³\82ñ" : "\82¨\8bq\82³\82ñ");
4683 #endif
4684             }
4685         }
4686         if (Role_if(PM_KNIGHT)) {
4687 /*JP
4688             You_feel("like a common thief.");
4689 */
4690             You("\93D\96_\93¯\91R\82È\8bC\82ª\82µ\82½\81D");
4691             adjalign(-sgn(u.ualign.type));
4692         }
4693     } else if (!um_dist(shkp->mx, shkp->my, 5)
4694                && !shkp->msleeping && shkp->mcanmove
4695                && (ESHK(shkp)->billct || ESHK(shkp)->debit)) {
4696         register struct obj *obj, *obj2;
4697
4698         if (nolimbs(shkp->data)) {
4699 /*JP
4700             grabs = "knocks off";
4701 */
4702             grabs = "\92@\82«\97\8e\82µ\82½";
4703 #if 0
4704             /* This is what should happen, but for balance
4705              * reasons, it isn't currently.
4706              */
4707             if (lang == 2)
4708                 pline("%s curses %s inability to grab your backpack!",
4709                       Shknam(shkp), noit_mhim(shkp));
4710             rile_shk(shkp);
4711             return;
4712 #endif
4713         }
4714         if (distu(shkp->mx, shkp->my) > 2) {
4715             mnexto(shkp);
4716             /* for some reason the shopkeeper can't come next to you */
4717             if (distu(shkp->mx, shkp->my) > 2) {
4718                 if (lang == 2)
4719
4720 /*JP
4721                     pline("%s curses you in anger and frustration!",
4722 */
4723                     pline("\93{\82è\82Å\95s\96\9e\82Ì\82½\82Ü\82Á\82Ä\82¢\82é%s\82Í\82 \82È\82½\82ð\8eô\82Á\82½\81I",
4724                           Shknam(shkp));
4725                 else if (lang == 1)
4726                     growl(shkp);
4727                 rile_shk(shkp);
4728                 return;
4729             } else
4730 #if 0 /*JP:T*/
4731                 pline("%s %s, and %s your backpack!", Shknam(shkp),
4732                       makeplural(locomotion(shkp->data, "leap")), grabs);
4733 #else
4734                 pline("%s\82Í\94ò\82Ñ\82Â\82¢\82Ä\81C\82 \82È\82½\82Ì\94w\95\89\82¢\91Ü\82ð%s\81I", Shknam(shkp),
4735                       grabs);
4736 #endif
4737         } else
4738 /*JP
4739             pline("%s %s your backpack!", Shknam(shkp), grabs);
4740 */
4741             pline("%s\82Í\82 \82È\82½\82Ì\94w\95\89\82¢\91Ü\82ð%s\81I", Shknam(shkp), grabs);
4742
4743         for (obj = invent; obj; obj = obj2) {
4744             obj2 = obj->nobj;
4745             if ((obj->owornmask & ~(W_SWAPWEP | W_QUIVER)) != 0
4746                 || (obj == uswapwep && u.twoweap)
4747                 || (obj->otyp == LEASH && obj->leashmon))
4748                 continue;
4749             if (obj == current_wand)
4750                 continue;
4751             setnotworn(obj);
4752             freeinv(obj);
4753             subfrombill(obj, shkp);
4754             (void) add_to_minv(shkp, obj); /* may free obj */
4755         }
4756     }
4757 }
4758
4759 STATIC_OVL void
4760 makekops(mm)
4761 coord *mm;
4762 {
4763     static const short k_mndx[4] = { PM_KEYSTONE_KOP, PM_KOP_SERGEANT,
4764                                      PM_KOP_LIEUTENANT, PM_KOP_KAPTAIN };
4765     int k_cnt[4], cnt, mndx, k;
4766
4767     k_cnt[0] = cnt = abs(depth(&u.uz)) + rnd(5);
4768     k_cnt[1] = (cnt / 3) + 1; /* at least one sarge */
4769     k_cnt[2] = (cnt / 6);     /* maybe a lieutenant */
4770     k_cnt[3] = (cnt / 9);     /* and maybe a kaptain */
4771
4772     for (k = 0; k < 4; k++) {
4773         if ((cnt = k_cnt[k]) == 0)
4774             break;
4775         mndx = k_mndx[k];
4776         if (mvitals[mndx].mvflags & G_GONE)
4777             continue;
4778
4779         while (cnt--)
4780             if (enexto(mm, mm->x, mm->y, &mons[mndx]))
4781                 (void) makemon(&mons[mndx], mm->x, mm->y, NO_MM_FLAGS);
4782     }
4783 }
4784
4785 void
4786 pay_for_damage(dmgstr, cant_mollify)
4787 const char *dmgstr;
4788 boolean cant_mollify;
4789 {
4790     register struct monst *shkp = (struct monst *) 0;
4791     char shops_affected[5];
4792     boolean uinshp = (*u.ushops != '\0');
4793     char qbuf[80];
4794     xchar x, y;
4795 #if 0 /*JP*/
4796     boolean dugwall = (!strcmp(dmgstr, "dig into")    /* wand */
4797                        || !strcmp(dmgstr, "damage")); /* pick-axe */
4798 #else
4799     boolean ni_wo = !strcmp(dmgstr, "\8c\8a\82ð\82 \82¯\82é");              /* wand */
4800     boolean dugwall = (ni_wo || !strcmp(dmgstr, "\8f\9d\82Â\82¯\82é")); /* pick-axe */
4801 #endif
4802     boolean animal, pursue;
4803     struct damage *tmp_dam, *appear_here = 0;
4804     long cost_of_damage = 0L;
4805     unsigned int nearest_shk = (ROWNO * ROWNO) + (COLNO * COLNO),
4806                  nearest_damage = nearest_shk;
4807     int picks = 0;
4808
4809     for (tmp_dam = level.damagelist; tmp_dam; tmp_dam = tmp_dam->next) {
4810         char *shp;
4811
4812         if (tmp_dam->when != monstermoves || !tmp_dam->cost)
4813             continue;
4814         cost_of_damage += tmp_dam->cost;
4815         Strcpy(shops_affected,
4816                in_rooms(tmp_dam->place.x, tmp_dam->place.y, SHOPBASE));
4817         for (shp = shops_affected; *shp; shp++) {
4818             struct monst *tmp_shk;
4819             unsigned int shk_distance;
4820
4821             if (!(tmp_shk = shop_keeper(*shp)))
4822                 continue;
4823             if (tmp_shk == shkp) {
4824                 unsigned int damage_distance =
4825                     distu(tmp_dam->place.x, tmp_dam->place.y);
4826
4827                 if (damage_distance < nearest_damage) {
4828                     nearest_damage = damage_distance;
4829                     appear_here = tmp_dam;
4830                 }
4831                 continue;
4832             }
4833             if (!inhishop(tmp_shk))
4834                 continue;
4835             shk_distance = distu(tmp_shk->mx, tmp_shk->my);
4836             if (shk_distance > nearest_shk)
4837                 continue;
4838             if ((shk_distance == nearest_shk) && picks) {
4839                 if (rn2(++picks))
4840                     continue;
4841             } else
4842                 picks = 1;
4843             shkp = tmp_shk;
4844             nearest_shk = shk_distance;
4845             appear_here = tmp_dam;
4846             nearest_damage = distu(tmp_dam->place.x, tmp_dam->place.y);
4847         }
4848     }
4849
4850     if (!cost_of_damage || !shkp)
4851         return;
4852
4853     animal = (shkp->data->msound <= MS_ANIMAL);
4854     pursue = FALSE;
4855     x = appear_here->place.x;
4856     y = appear_here->place.y;
4857
4858     /* not the best introduction to the shk... */
4859     (void) strncpy(ESHK(shkp)->customer, plname, PL_NSIZ);
4860
4861     /* if the shk is already on the war path, be sure it's all out */
4862     if (ANGRY(shkp) || ESHK(shkp)->following) {
4863         hot_pursuit(shkp);
4864         return;
4865     }
4866
4867     /* if the shk is not in their shop.. */
4868     if (!*in_rooms(shkp->mx, shkp->my, SHOPBASE)) {
4869         if (!cansee(shkp->mx, shkp->my))
4870             return;
4871         pursue = TRUE;
4872         goto getcad;
4873     }
4874
4875     if (uinshp) {
4876         if (um_dist(shkp->mx, shkp->my, 1)
4877             && !um_dist(shkp->mx, shkp->my, 3)) {
4878 /*JP
4879             pline("%s leaps towards you!", Shknam(shkp));
4880 */
4881             pline("%s\82Í\82 \82È\82½\82É\94ò\82Ñ\82©\82©\82Á\82½\81I", Shknam(shkp));
4882             mnexto(shkp);
4883         }
4884         pursue = um_dist(shkp->mx, shkp->my, 1);
4885         if (pursue)
4886             goto getcad;
4887     } else {
4888         /*
4889          * Make shkp show up at the door.  Effect:  If there is a monster
4890          * in the doorway, have the hero hear the shopkeeper yell a bit,
4891          * pause, then have the shopkeeper appear at the door, having
4892          * yanked the hapless critter out of the way.
4893          */
4894         if (MON_AT(x, y)) {
4895             if (!animal) {
4896                 if (!Deaf && !muteshk(shkp)) {
4897 /*JP
4898                 You_hear("an angry voice:");
4899 */
4900                 You("\93{\82è\82Ì\90º\82ð\95·\82¢\82½\81F");
4901 /*JP
4902                 verbalize("Out of my way, scum!");
4903 */
4904                 verbalize("\82Ç\82¯\81I\83N\83\\82Á\82½\82ê\81I");
4905                 }
4906                 wait_synch();
4907 #if defined(UNIX) || defined(VMS)
4908 #if defined(SYSV) || defined(ULTRIX) || defined(VMS)
4909                 (void)
4910 #endif
4911                     sleep(1);
4912 #endif
4913             } else {
4914                 growl(shkp);
4915             }
4916         }
4917         (void) mnearto(shkp, x, y, TRUE);
4918     }
4919
4920     if ((um_dist(x, y, 1) && !uinshp) || cant_mollify
4921         || (money_cnt(invent) + ESHK(shkp)->credit) < cost_of_damage
4922         || !rn2(50)) {
4923  getcad:
4924         if (muteshk(shkp)) {
4925             if (animal && shkp->mcanmove && !shkp->msleeping)
4926                 yelp(shkp);
4927         } else if (pursue || uinshp || !um_dist(x, y, 1)) {
4928             if (!Deaf)
4929 #if 0 /*JP*/
4930                 verbalize("How dare you %s my %s?", dmgstr,
4931                           dugwall ? "shop" : "door");
4932 #else
4933                 verbalize("\82Ç\82¤\82µ\82Ä%s%s%s\82è\82µ\82½\82ñ\82¾\81H",
4934                           dugwall ? "\93X" : "\94à",
4935                           ni_wo ? "\82É" : "\82ð",
4936                           jpast(dmgstr));
4937 #endif
4938             else
4939 #if 0 /*JP:T*/
4940                 pline("%s is %s that you decided to %s %s %s!",
4941                       Shknam(shkp), angrytexts[rn2(SIZE(angrytexts))],
4942                       dmgstr, noit_mhis(shkp), dugwall ? "shop" : "door");
4943 #else
4944                 pline("%s\82Í\82 \82È\82½\82ª%s\82ð%s\82±\82Æ\82É\91Î\82µ\82Ä%s\81I",
4945                       Shknam(shkp),
4946                       dugwall ? "\93X" : "\94à", dmgstr,
4947                       angrytexts[rn2(SIZE(angrytexts))]);
4948 #endif
4949         } else {
4950             if (!Deaf) {
4951 /*JP
4952                 pline("%s shouts:", Shknam(shkp));
4953 */
4954                 pline("%s\82Í\82³\82¯\82ñ\82¾\81F", Shknam(shkp));
4955 #if 0 /*JP*/
4956                 verbalize("Who dared %s my %s?", dmgstr,
4957                           dugwall ? "shop" : "door");
4958 #else
4959                 verbalize("\92N\82ª%s%s%s\82è\82µ\82½\82ñ\82¾\82ë\82¤\81H",
4960                           dugwall ? "\93X" : "\94à",
4961                           ni_wo ? "\82É" : "\82ð",
4962                           jpast(dmgstr));
4963 #endif
4964             } else {
4965 #if 0 /*JP:T*/
4966                 pline("%s is %s that someone decided to %s %s %s!",
4967                       Shknam(shkp), angrytexts[rn2(SIZE(angrytexts))],
4968                       dmgstr, noit_mhis(shkp), dugwall ? "shop" : "door");
4969 #else
4970                 pline("%s\82Í\92N\82©\82ª%s\82ð%s\82±\82Æ\82É\91Î\82µ\82Ä%s\81I",
4971                       Shknam(shkp),
4972                       dugwall ? "\93X" : "\94à", dmgstr,
4973                       angrytexts[rn2(SIZE(angrytexts))]);
4974 #endif
4975             }
4976         }
4977         hot_pursuit(shkp);
4978         return;
4979     }
4980
4981     if (Invis)
4982 /*JP
4983         Your("invisibility does not fool %s!", shkname(shkp));
4984 */
4985         pline("%s\82Í\93§\96¾\82È\82 \82È\82½\82É\82¾\82Ü\82³\82ê\82È\82©\82Á\82½\81I", shkname(shkp));
4986 #if 0 /*JP*/
4987     Sprintf(qbuf, "%sYou did %ld %s worth of damage!%s  Pay?",
4988             !animal ? cad(TRUE) : "", cost_of_damage,
4989             currency(cost_of_damage), !animal ? "\"" : "");
4990 #else
4991     Sprintf(qbuf,"\81u\82¨\82¢\81I%ld%s\82Ì\91¹\8aQ\82¾\81I\81v\95¥\82¢\82Ü\82·\82©\81H",
4992             cost_of_damage, currency(cost_of_damage));
4993 #endif
4994     if (yn(qbuf) != 'n') {
4995         cost_of_damage = check_credit(cost_of_damage, shkp);
4996         if (cost_of_damage > 0L) {
4997             money2mon(shkp, cost_of_damage);
4998             context.botl = 1;
4999         }
5000 /*JP
5001         pline("Mollified, %s accepts your restitution.", shkname(shkp));
5002 */
5003         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));
5004         /* move shk back to his home loc */
5005         home_shk(shkp, FALSE);
5006         pacify_shk(shkp);
5007     } else {
5008         if (!animal) {
5009             if (!Deaf && !muteshk(shkp))
5010 /*JP
5011             verbalize("Oh, yes!  You'll pay!");
5012 */
5013             verbalize("\82³\82 \81C\95¥\82¤\82ñ\82¾\81I");
5014             else
5015 #if 0 /*JP*/
5016                 pline("%s lunges %s %s toward your %s!",
5017                       Shknam(shkp), noit_mhis(shkp),
5018                       mbodypart(shkp, HAND), body_part(NECK));
5019 #else
5020                 pline("%s\82Í%s\82ð\82 \82È\82½\82Ì%s\82É\93Ë\82«\8fo\82µ\82½\81I",
5021                       Shknam(shkp),
5022                       mbodypart(shkp, HAND),
5023                       body_part(NECK));
5024 #endif
5025         } else
5026             growl(shkp);
5027         hot_pursuit(shkp);
5028         adjalign(-sgn(u.ualign.type));
5029     }
5030 }
5031
5032 /* called in dokick.c when we kick an object that might be in a store */
5033 boolean
5034 costly_spot(x, y)
5035 register xchar x, y;
5036 {
5037     struct monst *shkp;
5038     struct eshk *eshkp;
5039
5040     if (!level.flags.has_shop)
5041         return FALSE;
5042     shkp = shop_keeper(*in_rooms(x, y, SHOPBASE));
5043     if (!shkp || !inhishop(shkp))
5044         return FALSE;
5045     eshkp = ESHK(shkp);
5046     return  (boolean) (inside_shop(x, y)
5047                        && !(x == eshkp->shk.x && y == eshkp->shk.y));
5048 }
5049
5050 /* called by dotalk(sounds.c) when #chatting; returns obj if location
5051    contains shop goods and shopkeeper is willing & able to speak */
5052 struct obj *
5053 shop_object(x, y)
5054 register xchar x, y;
5055 {
5056     register struct obj *otmp;
5057     register struct monst *shkp;
5058
5059     if (!(shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) || !inhishop(shkp))
5060         return (struct obj *) 0;
5061
5062     for (otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere)
5063         if (otmp->oclass != COIN_CLASS)
5064             break;
5065     /* note: otmp might have ->no_charge set, but that's ok */
5066     return (otmp && costly_spot(x, y)
5067             && NOTANGRY(shkp) && shkp->mcanmove && !shkp->msleeping)
5068                ? otmp
5069                : (struct obj *) 0;
5070 }
5071
5072 /* give price quotes for all objects linked to this one (ie, on this spot) */
5073 void
5074 price_quote(first_obj)
5075 register struct obj *first_obj;
5076 {
5077     register struct obj *otmp;
5078     char buf[BUFSZ], price[40];
5079     long cost = 0L;
5080     int cnt = 0;
5081     boolean contentsonly = FALSE;
5082     winid tmpwin;
5083     struct monst *shkp = shop_keeper(inside_shop(u.ux, u.uy));
5084
5085     tmpwin = create_nhwindow(NHW_MENU);
5086 /*JP
5087     putstr(tmpwin, 0, "Fine goods for sale:");
5088 */
5089     putstr(tmpwin, 0, "\94\84\82è\82É\82Å\82Ä\82¢\82é\82·\82Î\82ç\82µ\82¢\8f¤\95i\81F");
5090     putstr(tmpwin, 0, "");
5091     for (otmp = first_obj; otmp; otmp = otmp->nexthere) {
5092         if (otmp->oclass == COIN_CLASS)
5093             continue;
5094         cost = (otmp->no_charge || otmp == uball || otmp == uchain) ? 0L
5095                  : get_cost(otmp, shkp);
5096         contentsonly = !cost;
5097         if (Has_contents(otmp))
5098             cost += contained_cost(otmp, shkp, 0L, FALSE, FALSE);
5099         if (!cost) {
5100 /*JP
5101             Strcpy(price, "no charge");
5102 */
5103             Strcpy(price, "\96³\97¿");
5104             contentsonly = FALSE;
5105         } else {
5106 #if 0 /*JP*/
5107             Sprintf(price, "%ld %s%s", cost, currency(cost),
5108                     (otmp->quan) > 1L ? " each" : "");
5109 #else
5110             Sprintf(price, "%s%ld%s", 
5111                     otmp->quan > 1L ? "\82»\82ê\82¼\82ê" : "", cost, currency(cost));
5112 #endif
5113         }
5114 #if 0 /*JP*/
5115         Sprintf(buf, "%s%s, %s", contentsonly ? the_contents_of : "",
5116                 doname(otmp), price);
5117 #else
5118         Sprintf(buf, "%s%s\81C%s", doname(otmp),
5119                 contentsonly ? "\82Ì\92\86\90g" : "", price);
5120 #endif
5121         putstr(tmpwin, 0, buf), cnt++;
5122     }
5123     if (cnt > 1) {
5124         display_nhwindow(tmpwin, TRUE);
5125     } else if (cnt == 1) {
5126         if (!cost) {
5127             /* "<doname(obj)>, no charge" */
5128 #if 0 /*JP*/
5129             pline("%s!", upstart(buf)); /* buf still contains the string */
5130 #else
5131             pline("%s\81I", buf); /* buf still contains the string */
5132 #endif
5133         } else {
5134             /* print cost in slightly different format, so can't reuse buf;
5135                cost and contentsonly are already set up */
5136 #if 0 /*JP*/
5137             Sprintf(buf, "%s%s", contentsonly ? the_contents_of : "",
5138                     doname(first_obj));
5139 #else
5140             Sprintf(buf, "%s%s", doname(first_obj),
5141                     contentsonly ? "\82Ì\92\86\90g" : "");
5142 #endif
5143 #if 0 /*JP*/
5144             pline("%s, price %ld %s%s%s", upstart(buf), cost, currency(cost),
5145                   (first_obj->quan > 1L) ? " each" : "",
5146                   contentsonly ? "." : shk_embellish(first_obj, cost));
5147 #else
5148             pline("%s%s\82Í%s%ld%s\82¾\81D", 
5149                   shk_embellish(first_obj, cost), buf,
5150                   first_obj->quan > 1L ? "\82»\82ê\82¼\82ê" : "",
5151                   cost, currency(cost));
5152 #endif
5153         }
5154     }
5155     destroy_nhwindow(tmpwin);
5156 }
5157
5158 /*JP
5159  \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
5160  \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
5161  */
5162 STATIC_OVL const char *
5163 shk_embellish(itm, cost)
5164 register struct obj *itm;
5165 long cost;
5166 {
5167     if (!rn2(3)) {
5168         register int o, choice = rn2(5);
5169
5170         if (choice == 0)
5171             choice = (cost < 100L ? 1 : cost < 500L ? 2 : 3);
5172         switch (choice) {
5173         case 4:
5174             if (cost < 10L)
5175                 break;
5176             else
5177                 o = itm->oclass;
5178             if (o == FOOD_CLASS)
5179 /*JP
5180                 return ", gourmets' delight!";
5181 */
5182                 return "\83O\83\8b\83\81\82ª\8b\83\82¢\82Ä\8aì\82Ô";
5183             if (objects[itm->otyp].oc_name_known
5184                     ? objects[itm->otyp].oc_magic
5185                     : (o == AMULET_CLASS || o == RING_CLASS || o == WAND_CLASS
5186                        || o == POTION_CLASS || o == SCROLL_CLASS
5187                        || o == SPBOOK_CLASS))
5188 /*JP
5189                 return ", painstakingly developed!";
5190 */
5191                 return "\88ê\8b\89\82Ì\96\82\97Í\82ð\94é\82ß\82½";
5192 /*JP
5193             return ", superb craftsmanship!";
5194 */
5195             return "\88ê\97¬\90E\90l\82Ì\8dì\82Á\82½";
5196         case 3:
5197 /*JP
5198             return ", finest quality.";
5199 */
5200             return "\8dÅ\8d\82\82Ì\95i\8e¿\82ð\8cÖ\82é";
5201         case 2:
5202 /*JP
5203             return ", an excellent choice.";
5204 */
5205             return "\82³\82·\82ª\82¨\8bq\82³\82ñ\96Ú\82ª\8d\82\82¢\81I";
5206         case 1:
5207 /*JP
5208             return ", a real bargain.";
5209 */
5210             return "\96{\93ú\82Ì\96Ú\8bÊ\8f¤\95i\81I";
5211         default:
5212             break;
5213         }
5214     } else if (itm->oartifact) {
5215 /*JP
5216         return ", one of a kind!";
5217 */
5218         return "\82±\82ê\82Í\90¢\8aE\82É\82Ü\82½\82Æ\82È\82¢\81I";
5219     }
5220 /*JP
5221     return ".";
5222 */
5223     return "";
5224 }
5225
5226 /* First 4 supplied by Ronen and Tamar, remainder by development team */
5227 const char *Izchak_speaks[] = {
5228 /*JP
5229     "%s says: 'These shopping malls give me a headache.'",
5230 */
5231     "%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",
5232 /*JP
5233     "%s says: 'Slow down.  Think clearly.'",
5234 */
5235     "%s\9eH\82­\81w\97\8e\82¿\92\85\82¢\82Ä\81C\96¾\9dð\82É\8dl\82¦\82æ\81D\81x",
5236 /*JP
5237     "%s says: 'You need to take things one at a time.'",
5238 */
5239     "%s\9eH\82­\81w\88ê\93x\82É\88ê\8cÂ\82¸\82Â\8eæ\82é\95K\97v\82ª\82 \82é\81D\81x",
5240 /*JP
5241     "%s says: 'I don't like poofy coffee... give me Columbian Supremo.'",
5242 */
5243     "%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",
5244 /*JP
5245     "%s says that getting the devteam's agreement on anything is difficult.",
5246 */
5247     "\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",
5248 /*JP
5249     "%s says that he has noticed those who serve their deity will prosper.",
5250 */
5251     "%s\82Í\90_\82É\8ed\82¦\82Ä\82¢\82é\82â\82Â\82Í\90¬\8c÷\82µ\82Ä\82¢\82é\82Æ\8fq\82×\82½\81D",
5252 /*JP
5253     "%s says: 'Don't try to steal from me - I have friends in high places!'",
5254 */
5255     "%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",
5256 /*JP
5257     "%s says: 'You may well need something from this shop in the future.'",
5258 */
5259     "%s\9eH\82­\81w\8f«\97\88\82±\82Ì\93X\82Ì\89½\82©\82ª\95K\97v\82Æ\82È\82é\82¾\82ë\82¤\81x",
5260 /*JP
5261     "%s comments about the Valley of the Dead as being a gateway."
5262 */
5263     "%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"
5264 };
5265
5266 void
5267 shk_chat(shkp)
5268 struct monst *shkp;
5269 {
5270     struct eshk *eshk;
5271     long shkmoney;
5272
5273     if (!shkp->isshk) {
5274         /* The monster type is shopkeeper, but this monster is
5275            not actually a shk, which could happen if someone
5276            wishes for a shopkeeper statue and then animates it.
5277            (Note: shkname() would be "" in a case like this.) */
5278 #if 0 /*JP*/
5279         pline("%s asks whether you've seen any untended shops recently.",
5280 #else
5281         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",
5282 #endif
5283               Monnam(shkp));
5284         /* [Perhaps we ought to check whether this conversation
5285            is taking place inside an untended shop, but a shopless
5286            shk can probably be expected to be rather disoriented.] */
5287         return;
5288     }
5289
5290     eshk = ESHK(shkp);
5291     if (ANGRY(shkp)) {
5292 #if 0 /*JP:T*/
5293         pline("%s %s how much %s dislikes %s customers.",
5294               Shknam(shkp),
5295               (!Deaf && !muteshk(shkp)) ? "mentions" : "indicates",
5296               noit_mhe(shkp), eshk->robbed ? "non-paying" : "rude");
5297 #else
5298         pline("%s\82Í%s\8bq\82Í\91å\8c\99\82¢\82¾\82Æ%s\81D",
5299               Shknam(shkp),
5300               eshk->robbed ? "\8bà\82ð\8ex\95¥\82í\82È\82¢" : "\96³\97ç\82È",
5301               (!Deaf && !muteshk(shkp)) ? "\8c¾\82Á\82½" : "\8e¦\82µ\82½");
5302 #endif
5303     } else if (eshk->following) {
5304         if (strncmp(eshk->customer, plname, PL_NSIZ)) {
5305             if (!Deaf && !muteshk(shkp))
5306 #if 0 /*JP:T*/
5307                 verbalize("%s %s!  I was looking for %s.",
5308                       Hello(shkp), plname, eshk->customer);
5309 #else
5310                 verbalize("%s\81I\8e\84\82Í%s\82ð\92T\82µ\82Ä\82¢\82Ü\82·\81D",
5311                       Hello(shkp), eshk->customer);
5312 #endif
5313             eshk->following = 0;
5314         } else {
5315             if (!Deaf && !muteshk(shkp))
5316 #if 0 /*JP:T*/
5317                 verbalize("%s %s!  Didn't you forget to pay?",
5318                           Hello(shkp), plname);
5319 #else
5320                 verbalize("%s\81I\8ex\95¥\82¢\82ð\96Y\82ê\82Ä\82¢\82Ü\82¹\82ñ\82©\81H", 
5321                           Hello(shkp));
5322 #endif
5323             else
5324 #if 0 /*JP*/
5325                 pline("%s taps you on the %s.",
5326                       Shknam(shkp), body_part(ARM));
5327 #else
5328                 pline("%s\82Í\82 \82È\82½\82Ì%s\82ð\8cy\82­\82½\82½\82¢\82½\81D",
5329                       Shknam(shkp), body_part(ARM));
5330 #endif
5331         }
5332     } else if (eshk->billct) {
5333         register long total = addupbill(shkp) + eshk->debit;
5334
5335 #if 0 /*JP:T*/
5336         pline("%s %s that your bill comes to %ld %s.",
5337               Shknam(shkp),
5338               (!Deaf && !muteshk(shkp)) ? "says" : "indicates",
5339               total, currency(total));
5340 #else
5341         pline("%s\82Í\8a¨\92è\82ª%ld%s\82É\82È\82é\82Æ%s\81D",
5342               Shknam(shkp),
5343               total, currency(total),
5344               (!Deaf && !muteshk(shkp)) ? "\8c¾\82Á\82½" : "\8e¦\82µ\82½");
5345 #endif
5346     } else if (eshk->debit) {
5347 #if 0 /*JP*/
5348         pline("%s %s that you owe %s %ld %s.",
5349               Shknam(shkp),
5350               (!Deaf && !muteshk(shkp)) ? "reminds you" : "indicates",
5351               noit_mhim(shkp), eshk->debit, currency(eshk->debit));
5352 #else
5353         pline("\82 \82È\82½\82Í%s\82É%ld%s\82Ì\8eØ\82è\82ª\82 \82é\82±\82Æ\82ð\8ev\82¢\82¾\82µ\82½\81D",
5354               Shknam(shkp), eshk->debit, currency(eshk->debit));
5355 #endif
5356     } else if (eshk->credit) {
5357 #if 0 /*JP:T*/
5358         pline("%s encourages you to use your %ld %s of credit.",
5359               Shknam(shkp), eshk->credit, currency(eshk->credit));
5360 #else
5361         pline("%s\82Í%ld%s\82Ì\97a\82¯\8bà\82ð\8eg\82¤\82æ\82¤\8a©\82ß\82½\81D",
5362               Shknam(shkp), eshk->credit, currency(eshk->credit));
5363 #endif
5364     } else if (eshk->robbed) {
5365 #if 0 /*JP:T*/
5366         pline("%s %s about a recent robbery.",
5367               Shknam(shkp),
5368               (!Deaf && !muteshk(shkp)) ? "complains" : "indicates concern");
5369 #else
5370         pline("%s\82Í\8dÅ\8bß\82Ì\8b­\93\90\82É\82Â\82¢\82Ä%s\81D",
5371               Shknam(shkp),
5372               (!Deaf && !muteshk(shkp)) ? "\8bð\92s\82ð\82±\82Ú\82µ\82½" : "\8c\9c\94O\82ð\8e¦\82µ\82½");
5373 #endif
5374     } else if ((shkmoney = money_cnt(shkp->minvent)) < 50L) {
5375 #if 0 /*JP*/
5376         pline("%s %s that business is bad.",
5377               Shknam(shkp),
5378               (!Deaf && !muteshk(shkp)) ? "complains" : "indicates");
5379 #else
5380         pline("%s\82Í\8f¤\94\84\82ª\8e|\82­\82¢\82Á\82Ä\82È\82¢\82Æ%s\81D",
5381               Shknam(shkp),
5382               (!Deaf && !muteshk(shkp)) ? "\8bð\92s\82ð\82±\82Ú\82µ\82½" : "\8e¦\82µ\82½");
5383 #endif
5384     } else if (shkmoney > 4000) {
5385 #if 0 /*JP:T*/
5386         pline("%s %s that business is good.",
5387               Shknam(shkp),
5388               (!Deaf && !muteshk(shkp)) ? "says" : "indicates");
5389 #else
5390         pline("%s\82Í\8f¤\94\84\82ª\8e|\82­\82¢\82Á\82Ä\82¢\82é\82Æ%s\81D",
5391               Shknam(shkp),
5392               (!Deaf && !muteshk(shkp)) ? "\8c¾\82Á\82½" : "\8e¦\82µ\82½");
5393 #endif
5394     } else if (is_izchak(shkp, FALSE)) {
5395         if (!Deaf && !muteshk(shkp))
5396             pline(Izchak_speaks[rn2(SIZE(Izchak_speaks))], shkname(shkp));
5397     } else {
5398         if (!Deaf && !muteshk(shkp))
5399 /*JP
5400             pline("%s talks about the problem of shoplifters.", Shknam(shkp));
5401 */
5402             pline("%s\82Í\96\9c\88ø\82Ì\96â\91è\82É\82Â\82¢\82Ä\98b\82µ\82½\81D", Shknam(shkp));
5403     }
5404 }
5405
5406 STATIC_OVL void
5407 kops_gone(silent)
5408 boolean silent;
5409 {
5410     register int cnt = 0;
5411     register struct monst *mtmp, *mtmp2;
5412
5413     for (mtmp = fmon; mtmp; mtmp = mtmp2) {
5414         mtmp2 = mtmp->nmon;
5415         if (mtmp->data->mlet == S_KOP) {
5416             if (canspotmon(mtmp))
5417                 cnt++;
5418             mongone(mtmp);
5419         }
5420     }
5421     if (cnt && !silent)
5422 #if 0 /*JP*/
5423         pline_The("Kop%s (disappointed) vanish%s into thin air.",
5424                   plur(cnt), (cnt == 1) ? "es" : "");
5425 #else
5426         pline("\8cx\8a¯\82Í(\82ª\82Á\82©\82è\82µ\82Ä)\8ep\82ð\8fÁ\82µ\82½\81D");
5427 #endif
5428 }
5429
5430 STATIC_OVL long
5431 cost_per_charge(shkp, otmp, altusage)
5432 struct monst *shkp;
5433 struct obj *otmp;
5434 boolean altusage; /* some items have an "alternate" use with different cost */
5435 {
5436     long tmp = 0L;
5437
5438     if (!shkp || !inhishop(shkp))
5439         return 0L; /* insurance */
5440     tmp = get_cost(otmp, shkp);
5441
5442     /* The idea is to make the exhaustive use of an unpaid item
5443      * more expensive than buying it outright.
5444      */
5445     if (otmp->otyp == MAGIC_LAMP) { /* 1 */
5446         /* normal use (ie, as light source) of a magic lamp never
5447            degrades its value, but not charging anything would make
5448            identification too easy; charge an amount comparable to
5449            what is charged for an ordinary lamp (don't bother with
5450            angry shk surcharge) */
5451         if (!altusage)
5452             tmp = (long) objects[OIL_LAMP].oc_cost;
5453         else
5454             tmp += tmp / 3L;                 /* djinni is being released */
5455     } else if (otmp->otyp == MAGIC_MARKER) { /* 70 - 100 */
5456         /* No way to determine in advance how many charges will be
5457          * wasted.  So, arbitrarily, one half of the price per use.
5458          */
5459         tmp /= 2L;
5460     } else if (otmp->otyp == BAG_OF_TRICKS /* 1 - 20 */
5461                || otmp->otyp == HORN_OF_PLENTY) {
5462         /* altusage: emptying of all the contents at once */
5463         if (!altusage)
5464             tmp /= 5L;
5465     } else if (otmp->otyp == CRYSTAL_BALL               /* 1 - 5 */
5466                || otmp->otyp == OIL_LAMP                /* 1 - 10 */
5467                || otmp->otyp == BRASS_LANTERN
5468                || (otmp->otyp >= MAGIC_FLUTE
5469                    && otmp->otyp <= DRUM_OF_EARTHQUAKE) /* 5 - 9 */
5470                || otmp->oclass == WAND_CLASS) {         /* 3 - 11 */
5471         if (otmp->spe > 1)
5472             tmp /= 4L;
5473     } else if (otmp->oclass == SPBOOK_CLASS) {
5474         tmp -= tmp / 5L;
5475     } else if (otmp->otyp == CAN_OF_GREASE || otmp->otyp == TINNING_KIT
5476                || otmp->otyp == EXPENSIVE_CAMERA) {
5477         tmp /= 10L;
5478     } else if (otmp->otyp == POT_OIL) {
5479         tmp /= 5L;
5480     }
5481     return tmp;
5482 }
5483
5484 /* Charge the player for partial use of an unpaid object.
5485  *
5486  * Note that bill_dummy_object() should be used instead
5487  * when an object is completely used.
5488  */
5489 void
5490 check_unpaid_usage(otmp, altusage)
5491 struct obj *otmp;
5492 boolean altusage;
5493 {
5494     struct monst *shkp;
5495     const char *fmt, *arg1, *arg2;
5496     char buf[BUFSZ];
5497     long tmp;
5498
5499     if (!otmp->unpaid || !*u.ushops
5500         || (otmp->spe <= 0 && objects[otmp->otyp].oc_charged))
5501         return;
5502     if (!(shkp = shop_keeper(*u.ushops)) || !inhishop(shkp))
5503         return;
5504     if ((tmp = cost_per_charge(shkp, otmp, altusage)) == 0L)
5505         return;
5506
5507     arg1 = arg2 = "";
5508     if (otmp->oclass == SPBOOK_CLASS) {
5509 /*JP
5510         fmt = "%sYou owe%s %ld %s.";
5511 */
5512         fmt = "%s%s%ld%s\82Ì\8eØ\82è\82¾\81D";
5513 /*JP
5514         Sprintf(buf, "This is no free library, %s!  ", cad(FALSE));
5515 */
5516         Strcpy(buf, "\82¨\82¢\81I\82±\82±\82Í\90}\8f\91\8aÙ\82\82á\82È\82¢\81I");
5517         arg1 = rn2(2) ? buf : "";
5518 /*JP
5519         arg2 = ESHK(shkp)->debit > 0L ? " an additional" : "";
5520 */
5521         arg2 = ESHK(shkp)->debit > 0L ? "\82³\82ç\82É\8c¾\82¦\82Î" : "";
5522     } else if (otmp->otyp == POT_OIL) {
5523 /*JP
5524         fmt = "%s%sThat will cost you %ld %s (Yendorian Fuel Tax).";
5525 */
5526         fmt = "%s%s\92l\92i\82Í%ld%s(\83C\83F\83\93\83_\81[\94R\97¿\90Å)\82¾\81D";
5527     } else if (altusage && (otmp->otyp == BAG_OF_TRICKS
5528                             || otmp->otyp == HORN_OF_PLENTY)) {
5529 /*JP
5530         fmt = "%s%sEmptying that will cost you %ld %s.";
5531 */
5532         fmt = "%s%s\82»\82ê\82Ì\8eg\97p\97¿\82Í%ld%s\82¾\81D";
5533         if (!rn2(3))
5534 /*JP
5535             arg1 = "Whoa!  ";
5536 */
5537             arg1 = "\82¤\82í\81I";
5538         if (!rn2(3))
5539 /*JP
5540             arg1 = "Watch it!  ";
5541 */
5542             arg1 = "\8bC\82ð\82Â\82¯\82ë\81I";
5543     } else {
5544 /*JP
5545         fmt = "%s%sUsage fee, %ld %s.";
5546 */
5547         fmt = "%s%s\8eg\97p\97¿\82Í\81C%ld%s\82¾\81D";
5548         if (!rn2(3))
5549 /*JP
5550             arg1 = "Hey!  ";
5551 */
5552             arg1 = "\82¨\82¢\81I";
5553         if (!rn2(3))
5554 /*JP
5555             arg2 = "Ahem.  ";
5556 */
5557             arg2 = "\83S\83z\83\93\81D";
5558     }
5559
5560     if (!Deaf && !muteshk(shkp)) {
5561         verbalize(fmt, arg1, arg2, tmp, currency(tmp));
5562         exercise(A_WIS, TRUE); /* you just got info */
5563     }
5564     ESHK(shkp)->debit += tmp;
5565 }
5566
5567 /* for using charges of unpaid objects "used in the normal manner" */
5568 void
5569 check_unpaid(otmp)
5570 struct obj *otmp;
5571 {
5572     check_unpaid_usage(otmp, FALSE); /* normal item use */
5573 }
5574
5575 void
5576 costly_gold(x, y, amount)
5577 register xchar x, y;
5578 register long amount;
5579 {
5580     register long delta;
5581     register struct monst *shkp;
5582     register struct eshk *eshkp;
5583
5584     if (!costly_spot(x, y))
5585         return;
5586     /* shkp now guaranteed to exist by costly_spot() */
5587     shkp = shop_keeper(*in_rooms(x, y, SHOPBASE));
5588
5589     eshkp = ESHK(shkp);
5590     if (eshkp->credit >= amount) {
5591         if (eshkp->credit > amount)
5592 /*JP
5593             Your("credit is reduced by %ld %s.", amount, currency(amount));
5594 */
5595             Your("\97a\82¯\8bà\82Í%ld%s\8c¸\82Á\82½\81D", amount, currency(amount));
5596         else
5597 /*JP
5598             Your("credit is erased.");
5599 */
5600             Your("\97a\82¯\8bà\82Í\92 \8fÁ\82µ\82É\82È\82Á\82½\81D");
5601         eshkp->credit -= amount;
5602     } else {
5603         delta = amount - eshkp->credit;
5604         if (eshkp->credit)
5605 /*JP
5606             Your("credit is erased.");
5607 */
5608             Your("\97a\82¯\8bà\82Í\92 \8fÁ\82µ\82É\82È\82Á\82½\81D");
5609         if (eshkp->debit)
5610 /*JP
5611             Your("debt increases by %ld %s.", delta, currency(delta));
5612 */
5613             Your("\8eØ\8bà\82Í%ld%s\91\9d\82¦\82½\81D", delta, currency(delta));
5614         else
5615 /*JP
5616             You("owe %s %ld %s.", shkname(shkp), delta, currency(delta));
5617 */
5618             You("%s\82É%ld%s\82Ì\8eØ\82è\82ð\82Â\82­\82Á\82½\81D", shkname(shkp), delta, currency(delta));
5619         eshkp->debit += delta;
5620         eshkp->loan += delta;
5621         eshkp->credit = 0L;
5622     }
5623 }
5624
5625 /* used in domove to block diagonal shop-exit */
5626 /* x,y should always be a door */
5627 boolean
5628 block_door(x, y)
5629 register xchar x, y;
5630 {
5631     register int roomno = *in_rooms(x, y, SHOPBASE);
5632     register struct monst *shkp;
5633
5634     if (roomno < 0 || !IS_SHOP(roomno))
5635         return FALSE;
5636     if (!IS_DOOR(levl[x][y].typ))
5637         return FALSE;
5638     if (roomno != *u.ushops)
5639         return FALSE;
5640
5641     if (!(shkp = shop_keeper((char) roomno)) || !inhishop(shkp))
5642         return FALSE;
5643
5644     if (shkp->mx == ESHK(shkp)->shk.x && shkp->my == ESHK(shkp)->shk.y
5645         /* Actually, the shk should be made to block _any_
5646          * door, including a door the player digs, if the
5647          * shk is within a 'jumping' distance.
5648          */
5649         && ESHK(shkp)->shd.x == x
5650         && ESHK(shkp)->shd.y == y
5651         && shkp->mcanmove && !shkp->msleeping
5652         && (ESHK(shkp)->debit || ESHK(shkp)->billct || ESHK(shkp)->robbed)) {
5653 #if 0 /*JP*/
5654         pline("%s%s blocks your way!", Shknam(shkp),
5655               Invis ? " senses your motion and" : "");
5656 #else
5657         pline("%s\82Í%s\82 \82È\82½\82Ì\91O\82É\97§\82¿\82Ó\82³\82ª\82Á\82½\81I", Shknam(shkp),
5658               Invis ? "\93®\82«\82ð\8a´\82\82Æ\82è\81C" : "");
5659 #endif
5660         return TRUE;
5661     }
5662     return FALSE;
5663 }
5664
5665 /* used in domove to block diagonal shop-entry;
5666    u.ux, u.uy should always be a door */
5667 boolean
5668 block_entry(x, y)
5669 register xchar x, y;
5670 {
5671     register xchar sx, sy;
5672     register int roomno;
5673     register struct monst *shkp;
5674
5675     if (!(IS_DOOR(levl[u.ux][u.uy].typ)
5676           && levl[u.ux][u.uy].doormask == D_BROKEN))
5677         return FALSE;
5678
5679     roomno = *in_rooms(x, y, SHOPBASE);
5680     if (roomno < 0 || !IS_SHOP(roomno))
5681         return FALSE;
5682     if (!(shkp = shop_keeper((char) roomno)) || !inhishop(shkp))
5683         return FALSE;
5684
5685     if (ESHK(shkp)->shd.x != u.ux || ESHK(shkp)->shd.y != u.uy)
5686         return FALSE;
5687
5688     sx = ESHK(shkp)->shk.x;
5689     sy = ESHK(shkp)->shk.y;
5690
5691     if (shkp->mx == sx && shkp->my == sy && shkp->mcanmove && !shkp->msleeping
5692         && (x == sx - 1 || x == sx + 1 || y == sy - 1 || y == sy + 1)
5693         && (Invis || carrying(PICK_AXE) || carrying(DWARVISH_MATTOCK)
5694             || u.usteed)) {
5695 #if 0 /*JP:T*/
5696         pline("%s%s blocks your way!", Shknam(shkp),
5697               Invis ? " senses your motion and" : "");
5698 #else
5699         pline("%s%s\82 \82È\82½\82Ì\91O\82É\97§\82¿\82Ó\82³\82ª\82Á\82½\81I", Shknam(shkp),
5700               Invis ? "\93®\82«\82ð\8a´\82\82Æ\82è\81C" : "");
5701 #endif
5702         return TRUE;
5703     }
5704     return FALSE;
5705 }
5706
5707 /* "your " or "Foobar's " (note the trailing space) */
5708 /* \81u\82 \82È\82½\82Ì\81v\82©\81uFoobar\82Ì\81v(\96\96\94ö\82É\8bó\94\92\82Í\95s\97v) */
5709 char *
5710 shk_your(buf, obj)
5711 char *buf;
5712 struct obj *obj;
5713 {
5714     if (!shk_owns(buf, obj) && !mon_owns(buf, obj))
5715         Strcpy(buf, the_your[carried(obj) ? 1 : 0]);
5716 /*JP
5717     return strcat(buf, " ");
5718 */
5719     return buf;
5720 }
5721
5722 char *
5723 Shk_Your(buf, obj)
5724 char *buf;
5725 struct obj *obj;
5726 {
5727     (void) shk_your(buf, obj);
5728 #if 0 /*JP*/
5729     *buf = highc(*buf);
5730 #endif
5731     return buf;
5732 }
5733
5734 STATIC_OVL char *
5735 shk_owns(buf, obj)
5736 char *buf;
5737 struct obj *obj;
5738 {
5739     struct monst *shkp;
5740     xchar x, y;
5741
5742     if (get_obj_location(obj, &x, &y, 0)
5743         && (obj->unpaid || (obj->where == OBJ_FLOOR && !obj->no_charge
5744                             && costly_spot(x, y)))) {
5745         shkp = shop_keeper(inside_shop(x, y));
5746 #if 0 /*JP*/
5747         return strcpy(buf, shkp ? s_suffix(shkname(shkp)) : the_your[0]);
5748 #else
5749         if (shkp) {
5750             strcpy(buf, shkname(shkp));
5751             strcat(buf, "\82Ì");
5752         } else {
5753             strcpy(buf, "");
5754         }
5755         return buf;
5756 #endif
5757     }
5758     return (char *) 0;
5759 }
5760
5761 STATIC_OVL char *
5762 mon_owns(buf, obj)
5763 char *buf;
5764 struct obj *obj;
5765 {
5766     if (obj->where == OBJ_MINVENT)
5767 #if 0 /*JP*/
5768         return strcpy(buf, s_suffix(y_monnam(obj->ocarry)));
5769 #else
5770         {
5771             strcpy(buf, mon_nam(obj->ocarry));
5772             strcat(buf, "\82Ì");
5773             return buf;
5774         }
5775 #endif
5776     return (char *) 0;
5777 }
5778
5779 #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¢*/
5780 STATIC_OVL const char *
5781 cad(altusage)
5782 boolean altusage; /* used as a verbalized exclamation:  \"Cad! ...\" */
5783 {
5784     const char *res = 0;
5785
5786     switch (is_demon(youmonst.data) ? 3 : poly_gender()) {
5787     case 0:
5788         res = "cad";
5789         break;
5790     case 1:
5791         res = "minx";
5792         break;
5793     case 2:
5794         res = "beast";
5795         break;
5796     case 3:
5797         res = "fiend";
5798         break;
5799     default:
5800         impossible("cad: unknown gender");
5801         res = "thing";
5802         break;
5803     }
5804     if (altusage) {
5805         char *cadbuf = mon_nam(&youmonst); /* snag an output buffer */
5806
5807         /* alternate usage adds a leading double quote and trailing
5808            exclamation point plus sentence separating spaces */
5809         Sprintf(cadbuf, "\"%s!  ", res);
5810         cadbuf[1] = highc(cadbuf[1]);
5811         res = cadbuf;
5812     }
5813     return res;
5814 }
5815 #endif /*JP*/
5816
5817 #ifdef __SASC
5818 void
5819 sasc_bug(struct obj *op, unsigned x)
5820 {
5821     op->unpaid = x;
5822 }
5823 #endif
5824
5825 /*shk.c*/