OSDN Git Service

fix #36223
[jnethack/source.git] / src / invent.c
1 /* NetHack 3.6  invent.c        $NHDT-Date: 1447576348 2015/11/15 08:32:28 $  $NHDT-Branch: master $:$NHDT-Revision: 1.179 $ */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /* NetHack may be freely redistributed.  See license for details. */
4
5 /* JNetHack Copyright */
6 /* (c) Issei Numata, Naoki Hamada, Shigehiro Miyashita, 1994-2000  */
7 /* For 3.4-, Copyright (c) SHIRAKATA Kentaro, 2002-2016            */
8 /* JNetHack may be freely redistributed.  See license for details. */
9
10 #include "hack.h"
11
12 #define NOINVSYM '#'
13 #define CONTAINED_SYM '>' /* designator for inside a container */
14
15 STATIC_DCL int FDECL(CFDECLSPEC sortloot_cmp, (struct obj *, struct obj *));
16 STATIC_DCL void NDECL(reorder_invent);
17 STATIC_DCL boolean FDECL(mergable, (struct obj *, struct obj *));
18 STATIC_DCL void FDECL(noarmor, (BOOLEAN_P));
19 STATIC_DCL void FDECL(invdisp_nothing, (const char *, const char *));
20 STATIC_DCL boolean FDECL(worn_wield_only, (struct obj *));
21 STATIC_DCL boolean FDECL(only_here, (struct obj *));
22 STATIC_DCL void FDECL(compactify, (char *));
23 STATIC_DCL boolean FDECL(splittable, (struct obj *));
24 STATIC_DCL boolean FDECL(taking_off, (const char *));
25 STATIC_DCL boolean FDECL(putting_on, (const char *));
26 STATIC_PTR int FDECL(ckunpaid, (struct obj *));
27 STATIC_PTR int FDECL(ckvalidcat, (struct obj *));
28 STATIC_PTR char *FDECL(safeq_xprname, (struct obj *));
29 STATIC_PTR char *FDECL(safeq_shortxprname, (struct obj *));
30 STATIC_DCL char FDECL(display_pickinv, (const char *, BOOLEAN_P, long *));
31 STATIC_DCL char FDECL(display_used_invlets, (CHAR_P));
32 STATIC_DCL void FDECL(tally_BUCX,
33                       (struct obj *, int *, int *, int *, int *, int *));
34 STATIC_DCL boolean FDECL(this_type_only, (struct obj *));
35 STATIC_DCL void NDECL(dounpaid);
36 STATIC_DCL struct obj *FDECL(find_unpaid, (struct obj *, struct obj **));
37 STATIC_DCL void FDECL(menu_identify, (int));
38 STATIC_DCL boolean FDECL(tool_in_use, (struct obj *));
39 STATIC_DCL char FDECL(obj_to_let, (struct obj *));
40
41 static int lastinvnr = 51; /* 0 ... 51 (never saved&restored) */
42
43 /* wizards can wish for venom, which will become an invisible inventory
44  * item without this.  putting it in inv_order would mean venom would
45  * suddenly become a choice for all the inventory-class commands, which
46  * would probably cause mass confusion.  the test for inventory venom
47  * is only WIZARD and not wizard because the wizard can leave venom lying
48  * around on a bones level for normal players to find.  [Note to the
49  * confused:  'WIZARD' used to be a compile-time conditional so this was
50  * guarded by #ifdef WIZARD/.../#endif.]
51  */
52 static char venom_inv[] = { VENOM_CLASS, 0 }; /* (constant) */
53
54 STATIC_OVL int CFDECLSPEC
55 sortloot_cmp(obj1, obj2)
56 struct obj *obj1;
57 struct obj *obj2;
58 {
59     int val1 = 0;
60     int val2 = 0;
61
62     /* Sort object names in lexicographical order, ignoring quantity. */
63     int name_cmp = strcmpi(cxname_singular(obj1), cxname_singular(obj2));
64
65     if (name_cmp != 0) {
66         return name_cmp;
67     }
68
69     /* Sort by BUC. Map blessed to 4, uncursed to 2, cursed to 1, and unknown
70      * to 0. */
71     val1 = obj1->bknown
72                ? (obj1->blessed << 2)
73                      + ((!obj1->blessed && !obj1->cursed) << 1) + obj1->cursed
74                : 0;
75     val2 = obj2->bknown
76                ? (obj2->blessed << 2)
77                      + ((!obj2->blessed && !obj2->cursed) << 1) + obj2->cursed
78                : 0;
79     if (val1 != val2) {
80         return val2 - val1; /* Because bigger is better. */
81     }
82
83     /* Sort by greasing. This will put the objects in degreasing order. */
84     val1 = obj1->greased;
85     val2 = obj2->greased;
86     if (val1 != val2) {
87         return val2 - val1; /* Because bigger is better. */
88     }
89
90     /* Sort by erosion. The effective amount is what matters. */
91     val1 = greatest_erosion(obj1);
92     val2 = greatest_erosion(obj2);
93     if (val1 != val2) {
94         return val1 - val2; /* Because bigger is WORSE. */
95     }
96
97     /* Sort by erodeproofing. Map known-invulnerable to 1, and both
98      * known-vulnerable and unknown-vulnerability to 0, because that's how
99      * they're displayed. */
100     val1 = obj1->rknown && obj1->oerodeproof;
101     val2 = obj2->rknown && obj2->oerodeproof;
102     if (val1 != val2) {
103         return val2 - val1; /* Because bigger is better. */
104     }
105
106     /* Sort by enchantment. Map unknown to -1000, which is comfortably below
107      * the range of ->spe. */
108     val1 = obj1->known ? obj1->spe : -1000;
109     val2 = obj2->known ? obj2->spe : -1000;
110     if (val1 != val2) {
111         return val2 - val1; /* Because bigger is better. */
112     }
113
114     /* They're identical, as far as we're concerned,
115        but we want to force a determistic order between them. */
116     return (obj1->o_id > obj2->o_id) ? 1 : -1;
117 }
118
119 struct obj **
120 objarr_init(n)
121 int n;
122 {
123     return (struct obj **) alloc(n * sizeof(struct obj *));
124 }
125
126 void
127 objarr_set(otmp, idx, oarray, dosort)
128 struct obj *otmp;
129 int idx;
130 struct obj **oarray;
131 boolean dosort;
132 {
133     if (dosort) {
134         int j;
135         for (j = idx; j; j--) {
136             if (sortloot_cmp(otmp, oarray[j - 1]) > 0)
137                 break;
138             oarray[j] = oarray[j - 1];
139         }
140         oarray[j] = otmp;
141     } else {
142         oarray[idx] = otmp;
143     }
144 }
145
146 void
147 assigninvlet(otmp)
148 register struct obj *otmp;
149 {
150     boolean inuse[52];
151     register int i;
152     register struct obj *obj;
153
154     /* there should be at most one of these in inventory... */
155     if (otmp->oclass == COIN_CLASS) {
156         otmp->invlet = GOLD_SYM;
157         return;
158     }
159
160     for (i = 0; i < 52; i++)
161         inuse[i] = FALSE;
162     for (obj = invent; obj; obj = obj->nobj)
163         if (obj != otmp) {
164             i = obj->invlet;
165             if ('a' <= i && i <= 'z')
166                 inuse[i - 'a'] = TRUE;
167             else if ('A' <= i && i <= 'Z')
168                 inuse[i - 'A' + 26] = TRUE;
169             if (i == otmp->invlet)
170                 otmp->invlet = 0;
171         }
172     if ((i = otmp->invlet)
173         && (('a' <= i && i <= 'z') || ('A' <= i && i <= 'Z')))
174         return;
175     for (i = lastinvnr + 1; i != lastinvnr; i++) {
176         if (i == 52) {
177             i = -1;
178             continue;
179         }
180         if (!inuse[i])
181             break;
182     }
183     otmp->invlet =
184         (inuse[i] ? NOINVSYM : (i < 26) ? ('a' + i) : ('A' + i - 26));
185     lastinvnr = i;
186 }
187
188 /* note: assumes ASCII; toggling a bit puts lowercase in front of uppercase */
189 #define inv_rank(o) ((o)->invlet ^ 040)
190
191 /* sort the inventory; used by addinv() and doorganize() */
192 STATIC_OVL void
193 reorder_invent()
194 {
195     struct obj *otmp, *prev, *next;
196     boolean need_more_sorting;
197
198     do {
199         /*
200          * We expect at most one item to be out of order, so this
201          * isn't nearly as inefficient as it may first appear.
202          */
203         need_more_sorting = FALSE;
204         for (otmp = invent, prev = 0; otmp;) {
205             next = otmp->nobj;
206             if (next && inv_rank(next) < inv_rank(otmp)) {
207                 need_more_sorting = TRUE;
208                 if (prev)
209                     prev->nobj = next;
210                 else
211                     invent = next;
212                 otmp->nobj = next->nobj;
213                 next->nobj = otmp;
214                 prev = next;
215             } else {
216                 prev = otmp;
217                 otmp = next;
218             }
219         }
220     } while (need_more_sorting);
221 }
222
223 #undef inv_rank
224
225 /* scan a list of objects to see whether another object will merge with
226    one of them; used in pickup.c when all 52 inventory slots are in use,
227    to figure out whether another object could still be picked up */
228 struct obj *
229 merge_choice(objlist, obj)
230 struct obj *objlist, *obj;
231 {
232     struct monst *shkp;
233     int save_nocharge;
234
235     if (obj->otyp == SCR_SCARE_MONSTER) /* punt on these */
236         return (struct obj *) 0;
237     /* if this is an item on the shop floor, the attributes it will
238        have when carried are different from what they are now; prevent
239        that from eliciting an incorrect result from mergable() */
240     save_nocharge = obj->no_charge;
241     if (objlist == invent && obj->where == OBJ_FLOOR
242         && (shkp = shop_keeper(inside_shop(obj->ox, obj->oy))) != 0) {
243         if (obj->no_charge)
244             obj->no_charge = 0;
245         /* A billable object won't have its `unpaid' bit set, so would
246            erroneously seem to be a candidate to merge with a similar
247            ordinary object.  That's no good, because once it's really
248            picked up, it won't merge after all.  It might merge with
249            another unpaid object, but we can't check that here (depends
250            too much upon shk's bill) and if it doesn't merge it would
251            end up in the '#' overflow inventory slot, so reject it now. */
252         else if (inhishop(shkp))
253             return (struct obj *) 0;
254     }
255     while (objlist) {
256         if (mergable(objlist, obj))
257             break;
258         objlist = objlist->nobj;
259     }
260     obj->no_charge = save_nocharge;
261     return objlist;
262 }
263
264 /* merge obj with otmp and delete obj if types agree */
265 int
266 merged(potmp, pobj)
267 struct obj **potmp, **pobj;
268 {
269     register struct obj *otmp = *potmp, *obj = *pobj;
270
271     if (mergable(otmp, obj)) {
272         /* Approximate age: we do it this way because if we were to
273          * do it "accurately" (merge only when ages are identical)
274          * we'd wind up never merging any corpses.
275          * otmp->age = otmp->age*(1-proportion) + obj->age*proportion;
276          *
277          * Don't do the age manipulation if lit.  We would need
278          * to stop the burn on both items, then merge the age,
279          * then restart the burn.
280          */
281         if (!obj->lamplit)
282             otmp->age = ((otmp->age * otmp->quan) + (obj->age * obj->quan))
283                         / (otmp->quan + obj->quan);
284
285         otmp->quan += obj->quan;
286         /* temporary special case for gold objects!!!! */
287         if (otmp->oclass == COIN_CLASS)
288             otmp->owt = weight(otmp);
289         /* and puddings!!!1!!one! */
290         else if (!Is_pudding(otmp))
291             otmp->owt += obj->owt;
292         if (!has_oname(otmp) && has_oname(obj))
293             otmp = *potmp = oname(otmp, ONAME(obj));
294         obj_extract_self(obj);
295
296         /* really should merge the timeouts */
297         if (obj->lamplit)
298             obj_merge_light_sources(obj, otmp);
299         if (obj->timed)
300             obj_stop_timers(obj); /* follows lights */
301
302         /* fixup for `#adjust' merging wielded darts, daggers, &c */
303         if (obj->owornmask && carried(otmp)) {
304             long wmask = otmp->owornmask | obj->owornmask;
305
306             /* Both the items might be worn in competing slots;
307                merger preference (regardless of which is which):
308              primary weapon + alternate weapon -> primary weapon;
309              primary weapon + quiver -> primary weapon;
310              alternate weapon + quiver -> alternate weapon.
311                (Prior to 3.3.0, it was not possible for the two
312                stacks to be worn in different slots and `obj'
313                didn't need to be unworn when merging.) */
314             if (wmask & W_WEP)
315                 wmask = W_WEP;
316             else if (wmask & W_SWAPWEP)
317                 wmask = W_SWAPWEP;
318             else if (wmask & W_QUIVER)
319                 wmask = W_QUIVER;
320             else {
321                 impossible("merging strangely worn items (%lx)", wmask);
322                 wmask = otmp->owornmask;
323             }
324             if ((otmp->owornmask & ~wmask) != 0L)
325                 setnotworn(otmp);
326             setworn(otmp, wmask);
327             setnotworn(obj);
328 #if 0
329         /* (this should not be necessary, since items
330             already in a monster's inventory don't ever get
331             merged into other objects [only vice versa]) */
332         } else if (obj->owornmask && mcarried(otmp)) {
333             if (obj == MON_WEP(otmp->ocarry)) {
334                 MON_WEP(otmp->ocarry) = otmp;
335                 otmp->owornmask = W_WEP;
336             }
337 #endif /*0*/
338         }
339
340         /* handle puddings a bit differently; absorption will
341          * free the other object automatically so we can just
342          * return out from here.  */
343         if (Is_pudding(obj)) {
344             pudding_merge_message(otmp, obj);
345             obj_absorb(potmp, pobj);
346             return 1;
347         }
348
349         obfree(obj, otmp); /* free(obj), bill->otmp */
350         return 1;
351     }
352     return 0;
353 }
354
355 /*
356  * Adjust hero intrinsics as if this object was being added to the hero's
357  * inventory.  Called _before_ the object has been added to the hero's
358  * inventory.
359  *
360  * This is called when adding objects to the hero's inventory normally (via
361  * addinv) or when an object in the hero's inventory has been polymorphed
362  * in-place.
363  *
364  * It may be valid to merge this code with with addinv_core2().
365  */
366 void
367 addinv_core1(obj)
368 struct obj *obj;
369 {
370     if (obj->oclass == COIN_CLASS) {
371         context.botl = 1;
372     } else if (obj->otyp == AMULET_OF_YENDOR) {
373         if (u.uhave.amulet)
374             impossible("already have amulet?");
375         u.uhave.amulet = 1;
376         u.uachieve.amulet = 1;
377     } else if (obj->otyp == CANDELABRUM_OF_INVOCATION) {
378         if (u.uhave.menorah)
379             impossible("already have candelabrum?");
380         u.uhave.menorah = 1;
381         u.uachieve.menorah = 1;
382     } else if (obj->otyp == BELL_OF_OPENING) {
383         if (u.uhave.bell)
384             impossible("already have silver bell?");
385         u.uhave.bell = 1;
386         u.uachieve.bell = 1;
387     } else if (obj->otyp == SPE_BOOK_OF_THE_DEAD) {
388         if (u.uhave.book)
389             impossible("already have the book?");
390         u.uhave.book = 1;
391         u.uachieve.book = 1;
392     } else if (obj->oartifact) {
393         if (is_quest_artifact(obj)) {
394             if (u.uhave.questart)
395                 impossible("already have quest artifact?");
396             u.uhave.questart = 1;
397             artitouch(obj);
398         }
399         set_artifact_intrinsic(obj, 1, W_ART);
400     }
401     if (obj->otyp == LUCKSTONE && obj->record_achieve_special) {
402         u.uachieve.mines_luckstone = 1;
403         obj->record_achieve_special = 0;
404     } else if ((obj->otyp == AMULET_OF_REFLECTION
405                 || obj->otyp == BAG_OF_HOLDING)
406                && obj->record_achieve_special) {
407         u.uachieve.finish_sokoban = 1;
408         obj->record_achieve_special = 0;
409     }
410 }
411
412 /*
413  * Adjust hero intrinsics as if this object was being added to the hero's
414  * inventory.  Called _after_ the object has been added to the hero's
415  * inventory.
416  *
417  * This is called when adding objects to the hero's inventory normally (via
418  * addinv) or when an object in the hero's inventory has been polymorphed
419  * in-place.
420  */
421 void
422 addinv_core2(obj)
423 struct obj *obj;
424 {
425     if (confers_luck(obj)) {
426         /* new luckstone must be in inventory by this point
427          * for correct calculation */
428         set_moreluck();
429     }
430 }
431
432 /*
433  * Add obj to the hero's inventory.  Make sure the object is "free".
434  * Adjust hero attributes as necessary.
435  */
436 struct obj *
437 addinv(obj)
438 struct obj *obj;
439 {
440     struct obj *otmp, *prev;
441     int saved_otyp = (int) obj->otyp; /* for panic */
442
443     if (obj->where != OBJ_FREE)
444         panic("addinv: obj not free");
445     /* normally addtobill() clears no_charge when items in a shop are
446        picked up, but won't do so if the shop has become untended */
447     obj->no_charge = 0; /* should not be set in hero's invent */
448     if (Has_contents(obj))
449         picked_container(obj); /* clear no_charge */
450     obj->was_thrown = 0;       /* not meaningful for invent */
451
452     addinv_core1(obj);
453
454     /* merge with quiver in preference to any other inventory slot
455        in case quiver and wielded weapon are both eligible; adding
456        extra to quivered stack is more useful than to wielded one */
457     if (uquiver && merged(&uquiver, &obj)) {
458         obj = uquiver;
459         if (!obj)
460             panic("addinv: null obj after quiver merge otyp=%d", saved_otyp);
461         goto added;
462     }
463     /* merge if possible; find end of chain in the process */
464     for (prev = 0, otmp = invent; otmp; prev = otmp, otmp = otmp->nobj)
465         if (merged(&otmp, &obj)) {
466             obj = otmp;
467             if (!obj)
468                 panic("addinv: null obj after merge otyp=%d", saved_otyp);
469             goto added;
470         }
471     /* didn't merge, so insert into chain */
472     assigninvlet(obj);
473     if (flags.invlet_constant || !prev) {
474         obj->nobj = invent; /* insert at beginning */
475         invent = obj;
476         if (flags.invlet_constant)
477             reorder_invent();
478     } else {
479         prev->nobj = obj; /* insert at end */
480         obj->nobj = 0;
481     }
482     obj->where = OBJ_INVENT;
483
484 added:
485     addinv_core2(obj);
486     carry_obj_effects(obj); /* carrying affects the obj */
487     update_inventory();
488     return obj;
489 }
490
491 /*
492  * Some objects are affected by being carried.
493  * Make those adjustments here. Called _after_ the object
494  * has been added to the hero's or monster's inventory,
495  * and after hero's intrinsics have been updated.
496  */
497 void
498 carry_obj_effects(obj)
499 struct obj *obj;
500 {
501     /* Cursed figurines can spontaneously transform
502        when carried. */
503     if (obj->otyp == FIGURINE) {
504         if (obj->cursed && obj->corpsenm != NON_PM
505             && !dead_species(obj->corpsenm, TRUE)) {
506             attach_fig_transform_timeout(obj);
507         }
508     }
509 }
510
511 /* Add an item to the inventory unless we're fumbling or it refuses to be
512  * held (via touch_artifact), and give a message.
513  * If there aren't any free inventory slots, we'll drop it instead.
514  * If both success and failure messages are NULL, then we're just doing the
515  * fumbling/slot-limit checking for a silent grab.  In any case,
516  * touch_artifact will print its own messages if they are warranted.
517  */
518 struct obj *
519 hold_another_object(obj, drop_fmt, drop_arg, hold_msg)
520 struct obj *obj;
521 const char *drop_fmt, *drop_arg, *hold_msg;
522 {
523     char buf[BUFSZ];
524
525     if (!Blind)
526         obj->dknown = 1; /* maximize mergibility */
527     if (obj->oartifact) {
528         /* place_object may change these */
529         boolean crysknife = (obj->otyp == CRYSKNIFE);
530         int oerode = obj->oerodeproof;
531         boolean wasUpolyd = Upolyd;
532
533         /* in case touching this object turns out to be fatal */
534         place_object(obj, u.ux, u.uy);
535
536         if (!touch_artifact(obj, &youmonst)) {
537             obj_extract_self(obj); /* remove it from the floor */
538             dropy(obj);            /* now put it back again :-) */
539             return obj;
540         } else if (wasUpolyd && !Upolyd) {
541             /* loose your grip if you revert your form */
542             if (drop_fmt)
543                 pline(drop_fmt, drop_arg);
544             obj_extract_self(obj);
545             dropy(obj);
546             return obj;
547         }
548         obj_extract_self(obj);
549         if (crysknife) {
550             obj->otyp = CRYSKNIFE;
551             obj->oerodeproof = oerode;
552         }
553     }
554     if (Fumbling) {
555         if (drop_fmt)
556             pline(drop_fmt, drop_arg);
557         dropy(obj);
558     } else {
559         long oquan = obj->quan;
560         int prev_encumbr = near_capacity(); /* before addinv() */
561
562         /* encumbrance only matters if it would now become worse
563            than max( current_value, stressed ) */
564         if (prev_encumbr < MOD_ENCUMBER)
565             prev_encumbr = MOD_ENCUMBER;
566         /* addinv() may redraw the entire inventory, overwriting
567            drop_arg when it comes from something like doname() */
568         if (drop_arg)
569             drop_arg = strcpy(buf, drop_arg);
570
571         obj = addinv(obj);
572         if (inv_cnt(FALSE) > 52 || ((obj->otyp != LOADSTONE || !obj->cursed)
573                                     && near_capacity() > prev_encumbr)) {
574             if (drop_fmt)
575                 pline(drop_fmt, drop_arg);
576             /* undo any merge which took place */
577             if (obj->quan > oquan)
578                 obj = splitobj(obj, oquan);
579             dropx(obj);
580         } else {
581             if (flags.autoquiver && !uquiver && !obj->owornmask
582                 && (is_missile(obj) || ammo_and_launcher(obj, uwep)
583                     || ammo_and_launcher(obj, uswapwep)))
584                 setuqwep(obj);
585             if (hold_msg || drop_fmt)
586                 prinv(hold_msg, obj, oquan);
587         }
588     }
589     return obj;
590 }
591
592 /* useup() all of an item regardless of its quantity */
593 void
594 useupall(obj)
595 struct obj *obj;
596 {
597     setnotworn(obj);
598     freeinv(obj);
599     obfree(obj, (struct obj *) 0); /* deletes contents also */
600 }
601
602 void
603 useup(obj)
604 register struct obj *obj;
605 {
606     /* Note:  This works correctly for containers because they (containers)
607        don't merge. */
608     if (obj->quan > 1L) {
609         obj->in_use = FALSE; /* no longer in use */
610         obj->quan--;
611         obj->owt = weight(obj);
612         update_inventory();
613     } else {
614         useupall(obj);
615     }
616 }
617
618 /* use one charge from an item and possibly incur shop debt for it */
619 void
620 consume_obj_charge(obj, maybe_unpaid)
621 struct obj *obj;
622 boolean maybe_unpaid; /* false if caller handles shop billing */
623 {
624     if (maybe_unpaid)
625         check_unpaid(obj);
626     obj->spe -= 1;
627     if (obj->known)
628         update_inventory();
629 }
630
631 /*
632  * Adjust hero's attributes as if this object was being removed from the
633  * hero's inventory.  This should only be called from freeinv() and
634  * where we are polymorphing an object already in the hero's inventory.
635  *
636  * Should think of a better name...
637  */
638 void
639 freeinv_core(obj)
640 struct obj *obj;
641 {
642     if (obj->oclass == COIN_CLASS) {
643         context.botl = 1;
644         return;
645     } else if (obj->otyp == AMULET_OF_YENDOR) {
646         if (!u.uhave.amulet)
647             impossible("don't have amulet?");
648         u.uhave.amulet = 0;
649     } else if (obj->otyp == CANDELABRUM_OF_INVOCATION) {
650         if (!u.uhave.menorah)
651             impossible("don't have candelabrum?");
652         u.uhave.menorah = 0;
653     } else if (obj->otyp == BELL_OF_OPENING) {
654         if (!u.uhave.bell)
655             impossible("don't have silver bell?");
656         u.uhave.bell = 0;
657     } else if (obj->otyp == SPE_BOOK_OF_THE_DEAD) {
658         if (!u.uhave.book)
659             impossible("don't have the book?");
660         u.uhave.book = 0;
661     } else if (obj->oartifact) {
662         if (is_quest_artifact(obj)) {
663             if (!u.uhave.questart)
664                 impossible("don't have quest artifact?");
665             u.uhave.questart = 0;
666         }
667         set_artifact_intrinsic(obj, 0, W_ART);
668     }
669
670     if (obj->otyp == LOADSTONE) {
671         curse(obj);
672     } else if (confers_luck(obj)) {
673         set_moreluck();
674         context.botl = 1;
675     } else if (obj->otyp == FIGURINE && obj->timed) {
676         (void) stop_timer(FIG_TRANSFORM, obj_to_any(obj));
677     }
678 }
679
680 /* remove an object from the hero's inventory */
681 void
682 freeinv(obj)
683 register struct obj *obj;
684 {
685     extract_nobj(obj, &invent);
686     freeinv_core(obj);
687     update_inventory();
688 }
689
690 void
691 delallobj(x, y)
692 int x, y;
693 {
694     struct obj *otmp, *otmp2;
695
696     for (otmp = level.objects[x][y]; otmp; otmp = otmp2) {
697         if (otmp == uball)
698             unpunish();
699         /* after unpunish(), or might get deallocated chain */
700         otmp2 = otmp->nexthere;
701         if (otmp == uchain)
702             continue;
703         delobj(otmp);
704     }
705 }
706
707 /* destroy object in fobj chain (if unpaid, it remains on the bill) */
708 void
709 delobj(obj)
710 register struct obj *obj;
711 {
712     boolean update_map;
713
714     if (obj->otyp == AMULET_OF_YENDOR
715         || obj->otyp == CANDELABRUM_OF_INVOCATION
716         || obj->otyp == BELL_OF_OPENING
717         || obj->otyp == SPE_BOOK_OF_THE_DEAD) {
718         /* player might be doing something stupid, but we
719          * can't guarantee that.  assume special artifacts
720          * are indestructible via drawbridges, and exploding
721          * chests, and golem creation, and ...
722          */
723         return;
724     }
725     update_map = (obj->where == OBJ_FLOOR);
726     obj_extract_self(obj);
727     if (update_map)
728         newsym(obj->ox, obj->oy);
729     obfree(obj, (struct obj *) 0); /* frees contents also */
730 }
731
732 /* try to find a particular type of object at designated map location */
733 struct obj *
734 sobj_at(otyp, x, y)
735 int otyp;
736 int x, y;
737 {
738     register struct obj *otmp;
739
740     for (otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere)
741         if (otmp->otyp == otyp)
742             break;
743
744     return otmp;
745 }
746
747 /* sobj_at(&c) traversal -- find next object of specified type */
748 struct obj *
749 nxtobj(obj, type, by_nexthere)
750 struct obj *obj;
751 int type;
752 boolean by_nexthere;
753 {
754     register struct obj *otmp;
755
756     otmp = obj; /* start with the object after this one */
757     do {
758         otmp = !by_nexthere ? otmp->nobj : otmp->nexthere;
759         if (!otmp)
760             break;
761     } while (otmp->otyp != type);
762
763     return otmp;
764 }
765
766 struct obj *
767 carrying(type)
768 register int type;
769 {
770     register struct obj *otmp;
771
772     for (otmp = invent; otmp; otmp = otmp->nobj)
773         if (otmp->otyp == type)
774             return  otmp;
775     return (struct obj *) 0;
776 }
777
778 /* Fictional and not-so-fictional currencies.
779  * http://concord.wikia.com/wiki/List_of_Fictional_Currencies
780  */
781 static const char *const currencies[] = {
782     "Altarian Dollar",       /* The Hitchhiker's Guide to the Galaxy */
783     "Ankh-Morpork Dollar",   /* Discworld */
784     "auric",                 /* The Domination of Draka */
785     "buckazoid",             /* Space Quest */
786     "cirbozoid",             /* Starslip */
787     "credit chit",           /* Deus Ex */
788     "cubit",                 /* Battlestar Galactica */
789     "Flanian Pobble Bead",   /* The Hitchhiker's Guide to the Galaxy */
790     "fretzer",               /* Jules Verne */
791     "imperial credit",       /* Star Wars */
792     "Hong Kong Luna Dollar", /* The Moon is a Harsh Mistress */
793     "kongbuck",              /* Snow Crash */
794     "nanite",                /* System Shock 2 */
795     "quatloo",               /* Star Trek, Sim City */
796     "simoleon",              /* Sim City */
797     "solari",                /* Spaceballs */
798     "spacebuck",             /* Spaceballs */
799     "sporebuck",             /* Spore */
800     "Triganic Pu",           /* The Hitchhiker's Guide to the Galaxy */
801     "woolong",               /* Cowboy Bebop */
802     "zorkmid",               /* Zork, NetHack */
803 };
804
805 const char *
806 currency(amount)
807 long amount;
808 {
809     const char *res;
810
811 #if 0 /*JP*/
812     res = Hallucination ? currencies[rn2(SIZE(currencies))] : "zorkmid";
813     if (amount != 1L)
814         res = makeplural(res);
815 #else
816     res = Hallucination ? currencies[rn2(SIZE(currencies))] : "\83S\81[\83\8b\83h";
817 #endif
818     return res;
819 }
820
821 boolean
822 have_lizard()
823 {
824     register struct obj *otmp;
825
826     for (otmp = invent; otmp; otmp = otmp->nobj)
827         if (otmp->otyp == CORPSE && otmp->corpsenm == PM_LIZARD)
828             return  TRUE;
829     return FALSE;
830 }
831
832 /* 3.6.0 tribute */
833 struct obj *
834 u_have_novel()
835 {
836     register struct obj *otmp;
837
838     for (otmp = invent; otmp; otmp = otmp->nobj)
839         if (otmp->otyp == SPE_NOVEL)
840             return otmp;
841     return (struct obj *) 0;
842 }
843
844 struct obj *
845 o_on(id, objchn)
846 unsigned int id;
847 register struct obj *objchn;
848 {
849     struct obj *temp;
850
851     while (objchn) {
852         if (objchn->o_id == id)
853             return objchn;
854         if (Has_contents(objchn) && (temp = o_on(id, objchn->cobj)))
855             return temp;
856         objchn = objchn->nobj;
857     }
858     return (struct obj *) 0;
859 }
860
861 boolean
862 obj_here(obj, x, y)
863 register struct obj *obj;
864 int x, y;
865 {
866     register struct obj *otmp;
867
868     for (otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere)
869         if (obj == otmp)
870             return TRUE;
871     return FALSE;
872 }
873
874 struct obj *
875 g_at(x, y)
876 register int x, y;
877 {
878     register struct obj *obj = level.objects[x][y];
879
880     while (obj) {
881         if (obj->oclass == COIN_CLASS)
882             return obj;
883         obj = obj->nexthere;
884     }
885     return (struct obj *) 0;
886 }
887
888 /* compact a string of inventory letters by dashing runs of letters */
889 STATIC_OVL void
890 compactify(buf)
891 register char *buf;
892 {
893     register int i1 = 1, i2 = 1;
894     register char ilet, ilet1, ilet2;
895
896     ilet2 = buf[0];
897     ilet1 = buf[1];
898     buf[++i2] = buf[++i1];
899     ilet = buf[i1];
900     while (ilet) {
901         if (ilet == ilet1 + 1) {
902             if (ilet1 == ilet2 + 1)
903                 buf[i2 - 1] = ilet1 = '-';
904             else if (ilet2 == '-') {
905                 buf[i2 - 1] = ++ilet1;
906                 buf[i2] = buf[++i1];
907                 ilet = buf[i1];
908                 continue;
909             }
910         } else if (ilet == NOINVSYM) {
911             /* compact three or more consecutive '#'
912                characters into "#-#" */
913             if (i2 >= 2 && buf[i2 - 2] == NOINVSYM && buf[i2 - 1] == NOINVSYM)
914                 buf[i2 - 1] = '-';
915             else if (i2 >= 3 && buf[i2 - 3] == NOINVSYM && buf[i2 - 2] == '-'
916                      && buf[i2 - 1] == NOINVSYM)
917                 --i2;
918         }
919         ilet2 = ilet1;
920         ilet1 = ilet;
921         buf[++i2] = buf[++i1];
922         ilet = buf[i1];
923     }
924 }
925
926 /* some objects shouldn't be split when count given to getobj or askchain */
927 STATIC_OVL boolean
928 splittable(obj)
929 struct obj *obj;
930 {
931     return !((obj->otyp == LOADSTONE && obj->cursed)
932              || (obj == uwep && welded(uwep)));
933 }
934
935 /* match the prompt for either 'T' or 'R' command */
936 STATIC_OVL boolean
937 taking_off(action)
938 const char *action;
939 {
940     return !strcmp(action, "take off") || !strcmp(action, "remove");
941 }
942
943 /* match the prompt for either 'W' or 'P' command */
944 STATIC_OVL boolean
945 putting_on(action)
946 const char *action;
947 {
948     return !strcmp(action, "wear") || !strcmp(action, "put on");
949 }
950
951 /*
952  * getobj returns:
953  *      struct obj *xxx:        object to do something with.
954  *      (struct obj *) 0        error return: no object.
955  *      &zeroobj                explicitly no object (as in w-).
956 !!!! test if gold can be used in unusual ways (eaten etc.)
957 !!!! may be able to remove "usegold"
958  */
959 /*JP
960 ** word \82É\82Í\89p\8cê\82Å\93®\8e\8c\82ª\93ü\82é\81D
961 **
962 ** \93ú\96{\8cê\82Å\82Í\81C\81u\82Ç\82ê\82ð\8f\91\82«\82Ü\82·\82©\81v\82æ\82è\81u\82Ç\82ê\82É\8f\91\82«\82Ü\82·\82©\81v\82Ì\95û\82ª\8e©\91R\82È\82Ì\82Å\81C
963 ** \8dÅ\8f\89\82Ì\88ê\95\8e\9a\82É\81u\82É\81v\82â\81u\82Ì\81v\82ð\8ew\92è\82µ\82½\8fê\8d\87\82Í\8f\95\8e\8c\82ð\95Ï\8dX\82·\82é\81D
964 **
965 */
966 struct obj *
967 getobj(let, word)
968 register const char *let, *word;
969 {
970     register struct obj *otmp;
971     register char ilet;
972     char buf[BUFSZ], qbuf[QBUFSZ];
973     char lets[BUFSZ], altlets[BUFSZ], *ap;
974     register int foo = 0;
975     register char *bp = buf;
976     xchar allowcnt = 0; /* 0, 1 or 2 */
977     struct obj *firstobj = invent;
978     boolean usegold = FALSE; /* can't use gold because its illegal */
979     boolean allowall = FALSE;
980     boolean allownone = FALSE;
981     boolean useboulder = FALSE;
982     xchar foox = 0;
983     long cnt, prevcnt;
984     boolean prezero;
985     long dummymask;
986
987 #if 1 /*JP*/
988     const char *jword;
989     const char *joshi;
990     const char *what;
991
992     struct trans_verb *tv = trans_verb(word);
993
994     jword = tv->jp;
995     what = tv->what;
996     joshi = tv->particle;
997 #endif
998     if (*let == ALLOW_COUNT)
999         let++, allowcnt = 1;
1000     if (*let == COIN_CLASS)
1001         let++, usegold = TRUE;
1002
1003     /* Equivalent of an "ugly check" for gold */
1004     if (usegold && !strcmp(word, "eat")
1005         && (!metallivorous(youmonst.data)
1006             || youmonst.data == &mons[PM_RUST_MONSTER]))
1007         usegold = FALSE;
1008
1009     if (*let == ALL_CLASSES)
1010         let++, allowall = TRUE;
1011     if (*let == ALLOW_NONE)
1012         let++, allownone = TRUE;
1013     /* "ugly check" for reading fortune cookies, part 1.
1014      * The normal 'ugly check' keeps the object on the inventory list.
1015      * We don't want to do that for shirts/cookies, so the check for
1016      * them is handled a bit differently (and also requires that we set
1017      * allowall in the caller).
1018      */
1019     if (allowall && !strcmp(word, "read"))
1020         allowall = FALSE;
1021
1022     /* another ugly check: show boulders (not statues) */
1023     if (*let == WEAPON_CLASS && !strcmp(word, "throw")
1024         && throws_rocks(youmonst.data))
1025         useboulder = TRUE;
1026
1027     if (allownone)
1028         *bp++ = '-';
1029     if (bp > buf && bp[-1] == '-')
1030         *bp++ = ' ';
1031     ap = altlets;
1032
1033     if (!flags.invlet_constant)
1034         reassign();
1035
1036     for (otmp = firstobj; otmp; otmp = otmp->nobj) {
1037         if (&bp[foo] == &buf[sizeof buf - 1]
1038             || ap == &altlets[sizeof altlets - 1]) {
1039             /* we must have a huge number of NOINVSYM items somehow */
1040             impossible("getobj: inventory overflow");
1041             break;
1042         }
1043
1044         if (!*let || index(let, otmp->oclass)
1045             || (usegold && otmp->invlet == GOLD_SYM)
1046             || (useboulder && otmp->otyp == BOULDER)) {
1047             register int otyp = otmp->otyp;
1048             bp[foo++] = otmp->invlet;
1049
1050 /* clang-format off */
1051 /* *INDENT-OFF* */
1052             /* ugly check: remove inappropriate things */
1053             if (
1054                 (taking_off(word) /* exclude if not worn */
1055                  && !(otmp->owornmask & (W_ARMOR | W_ACCESSORY)))
1056              || (putting_on(word) /* exclude if already worn */
1057                  && (otmp->owornmask & (W_ARMOR | W_ACCESSORY)))
1058 #if 0 /* 3.4.1 -- include currently wielded weapon among 'wield' choices */
1059              || (!strcmp(word, "wield")
1060                  && (otmp->owornmask & W_WEP))
1061 #endif
1062              || (!strcmp(word, "ready") /* exclude if wielded */
1063                  && (otmp == uwep || (otmp == uswapwep && u.twoweap)))
1064              || ((!strcmp(word, "dip") || !strcmp(word, "grease"))
1065                  && inaccessible_equipment(otmp, (const char *) 0, FALSE))
1066              ) {
1067                 foo--;
1068                 foox++;
1069             }
1070             /* Second ugly check; unlike the first it won't trigger an
1071              * "else" in "you don't have anything else to ___".
1072              */
1073             else if (
1074                 (putting_on(word)
1075                  && ((otmp->oclass == FOOD_CLASS && otmp->otyp != MEAT_RING)
1076                      || (otmp->oclass == TOOL_CLASS && otyp != BLINDFOLD
1077                          && otyp != TOWEL && otyp != LENSES)))
1078              || (!strcmp(word, "wield")
1079                  && (otmp->oclass == TOOL_CLASS && !is_weptool(otmp)))
1080              || (!strcmp(word, "eat") && !is_edible(otmp))
1081              || (!strcmp(word, "sacrifice")
1082                  && (otyp != CORPSE && otyp != AMULET_OF_YENDOR
1083                      && otyp != FAKE_AMULET_OF_YENDOR))
1084              || (!strcmp(word, "write with")
1085                  && (otmp->oclass == TOOL_CLASS
1086                      && otyp != MAGIC_MARKER && otyp != TOWEL))
1087              || (!strcmp(word, "tin")
1088                  && (otyp != CORPSE || !tinnable(otmp)))
1089              || (!strcmp(word, "rub")
1090                  && ((otmp->oclass == TOOL_CLASS && otyp != OIL_LAMP
1091                       && otyp != MAGIC_LAMP && otyp != BRASS_LANTERN)
1092                      || (otmp->oclass == GEM_CLASS && !is_graystone(otmp))))
1093              || (!strcmp(word, "use or apply")
1094                  /* Picks, axes, pole-weapons, bullwhips */
1095                  && ((otmp->oclass == WEAPON_CLASS
1096                       && !is_pick(otmp) && !is_axe(otmp)
1097                       && !is_pole(otmp) && otyp != BULLWHIP)
1098                      || (otmp->oclass == POTION_CLASS
1099                          /* only applicable potion is oil, and it will only
1100                             be offered as a choice when already discovered */
1101                          && (otyp != POT_OIL || !otmp->dknown
1102                              || !objects[POT_OIL].oc_name_known))
1103                      || (otmp->oclass == FOOD_CLASS
1104                          && otyp != CREAM_PIE && otyp != EUCALYPTUS_LEAF)
1105                      || (otmp->oclass == GEM_CLASS && !is_graystone(otmp))))
1106              || (!strcmp(word, "invoke")
1107                  && !otmp->oartifact
1108                  && !objects[otyp].oc_unique
1109                  && (otyp != FAKE_AMULET_OF_YENDOR || otmp->known)
1110                  && otyp != CRYSTAL_BALL /* synonym for apply */
1111                  /* note: presenting the possibility of invoking non-artifact
1112                     mirrors and/or lamps is simply a cruel deception... */
1113                  && otyp != MIRROR
1114                  && otyp != MAGIC_LAMP
1115                  && (otyp != OIL_LAMP /* don't list known oil lamp */
1116                      || (otmp->dknown && objects[OIL_LAMP].oc_name_known)))
1117              || (!strcmp(word, "untrap with")
1118                  && ((otmp->oclass == TOOL_CLASS && otyp != CAN_OF_GREASE)
1119                      || (otmp->oclass == POTION_CLASS
1120                          /* only applicable potion is oil, and it will only
1121                             be offered as a choice when already discovered */
1122                          && (otyp != POT_OIL || !otmp->dknown
1123                              || !objects[POT_OIL].oc_name_known))))
1124              || (!strcmp(word, "tip") && !Is_container(otmp)
1125                  /* include horn of plenty if sufficiently discovered */
1126                  && (otmp->otyp != HORN_OF_PLENTY || !otmp->dknown
1127                      || !objects[HORN_OF_PLENTY].oc_name_known))
1128              || (!strcmp(word, "charge") && !is_chargeable(otmp))
1129              || (!strcmp(word, "call") && !objtyp_is_callable(otyp))
1130              ) {
1131                 foo--;
1132             }
1133             /* Third ugly check:  acceptable but not listed as likely
1134              * candidates in the prompt or in the inventory subset if
1135              * player responds with '?'.
1136              */
1137             else if (
1138              /* ugly check for unworn armor that can't be worn */
1139                 (putting_on(word) && *let == ARMOR_CLASS
1140                  && !canwearobj(otmp, &dummymask, FALSE))
1141              /* or armor with 'P' or 'R' or accessory with 'W' or 'T' */
1142              || ((putting_on(word) || taking_off(word))
1143                  && ((*let == ARMOR_CLASS) ^ (otmp->oclass == ARMOR_CLASS)))
1144              /* or unsuitable items rubbed on known touchstone */
1145              || (!strncmp(word, "rub on the stone", 16)
1146                  && *let == GEM_CLASS && otmp->dknown
1147                  && objects[otyp].oc_name_known)
1148              /* suppress corpses on astral, amulets elsewhere */
1149              || (!strcmp(word, "sacrifice")
1150                  /* (!astral && amulet) || (astral && !amulet) */
1151                  && (!Is_astralevel(&u.uz) ^ (otmp->oclass != AMULET_CLASS)))
1152              /* suppress container being stashed into */
1153              || (!strcmp(word, "stash") && !ck_bag(otmp))
1154              /* worn armor or accessory covered by cursed worn armor */
1155              || (taking_off(word)
1156                  && inaccessible_equipment(otmp, (const char *) 0, TRUE))
1157              ) {
1158                 /* acceptable but not listed as likely candidate */
1159                 foo--;
1160                 allowall = TRUE;
1161                 *ap++ = otmp->invlet;
1162             }
1163 /* *INDENT-ON* */
1164 /* clang-format on */
1165         } else {
1166             /* "ugly check" for reading fortune cookies, part 2 */
1167             if ((!strcmp(word, "read") && is_readable(otmp)))
1168                 allowall = usegold = TRUE;
1169         }
1170     }
1171
1172     bp[foo] = 0;
1173     if (foo == 0 && bp > buf && bp[-1] == ' ')
1174         *--bp = 0;
1175     Strcpy(lets, bp); /* necessary since we destroy buf */
1176     if (foo > 5)      /* compactify string */
1177         compactify(bp);
1178     *ap = '\0';
1179
1180     if (!foo && !allowall && !allownone) {
1181 /*JP
1182         You("don't have anything %sto %s.", foox ? "else " : "", word);
1183 */
1184         You("%s%s\82à\82Ì\82ð\8e\9d\82Á\82Ä\82¢\82È\82¢\81D", foox ? "\91¼\82É" : "", jconj(jword, "\82ê\82é"));
1185         return (struct obj *) 0;
1186     }
1187     for (;;) {
1188         cnt = 0;
1189         if (allowcnt == 2)
1190             allowcnt = 1; /* abort previous count */
1191         prezero = FALSE;
1192         if (!buf[0]) {
1193 /*JP
1194             Sprintf(qbuf, "What do you want to %s? [*]", word);
1195 */
1196             Sprintf(qbuf, "%s%s%s\82©\81H[*]", what, joshi, jpolite(jword));
1197         } else {
1198 /*JP
1199             Sprintf(qbuf, "What do you want to %s? [%s or ?*]", word, buf);
1200 */
1201             Sprintf(qbuf, "%s%s%s\82©\81H[%s or ?*]", what, joshi, jpolite(jword), buf);
1202         }
1203         if (in_doagain)
1204             ilet = readchar();
1205         else
1206             ilet = yn_function(qbuf, (char *) 0, '\0');
1207         if (digit(ilet) && !allowcnt) {
1208 /*JP
1209             pline("No count allowed with this command.");
1210 */
1211             pline("\82±\82Ì\83R\83}\83\93\83h\82É\90\94\8e\9a\82Í\82Â\82©\82¦\82È\82¢\81D");
1212             continue;
1213         }
1214         if (ilet == '0')
1215             prezero = TRUE;
1216         while (digit(ilet)) {
1217             if (ilet != '?' && ilet != '*')
1218                 savech(ilet);
1219             /* accumulate unless cnt has overflowed */
1220             if (allowcnt < 3) {
1221                 prevcnt = cnt;
1222                 cnt = 10L * cnt + (long) (ilet - '0');
1223                 /* signal presence of cnt */
1224                 allowcnt = (cnt >= prevcnt) ? 2 : 3;
1225             }
1226             ilet = readchar();
1227         }
1228         if (allowcnt == 3) {
1229             /* overflow detected; force cnt to be invalid */
1230             cnt = -1L;
1231             allowcnt = 2;
1232         }
1233         if (index(quitchars, ilet)) {
1234             if (flags.verbose)
1235                 pline1(Never_mind);
1236             return (struct obj *) 0;
1237         }
1238         if (ilet == '-') {
1239             if (!allownone) {
1240                 char *suf = (char *) 0;
1241
1242                 strcpy(buf, word);
1243                 if ((bp = strstr(buf, " on the ")) != 0) {
1244                     /* rub on the stone[s] */
1245                     *bp = '\0';
1246                     suf = (bp + 1);
1247                 }
1248                 if ((bp = strstr(buf, " or ")) != 0) {
1249                     *bp = '\0';
1250                     bp = (rn2(2) ? buf : (bp + 4));
1251                 } else
1252                     bp = buf;
1253                 You("mime %s something%s%s.", ing_suffix(bp), suf ? " " : "",
1254                     suf ? suf : "");
1255             }
1256             return (allownone ? &zeroobj : (struct obj *) 0);
1257         }
1258         /* since gold is now kept in inventory, we need to do processing for
1259            select-from-invent before checking whether gold has been picked */
1260         if (ilet == '?' || ilet == '*') {
1261             char *allowed_choices = (ilet == '?') ? lets : (char *) 0;
1262             long ctmp = 0;
1263
1264             if (ilet == '?' && !*lets && *altlets)
1265                 allowed_choices = altlets;
1266             ilet = display_pickinv(allowed_choices, TRUE,
1267                                    allowcnt ? &ctmp : (long *) 0);
1268             if (!ilet)
1269                 continue;
1270             if (allowcnt && ctmp >= 0) {
1271                 cnt = ctmp;
1272                 if (!cnt)
1273                     prezero = TRUE;
1274                 allowcnt = 2;
1275             }
1276             if (ilet == '\033') {
1277                 if (flags.verbose)
1278                     pline1(Never_mind);
1279                 return (struct obj *) 0;
1280             }
1281             /* they typed a letter (not a space) at the prompt */
1282         }
1283         /* find the item which was picked */
1284         for (otmp = invent; otmp; otmp = otmp->nobj)
1285             if (otmp->invlet == ilet)
1286                 break;
1287         /* some items have restrictions */
1288         if (ilet == def_oc_syms[COIN_CLASS].sym
1289             /* guard against the [hypothetical] chace of having more
1290                than one invent slot of gold and picking the non-'$' one */
1291             || (otmp && otmp->oclass == COIN_CLASS)) {
1292             if (!usegold) {
1293 /*JP
1294                 You("cannot %s gold.", word);
1295 */
1296                 You("\8bà\89Ý%s%s\82±\82Æ\82Í\82Å\82«\82È\82¢\81D", joshi, jword);
1297                 return (struct obj *) 0;
1298             }
1299             /* Historic note: early Nethack had a bug which was
1300              * first reported for Larn, where trying to drop 2^32-n
1301              * gold pieces was allowed, and did interesting things
1302              * to your money supply.  The LRS is the tax bureau
1303              * from Larn.
1304              */
1305             if (allowcnt == 2 && cnt <= 0) {
1306                 if (cnt < 0 || !prezero)
1307                     pline_The(
1308 /*JP
1309                   "LRS would be very interested to know you have that much.");
1310 */
1311                   "\82»\82Ì\8bZ\82Í\82Æ\82 \82é\83Q\81[\83\80\82Ì\83J\83W\83m\82Å\8eg\82¦\82½\82¯\82Ç\81C\82à\82Í\82â\8eg\82¦\82È\82¢\82æ\81D");
1312                 return (struct obj *) 0;
1313             }
1314         }
1315         if (allowcnt == 2 && !strcmp(word, "throw")) {
1316             /* permit counts for throwing gold, but don't accept
1317              * counts for other things since the throw code will
1318              * split off a single item anyway */
1319             if (ilet != def_oc_syms[COIN_CLASS].sym
1320                 && !(otmp && otmp->oclass == COIN_CLASS))
1321                 allowcnt = 1;
1322             if (cnt == 0 && prezero)
1323                 return (struct obj *) 0;
1324             if (cnt > 1) {
1325 /*JP
1326                 You("can only throw one item at a time.");
1327 */
1328                 You("\93¯\8e\9e\82É\82½\82­\82³\82ñ\82Ì\82à\82Ì\82ð\93\8a\82°\82ç\82ê\82È\82¢\81D");
1329                 continue;
1330             }
1331         }
1332         context.botl = 1; /* May have changed the amount of money */
1333         savech(ilet);
1334         /* [we used to set otmp (by finding ilet in invent) here, but
1335            that's been moved above so that otmp can be checked earlier] */
1336         /* verify the chosen object */
1337         if (!otmp) {
1338 /*JP
1339             You("don't have that object.");
1340 */
1341             You("\82»\82ñ\82È\82à\82Ì\82Í\8e\9d\82Á\82Ä\82¢\82È\82¢\81D");
1342             if (in_doagain)
1343                 return (struct obj *) 0;
1344             continue;
1345         } else if (cnt < 0 || otmp->quan < cnt) {
1346 /*JP
1347             You("don't have that many!  You have only %ld.", otmp->quan);
1348 */
1349             pline("\82»\82ñ\82È\82É\82½\82­\82³\82ñ\82Í\8e\9d\82Á\82Ä\82¢\82È\82¢\81I\82¹\82¢\82º\82¢%ld\8cÂ\82Á\82Ä\82Æ\82±\82¾\81D", otmp->quan);
1350             if (in_doagain)
1351                 return (struct obj *) 0;
1352             continue;
1353         }
1354         break;
1355     }
1356     if (!allowall && let && !index(let, otmp->oclass)
1357         && !(usegold && otmp->oclass == COIN_CLASS)) {
1358 #if 0 /*JP*/
1359         silly_thing(word, otmp);
1360 #else
1361         silly_thing(jword, otmp);
1362 #endif
1363         return (struct obj *) 0;
1364     }
1365     if (allowcnt == 2) { /* cnt given */
1366         if (cnt == 0)
1367             return (struct obj *) 0;
1368         if (cnt != otmp->quan) {
1369             /* don't split a stack of cursed loadstones */
1370             if (splittable(otmp))
1371                 otmp = splitobj(otmp, cnt);
1372             else if (otmp->otyp == LOADSTONE && otmp->cursed)
1373                 /* kludge for canletgo()'s can't-drop-this message */
1374                 otmp->corpsenm = (int) cnt;
1375         }
1376     }
1377     return otmp;
1378 }
1379
1380 void
1381 silly_thing(word, otmp)
1382 const char *word;
1383 struct obj *otmp;
1384 {
1385 #if 1 /* 'P','R' vs 'W','T' handling is obsolete */
1386     nhUse(otmp);
1387 #else
1388     const char *s1, *s2, *s3, *what;
1389     int ocls = otmp->oclass, otyp = otmp->otyp;
1390
1391     s1 = s2 = s3 = 0;
1392     /* check for attempted use of accessory commands ('P','R') on armor
1393        and for corresponding armor commands ('W','T') on accessories */
1394     if (ocls == ARMOR_CLASS) {
1395 #if 0 /*JP*/
1396         if (!strcmp(word, "put on"))
1397             s1 = "W", s2 = "wear", s3 = "";
1398         else if (!strcmp(word, "remove"))
1399             s1 = "T", s2 = "take", s3 = " off";
1400 #else
1401         if (!strcmp(word, "\90g\82É\82Â\82¯\82é"))
1402             s1 = "W", s2 = "\90g\82É\82Â\82¯\82é", s3 = "";
1403         else if (!strcmp(word, "\82Í\82¸\82·"))
1404             s1 = "T", s2 = "\82Í\82¸\82·", s3 = "";
1405 #endif
1406     } else if ((ocls == RING_CLASS || otyp == MEAT_RING)
1407                || ocls == AMULET_CLASS
1408                || (otyp == BLINDFOLD || otyp == TOWEL || otyp == LENSES)) {
1409 #if 0 /*JP*/
1410         if (!strcmp(word, "wear"))
1411             s1 = "P", s2 = "put", s3 = " on";
1412         else if (!strcmp(word, "take off"))
1413             s1 = "R", s2 = "remove", s3 = "";
1414 #else
1415         if (!strcmp(word, "\90g\82É\82Â\82¯\82é"))
1416           s1 = "P", s2 = "\90g\82É\82Â\82¯\82é", s3 = "";
1417         else if (!strcmp(word, "\82Í\82¸\82·"))
1418           s1 = "R", s2 = "\82Í\82¸\82·", s3 = "";
1419 #endif
1420     }
1421     if (s1) {
1422 #if 0 /*JP*/
1423         what = "that";
1424         /* quantity for armor and accessory objects is always 1,
1425            but some things should be referred to as plural */
1426         if (otyp == LENSES || is_gloves(otmp) || is_boots(otmp))
1427             what = "those";
1428 #endif
1429 /*JP
1430         pline("Use the '%s' command to %s %s%s.", s1, s2, what, s3);
1431 */
1432         pline("\82»\82ê\82ð%s\82É\82Í'%s'\83R\83}\83\93\83h\82ð\8eg\82¤\82±\82Æ\81D", s2, s1);
1433     } else
1434 #endif
1435         pline(silly_thing_to, word);
1436 }
1437
1438 STATIC_PTR int
1439 ckvalidcat(otmp)
1440 struct obj *otmp;
1441 {
1442     /* use allow_category() from pickup.c */
1443     return (int) allow_category(otmp);
1444 }
1445
1446 STATIC_PTR int
1447 ckunpaid(otmp)
1448 struct obj *otmp;
1449 {
1450     return (otmp->unpaid || (Has_contents(otmp) && count_unpaid(otmp->cobj)));
1451 }
1452
1453 boolean
1454 wearing_armor()
1455 {
1456     return (boolean) (uarm || uarmc || uarmf || uarmg
1457                       || uarmh || uarms || uarmu);
1458 }
1459
1460 boolean
1461 is_worn(otmp)
1462 struct obj *otmp;
1463 {
1464     return (otmp->owornmask & (W_ARMOR | W_ACCESSORY | W_SADDLE | W_WEAPON))
1465             ? TRUE
1466             : FALSE;
1467 }
1468
1469 /* extra xprname() input that askchain() can't pass through safe_qbuf() */
1470 STATIC_VAR struct xprnctx {
1471     char let;
1472     boolean dot;
1473 } safeq_xprn_ctx;
1474
1475 /* safe_qbuf() -> short_oname() callback */
1476 STATIC_PTR char *
1477 safeq_xprname(obj)
1478 struct obj *obj;
1479 {
1480     return xprname(obj, (char *) 0, safeq_xprn_ctx.let, safeq_xprn_ctx.dot,
1481                    0L, 0L);
1482 }
1483
1484 /* alternate safe_qbuf() -> short_oname() callback */
1485 STATIC_PTR char *
1486 safeq_shortxprname(obj)
1487 struct obj *obj;
1488 {
1489     return xprname(obj, ansimpleoname(obj), safeq_xprn_ctx.let,
1490                    safeq_xprn_ctx.dot, 0L, 0L);
1491 }
1492
1493 static NEARDATA const char removeables[] = { ARMOR_CLASS, WEAPON_CLASS,
1494                                              RING_CLASS,  AMULET_CLASS,
1495                                              TOOL_CLASS,  0 };
1496
1497 /* interactive version of getobj - used for Drop, Identify and */
1498 /* Takeoff (A). Return the number of times fn was called successfully */
1499 /* If combo is TRUE, we just use this to get a category list */
1500 /*JP CHECK: 3.4.3 \82Ì\8cÄ\82Ñ\8fo\82µ\8c³
1501 do.c:864:               (result = ggetobj("drop", drop, 0, FALSE, (unsigned *)0)) < -1)
1502 do.c:925:       i = ggetobj("drop", drop, 0, TRUE, &ggoresults);
1503 do_wear.c:2538:     (result = ggetobj("take off", select_off, 0, FALSE, (unsigned *)0)) < -1)
1504 do_wear.c:2586: if (ggetobj("take off", select_off, 0, TRUE, (unsigned *)0) == -2)
1505 invent.c:1782:          n = ggetobj("identify", identify, id_limit, FALSE, (unsigned *)0);
1506 */
1507 int
1508 ggetobj(word, fn, mx, combo, resultflags)
1509 const char *word;
1510 int FDECL((*fn), (OBJ_P)), mx;
1511 boolean combo; /* combination menu flag */
1512 unsigned *resultflags;
1513 {
1514     int FDECL((*ckfn), (OBJ_P)) = (int FDECL((*), (OBJ_P))) 0;
1515     boolean FDECL((*filter), (OBJ_P)) = (boolean FDECL((*), (OBJ_P))) 0;
1516     boolean takeoff, ident, allflag, m_seen;
1517     int itemcount;
1518     int oletct, iletct, unpaid, oc_of_sym;
1519     char sym, *ip, olets[MAXOCLASSES + 5], ilets[MAXOCLASSES + 5];
1520     char extra_removeables[3 + 1]; /* uwep,uswapwep,uquiver */
1521     char buf[BUFSZ], qbuf[QBUFSZ];
1522 #if 1 /*JP*/
1523     const char *joshi = "\82ð";
1524     const char *jword;
1525
1526     const struct trans_verb *tv = trans_verb(word);
1527     jword = tv->jp;
1528     joshi = tv->particle;
1529 #endif
1530
1531     if (resultflags)
1532         *resultflags = 0;
1533     takeoff = ident = allflag = m_seen = FALSE;
1534     if (!invent) {
1535 /*JP
1536         You("have nothing to %s.", word);
1537 */
1538         You("%s\82à\82Ì\82Í\8e\9d\82Á\82Ä\82¢\82È\82¢\81D", jcan(jword));
1539         return 0;
1540     }
1541     add_valid_menu_class(0); /* reset */
1542     if (taking_off(word)) {
1543         takeoff = TRUE;
1544         filter = is_worn;
1545     } else if (!strcmp(word, "identify")) {
1546         ident = TRUE;
1547         filter = not_fully_identified;
1548     }
1549
1550     iletct = collect_obj_classes(ilets, invent, FALSE, filter, &itemcount);
1551     unpaid = count_unpaid(invent);
1552
1553     if (ident && !iletct) {
1554         return -1; /* no further identifications */
1555     } else if (!takeoff && (unpaid || invent)) {
1556         ilets[iletct++] = ' ';
1557         if (unpaid)
1558             ilets[iletct++] = 'u';
1559         if (count_buc(invent, BUC_BLESSED))
1560             ilets[iletct++] = 'B';
1561         if (count_buc(invent, BUC_UNCURSED))
1562             ilets[iletct++] = 'U';
1563         if (count_buc(invent, BUC_CURSED))
1564             ilets[iletct++] = 'C';
1565         if (count_buc(invent, BUC_UNKNOWN))
1566             ilets[iletct++] = 'X';
1567         if (invent)
1568             ilets[iletct++] = 'a';
1569     } else if (takeoff && invent) {
1570         ilets[iletct++] = ' ';
1571     }
1572     ilets[iletct++] = 'i';
1573     if (!combo)
1574         ilets[iletct++] = 'm'; /* allow menu presentation on request */
1575     ilets[iletct] = '\0';
1576
1577     for (;;) {
1578 #if 0 /*JP*/
1579         Sprintf(qbuf, "What kinds of thing do you want to %s? [%s]", word,
1580                 ilets);
1581 #else
1582         Sprintf(qbuf,"\82Ç\82Ì\8eí\97Þ\82Ì\82à\82Ì%s%s\82©\81H[%s]", joshi,
1583                 jpolite(jword), ilets);
1584 #endif
1585         getlin(qbuf, buf);
1586         if (buf[0] == '\033')
1587             return 0;
1588         if (index(buf, 'i')) {
1589             if (display_inventory((char *) 0, TRUE) == '\033')
1590                 return 0;
1591         } else
1592             break;
1593     }
1594
1595     extra_removeables[0] = '\0';
1596     if (takeoff) {
1597         /* arbitrary types of items can be placed in the weapon slots
1598            [any duplicate entries in extra_removeables[] won't matter] */
1599         if (uwep)
1600             (void) strkitten(extra_removeables, uwep->oclass);
1601         if (uswapwep)
1602             (void) strkitten(extra_removeables, uswapwep->oclass);
1603         if (uquiver)
1604             (void) strkitten(extra_removeables, uquiver->oclass);
1605     }
1606
1607     ip = buf;
1608     olets[oletct = 0] = '\0';
1609     while ((sym = *ip++) != '\0') {
1610         if (sym == ' ')
1611             continue;
1612         oc_of_sym = def_char_to_objclass(sym);
1613         if (takeoff && oc_of_sym != MAXOCLASSES) {
1614             if (index(extra_removeables, oc_of_sym)) {
1615                 ; /* skip rest of takeoff checks */
1616             } else if (!index(removeables, oc_of_sym)) {
1617 /*JP
1618                 pline("Not applicable.");
1619 */
1620                 pline("\82»\82ê\82Í\82Å\82«\82È\82¢\81D");
1621                 return 0;
1622             } else if (oc_of_sym == ARMOR_CLASS && !wearing_armor()) {
1623                 noarmor(FALSE);
1624                 return 0;
1625             } else if (oc_of_sym == WEAPON_CLASS && !uwep && !uswapwep
1626                        && !uquiver) {
1627 /*JP
1628                 You("are not wielding anything.");
1629 */
1630                 You("\89½\82à\91\95\94õ\82µ\82Ä\82¢\82È\82¢\81D");
1631                 return 0;
1632             } else if (oc_of_sym == RING_CLASS && !uright && !uleft) {
1633 /*JP
1634                 You("are not wearing rings.");
1635 */
1636                 You("\8ew\97Ö\82ð\90g\82É\82Â\82¯\82Ä\82¢\82È\82¢\81D");
1637                 return 0;
1638             } else if (oc_of_sym == AMULET_CLASS && !uamul) {
1639 /*JP
1640                 You("are not wearing an amulet.");
1641 */
1642                 You("\96\82\8f\9c\82¯\82ð\90g\82É\82Â\82¯\82Ä\82¢\82È\82¢\81D");
1643                 return 0;
1644             } else if (oc_of_sym == TOOL_CLASS && !ublindf) {
1645 /*JP
1646                 You("are not wearing a blindfold.");
1647 */
1648                 You("\96Ú\89B\82µ\82ð\82µ\82Ä\82¢\82È\82¢\81D");
1649                 return 0;
1650             }
1651         }
1652
1653         if (oc_of_sym == COIN_CLASS && !combo) {
1654             context.botl = 1;
1655         } else if (sym == 'a') {
1656             allflag = TRUE;
1657         } else if (sym == 'A') {
1658             /* same as the default */;
1659         } else if (sym == 'u') {
1660             add_valid_menu_class('u');
1661             ckfn = ckunpaid;
1662         } else if (sym == 'B') {
1663             add_valid_menu_class('B');
1664             ckfn = ckvalidcat;
1665         } else if (sym == 'U') {
1666             add_valid_menu_class('U');
1667             ckfn = ckvalidcat;
1668         } else if (sym == 'C') {
1669             add_valid_menu_class('C');
1670             ckfn = ckvalidcat;
1671         } else if (sym == 'X') {
1672             add_valid_menu_class('X');
1673             ckfn = ckvalidcat;
1674         } else if (sym == 'm') {
1675             m_seen = TRUE;
1676         } else if (oc_of_sym == MAXOCLASSES) {
1677 /*JP
1678             You("don't have any %c's.", sym);
1679 */
1680             You("%c\82É\91®\82·\82é\95¨\82ð\8e\9d\82Á\82Ä\82¢\82È\82¢\81D", sym);
1681         } else if (oc_of_sym != VENOM_CLASS) { /* suppress venom */
1682             if (!index(olets, oc_of_sym)) {
1683                 add_valid_menu_class(oc_of_sym);
1684                 olets[oletct++] = oc_of_sym;
1685                 olets[oletct] = 0;
1686             }
1687         }
1688     }
1689
1690     if (m_seen) {
1691         return (allflag || (!oletct && ckfn != ckunpaid)) ? -2 : -3;
1692     } else if (flags.menu_style != MENU_TRADITIONAL && combo && !allflag) {
1693         return 0;
1694 #if 0
1695     /* !!!! test gold dropping */
1696     } else if (allowgold == 2 && !oletct) {
1697         return 1; /* you dropped gold (or at least tried to)  */
1698 #endif
1699     } else {
1700         int cnt = askchain(&invent, olets, allflag, fn, ckfn, mx, word);
1701         /*
1702          * askchain() has already finished the job in this case
1703          * so set a special flag to convey that back to the caller
1704          * so that it won't continue processing.
1705          * Fix for bug C331-1 reported by Irina Rempt-Drijfhout.
1706          */
1707         if (combo && allflag && resultflags)
1708             *resultflags |= ALL_FINISHED;
1709         return cnt;
1710     }
1711 }
1712
1713 /*
1714  * Walk through the chain starting at objchn and ask for all objects
1715  * with olet in olets (if nonNULL) and satisfying ckfn (if nonnull)
1716  * whether the action in question (i.e., fn) has to be performed.
1717  * If allflag then no questions are asked. Max gives the max nr of
1718  * objects to be treated. Return the number of objects treated.
1719  */
1720 /*JP CHECK: 3.4.3 \82Å\82Ì\8cÄ\82Ñ\8fo\82µ\8c³
1721 invent.c:1512:ggetobj() int cnt = askchain(&invent, olets, allflag, fn, ckfn, mx, word); 
1722 pickup.c:2615:("nodot") if (askchain((struct obj **)&current_container->cobj,
1723 pickup.c:2711:("nodot") (void) askchain((struct obj **)&invent,
1724   word\82É\82Í\93®\8e\8c\82ª\89p\8cê\82Å\93ü\82é\81B
1725 */
1726 int
1727 askchain(objchn, olets, allflag, fn, ckfn, mx, word)
1728 struct obj **objchn;
1729 register int allflag, mx;
1730 register const char *olets, *word; /* olets is an Obj Class char array */
1731 register int FDECL((*fn), (OBJ_P)), FDECL((*ckfn), (OBJ_P));
1732 {
1733     struct obj *otmp, *otmpo;
1734     register char sym, ilet;
1735     register int cnt = 0, dud = 0, tmp;
1736     boolean takeoff, nodot, ident, take_out, put_in, first, ininv;
1737     char qbuf[QBUFSZ], qpfx[QBUFSZ];
1738
1739     takeoff = taking_off(word);
1740     ident = !strcmp(word, "identify");
1741     take_out = !strcmp(word, "take out");
1742     put_in = !strcmp(word, "put in");
1743     nodot = (!strcmp(word, "nodot") || !strcmp(word, "drop") || ident
1744              || takeoff || take_out || put_in);
1745     ininv = (*objchn == invent);
1746     first = TRUE;
1747 /* Changed so the askchain is interrogated in the order specified.
1748  * For example, if a person specifies =/ then first all rings will be
1749  * asked about followed by all wands -dgk
1750  */
1751 nextclass:
1752     ilet = 'a' - 1;
1753     if (*objchn && (*objchn)->oclass == COIN_CLASS)
1754         ilet--;                     /* extra iteration */
1755     /*
1756      * Multiple Drop can change the invent chain while it operates
1757      * (dropping a burning potion of oil while levitating creates
1758      * an explosion which can destroy inventory items), so simple
1759      * list traversal
1760      *  for (otmp = *objchn; otmp; otmp = otmp2) {
1761      *      otmp2 = otmp->nobj;
1762      *      ...
1763      *  }
1764      * is inadequate here.  Use each object's bypass bit to keep
1765      * track of which list elements have already been processed.
1766      */
1767     bypass_objlist(*objchn, FALSE); /* clear chain's bypass bits */
1768     while ((otmp = nxt_unbypassed_obj(*objchn)) != 0) {
1769         if (ilet == 'z')
1770             ilet = 'A';
1771         else
1772             ilet++;
1773         if (olets && *olets && otmp->oclass != *olets)
1774             continue;
1775         if (takeoff && !is_worn(otmp))
1776             continue;
1777         if (ident && !not_fully_identified(otmp))
1778             continue;
1779         if (ckfn && !(*ckfn)(otmp))
1780             continue;
1781         if (!allflag) {
1782             safeq_xprn_ctx.let = ilet;
1783             safeq_xprn_ctx.dot = !nodot;
1784             *qpfx = '\0';
1785             if (first) {
1786                 /* traditional_loot() skips prompting when only one
1787                    class of objects is involved, so prefix the first
1788                    object being queried here with an explanation why */
1789                 if (take_out || put_in)
1790                     Sprintf(qpfx, "%s: ", word), *qpfx = highc(*qpfx);
1791                 first = FALSE;
1792             }
1793 #if 0 /*JP*/
1794             (void) safe_qbuf(
1795                 qbuf, qpfx, "?", otmp, ininv ? safeq_xprname : doname,
1796                 ininv ? safeq_shortxprname : ansimpleoname, "item");
1797 #else
1798             (void) safe_qbuf(
1799                 qbuf, qpfx, "\81H", otmp, ininv ? safeq_xprname : doname,
1800                 ininv ? safeq_shortxprname : ansimpleoname, "\83A\83C\83e\83\80");
1801 #endif
1802             sym = (takeoff || ident || otmp->quan < 2L) ? nyaq(qbuf)
1803                                                         : nyNaq(qbuf);
1804         } else
1805             sym = 'y';
1806
1807         otmpo = otmp;
1808         if (sym == '#') {
1809             /* Number was entered; split the object unless it corresponds
1810                to 'none' or 'all'.  2 special cases: cursed loadstones and
1811                welded weapons (eg, multiple daggers) will remain as merged
1812                unit; done to avoid splitting an object that won't be
1813                droppable (even if we're picking up rather than dropping).
1814              */
1815             if (!yn_number)
1816                 sym = 'n';
1817             else {
1818                 sym = 'y';
1819                 if (yn_number < otmp->quan && splittable(otmp))
1820                     otmp = splitobj(otmp, yn_number);
1821             }
1822         }
1823         switch (sym) {
1824         case 'a':
1825             allflag = 1;
1826         case 'y':
1827             tmp = (*fn)(otmp);
1828             if (tmp < 0) {
1829                 if (container_gone(fn)) {
1830                     /* otmp caused magic bag to explode;
1831                        both are now gone */
1832                     otmp = 0; /* and return */
1833                 } else if (otmp && otmp != otmpo) {
1834                     /* split occurred, merge again */
1835                     (void) merged(&otmpo, &otmp);
1836                 }
1837                 goto ret;
1838             }
1839             cnt += tmp;
1840             if (--mx == 0)
1841                 goto ret;
1842         case 'n':
1843             if (nodot)
1844                 dud++;
1845         default:
1846             break;
1847         case 'q':
1848             /* special case for seffects() */
1849             if (ident)
1850                 cnt = -1;
1851             goto ret;
1852         }
1853     }
1854     if (olets && *olets && *++olets)
1855         goto nextclass;
1856     if (!takeoff && (dud || cnt))
1857 /*JP
1858         pline("That was all.");
1859 */
1860         pline("\82±\82ê\82Å\91S\95\94\82¾\81D");
1861     else if (!dud && !cnt)
1862 /*JP
1863         pline("No applicable objects.");
1864 */
1865         pline("\82»\82ê\82Í\82Å\82«\82È\82¢\81D");
1866 ret:
1867     bypass_objlist(*objchn, FALSE);
1868     return cnt;
1869 }
1870
1871 /*
1872  *      Object identification routines:
1873  */
1874
1875 /* make an object actually be identified; no display updating */
1876 void
1877 fully_identify_obj(otmp)
1878 struct obj *otmp;
1879 {
1880     makeknown(otmp->otyp);
1881     if (otmp->oartifact)
1882         discover_artifact((xchar) otmp->oartifact);
1883     otmp->known = otmp->dknown = otmp->bknown = otmp->rknown = 1;
1884     if (Is_container(otmp) || otmp->otyp == STATUE)
1885         otmp->cknown = otmp->lknown = 1;
1886     if (otmp->otyp == EGG && otmp->corpsenm != NON_PM)
1887         learn_egg_type(otmp->corpsenm);
1888 }
1889
1890 /* ggetobj callback routine; identify an object and give immediate feedback */
1891 int
1892 identify(otmp)
1893 struct obj *otmp;
1894 {
1895     fully_identify_obj(otmp);
1896     prinv((char *) 0, otmp, 0L);
1897     return 1;
1898 }
1899
1900 /* menu of unidentified objects; select and identify up to id_limit of them */
1901 STATIC_OVL void
1902 menu_identify(id_limit)
1903 int id_limit;
1904 {
1905     menu_item *pick_list;
1906     int n, i, first = 1, tryct = 5;
1907     char buf[BUFSZ];
1908     /* assumptions:  id_limit > 0 and at least one unID'd item is present */
1909
1910     while (id_limit) {
1911 #if 0 /*JP:T*/
1912         Sprintf(buf, "What would you like to identify %s?",
1913                 first ? "first" : "next");
1914 #else
1915         Sprintf(buf, "\82Ç\82ê\82ð%s\82É\8e¯\95Ê\82µ\82Ü\82·\82©\81H",
1916                 first ? "\8dÅ\8f\89" : "\8e\9f");
1917 #endif
1918         n = query_objlist(buf, invent, SIGNAL_NOMENU | SIGNAL_ESCAPE
1919                                            | USE_INVLET | INVORDER_SORT,
1920                           &pick_list, PICK_ANY, not_fully_identified);
1921
1922         if (n > 0) {
1923             if (n > id_limit)
1924                 n = id_limit;
1925             for (i = 0; i < n; i++, id_limit--)
1926                 (void) identify(pick_list[i].item.a_obj);
1927             free((genericptr_t) pick_list);
1928             mark_synch(); /* Before we loop to pop open another menu */
1929             first = 0;
1930         } else if (n == -2) { /* player used ESC to quit menu */
1931             break;
1932         } else if (n == -1) { /* no eligible items found */
1933 /*JP
1934             pline("That was all.");
1935 */
1936             pline("\82±\82ê\82Å\91S\95\94\82¾\81D");
1937             break;
1938         } else if (!--tryct) { /* stop re-prompting */
1939             pline1(thats_enough_tries);
1940             break;
1941         } else { /* try again */
1942             pline("Choose an item; use ESC to decline.");
1943         }
1944     }
1945 }
1946
1947 /* dialog with user to identify a given number of items; 0 means all */
1948 void
1949 identify_pack(id_limit, learning_id)
1950 int id_limit;
1951 boolean learning_id; /* true if we just read unknown identify scroll */
1952 {
1953     struct obj *obj, *the_obj;
1954     int n, unid_cnt;
1955
1956     unid_cnt = 0;
1957     the_obj = 0; /* if unid_cnt ends up 1, this will be it */
1958     for (obj = invent; obj; obj = obj->nobj)
1959         if (not_fully_identified(obj))
1960             ++unid_cnt, the_obj = obj;
1961
1962     if (!unid_cnt) {
1963 #if 0 /*JP:T*/
1964         You("have already identified all %sof your possessions.",
1965             learning_id ? "the rest " : "");
1966 #else
1967         You("%s\91S\82Ä\82Ì\8f\8a\97L\95¨\82ð\8e¯\95Ê\82µ\82Ä\82µ\82Ü\82Á\82Ä\82¢\82é\81D",
1968             learning_id ? "\8ec\82è" : "");
1969 #endif
1970     } else if (!id_limit || id_limit >= unid_cnt) {
1971         /* identify everything */
1972         if (unid_cnt == 1) {
1973             (void) identify(the_obj);
1974         } else {
1975             /* TODO:  use fully_identify_obj and cornline/menu/whatever here
1976              */
1977             for (obj = invent; obj; obj = obj->nobj)
1978                 if (not_fully_identified(obj))
1979                     (void) identify(obj);
1980         }
1981     } else {
1982         /* identify up to `id_limit' items */
1983         n = 0;
1984         if (flags.menu_style == MENU_TRADITIONAL)
1985             do {
1986                 n = ggetobj("identify", identify, id_limit, FALSE,
1987                             (unsigned *) 0);
1988                 if (n < 0)
1989                     break; /* quit or no eligible items */
1990             } while ((id_limit -= n) > 0);
1991         if (n == 0 || n < -1)
1992             menu_identify(id_limit);
1993     }
1994     update_inventory();
1995 }
1996
1997 /* called when regaining sight; mark inventory objects which were picked
1998    up while blind as now having been seen */
1999 void
2000 learn_unseen_invent()
2001 {
2002     struct obj *otmp;
2003
2004     if (Blind)
2005         return; /* sanity check */
2006
2007     for (otmp = invent; otmp; otmp = otmp->nobj) {
2008         if (otmp->dknown)
2009             continue; /* already seen */
2010         /* set dknown, perhaps bknown (for priest[ess]) */
2011         (void) xname(otmp);
2012         /*
2013          * If object->eknown gets implemented (see learnwand(zap.c)),
2014          * handle deferred discovery here.
2015          */
2016     }
2017     update_inventory();
2018 }
2019
2020 /* should of course only be called for things in invent */
2021 STATIC_OVL char
2022 obj_to_let(obj)
2023 struct obj *obj;
2024 {
2025     if (!flags.invlet_constant) {
2026         obj->invlet = NOINVSYM;
2027         reassign();
2028     }
2029     return obj->invlet;
2030 }
2031
2032 /*
2033  * Print the indicated quantity of the given object.  If quan == 0L then use
2034  * the current quantity.
2035  */
2036 void
2037 prinv(prefix, obj, quan)
2038 const char *prefix;
2039 struct obj *obj;
2040 long quan;
2041 {
2042     if (!prefix)
2043         prefix = "";
2044 #if 0 /*JP*/
2045     pline("%s%s%s", prefix, *prefix ? " " : "",
2046           xprname(obj, (char *) 0, obj_to_let(obj), TRUE, 0L, quan));
2047 #else
2048     pline("%s%s",
2049           xprname(obj, (char *)0, obj_to_let(obj), *prefix ? FALSE : TRUE, 0L, quan),
2050           prefix);
2051 #endif
2052 }
2053
2054 char *
2055 xprname(obj, txt, let, dot, cost, quan)
2056 struct obj *obj;
2057 const char *txt; /* text to print instead of obj */
2058 char let;        /* inventory letter */
2059 boolean dot;     /* append period; (dot && cost => Iu) */
2060 long cost;       /* cost (for inventory of unpaid or expended items) */
2061 long quan;       /* if non-0, print this quantity, not obj->quan */
2062 {
2063 #ifdef LINT /* handle static char li[BUFSZ]; */
2064     char li[BUFSZ];
2065 #else
2066     static char li[BUFSZ];
2067 #endif
2068     boolean use_invlet = flags.invlet_constant && let != CONTAINED_SYM;
2069     long savequan = 0;
2070
2071     if (quan && obj) {
2072         savequan = obj->quan;
2073         obj->quan = quan;
2074     }
2075
2076     /*
2077      * If let is:
2078      *  *  Then obj == null and we are printing a total amount.
2079      *  >  Then the object is contained and doesn't have an inventory letter.
2080      */
2081     if (cost != 0 || let == '*') {
2082         /* if dot is true, we're doing Iu, otherwise Ix */
2083 #if 0 /*JP*/
2084         Sprintf(li, "%c - %-45s %6ld %s",
2085 #else
2086         Sprintf(li, "%c - %-45s %6ld%s",
2087 #endif
2088                 (dot && use_invlet ? obj->invlet : let),
2089                 (txt ? txt : doname(obj)), cost, currency(cost));
2090     } else {
2091         /* ordinary inventory display or pickup message */
2092         Sprintf(li, "%c - %s%s", (use_invlet ? obj->invlet : let),
2093 /*JP
2094                 (txt ? txt : doname(obj)), (dot ? "." : ""));
2095 */
2096                 (txt ? txt : doname(obj)), (dot ? "\81D" : ""));
2097     }
2098     if (savequan)
2099         obj->quan = savequan;
2100
2101     return li;
2102 }
2103
2104 /* the 'i' command */
2105 int
2106 ddoinv()
2107 {
2108     (void) display_inventory((char *) 0, FALSE);
2109     return 0;
2110 }
2111
2112 /*
2113  * find_unpaid()
2114  *
2115  * Scan the given list of objects.  If last_found is NULL, return the first
2116  * unpaid object found.  If last_found is not NULL, then skip over unpaid
2117  * objects until last_found is reached, then set last_found to NULL so the
2118  * next unpaid object is returned.  This routine recursively follows
2119  * containers.
2120  */
2121 STATIC_OVL struct obj *
2122 find_unpaid(list, last_found)
2123 struct obj *list, **last_found;
2124 {
2125     struct obj *obj;
2126
2127     while (list) {
2128         if (list->unpaid) {
2129             if (*last_found) {
2130                 /* still looking for previous unpaid object */
2131                 if (list == *last_found)
2132                     *last_found = (struct obj *) 0;
2133             } else
2134                 return ((*last_found = list));
2135         }
2136         if (Has_contents(list)) {
2137             if ((obj = find_unpaid(list->cobj, last_found)) != 0)
2138                 return obj;
2139         }
2140         list = list->nobj;
2141     }
2142     return (struct obj *) 0;
2143 }
2144
2145 /* for perm_invent when operating on a partial inventory display, so that
2146    the persistent one doesn't get shrunk during filtering for item selection
2147    then regrown to full inventory, possibly being resized in the process */
2148 static winid cached_pickinv_win = WIN_ERR;
2149
2150 void
2151 free_pickinv_cache()
2152 {
2153     if (cached_pickinv_win != WIN_ERR) {
2154         destroy_nhwindow(cached_pickinv_win);
2155         cached_pickinv_win = WIN_ERR;
2156     }
2157 }
2158
2159 /*
2160  * Internal function used by display_inventory and getobj that can display
2161  * inventory and return a count as well as a letter. If out_cnt is not null,
2162  * any count returned from the menu selection is placed here.
2163  */
2164 STATIC_OVL char
2165 display_pickinv(lets, want_reply, out_cnt)
2166 register const char *lets;
2167 boolean want_reply;
2168 long *out_cnt;
2169 {
2170     struct obj *otmp;
2171     char ilet, ret;
2172     char *invlet = flags.inv_order;
2173     int i, n, classcount;
2174     winid win;                        /* windows being used */
2175     anything any;
2176     menu_item *selected;
2177     struct obj **oarray;
2178
2179     if (flags.perm_invent && lets && *lets) {
2180         /* partial inventory in perm_invent setting; don't operate on
2181            full inventory window, use an alternate one instead; create
2182            the first time needed and keep it for re-use as needed later */
2183         if (cached_pickinv_win == WIN_ERR)
2184             cached_pickinv_win = create_nhwindow(NHW_MENU);
2185         win = cached_pickinv_win;
2186     } else
2187         win = WIN_INVEN;
2188
2189     /*
2190      * Exit early if no inventory -- but keep going if we are doing
2191      * a permanent inventory update.  We need to keep going so the
2192      * permanent inventory window updates itself to remove the last
2193      * item(s) dropped.  One down side:  the addition of the exception
2194      * for permanent inventory window updates _can_ pop the window
2195      * up when it's not displayed -- even if it's empty -- because we
2196      * don't know at this level if its up or not.  This may not be
2197      * an issue if empty checks are done before hand and the call
2198      * to here is short circuited away.
2199      */
2200     if (!invent && !(flags.perm_invent && !lets && !want_reply)) {
2201 /*JP
2202         pline("Not carrying anything.");
2203 */
2204         pline("\89½\82à\8e\9d\82Á\82Ä\82¢\82È\82¢\81D");
2205         return 0;
2206     }
2207
2208     /* oxymoron? temporarily assign permanent inventory letters */
2209     if (!flags.invlet_constant)
2210         reassign();
2211
2212     if (lets && strlen(lets) == 1 && !iflags.override_ID) {
2213         /* when only one item of interest, use pline instead of menus;
2214            we actually use a fake message-line menu in order to allow
2215            the user to perform selection at the --More-- prompt for tty */
2216         ret = '\0';
2217         for (otmp = invent; otmp; otmp = otmp->nobj) {
2218             if (otmp->invlet == lets[0]) {
2219                 ret = message_menu(
2220                     lets[0], want_reply ? PICK_ONE : PICK_NONE,
2221                     xprname(otmp, (char *) 0, lets[0], TRUE, 0L, 0L));
2222                 if (out_cnt)
2223                     *out_cnt = -1L; /* select all */
2224                 break;
2225             }
2226         }
2227         return ret;
2228     }
2229
2230     /* count the number of items */
2231     for (n = 0, otmp = invent; otmp; otmp = otmp->nobj)
2232         if (!lets || !*lets || index(lets, otmp->invlet))
2233             n++;
2234
2235     oarray = objarr_init(n);
2236
2237     /* Add objects to the array */
2238     i = 0;
2239     for (otmp = invent; otmp; otmp = otmp->nobj)
2240         if (!lets || !*lets || index(lets, otmp->invlet)) {
2241             objarr_set(otmp, i++, oarray, (flags.sortloot == 'f'));
2242         }
2243
2244     start_menu(win);
2245     any = zeroany;
2246     if (wizard && iflags.override_ID) {
2247         char prompt[BUFSZ];
2248         any.a_char = -1;
2249         /* wiz_identify stuffed the wiz_identify cmd character
2250            into iflags.override_ID */
2251         Sprintf(prompt, "Debug Identify (%s to permanently identify)",
2252                 visctrl(iflags.override_ID));
2253         add_menu(win, NO_GLYPH, &any, '_', iflags.override_ID, ATR_NONE,
2254                  prompt, MENU_UNSELECTED);
2255     }
2256 nextclass:
2257     classcount = 0;
2258     any = zeroany; /* set all bits to zero */
2259     for (i = 0; i < n; i++) {
2260         otmp = oarray[i];
2261         ilet = otmp->invlet;
2262         any = zeroany; /* zero */
2263         if (!flags.sortpack || otmp->oclass == *invlet) {
2264             if (flags.sortpack && !classcount) {
2265                 add_menu(win, NO_GLYPH, &any, 0, 0, iflags.menu_headings,
2266                          let_to_name(*invlet, FALSE,
2267                                      (want_reply && iflags.menu_head_objsym)),
2268                          MENU_UNSELECTED);
2269                 classcount++;
2270             }
2271             any.a_char = ilet;
2272             add_menu(win, obj_to_glyph(otmp), &any, ilet, 0, ATR_NONE,
2273                      doname(otmp), MENU_UNSELECTED);
2274         }
2275     }
2276     if (flags.sortpack) {
2277         if (*++invlet)
2278             goto nextclass;
2279         if (--invlet != venom_inv) {
2280             invlet = venom_inv;
2281             goto nextclass;
2282         }
2283     }
2284     free(oarray);
2285     end_menu(win, (char *) 0);
2286
2287     n = select_menu(win, want_reply ? PICK_ONE : PICK_NONE, &selected);
2288     if (n > 0) {
2289         ret = selected[0].item.a_char;
2290         if (out_cnt)
2291             *out_cnt = selected[0].count;
2292         free((genericptr_t) selected);
2293     } else
2294         ret = !n ? '\0' : '\033'; /* cancelled */
2295
2296     return ret;
2297 }
2298
2299 /*
2300  * If lets == NULL or "", list all objects in the inventory.  Otherwise,
2301  * list all objects with object classes that match the order in lets.
2302  *
2303  * Returns the letter identifier of a selected item, or 0 if nothing
2304  * was selected.
2305  */
2306 char
2307 display_inventory(lets, want_reply)
2308 const char *lets;
2309 boolean want_reply;
2310 {
2311     return display_pickinv(lets, want_reply, (long *) 0);
2312 }
2313
2314 /*
2315  * Show what is current using inventory letters.
2316  *
2317  */
2318 STATIC_OVL char
2319 display_used_invlets(avoidlet)
2320 char avoidlet;
2321 {
2322     struct obj *otmp;
2323     char ilet, ret = 0;
2324     char *invlet = flags.inv_order;
2325     int n, classcount, invdone = 0;
2326     winid win;
2327     anything any;
2328     menu_item *selected;
2329
2330     if (invent) {
2331         win = create_nhwindow(NHW_MENU);
2332         start_menu(win);
2333         while (!invdone) {
2334             any = zeroany; /* set all bits to zero */
2335             classcount = 0;
2336             for (otmp = invent; otmp; otmp = otmp->nobj) {
2337                 ilet = otmp->invlet;
2338                 if (ilet == avoidlet)
2339                     continue;
2340                 if (!flags.sortpack || otmp->oclass == *invlet) {
2341                     if (flags.sortpack && !classcount) {
2342                         any = zeroany; /* zero */
2343                         add_menu(win, NO_GLYPH, &any, 0, 0,
2344                                  iflags.menu_headings,
2345                                  let_to_name(*invlet, FALSE, FALSE),
2346                                  MENU_UNSELECTED);
2347                         classcount++;
2348                     }
2349                     any.a_char = ilet;
2350                     add_menu(win, obj_to_glyph(otmp), &any, ilet, 0, ATR_NONE,
2351                              doname(otmp), MENU_UNSELECTED);
2352                 }
2353             }
2354             if (flags.sortpack && *++invlet)
2355                 continue;
2356             invdone = 1;
2357         }
2358         end_menu(win, "Inventory letters used:");
2359
2360         n = select_menu(win, PICK_NONE, &selected);
2361         if (n > 0) {
2362             ret = selected[0].item.a_char;
2363             free((genericptr_t) selected);
2364         } else
2365             ret = !n ? '\0' : '\033'; /* cancelled */
2366         destroy_nhwindow(win);
2367     }
2368     return ret;
2369 }
2370
2371 /*
2372  * Returns the number of unpaid items within the given list.  This includes
2373  * contained objects.
2374  */
2375 int
2376 count_unpaid(list)
2377 struct obj *list;
2378 {
2379     int count = 0;
2380
2381     while (list) {
2382         if (list->unpaid)
2383             count++;
2384         if (Has_contents(list))
2385             count += count_unpaid(list->cobj);
2386         list = list->nobj;
2387     }
2388     return count;
2389 }
2390
2391 /*
2392  * Returns the number of items with b/u/c/unknown within the given list.
2393  * This does NOT include contained objects.
2394  *
2395  * Assumes that the hero sees or touches or otherwise senses the objects
2396  * at some point:  bknown is forced for priest[ess], like in xname().
2397  */
2398 int
2399 count_buc(list, type)
2400 struct obj *list;
2401 int type;
2402 {
2403     int count = 0;
2404
2405     for (; list; list = list->nobj) {
2406         /* coins are "none of the above" as far as BUCX filtering goes */
2407         if (list->oclass == COIN_CLASS)
2408             continue;
2409         /* priests always know bless/curse state */
2410         if (Role_if(PM_PRIEST))
2411             list->bknown = 1;
2412
2413         /* check whether this object matches the requested type */
2414         if (!list->bknown
2415                 ? (type == BUC_UNKNOWN)
2416                 : list->blessed ? (type == BUC_BLESSED)
2417                                 : list->cursed ? (type == BUC_CURSED)
2418                                                : (type == BUC_UNCURSED))
2419             ++count;
2420     }
2421     return count;
2422 }
2423
2424 /* similar to count_buc(), but tallies all states at once
2425    rather than looking for a specific type */
2426 STATIC_OVL void
2427 tally_BUCX(list, bcp, ucp, ccp, xcp, ocp)
2428 struct obj *list;
2429 int *bcp, *ucp, *ccp, *xcp, *ocp;
2430 {
2431     *bcp = *ucp = *ccp = *xcp = *ocp = 0;
2432     for (; list; list = list->nobj) {
2433         if (list->oclass == COIN_CLASS) {
2434             ++(*ocp); /* "other" */
2435             continue;
2436         }
2437         /* priests always know bless/curse state */
2438         if (Role_if(PM_PRIEST))
2439             list->bknown = 1;
2440
2441         if (!list->bknown)
2442             ++(*xcp);
2443         else if (list->blessed)
2444             ++(*bcp);
2445         else if (list->cursed)
2446             ++(*ccp);
2447         else /* neither blessed nor cursed => uncursed */
2448             ++(*ucp);
2449     }
2450 }
2451
2452 long
2453 count_contents(container, nested, quantity, everything)
2454 struct obj *container;
2455 boolean nested, /* include contents of any nested containers */
2456     quantity,   /* count all vs count separate stacks */
2457     everything; /* all objects vs only unpaid objects */
2458 {
2459     struct obj *otmp;
2460     long count = 0L;
2461
2462     for (otmp = container->cobj; otmp; otmp = otmp->nobj) {
2463         if (nested && Has_contents(otmp))
2464             count += count_contents(otmp, nested, quantity, everything);
2465         if (everything || otmp->unpaid)
2466             count += quantity ? otmp->quan : 1L;
2467     }
2468     return count;
2469 }
2470
2471 STATIC_OVL void
2472 dounpaid()
2473 {
2474     winid win;
2475     struct obj *otmp, *marker;
2476     register char ilet;
2477     char *invlet = flags.inv_order;
2478     int classcount, count, num_so_far;
2479     long cost, totcost;
2480
2481     count = count_unpaid(invent);
2482
2483     if (count == 1) {
2484         marker = (struct obj *) 0;
2485         otmp = find_unpaid(invent, &marker);
2486         cost = unpaid_cost(otmp, FALSE);
2487         iflags.suppress_price++; /* suppress "(unpaid)" suffix */
2488         pline1(xprname(otmp, distant_name(otmp, doname),
2489                        carried(otmp) ? otmp->invlet : CONTAINED_SYM, TRUE,
2490                        cost, 0L));
2491         iflags.suppress_price--;
2492         return;
2493     }
2494
2495     win = create_nhwindow(NHW_MENU);
2496     cost = totcost = 0;
2497     num_so_far = 0; /* count of # printed so far */
2498     if (!flags.invlet_constant)
2499         reassign();
2500
2501     do {
2502         classcount = 0;
2503         for (otmp = invent; otmp; otmp = otmp->nobj) {
2504             ilet = otmp->invlet;
2505             if (otmp->unpaid) {
2506                 if (!flags.sortpack || otmp->oclass == *invlet) {
2507                     if (flags.sortpack && !classcount) {
2508                         putstr(win, 0, let_to_name(*invlet, TRUE, FALSE));
2509                         classcount++;
2510                     }
2511
2512                     totcost += cost = unpaid_cost(otmp, FALSE);
2513                     iflags.suppress_price++; /* suppress "(unpaid)" suffix */
2514                     putstr(win, 0, xprname(otmp, distant_name(otmp, doname),
2515                                            ilet, TRUE, cost, 0L));
2516                     iflags.suppress_price--;
2517                     num_so_far++;
2518                 }
2519             }
2520         }
2521     } while (flags.sortpack && (*++invlet));
2522
2523     if (count > num_so_far) {
2524         /* something unpaid is contained */
2525         if (flags.sortpack)
2526             putstr(win, 0, let_to_name(CONTAINED_SYM, TRUE, FALSE));
2527         /*
2528          * Search through the container objects in the inventory for
2529          * unpaid items.  The top level inventory items have already
2530          * been listed.
2531          */
2532         for (otmp = invent; otmp; otmp = otmp->nobj) {
2533             if (Has_contents(otmp)) {
2534                 long contcost = 0L;
2535
2536                 marker = (struct obj *) 0; /* haven't found any */
2537                 while (find_unpaid(otmp->cobj, &marker)) {
2538                     totcost += cost = unpaid_cost(marker, FALSE);
2539                     contcost += cost;
2540                     if (otmp->cknown) {
2541                         iflags.suppress_price++; /* suppress "(unpaid)" sfx */
2542                         putstr(win, 0,
2543                                xprname(marker, distant_name(marker, doname),
2544                                        CONTAINED_SYM, TRUE, cost, 0L));
2545                         iflags.suppress_price--;
2546                     }
2547                 }
2548                 if (!otmp->cknown) {
2549                     char contbuf[BUFSZ];
2550
2551                     /* Shopkeeper knows what to charge for contents */
2552                     Sprintf(contbuf, "%s contents", s_suffix(xname(otmp)));
2553                     putstr(win, 0,
2554                            xprname((struct obj *) 0, contbuf, CONTAINED_SYM,
2555                                    TRUE, contcost, 0L));
2556                 }
2557             }
2558         }
2559     }
2560
2561     putstr(win, 0, "");
2562 #if 0 /*JP*/
2563     putstr(win, 0,
2564            xprname((struct obj *) 0, "Total:", '*', FALSE, totcost, 0L));
2565 #else
2566     putstr(win, 0,
2567            xprname((struct obj *) 0, "\8d\87\8cv\81F", '*', FALSE, totcost, 0L));
2568 #endif
2569     display_nhwindow(win, FALSE);
2570     destroy_nhwindow(win);
2571 }
2572
2573 /* query objlist callback: return TRUE if obj type matches "this_type" */
2574 static int this_type;
2575
2576 STATIC_OVL boolean
2577 this_type_only(obj)
2578 struct obj *obj;
2579 {
2580     boolean res = (obj->oclass == this_type);
2581
2582     if (obj->oclass != COIN_CLASS) {
2583         switch (this_type) {
2584         case 'B':
2585             res = (obj->bknown && obj->blessed);
2586             break;
2587         case 'U':
2588             res = (obj->bknown && !(obj->blessed || obj->cursed));
2589             break;
2590         case 'C':
2591             res = (obj->bknown && obj->cursed);
2592             break;
2593         case 'X':
2594             res = !obj->bknown;
2595             break;
2596         default:
2597             break; /* use 'res' as-is */
2598         }
2599     }
2600     return res;
2601 }
2602
2603 /* the 'I' command */
2604 int
2605 dotypeinv()
2606 {
2607     char c = '\0';
2608     int n, i = 0;
2609     char *extra_types, types[BUFSZ];
2610     int class_count, oclass, unpaid_count, itemcount;
2611     int bcnt, ccnt, ucnt, xcnt, ocnt;
2612     boolean billx = *u.ushops && doinvbill(0);
2613     menu_item *pick_list;
2614     boolean traditional = TRUE;
2615 /*JP
2616     const char *prompt = "What type of object do you want an inventory of?";
2617 */
2618     const char *prompt = "\82Ç\82Ì\8eí\97Þ\82Ì\8e\9d\82¿\95¨\82ð\8c©\82Ü\82·\82©\81H";
2619
2620     if (!invent && !billx) {
2621 /*JP
2622         You("aren't carrying anything.");
2623 */
2624         You("\82»\82Ì\8eí\97Þ\82Ì\95¨\82Í\89½\82à\8e\9d\82Á\82Ä\82¢\82È\82¢\81D");
2625         return 0;
2626     }
2627     unpaid_count = count_unpaid(invent);
2628     tally_BUCX(invent, &bcnt, &ucnt, &ccnt, &xcnt, &ocnt);
2629
2630     if (flags.menu_style != MENU_TRADITIONAL) {
2631         if (flags.menu_style == MENU_FULL
2632             || flags.menu_style == MENU_PARTIAL) {
2633             traditional = FALSE;
2634             i = UNPAID_TYPES;
2635             if (billx)
2636                 i |= BILLED_TYPES;
2637             if (bcnt)
2638                 i |= BUC_BLESSED;
2639             if (ucnt)
2640                 i |= BUC_UNCURSED;
2641             if (ccnt)
2642                 i |= BUC_CURSED;
2643             if (xcnt)
2644                 i |= BUC_UNKNOWN;
2645             n = query_category(prompt, invent, i, &pick_list, PICK_ONE);
2646             if (!n)
2647                 return 0;
2648             this_type = c = pick_list[0].item.a_int;
2649             free((genericptr_t) pick_list);
2650         }
2651     }
2652     if (traditional) {
2653         /* collect a list of classes of objects carried, for use as a prompt
2654          */
2655         types[0] = 0;
2656         class_count =
2657             collect_obj_classes(types, invent, FALSE,
2658                                 (boolean FDECL((*), (OBJ_P))) 0, &itemcount);
2659         if (unpaid_count || billx || (bcnt + ccnt + ucnt + xcnt) != 0)
2660             types[class_count++] = ' ';
2661         if (unpaid_count)
2662             types[class_count++] = 'u';
2663         if (billx)
2664             types[class_count++] = 'x';
2665         if (bcnt)
2666             types[class_count++] = 'B';
2667         if (ucnt)
2668             types[class_count++] = 'U';
2669         if (ccnt)
2670             types[class_count++] = 'C';
2671         if (xcnt)
2672             types[class_count++] = 'X';
2673         types[class_count] = '\0';
2674         /* add everything not already included; user won't see these */
2675         extra_types = eos(types);
2676         *extra_types++ = '\033';
2677         if (!unpaid_count)
2678             *extra_types++ = 'u';
2679         if (!billx)
2680             *extra_types++ = 'x';
2681         if (!bcnt)
2682             *extra_types++ = 'B';
2683         if (!ucnt)
2684             *extra_types++ = 'U';
2685         if (!ccnt)
2686             *extra_types++ = 'C';
2687         if (!xcnt)
2688             *extra_types++ = 'X';
2689         *extra_types = '\0'; /* for index() */
2690         for (i = 0; i < MAXOCLASSES; i++)
2691             if (!index(types, def_oc_syms[i].sym)) {
2692                 *extra_types++ = def_oc_syms[i].sym;
2693                 *extra_types = '\0';
2694             }
2695
2696         if (class_count > 1) {
2697             c = yn_function(prompt, types, '\0');
2698             savech(c);
2699             if (c == '\0') {
2700                 clear_nhwindow(WIN_MESSAGE);
2701                 return 0;
2702             }
2703         } else {
2704             /* only one thing to itemize */
2705             if (unpaid_count)
2706                 c = 'u';
2707             else if (billx)
2708                 c = 'x';
2709             else
2710                 c = types[0];
2711         }
2712     }
2713     if (c == 'x' || (c == 'X' && billx && !xcnt)) {
2714         if (billx)
2715             (void) doinvbill(1);
2716         else
2717 #if 0 /*JP*/
2718             pline("No used-up objects%s.",
2719                   unpaid_count ? " on your shopping bill" : "");
2720 #else
2721           pline("\8eg\82Á\82Ä\82µ\82Ü\82Á\82½\95¨\82Í%s\82È\82¢\81D",
2722                   unpaid_count ? "\8f¤\93X\82Ì\90¿\8b\81\8f\91\82É\82Í" : "");
2723 #endif
2724         return 0;
2725     }
2726     if (c == 'u' || (c == 'U' && unpaid_count && !ucnt)) {
2727         if (unpaid_count)
2728             dounpaid();
2729         else
2730 /*JP
2731             You("are not carrying any unpaid objects.");
2732 */
2733             You("\96¢\95¥\82¢\82Ì\83A\83C\83e\83\80\82ð\8e\9d\82Á\82Ä\82¢\82È\82¢\81D");
2734         return 0;
2735     }
2736     if (traditional) {
2737         if (index("BUCX", c))
2738             oclass = c; /* not a class but understood by this_type_only() */
2739         else
2740             oclass = def_char_to_objclass(c); /* change to object class */
2741
2742         if (oclass == COIN_CLASS)
2743             return doprgold();
2744         if (index(types, c) > index(types, '\033')) {
2745             /* '> ESC' => hidden choice, something known not to be carried */
2746             const char *which = 0;
2747
2748             switch (c) {
2749             case 'B':
2750                 which = "known to be blessed";
2751                 break;
2752             case 'U':
2753                 which = "known to be uncursed";
2754                 break;
2755             case 'C':
2756                 which = "known to be cursed";
2757                 break;
2758             case 'X':
2759                 You(
2760           "have no objects whose blessed/uncursed/cursed status is unknown.");
2761                 break; /* better phrasing is desirable */
2762             default:
2763 /*JP
2764                 which = "such";
2765 */
2766                 which = "\82»\82Ì\82æ\82¤\82È";
2767                 break;
2768             }
2769             if (which)
2770 /*JP
2771                 You("have no %s objects.", which);
2772 */
2773                 You("%s\82à\82Ì\82Í\89½\82à\8e\9d\82Á\82Ä\82¢\82È\82¢\81D", which);
2774             return 0;
2775         }
2776         this_type = oclass;
2777     }
2778     if (query_objlist((char *) 0, invent,
2779                       (flags.invlet_constant ? USE_INVLET : 0)
2780                           | INVORDER_SORT,
2781                       &pick_list, PICK_NONE, this_type_only) > 0)
2782         free((genericptr_t) pick_list);
2783     return 0;
2784 }
2785
2786 /* return a string describing the dungeon feature at <x,y> if there
2787    is one worth mentioning at that location; otherwise null */
2788 const char *
2789 dfeature_at(x, y, buf)
2790 int x, y;
2791 char *buf;
2792 {
2793     struct rm *lev = &levl[x][y];
2794     int ltyp = lev->typ, cmap = -1;
2795     const char *dfeature = 0;
2796     static char altbuf[BUFSZ];
2797
2798     if (IS_DOOR(ltyp)) {
2799         switch (lev->doormask) {
2800         case D_NODOOR:
2801             cmap = S_ndoor;
2802             break; /* "doorway" */
2803         case D_ISOPEN:
2804             cmap = S_vodoor;
2805             break; /* "open door" */
2806         case D_BROKEN:
2807 /*JP
2808             dfeature = "broken door";
2809 */
2810             dfeature = "\89ó\82ê\82½\94à";
2811             break;
2812         default:
2813             cmap = S_vcdoor;
2814             break; /* "closed door" */
2815         }
2816         /* override door description for open drawbridge */
2817         if (is_drawbridge_wall(x, y) >= 0)
2818 /*JP
2819             dfeature = "open drawbridge portcullis", cmap = -1;
2820 */
2821             dfeature = "\8d~\82è\82Ä\82¢\82é\92µ\82Ë\8b´", cmap = -1;
2822     } else if (IS_FOUNTAIN(ltyp))
2823         cmap = S_fountain; /* "fountain" */
2824     else if (IS_THRONE(ltyp))
2825         cmap = S_throne; /* "opulent throne" */
2826     else if (is_lava(x, y))
2827         cmap = S_lava; /* "molten lava" */
2828     else if (is_ice(x, y))
2829         cmap = S_ice; /* "ice" */
2830     else if (is_pool(x, y))
2831 /*JP
2832         dfeature = "pool of water";
2833 */
2834         dfeature = "\90\85\82½\82Ü\82è";
2835     else if (IS_SINK(ltyp))
2836         cmap = S_sink; /* "sink" */
2837     else if (IS_ALTAR(ltyp)) {
2838 #if 0 /*JP*/
2839         Sprintf(altbuf, "%saltar to %s (%s)",
2840                 ((lev->altarmask & AM_SHRINE)
2841                  && (Is_astralevel(&u.uz) || Is_sanctum(&u.uz)))
2842                     ? "high "
2843                     : "",
2844                 a_gname(),
2845                 align_str(Amask2align(lev->altarmask & ~AM_SHRINE)));
2846 #else
2847         Sprintf(altbuf, "%s%s\82Ì\8dÕ\92d(%s)",
2848                 ((lev->altarmask & AM_SHRINE)
2849                  && (Is_astralevel(&u.uz) || Is_sanctum(&u.uz)))
2850                     ? "\8d\82\88Ê\82Ì"
2851                     : "",
2852                 a_gname(),
2853                 align_str(Amask2align(lev->altarmask & ~AM_SHRINE)));
2854 #endif
2855         dfeature = altbuf;
2856     } else if ((x == xupstair && y == yupstair)
2857                || (x == sstairs.sx && y == sstairs.sy && sstairs.up))
2858         cmap = S_upstair; /* "staircase up" */
2859     else if ((x == xdnstair && y == ydnstair)
2860              || (x == sstairs.sx && y == sstairs.sy && !sstairs.up))
2861         cmap = S_dnstair; /* "staircase down" */
2862     else if (x == xupladder && y == yupladder)
2863         cmap = S_upladder; /* "ladder up" */
2864     else if (x == xdnladder && y == ydnladder)
2865         cmap = S_dnladder; /* "ladder down" */
2866     else if (ltyp == DRAWBRIDGE_DOWN)
2867         cmap = S_vodbridge; /* "lowered drawbridge" */
2868     else if (ltyp == DBWALL)
2869         cmap = S_vcdbridge; /* "raised drawbridge" */
2870     else if (IS_GRAVE(ltyp))
2871         cmap = S_grave; /* "grave" */
2872     else if (ltyp == TREE)
2873         cmap = S_tree; /* "tree" */
2874     else if (ltyp == IRONBARS)
2875 /*JP
2876         dfeature = "set of iron bars";
2877 */
2878         dfeature = "\93S\82Ì\96_";
2879
2880     if (cmap >= 0)
2881         dfeature = defsyms[cmap].explanation;
2882     if (dfeature)
2883         Strcpy(buf, dfeature);
2884     return dfeature;
2885 }
2886
2887 /* look at what is here; if there are many objects (pile_limit or more),
2888    don't show them unless obj_cnt is 0 */
2889 int
2890 look_here(obj_cnt, picked_some)
2891 int obj_cnt; /* obj_cnt > 0 implies that autopickup is in progress */
2892 boolean picked_some;
2893 {
2894     struct obj *otmp;
2895     struct trap *trap;
2896 #if 0 /*JP:C*/
2897     const char *verb = Blind ? "feel" : "see";
2898 #else
2899     const char *verb = Blind ? "\82ª\82 \82é\82æ\82¤\82È\8bC\82ª\82µ\82½" : "\82ð\82Ý\82Â\82¯\82½";
2900 #endif
2901     const char *dfeature = (char *) 0;
2902     char fbuf[BUFSZ], fbuf2[BUFSZ];
2903     winid tmpwin;
2904     boolean skip_objects, felt_cockatrice = FALSE;
2905
2906     /* default pile_limit is 5; a value of 0 means "never skip"
2907        (and 1 effectively forces "always skip") */
2908     skip_objects = (flags.pile_limit > 0 && obj_cnt >= flags.pile_limit);
2909     if (u.uswallow && u.ustuck) {
2910         struct monst *mtmp = u.ustuck;
2911 #if 0 /*JP:T*/
2912         Sprintf(fbuf, "Contents of %s %s", s_suffix(mon_nam(mtmp)),
2913                 mbodypart(mtmp, STOMACH));
2914 #else
2915         Sprintf(fbuf, "%s\82Ì%s\82Ì\92\86\90g", mon_nam(mtmp),
2916                 mbodypart(mtmp, STOMACH));
2917 #endif
2918 #if 0 /*JP*//*\8cê\8f\87\82ª\88á\82¤\82Ì\82Å\91f\92¼\82É*/
2919         /* Skip "Contents of " by using fbuf index 12 */
2920         You("%s to %s what is lying in %s.", Blind ? "try" : "look around",
2921             verb, &fbuf[12]);
2922 #else
2923         You("%s\82Ì%s\82É\89½\82ª\82 \82é\82©%s\81D",
2924             mon_nam(mtmp), mbodypart(mtmp, STOMACH),
2925             Blind ? "\82³\82®\82Á\82½" : "\8c©\89ñ\82µ\82½");
2926 #endif
2927         otmp = mtmp->minvent;
2928         if (otmp) {
2929             for (; otmp; otmp = otmp->nobj) {
2930                 /* If swallower is an animal, it should have become stone
2931                  * but... */
2932                 if (otmp->otyp == CORPSE)
2933                     feel_cockatrice(otmp, FALSE);
2934             }
2935 #if 0 /*JP*/
2936             if (Blind)
2937                 Strcpy(fbuf, "You feel");
2938             Strcat(fbuf, ":");
2939 #else
2940             Sprintf(fbuf, "\82±\82±\82É\82 \82é%s\82à\82Ì\82Í\81F", Blind ? "\82ç\82µ\82¢" : "");
2941 #endif
2942             (void) display_minventory(mtmp, MINV_ALL, fbuf);
2943         } else {
2944 #if 0 /*JP:C*/
2945             You("%s no objects here.", verb);
2946 #else
2947             pline(Blind ? "\82 \82È\82½\82Í\89½\82à\82È\82¢\82æ\82¤\82È\8bC\82ª\82µ\82½\81D"
2948                   : "\82 \82È\82½\82Í\89½\82à\82Ý\82Â\82¯\82ç\82ê\82È\82©\82Á\82½\81D");
2949 #endif
2950         }
2951         return !!Blind;
2952     }
2953     if (!skip_objects && (trap = t_at(u.ux, u.uy)) && trap->tseen)
2954 /*JP
2955         There("is %s here.",
2956 */
2957         pline("\82±\82±\82É\82Í%s\82ª\82 \82é\81D",
2958               an(defsyms[trap_to_defsym(trap->ttyp)].explanation));
2959
2960     otmp = level.objects[u.ux][u.uy];
2961     dfeature = dfeature_at(u.ux, u.uy, fbuf2);
2962 /*JP
2963     if (dfeature && !strcmp(dfeature, "pool of water") && Underwater)
2964 */
2965     if (dfeature && !strcmp(dfeature, "\90\85\82½\82Ü\82è") && Underwater)
2966         dfeature = 0;
2967
2968     if (Blind) {
2969         boolean drift = Is_airlevel(&u.uz) || Is_waterlevel(&u.uz);
2970
2971 /*JP
2972         if (dfeature && !strncmp(dfeature, "altar ", 6)) {
2973 */
2974         if (dfeature && !strncmp(dfeature, "\8dÕ\92d", 4)) {
2975             /* don't say "altar" twice, dfeature has more info */
2976 /*JP
2977             You("try to feel what is here.");
2978 */
2979             You("\82±\82±\82É\89½\82ª\82 \82é\82Ì\82©\92²\82×\82æ\82¤\82Æ\82µ\82½\81D");
2980         } else {
2981 #if 0 /*JP*/
2982             const char *where = (Blind && !can_reach_floor(TRUE))
2983                                     ? "lying beneath you"
2984                                     : "lying here on the ",
2985                        *onwhat = (Blind && !can_reach_floor(TRUE))
2986                                      ? ""
2987                                      : surface(u.ux, u.uy);
2988
2989             You("try to feel what is %s%s.", drift ? "floating here" : where,
2990                 drift ? "" : onwhat);
2991 #else
2992             if (drift) {
2993                 You("\89½\82ª\95\82\82¢\82Ä\82¢\82é\82Ì\82©\92²\82×\82æ\82¤\82Æ\82µ\82½\81D");
2994             } else if (Blind && !can_reach_floor(TRUE)) {
2995                 You("\89½\82ª\91«\89º\82É\82 \82é\82Ì\82©\92²\82×\82æ\82¤\82Æ\82µ\82½\81D");
2996             } else {
2997                 You("\89½\82ª%s\82Ì\8fã\82É\82 \82é\82Ì\82©\92²\82×\82æ\82¤\82Æ\82µ\82½\81D", surface(u.ux, u.uy));
2998             }
2999 #endif
3000         }
3001         if (dfeature && !drift && !strcmp(dfeature, surface(u.ux, u.uy)))
3002             dfeature = 0; /* ice already identified */
3003         if (!can_reach_floor(TRUE)) {
3004 /*JP
3005             pline("But you can't reach it!");
3006 */
3007             pline("\82µ\82©\82µ\93Í\82©\82È\82¢\81I");
3008             return 0;
3009         }
3010     }
3011
3012     if (dfeature)
3013 /*JP
3014         Sprintf(fbuf, "There is %s here.", an(dfeature));
3015 */
3016         Sprintf(fbuf, "\82±\82±\82É\82Í%s\82ª\82 \82é\81D", an(dfeature));
3017
3018     if (!otmp || is_lava(u.ux, u.uy)
3019         || (is_pool(u.ux, u.uy) && !Underwater)) {
3020         if (dfeature)
3021             pline1(fbuf);
3022         read_engr_at(u.ux, u.uy); /* Eric Backus */
3023         if (!skip_objects && (Blind || !dfeature))
3024 #if 0 /*JP:C*/
3025             You("%s no objects here.", verb);
3026 #else
3027           pline(Blind ?
3028                 "\82È\82É\82à\82È\82¢\82æ\82¤\82È\8bC\82ª\82·\82é\81D" :
3029                 "\82È\82É\82à\82Ý\82Â\82¯\82ç\82ê\82È\82©\82Á\82½\81D");
3030 #endif
3031         return !!Blind;
3032     }
3033     /* we know there is something here */
3034
3035     if (skip_objects) {
3036         if (dfeature)
3037             pline1(fbuf);
3038         read_engr_at(u.ux, u.uy); /* Eric Backus */
3039         if (obj_cnt == 1 && otmp->quan == 1L)
3040             There("is %s object here.", picked_some ? "another" : "an");
3041         else
3042 #if 0 /*JP*/
3043             There("are %s%s objects here.",
3044                   (obj_cnt < 5)
3045                       ? "a few"
3046                       : (obj_cnt < 10)
3047                           ? "several"
3048                           : "many",
3049                   picked_some ? " more" : "");
3050 #else
3051             pline("\82±\82±\82É\82Í%s%s\82à\82Ì\82ª\82 \82é\81D",
3052                   picked_some ? "\82³\82ç\82É" : "",
3053                   (obj_cnt < 10)
3054                       ? "\82¢\82­\82Â\82©\82Ì"
3055                       : "\82½\82­\82³\82ñ\82Ì");
3056 #endif
3057         for (; otmp; otmp = otmp->nexthere)
3058             if (otmp->otyp == CORPSE && will_feel_cockatrice(otmp, FALSE)) {
3059                 pline("%s %s%s.",
3060                       (obj_cnt > 1)
3061                           ? "Including"
3062                           : (otmp->quan > 1L)
3063                               ? "They're"
3064                               : "It's",
3065                       corpse_xname(otmp, (const char *) 0, CXN_ARTICLE),
3066                       poly_when_stoned(youmonst.data)
3067                           ? ""
3068                           : ", unfortunately");
3069                 feel_cockatrice(otmp, FALSE);
3070                 break;
3071             }
3072     } else if (!otmp->nexthere) {
3073         /* only one object */
3074         if (dfeature)
3075             pline1(fbuf);
3076         read_engr_at(u.ux, u.uy); /* Eric Backus */
3077 /*JP
3078         You("%s here %s.", verb, doname_with_price(otmp));
3079 */
3080         pline("%s%s\81D", doname_with_price(otmp), verb);
3081         iflags.last_msg = PLNMSG_ONE_ITEM_HERE;
3082         if (otmp->otyp == CORPSE)
3083             feel_cockatrice(otmp, FALSE);
3084     } else {
3085         char buf[BUFSZ];
3086
3087         display_nhwindow(WIN_MESSAGE, FALSE);
3088         tmpwin = create_nhwindow(NHW_MENU);
3089         if (dfeature) {
3090             putstr(tmpwin, 0, fbuf);
3091             putstr(tmpwin, 0, "");
3092         }
3093 #if 0 /*JP*/
3094         Sprintf(buf, "%s that %s here:",
3095                 picked_some ? "Other things" : "Things",
3096                 Blind ? "you feel" : "are");
3097 #else
3098         Sprintf(buf, "%s\82±\82±\82É\82 \82é%s\82à\82Ì\82Í\81F",
3099                 picked_some ? "\91¼\82É" : "",
3100                 Blind ? "\82ç\82µ\82¢" : "");
3101 #endif
3102         putstr(tmpwin, 0, buf);
3103         for (; otmp; otmp = otmp->nexthere) {
3104             if (otmp->otyp == CORPSE && will_feel_cockatrice(otmp, FALSE)) {
3105                 felt_cockatrice = TRUE;
3106                 Sprintf(buf, "%s...", doname(otmp));
3107                 putstr(tmpwin, 0, buf);
3108                 break;
3109             }
3110             putstr(tmpwin, 0, doname_with_price(otmp));
3111         }
3112         display_nhwindow(tmpwin, TRUE);
3113         destroy_nhwindow(tmpwin);
3114         if (felt_cockatrice)
3115             feel_cockatrice(otmp, FALSE);
3116         read_engr_at(u.ux, u.uy); /* Eric Backus */
3117     }
3118     return !!Blind;
3119 }
3120
3121 /* the ':' command - explicitly look at what is here, including all objects */
3122 int
3123 dolook()
3124 {
3125     return look_here(0, FALSE);
3126 }
3127
3128 boolean
3129 will_feel_cockatrice(otmp, force_touch)
3130 struct obj *otmp;
3131 boolean force_touch;
3132 {
3133     if ((Blind || force_touch) && !uarmg && !Stone_resistance
3134         && (otmp->otyp == CORPSE && touch_petrifies(&mons[otmp->corpsenm])))
3135         return TRUE;
3136     return FALSE;
3137 }
3138
3139 void
3140 feel_cockatrice(otmp, force_touch)
3141 struct obj *otmp;
3142 boolean force_touch;
3143 {
3144     char kbuf[BUFSZ];
3145
3146     if (will_feel_cockatrice(otmp, force_touch)) {
3147         /* "the <cockatrice> corpse" */
3148         Strcpy(kbuf, corpse_xname(otmp, (const char *) 0, CXN_PFX_THE));
3149
3150         if (poly_when_stoned(youmonst.data))
3151 #if 0 /*JP*/
3152             You("touched %s with your bare %s.", kbuf,
3153                 makeplural(body_part(HAND)));
3154 #else
3155             You("%s\82Ì\8e\80\91Ì\82É\91f%s\82Å\90G\82Á\82½\81D", kbuf,
3156                 body_part(HAND));
3157 #endif
3158         else
3159 /*JP
3160             pline("Touching %s is a fatal mistake...", kbuf);
3161 */
3162             pline("%s\82Ì\8e\80\91Ì\82É\90G\82ê\82é\82Ì\82Í\92v\96½\93I\82È\8aÔ\88á\82¢\82¾\81D\81D\81D", kbuf);
3163         /* normalize body shape here; hand, not body_part(HAND) */
3164 /*JP
3165         Sprintf(kbuf, "touching %s bare-handed", killer_xname(otmp));
3166 */
3167         Sprintf(kbuf, "%s\82Ì\8e\80\91Ì\82É\90G\82ê\82Ä", killer_xname(otmp));
3168         /* will call polymon() for the poly_when_stoned() case */
3169         instapetrify(kbuf);
3170     }
3171 }
3172
3173 void
3174 stackobj(obj)
3175 struct obj *obj;
3176 {
3177     struct obj *otmp;
3178
3179     for (otmp = level.objects[obj->ox][obj->oy]; otmp; otmp = otmp->nexthere)
3180         if (otmp != obj && merged(&obj, &otmp))
3181             break;
3182     return;
3183 }
3184
3185 /* returns TRUE if obj  & otmp can be merged */
3186 STATIC_OVL boolean
3187 mergable(otmp, obj)
3188 register struct obj *otmp, *obj;
3189 {
3190     int objnamelth = 0, otmpnamelth = 0;
3191     if (obj == otmp)
3192         return FALSE; /* already the same object */
3193     if (obj->otyp != otmp->otyp)
3194         return FALSE;
3195     /* coins of the same kind will always merge */
3196     if (obj->oclass == COIN_CLASS)
3197         return TRUE;
3198     if (obj->unpaid != otmp->unpaid || obj->spe != otmp->spe
3199         || obj->dknown != otmp->dknown
3200         || (obj->bknown != otmp->bknown && !Role_if(PM_PRIEST))
3201         || obj->cursed != otmp->cursed || obj->blessed != otmp->blessed
3202         || obj->no_charge != otmp->no_charge || obj->obroken != otmp->obroken
3203         || obj->otrapped != otmp->otrapped || obj->lamplit != otmp->lamplit
3204         || obj->greased != otmp->greased || obj->oeroded != otmp->oeroded
3205         || obj->oeroded2 != otmp->oeroded2 || obj->bypass != otmp->bypass)
3206         return FALSE;
3207
3208     if (obj->nomerge) /* explicitly marked to prevent merge */
3209         return FALSE;
3210
3211     if ((obj->oclass == WEAPON_CLASS || obj->oclass == ARMOR_CLASS)
3212         && (obj->oerodeproof != otmp->oerodeproof
3213             || obj->rknown != otmp->rknown))
3214         return FALSE;
3215
3216     if (obj->oclass == FOOD_CLASS
3217         && (obj->oeaten != otmp->oeaten || obj->orotten != otmp->orotten))
3218         return FALSE;
3219
3220     if (obj->otyp == CORPSE || obj->otyp == EGG || obj->otyp == TIN) {
3221         if (obj->corpsenm != otmp->corpsenm)
3222             return FALSE;
3223     }
3224
3225     /* hatching eggs don't merge; ditto for revivable corpses */
3226     if ((obj->otyp == EGG && (obj->timed || otmp->timed))
3227         || (obj->otyp == CORPSE && otmp->corpsenm >= LOW_PM
3228             && is_reviver(&mons[otmp->corpsenm])))
3229         return FALSE;
3230
3231     /* allow candle merging only if their ages are close */
3232     /* see begin_burn() for a reference for the magic "25" */
3233     if (Is_candle(obj) && obj->age / 25 != otmp->age / 25)
3234         return FALSE;
3235
3236     /* burning potions of oil never merge */
3237     if (obj->otyp == POT_OIL && obj->lamplit)
3238         return FALSE;
3239
3240     /* don't merge surcharged item with base-cost item */
3241     if (obj->unpaid && !same_price(obj, otmp))
3242         return FALSE;
3243
3244     /* if they have names, make sure they're the same */
3245     objnamelth = strlen(safe_oname(obj));
3246     otmpnamelth = strlen(safe_oname(otmp));
3247     if ((objnamelth != otmpnamelth
3248          && ((objnamelth && otmpnamelth) || obj->otyp == CORPSE))
3249         || (objnamelth && otmpnamelth
3250             && strncmp(ONAME(obj), ONAME(otmp), objnamelth)))
3251         return FALSE;
3252
3253     /* for the moment, any additional information is incompatible */
3254     if (has_omonst(obj) || has_omid(obj) || has_olong(obj) || has_omonst(otmp)
3255         || has_omid(otmp) || has_olong(otmp))
3256         return FALSE;
3257
3258     if (obj->oartifact != otmp->oartifact)
3259         return FALSE;
3260
3261     if (obj->known == otmp->known || !objects[otmp->otyp].oc_uses_known) {
3262         return (boolean) objects[obj->otyp].oc_merge;
3263     } else
3264         return FALSE;
3265 }
3266
3267 /* the '$' command */
3268 int
3269 doprgold()
3270 {
3271     /* the messages used to refer to "carrying gold", but that didn't
3272        take containers into account */
3273     long umoney = money_cnt(invent);
3274     if (!umoney)
3275 /*JP
3276         Your("wallet is empty.");
3277 */
3278         Your("\8dà\95z\82Í\8bó\82Á\82Û\82¾\81D");
3279     else
3280 /*JP
3281         Your("wallet contains %ld %s.", umoney, currency(umoney));
3282 */
3283         Your("\8dà\95z\82É\82Í%ld%s\93ü\82Á\82Ä\82¢\82é\81D", umoney, currency(umoney));
3284     shopper_financial_report();
3285     return 0;
3286 }
3287
3288 /* the ')' command */
3289 int
3290 doprwep()
3291 {
3292     if (!uwep) {
3293 /*JP
3294         You("are empty %s.", body_part(HANDED));
3295 */
3296         if(!uwep) You("%s\82É\95\90\8aí\82ð\82à\82Á\82Ä\82¢\82È\82¢\81D", body_part(HAND));
3297     } else {
3298         prinv((char *) 0, uwep, 0L);
3299         if (u.twoweap)
3300             prinv((char *) 0, uswapwep, 0L);
3301     }
3302     return 0;
3303 }
3304
3305 /* caller is responsible for checking !wearing_armor() */
3306 STATIC_OVL void
3307 noarmor(report_uskin)
3308 boolean report_uskin;
3309 {
3310     if (!uskin || !report_uskin) {
3311 /*JP
3312         You("are not wearing any armor.");
3313 */
3314         You("\8aZ\82ð\92\85\82Ä\82¢\82È\82¢\81D");
3315     } else {
3316         char *p, *uskinname, buf[BUFSZ];
3317
3318         uskinname = strcpy(buf, simpleonames(uskin));
3319 #if 0 /*JP*/
3320         /* shorten "set of <color> dragon scales" to "<color> scales"
3321            and "<color> dragon scale mail" to "<color> scale mail" */
3322         if (!strncmpi(uskinname, "set of ", 7))
3323             uskinname += 7;
3324         if ((p = strstri(uskinname, " dragon ")) != 0)
3325             while ((p[1] = p[8]) != '\0')
3326                 ++p;
3327 #else /*\81u<\90F>\83h\83\89\83S\83\93\82Ì\97Ø\81v\82ð\81u<\90F>\82Ì\97Ø\81v\82É\82·\82é*/
3328         if ((p = strstri(uskinname, "\83h\83\89\83S\83\93\82Ì\97Ø")) != 0)
3329             strcpy(p, "\97Ø");
3330 #endif
3331
3332 /*JP
3333         You("are not wearing armor but have %s embedded in your skin.",
3334 */
3335         You("\82Í\8aZ\82ð\92\85\82Ä\82¢\82È\82¢\82ª\81C%s\82ª\94§\82É\96\84\82ß\8d\9e\82Ü\82ê\82Ä\82¢\82é\81D",
3336             uskinname);
3337     }
3338 }
3339
3340 /* the '[' command */
3341 int
3342 doprarm()
3343 {
3344     char lets[8];
3345     register int ct = 0;
3346     /*
3347      * Note:  players sometimes get here by pressing a function key which
3348      * transmits ''ESC [ <something>'' rather than by pressing '[';
3349      * there's nothing we can--or should-do about that here.
3350      */
3351
3352     if (!wearing_armor()) {
3353         noarmor(TRUE);
3354     } else {
3355         if (uarmu)
3356             lets[ct++] = obj_to_let(uarmu);
3357         if (uarm)
3358             lets[ct++] = obj_to_let(uarm);
3359         if (uarmc)
3360             lets[ct++] = obj_to_let(uarmc);
3361         if (uarmh)
3362             lets[ct++] = obj_to_let(uarmh);
3363         if (uarms)
3364             lets[ct++] = obj_to_let(uarms);
3365         if (uarmg)
3366             lets[ct++] = obj_to_let(uarmg);
3367         if (uarmf)
3368             lets[ct++] = obj_to_let(uarmf);
3369         lets[ct] = 0;
3370         (void) display_inventory(lets, FALSE);
3371     }
3372     return 0;
3373 }
3374
3375 /* the '=' command */
3376 int
3377 doprring()
3378 {
3379     if (!uleft && !uright)
3380 /*JP
3381         You("are not wearing any rings.");
3382 */
3383         You("\8ew\97Ö\82ð\90g\82É\82Â\82¯\82Ä\82¢\82È\82¢\81D");
3384     else {
3385         char lets[3];
3386         register int ct = 0;
3387
3388         if (uleft)
3389             lets[ct++] = obj_to_let(uleft);
3390         if (uright)
3391             lets[ct++] = obj_to_let(uright);
3392         lets[ct] = 0;
3393         (void) display_inventory(lets, FALSE);
3394     }
3395     return 0;
3396 }
3397
3398 /* the '"' command */
3399 int
3400 dopramulet()
3401 {
3402     if (!uamul)
3403 /*JP
3404         You("are not wearing an amulet.");
3405 */
3406         You("\96\82\8f\9c\82¯\82ð\90g\82É\82Â\82¯\82Ä\82¢\82È\82¢\81D");
3407     else
3408         prinv((char *) 0, uamul, 0L);
3409     return 0;
3410 }
3411
3412 STATIC_OVL boolean
3413 tool_in_use(obj)
3414 struct obj *obj;
3415 {
3416     if ((obj->owornmask & (W_TOOL | W_SADDLE)) != 0L)
3417         return TRUE;
3418     if (obj->oclass != TOOL_CLASS)
3419         return FALSE;
3420     return (boolean) (obj == uwep || obj->lamplit
3421                       || (obj->otyp == LEASH && obj->leashmon));
3422 }
3423
3424 /* the '(' command */
3425 int
3426 doprtool()
3427 {
3428     struct obj *otmp;
3429     int ct = 0;
3430     char lets[52 + 1];
3431
3432     for (otmp = invent; otmp; otmp = otmp->nobj)
3433         if (tool_in_use(otmp))
3434             lets[ct++] = obj_to_let(otmp);
3435     lets[ct] = '\0';
3436     if (!ct)
3437 /*JP
3438         You("are not using any tools.");
3439 */
3440         You("\8eg\82¦\82é\93¹\8bï\82ð\82à\82Á\82Ä\82¢\82È\82¢\81D");
3441     else
3442         (void) display_inventory(lets, FALSE);
3443     return 0;
3444 }
3445
3446 /* '*' command; combines the ')' + '[' + '=' + '"' + '(' commands;
3447    show inventory of all currently wielded, worn, or used objects */
3448 int
3449 doprinuse()
3450 {
3451     struct obj *otmp;
3452     int ct = 0;
3453     char lets[52 + 1];
3454
3455     for (otmp = invent; otmp; otmp = otmp->nobj)
3456         if (is_worn(otmp) || tool_in_use(otmp))
3457             lets[ct++] = obj_to_let(otmp);
3458     lets[ct] = '\0';
3459     if (!ct)
3460 /*JP
3461         You("are not wearing or wielding anything.");
3462 */
3463         You("\89½\82à\92\85\82Ä\82¢\82È\82¢\82µ\81C\91\95\94õ\82µ\82Ä\82¢\82È\82¢\81D");
3464     else
3465         (void) display_inventory(lets, FALSE);
3466     return 0;
3467 }
3468
3469 /*
3470  * uses up an object that's on the floor, charging for it as necessary
3471  */
3472 void
3473 useupf(obj, numused)
3474 register struct obj *obj;
3475 long numused;
3476 {
3477     register struct obj *otmp;
3478     boolean at_u = (obj->ox == u.ux && obj->oy == u.uy);
3479
3480     /* burn_floor_objects() keeps an object pointer that it tries to
3481      * useupf() multiple times, so obj must survive if plural */
3482     if (obj->quan > numused)
3483         otmp = splitobj(obj, numused);
3484     else
3485         otmp = obj;
3486     if (costly_spot(otmp->ox, otmp->oy)) {
3487         if (index(u.urooms, *in_rooms(otmp->ox, otmp->oy, 0)))
3488             addtobill(otmp, FALSE, FALSE, FALSE);
3489         else
3490             (void) stolen_value(otmp, otmp->ox, otmp->oy, FALSE, FALSE);
3491     }
3492     delobj(otmp);
3493     if (at_u && u.uundetected && hides_under(youmonst.data))
3494         (void) hideunder(&youmonst);
3495 }
3496
3497 /*
3498  * Conversion from a class to a string for printing.
3499  * This must match the object class order.
3500  */
3501 STATIC_VAR NEARDATA const char *names[] = {
3502 #if 0 /*JP*/
3503     0, "Illegal objects", "Weapons", "Armor", "Rings", "Amulets", "Tools",
3504     "Comestibles", "Potions", "Scrolls", "Spellbooks", "Wands", "Coins",
3505     "Gems/Stones", "Boulders/Statues", "Iron balls", "Chains", "Venoms"
3506 #else
3507     0, "\96­\82È\95¨\91Ì", "\95\90\8aí", "\8aZ", "\8ew\97Ö", "\96\82\8f\9c\82¯", "\93¹\8bï",
3508     "\90H\97¿", "\96ò", "\8aª\95¨", "\96\82\96@\8f\91", "\8fñ", "\8bà\89Ý",
3509     "\95ó\90Î", "\8aâ\82Ü\82½\82Í\92¤\91\9c", "\93S\8b\85", "\8d½", "\93Å"
3510 #endif
3511 };
3512
3513 static NEARDATA const char oth_symbols[] = { CONTAINED_SYM, '\0' };
3514
3515 /*JP
3516 static NEARDATA const char *oth_names[] = { "Bagged/Boxed items" };
3517 */
3518 static NEARDATA const char *oth_names[] = { "\8bl\82ß\82ç\82ê\82½\93¹\8bï" };
3519
3520 static NEARDATA char *invbuf = (char *) 0;
3521 static NEARDATA unsigned invbufsiz = 0;
3522
3523 char *
3524 let_to_name(let, unpaid, showsym)
3525 char let;
3526 boolean unpaid, showsym;
3527 {
3528     const char *ocsymfmt = "  ('%c')";
3529     const int invbuf_sympadding = 8; /* arbitrary */
3530     const char *class_name;
3531     const char *pos;
3532     int oclass = (let >= 1 && let < MAXOCLASSES) ? let : 0;
3533     unsigned len;
3534
3535     if (oclass)
3536         class_name = names[oclass];
3537     else if ((pos = index(oth_symbols, let)) != 0)
3538         class_name = oth_names[pos - oth_symbols];
3539     else
3540         class_name = names[0];
3541
3542 /*JP
3543     len = strlen(class_name) + (unpaid ? sizeof "unpaid_" : sizeof "")
3544 */
3545     len = strlen(class_name) + (unpaid ? sizeof "\96¢\95¥\82¢\82Ì" : sizeof "")
3546           + (oclass ? (strlen(ocsymfmt) + invbuf_sympadding) : 0);
3547     if (len > invbufsiz) {
3548         if (invbuf)
3549             free((genericptr_t) invbuf);
3550         invbufsiz = len + 10; /* add slop to reduce incremental realloc */
3551         invbuf = (char *) alloc(invbufsiz);
3552     }
3553     if (unpaid)
3554 /*JP
3555         Strcat(strcpy(invbuf, "Unpaid "), class_name);
3556 */
3557         Strcat(strcpy(invbuf, "\96¢\95¥\82¢\82Ì"), class_name);
3558     else
3559         Strcpy(invbuf, class_name);
3560     if ((oclass != 0) && showsym) {
3561         char *bp = eos(invbuf);
3562         int mlen = invbuf_sympadding - strlen(class_name);
3563         while (--mlen > 0) {
3564             *bp = ' ';
3565             bp++;
3566         }
3567         *bp = '\0';
3568         Sprintf(eos(invbuf), ocsymfmt, def_oc_syms[oclass].sym);
3569     }
3570     return invbuf;
3571 }
3572
3573 /* release the static buffer used by let_to_name() */
3574 void
3575 free_invbuf()
3576 {
3577     if (invbuf)
3578         free((genericptr_t) invbuf), invbuf = (char *) 0;
3579     invbufsiz = 0;
3580 }
3581
3582 /* give consecutive letters to every item in inventory (for !fixinv mode);
3583    gold is always forced to '$' slot at head of list */
3584 void
3585 reassign()
3586 {
3587     int i;
3588     struct obj *obj, *prevobj, *goldobj;
3589
3590     /* first, remove [first instance of] gold from invent, if present */
3591     prevobj = goldobj = 0;
3592     for (obj = invent; obj; prevobj = obj, obj = obj->nobj)
3593         if (obj->oclass == COIN_CLASS) {
3594             goldobj = obj;
3595             if (prevobj)
3596                 prevobj->nobj = goldobj->nobj;
3597             else
3598                 invent = goldobj->nobj;
3599             break;
3600         }
3601     /* second, re-letter the rest of the list */
3602     for (obj = invent, i = 0; obj; obj = obj->nobj, i++)
3603         obj->invlet =
3604             (i < 26) ? ('a' + i) : (i < 52) ? ('A' + i - 26) : NOINVSYM;
3605     /* third, assign gold the "letter" '$' and re-insert it at head */
3606     if (goldobj) {
3607         goldobj->invlet = GOLD_SYM;
3608         goldobj->nobj = invent;
3609         invent = goldobj;
3610     }
3611     if (i >= 52)
3612         i = 52 - 1;
3613     lastinvnr = i;
3614 }
3615
3616 /* #adjust command
3617  *
3618  *      User specifies a 'from' slot for inventory stack to move,
3619  *      then a 'to' slot for its destination.  Open slots and those
3620  *      filled by compatible stacks are listed as likely candidates
3621  *      but user can pick any inventory letter (including 'from').
3622  *      All compatible items found are gathered into the 'from'
3623  *      stack as it is moved.  If the 'to' slot isn't empty and
3624  *      doesn't merge, then its stack is swapped to the 'from' slot.
3625  *
3626  *      If the user specifies a count when choosing the 'from' slot,
3627  *      and that count is less than the full size of the stack,
3628  *      then the stack will be split.  The 'count' portion is moved
3629  *      to the destination, and the only candidate for merging with
3630  *      it is the stack already at the 'to' slot, if any.  When the
3631  *      destination is non-empty but won't merge, whatever is there
3632  *      will be moved to an open slot; if there isn't any open slot
3633  *      available, the adjustment attempt fails.
3634  *
3635  *      Splitting has one special case:  if 'to' slot is non-empty
3636  *      and is compatible with 'from' in all respects except for
3637  *      user-assigned names, the 'count' portion being moved is
3638  *      effectively renamed so that it will merge with 'to' stack.
3639  */
3640 int
3641 doorganize() /* inventory organizer by Del Lamb */
3642 {
3643     struct obj *obj, *otmp, *splitting, *bumped;
3644     int ix, cur, trycnt;
3645     char let;
3646     char alphabet[52 + 1], buf[52 + 1];
3647     char qbuf[QBUFSZ];
3648     char allowall[3]; /* { ALLOW_COUNT, ALL_CLASSES, 0 } */
3649     const char *adj_type;
3650
3651     if (!invent) {
3652         You("aren't carrying anything to adjust.");
3653         return 0;
3654     }
3655
3656     if (!flags.invlet_constant)
3657         reassign();
3658     /* get object the user wants to organize (the 'from' slot) */
3659     allowall[0] = ALLOW_COUNT;
3660     allowall[1] = ALL_CLASSES;
3661     allowall[2] = '\0';
3662     if (!(obj = getobj(allowall, "adjust")))
3663         return 0;
3664
3665     /* figure out whether user gave a split count to getobj() */
3666     splitting = bumped = 0;
3667     for (otmp = invent; otmp; otmp = otmp->nobj)
3668         if (otmp->nobj == obj) { /* knowledge of splitobj() operation */
3669             if (otmp->invlet == obj->invlet)
3670                 splitting = otmp;
3671             break;
3672         }
3673
3674     /* initialize the list with all lower and upper case letters */
3675     for (ix = 0, let = 'a'; let <= 'z';)
3676         alphabet[ix++] = let++;
3677     for (let = 'A'; let <= 'Z';)
3678         alphabet[ix++] = let++;
3679     alphabet[ix] = '\0';
3680     /* for floating inv letters, truncate list after the first open slot */
3681     if (!flags.invlet_constant && (ix = inv_cnt(FALSE)) < 52)
3682         alphabet[ix + (splitting ? 0 : 1)] = '\0';
3683
3684     /* blank out all the letters currently in use in the inventory */
3685     /* except those that will be merged with the selected object   */
3686     for (otmp = invent; otmp; otmp = otmp->nobj)
3687         if (otmp != obj && !mergable(otmp, obj)) {
3688             let = otmp->invlet;
3689             if (let >= 'a' && let <= 'z')
3690                 alphabet[let - 'a'] = ' ';
3691             else if (let >= 'A' && let <= 'Z')
3692                 alphabet[let - 'A' + 26] = ' ';
3693         }
3694
3695     /* compact the list by removing all the blanks */
3696     for (ix = cur = 0; alphabet[ix]; ix++)
3697         if (alphabet[ix] != ' ')
3698             buf[cur++] = alphabet[ix];
3699     if (!cur && obj->invlet == NOINVSYM)
3700         buf[cur++] = NOINVSYM;
3701     buf[cur] = '\0';
3702     /* and by dashing runs of letters */
3703     if (cur > 5)
3704         compactify(buf);
3705
3706     /* get 'to' slot to use as destination */
3707 #if 0 /*JP:T*/
3708     Sprintf(qbuf, "Adjust letter to what [%s]%s?", buf,
3709             invent ? " (? see used letters)" : "");
3710 #else
3711     Sprintf(qbuf, "\82Ç\82Ì\95\8e\9a\82É\92²\90®\82µ\82Ü\82·\82©[%s]%s\81H", buf,
3712             invent ? " (? \82Å\8eg\82Á\82Ä\82¢\82é\95\8e\9a\82ð\95\\8e¦)" : "");
3713 #endif
3714     for (trycnt = 1; ; ++trycnt) {
3715         let = yn_function(qbuf, (char *) 0, '\0');
3716         if (let == '?' || let == '*') {
3717             let = display_used_invlets(splitting ? obj->invlet : 0);
3718             if (!let)
3719                 continue;
3720             if (let == '\033')
3721                 goto noadjust;
3722         }
3723         if (index(quitchars, let)
3724             /* adjusting to same slot is meaningful since all
3725                compatible stacks get collected along the way,
3726                but splitting to same slot is not */
3727             || (splitting && let == obj->invlet)) {
3728         noadjust:
3729             if (splitting)
3730                 (void) merged(&splitting, &obj);
3731             pline1(Never_mind);
3732             return 0;
3733         }
3734         if ((letter(let) && let != '@') || index(buf, let))
3735             break; /* got one */
3736         if (trycnt == 5)
3737             goto noadjust;
3738 #if 0 /*JP*/
3739         pline("Select an inventory slot letter."); /* else try again */
3740 #else
3741         pline("\8e\9d\82¿\95¨\82Ì\95\8e\9a\82ð\91I\82ñ\82Å\82­\82¾\82³\82¢\81D");
3742 #endif
3743     }
3744
3745     /* change the inventory and print the resulting item */
3746 /*JP
3747     adj_type = !splitting ? "Moving:" : "Splitting:";
3748 */
3749     adj_type = !splitting ? "\82ð\88Ú\93®\82µ\82½\81D" : "\82ð\95ª\8a\84\82µ\82½\81D";
3750
3751     /*
3752      * don't use freeinv/addinv to avoid double-touching artifacts,
3753      * dousing lamps, losing luck, cursing loadstone, etc.
3754      */
3755     extract_nobj(obj, &invent);
3756
3757     for (otmp = invent; otmp;) {
3758         if (!splitting) {
3759             if (merged(&otmp, &obj)) {
3760 /*JP
3761                 adj_type = "Merging:";
3762 */
3763                 adj_type = "\82ð\8d\87\82í\82¹\82½\81D";
3764                 obj = otmp;
3765                 otmp = otmp->nobj;
3766                 extract_nobj(obj, &invent);
3767                 continue; /* otmp has already been updated */
3768             } else if (otmp->invlet == let) {
3769 /*JP
3770                 adj_type = "Swapping:";
3771 */
3772                 adj_type = "\82ð\8cð\8a·\82µ\82½\81D";
3773                 otmp->invlet = obj->invlet;
3774             }
3775         } else {
3776             /* splitting: don't merge extra compatible stacks;
3777                if destination is compatible, do merge with it,
3778                otherwise bump whatever is there to an open slot */
3779             if (otmp->invlet == let) {
3780                 int olth = 0;
3781
3782                 if (has_oname(obj))
3783                     olth = strlen(ONAME(obj));
3784                 /* ugly hack:  if these objects aren't going to merge
3785                    solely because they have conflicting user-assigned
3786                    names, strip off the name of the one being moved */
3787                 if (olth && !obj->oartifact && !mergable(otmp, obj)) {
3788                     char *holdname = ONAME(obj);
3789                     ONAME(obj) = (char *) 0;
3790                     /* restore name iff merging is still not possible */
3791                     if (!mergable(otmp, obj)) {
3792                         ONAME(obj) = holdname;
3793                         holdname = (char *) 0;
3794                     } else
3795                         free((genericptr_t) holdname);
3796                 }
3797
3798                 if (merged(&otmp, &obj)) {
3799                     obj = otmp;
3800                     extract_nobj(obj, &invent);
3801                 } else if (inv_cnt(FALSE) >= 52) {
3802                     (void) merged(&splitting, &obj); /* undo split */
3803                     /* "knapsack cannot accommodate any more items" */
3804                     Your("pack is too full.");
3805                     return 0;
3806                 } else {
3807                     bumped = otmp;
3808                     extract_nobj(bumped, &invent);
3809                 }
3810                 break;
3811             } /* found 'to' slot */
3812         }     /* splitting */
3813         otmp = otmp->nobj;
3814     }
3815
3816     /* inline addinv; insert loose object at beginning of inventory */
3817     obj->invlet = let;
3818     obj->nobj = invent;
3819     obj->where = OBJ_INVENT;
3820     invent = obj;
3821     reorder_invent();
3822     if (bumped) {
3823         /* splitting the 'from' stack is causing an incompatible
3824            stack in the 'to' slot to be moved into an open one;
3825            we need to do another inline insertion to inventory */
3826         assigninvlet(bumped);
3827         bumped->nobj = invent;
3828         bumped->where = OBJ_INVENT;
3829         invent = bumped;
3830         reorder_invent();
3831     }
3832
3833     /* messages deferred until inventory has been fully reestablished */
3834     prinv(adj_type, obj, 0L);
3835     if (bumped)
3836         prinv("Moving:", bumped, 0L);
3837     if (splitting)
3838         clear_splitobjs(); /* reset splitobj context */
3839     update_inventory();
3840     return 0;
3841 }
3842
3843 /* common to display_minventory and display_cinventory */
3844 STATIC_OVL void
3845 invdisp_nothing(hdr, txt)
3846 const char *hdr, *txt;
3847 {
3848     winid win;
3849     anything any;
3850     menu_item *selected;
3851
3852     any = zeroany;
3853     win = create_nhwindow(NHW_MENU);
3854     start_menu(win);
3855     add_menu(win, NO_GLYPH, &any, 0, 0, iflags.menu_headings, hdr,
3856              MENU_UNSELECTED);
3857     add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE, "", MENU_UNSELECTED);
3858     add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE, txt, MENU_UNSELECTED);
3859     end_menu(win, (char *) 0);
3860     if (select_menu(win, PICK_NONE, &selected) > 0)
3861         free((genericptr_t) selected);
3862     destroy_nhwindow(win);
3863     return;
3864 }
3865
3866 /* query_objlist callback: return things that are worn or wielded */
3867 STATIC_OVL boolean
3868 worn_wield_only(obj)
3869 struct obj *obj;
3870 {
3871 #if 1
3872     /* check for things that *are* worn or wielded (only used for monsters,
3873        so we don't worry about excluding W_CHAIN, W_ARTI and the like) */
3874     return (boolean) (obj->owornmask != 0L);
3875 #else
3876     /* this used to check for things that *might* be worn or wielded,
3877        but that's not particularly interesting */
3878     if (is_weptool(obj) || is_wet_towel(obj) || obj->otyp == MEAT_RING)
3879         return TRUE;
3880     return (boolean) (obj->oclass == WEAPON_CLASS
3881                       || obj->oclass == ARMOR_CLASS
3882                       || obj->oclass == AMULET_CLASS
3883                       || obj->oclass == RING_CLASS);
3884 #endif
3885 }
3886
3887 /*
3888  * Display a monster's inventory.
3889  * Returns a pointer to the object from the monster's inventory selected
3890  * or NULL if nothing was selected.
3891  *
3892  * By default, only worn and wielded items are displayed.  The caller
3893  * can pick one.  Modifier flags are:
3894  *
3895  *      MINV_NOLET      - nothing selectable
3896  *      MINV_ALL        - display all inventory
3897  */
3898 struct obj *
3899 display_minventory(mon, dflags, title)
3900 register struct monst *mon;
3901 int dflags;
3902 char *title;
3903 {
3904     struct obj *ret;
3905     char tmp[QBUFSZ];
3906     int n;
3907     menu_item *selected = 0;
3908     int do_all = (dflags & MINV_ALL) != 0,
3909         incl_hero = (do_all && u.uswallow && mon == u.ustuck),
3910         have_inv = (mon->minvent != 0), have_any = (have_inv || incl_hero);
3911
3912 #if 0 /*JP*/
3913     Sprintf(tmp, "%s %s:", s_suffix(noit_Monnam(mon)),
3914             do_all ? "possessions" : "armament");
3915 #else
3916     Sprintf(tmp, "%s\82Ì%s\81F", Monnam(mon),
3917             do_all ? "\8e\9d\82¿\95¨" : "\91\95\94õ");
3918 #endif
3919
3920     if (do_all ? have_any : (mon->misc_worn_check || MON_WEP(mon))) {
3921         /* Fool the 'weapon in hand' routine into
3922          * displaying 'weapon in claw', etc. properly.
3923          */
3924         youmonst.data = mon->data;
3925
3926         n = query_objlist(title ? title : tmp, mon->minvent,
3927                           INVORDER_SORT | (incl_hero ? INCLUDE_HERO : 0),
3928                           &selected,
3929                           (dflags & MINV_NOLET) ? PICK_NONE : PICK_ONE,
3930                           do_all ? allow_all : worn_wield_only);
3931
3932         set_uasmon();
3933     } else {
3934 /*JP
3935         invdisp_nothing(title ? title : tmp, "(none)");
3936 */
3937         invdisp_nothing(title ? title : tmp, "(\89½\82à\82È\82¢)");
3938         n = 0;
3939     }
3940
3941     if (n > 0) {
3942         ret = selected[0].item.a_obj;
3943         free((genericptr_t) selected);
3944     } else
3945         ret = (struct obj *) 0;
3946     return ret;
3947 }
3948
3949 /*
3950  * Display the contents of a container in inventory style.
3951  * Currently, this is only used for statues, via wand of probing.
3952  */
3953 struct obj *
3954 display_cinventory(obj)
3955 register struct obj *obj;
3956 {
3957     struct obj *ret;
3958     char qbuf[QBUFSZ];
3959     int n;
3960     menu_item *selected = 0;
3961
3962 #if 0 /*JP*/
3963     (void) safe_qbuf(qbuf, "Contents of ", ":", obj, doname, ansimpleoname,
3964                      "that");
3965 #else
3966     (void) safe_qbuf(qbuf, "", "\82Ì\92\86\90g\81F", obj, doname, ansimpleoname,
3967                      "\82»");
3968 #endif
3969
3970     if (obj->cobj) {
3971         n = query_objlist(qbuf, obj->cobj, INVORDER_SORT, &selected,
3972                           PICK_NONE, allow_all);
3973     } else {
3974 /*JP
3975         invdisp_nothing(qbuf, "(empty)");
3976 */
3977         invdisp_nothing(qbuf, "(\8bó\82Á\82Û)");
3978         n = 0;
3979     }
3980     if (n > 0) {
3981         ret = selected[0].item.a_obj;
3982         free((genericptr_t) selected);
3983     } else
3984         ret = (struct obj *) 0;
3985     obj->cknown = 1;
3986     return ret;
3987 }
3988
3989 /* query objlist callback: return TRUE if obj is at given location */
3990 static coord only;
3991
3992 STATIC_OVL boolean
3993 only_here(obj)
3994 struct obj *obj;
3995 {
3996     return (obj->ox == only.x && obj->oy == only.y);
3997 }
3998
3999 /*
4000  * Display a list of buried items in inventory style.  Return a non-zero
4001  * value if there were items at that spot.
4002  *
4003  * Currently, this is only used with a wand of probing zapped downwards.
4004  */
4005 int
4006 display_binventory(x, y, as_if_seen)
4007 int x, y;
4008 boolean as_if_seen;
4009 {
4010     struct obj *obj;
4011     menu_item *selected = 0;
4012     int n;
4013
4014     /* count # of objects here */
4015     for (n = 0, obj = level.buriedobjlist; obj; obj = obj->nobj)
4016         if (obj->ox == x && obj->oy == y) {
4017             if (as_if_seen)
4018                 obj->dknown = 1;
4019             n++;
4020         }
4021
4022     if (n) {
4023         only.x = x;
4024         only.y = y;
4025 /*JP
4026         if (query_objlist("Things that are buried here:", level.buriedobjlist,
4027 */
4028         if (query_objlist("\82±\82±\82É\96\84\82ß\82ç\82ê\82Ä\82¢\82é\82à\82Ì\81F", level.buriedobjlist,
4029                           INVORDER_SORT, &selected, PICK_NONE, only_here) > 0)
4030             free((genericptr_t) selected);
4031         only.x = only.y = 0;
4032     }
4033     return n;
4034 }
4035
4036 /*invent.c*/