OSDN Git Service

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