OSDN Git Service

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