OSDN Git Service

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