OSDN Git Service

update year to 2020
[jnethack/source.git] / src / pickup.c
1 /* NetHack 3.6  pickup.c        $NHDT-Date: 1576282488 2019/12/14 00:14:48 $  $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.237 $ */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /*-Copyright (c) Robert Patrick Rankin, 2012. */
4 /* NetHack may be freely redistributed.  See license for details. */
5
6 /* JNetHack Copyright */
7 /* (c) Issei Numata, Naoki Hamada, Shigehiro Miyashita, 1994-2000  */
8 /* For 3.4-, Copyright (c) SHIRAKATA Kentaro, 2002-2020            */
9 /* JNetHack may be freely redistributed.  See license for details. */
10
11 /*
12  *      Contains code for picking objects up, and container use.
13  */
14
15 #include "hack.h"
16
17 #define CONTAINED_SYM '>' /* from invent.c */
18
19 STATIC_DCL void FDECL(simple_look, (struct obj *, BOOLEAN_P));
20 STATIC_DCL boolean FDECL(query_classes, (char *, boolean *, boolean *,
21                                          const char *, struct obj *,
22                                          BOOLEAN_P, int *));
23 STATIC_DCL boolean FDECL(fatal_corpse_mistake, (struct obj *, BOOLEAN_P));
24 STATIC_DCL void FDECL(check_here, (BOOLEAN_P));
25 STATIC_DCL boolean FDECL(n_or_more, (struct obj *));
26 STATIC_DCL boolean FDECL(all_but_uchain, (struct obj *));
27 #if 0 /* not used */
28 STATIC_DCL boolean FDECL(allow_cat_no_uchain, (struct obj *));
29 #endif
30 STATIC_DCL int FDECL(autopick, (struct obj *, int, menu_item **));
31 STATIC_DCL int FDECL(count_categories, (struct obj *, int));
32 STATIC_DCL int FDECL(delta_cwt, (struct obj *, struct obj *));
33 STATIC_DCL long FDECL(carry_count, (struct obj *, struct obj *, long,
34                                     BOOLEAN_P, int *, int *));
35 STATIC_DCL int FDECL(lift_object, (struct obj *, struct obj *, long *,
36                                    BOOLEAN_P));
37 STATIC_DCL boolean FDECL(mbag_explodes, (struct obj *, int));
38 STATIC_DCL long FDECL(boh_loss, (struct obj *container, int));
39 STATIC_PTR int FDECL(in_container, (struct obj *));
40 STATIC_PTR int FDECL(out_container, (struct obj *));
41 STATIC_DCL void FDECL(removed_from_icebox, (struct obj *));
42 STATIC_DCL long FDECL(mbag_item_gone, (int, struct obj *));
43 STATIC_DCL void FDECL(explain_container_prompt, (BOOLEAN_P));
44 STATIC_DCL int FDECL(traditional_loot, (BOOLEAN_P));
45 STATIC_DCL int FDECL(menu_loot, (int, BOOLEAN_P));
46 STATIC_DCL char FDECL(in_or_out_menu, (const char *, struct obj *, BOOLEAN_P,
47                                        BOOLEAN_P, BOOLEAN_P, BOOLEAN_P));
48 STATIC_DCL boolean FDECL(able_to_loot, (int, int, BOOLEAN_P));
49 STATIC_DCL boolean NDECL(reverse_loot);
50 STATIC_DCL boolean FDECL(mon_beside, (int, int));
51 STATIC_DCL int FDECL(do_loot_cont, (struct obj **, int, int));
52 STATIC_DCL void FDECL(tipcontainer, (struct obj *));
53
54 /* define for query_objlist() and autopickup() */
55 #define FOLLOW(curr, flags) \
56     (((flags) & BY_NEXTHERE) ? (curr)->nexthere : (curr)->nobj)
57
58 #define GOLD_WT(n) (((n) + 50L) / 100L)
59 /* if you can figure this out, give yourself a hearty pat on the back... */
60 #define GOLD_CAPACITY(w, n) (((w) * -100L) - ((n) + 50L) - 1L)
61
62 /* A variable set in use_container(), to be used by the callback routines
63    in_container() and out_container() from askchain() and use_container().
64    Also used by menu_loot() and container_gone(). */
65 static NEARDATA struct obj *current_container;
66 static NEARDATA boolean abort_looting;
67 #define Icebox (current_container->otyp == ICE_BOX)
68
69 static const char
70 /*JP
71         moderateloadmsg[] = "You have a little trouble lifting",
72 */
73         moderateloadmsg[] = "\82ð\8e\9d\82Á\82½\82ç\8f­\82µ\82Ó\82ç\82Â\82¢\82½",
74 /*JP
75         nearloadmsg[] = "You have much trouble lifting",
76 */
77         nearloadmsg[] = "\82Í\82¸\82Á\82µ\82è\82Æ\8c¨\82É\82Ì\82µ\82©\82©\82Á\82½",
78 /*JP
79         overloadmsg[] = "You have extreme difficulty lifting";
80 */
81         overloadmsg[] = "\82ð\8e\9d\82¿\82 \82°\82é\82Ì\82Í\82Æ\82Ä\82à\82Â\82ç\82¢";
82
83 /* BUG: this lets you look at cockatrice corpses while blind without
84    touching them */
85 /* much simpler version of the look-here code; used by query_classes() */
86 STATIC_OVL void
87 simple_look(otmp, here)
88 struct obj *otmp; /* list of objects */
89 boolean here;     /* flag for type of obj list linkage */
90 {
91     /* Neither of the first two cases is expected to happen, since
92      * we're only called after multiple classes of objects have been
93      * detected, hence multiple objects must be present.
94      */
95     if (!otmp) {
96         impossible("simple_look(null)");
97     } else if (!(here ? otmp->nexthere : otmp->nobj)) {
98         pline1(doname(otmp));
99     } else {
100         winid tmpwin = create_nhwindow(NHW_MENU);
101
102         putstr(tmpwin, 0, "");
103         do {
104             putstr(tmpwin, 0, doname(otmp));
105             otmp = here ? otmp->nexthere : otmp->nobj;
106         } while (otmp);
107         display_nhwindow(tmpwin, TRUE);
108         destroy_nhwindow(tmpwin);
109     }
110 }
111
112 int
113 collect_obj_classes(ilets, otmp, here, filter, itemcount)
114 char ilets[];
115 register struct obj *otmp;
116 boolean here;
117 boolean FDECL((*filter), (OBJ_P));
118 int *itemcount;
119 {
120     register int iletct = 0;
121     register char c;
122
123     *itemcount = 0;
124     ilets[iletct] = '\0'; /* terminate ilets so that index() will work */
125     while (otmp) {
126         c = def_oc_syms[(int) otmp->oclass].sym;
127         if (!index(ilets, c) && (!filter || (*filter)(otmp)))
128             ilets[iletct++] = c, ilets[iletct] = '\0';
129         *itemcount += 1;
130         otmp = here ? otmp->nexthere : otmp->nobj;
131     }
132
133     return iletct;
134 }
135
136 /*
137  * Suppose some '?' and '!' objects are present, but '/' objects aren't:
138  *      "a" picks all items without further prompting;
139  *      "A" steps through all items, asking one by one;
140  *      "?" steps through '?' items, asking, and ignores '!' ones;
141  *      "/" becomes 'A', since no '/' present;
142  *      "?a" or "a?" picks all '?' without further prompting;
143  *      "/a" or "a/" becomes 'A' since there aren't any '/'
144  *          (bug fix:  3.1.0 thru 3.1.3 treated it as "a");
145  *      "?/a" or "a?/" or "/a?",&c picks all '?' even though no '/'
146  *          (ie, treated as if it had just been "?a").
147  */
148 /*JP CHECK: 3.4.3 \82Å\82Ì\8cÄ\82Ñ\8fo\82µ\8c³
149 pickup.c:572:("\8fE\82¤")   if (!query_classes(oclasses, &selective, &all_of_a_type,
150 pickup.c:2604:("\8eæ\82è\8fo\82·")    if (query_classes(select, &one_by_one, &allflag,
151 pickup.c:2704:("\93ü\82ê\82é")        if (query_classes(select, &one_by_one, &allflag, "\93ü\82ê\82é",
152 */
153 STATIC_OVL boolean
154 query_classes(oclasses, one_at_a_time, everything, action, objs, here,
155               menu_on_demand)
156 char oclasses[];
157 boolean *one_at_a_time, *everything;
158 const char *action;
159 struct obj *objs;
160 boolean here;
161 int *menu_on_demand;
162 {
163     char ilets[36], inbuf[BUFSZ] = DUMMY; /* FIXME: hardcoded ilets[] length */
164     int iletct, oclassct;
165     boolean not_everything, filtered;
166     char qbuf[QBUFSZ];
167     boolean m_seen;
168     int itemcount, bcnt, ucnt, ccnt, xcnt, ocnt;
169
170     oclasses[oclassct = 0] = '\0';
171     *one_at_a_time = *everything = m_seen = FALSE;
172     if (menu_on_demand)
173         *menu_on_demand = 0;
174     iletct = collect_obj_classes(ilets, objs, here,
175                                  (boolean FDECL((*), (OBJ_P))) 0, &itemcount);
176     if (iletct == 0)
177         return FALSE;
178
179     if (iletct == 1) {
180         oclasses[0] = def_char_to_objclass(ilets[0]);
181         oclasses[1] = '\0';
182     } else { /* more than one choice available */
183         /* additional choices */
184         ilets[iletct++] = ' ';
185         ilets[iletct++] = 'a';
186         ilets[iletct++] = 'A';
187         ilets[iletct++] = (objs == invent ? 'i' : ':');
188     }
189     if (itemcount && menu_on_demand)
190         ilets[iletct++] = 'm';
191     if (count_unpaid(objs))
192         ilets[iletct++] = 'u';
193
194     tally_BUCX(objs, here, &bcnt, &ucnt, &ccnt, &xcnt, &ocnt);
195     if (bcnt)
196         ilets[iletct++] = 'B';
197     if (ucnt)
198         ilets[iletct++] = 'U';
199     if (ccnt)
200         ilets[iletct++] = 'C';
201     if (xcnt)
202         ilets[iletct++] = 'X';
203     ilets[iletct] = '\0';
204
205     if (iletct > 1) {
206         const char *where = 0;
207         char sym, oc_of_sym, *p;
208
209  ask_again:
210         oclasses[oclassct = 0] = '\0';
211         *one_at_a_time = *everything = FALSE;
212         not_everything = filtered = FALSE;
213 #if 0 /*JP:T*/
214         Sprintf(qbuf, "What kinds of thing do you want to %s? [%s]", action,
215                 ilets);
216 #else
217         Sprintf(qbuf,"\82Ç\82Ì\8eí\97Þ\82Ì\82à\82Ì\82ð%s\82©\81H[%s]", jpolite(action),
218                 ilets);
219 #endif
220         getlin(qbuf, inbuf);
221         if (*inbuf == '\033')
222             return FALSE;
223
224         for (p = inbuf; (sym = *p++) != 0; ) {
225             if (sym == ' ')
226                 continue;
227             else if (sym == 'A')
228                 *one_at_a_time = TRUE;
229             else if (sym == 'a')
230                 *everything = TRUE;
231             else if (sym == ':') {
232                 simple_look(objs, here); /* dumb if objs==invent */
233                 /* if we just scanned the contents of a container
234                    then mark it as having known contents */
235                 if (objs->where == OBJ_CONTAINED)
236                     objs->ocontainer->cknown = 1;
237                 goto ask_again;
238             } else if (sym == 'i') {
239                 (void) display_inventory((char *) 0, TRUE);
240                 goto ask_again;
241             } else if (sym == 'm') {
242                 m_seen = TRUE;
243             } else if (index("uBUCX", sym)) {
244                 add_valid_menu_class(sym); /* 'u' or 'B','U','C',or 'X' */
245                 filtered = TRUE;
246             } else {
247                 oc_of_sym = def_char_to_objclass(sym);
248                 if (index(ilets, sym)) {
249                     add_valid_menu_class(oc_of_sym);
250                     oclasses[oclassct++] = oc_of_sym;
251                     oclasses[oclassct] = '\0';
252                 } else {
253                     if (!where)
254 /*JP
255                         where = !strcmp(action, "pick up") ? "here"
256 */
257                         where = !strcmp(action, "\8fE\82¤") ? "\82±\82±"
258 /*JP
259                                 : !strcmp(action, "take out") ? "inside" : "";
260 */
261                                 : !strcmp(action, "\8eæ\82è\8fo\82·") ? "\82Ì\92\86" : "";
262                     if (*where)
263 /*JP
264                         There("are no %c's %s.", sym, where);
265 */
266                         pline("%c\82Í%s\82É\82È\82¢\81D", sym, where);
267                     else
268 /*JP
269                         You("have no %c's.", sym);
270 */
271                         You("%c\82Í\8e\9d\82Á\82Ä\82¢\82È\82¢\81D", sym);
272                     not_everything = TRUE;
273                 }
274             }
275         } /* for p:sym in inbuf */
276
277         if (m_seen && menu_on_demand) {
278             *menu_on_demand = (((*everything || !oclassct) && !filtered)
279                                ? -2 : -3);
280             return FALSE;
281         }
282         if (!oclassct && (!*everything || not_everything)) {
283             /* didn't pick anything,
284                or tried to pick something that's not present */
285             *one_at_a_time = TRUE; /* force 'A' */
286             *everything = FALSE;   /* inhibit 'a' */
287         }
288     }
289     return TRUE;
290 }
291
292 /* check whether hero is bare-handedly touching a cockatrice corpse */
293 STATIC_OVL boolean
294 fatal_corpse_mistake(obj, remotely)
295 struct obj *obj;
296 boolean remotely;
297 {
298     if (uarmg || remotely || obj->otyp != CORPSE
299         || !touch_petrifies(&mons[obj->corpsenm]) || Stone_resistance)
300         return FALSE;
301
302     if (poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM)) {
303         display_nhwindow(WIN_MESSAGE, FALSE); /* --More-- */
304         return FALSE;
305     }
306
307 /*JP
308     pline("Touching %s is a fatal mistake.",
309 */
310     pline("%s\82É\90G\82ê\82é\82Ì\82Í\92v\96½\93I\82È\8aÔ\88á\82¢\82¾\81D",
311           corpse_xname(obj, (const char *) 0, CXN_SINGULAR | CXN_ARTICLE));
312     instapetrify(killer_xname(obj));
313     return TRUE;
314 }
315
316 /* attempting to manipulate a Rider's corpse triggers its revival */
317 boolean
318 rider_corpse_revival(obj, remotely)
319 struct obj *obj;
320 boolean remotely;
321 {
322     if (!obj || obj->otyp != CORPSE || !is_rider(&mons[obj->corpsenm]))
323         return FALSE;
324
325 /*JP
326     pline("At your %s, the corpse suddenly moves...",
327 */
328     pline("\82 \82È\82½\82ª%s\82é\82Æ\93Ë\91R\8e\80\91Ì\82ª\93®\82«\8fo\82µ\82½\81D\81D\81D",
329 /*JP
330           remotely ? "attempted acquisition" : "touch");
331 */
332           remotely ? "\8al\93¾\82µ\82æ\82¤\82Æ\82·" : "\90G");
333     (void) revive_corpse(obj);
334     exercise(A_WIS, FALSE);
335     return TRUE;
336 }
337
338 /* look at the objects at our location, unless there are too many of them */
339 STATIC_OVL void
340 check_here(picked_some)
341 boolean picked_some;
342 {
343     register struct obj *obj;
344     register int ct = 0;
345
346     /* count the objects here */
347     for (obj = level.objects[u.ux][u.uy]; obj; obj = obj->nexthere) {
348         if (obj != uchain)
349             ct++;
350     }
351
352     /* If there are objects here, take a look. */
353     if (ct) {
354         if (context.run)
355             nomul(0);
356         flush_screen(1);
357         (void) look_here(ct, picked_some);
358     } else {
359         read_engr_at(u.ux, u.uy);
360     }
361 }
362
363 /* Value set by query_objlist() for n_or_more(). */
364 static long val_for_n_or_more;
365
366 /* query_objlist callback: return TRUE if obj's count is >= reference value */
367 STATIC_OVL boolean
368 n_or_more(obj)
369 struct obj *obj;
370 {
371     if (obj == uchain)
372         return FALSE;
373     return (boolean) (obj->quan >= val_for_n_or_more);
374 }
375
376 /* list of valid menu classes for query_objlist() and allow_category callback
377    (with room for all object classes, 'u'npaid, BUCX, and terminator) */
378 static char valid_menu_classes[MAXOCLASSES + 1 + 4 + 1];
379 static boolean class_filter, bucx_filter, shop_filter;
380
381 /* check valid_menu_classes[] for an entry; also used by askchain() */
382 boolean
383 menu_class_present(c)
384 int c;
385 {
386     return (c && index(valid_menu_classes, c)) ? TRUE : FALSE;
387 }
388
389 void
390 add_valid_menu_class(c)
391 int c;
392 {
393     static int vmc_count = 0;
394
395     if (c == 0) { /* reset */
396         vmc_count = 0;
397         class_filter = bucx_filter = shop_filter = FALSE;
398     } else if (!menu_class_present(c)) {
399         valid_menu_classes[vmc_count++] = (char) c;
400         /* categorize the new class */
401         switch (c) {
402         case 'B':
403         case 'U':
404         case 'C': /*FALLTHRU*/
405         case 'X':
406             bucx_filter = TRUE;
407             break;
408         case 'u':
409             shop_filter = TRUE;
410             break;
411         default:
412             class_filter = TRUE;
413             break;
414         }
415     }
416     valid_menu_classes[vmc_count] = '\0';
417 }
418
419 /* query_objlist callback: return TRUE if not uchain */
420 STATIC_OVL boolean
421 all_but_uchain(obj)
422 struct obj *obj;
423 {
424     return (boolean) (obj != uchain);
425 }
426
427 /* query_objlist callback: return TRUE */
428 /*ARGUSED*/
429 boolean
430 allow_all(obj)
431 struct obj *obj UNUSED;
432 {
433     return TRUE;
434 }
435
436 boolean
437 allow_category(obj)
438 struct obj *obj;
439 {
440     /* For coins, if any class filter is specified, accept if coins
441      * are included regardless of whether either unpaid or BUC-status
442      * is also specified since player has explicitly requested coins.
443      * If no class filtering is specified but bless/curse state is,
444      * coins are either unknown or uncursed based on an option setting.
445      */
446     if (obj->oclass == COIN_CLASS)
447         return class_filter
448                  ? (index(valid_menu_classes, COIN_CLASS) ? TRUE : FALSE)
449                  : shop_filter /* coins are never unpaid, but check anyway */
450                     ? (obj->unpaid ? TRUE : FALSE)
451                     : bucx_filter
452                        ? (index(valid_menu_classes, iflags.goldX ? 'X' : 'U')
453                           ? TRUE : FALSE)
454                        : TRUE; /* catchall: no filters specified, so accept */
455
456     if (Role_if(PM_PRIEST) && !obj->bknown)
457         set_bknown(obj, 1);
458
459     /*
460      * There are three types of filters possible and the first and
461      * third can have more than one entry:
462      *  1) object class (armor, potion, &c);
463      *  2) unpaid shop item;
464      *  3) bless/curse state (blessed, uncursed, cursed, BUC-unknown).
465      * When only one type is present, the situation is simple:
466      * to be accepted, obj's status must match one of the entries.
467      * When more than one type is present, the obj will now only
468      * be accepted when it matches one entry of each type.
469      * So ?!B will accept blessed scrolls or potions, and [u will
470      * accept unpaid armor.  (In 3.4.3, an object was accepted by
471      * this filter if it met any entry of any type, so ?!B resulted
472      * in accepting all scrolls and potions regardless of bless/curse
473      * state plus all blessed non-scroll, non-potion objects.)
474      */
475
476     /* if class is expected but obj's class is not in the list, reject */
477     if (class_filter && !index(valid_menu_classes, obj->oclass))
478         return FALSE;
479     /* if unpaid is expected and obj isn't unpaid, reject (treat a container
480        holding any unpaid object as unpaid even if isn't unpaid itself) */
481     if (shop_filter && !obj->unpaid
482         && !(Has_contents(obj) && count_unpaid(obj->cobj) > 0))
483         return FALSE;
484     /* check for particular bless/curse state */
485     if (bucx_filter) {
486         /* first categorize this object's bless/curse state */
487         char bucx = !obj->bknown ? 'X'
488                       : obj->blessed ? 'B' : obj->cursed ? 'C' : 'U';
489
490         /* if its category is not in the list, reject */
491         if (!index(valid_menu_classes, bucx))
492             return FALSE;
493     }
494     /* obj didn't fail any of the filter checks, so accept */
495     return TRUE;
496 }
497
498 #if 0 /* not used */
499 /* query_objlist callback: return TRUE if valid category (class), no uchain */
500 STATIC_OVL boolean
501 allow_cat_no_uchain(obj)
502 struct obj *obj;
503 {
504     if (obj != uchain
505         && ((index(valid_menu_classes, 'u') && obj->unpaid)
506             || index(valid_menu_classes, obj->oclass)))
507         return TRUE;
508     return FALSE;
509 }
510 #endif
511
512 /* query_objlist callback: return TRUE if valid class and worn */
513 boolean
514 is_worn_by_type(otmp)
515 register struct obj *otmp;
516 {
517     return (is_worn(otmp) && allow_category(otmp)) ? TRUE : FALSE;
518 }
519
520 /*
521  * Have the hero pick things from the ground
522  * or a monster's inventory if swallowed.
523  *
524  * Arg what:
525  *      >0  autopickup
526  *      =0  interactive
527  *      <0  pickup count of something
528  *
529  * Returns 1 if tried to pick something up, whether
530  * or not it succeeded.
531  */
532 int
533 pickup(what)
534 int what; /* should be a long */
535 {
536     int i, n, res, count, n_tried = 0, n_picked = 0;
537     menu_item *pick_list = (menu_item *) 0;
538     boolean autopickup = what > 0;
539     struct obj **objchain_p;
540     int traverse_how;
541
542     /* we might have arrived here while fainted or sleeping, via
543        random teleport or levitation timeout; if so, skip check_here
544        and read_engr_at in addition to bypassing autopickup itself
545        [probably ought to check whether hero is using a cockatrice
546        corpse for a pillow here... (also at initial faint/sleep)] */
547     if (autopickup && multi < 0 && unconscious())
548         return 0;
549
550     if (what < 0) /* pick N of something */
551         count = -what;
552     else /* pick anything */
553         count = 0;
554
555     if (!u.uswallow) {
556         struct trap *ttmp;
557
558         /* no auto-pick if no-pick move, nothing there, or in a pool */
559         if (autopickup && (context.nopick || !OBJ_AT(u.ux, u.uy)
560                            || (is_pool(u.ux, u.uy) && !Underwater)
561                            || is_lava(u.ux, u.uy))) {
562             read_engr_at(u.ux, u.uy);
563             return 0;
564         }
565         /* no pickup if levitating & not on air or water level */
566         if (!can_reach_floor(TRUE)) {
567             if ((multi && !context.run) || (autopickup && !flags.pickup)
568                 || ((ttmp = t_at(u.ux, u.uy)) != 0
569                     && (uteetering_at_seen_pit(ttmp) || uescaped_shaft(ttmp))))
570                 read_engr_at(u.ux, u.uy);
571             return 0;
572         }
573         /* multi && !context.run means they are in the middle of some other
574          * action, or possibly paralyzed, sleeping, etc.... and they just
575          * teleported onto the object.  They shouldn't pick it up.
576          */
577         if ((multi && !context.run) || (autopickup && !flags.pickup)) {
578             check_here(FALSE);
579             return 0;
580         }
581         if (notake(youmonst.data)) {
582             if (!autopickup)
583 /*JP
584                 You("are physically incapable of picking anything up.");
585 */
586                 You("\95¨\97\9d\93I\82É\8fE\82¢\82 \82°\82é\82±\82Æ\82ª\82Å\82«\82È\82¢\81D");
587             else
588                 check_here(FALSE);
589             return 0;
590         }
591
592         /* if there's anything here, stop running */
593         if (OBJ_AT(u.ux, u.uy) && context.run && context.run != 8
594             && !context.nopick)
595             nomul(0);
596     }
597
598     add_valid_menu_class(0); /* reset */
599     if (!u.uswallow) {
600         objchain_p = &level.objects[u.ux][u.uy];
601         traverse_how = BY_NEXTHERE;
602     } else {
603         objchain_p = &u.ustuck->minvent;
604         traverse_how = 0; /* nobj */
605     }
606     /*
607      * Start the actual pickup process.  This is split into two main
608      * sections, the newer menu and the older "traditional" methods.
609      * Automatic pickup has been split into its own menu-style routine
610      * to make things less confusing.
611      */
612     if (autopickup) {
613         n = autopick(*objchain_p, traverse_how, &pick_list);
614         goto menu_pickup;
615     }
616
617     if (flags.menu_style != MENU_TRADITIONAL || iflags.menu_requested) {
618         /* use menus exclusively */
619         traverse_how |= AUTOSELECT_SINGLE
620                         | (flags.sortpack ? INVORDER_SORT : 0);
621         if (count) { /* looking for N of something */
622             char qbuf[QBUFSZ];
623
624 /*JP
625             Sprintf(qbuf, "Pick %d of what?", count);
626 */
627             Sprintf(qbuf, "\89½\82ð%d\8cÂ\8fE\82¢\82Ü\82·\82©\81H", count);
628             val_for_n_or_more = count; /* set up callback selector */
629             n = query_objlist(qbuf, objchain_p, traverse_how,
630                               &pick_list, PICK_ONE, n_or_more);
631             /* correct counts, if any given */
632             for (i = 0; i < n; i++)
633                 pick_list[i].count = count;
634         } else {
635 #if 0 /*JP:T*/
636             n = query_objlist("Pick up what?", objchain_p,
637                               (traverse_how | FEEL_COCKATRICE),
638                               &pick_list, PICK_ANY, all_but_uchain);
639 #else
640             n = query_objlist("\89½\82ð\8fE\82¢\82Ü\82·\82©\81H", objchain_p,
641                               (traverse_how | FEEL_COCKATRICE),
642                               &pick_list, PICK_ANY, all_but_uchain);
643 #endif
644         }
645
646  menu_pickup:
647         n_tried = n;
648         for (n_picked = i = 0; i < n; i++) {
649             res = pickup_object(pick_list[i].item.a_obj, pick_list[i].count,
650                                 FALSE);
651             if (res < 0)
652                 break; /* can't continue */
653             n_picked += res;
654         }
655         if (pick_list)
656             free((genericptr_t) pick_list);
657
658     } else {
659         /* old style interface */
660         int ct = 0;
661         long lcount;
662         boolean all_of_a_type, selective, bycat;
663         char oclasses[MAXOCLASSES + 10]; /* +10: room for B,U,C,X plus slop */
664         struct obj *obj, *obj2;
665
666         oclasses[0] = '\0';   /* types to consider (empty for all) */
667         all_of_a_type = TRUE; /* take all of considered types */
668         selective = FALSE;    /* ask for each item */
669
670         /* check for more than one object */
671         for (obj = *objchain_p; obj; obj = FOLLOW(obj, traverse_how))
672             ct++;
673
674         if (ct == 1 && count) {
675             /* if only one thing, then pick it */
676             obj = *objchain_p;
677             lcount = min(obj->quan, (long) count);
678             n_tried++;
679             if (pickup_object(obj, lcount, FALSE) > 0)
680                 n_picked++; /* picked something */
681             goto end_query;
682
683         } else if (ct >= 2) {
684             int via_menu = 0;
685
686 /*JP
687             There("are %s objects here.", (ct <= 10) ? "several" : "many");
688 */
689             pline("\82±\82±\82É\82Í%s\82à\82Ì\82ª\82 \82é\81D", (ct <= 10) ? "\82¢\82­\82Â\82©" : "\91ò\8eR\82Ì");
690 #if 0 /*JP:T*/
691             if (!query_classes(oclasses, &selective, &all_of_a_type,
692                                "pick up", *objchain_p,
693                                (traverse_how & BY_NEXTHERE) ? TRUE : FALSE,
694                                &via_menu)) {
695 #else
696             if (!query_classes(oclasses, &selective, &all_of_a_type,
697                                "\8fE\82¤", *objchain_p,
698                                (traverse_how & BY_NEXTHERE) ? TRUE : FALSE,
699                                &via_menu)) {
700 #endif
701                 if (!via_menu)
702                     goto pickupdone;
703                 if (selective)
704                     traverse_how |= INVORDER_SORT;
705 #if 0 /*JP:T*/
706                 n = query_objlist("Pick up what?", objchain_p, traverse_how,
707                                   &pick_list, PICK_ANY,
708                                   (via_menu == -2) ? allow_all
709                                                    : allow_category);
710 #else
711                 n = query_objlist("\89½\82ð\8fE\82¢\82Ü\82·\82©\81H", objchain_p, traverse_how,
712                                   &pick_list, PICK_ANY,
713                                   (via_menu == -2) ? allow_all
714                                                    : allow_category);
715 #endif
716                 goto menu_pickup;
717             }
718         }
719         bycat = (menu_class_present('B') || menu_class_present('U')
720                  || menu_class_present('C') || menu_class_present('X'));
721
722         for (obj = *objchain_p; obj; obj = obj2) {
723             obj2 = FOLLOW(obj, traverse_how);
724             if (bycat ? !allow_category(obj)
725                       : (!selective && oclasses[0]
726                          && !index(oclasses, obj->oclass)))
727                 continue;
728
729             lcount = -1L;
730             if (!all_of_a_type) {
731                 char qbuf[BUFSZ];
732
733 #if 0 /*JP:T*/
734                 (void) safe_qbuf(qbuf, "Pick up ", "?", obj, doname,
735                                  ansimpleoname, something);
736 #else
737                 (void) safe_qbuf(qbuf, "", "\82ð\8fE\82¢\82Ü\82·\82©\81H", obj, doname,
738                                  ansimpleoname, "\82±\82ê");
739 #endif
740                 switch ((obj->quan < 2L) ? ynaq(qbuf) : ynNaq(qbuf)) {
741                 case 'q':
742                     goto end_query; /* out 2 levels */
743                 case 'n':
744                     continue;
745                 case 'a':
746                     all_of_a_type = TRUE;
747                     if (selective) {
748                         selective = FALSE;
749                         oclasses[0] = obj->oclass;
750                         oclasses[1] = '\0';
751                     }
752                     break;
753                 case '#': /* count was entered */
754                     if (!yn_number)
755                         continue; /* 0 count => No */
756                     lcount = (long) yn_number;
757                     if (lcount > obj->quan)
758                         lcount = obj->quan;
759                     /*FALLTHRU*/
760                 default: /* 'y' */
761                     break;
762                 }
763             }
764             if (lcount == -1L)
765                 lcount = obj->quan;
766
767             n_tried++;
768             if ((res = pickup_object(obj, lcount, FALSE)) < 0)
769                 break;
770             n_picked += res;
771         }
772  end_query:
773         ; /* statement required after label */
774     }
775
776     if (!u.uswallow) {
777         if (hides_under(youmonst.data))
778             (void) hideunder(&youmonst);
779
780         /* position may need updating (invisible hero) */
781         if (n_picked)
782             newsym_force(u.ux, u.uy);
783
784         /* check if there's anything else here after auto-pickup is done */
785         if (autopickup)
786             check_here(n_picked > 0);
787     }
788  pickupdone:
789     add_valid_menu_class(0); /* reset */
790     return (n_tried > 0);
791 }
792
793 struct autopickup_exception *
794 check_autopickup_exceptions(obj)
795 struct obj *obj;
796 {
797     /*
798      *  Does the text description of this match an exception?
799      */
800     struct autopickup_exception *ape = apelist;
801
802     if (ape) {
803         char *objdesc = makesingular(doname(obj));
804
805         while (ape && !regex_match(objdesc, ape->regex))
806             ape = ape->next;
807     }
808     return ape;
809 }
810
811 boolean
812 autopick_testobj(otmp, calc_costly)
813 struct obj *otmp;
814 boolean calc_costly;
815 {
816     struct autopickup_exception *ape;
817     static boolean costly = FALSE;
818     const char *otypes = flags.pickup_types;
819     boolean pickit;
820
821     /* calculate 'costly' just once for a given autopickup operation */
822     if (calc_costly)
823         costly = (otmp->where == OBJ_FLOOR
824                   && costly_spot(otmp->ox, otmp->oy));
825
826     /* first check: reject if an unpaid item in a shop */
827     if (costly && !otmp->no_charge)
828         return FALSE;
829
830     /* check for pickup_types */
831     pickit = (!*otypes || index(otypes, otmp->oclass));
832
833     /* check for autopickup exceptions */
834     ape = check_autopickup_exceptions(otmp);
835     if (ape)
836         pickit = ape->grab;
837
838     /* pickup_thrown overrides pickup_types and exceptions */
839     if (!pickit)
840         pickit = (flags.pickup_thrown && otmp->was_thrown);
841     return pickit;
842 }
843
844 /*
845  * Pick from the given list using flags.pickup_types.  Return the number
846  * of items picked (not counts).  Create an array that returns pointers
847  * and counts of the items to be picked up.  If the number of items
848  * picked is zero, the pickup list is left alone.  The caller of this
849  * function must free the pickup list.
850  */
851 STATIC_OVL int
852 autopick(olist, follow, pick_list)
853 struct obj *olist;     /* the object list */
854 int follow;            /* how to follow the object list */
855 menu_item **pick_list; /* list of objects and counts to pick up */
856 {
857     menu_item *pi; /* pick item */
858     struct obj *curr;
859     int n;
860     boolean check_costly = TRUE;
861
862     /* first count the number of eligible items */
863     for (n = 0, curr = olist; curr; curr = FOLLOW(curr, follow)) {
864         if (autopick_testobj(curr, check_costly))
865             ++n;
866         check_costly = FALSE; /* only need to check once per autopickup */
867     }
868
869     if (n) {
870         *pick_list = pi = (menu_item *) alloc(sizeof (menu_item) * n);
871         for (n = 0, curr = olist; curr; curr = FOLLOW(curr, follow)) {
872             if (autopick_testobj(curr, FALSE)) {
873                 pi[n].item.a_obj = curr;
874                 pi[n].count = curr->quan;
875                 n++;
876             }
877         }
878     }
879     return n;
880 }
881
882 /*
883  * Put up a menu using the given object list.  Only those objects on the
884  * list that meet the approval of the allow function are displayed.  Return
885  * a count of the number of items selected, as well as an allocated array of
886  * menu_items, containing pointers to the objects selected and counts.  The
887  * returned counts are guaranteed to be in bounds and non-zero.
888  *
889  * Query flags:
890  *      BY_NEXTHERE       - Follow object list via nexthere instead of nobj.
891  *      AUTOSELECT_SINGLE - Don't ask if only 1 object qualifies - just
892  *                          use it.
893  *      USE_INVLET        - Use object's invlet.
894  *      INVORDER_SORT     - Use hero's pack order.
895  *      INCLUDE_HERO      - Showing engulfer's invent; show hero too.
896  *      SIGNAL_NOMENU     - Return -1 rather than 0 if nothing passes "allow".
897  *      SIGNAL_ESCAPE     - Return -1 rather than 0 if player uses ESC to
898  *                          pick nothing.
899  *      FEEL_COCKATRICE   - touch corpse.
900  */
901 int
902 query_objlist(qstr, olist_p, qflags, pick_list, how, allow)
903 const char *qstr;                 /* query string */
904 struct obj **olist_p;             /* the list to pick from */
905 int qflags;                       /* options to control the query */
906 menu_item **pick_list;            /* return list of items picked */
907 int how;                          /* type of query */
908 boolean FDECL((*allow), (OBJ_P)); /* allow function */
909 {
910     int i, n;
911     winid win;
912     struct obj *curr, *last, fake_hero_object, *olist = *olist_p;
913     char *pack;
914     anything any;
915     boolean printed_type_name, first,
916             sorted = (qflags & INVORDER_SORT) != 0,
917             engulfer = (qflags & INCLUDE_HERO) != 0,
918             engulfer_minvent;
919     unsigned sortflags;
920     Loot *sortedolist, *srtoli;
921
922     *pick_list = (menu_item *) 0;
923     if (!olist && !engulfer)
924         return 0;
925
926     /* count the number of items allowed */
927     for (n = 0, last = 0, curr = olist; curr; curr = FOLLOW(curr, qflags))
928         if ((*allow)(curr)) {
929             last = curr;
930             n++;
931         }
932     /* can't depend upon 'engulfer' because that's used to indicate whether
933        hero should be shown as an extra, fake item */
934     engulfer_minvent = (olist && olist->where == OBJ_MINVENT
935                         && u.uswallow && olist->ocarry == u.ustuck);
936     if (engulfer_minvent && n == 1 && olist->owornmask != 0L) {
937         qflags &= ~AUTOSELECT_SINGLE;
938     }
939     if (engulfer) {
940         ++n;
941         /* don't autoselect swallowed hero if it's the only choice */
942         qflags &= ~AUTOSELECT_SINGLE;
943     }
944
945     if (n == 0) /* nothing to pick here */
946         return (qflags & SIGNAL_NOMENU) ? -1 : 0;
947
948     if (n == 1 && (qflags & AUTOSELECT_SINGLE)) {
949         *pick_list = (menu_item *) alloc(sizeof (menu_item));
950         (*pick_list)->item.a_obj = last;
951         (*pick_list)->count = last->quan;
952         return 1;
953     }
954
955     sortflags = (((flags.sortloot == 'f'
956                    || (flags.sortloot == 'l' && !(qflags & USE_INVLET)))
957                   ? SORTLOOT_LOOT
958                   : ((qflags & USE_INVLET) ? SORTLOOT_INVLET : 0))
959                  | (flags.sortpack ? SORTLOOT_PACK : 0)
960                  | ((qflags & FEEL_COCKATRICE) ? SORTLOOT_PETRIFY : 0));
961     sortedolist = sortloot(&olist, sortflags,
962                            (qflags & BY_NEXTHERE) ? TRUE : FALSE, allow);
963
964     win = create_nhwindow(NHW_MENU);
965     start_menu(win);
966     any = zeroany;
967     /*
968      * Run through the list and add the objects to the menu.  If
969      * INVORDER_SORT is set, we'll run through the list once for
970      * each type so we can group them.  The allow function was
971      * called by sortloot() and will be called once per item here.
972      */
973     pack = flags.inv_order;
974     first = TRUE;
975     do {
976         printed_type_name = FALSE;
977         for (srtoli = sortedolist; ((curr = srtoli->obj) != 0); ++srtoli) {
978             if (sorted && curr->oclass != *pack)
979                 continue;
980             if ((qflags & FEEL_COCKATRICE) && curr->otyp == CORPSE
981                 && will_feel_cockatrice(curr, FALSE)) {
982                 destroy_nhwindow(win); /* stop the menu and revert */
983                 (void) look_here(0, FALSE);
984                 unsortloot(&sortedolist);
985                 return 0;
986             }
987             if ((*allow)(curr)) {
988                 /* if sorting, print type name (once only) */
989                 if (sorted && !printed_type_name) {
990                     any = zeroany;
991                     add_menu(win, NO_GLYPH, &any, 0, 0, iflags.menu_headings,
992                              let_to_name(*pack, FALSE,
993                                          ((how != PICK_NONE)
994                                           && iflags.menu_head_objsym)),
995                              MENU_UNSELECTED);
996                     printed_type_name = TRUE;
997                 }
998
999                 any.a_obj = curr;
1000                 add_menu(win, obj_to_glyph(curr, rn2_on_display_rng), &any,
1001                          (qflags & USE_INVLET) ? curr->invlet
1002                            : (first && curr->oclass == COIN_CLASS) ? '$' : 0,
1003                          def_oc_syms[(int) objects[curr->otyp].oc_class].sym,
1004                          ATR_NONE, doname_with_price(curr), MENU_UNSELECTED);
1005                 first = FALSE;
1006             }
1007         }
1008         pack++;
1009     } while (sorted && *pack);
1010     unsortloot(&sortedolist);
1011
1012     if (engulfer) {
1013         char buf[BUFSZ];
1014
1015         any = zeroany;
1016         if (sorted && n > 1) {
1017 #if 0 /*JP:T*/
1018             Sprintf(buf, "%s Creatures",
1019                     is_animal(u.ustuck->data) ? "Swallowed" : "Engulfed");
1020 #else
1021             Sprintf(buf, "%s\8d\9e\82Ü\82ê\82Ä\82¢\82é\89ö\95¨",
1022                     is_animal(u.ustuck->data) ? "\88ù\82Ý" : "\8aª\82«");
1023 #endif
1024             add_menu(win, NO_GLYPH, &any, 0, 0, iflags.menu_headings, buf,
1025                      MENU_UNSELECTED);
1026         }
1027         fake_hero_object = zeroobj;
1028         fake_hero_object.quan = 1L; /* not strictly necessary... */
1029         any.a_obj = &fake_hero_object;
1030         add_menu(win, mon_to_glyph(&youmonst, rn2_on_display_rng), &any,
1031                  /* fake inventory letter, no group accelerator */
1032                  CONTAINED_SYM, 0, ATR_NONE, an(self_lookat(buf)),
1033                  MENU_UNSELECTED);
1034     }
1035
1036     end_menu(win, qstr);
1037     n = select_menu(win, how, pick_list);
1038     destroy_nhwindow(win);
1039
1040     if (n > 0) {
1041         menu_item *mi;
1042         int k;
1043
1044         /* fix up counts:  -1 means no count used => pick all;
1045            if fake_hero_object was picked, discard that choice */
1046         for (i = k = 0, mi = *pick_list; i < n; i++, mi++) {
1047             curr = mi->item.a_obj;
1048             if (curr == &fake_hero_object) {
1049                 /* this isn't actually possible; fake item representing
1050                    hero is only included for look here (':'), not pickup,
1051                    and that's PICK_NONE so we can't get here from there */
1052 /*JP
1053                 You_cant("pick yourself up!");
1054 */
1055                 You_cant("\8e©\95ª\8e©\90g\82Í\8fE\82¦\82È\82¢\81I");
1056                 continue;
1057             }
1058             if (engulfer_minvent && curr->owornmask != 0L) {
1059 /*JP
1060                 You_cant("pick %s up.", ysimple_name(curr));
1061 */
1062                 You_cant("%s\82ð\8fE\82¦\82È\82¢\81D", ysimple_name(curr));
1063                 continue;
1064             }
1065             if (mi->count == -1L || mi->count > curr->quan)
1066                 mi->count = curr->quan;
1067             if (k < i)
1068                 (*pick_list)[k] = *mi;
1069             ++k;
1070         }
1071         if (!k) {
1072             /* fake_hero was only choice so discard whole list */
1073             free((genericptr_t) *pick_list);
1074             *pick_list = 0;
1075             n = 0;
1076         } else if (k < n) {
1077             /* other stuff plus fake_hero; last slot is now unused
1078                (could be more than one if player tried to pick items
1079                worn by engulfer) */
1080             while (n > k) {
1081                 --n;
1082                 (*pick_list)[n].item = zeroany;
1083                 (*pick_list)[n].count = 0L;
1084             }
1085         }
1086     } else if (n < 0) {
1087         /* -1 is used for SIGNAL_NOMENU, so callers don't expect it
1088            to indicate that the player declined to make a choice */
1089         n = (qflags & SIGNAL_ESCAPE) ? -2 : 0;
1090     }
1091     return n;
1092 }
1093
1094 /*
1095  * allow menu-based category (class) selection (for Drop,take off etc.)
1096  *
1097  */
1098 int
1099 query_category(qstr, olist, qflags, pick_list, how)
1100 const char *qstr;      /* query string */
1101 struct obj *olist;     /* the list to pick from */
1102 int qflags;            /* behaviour modification flags */
1103 menu_item **pick_list; /* return list of items picked */
1104 int how;               /* type of query */
1105 {
1106     int n;
1107     winid win;
1108     struct obj *curr;
1109     char *pack;
1110     anything any;
1111     boolean collected_type_name;
1112     char invlet;
1113     int ccount;
1114     boolean FDECL((*ofilter), (OBJ_P)) = (boolean FDECL((*), (OBJ_P))) 0;
1115     boolean do_unpaid = FALSE;
1116     boolean do_blessed = FALSE, do_cursed = FALSE, do_uncursed = FALSE,
1117             do_buc_unknown = FALSE;
1118     int num_buc_types = 0;
1119
1120     *pick_list = (menu_item *) 0;
1121     if (!olist)
1122         return 0;
1123     if ((qflags & UNPAID_TYPES) && count_unpaid(olist))
1124         do_unpaid = TRUE;
1125     if (qflags & WORN_TYPES)
1126         ofilter = is_worn;
1127     if ((qflags & BUC_BLESSED) && count_buc(olist, BUC_BLESSED, ofilter)) {
1128         do_blessed = TRUE;
1129         num_buc_types++;
1130     }
1131     if ((qflags & BUC_CURSED) && count_buc(olist, BUC_CURSED, ofilter)) {
1132         do_cursed = TRUE;
1133         num_buc_types++;
1134     }
1135     if ((qflags & BUC_UNCURSED) && count_buc(olist, BUC_UNCURSED, ofilter)) {
1136         do_uncursed = TRUE;
1137         num_buc_types++;
1138     }
1139     if ((qflags & BUC_UNKNOWN) && count_buc(olist, BUC_UNKNOWN, ofilter)) {
1140         do_buc_unknown = TRUE;
1141         num_buc_types++;
1142     }
1143
1144     ccount = count_categories(olist, qflags);
1145     /* no point in actually showing a menu for a single category */
1146     if (ccount == 1 && !do_unpaid && num_buc_types <= 1
1147         && !(qflags & BILLED_TYPES)) {
1148         for (curr = olist; curr; curr = FOLLOW(curr, qflags)) {
1149             if (ofilter && !(*ofilter)(curr))
1150                 continue;
1151             break;
1152         }
1153         if (curr) {
1154             *pick_list = (menu_item *) alloc(sizeof(menu_item));
1155             (*pick_list)->item.a_int = curr->oclass;
1156             n = 1;
1157         } else {
1158             debugpline0("query_category: no single object match");
1159             n = 0;
1160         }
1161         /* early return is ok; there's no temp window yet */
1162         return n;
1163     }
1164
1165     win = create_nhwindow(NHW_MENU);
1166     start_menu(win);
1167     pack = flags.inv_order;
1168
1169     if (qflags & CHOOSE_ALL) {
1170         invlet = 'A';
1171         any = zeroany;
1172         any.a_int = 'A';
1173         add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE,
1174 /*JP
1175                  (qflags & WORN_TYPES) ? "Auto-select every item being worn"
1176 */
1177                  (qflags & WORN_TYPES) ? "\90g\82É\82Â\82¯\82ç\82ê\82é\95¨\91S\82Ä"
1178 /*JP
1179                                        : "Auto-select every item",
1180 */
1181                                        : "\91S\82Ä",
1182                  MENU_UNSELECTED);
1183
1184         any = zeroany;
1185         add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE, "", MENU_UNSELECTED);
1186     }
1187
1188     if ((qflags & ALL_TYPES) && (ccount > 1)) {
1189         invlet = 'a';
1190         any = zeroany;
1191         any.a_int = ALL_TYPES_SELECTED;
1192         add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE,
1193 /*JP
1194                  (qflags & WORN_TYPES) ? "All worn types" : "All types",
1195 */
1196                  (qflags & WORN_TYPES) ? "\90g\82É\82Â\82¯\82é\82à\82Ì\91S\82Ä" : "\91S\82Ä",
1197                  MENU_UNSELECTED);
1198         invlet = 'b';
1199     } else
1200         invlet = 'a';
1201     do {
1202         collected_type_name = FALSE;
1203         for (curr = olist; curr; curr = FOLLOW(curr, qflags)) {
1204             if (curr->oclass == *pack) {
1205                 if (ofilter && !(*ofilter)(curr))
1206                     continue;
1207                 if (!collected_type_name) {
1208                     any = zeroany;
1209                     any.a_int = curr->oclass;
1210                     add_menu(
1211                         win, NO_GLYPH, &any, invlet++,
1212                         def_oc_syms[(int) objects[curr->otyp].oc_class].sym,
1213                         ATR_NONE, let_to_name(*pack, FALSE,
1214                                               (how != PICK_NONE)
1215                                                   && iflags.menu_head_objsym),
1216                         MENU_UNSELECTED);
1217                     collected_type_name = TRUE;
1218                 }
1219             }
1220         }
1221         pack++;
1222         if (invlet >= 'u') {
1223             impossible("query_category: too many categories");
1224             n = 0;
1225             goto query_done;
1226         }
1227     } while (*pack);
1228
1229     if (do_unpaid || (qflags & BILLED_TYPES) || do_blessed || do_cursed
1230         || do_uncursed || do_buc_unknown) {
1231         any = zeroany;
1232         add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE, "", MENU_UNSELECTED);
1233     }
1234
1235     /* unpaid items if there are any */
1236     if (do_unpaid) {
1237         invlet = 'u';
1238         any = zeroany;
1239         any.a_int = 'u';
1240 /*JP
1241         add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE, "Unpaid items",
1242 */
1243         add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE, "\96¢\95¥\82Ì\82à\82Ì",
1244                  MENU_UNSELECTED);
1245     }
1246     /* billed items: checked by caller, so always include if BILLED_TYPES */
1247     if (qflags & BILLED_TYPES) {
1248         invlet = 'x';
1249         any = zeroany;
1250         any.a_int = 'x';
1251         add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE,
1252 /*JP
1253                  "Unpaid items already used up", MENU_UNSELECTED);
1254 */
1255                  "\96¢\95¥\82Å\8eg\82Á\82Ä\82µ\82Ü\82Á\82½\82à\82Ì", MENU_UNSELECTED);
1256     }
1257
1258     /* items with b/u/c/unknown if there are any;
1259        this cluster of menu entries is in alphabetical order,
1260        reversing the usual sequence of 'U' and 'C' in BUCX */
1261     if (do_blessed) {
1262         invlet = 'B';
1263         any = zeroany;
1264         any.a_int = 'B';
1265         add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE,
1266 /*JP
1267                  "Items known to be Blessed", MENU_UNSELECTED);
1268 */
1269                  "\8fj\95\9f\82³\82ê\82Ä\82¢\82é\82Æ\82í\82©\82Á\82Ä\82¢\82é\82à\82Ì", MENU_UNSELECTED);
1270     }
1271     if (do_cursed) {
1272         invlet = 'C';
1273         any = zeroany;
1274         any.a_int = 'C';
1275         add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE,
1276 /*JP
1277                  "Items known to be Cursed", MENU_UNSELECTED);
1278 */
1279                  "\8eô\82í\82ê\82Ä\82¢\82é\82Æ\82í\82©\82Á\82Ä\82¢\82é\82à\82Ì", MENU_UNSELECTED);
1280     }
1281     if (do_uncursed) {
1282         invlet = 'U';
1283         any = zeroany;
1284         any.a_int = 'U';
1285         add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE,
1286 /*JP
1287                  "Items known to be Uncursed", MENU_UNSELECTED);
1288 */
1289                  "\8eô\82í\82ê\82Ä\82¢\82È\82¢\82Æ\82í\82©\82Á\82Ä\82¢\82é\82à\82Ì", MENU_UNSELECTED);
1290     }
1291     if (do_buc_unknown) {
1292         invlet = 'X';
1293         any = zeroany;
1294         any.a_int = 'X';
1295 #if 0 /*JP:T*/
1296         add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE,
1297                  "Items of unknown Bless/Curse status", MENU_UNSELECTED);
1298 #else
1299         add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE,
1300                  "\8fj\95\9f\81^\8eô\82¢\82ª\82í\82©\82ç\82È\82¢\82à\82Ì", MENU_UNSELECTED);
1301 #endif
1302     }
1303     end_menu(win, qstr);
1304     n = select_menu(win, how, pick_list);
1305  query_done:
1306     destroy_nhwindow(win);
1307     if (n < 0)
1308         n = 0; /* caller's don't expect -1 */
1309     return n;
1310 }
1311
1312 STATIC_OVL int
1313 count_categories(olist, qflags)
1314 struct obj *olist;
1315 int qflags;
1316 {
1317     char *pack;
1318     boolean counted_category;
1319     int ccount = 0;
1320     struct obj *curr;
1321
1322     pack = flags.inv_order;
1323     do {
1324         counted_category = FALSE;
1325         for (curr = olist; curr; curr = FOLLOW(curr, qflags)) {
1326             if (curr->oclass == *pack) {
1327                 if ((qflags & WORN_TYPES)
1328                     && !(curr->owornmask & (W_ARMOR | W_ACCESSORY
1329                                             | W_WEAPONS)))
1330                     continue;
1331                 if (!counted_category) {
1332                     ccount++;
1333                     counted_category = TRUE;
1334                 }
1335             }
1336         }
1337         pack++;
1338     } while (*pack);
1339     return ccount;
1340 }
1341
1342 /*
1343  *  How much the weight of the given container will change when the given
1344  *  object is removed from it.  Use before and after weight amounts rather
1345  *  than trying to match the calculation used by weight() in mkobj.c.
1346  */
1347 STATIC_OVL int
1348 delta_cwt(container, obj)
1349 struct obj *container, *obj;
1350 {
1351     struct obj **prev;
1352     int owt, nwt;
1353
1354     if (container->otyp != BAG_OF_HOLDING)
1355         return obj->owt;
1356
1357     owt = nwt = container->owt;
1358     /* find the object so that we can remove it */
1359     for (prev = &container->cobj; *prev; prev = &(*prev)->nobj)
1360         if (*prev == obj)
1361             break;
1362     if (!*prev) {
1363         panic("delta_cwt: obj not inside container?");
1364     } else {
1365         /* temporarily remove the object and calculate resulting weight */
1366         *prev = obj->nobj;
1367         nwt = weight(container);
1368         *prev = obj; /* put the object back; obj->nobj is still valid */
1369     }
1370     return owt - nwt;
1371 }
1372
1373 /* could we carry `obj'? if not, could we carry some of it/them? */
1374 STATIC_OVL long
1375 carry_count(obj, container, count, telekinesis, wt_before, wt_after)
1376 struct obj *obj, *container; /* object to pick up, bag it's coming out of */
1377 long count;
1378 boolean telekinesis;
1379 int *wt_before, *wt_after;
1380 {
1381     boolean adjust_wt = container && carried(container),
1382             is_gold = obj->oclass == COIN_CLASS;
1383     int wt, iw, ow, oow;
1384     long qq, savequan, umoney;
1385     unsigned saveowt;
1386 #if 0 /*JP*/
1387     const char *verb, *prefx1, *prefx2, *suffx;
1388 #else
1389     const char *verb, *prefx1;
1390 #endif
1391     char obj_nambuf[BUFSZ], where[BUFSZ];
1392
1393     savequan = obj->quan;
1394     saveowt = obj->owt;
1395     umoney = money_cnt(invent);
1396     iw = max_capacity();
1397
1398     if (count != savequan) {
1399         obj->quan = count;
1400         obj->owt = (unsigned) weight(obj);
1401     }
1402     wt = iw + (int) obj->owt;
1403     if (adjust_wt)
1404         wt -= delta_cwt(container, obj);
1405     /* This will go with silver+copper & new gold weight */
1406     if (is_gold) /* merged gold might affect cumulative weight */
1407         wt -= (GOLD_WT(umoney) + GOLD_WT(count) - GOLD_WT(umoney + count));
1408     if (count != savequan) {
1409         obj->quan = savequan;
1410         obj->owt = saveowt;
1411     }
1412     *wt_before = iw;
1413     *wt_after = wt;
1414
1415     if (wt < 0)
1416         return count;
1417
1418     /* see how many we can lift */
1419     if (is_gold) {
1420         iw -= (int) GOLD_WT(umoney);
1421         if (!adjust_wt) {
1422             qq = GOLD_CAPACITY((long) iw, umoney);
1423         } else {
1424             oow = 0;
1425             qq = 50L - (umoney % 100L) - 1L;
1426             if (qq < 0L)
1427                 qq += 100L;
1428             for (; qq <= count; qq += 100L) {
1429                 obj->quan = qq;
1430                 obj->owt = (unsigned) GOLD_WT(qq);
1431                 ow = (int) GOLD_WT(umoney + qq);
1432                 ow -= delta_cwt(container, obj);
1433                 if (iw + ow >= 0)
1434                     break;
1435                 oow = ow;
1436             }
1437             iw -= oow;
1438             qq -= 100L;
1439         }
1440         if (qq < 0L)
1441             qq = 0L;
1442         else if (qq > count)
1443             qq = count;
1444         wt = iw + (int) GOLD_WT(umoney + qq);
1445     } else if (count > 1 || count < obj->quan) {
1446         /*
1447          * Ugh. Calc num to lift by changing the quan of of the
1448          * object and calling weight.
1449          *
1450          * This works for containers only because containers
1451          * don't merge.  -dean
1452          */
1453         for (qq = 1L; qq <= count; qq++) {
1454             obj->quan = qq;
1455             obj->owt = (unsigned) (ow = weight(obj));
1456             if (adjust_wt)
1457                 ow -= delta_cwt(container, obj);
1458             if (iw + ow >= 0)
1459                 break;
1460             wt = iw + ow;
1461         }
1462         --qq;
1463     } else {
1464         /* there's only one, and we can't lift it */
1465         qq = 0L;
1466     }
1467     obj->quan = savequan;
1468     obj->owt = saveowt;
1469
1470     if (qq < count) {
1471         /* some message will be given */
1472         Strcpy(obj_nambuf, doname(obj));
1473         if (container) {
1474 /*JP
1475             Sprintf(where, "in %s", the(xname(container)));
1476 */
1477             Sprintf(where, "%s\82Ì\92\86\82É\93ü\82Á\82Ä\82¢\82é", the(xname(container)));
1478 /*JP
1479             verb = "carry";
1480 */
1481             verb = "\89^\82×\82È\82¢";
1482         } else {
1483 /*JP
1484             Strcpy(where, "lying here");
1485 */
1486             Strcpy(where, "\82±\82±\82É\92u\82¢\82Ä\82 \82é");
1487 /*JP
1488             verb = telekinesis ? "acquire" : "lift";
1489 */
1490             verb = telekinesis ? "\8al\93¾\82Å\82«\82È\82¢" : "\8e\9d\82¿\82 \82°\82ç\82ê\82È\82¢";
1491         }
1492     } else {
1493         /* lint suppression */
1494         *obj_nambuf = *where = '\0';
1495         verb = "";
1496     }
1497     /* we can carry qq of them */
1498     if (qq > 0) {
1499         if (qq < count)
1500 #if 0 /*JP:T*/
1501             You("can only %s %s of the %s %s.", verb,
1502                 (qq == 1L) ? "one" : "some", obj_nambuf, where);
1503 #else
1504             You("%s%s\82Ì\82¤\82¿\82Ì%s\82µ\82©%s\81D",
1505                 where, obj_nambuf, (qq == 1L) ? "\88ê\82Â" : "\82¢\82­\82Â\82©", verb);
1506 #endif
1507         *wt_after = wt;
1508         return qq;
1509     }
1510
1511     if (!container)
1512 #if 0 /*JP:T*/
1513         Strcpy(where, "here"); /* slightly shorter form */
1514 #else
1515         Strcpy(where, "\82±\82±\82É\82Í");  /* slightly shorter form */
1516 #endif
1517     if (invent || umoney) {
1518 #if 0 /*JP*/
1519         prefx1 = "you cannot ";
1520         prefx2 = "";
1521         suffx = " any more";
1522 #else
1523         prefx1 = "\82±\82ê\88È\8fã";
1524 #endif
1525     } else {
1526 #if 0 /*JP*/
1527         prefx1 = (obj->quan == 1L) ? "it " : "even one ";
1528         prefx2 = "is too heavy for you to ";
1529         suffx = "";
1530 #else
1531         prefx1 = "\8fd\82·\82¬\82Ä";
1532 #endif
1533     }
1534 #if 0 /*JP:C*/
1535     There("%s %s %s, but %s%s%s%s.", otense(obj, "are"), obj_nambuf, where,
1536           prefx1, prefx2, verb, suffx);
1537 #else
1538     pline("%s%s\82ª\82 \82é\81C\82µ\82©\82µ%s%s\81D",
1539           where, obj_nambuf, prefx1, verb);
1540 #endif
1541
1542     /* *wt_after = iw; */
1543     return 0L;
1544 }
1545
1546 /* determine whether character is able and player is willing to carry `obj' */
1547 STATIC_OVL
1548 int
1549 lift_object(obj, container, cnt_p, telekinesis)
1550 struct obj *obj, *container; /* object to pick up, bag it's coming out of */
1551 long *cnt_p;
1552 boolean telekinesis;
1553 {
1554     int result, old_wt, new_wt, prev_encumbr, next_encumbr;
1555
1556     if (obj->otyp == BOULDER && Sokoban) {
1557 #if 0 /*JP:T*/
1558         You("cannot get your %s around this %s.", body_part(HAND),
1559             xname(obj));
1560 #else
1561         You("%s\82ð%s\82Å\8e\9d\82¿\82 \82°\82é\82±\82Æ\82ª\82Å\82«\82È\82¢\81D",
1562                         xname(obj), body_part(HAND));
1563 #endif
1564         return -1;
1565     }
1566     /* override weight consideration for loadstone picked up by anybody
1567        and for boulder picked up by hero poly'd into a giant; override
1568        availability of open inventory slot iff not already carrying one */
1569     if (obj->otyp == LOADSTONE
1570         || (obj->otyp == BOULDER && throws_rocks(youmonst.data))) {
1571         if (inv_cnt(FALSE) < 52 || !carrying(obj->otyp)
1572             || merge_choice(invent, obj))
1573             return 1; /* lift regardless of current situation */
1574         /* if we reach here, we're out of slots and already have at least
1575            one of these, so treat this one more like a normal item */
1576 #if 0 /*JP:T*/
1577         You("are carrying too much stuff to pick up %s %s.",
1578             (obj->quan == 1L) ? "another" : "more", simpleonames(obj));
1579 #else
1580         You("%s\82ð%s\8fE\82¤\82É\82Í\95¨\82ð\8e\9d\82¿\82·\82¬\82Ä\82¢\82é\81D",
1581             simpleonames(obj), (obj->quan == 1L) ? "\82à\82¤\88ê\82Â" : "\82à\82Á\82Æ");
1582 #endif
1583         return -1;
1584     }
1585
1586     *cnt_p = carry_count(obj, container, *cnt_p, telekinesis,
1587                          &old_wt, &new_wt);
1588     if (*cnt_p < 1L) {
1589         result = -1; /* nothing lifted */
1590     } else if (obj->oclass != COIN_CLASS
1591                /* [exception for gold coins will have to change
1592                    if silver/copper ones ever get implemented] */
1593                && inv_cnt(FALSE) >= 52 && !merge_choice(invent, obj)) {
1594         /* if there is some gold here (and we haven't already skipped it),
1595            we aren't limited by the 52 item limit for it, but caller and
1596            "grandcaller" aren't prepared to skip stuff and then pickup
1597            just gold, so the best we can do here is vary the message */
1598 #if 0 /*JP*/
1599         Your("knapsack cannot accommodate any more items%s.",
1600              /* floor follows by nexthere, otherwise container so by nobj */
1601              nxtobj(obj, GOLD_PIECE, (boolean) (obj->where == OBJ_FLOOR))
1602                  ? " (except gold)" : "");
1603 #else
1604         Your("\83i\83b\83v\83U\83b\83N\82Í%s\82±\82ê\88È\8fã\83A\83C\83e\83\80\82ð\8bl\82ß\8d\9e\82ß\82È\82¢\81D",
1605              /* floor follows by nexthere, otherwise container so by nobj */
1606              nxtobj(obj, GOLD_PIECE, (boolean) (obj->where == OBJ_FLOOR))
1607                  ? "(\8bà\89Ý\88È\8aO)" : "");
1608 #endif
1609         result = -1; /* nothing lifted */
1610     } else {
1611         result = 1;
1612         prev_encumbr = near_capacity();
1613         if (prev_encumbr < flags.pickup_burden)
1614             prev_encumbr = flags.pickup_burden;
1615         next_encumbr = calc_capacity(new_wt - old_wt);
1616         if (next_encumbr > prev_encumbr) {
1617             if (telekinesis) {
1618                 result = 0; /* don't lift */
1619             } else {
1620                 char qbuf[BUFSZ];
1621 #if 1 /*JP*/
1622                 char qsfx[BUFSZ];
1623 #endif
1624                 long savequan = obj->quan;
1625
1626                 obj->quan = *cnt_p;
1627 #if 0 /*JP*/
1628                 Strcpy(qbuf, (next_encumbr > HVY_ENCUMBER)
1629                                  ? overloadmsg
1630                                  : (next_encumbr > MOD_ENCUMBER)
1631                                        ? nearloadmsg
1632                                        : moderateloadmsg);
1633 #else
1634                 /*JP:\83A\83C\83e\83\80\96¼\82Ì\8cã\82ë\82É\95t\82¯\82½\82¢\82ªsafe_qbuf\82Ìqsuffix\82Í
1635                      qbuf\82Æ\8b¤\97p\82Å\82«\82È\82¢\82Ì\82Å\95Ê\82Éqsfx\82ð\97p\88Ó\82µ\82Ä\82»\82¿\82ç\82ð\8eg\82¤*/
1636                 Strcpy(qsfx, (next_encumbr > HVY_ENCUMBER)
1637                                  ? overloadmsg
1638                                  : (next_encumbr > MOD_ENCUMBER)
1639                                        ? nearloadmsg
1640                                        : moderateloadmsg);
1641                 Strcat(qsfx, "\81D\91±\82¯\82Ü\82·\82©\81H");
1642 #endif
1643
1644 #if 0 /*JP*//*\93ú\96{\8cê\82Å\82Í\82Ç\82¿\82ç\82à\81u\8e\9d\82Â\81v\82Å\8dÏ\82Ü\82¹\82é*/
1645                 if (container)
1646                     (void) strsubst(qbuf, "lifting", "removing");
1647 #endif
1648 #if 0 /*JP*/
1649                 Strcat(qbuf, " ");
1650                 (void) safe_qbuf(qbuf, qbuf, ".  Continue?", obj, doname,
1651                                  ansimpleoname, something);
1652 #else /*JP:\91O\82É\82Í\89½\82à\95t\82¯\82¸\8cã\82ë\82Éqsfx\82ð\95t\82¯\82é*/
1653                 (void) safe_qbuf(qbuf, "", qsfx, obj, doname,
1654                                  ansimpleoname, "\82±\82ê");
1655 #endif
1656                 obj->quan = savequan;
1657                 switch (ynq(qbuf)) {
1658                 case 'q':
1659                     result = -1;
1660                     break;
1661                 case 'n':
1662                     result = 0;
1663                     break;
1664                 default:
1665                     break; /* 'y' => result == 1 */
1666                 }
1667                 clear_nhwindow(WIN_MESSAGE);
1668             }
1669         }
1670     }
1671
1672     if (obj->otyp == SCR_SCARE_MONSTER && result <= 0 && !container)
1673         obj->spe = 0;
1674     return result;
1675 }
1676
1677 /*
1678  * Pick up <count> of obj from the ground and add it to the hero's inventory.
1679  * Returns -1 if caller should break out of its loop, 0 if nothing picked
1680  * up, 1 if otherwise.
1681  */
1682 int
1683 pickup_object(obj, count, telekinesis)
1684 struct obj *obj;
1685 long count;
1686 boolean telekinesis; /* not picking it up directly by hand */
1687 {
1688     int res, nearload;
1689
1690     if (obj->quan < count) {
1691         impossible("pickup_object: count %ld > quan %ld?", count, obj->quan);
1692         return 0;
1693     }
1694
1695     /* In case of auto-pickup, where we haven't had a chance
1696        to look at it yet; affects docall(SCR_SCARE_MONSTER). */
1697     if (!Blind)
1698         obj->dknown = 1;
1699
1700     if (obj == uchain) { /* do not pick up attached chain */
1701         return 0;
1702     } else if (obj->where == OBJ_MINVENT && obj->owornmask != 0L
1703                && u.uswallow && obj->ocarry == u.ustuck) {
1704 /*JP
1705         You_cant("pick %s up.", ysimple_name(obj));
1706 */
1707         You_cant("%s\82ð\8fE\82¦\82È\82¢\81D", ysimple_name(obj));
1708         return 0;
1709     } else if (obj->oartifact && !touch_artifact(obj, &youmonst)) {
1710         return 0;
1711     } else if (obj->otyp == CORPSE) {
1712         if (fatal_corpse_mistake(obj, telekinesis)
1713             || rider_corpse_revival(obj, telekinesis))
1714             return -1;
1715     } else if (obj->otyp == SCR_SCARE_MONSTER) {
1716         if (obj->blessed)
1717             obj->blessed = 0;
1718         else if (!obj->spe && !obj->cursed)
1719             obj->spe = 1;
1720         else {
1721 #if 0 /*JP:T*/
1722             pline_The("scroll%s %s to dust as you %s %s up.", plur(obj->quan),
1723                       otense(obj, "turn"), telekinesis ? "raise" : "pick",
1724                       (obj->quan == 1L) ? "it" : "them");
1725 #else
1726             pline("\8aª\95¨\82Í\82 \82È\82½\82ª%s\8fã\82°\82é\82Æ\90o\82Æ\82È\82Á\82Ä\82µ\82Ü\82Á\82½\81D",
1727                       telekinesis ? "\8e\9d\82¿" : "\8fE\82¢");
1728 #endif
1729             if (!(objects[SCR_SCARE_MONSTER].oc_name_known)
1730                 && !(objects[SCR_SCARE_MONSTER].oc_uname))
1731                 docall(obj);
1732             useupf(obj, obj->quan);
1733             return 1; /* tried to pick something up and failed, but
1734                          don't want to terminate pickup loop yet   */
1735         }
1736     }
1737
1738     if ((res = lift_object(obj, (struct obj *) 0, &count, telekinesis)) <= 0)
1739         return res;
1740
1741     /* Whats left of the special case for gold :-) */
1742     if (obj->oclass == COIN_CLASS)
1743         context.botl = 1;
1744     if (obj->quan != count && obj->otyp != LOADSTONE)
1745         obj = splitobj(obj, count);
1746
1747     obj = pick_obj(obj);
1748
1749     if (uwep && uwep == obj)
1750         mrg_to_wielded = TRUE;
1751     nearload = near_capacity();
1752     prinv(nearload == SLT_ENCUMBER ? moderateloadmsg : (char *) 0, obj,
1753           count);
1754     mrg_to_wielded = FALSE;
1755     return 1;
1756 }
1757
1758 /*
1759  * Do the actual work of picking otmp from the floor or monster's interior
1760  * and putting it in the hero's inventory.  Take care of billing.  Return a
1761  * pointer to the object where otmp ends up.  This may be different
1762  * from otmp because of merging.
1763  */
1764 struct obj *
1765 pick_obj(otmp)
1766 struct obj *otmp;
1767 {
1768     struct obj *result;
1769     int ox = otmp->ox, oy = otmp->oy;
1770     boolean robshop = (!u.uswallow && otmp != uball && costly_spot(ox, oy));
1771
1772     obj_extract_self(otmp);
1773     newsym(ox, oy);
1774
1775     /* for shop items, addinv() needs to be after addtobill() (so that
1776        object merger can take otmp->unpaid into account) but before
1777        remote_robbery() (which calls rob_shop() which calls setpaid()
1778        after moving costs of unpaid items to shop debt; setpaid()
1779        calls clear_unpaid() for lots of object chains, but 'otmp' isn't
1780        on any of those between obj_extract_self() and addinv(); for
1781        3.6.0, 'otmp' remained flagged as an unpaid item in inventory
1782        and triggered impossible() every time inventory was examined) */
1783     if (robshop) {
1784         char saveushops[5], fakeshop[2];
1785
1786         /* addtobill cares about your location rather than the object's;
1787            usually they'll be the same, but not when using telekinesis
1788            (if ever implemented) or a grappling hook */
1789         Strcpy(saveushops, u.ushops);
1790         fakeshop[0] = *in_rooms(ox, oy, SHOPBASE);
1791         fakeshop[1] = '\0';
1792         Strcpy(u.ushops, fakeshop);
1793         /* sets obj->unpaid if necessary */
1794         addtobill(otmp, TRUE, FALSE, FALSE);
1795         Strcpy(u.ushops, saveushops);
1796         robshop = otmp->unpaid && !index(u.ushops, *fakeshop);
1797     }
1798
1799     result = addinv(otmp);
1800     /* if you're taking a shop item from outside the shop, make shk notice */
1801     if (robshop)
1802         remote_burglary(ox, oy);
1803
1804     return result;
1805 }
1806
1807 /*
1808  * prints a message if encumbrance changed since the last check and
1809  * returns the new encumbrance value (from near_capacity()).
1810  */
1811 int
1812 encumber_msg()
1813 {
1814     static int oldcap = UNENCUMBERED;
1815     int newcap = near_capacity();
1816
1817     if (oldcap < newcap) {
1818         switch (newcap) {
1819         case 1:
1820 /*JP
1821             Your("movements are slowed slightly because of your load.");
1822 */
1823             Your("\93®\82«\82Í\89×\95¨\82Ì\82½\82ß\82É\8f­\82µ\92x\82­\82È\82Á\82½\81D");
1824             break;
1825         case 2:
1826 /*JP
1827             You("rebalance your load.  Movement is difficult.");
1828 */
1829             You("\89×\95¨\82Ì\92Þ\8d\87\82ð\82Æ\82è\92¼\82µ\82½\82ª\81C\93®\82«\82É\82­\82¢\81D");
1830             break;
1831         case 3:
1832 #if 0 /*JP:T*/
1833             You("%s under your heavy load.  Movement is very hard.",
1834                 stagger(youmonst.data, "stagger"));
1835 #else
1836             You("\89×\95¨\82Ì\8fd\82Ý\82Å\82æ\82ë\82æ\82ë\82µ\82½\81D\93®\82­\82Ì\82ª\94ñ\8fí\82É\82«\82Â\82¢\81D");
1837 #endif
1838             break;
1839         default:
1840 #if 0 /*JP:T*/
1841             You("%s move a handspan with this load!",
1842                 newcap == 4 ? "can barely" : "can't even");
1843 #else
1844             You("\82±\82Ì\8fd\82³\82Å\82Í\8f­\82µ\82à\93®\82¯\82È\82¢\81I");
1845 #endif
1846             break;
1847         }
1848         context.botl = 1;
1849     } else if (oldcap > newcap) {
1850         switch (newcap) {
1851         case 0:
1852 /*JP
1853             Your("movements are now unencumbered.");
1854 */
1855             Your("\93®\82«\82Í\8ay\82É\82È\82Á\82½\81D");
1856             break;
1857         case 1:
1858 /*JP
1859             Your("movements are only slowed slightly by your load.");
1860 */
1861             You("\82¿\82å\82Á\82Æ\93®\82«\82â\82·\82­\82È\82Á\82½\81D");
1862             break;
1863         case 2:
1864 /*JP
1865             You("rebalance your load.  Movement is still difficult.");
1866 */
1867             You("\89×\95¨\82Ì\92Þ\8d\87\82ð\82Æ\82è\92¼\82µ\82½\81D\82¾\82ª\82Ü\82¾\93®\82­\82Ì\82Í\82«\82Â\82¢\81D");
1868             break;
1869         case 3:
1870 #if 0 /*JP:T*/
1871             You("%s under your load.  Movement is still very hard.",
1872                 stagger(youmonst.data, "stagger"));
1873 #else
1874             You("\89×\95¨\82Ì\8fd\82Ý\82ª\82¸\82Á\82µ\82è\82Æ\82­\82é\81D\82Ü\82¾\93®\82­\82Ì\82ª\94ñ\8fí\82É\82«\82Â\82¢\81D");
1875 #endif
1876             break;
1877         }
1878         context.botl = 1;
1879     }
1880
1881     oldcap = newcap;
1882     return newcap;
1883 }
1884
1885 /* Is there a container at x,y. Optional: return count of containers at x,y */
1886 int
1887 container_at(x, y, countem)
1888 int x, y;
1889 boolean countem;
1890 {
1891     struct obj *cobj, *nobj;
1892     int container_count = 0;
1893
1894     for (cobj = level.objects[x][y]; cobj; cobj = nobj) {
1895         nobj = cobj->nexthere;
1896         if (Is_container(cobj)) {
1897             container_count++;
1898             if (!countem)
1899                 break;
1900         }
1901     }
1902     return container_count;
1903 }
1904
1905 STATIC_OVL boolean
1906 able_to_loot(x, y, looting)
1907 int x, y;
1908 boolean looting; /* loot vs tip */
1909 {
1910 /*JP
1911     const char *verb = looting ? "loot" : "tip";
1912 */
1913     const char *verb = looting ? "\8aJ\82¯\82é" : "\82Ð\82Á\82­\82è\95Ô\82·";
1914
1915     if (!can_reach_floor(TRUE)) {
1916         if (u.usteed && P_SKILL(P_RIDING) < P_BASIC)
1917             rider_cant_reach(); /* not skilled enough to reach */
1918         else
1919             cant_reach_floor(x, y, FALSE, TRUE);
1920         return FALSE;
1921     } else if ((is_pool(x, y) && (looting || !Underwater)) || is_lava(x, y)) {
1922         /* at present, can't loot in water even when Underwater;
1923            can tip underwater, but not when over--or stuck in--lava */
1924 #if 0 /*JP:T*/
1925         You("cannot %s things that are deep in the %s.", verb,
1926             hliquid(is_lava(x, y) ? "lava" : "water"));
1927 #else
1928         You("%s\82É\90[\82­\82É\92¾\82ñ\82¾\82à\82Ì\82ð%s\82±\82Æ\82Í\82Å\82«\82È\82¢\81D",
1929             hliquid(is_lava(u.ux, u.uy) ? "\97n\8aâ" : "\90\85"), verb);
1930 #endif
1931         return FALSE;
1932     } else if (nolimbs(youmonst.data)) {
1933 /*JP
1934         pline("Without limbs, you cannot %s anything.", verb);
1935 */
1936         pline("\8eè\91«\82ª\82È\82¢\82Ì\82Å\81C%s\82±\82Æ\82Í\82Å\82«\82È\82¢\81D", verb);
1937         return FALSE;
1938     } else if (looting && !freehand()) {
1939 /*JP
1940         pline("Without a free %s, you cannot loot anything.",
1941 */
1942         pline("\8e©\97R\82É\82È\82é%s\82ª\82È\82¢\82Ì\82Å\81C\8aJ\82¯\82é\82±\82Æ\82Í\82Å\82«\82È\82¢\81D",
1943               body_part(HAND));
1944         return FALSE;
1945     }
1946     return TRUE;
1947 }
1948
1949 STATIC_OVL boolean
1950 mon_beside(x, y)
1951 int x, y;
1952 {
1953     int i, j, nx, ny;
1954
1955     for (i = -1; i <= 1; i++)
1956         for (j = -1; j <= 1; j++) {
1957             nx = x + i;
1958             ny = y + j;
1959             if (isok(nx, ny) && MON_AT(nx, ny))
1960                 return TRUE;
1961         }
1962     return FALSE;
1963 }
1964
1965 STATIC_OVL int
1966 do_loot_cont(cobjp, cindex, ccount)
1967 struct obj **cobjp;
1968 int cindex, ccount; /* index of this container (1..N), number of them (N) */
1969 {
1970     struct obj *cobj = *cobjp;
1971
1972     if (!cobj)
1973         return 0;
1974     if (cobj->olocked) {
1975         if (ccount < 2)
1976 #if 0 /*JP:T*/
1977             pline("%s locked.",
1978                   cobj->lknown ? "It is" : "Hmmm, it turns out to be");
1979 #else
1980             pline("%s\8c®\82ª\82©\82©\82Á\82Ä\82¢\82é\81D",
1981                   cobj->lknown ? "" : "\82Þ\81[\82ñ\81C");
1982 #endif
1983         else if (cobj->lknown)
1984 /*JP
1985             pline("%s is locked.", The(xname(cobj)));
1986 */
1987             pline("%s\82Í\8c®\82ª\82©\82©\82Á\82Ä\82¢\82é\81D", xname(cobj));
1988         else
1989 /*JP
1990             pline("Hmmm, %s turns out to be locked.", the(xname(cobj)));
1991 */
1992             pline("\82Þ\81[\82ñ\81C%s\82Í\8c®\82ª\82©\82©\82Á\82Ä\82¢\82é\81D", xname(cobj));
1993         cobj->lknown = 1;
1994         return 0;
1995     }
1996     cobj->lknown = 1; /* floor container, so no need for update_inventory() */
1997
1998     if (cobj->otyp == BAG_OF_TRICKS) {
1999         int tmp;
2000
2001 /*JP
2002         You("carefully open %s...", the(xname(cobj)));
2003 */
2004         You("\90T\8fd\82É%s\82ð\8aJ\82¯\82½\81D\81D\81D", xname(cobj));
2005 /*JP
2006         pline("It develops a huge set of teeth and bites you!");
2007 */
2008         pline("\8a\93\82©\82ç\91å\82«\82È\8e\95\82ª\90\82¦\82Ä\82«\82Ä\81C\82 \82È\82½\82ð\8a\9a\82ñ\82¾\81I");
2009         tmp = rnd(10);
2010 /*JP
2011         losehp(Maybe_Half_Phys(tmp), "carnivorous bag", KILLED_BY_AN);
2012 */
2013         losehp(Maybe_Half_Phys(tmp), "\90H\93÷\8a\93\82É\8a\9a\82Ü\82ê\82Ä", KILLED_BY_AN);
2014         makeknown(BAG_OF_TRICKS);
2015         abort_looting = TRUE;
2016         return 1;
2017     }
2018
2019 /*JP
2020     You("%sopen %s...", (!cobj->cknown || !cobj->lknown) ? "carefully " : "",
2021 */
2022     You("%s%s\82ð\8aJ\82¯\82½\81D\81D\81D", (!cobj->cknown || !cobj->lknown) ? "\90T\8fd\82É" : "",
2023         the(xname(cobj)));
2024     return use_container(cobjp, 0, (boolean) (cindex < ccount));
2025 }
2026
2027 /* loot a container on the floor or loot saddle from mon. */
2028 int
2029 doloot()
2030 {
2031     struct obj *cobj, *nobj;
2032     register int c = -1;
2033     int timepassed = 0;
2034     coord cc;
2035     boolean underfoot = TRUE;
2036 #if 0 /*JP*//*not used*/
2037     const char *dont_find_anything = "don't find anything";
2038 #endif
2039     struct monst *mtmp;
2040     char qbuf[BUFSZ];
2041     int prev_inquiry = 0;
2042     boolean prev_loot = FALSE;
2043     int num_conts = 0;
2044
2045     abort_looting = FALSE;
2046
2047     if (check_capacity((char *) 0)) {
2048         /* "Can't do that while carrying so much stuff." */
2049         return 0;
2050     }
2051     if (nohands(youmonst.data)) {
2052 #if 0 /*JP:T*/
2053         You("have no hands!"); /* not `body_part(HAND)' */
2054 #else
2055         pline("\82 \82È\82½\82É\82Í\8eè\82ª\82È\82¢\81I");
2056 #endif
2057         return 0;
2058     }
2059     if (Confusion) {
2060         if (rn2(6) && reverse_loot())
2061             return 1;
2062         if (rn2(2)) {
2063 /*JP
2064             pline("Being confused, you find nothing to loot.");
2065 */
2066             pline("\8d¬\97\90\82µ\82Ä\82¢\82é\82Ì\82Å\81C\8aJ\82¯\82é\82à\82Ì\82ð\8c©\82Â\82¯\82ç\82ê\82È\82¢\81D");
2067             return 1; /* costs a turn */
2068         }             /* else fallthrough to normal looting */
2069     }
2070     cc.x = u.ux;
2071     cc.y = u.uy;
2072
2073     if (iflags.menu_requested)
2074         goto lootmon;
2075
2076  lootcont:
2077     if ((num_conts = container_at(cc.x, cc.y, TRUE)) > 0) {
2078         boolean anyfound = FALSE;
2079
2080         if (!able_to_loot(cc.x, cc.y, TRUE))
2081             return 0;
2082
2083         if (Blind && !uarmg) {
2084             /* if blind and without gloves, attempting to #loot at the
2085                location of a cockatrice corpse is fatal before asking
2086                whether to manipulate any containers */
2087             for (nobj = sobj_at(CORPSE, cc.x, cc.y); nobj;
2088                  nobj = nxtobj(nobj, CORPSE, TRUE))
2089                 if (will_feel_cockatrice(nobj, FALSE)) {
2090                     feel_cockatrice(nobj, FALSE);
2091                     /* if life-saved (or poly'd into stone golem),
2092                        terminate attempt to loot */
2093                     return 1;
2094                 }
2095         }
2096
2097         if (num_conts > 1) {
2098             /* use a menu to loot many containers */
2099             int n, i;
2100             winid win;
2101             anything any;
2102             menu_item *pick_list = (menu_item *) 0;
2103
2104             any.a_void = 0;
2105             win = create_nhwindow(NHW_MENU);
2106             start_menu(win);
2107
2108             for (cobj = level.objects[cc.x][cc.y]; cobj;
2109                  cobj = cobj->nexthere)
2110                 if (Is_container(cobj)) {
2111                     any.a_obj = cobj;
2112                     add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE,
2113                              doname(cobj), MENU_UNSELECTED);
2114                 }
2115 /*JP
2116             end_menu(win, "Loot which containers?");
2117 */
2118             end_menu(win, "\82Ç\82ê\82ð\8aJ\82¯\82Ü\82·\82©\81H");
2119             n = select_menu(win, PICK_ANY, &pick_list);
2120             destroy_nhwindow(win);
2121
2122             if (n > 0) {
2123                 for (i = 1; i <= n; i++) {
2124                     cobj = pick_list[i - 1].item.a_obj;
2125                     timepassed |= do_loot_cont(&cobj, i, n);
2126                     if (abort_looting) {
2127                         /* chest trap or magic bag explosion or <esc> */
2128                         free((genericptr_t) pick_list);
2129                         return timepassed;
2130                     }
2131                 }
2132                 free((genericptr_t) pick_list);
2133             }
2134             if (n != 0)
2135                 c = 'y';
2136         } else {
2137             for (cobj = level.objects[cc.x][cc.y]; cobj; cobj = nobj) {
2138                 nobj = cobj->nexthere;
2139
2140                 if (Is_container(cobj)) {
2141 #if 0 /*JP:T*/
2142                     c = ynq(safe_qbuf(qbuf, "There is ", " here, loot it?",
2143                                       cobj, doname, ansimpleoname,
2144                                       "a container"));
2145 #else
2146                     c = ynq(safe_qbuf(qbuf, "\82±\82±\82É\82Í", "\82ª\82 \82é\81C\8aJ\82¯\82Ü\82·\82©\81H",
2147                                       cobj, doname, ansimpleoname,
2148                                       "\93ü\82ê\95¨"));
2149 #endif
2150                     if (c == 'q')
2151                         return timepassed;
2152                     if (c == 'n')
2153                         continue;
2154                     anyfound = TRUE;
2155
2156                     timepassed |= do_loot_cont(&cobj, 1, 1);
2157                     if (abort_looting)
2158                         /* chest trap or magic bag explosion or <esc> */
2159                         return timepassed;
2160                 }
2161             }
2162             if (anyfound)
2163                 c = 'y';
2164         }
2165     } else if (IS_GRAVE(levl[cc.x][cc.y].typ)) {
2166 /*JP
2167         You("need to dig up the grave to effectively loot it...");
2168 */
2169         You("\95æ\8dr\82ç\82µ\82ð\82·\82é\82É\82Í\8c@\82ç\82È\82­\82Ä\82Í\81D\81D\81D");
2170     }
2171
2172     /*
2173      * 3.3.1 introduced directional looting for some things.
2174      */
2175  lootmon:
2176     if (c != 'y' && mon_beside(u.ux, u.uy)) {
2177 /*JP
2178         if (!get_adjacent_loc("Loot in what direction?",
2179 */
2180         if (!get_adjacent_loc("\82Ç\82Ì\95û\8cü\82ð\92²\82×\82é\81H",
2181 /*JP
2182                               "Invalid loot location", u.ux, u.uy, &cc))
2183 */
2184                               "\96³\8cø\82È\95û\8cü", u.ux, u.uy, &cc))
2185             return 0;
2186         if (cc.x == u.ux && cc.y == u.uy) {
2187             underfoot = TRUE;
2188             if (container_at(cc.x, cc.y, FALSE))
2189                 goto lootcont;
2190         } else
2191             underfoot = FALSE;
2192         if (u.dz < 0) {
2193 #if 0 /*JP:T*/
2194             You("%s to loot on the %s.", dont_find_anything,
2195                 ceiling(cc.x, cc.y));
2196 #else
2197             You("%s\82ð\92²\82×\82½\82ª\89½\82à\82Ý\82Â\82©\82ç\82È\82©\82Á\82½\81D",
2198                 ceiling(cc.x, cc.y));
2199 #endif
2200             timepassed = 1;
2201             return timepassed;
2202         }
2203         mtmp = m_at(cc.x, cc.y);
2204         if (mtmp)
2205             timepassed = loot_mon(mtmp, &prev_inquiry, &prev_loot);
2206         /* always use a turn when choosing a direction is impaired,
2207            even if you've successfully targetted a saddled creature
2208            and then answered "no" to the "remove its saddle?" prompt */
2209         if (Confusion || Stunned)
2210             timepassed = 1;
2211
2212         /* Preserve pre-3.3.1 behaviour for containers.
2213          * Adjust this if-block to allow container looting
2214          * from one square away to change that in the future.
2215          */
2216         if (!underfoot) {
2217             if (container_at(cc.x, cc.y, FALSE)) {
2218                 if (mtmp) {
2219 #if 0 /*JP:T*/
2220                     You_cant("loot anything %sthere with %s in the way.",
2221                              prev_inquiry ? "else " : "", mon_nam(mtmp));
2222 #else
2223                     pline("%s\82ª\82¢\82é\82Ì\82Å%s\94 \82ð\8aJ\82¯\82ç\82ê\82È\82¢\81D",
2224                             mon_nam(mtmp), prev_inquiry ? "\82Ù\82©\82Ì" : "");
2225 #endif
2226                     return timepassed;
2227                 } else {
2228 #if 0 /*JP:T*/
2229                     You("have to be at a container to loot it.");
2230 #else
2231                     You("\82Í\94 \82ð\8aJ\82¯\82é\82½\82ß\82É\82Í\93¯\82\88Ê\92u\82É\82¢\82È\82¯\82ê\82Î\82È\82ç\82È\82¢\81D");
2232 #endif
2233                 }
2234             } else {
2235 #if 0 /*JP:T*/
2236                 You("%s %sthere to loot.", dont_find_anything,
2237                     (prev_inquiry || prev_loot) ? "else " : "");
2238 #else
2239                 pline("\82±\82±\82É\82Í%s\8aJ\82¯\82ç\82ê\82é\82à\82Ì\82Í\82È\82¢\81D",
2240                     (prev_inquiry || prev_loot) ? "\82Ù\82©\82É" : "");
2241 #endif
2242                 return timepassed;
2243             }
2244         }
2245     } else if (c != 'y' && c != 'n') {
2246 #if 0 /*JP:T*/
2247         You("%s %s to loot.", dont_find_anything,
2248             underfoot ? "here" : "there");
2249 #else
2250         pline("%s\82É\82Í\8aJ\82¯\82ç\82ê\82é\82à\82Ì\82Í\82È\82¢\81D",
2251             underfoot ? "\82±\82±" : "\82»\82±");
2252 #endif
2253     }
2254     return timepassed;
2255 }
2256
2257 /* called when attempting to #loot while confused */
2258 STATIC_OVL boolean
2259 reverse_loot()
2260 {
2261     struct obj *goldob = 0, *coffers, *otmp, boxdummy;
2262     struct monst *mon;
2263     long contribution;
2264     int n, x = u.ux, y = u.uy;
2265
2266     if (!rn2(3)) {
2267         /* n objects: 1/(n+1) chance per object plus 1/(n+1) to fall off end
2268          */
2269         for (n = inv_cnt(TRUE), otmp = invent; otmp; --n, otmp = otmp->nobj)
2270             if (!rn2(n + 1)) {
2271 /*JP
2272                 prinv("You find old loot:", otmp, 0L);
2273 */
2274                 prinv("\88È\91O\8aJ\82¯\82½\82à\82Ì:", otmp, 0L);
2275                 return TRUE;
2276             }
2277         return FALSE;
2278     }
2279
2280     /* find a money object to mess with */
2281     for (goldob = invent; goldob; goldob = goldob->nobj)
2282         if (goldob->oclass == COIN_CLASS) {
2283             contribution = ((long) rnd(5) * goldob->quan + 4L) / 5L;
2284             if (contribution < goldob->quan)
2285                 goldob = splitobj(goldob, contribution);
2286             break;
2287         }
2288     if (!goldob)
2289         return FALSE;
2290
2291     if (!IS_THRONE(levl[x][y].typ)) {
2292         dropx(goldob);
2293         /* the dropped gold might have fallen to lower level */
2294         if (g_at(x, y))
2295 /*JP
2296             pline("Ok, now there is loot here.");
2297 */
2298             pline("\83I\81[\83P\81[\81C\82±\82±\82É\98d\98G\82ð\92u\82¢\82Ä\82¨\82±\82¤\81D");
2299     } else {
2300         /* find original coffers chest if present, otherwise use nearest one */
2301         otmp = 0;
2302         for (coffers = fobj; coffers; coffers = coffers->nobj)
2303             if (coffers->otyp == CHEST) {
2304                 if (coffers->spe == 2)
2305                     break; /* a throne room chest */
2306                 if (!otmp
2307                     || distu(coffers->ox, coffers->oy)
2308                            < distu(otmp->ox, otmp->oy))
2309                     otmp = coffers; /* remember closest ordinary chest */
2310             }
2311         if (!coffers)
2312             coffers = otmp;
2313
2314         if (coffers) {
2315 /*JP
2316             verbalize("Thank you for your contribution to reduce the debt.");
2317 */
2318             verbalize("\90Ô\8e\9a\8d\91\8dÂ\95Ô\8dÏ\82Ì\82½\82ß\82Ì\8añ\95t\82É\8a´\8eÓ\82µ\82Ü\82·\81D");
2319             freeinv(goldob);
2320             (void) add_to_container(coffers, goldob);
2321             coffers->owt = weight(coffers);
2322             coffers->cknown = 0;
2323             if (!coffers->olocked) {
2324                 boxdummy = zeroobj, boxdummy.otyp = SPE_WIZARD_LOCK;
2325                 (void) boxlock(coffers, &boxdummy);
2326             }
2327         } else if (levl[x][y].looted != T_LOOTED
2328                    && (mon = makemon(courtmon(), x, y, NO_MM_FLAGS)) != 0) {
2329             freeinv(goldob);
2330             add_to_minv(mon, goldob);
2331 /*JP
2332             pline("The exchequer accepts your contribution.");
2333 */
2334             pline("\8dà\96±\8fÈ\82Í\82 \82È\82½\82Ì\8añ\95t\82ð\8eó\82¯\82Æ\82Á\82½\81D");
2335             if (!rn2(10))
2336                 levl[x][y].looted = T_LOOTED;
2337         } else {
2338 /*JP
2339             You("drop %s.", doname(goldob));
2340 */
2341             You("%s\82ð\97\8e\82µ\82½\81D", doname(goldob));
2342             dropx(goldob);
2343         }
2344     }
2345     return TRUE;
2346 }
2347
2348 /* loot_mon() returns amount of time passed.
2349  */
2350 int
2351 loot_mon(mtmp, passed_info, prev_loot)
2352 struct monst *mtmp;
2353 int *passed_info;
2354 boolean *prev_loot;
2355 {
2356     int c = -1;
2357     int timepassed = 0;
2358     struct obj *otmp;
2359     char qbuf[QBUFSZ];
2360
2361     /* 3.3.1 introduced the ability to remove saddle from a steed.
2362      *  *passed_info is set to TRUE if a loot query was given.
2363      *  *prev_loot is set to TRUE if something was actually acquired in here.
2364      */
2365     if (mtmp && mtmp != u.usteed && (otmp = which_armor(mtmp, W_SADDLE))) {
2366         long unwornmask;
2367
2368         if (passed_info)
2369             *passed_info = 1;
2370 #if 0 /*JP:T*/
2371         Sprintf(qbuf, "Do you want to remove the saddle from %s?",
2372                 x_monnam(mtmp, ARTICLE_THE, (char *) 0,
2373                          SUPPRESS_SADDLE, FALSE));
2374 #else
2375         Sprintf(qbuf, "%s\82©\82ç\88Æ\82ð\82Í\82¸\82µ\82Ü\82·\82©\81H",
2376                 x_monnam(mtmp, ARTICLE_THE, (char *) 0,
2377                          SUPPRESS_SADDLE, FALSE));
2378 #endif
2379         if ((c = yn_function(qbuf, ynqchars, 'n')) == 'y') {
2380             if (nolimbs(youmonst.data)) {
2381 #if 0 /*JP:T*/
2382                 You_cant("do that without limbs."); /* not body_part(HAND) */
2383 #else
2384                 You_cant("\8eè\82ª\82È\82¢\82Æ\82Å\82«\82È\82¢\81D");
2385 #endif
2386                 return 0;
2387             }
2388             if (otmp->cursed) {
2389 /*JP
2390                 You("can't.  The saddle seems to be stuck to %s.",
2391 */
2392                 pline("\88Æ\82Í%s\82É\82­\82Á\82Â\82¢\82Ä\82¢\82é\82æ\82¤\82¾\81D",
2393                     x_monnam(mtmp, ARTICLE_THE, (char *) 0,
2394                              SUPPRESS_SADDLE, FALSE));
2395                 /* the attempt costs you time */
2396                 return 1;
2397             }
2398             obj_extract_self(otmp);
2399             if ((unwornmask = otmp->owornmask) != 0L) {
2400                 mtmp->misc_worn_check &= ~unwornmask;
2401                 otmp->owornmask = 0L;
2402                 update_mon_intrinsics(mtmp, otmp, FALSE, FALSE);
2403             }
2404 /*JP
2405             otmp = hold_another_object(otmp, "You drop %s!", doname(otmp),
2406 */
2407             otmp = hold_another_object(otmp, "%s\82ð\97\8e\82Æ\82µ\82½\81I", doname(otmp),
2408                                        (const char *) 0);
2409             nhUse(otmp);
2410             timepassed = rnd(3);
2411             if (prev_loot)
2412                 *prev_loot = TRUE;
2413         } else if (c == 'q') {
2414             return 0;
2415         }
2416     }
2417     /* 3.4.0 introduced ability to pick things up from swallower's stomach */
2418     if (u.uswallow) {
2419         int count = passed_info ? *passed_info : 0;
2420
2421         timepassed = pickup(count);
2422     }
2423     return timepassed;
2424 }
2425
2426 /*
2427  * Decide whether an object being placed into a magic bag will cause
2428  * it to explode.  If the object is a bag itself, check recursively.
2429  */
2430 STATIC_OVL boolean
2431 mbag_explodes(obj, depthin)
2432 struct obj *obj;
2433 int depthin;
2434 {
2435     /* these won't cause an explosion when they're empty */
2436     if ((obj->otyp == WAN_CANCELLATION || obj->otyp == BAG_OF_TRICKS)
2437         && obj->spe <= 0)
2438         return FALSE;
2439
2440     /* odds: 1/1, 2/2, 3/4, 4/8, 5/16, 6/32, 7/64, 8/128, 9/128, 10/128,... */
2441     if ((Is_mbag(obj) || obj->otyp == WAN_CANCELLATION)
2442         && (rn2(1 << (depthin > 7 ? 7 : depthin)) <= depthin))
2443         return TRUE;
2444     else if (Has_contents(obj)) {
2445         struct obj *otmp;
2446
2447         for (otmp = obj->cobj; otmp; otmp = otmp->nobj)
2448             if (mbag_explodes(otmp, depthin + 1))
2449                 return TRUE;
2450     }
2451     return FALSE;
2452 }
2453
2454 STATIC_OVL long
2455 boh_loss(container, held)
2456 struct obj *container;
2457 int held;
2458 {
2459     /* sometimes toss objects if a cursed magic bag */
2460     if (Is_mbag(container) && container->cursed && Has_contents(container)) {
2461         long loss = 0L;
2462         struct obj *curr, *otmp;
2463
2464         for (curr = container->cobj; curr; curr = otmp) {
2465             otmp = curr->nobj;
2466             if (!rn2(13)) {
2467                 obj_extract_self(curr);
2468                 loss += mbag_item_gone(held, curr);
2469             }
2470         }
2471         return loss;
2472     }
2473     return 0;
2474 }
2475
2476 /* Returns: -1 to stop, 1 item was inserted, 0 item was not inserted. */
2477 STATIC_PTR int
2478 in_container(obj)
2479 register struct obj *obj;
2480 {
2481     boolean floor_container = !carried(current_container);
2482     boolean was_unpaid = FALSE;
2483     char buf[BUFSZ];
2484
2485     if (!current_container) {
2486         impossible("<in> no current_container?");
2487         return 0;
2488     } else if (obj == uball || obj == uchain) {
2489 /*JP
2490         You("must be kidding.");
2491 */
2492         pline("\82²\8fç\92k\82ð\81D");
2493         return 0;
2494     } else if (obj == current_container) {
2495 /*JP
2496         pline("That would be an interesting topological exercise.");
2497 */
2498         pline("\82»\82ê\82Í\8b»\96¡\82ð\82»\82»\82ç\82ê\82é\83g\83|\83\8d\83W\81[\82Ì\96â\91è\82¾\81D");
2499         return 0;
2500     } else if (obj->owornmask & (W_ARMOR | W_ACCESSORY)) {
2501 #if 0 /*JP:T*/
2502         Norep("You cannot %s %s you are wearing.",
2503               Icebox ? "refrigerate" : "stash", something);
2504 #else
2505         Norep("\90g\82É\82Â\82¯\82Ä\82¢\82é\82à\82Ì\82ð%s\82±\82Æ\82Í\82Å\82«\82È\82¢\81D", 
2506               Icebox ? "\97â\93\80\82·\82é" : "\82µ\82Ü\82¤");
2507 #endif
2508         return 0;
2509     } else if ((obj->otyp == LOADSTONE) && obj->cursed) {
2510         set_bknown(obj, 1);
2511 /*JP
2512         pline_The("stone%s won't leave your person.", plur(obj->quan));
2513 */
2514         pline("\82Ç\82¤\82¢\82¤\82í\82¯\82©\82»\82Ì\90Î\82ð\82µ\82Ü\82¤\82±\82Æ\82Í\82Å\82«\82È\82¢\81D");
2515         return 0;
2516     } else if (obj->otyp == AMULET_OF_YENDOR
2517                || obj->otyp == CANDELABRUM_OF_INVOCATION
2518                || obj->otyp == BELL_OF_OPENING
2519                || obj->otyp == SPE_BOOK_OF_THE_DEAD) {
2520         /* Prohibit Amulets in containers; if you allow it, monsters can't
2521          * steal them.  It also becomes a pain to check to see if someone
2522          * has the Amulet.  Ditto for the Candelabrum, the Bell and the Book.
2523          */
2524 /*JP
2525         pline("%s cannot be confined in such trappings.", The(xname(obj)));
2526 */
2527         pline("%s\82Í\8bl\82ß\82é\82±\82Æ\82Í\82Å\82«\82È\82¢\81D", The(xname(obj)));
2528         return 0;
2529     } else if (obj->otyp == LEASH && obj->leashmon != 0) {
2530 /*JP
2531         pline("%s attached to your pet.", Tobjnam(obj, "are"));
2532 */
2533         pline("%s\82Í\83y\83b\83g\82É\95t\82¯\82ç\82ê\82Ä\82¢\82é\81D", xname(obj));
2534         return 0;
2535     } else if (obj == uwep) {
2536         if (welded(obj)) {
2537             weldmsg(obj);
2538             return 0;
2539         }
2540         setuwep((struct obj *) 0);
2541         /* This uwep check is obsolete.  It dates to 3.0 and earlier when
2542          * unwielding Firebrand would be fatal in hell if hero had no other
2543          * fire resistance.  Life-saving would force it to be re-wielded.
2544          */
2545         if (uwep)
2546             return 0; /* unwielded, died, rewielded */
2547     } else if (obj == uswapwep) {
2548         setuswapwep((struct obj *) 0);
2549     } else if (obj == uquiver) {
2550         setuqwep((struct obj *) 0);
2551     }
2552
2553     if (fatal_corpse_mistake(obj, FALSE))
2554         return -1;
2555
2556     /* boxes, boulders, and big statues can't fit into any container */
2557     if (obj->otyp == ICE_BOX || Is_box(obj) || obj->otyp == BOULDER
2558         || (obj->otyp == STATUE && bigmonst(&mons[obj->corpsenm]))) {
2559         /*
2560          *  xname() uses a static result array.  Save obj's name
2561          *  before current_container's name is computed.  Don't
2562          *  use the result of strcpy() within You() --- the order
2563          *  of evaluation of the parameters is undefined.
2564          */
2565         Strcpy(buf, the(xname(obj)));
2566 /*JP
2567         You("cannot fit %s into %s.", buf, the(xname(current_container)));
2568 */
2569         pline("%s\82ð%s\82É\8bl\82ß\8d\9e\82Þ\82±\82Æ\82Í\82Å\82«\82È\82¢\81D", buf, the(xname(current_container)));
2570         return 0;
2571     }
2572
2573     freeinv(obj);
2574
2575     if (obj_is_burning(obj)) /* this used to be part of freeinv() */
2576         (void) snuff_lit(obj);
2577
2578     if (floor_container && costly_spot(u.ux, u.uy)) {
2579         /* defer gold until after put-in message */
2580         if (obj->oclass != COIN_CLASS) {
2581             /* sellobj() will take an unpaid item off the shop bill */
2582             was_unpaid = obj->unpaid ? TRUE : FALSE;
2583             /* don't sell when putting the item into your own container,
2584              * but handle billing correctly */
2585             sellobj_state(current_container->no_charge
2586                           ? SELL_DONTSELL : SELL_DELIBERATE);
2587             sellobj(obj, u.ux, u.uy);
2588             sellobj_state(SELL_NORMAL);
2589         }
2590     }
2591     if (Icebox && !age_is_relative(obj)) {
2592         obj->age = monstermoves - obj->age; /* actual age */
2593         /* stop any corpse timeouts when frozen */
2594         if (obj->otyp == CORPSE && obj->timed) {
2595             long rot_alarm = stop_timer(ROT_CORPSE, obj_to_any(obj));
2596
2597             (void) stop_timer(REVIVE_MON, obj_to_any(obj));
2598             /* mark a non-reviving corpse as such */
2599             if (rot_alarm)
2600                 obj->norevive = 1;
2601         }
2602     } else if (Is_mbag(current_container) && mbag_explodes(obj, 0)) {
2603         /* explicitly mention what item is triggering the explosion */
2604 /*JP
2605         pline("As you put %s inside, you are blasted by a magical explosion!",
2606 */
2607         pline("%s\82ð\92\86\82É\93ü\82ê\82é\82Æ\81C\82 \82È\82½\82Í\96\82\96@\82Ì\94\9a\94­\82ð\97\81\82Ñ\82½\81I",
2608               doname(obj));
2609         /* did not actually insert obj yet */
2610         if (was_unpaid)
2611             addtobill(obj, FALSE, FALSE, TRUE);
2612         obfree(obj, (struct obj *) 0);
2613         /* if carried, shop goods will be flagged 'unpaid' and obfree() will
2614            handle bill issues, but if on floor, we need to put them on bill
2615            before deleting them (non-shop items will be flagged 'no_charge') */
2616         if (floor_container
2617             && costly_spot(current_container->ox, current_container->oy)) {
2618             struct obj save_no_charge;
2619
2620             save_no_charge.no_charge = current_container->no_charge;
2621             addtobill(current_container, FALSE, FALSE, FALSE);
2622             /* addtobill() clears no charge; we need to set it back
2623                so that useupf() doesn't double bill */
2624             current_container->no_charge = save_no_charge.no_charge;
2625         }
2626         delete_contents(current_container);
2627         if (!floor_container)
2628             useup(current_container);
2629         else if (obj_here(current_container, u.ux, u.uy))
2630             useupf(current_container, current_container->quan);
2631         else
2632             panic("in_container:  bag not found.");
2633
2634 /*JP
2635         losehp(d(6, 6), "magical explosion", KILLED_BY_AN);
2636 */
2637         losehp(d(6, 6), "\96\82\96@\82Ì\94\9a\94­\82Å", KILLED_BY_AN);
2638         current_container = 0; /* baggone = TRUE; */
2639     }
2640
2641     if (current_container) {
2642         Strcpy(buf, the(xname(current_container)));
2643 /*JP
2644         You("put %s into %s.", doname(obj), buf);
2645 */
2646         You("%s\82ð%s\82Ì\92\86\82É\82µ\82Ü\82Á\82½\81D", doname(obj), buf);
2647
2648         /* gold in container always needs to be added to credit */
2649         if (floor_container && obj->oclass == COIN_CLASS)
2650             sellobj(obj, current_container->ox, current_container->oy);
2651         (void) add_to_container(current_container, obj);
2652         current_container->owt = weight(current_container);
2653     }
2654     /* gold needs this, and freeinv() many lines above may cause
2655      * the encumbrance to disappear from the status, so just always
2656      * update status immediately.
2657      */
2658     bot();
2659     return (current_container ? 1 : -1);
2660 }
2661
2662 /* askchain() filter used by in_container();
2663  * returns True if the container is intact and 'obj' isn't it, False if
2664  * container is gone (magic bag explosion) or 'obj' is the container itself;
2665  * also used by getobj() when picking a single item to stash
2666  */
2667 int
2668 ck_bag(obj)
2669 struct obj *obj;
2670 {
2671     return (current_container && obj != current_container);
2672 }
2673
2674 /* Returns: -1 to stop, 1 item was removed, 0 item was not removed. */
2675 STATIC_PTR int
2676 out_container(obj)
2677 register struct obj *obj;
2678 {
2679     register struct obj *otmp;
2680     boolean is_gold = (obj->oclass == COIN_CLASS);
2681     int res, loadlev;
2682     long count;
2683
2684     if (!current_container) {
2685         impossible("<out> no current_container?");
2686         return -1;
2687     } else if (is_gold) {
2688         obj->owt = weight(obj);
2689     }
2690
2691     if (obj->oartifact && !touch_artifact(obj, &youmonst))
2692         return 0;
2693
2694     if (fatal_corpse_mistake(obj, FALSE))
2695         return -1;
2696
2697     count = obj->quan;
2698     if ((res = lift_object(obj, current_container, &count, FALSE)) <= 0)
2699         return res;
2700
2701     if (obj->quan != count && obj->otyp != LOADSTONE)
2702         obj = splitobj(obj, count);
2703
2704     /* Remove the object from the list. */
2705     obj_extract_self(obj);
2706     current_container->owt = weight(current_container);
2707
2708     if (Icebox)
2709         removed_from_icebox(obj);
2710
2711     if (!obj->unpaid && !carried(current_container)
2712         && costly_spot(current_container->ox, current_container->oy)) {
2713         obj->ox = current_container->ox;
2714         obj->oy = current_container->oy;
2715         addtobill(obj, FALSE, FALSE, FALSE);
2716     }
2717     if (is_pick(obj))
2718         pick_pick(obj); /* shopkeeper feedback */
2719
2720     otmp = addinv(obj);
2721     loadlev = near_capacity();
2722     prinv(loadlev ? ((loadlev < MOD_ENCUMBER)
2723 /*JP
2724                         ? "You have a little trouble removing"
2725 */
2726                         ? "\82ð\89^\82Ô\82Ì\82Í\8f­\81X\8d¢\93ï\82¾\81D"
2727 /*JP
2728                         : "You have much trouble removing")
2729 */
2730                         : "\82ð\89^\82Ô\82Ì\82Í\82©\82È\82è\8d¢\93ï\82¾\81D")
2731                   : (char *) 0,
2732           otmp, count);
2733
2734     if (is_gold) {
2735         bot(); /* update character's gold piece count immediately */
2736     }
2737     return 1;
2738 }
2739
2740 /* taking a corpse out of an ice box needs a couple of adjustments */
2741 STATIC_OVL void
2742 removed_from_icebox(obj)
2743 struct obj *obj;
2744 {
2745     if (!age_is_relative(obj)) {
2746         obj->age = monstermoves - obj->age; /* actual age */
2747         if (obj->otyp == CORPSE)
2748             start_corpse_timeout(obj);
2749     }
2750 }
2751
2752 /* an object inside a cursed bag of holding is being destroyed */
2753 STATIC_OVL long
2754 mbag_item_gone(held, item)
2755 int held;
2756 struct obj *item;
2757 {
2758     struct monst *shkp;
2759     long loss = 0L;
2760
2761     if (item->dknown)
2762 /*JP
2763         pline("%s %s vanished!", Doname2(item), otense(item, "have"));
2764 */
2765         pline("%s\82Í\8fÁ\82¦\8b\8e\82Á\82½\81I", Doname2(item));
2766     else
2767 #if 0 /*JP:T*/
2768         You("%s %s disappear!", Blind ? "notice" : "see", doname(item));
2769 #else
2770         You("%s\82ª\8c©\82¦\82È\82­\82È\82é\82Ì%s\81D", doname(item), Blind ? "\82É\8bC\82Ã\82¢\82½" : "\82ð\8c©\82½");
2771 #endif
2772
2773     if (*u.ushops && (shkp = shop_keeper(*u.ushops)) != 0) {
2774         if (held ? (boolean) item->unpaid : costly_spot(u.ux, u.uy))
2775             loss = stolen_value(item, u.ux, u.uy, (boolean) shkp->mpeaceful,
2776                                 TRUE);
2777     }
2778     obfree(item, (struct obj *) 0);
2779     return loss;
2780 }
2781
2782 /* used for #loot/apply, #tip, and final disclosure */
2783 void
2784 observe_quantum_cat(box, makecat, givemsg)
2785 struct obj *box;
2786 boolean makecat, givemsg;
2787 {
2788 /*JP
2789     static NEARDATA const char sc[] = "Schroedinger's Cat";
2790 */
2791     static NEARDATA const char sc[] = "\83V\83\85\83\8c\83f\83B\83\93\83K\81[\82Ì\94L";
2792     struct obj *deadcat;
2793     struct monst *livecat = 0;
2794     xchar ox, oy;
2795     boolean itsalive = !rn2(2);
2796
2797     if (get_obj_location(box, &ox, &oy, 0))
2798         box->ox = ox, box->oy = oy; /* in case it's being carried */
2799
2800     /* this isn't really right, since any form of observation
2801        (telepathic or monster/object/food detection) ought to
2802        force the determination of alive vs dead state; but basing it
2803        just on opening or disclosing the box is much simpler to cope with */
2804
2805     /* SchroedingersBox already has a cat corpse in it */
2806     deadcat = box->cobj;
2807     if (itsalive) {
2808         if (makecat)
2809             livecat = makemon(&mons[PM_HOUSECAT], box->ox, box->oy,
2810                               NO_MINVENT | MM_ADJACENTOK);
2811         if (livecat) {
2812             livecat->mpeaceful = 1;
2813             set_malign(livecat);
2814             if (givemsg) {
2815                 if (!canspotmon(livecat))
2816 #if 0 /*JP:T*/
2817                     You("think %s brushed your %s.", something,
2818                         body_part(FOOT));
2819 #else
2820                     You("%s\82ª\82 \82È\82½\82Ì%s\82ð\82­\82·\82®\82Á\82½\82Æ\8ev\82Á\82½\81D", something,
2821                         body_part(FOOT));
2822 #endif
2823                 else
2824 #if 0 /*JP:T*/
2825                     pline("%s inside the box is still alive!",
2826                           Monnam(livecat));
2827 #else
2828                     pline("\94 \82Ì\82È\82©\82Ì%s\82Í\82Ü\82¾\90\82«\82Ä\82¢\82é\81I",
2829                           Monnam(livecat));
2830 #endif
2831             }
2832             (void) christen_monst(livecat, sc);
2833             if (deadcat) {
2834                 obj_extract_self(deadcat);
2835                 obfree(deadcat, (struct obj *) 0), deadcat = 0;
2836             }
2837             box->owt = weight(box);
2838             box->spe = 0;
2839         }
2840     } else {
2841         box->spe = 0; /* now an ordinary box (with a cat corpse inside) */
2842         if (deadcat) {
2843             /* set_corpsenm() will start the rot timer that was removed
2844                when makemon() created SchroedingersBox; start it from
2845                now rather than from when this special corpse got created */
2846             deadcat->age = monstermoves;
2847             set_corpsenm(deadcat, PM_HOUSECAT);
2848             deadcat = oname(deadcat, sc);
2849         }
2850         if (givemsg)
2851 #if 0 /*JP:T*/
2852             pline_The("%s inside the box is dead!",
2853                       Hallucination ? rndmonnam((char *) 0) : "housecat");
2854 #else
2855             pline_The("\94 \82Ì\92\86\82Ì%s\82Í\8e\80\82ñ\82Å\82¢\82é\81I",
2856                       Hallucination ? rndmonnam((char *) 0) : "\94L");
2857 #endif
2858     }
2859     nhUse(deadcat);
2860     return;
2861 }
2862
2863 #undef Icebox
2864
2865 /* used by askchain() to check for magic bag explosion */
2866 boolean
2867 container_gone(fn)
2868 int FDECL((*fn), (OBJ_P));
2869 {
2870     /* result is only meaningful while use_container() is executing */
2871     return ((fn == in_container || fn == out_container)
2872             && !current_container);
2873 }
2874
2875 STATIC_OVL void
2876 explain_container_prompt(more_containers)
2877 boolean more_containers;
2878 {
2879     static const char *const explaintext[] = {
2880 #if 0 /*JP:T*/
2881         "Container actions:",
2882         "",
2883         " : -- Look: examine contents",
2884         " o -- Out: take things out",
2885         " i -- In: put things in",
2886         " b -- Both: first take things out, then put things in",
2887         " r -- Reversed: put things in, then take things out",
2888         " s -- Stash: put one item in", "",
2889         " n -- Next: loot next selected container",
2890         " q -- Quit: finished",
2891         " ? -- Help: display this text.",
2892         "", 0
2893 #else
2894         "\93ü\82ê\95¨\82Ö\82Ì\8ds\93®\81F",
2895         "",
2896         " : -- Look: \92\86\90g\82ð\92²\82×\82é",
2897         " o -- Out: \95¨\82ð\8fo\82·",
2898         " i -- In: \95¨\82ð\93ü\82ê\82é",
2899         " b -- Both: \82Ü\82¸\95¨\82ð\8fo\82µ\81A\82»\82ê\82©\82ç\95¨\82ð\93ü\82ê\82é",
2900         " r -- Reversed: \95¨\82ð\93ü\82ê\81A\82»\82ê\82©\82ç\95¨\82ð\8fo\82·",
2901         " s -- Stash: \95¨\82ð\88ê\82Â\93ü\82ê\82é",
2902         " n -- Next: \8e\9f\82É\91I\82ñ\82¾\93ü\82ê\95¨\82ð\92²\82×\82é",
2903         " q -- Quit: \89½\82à\82µ\82È\82¢",
2904         " ? -- Help: \82±\82ê\82ð\95\\8e¦\82·\82é",
2905         "", 0
2906 #endif
2907     };
2908     const char *const *txtpp;
2909     winid win;
2910
2911     /* "Do what with <container>? [:oibrsq or ?] (q)" */
2912     if ((win = create_nhwindow(NHW_TEXT)) != WIN_ERR) {
2913         for (txtpp = explaintext; *txtpp; ++txtpp) {
2914             if (!more_containers && !strncmp(*txtpp, " n ", 3))
2915                 continue;
2916             putstr(win, 0, *txtpp);
2917         }
2918         display_nhwindow(win, FALSE);
2919         destroy_nhwindow(win);
2920     }
2921 }
2922
2923 boolean
2924 u_handsy()
2925 {
2926     if (nohands(youmonst.data)) {
2927 #if 0 /*JP:T*/
2928         You("have no hands!"); /* not `body_part(HAND)' */
2929 #else
2930         pline("\82 \82È\82½\82É\82Í\8eè\82ª\82È\82¢\81I");  /* not `body_part(HAND)' */
2931 #endif
2932         return FALSE;
2933     } else if (!freehand()) {
2934 /*JP
2935         You("have no free %s.", body_part(HAND));
2936 */
2937         You("%s\82Ì\8e©\97R\82ª\8cø\82©\82È\82¢\81D", body_part(HAND));
2938         return FALSE;
2939     }
2940     return TRUE;
2941 }
2942
2943 static const char stashable[] = { ALLOW_COUNT, COIN_CLASS, ALL_CLASSES, 0 };
2944
2945 int
2946 use_container(objp, held, more_containers)
2947 struct obj **objp;
2948 int held;
2949 boolean more_containers; /* True iff #loot multiple and this isn't last one */
2950 {
2951     struct obj *otmp, *obj = *objp;
2952     boolean quantum_cat, cursed_mbag, loot_out, loot_in, loot_in_first,
2953         stash_one, inokay, outokay, outmaybe;
2954     char c, emptymsg[BUFSZ], qbuf[QBUFSZ], pbuf[QBUFSZ], xbuf[QBUFSZ];
2955     int used = 0;
2956     long loss;
2957
2958     abort_looting = FALSE;
2959     emptymsg[0] = '\0';
2960
2961     if (!u_handsy())
2962         return 0;
2963
2964     if (!obj->lknown) { /* do this in advance */
2965         obj->lknown = 1;
2966         if (held)
2967             update_inventory();
2968     }
2969     if (obj->olocked) {
2970 /*JP
2971         pline("%s locked.", Tobjnam(obj, "are"));
2972 */
2973         pline("%s\82Í\8c®\82ª\82©\82©\82Á\82Ä\82¢\82é\81D", xname(obj));
2974         if (held)
2975 /*JP
2976             You("must put it down to unlock.");
2977 */
2978             if (held) pline("\89º\82É\92u\82©\82È\82¢\82±\82Æ\82É\82Í\8c®\82ð\82Í\82¸\82¹\82È\82¢\81D");
2979         return 0;
2980     } else if (obj->otrapped) {
2981         if (held)
2982 /*JP
2983             You("open %s...", the(xname(obj)));
2984 */
2985             You("%s\82ð\8aJ\82¯\82½\81D\81D\81D", the(xname(obj)));
2986         (void) chest_trap(obj, HAND, FALSE);
2987         /* even if the trap fails, you've used up this turn */
2988         if (multi >= 0) { /* in case we didn't become paralyzed */
2989             nomul(-1);
2990 /*JP
2991             multi_reason = "opening a container";
2992 */
2993             multi_reason = "\94 \82ð\8aJ\82¯\82Ä\82¢\82é\8e\9e\82É";
2994             nomovemsg = "";
2995         }
2996         abort_looting = TRUE;
2997         return 1;
2998     }
2999
3000     current_container = obj; /* for use by in/out_container */
3001     /*
3002      * From here on out, all early returns go through 'containerdone:'.
3003      */
3004
3005     /* check for Schroedinger's Cat */
3006     quantum_cat = SchroedingersBox(current_container);
3007     if (quantum_cat) {
3008         observe_quantum_cat(current_container, TRUE, TRUE);
3009         used = 1;
3010     }
3011
3012     cursed_mbag = Is_mbag(current_container)
3013         && current_container->cursed
3014         && Has_contents(current_container);
3015     if (cursed_mbag
3016         && (loss = boh_loss(current_container, held)) != 0) {
3017         used = 1;
3018 /*JP
3019         You("owe %ld %s for lost merchandise.", loss, currency(loss));
3020 */
3021         You("\8e¸\82Á\82½\8f¤\95i\82Ì\82½\82ß\82É%ld%s\82Ì\95\89\8dÂ\82ð\95\89\82Á\82½\81D", loss, currency(loss));
3022         current_container->owt = weight(current_container);
3023     }
3024     inokay = (invent != 0
3025               && !(invent == current_container && !current_container->nobj));
3026     outokay = Has_contents(current_container);
3027     if (!outokay) /* preformat the empty-container message */
3028 #if 0 /*JP:T*/
3029         Sprintf(emptymsg, "%s is %sempty.", Ysimple_name2(current_container),
3030                 (quantum_cat || cursed_mbag) ? "now " : "");
3031 #else
3032         Sprintf(emptymsg, "%s\82Í%s\8bó\82Á\82Û\82¾\81D", Ysimple_name2(current_container),
3033                 (quantum_cat || cursed_mbag) ? "\8d¡\82Í" : "");
3034 #endif
3035
3036     /*
3037      * What-to-do prompt's list of possible actions:
3038      * always include the look-inside choice (':');
3039      * include the take-out choice ('o') if container
3040      * has anything in it or if player doesn't yet know
3041      * that it's empty (latter can change on subsequent
3042      * iterations if player picks ':' response);
3043      * include the put-in choices ('i','s') if hero
3044      * carries any inventory (including gold);
3045      * include do-both when 'o' is available, even if
3046      * inventory is empty--taking out could alter that;
3047      * include do-both-reversed when 'i' is available,
3048      * even if container is empty--for similar reason;
3049      * include the next container choice ('n') when
3050      * relevant, and make it the default;
3051      * always include the quit choice ('q'), and make
3052      * it the default if there's no next containter;
3053      * include the help choice (" or ?") if `cmdassist'
3054      * run-time option is set;
3055      * (Player can pick any of (o,i,b,r,n,s,?) even when
3056      * they're not listed among the available actions.)
3057      *
3058      * Do what with <the/your/Shk's container>? [:oibrs nq or ?] (q)
3059      * or
3060      * <The/Your/Shk's container> is empty.  Do what with it? [:irs nq or ?]
3061      */
3062     for (;;) { /* repeats iff '?' or ':' gets chosen */
3063         outmaybe = (outokay || !current_container->cknown);
3064         if (!outmaybe)
3065 #if 0 /*JP:T*/
3066             (void) safe_qbuf(qbuf, (char *) 0, " is empty.  Do what with it?",
3067                              current_container, Yname2, Ysimple_name2,
3068                              "This");
3069 #else
3070             (void) safe_qbuf(qbuf, (char *) 0, "\82Í\8bó\82¾\81D\82Ç\82¤\82·\82é\81H",
3071                              current_container, Yname2, Ysimple_name2,
3072                              "\82±\82ê");
3073 #endif
3074         else
3075 #if 0 /*JP:T*/
3076             (void) safe_qbuf(qbuf, "Do what with ", "?", current_container,
3077                              yname, ysimple_name, "it");
3078 #else
3079             (void) safe_qbuf(qbuf, (char *) 0, "\82ð\82Ç\82¤\82·\82é\81H", current_container,
3080                              yname, ysimple_name, "\82±\82ê");
3081 #endif
3082         /* ask player about what to do with this container */
3083         if (flags.menu_style == MENU_PARTIAL
3084             || flags.menu_style == MENU_FULL) {
3085             if (!inokay && !outmaybe) {
3086                 /* nothing to take out, nothing to put in;
3087                    trying to do both will yield proper feedback */
3088                 c = 'b';
3089             } else {
3090                 c = in_or_out_menu(qbuf, current_container, outmaybe, inokay,
3091                                    (boolean) (used != 0), more_containers);
3092             }
3093         } else { /* TRADITIONAL or COMBINATION */
3094             xbuf[0] = '\0'; /* list of extra acceptable responses */
3095             Strcpy(pbuf, ":");                   /* look inside */
3096             Strcat(outmaybe ? pbuf : xbuf, "o"); /* take out */
3097             Strcat(inokay ? pbuf : xbuf, "i");   /* put in */
3098             Strcat(outmaybe ? pbuf : xbuf, "b"); /* both */
3099             Strcat(inokay ? pbuf : xbuf, "rs");  /* reversed, stash */
3100             Strcat(pbuf, " ");                   /* separator */
3101             Strcat(more_containers ? pbuf : xbuf, "n"); /* next container */
3102             Strcat(pbuf, "q");                   /* quit */
3103             if (iflags.cmdassist)
3104                 /* this unintentionally allows user to answer with 'o' or
3105                    'r'; fortunately, those are already valid choices here */
3106 #if 0 /*JP:T*/
3107                 Strcat(pbuf, " or ?"); /* help */
3108 #else
3109                 Strcat(pbuf, "\82Ü\82½\82Í?"); /* help */
3110 #endif
3111             else
3112                 Strcat(xbuf, "?");
3113             if (*xbuf)
3114                 Strcat(strcat(pbuf, "\033"), xbuf);
3115             c = yn_function(qbuf, pbuf, more_containers ? 'n' : 'q');
3116         } /* PARTIAL|FULL vs other modes */
3117
3118         if (c == '?') {
3119             explain_container_prompt(more_containers);
3120         } else if (c == ':') { /* note: will set obj->cknown */
3121             if (!current_container->cknown)
3122                 used = 1; /* gaining info */
3123             container_contents(current_container, FALSE, FALSE, TRUE);
3124         } else
3125             break;
3126     } /* loop until something other than '?' or ':' is picked */
3127
3128     if (c == 'q')
3129         abort_looting = TRUE;
3130     if (c == 'n' || c == 'q') /* [not strictly needed; falling thru works] */
3131         goto containerdone;
3132     loot_out = (c == 'o' || c == 'b' || c == 'r');
3133     loot_in = (c == 'i' || c == 'b' || c == 'r');
3134     loot_in_first = (c == 'r'); /* both, reversed */
3135     stash_one = (c == 's');
3136
3137     /* out-only or out before in */
3138     if (loot_out && !loot_in_first) {
3139         if (!Has_contents(current_container)) {
3140             pline1(emptymsg); /* <whatever> is empty. */
3141             if (!current_container->cknown)
3142                 used = 1;
3143             current_container->cknown = 1;
3144         } else {
3145             add_valid_menu_class(0); /* reset */
3146             if (flags.menu_style == MENU_TRADITIONAL)
3147                 used |= traditional_loot(FALSE);
3148             else
3149                 used |= (menu_loot(0, FALSE) > 0);
3150             add_valid_menu_class(0);
3151         }
3152     }
3153
3154     if ((loot_in || stash_one)
3155         && (!invent || (invent == current_container && !invent->nobj))) {
3156 #if 0 /*JP:T*/
3157         You("don't have anything%s to %s.", invent ? " else" : "",
3158             stash_one ? "stash" : "put in");
3159 #else
3160         You("%s\93ü\82ê\82é\82à\82Ì\82ª\82È\82¢\81D", invent ? "\91¼\82É" : "");
3161 #endif
3162         loot_in = stash_one = FALSE;
3163     }
3164
3165     /*
3166      * Gone: being nice about only selecting food if we know we are
3167      * putting things in an ice chest.
3168      */
3169     if (loot_in) {
3170         add_valid_menu_class(0); /* reset */
3171         if (flags.menu_style == MENU_TRADITIONAL)
3172             used |= traditional_loot(TRUE);
3173         else
3174             used |= (menu_loot(0, TRUE) > 0);
3175         add_valid_menu_class(0);
3176     } else if (stash_one) {
3177         /* put one item into container */
3178         if ((otmp = getobj(stashable, "stash")) != 0) {
3179             if (in_container(otmp)) {
3180                 used = 1;
3181             } else {
3182                 /* couldn't put selected item into container for some
3183                    reason; might need to undo splitobj() */
3184                 (void) unsplitobj(otmp);
3185             }
3186         }
3187     }
3188     /* putting something in might have triggered magic bag explosion */
3189     if (!current_container)
3190         loot_out = FALSE;
3191
3192     /* out after in */
3193     if (loot_out && loot_in_first) {
3194         if (!Has_contents(current_container)) {
3195             pline1(emptymsg); /* <whatever> is empty. */
3196             if (!current_container->cknown)
3197                 used = 1;
3198             current_container->cknown = 1;
3199         } else {
3200             add_valid_menu_class(0); /* reset */
3201             if (flags.menu_style == MENU_TRADITIONAL)
3202                 used |= traditional_loot(FALSE);
3203             else
3204                 used |= (menu_loot(0, FALSE) > 0);
3205             add_valid_menu_class(0);
3206         }
3207     }
3208
3209  containerdone:
3210     if (used) {
3211         /* Not completely correct; if we put something in without knowing
3212            whatever was already inside, now we suddenly do.  That can't
3213            be helped unless we want to track things item by item and then
3214            deal with containers whose contents are "partly known". */
3215         if (current_container)
3216             current_container->cknown = 1;
3217         update_inventory();
3218     }
3219
3220     *objp = current_container; /* might have become null */
3221     if (current_container)
3222         current_container = 0; /* avoid hanging on to stale pointer */
3223     else
3224         abort_looting = TRUE;
3225     return used;
3226 }
3227
3228 /* loot current_container (take things out or put things in), by prompting */
3229 STATIC_OVL int
3230 traditional_loot(put_in)
3231 boolean put_in;
3232 {
3233     int FDECL((*actionfunc), (OBJ_P)), FDECL((*checkfunc), (OBJ_P));
3234     struct obj **objlist;
3235     char selection[MAXOCLASSES + 10]; /* +10: room for B,U,C,X plus slop */
3236     const char *action;
3237     boolean one_by_one, allflag;
3238     int used = 0, menu_on_request = 0;
3239
3240     if (put_in) {
3241 /*JP
3242         action = "put in";
3243 */
3244         action = "\93ü\82ê\82é";
3245         objlist = &invent;
3246         actionfunc = in_container;
3247         checkfunc = ck_bag;
3248     } else {
3249 /*JP
3250         action = "take out";
3251 */
3252         action = "\8eæ\82è\8fo\82·";
3253         objlist = &(current_container->cobj);
3254         actionfunc = out_container;
3255         checkfunc = (int FDECL((*), (OBJ_P))) 0;
3256     }
3257
3258     if (query_classes(selection, &one_by_one, &allflag, action, *objlist,
3259                       FALSE, &menu_on_request)) {
3260         if (askchain(objlist, (one_by_one ? (char *) 0 : selection), allflag,
3261                      actionfunc, checkfunc, 0, action))
3262             used = 1;
3263     } else if (menu_on_request < 0) {
3264         used = (menu_loot(menu_on_request, put_in) > 0);
3265     }
3266     return used;
3267 }
3268
3269 /* loot current_container (take things out or put things in), using a menu */
3270 STATIC_OVL int
3271 menu_loot(retry, put_in)
3272 int retry;
3273 boolean put_in;
3274 {
3275     int n, i, n_looted = 0;
3276     boolean all_categories = TRUE, loot_everything = FALSE;
3277     char buf[BUFSZ];
3278 /*JP
3279     const char *action = put_in ? "Put in" : "Take out";
3280 */
3281     const char *action = put_in ? "\93ü\82ê\82é" : "\8eæ\82è\8fo\82·";
3282     struct obj *otmp, *otmp2;
3283     menu_item *pick_list;
3284     int mflags, res;
3285     long count;
3286
3287     if (retry) {
3288         all_categories = (retry == -2);
3289     } else if (flags.menu_style == MENU_FULL) {
3290         all_categories = FALSE;
3291 /*JP
3292         Sprintf(buf, "%s what type of objects?", action);
3293 */
3294         Sprintf(buf, "\82Ç\82Ì\8eí\97Þ\82Ì\82à\82Ì\82ð%s\81H", action);
3295         mflags = (ALL_TYPES | UNPAID_TYPES | BUCX_TYPES | CHOOSE_ALL);
3296         n = query_category(buf, put_in ? invent : current_container->cobj,
3297                            mflags, &pick_list, PICK_ANY);
3298         if (!n)
3299             return 0;
3300         for (i = 0; i < n; i++) {
3301             if (pick_list[i].item.a_int == 'A')
3302                 loot_everything = TRUE;
3303             else if (pick_list[i].item.a_int == ALL_TYPES_SELECTED)
3304                 all_categories = TRUE;
3305             else
3306                 add_valid_menu_class(pick_list[i].item.a_int);
3307         }
3308         free((genericptr_t) pick_list);
3309     }
3310
3311     if (loot_everything) {
3312         if (!put_in) {
3313             current_container->cknown = 1;
3314             for (otmp = current_container->cobj; otmp; otmp = otmp2) {
3315                 otmp2 = otmp->nobj;
3316                 res = out_container(otmp);
3317                 if (res < 0)
3318                     break;
3319                 n_looted += res;
3320             }
3321         } else {
3322             for (otmp = invent; otmp && current_container; otmp = otmp2) {
3323                 otmp2 = otmp->nobj;
3324                 res = in_container(otmp);
3325                 if (res < 0)
3326                     break;
3327                 n_looted += res;
3328             }
3329         }
3330     } else {
3331         mflags = INVORDER_SORT;
3332         if (put_in && flags.invlet_constant)
3333             mflags |= USE_INVLET;
3334         if (!put_in)
3335             current_container->cknown = 1;
3336 /*JP
3337         Sprintf(buf, "%s what?", action);
3338 */
3339         Sprintf(buf, "\89½\82ð%s\81H", action);
3340         n = query_objlist(buf, put_in ? &invent : &(current_container->cobj),
3341                           mflags, &pick_list, PICK_ANY,
3342                           all_categories ? allow_all : allow_category);
3343         if (n) {
3344             n_looted = n;
3345             for (i = 0; i < n; i++) {
3346                 otmp = pick_list[i].item.a_obj;
3347                 count = pick_list[i].count;
3348                 if (count > 0 && count < otmp->quan) {
3349                     otmp = splitobj(otmp, count);
3350                     /* special split case also handled by askchain() */
3351                 }
3352                 res = put_in ? in_container(otmp) : out_container(otmp);
3353                 if (res < 0) {
3354                     if (!current_container) {
3355                         /* otmp caused current_container to explode;
3356                            both are now gone */
3357                         otmp = 0; /* and break loop */
3358                     } else if (otmp && otmp != pick_list[i].item.a_obj) {
3359                         /* split occurred, merge again */
3360                         (void) merged(&pick_list[i].item.a_obj, &otmp);
3361                     }
3362                     break;
3363                 }
3364             }
3365             free((genericptr_t) pick_list);
3366         }
3367     }
3368     return n_looted;
3369 }
3370
3371 STATIC_OVL char
3372 in_or_out_menu(prompt, obj, outokay, inokay, alreadyused, more_containers)
3373 const char *prompt;
3374 struct obj *obj;
3375 boolean outokay, inokay, alreadyused, more_containers;
3376 {
3377     /* underscore is not a choice; it's used to skip element [0] */
3378     static const char lootchars[] = "_:oibrsnq", abc_chars[] = "_:abcdenq";
3379     winid win;
3380     anything any;
3381     menu_item *pick_list;
3382     char buf[BUFSZ];
3383     int n;
3384     const char *menuselector = flags.lootabc ? abc_chars : lootchars;
3385
3386     any = zeroany;
3387     win = create_nhwindow(NHW_MENU);
3388     start_menu(win);
3389
3390     any.a_int = 1; /* ':' */
3391 /*JP
3392     Sprintf(buf, "Look inside %s", thesimpleoname(obj));
3393 */
3394     Sprintf(buf, "%s\82Ì\92\86\90g\82ð\8c©\82é", thesimpleoname(obj));
3395     add_menu(win, NO_GLYPH, &any, menuselector[any.a_int], 0, ATR_NONE, buf,
3396              MENU_UNSELECTED);
3397     if (outokay) {
3398         any.a_int = 2; /* 'o' */
3399 /*JP
3400         Sprintf(buf, "take %s out", something);
3401 */
3402         Strcpy(buf, "\89½\82©\82ð\8eæ\82è\8fo\82·");
3403         add_menu(win, NO_GLYPH, &any, menuselector[any.a_int], 0, ATR_NONE,
3404                  buf, MENU_UNSELECTED);
3405     }
3406     if (inokay) {
3407         any.a_int = 3; /* 'i' */
3408 /*JP
3409         Sprintf(buf, "put %s in", something);
3410 */
3411         Strcpy(buf, "\89½\82©\82ð\93ü\82ê\82é");
3412         add_menu(win, NO_GLYPH, &any, menuselector[any.a_int], 0, ATR_NONE,
3413                  buf, MENU_UNSELECTED);
3414     }
3415     if (outokay) {
3416         any.a_int = 4; /* 'b' */
3417 /*JP
3418         Sprintf(buf, "%stake out, then put in", inokay ? "both; " : "");
3419 */
3420         Sprintf(buf, "%s\82Ü\82¸\8eæ\82è\8fo\82·\81C\82»\82ê\82©\82ç\93ü\82ê\82é", inokay ? "\97¼\95û; " : "");
3421         add_menu(win, NO_GLYPH, &any, menuselector[any.a_int], 0, ATR_NONE,
3422                  buf, MENU_UNSELECTED);
3423     }
3424     if (inokay) {
3425         any.a_int = 5; /* 'r' */
3426 #if 0 /*JP:T*/
3427         Sprintf(buf, "%sput in, then take out",
3428                 outokay ? "both reversed; " : "");
3429 #else
3430         Sprintf(buf, "%s\82Ü\82¸\93ü\82ê\82é\81C\82»\82ê\82©\82ç\8eæ\82è\8fo\82·",
3431                 outokay ? "\97¼\95û\82ð\8bt\8f\87\82Å; " : "");
3432 #endif
3433         add_menu(win, NO_GLYPH, &any, menuselector[any.a_int], 0, ATR_NONE,
3434                  buf, MENU_UNSELECTED);
3435         any.a_int = 6; /* 's' */
3436 /*JP
3437         Sprintf(buf, "stash one item into %s", thesimpleoname(obj));
3438 */
3439         Sprintf(buf, "\82à\82Ì\82ð\88ê\82Â\82¾\82¯%s\82É\93ü\82ê\82é", thesimpleoname(obj));
3440         add_menu(win, NO_GLYPH, &any, menuselector[any.a_int], 0, ATR_NONE,
3441                  buf, MENU_UNSELECTED);
3442     }
3443     any.a_int = 0;
3444     add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE, "", MENU_UNSELECTED);
3445     if (more_containers) {
3446         any.a_int = 7; /* 'n' */
3447 #if 0 /*JP:T*/
3448         add_menu(win, NO_GLYPH, &any, menuselector[any.a_int], 0, ATR_NONE,
3449                  "loot next container", MENU_SELECTED);
3450 #else
3451         add_menu(win, NO_GLYPH, &any, menuselector[any.a_int], 0, ATR_NONE,
3452                  "\8e\9f\82Ì\94 \82ð\8aJ\82¯\82é", MENU_SELECTED);
3453 #endif
3454     }
3455     any.a_int = 8; /* 'q' */
3456 /*JP
3457     Strcpy(buf, alreadyused ? "done" : "do nothing");
3458 */
3459     Strcpy(buf, alreadyused ? "\8fI\82í\82é" : "\89½\82à\82µ\82È\82¢");
3460     add_menu(win, NO_GLYPH, &any, menuselector[any.a_int], 0, ATR_NONE, buf,
3461              more_containers ? MENU_UNSELECTED : MENU_SELECTED);
3462
3463     end_menu(win, prompt);
3464     n = select_menu(win, PICK_ONE, &pick_list);
3465     destroy_nhwindow(win);
3466     if (n > 0) {
3467         int k = pick_list[0].item.a_int;
3468
3469         if (n > 1 && k == (more_containers ? 7 : 8))
3470             k = pick_list[1].item.a_int;
3471         free((genericptr_t) pick_list);
3472         return lootchars[k]; /* :,o,i,b,r,s,n,q */
3473     }
3474     return (n == 0 && more_containers) ? 'n' : 'q'; /* next or quit */
3475 }
3476
3477 static const char tippables[] = { ALL_CLASSES, TOOL_CLASS, 0 };
3478
3479 /* #tip command -- empty container contents onto floor */
3480 int
3481 dotip()
3482 {
3483     struct obj *cobj, *nobj;
3484     coord cc;
3485     int boxes;
3486     char c, buf[BUFSZ], qbuf[BUFSZ];
3487     const char *spillage = 0;
3488
3489     /*
3490      * doesn't require free hands;
3491      * limbs are needed to tip floor containers
3492      */
3493
3494     /* at present, can only tip things at current spot, not adjacent ones */
3495     cc.x = u.ux, cc.y = u.uy;
3496
3497     /* check floor container(s) first; at most one will be accessed */
3498     if ((boxes = container_at(cc.x, cc.y, TRUE)) > 0) {
3499 #if 0 /*JP:T*/
3500         Sprintf(buf, "You can't tip %s while carrying so much.",
3501                 !flags.verbose ? "a container" : (boxes > 1) ? "one" : "it");
3502 #else
3503         Strcpy(buf, "\82½\82­\82³\82ñ\82à\82Ì\82ð\8e\9d\82¿\82·\82¬\82Ä\82¢\82é\82Ì\82Å\82Ð\82Á\82­\82è\82©\82¦\82¹\82È\82¢\81D");
3504 #endif
3505         if (!check_capacity(buf) && able_to_loot(cc.x, cc.y, FALSE)) {
3506             if (boxes > 1 && (flags.menu_style != MENU_TRADITIONAL
3507                               || iflags.menu_requested)) {
3508                 /* use menu to pick a container to tip */
3509                 int n, i;
3510                 winid win;
3511                 anything any;
3512                 menu_item *pick_list = (menu_item *) 0;
3513                 struct obj dummyobj, *otmp;
3514
3515                 any = zeroany;
3516                 win = create_nhwindow(NHW_MENU);
3517                 start_menu(win);
3518
3519                 for (cobj = level.objects[cc.x][cc.y], i = 0; cobj;
3520                      cobj = cobj->nexthere)
3521                     if (Is_container(cobj)) {
3522                         ++i;
3523                         any.a_obj = cobj;
3524                         add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE,
3525                                  doname(cobj), MENU_UNSELECTED);
3526                     }
3527                 if (invent) {
3528                     any = zeroany;
3529                     add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE,
3530                              "", MENU_UNSELECTED);
3531                     any.a_obj = &dummyobj;
3532                     /* use 'i' for inventory unless there are so many
3533                        containers that it's already being used */
3534                     i = (i <= 'i' - 'a' && !flags.lootabc) ? 'i' : 0;
3535 #if 0 /*JP:T*/
3536                     add_menu(win, NO_GLYPH, &any, i, 0, ATR_NONE,
3537                              "tip something being carried", MENU_SELECTED);
3538 #else
3539                     add_menu(win, NO_GLYPH, &any, i, 0, ATR_NONE,
3540                              "\93ü\82ê\95¨\82ð\82Ð\82Á\82­\82è\82©\82¦\82·", MENU_SELECTED);
3541 #endif
3542                 }
3543 /*JP
3544                 end_menu(win, "Tip which container?");
3545 */
3546                 end_menu(win, "\82Ç\82Ì\93ü\82ê\95¨\82ð\82Ð\82Á\82­\82è\82©\82¦\82·\81H");
3547                 n = select_menu(win, PICK_ONE, &pick_list);
3548                 destroy_nhwindow(win);
3549                 /*
3550                  * Deal with quirk of preselected item in pick-one menu:
3551                  * n ==  0 => picked preselected entry, toggling it off;
3552                  * n ==  1 => accepted preselected choice via SPACE or RETURN;
3553                  * n ==  2 => picked something other than preselected entry;
3554                  * n == -1 => cancelled via ESC;
3555                  */
3556                 otmp = (n <= 0) ? (struct obj *) 0 : pick_list[0].item.a_obj;
3557                 if (n > 1 && otmp == &dummyobj)
3558                     otmp = pick_list[1].item.a_obj;
3559                 if (pick_list)
3560                     free((genericptr_t) pick_list);
3561                 if (otmp && otmp != &dummyobj) {
3562                     tipcontainer(otmp);
3563                     return 1;
3564                 }
3565                 if (n == -1)
3566                     return 0;
3567                 /* else pick-from-invent below */
3568             } else {
3569                 for (cobj = level.objects[cc.x][cc.y]; cobj; cobj = nobj) {
3570                     nobj = cobj->nexthere;
3571                     if (!Is_container(cobj))
3572                         continue;
3573 #if 0 /*JP:T*/
3574                     c = ynq(safe_qbuf(qbuf, "There is ", " here, tip it?",
3575                                       cobj,
3576                                       doname, ansimpleoname, "container"));
3577 #else
3578                     c = ynq(safe_qbuf(qbuf, "\82±\82±\82É\82Í", " \82ª\82 \82é\81C\82Ð\82Á\82­\82è\95Ô\82·?",
3579                                       cobj,
3580                                       doname, ansimpleoname, "\93ü\82ê\95¨"));
3581 #endif
3582                     if (c == 'q')
3583                         return 0;
3584                     if (c == 'n')
3585                         continue;
3586                     tipcontainer(cobj);
3587                     /* can only tip one container at a time */
3588                     return 1;
3589                 }
3590             }
3591         }
3592     }
3593
3594     /* either no floor container(s) or couldn't tip one or didn't tip any */
3595     cobj = getobj(tippables, "tip");
3596     if (!cobj)
3597         return 0;
3598
3599     /* normal case */
3600     if (Is_container(cobj) || cobj->otyp == HORN_OF_PLENTY) {
3601         tipcontainer(cobj);
3602         return 1;
3603     }
3604     /* assorted other cases */
3605     if (Is_candle(cobj) && cobj->lamplit) {
3606         /* note "wax" even for tallow candles to avoid giving away info */
3607 /*JP
3608         spillage = "wax";
3609 */
3610         spillage = "\82ë\82¤";
3611     } else if ((cobj->otyp == POT_OIL && cobj->lamplit)
3612                || (cobj->otyp == OIL_LAMP && cobj->age != 0L)
3613                || (cobj->otyp == MAGIC_LAMP && cobj->spe != 0)) {
3614 /*JP
3615         spillage = "oil";
3616 */
3617         spillage = "\96û";
3618         /* todo: reduce potion's remaining burn timer or oil lamp's fuel */
3619     } else if (cobj->otyp == CAN_OF_GREASE && cobj->spe > 0) {
3620         /* charged consumed below */
3621 /*JP
3622         spillage = "grease";
3623 */
3624         spillage = "\8e\89";
3625     } else if (cobj->otyp == FOOD_RATION || cobj->otyp == CRAM_RATION
3626                || cobj->otyp == LEMBAS_WAFER) {
3627 /*JP
3628         spillage = "crumbs";
3629 */
3630         spillage = "\83p\83\93\82­\82¸";
3631     } else if (cobj->oclass == VENOM_CLASS) {
3632 /*JP
3633         spillage = "venom";
3634 */
3635         spillage = "\93Å\89t";
3636     }
3637     if (spillage) {
3638         buf[0] = '\0';
3639         if (is_pool(u.ux, u.uy))
3640 /*JP
3641             Sprintf(buf, " and gradually %s", vtense(spillage, "dissipate"));
3642 */
3643             Strcpy(buf, "\82»\82µ\82Ä\8f\99\81X\82É\8eU\82Á\82Ä\82¢\82Á\82½\81D");
3644         else if (is_lava(u.ux, u.uy))
3645 #if 0 /*JP:T*/
3646             Sprintf(buf, " and immediately %s away",
3647                     vtense(spillage, "burn"));
3648 #else
3649             Strcpy(buf, "\82»\82µ\82Ä\82·\82®\82É\94R\82¦\82Â\82«\82½\81D");
3650 #endif
3651 #if 0 /*JP:T*/
3652         pline("Some %s %s onto the %s%s.", spillage,
3653               vtense(spillage, "spill"), surface(u.ux, u.uy), buf);
3654 #else
3655         pline("%s\82ª%s\82Ì\8fã\82É\94ò\82Ñ\8eU\82Á\82½\81D%s", spillage,
3656               surface(u.ux, u.uy), buf);
3657 #endif
3658         /* shop usage message comes after the spill message */
3659         if (cobj->otyp == CAN_OF_GREASE && cobj->spe > 0) {
3660             consume_obj_charge(cobj, TRUE);
3661         }
3662         /* something [useless] happened */
3663         return 1;
3664     }
3665     /* anything not covered yet */
3666     if (cobj->oclass == POTION_CLASS) /* can't pour potions... */
3667 /*JP
3668         pline_The("%s %s securely sealed.", xname(cobj), otense(cobj, "are"));
3669 */
3670         pline_The("%s\82Í\82µ\82Á\82©\82è\82Æ\90ð\82ª\82³\82ê\82Ä\82¢\82é\81D", xname(cobj));
3671     else if (cobj->otyp == STATUE)
3672 /*JP
3673         pline("Nothing interesting happens.");
3674 */
3675         pline("\96Ê\94\92\82¢\82±\82Æ\82Í\89½\82à\8bN\82«\82È\82©\82Á\82½\81D");
3676     else
3677         pline1(nothing_happens);
3678     return 0;
3679 }
3680
3681 STATIC_OVL void
3682 tipcontainer(box)
3683 struct obj *box; /* or bag */
3684 {
3685     xchar ox = u.ux, oy = u.uy; /* #tip only works at hero's location */
3686     boolean empty_it = FALSE, maybeshopgoods;
3687
3688     /* box is either held or on floor at hero's spot; no need to check for
3689        nesting; when held, we need to update its location to match hero's;
3690        for floor, the coordinate updating is redundant */
3691     if (get_obj_location(box, &ox, &oy, 0))
3692         box->ox = ox, box->oy = oy;
3693
3694     /* Shop handling:  can't rely on the container's own unpaid
3695        or no_charge status because contents might differ with it.
3696        A carried container's contents will be flagged as unpaid
3697        or not, as appropriate, and need no special handling here.
3698        Items owned by the hero get sold to the shop without
3699        confirmation as with other uncontrolled drops.  A floor
3700        container's contents will be marked no_charge if owned by
3701        hero, otherwise they're owned by the shop.  By passing
3702        the contents through shop billing, they end up getting
3703        treated the same as in the carried case.   We do so one
3704        item at a time instead of doing whole container at once
3705        to reduce the chance of exhausting shk's billing capacity. */
3706     maybeshopgoods = !carried(box) && costly_spot(box->ox, box->oy);
3707
3708     /* caveat: this assumes that cknown, lknown, olocked, and otrapped
3709        fields haven't been overloaded to mean something special for the
3710        non-standard "container" horn of plenty */
3711     if (!box->lknown) {
3712         box->lknown = 1;
3713         if (carried(box))
3714             update_inventory(); /* jumping the gun slightly; hope that's ok */
3715     }
3716     if (box->olocked) {
3717 /*JP
3718         pline("It's locked.");
3719 */
3720         pline("\8c®\82ª\8a|\82©\82Á\82Ä\82¢\82é\81D");
3721     } else if (box->otrapped) {
3722         /* we're not reaching inside but we're still handling it... */
3723         (void) chest_trap(box, HAND, FALSE);
3724         /* even if the trap fails, you've used up this turn */
3725         if (multi >= 0) { /* in case we didn't become paralyzed */
3726             nomul(-1);
3727 /*JP
3728             multi_reason = "tipping a container";
3729 */
3730             multi_reason = "\94 \82ð\82Ð\82Á\82­\82è\95Ô\82µ\82Ä\82¢\82é\8e\9e\82É";
3731             nomovemsg = "";
3732         }
3733     } else if (box->otyp == BAG_OF_TRICKS || box->otyp == HORN_OF_PLENTY) {
3734         boolean bag = box->otyp == BAG_OF_TRICKS;
3735         int old_spe = box->spe, seen = 0;
3736
3737         if (maybeshopgoods && !box->no_charge)
3738             addtobill(box, FALSE, FALSE, TRUE);
3739         /* apply this bag/horn until empty or monster/object creation fails
3740            (if the latter occurs, force the former...) */
3741         do {
3742             if (!(bag ? bagotricks(box, TRUE, &seen)
3743                       : hornoplenty(box, TRUE)))
3744                 break;
3745         } while (box->spe > 0);
3746
3747         if (box->spe < old_spe) {
3748             if (bag)
3749 #if 0 /*JP:T*/
3750                 pline((seen == 0) ? "Nothing seems to happen."
3751                                   : (seen == 1) ? "A monster appears."
3752                                                 : "Monsters appear!");
3753 #else
3754                 pline((seen == 0) ? "\89½\82à\8bN\82«\82È\82©\82Á\82½\82æ\82¤\82¾\81D"
3755                                   : (seen == 1) ? "\89ö\95¨\82ª\8c»\82ê\82½\81D"
3756                                                 : "\89ö\95¨\82ª\8c»\82ê\82½\81I");
3757 #endif
3758             /* check_unpaid wants to see a non-zero charge count */
3759             box->spe = old_spe;
3760             check_unpaid_usage(box, TRUE);
3761             box->spe = 0; /* empty */
3762             box->cknown = 1;
3763         }
3764         if (maybeshopgoods && !box->no_charge)
3765             subfrombill(box, shop_keeper(*in_rooms(ox, oy, SHOPBASE)));
3766     } else if (SchroedingersBox(box)) {
3767         char yourbuf[BUFSZ];
3768
3769         observe_quantum_cat(box, TRUE, TRUE);
3770         if (!Has_contents(box)) /* evidently a live cat came out */
3771             /* container type of "large box" is inferred */
3772 /*JP
3773             pline("%sbox is now empty.", Shk_Your(yourbuf, box));
3774 */
3775             pline("%s\94 \82Í\8bó\82É\82È\82Á\82½\81D", Shk_Your(yourbuf, box));
3776         else /* holds cat corpse */
3777             empty_it = TRUE;
3778         box->cknown = 1;
3779     } else if (!Has_contents(box)) {
3780         box->cknown = 1;
3781 /*JP
3782         pline("It's empty.");
3783 */
3784         pline("\82±\82ê\82Í\8bó\82¾\81D");
3785     } else {
3786         empty_it = TRUE;
3787     }
3788
3789     if (empty_it) {
3790         struct obj *otmp, *nobj;
3791         boolean terse, highdrop = !can_reach_floor(TRUE),
3792                 altarizing = IS_ALTAR(levl[ox][oy].typ),
3793                 cursed_mbag = (Is_mbag(box) && box->cursed);
3794         int held = carried(box);
3795         long loss = 0L;
3796
3797         if (u.uswallow)
3798             highdrop = altarizing = FALSE;
3799         terse = !(highdrop || altarizing || costly_spot(box->ox, box->oy));
3800         box->cknown = 1;
3801         /* Terse formatting is
3802          * "Objects spill out: obj1, obj2, obj3, ..., objN."
3803          * If any other messages intervene between objects, we revert to
3804          * "ObjK drops to the floor.", "ObjL drops to the floor.", &c.
3805          */
3806 #if 0 /*JP:T*/
3807         pline("%s out%c",
3808               box->cobj->nobj ? "Objects spill" : "An object spills",
3809               terse ? ':' : '.');
3810 #else
3811         pline("\92\86\90g\82ª\8fo\82Ä\82«\82½%s",
3812               !(highdrop || altarizing) ? "\81F" : "\81D");
3813 #endif
3814         for (otmp = box->cobj; otmp; otmp = nobj) {
3815             nobj = otmp->nobj;
3816             obj_extract_self(otmp);
3817             otmp->ox = box->ox, otmp->oy = box->oy;
3818
3819             if (box->otyp == ICE_BOX) {
3820                 removed_from_icebox(otmp); /* resume rotting for corpse */
3821             } else if (cursed_mbag && !rn2(13)) {
3822                 loss += mbag_item_gone(held, otmp);
3823                 /* abbreviated drop format is no longer appropriate */
3824                 terse = FALSE;
3825                 continue;
3826             }
3827
3828             if (maybeshopgoods) {
3829                 addtobill(otmp, FALSE, FALSE, TRUE);
3830                 iflags.suppress_price++; /* doname formatting */
3831             }
3832
3833             if (highdrop) {
3834                 /* might break or fall down stairs; handles altars itself */
3835                 hitfloor(otmp, TRUE);
3836             } else {
3837                 if (altarizing) {
3838                     doaltarobj(otmp);
3839                 } else if (!terse) {
3840 #if 0 /*JP:T*/
3841                     pline("%s %s to the %s.", Doname2(otmp),
3842                           otense(otmp, "drop"), surface(ox, oy));
3843 #else
3844                     pline("%s\82Í%s\82Ì\8fã\82É\97\8e\82¿\82½\81D", Doname2(otmp),
3845                           surface(ox, oy));
3846 #endif
3847                 } else {
3848 /*JP
3849                     pline("%s%c", doname(otmp), nobj ? ',' : '.');
3850 */
3851                     pline("%s%s", doname(otmp), nobj ? "\81C" : "\81D");
3852                     iflags.last_msg = PLNMSG_OBJNAM_ONLY;
3853                 }
3854                 dropy(otmp);
3855                 if (iflags.last_msg != PLNMSG_OBJNAM_ONLY)
3856                     terse = FALSE; /* terse formatting has been interrupted */
3857             }
3858             if (maybeshopgoods)
3859                 iflags.suppress_price--; /* reset */
3860         }
3861         if (loss) /* magic bag lost some shop goods */
3862 /*JP
3863             You("owe %ld %s for lost merchandise.", loss, currency(loss));
3864 */
3865             You("\8e¸\82Á\82½\82à\82Ì\82É\91Î\82µ\82Ä%ld%s\82Ì\95\89\8dÂ\82ð\95\89\82Á\82½\81D", loss, currency(loss));
3866         box->owt = weight(box); /* mbag_item_gone() doesn't update this */
3867         if (held)
3868             (void) encumber_msg();
3869     }
3870     if (carried(box)) /* box is now empty with cknown set */
3871         update_inventory();
3872 }
3873
3874 /*pickup.c*/