OSDN Git Service

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