OSDN Git Service

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