OSDN Git Service

Daretoku.
[hengband/hengband.git] / src / cmd6.c
1 /* File: cmd6.c */
2
3 /*
4  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
5  *
6  * This software may be copied and distributed for educational, research,
7  * and not for profit purposes provided that this copyright and statement
8  * are included in all such copies.  Other copyrights may also apply.
9  */
10
11 /* Purpose: Object commands */
12
13 #include "angband.h"
14
15
16 /*
17  * This file includes code for eating food, drinking potions,
18  * reading scrolls, aiming wands, using staffs, zapping rods,
19  * and activating artifacts.
20  *
21  * In all cases, if the player becomes "aware" of the item's use
22  * by testing it, mark it as "aware" and reward some experience
23  * based on the object's level, always rounding up.  If the player
24  * remains "unaware", mark that object "kind" as "tried".
25  *
26  * This code now correctly handles the unstacking of wands, staffs,
27  * and rods.  Note the overly paranoid warning about potential pack
28  * overflow, which allows the player to use and drop a stacked item.
29  *
30  * In all "unstacking" scenarios, the "used" object is "carried" as if
31  * the player had just picked it up.  In particular, this means that if
32  * the use of an item induces pack overflow, that item will be dropped.
33  *
34  * For simplicity, these routines induce a full "pack reorganization"
35  * which not only combines similar items, but also reorganizes various
36  * items to obey the current "sorting" method.  This may require about
37  * 400 item comparisons, but only occasionally.
38  *
39  * There may be a BIG problem with any "effect" that can cause "changes"
40  * to the inventory.  For example, a "scroll of recharging" can cause
41  * a wand/staff to "disappear", moving the inventory up.  Luckily, the
42  * scrolls all appear BEFORE the staffs/wands, so this is not a problem.
43  * But, for example, a "staff of recharging" could cause MAJOR problems.
44  * In such a case, it will be best to either (1) "postpone" the effect
45  * until the end of the function, or (2) "change" the effect, say, into
46  * giving a staff "negative" charges, or "turning a staff into a stick".
47  * It seems as though a "rod of recharging" might in fact cause problems.
48  * The basic problem is that the act of recharging (and destroying) an
49  * item causes the inducer of that action to "move", causing "o_ptr" to
50  * no longer point at the correct item, with horrifying results.
51  *
52  * Note that food/potions/scrolls no longer use bit-flags for effects,
53  * but instead use the "sval" (which is also used to sort the objects).
54  */
55
56
57 static void do_cmd_eat_food_aux(int item)
58 {
59         int ident, lev;
60         object_type *o_ptr;
61
62         if (music_singing_any()) stop_singing();
63         if (hex_spelling_any()) stop_hex_spell_all();
64
65         /* Get the item (in the pack) */
66         if (item >= 0)
67         {
68                 o_ptr = &inventory[item];
69         }
70
71         /* Get the item (on the floor) */
72         else
73         {
74                 o_ptr = &o_list[0 - item];
75         }
76
77         /* Sound */
78         sound(SOUND_EAT);
79
80         /* Take a turn */
81         energy_use = 100;
82
83         /* Identity not known yet */
84         ident = FALSE;
85
86         /* Object level */
87         lev = k_info[o_ptr->k_idx].level;
88
89         if (o_ptr->tval == TV_FOOD)
90         {
91                 /* Analyze the food */
92                 switch (o_ptr->sval)
93                 {
94                         case SV_FOOD_POISON:
95                         {
96                                 if (!(p_ptr->resist_pois || IS_OPPOSE_POIS()))
97                                 {
98                                         if (set_poisoned(p_ptr->poisoned + randint0(10) + 10))
99                                         {
100                                                 ident = TRUE;
101                                         }
102                                 }
103                                 break;
104                         }
105
106                         case SV_FOOD_BLINDNESS:
107                         {
108                                 if (!p_ptr->resist_blind)
109                                 {
110                                         if (set_blind(p_ptr->blind + randint0(200) + 200))
111                                         {
112                                                 ident = TRUE;
113                                         }
114                                 }
115                                 break;
116                         }
117
118                         case SV_FOOD_PARANOIA:
119                         {
120                                 if (!p_ptr->resist_fear)
121                                 {
122                                         if (set_afraid(p_ptr->afraid + randint0(10) + 10))
123                                         {
124                                                 ident = TRUE;
125                                         }
126                                 }
127                                 break;
128                         }
129
130                         case SV_FOOD_CONFUSION:
131                         {
132                                 if (!p_ptr->resist_conf)
133                                 {
134                                         if (set_confused(p_ptr->confused + randint0(10) + 10))
135                                         {
136                                                 ident = TRUE;
137                                         }
138                                 }
139                                 break;
140                         }
141
142                         case SV_FOOD_HALLUCINATION:
143                         {
144                                 if (!p_ptr->resist_chaos)
145                                 {
146                                         if (set_image(p_ptr->image + randint0(250) + 250))
147                                         {
148                                                 ident = TRUE;
149                                         }
150                                 }
151                                 break;
152                         }
153
154                         case SV_FOOD_PARALYSIS:
155                         {
156                                 if (!p_ptr->free_act)
157                                 {
158                                         if (set_paralyzed(p_ptr->paralyzed + randint0(10) + 10))
159                                         {
160                                                 ident = TRUE;
161                                         }
162                                 }
163                                 break;
164                         }
165
166                         case SV_FOOD_WEAKNESS:
167                         {
168 #ifdef JP
169                                 take_hit(DAMAGE_NOESCAPE, damroll(6, 6), "ÆÇÆþ¤ê¿©ÎÁ", -1);
170 #else
171                                 take_hit(DAMAGE_NOESCAPE, damroll(6, 6), "poisonous food", -1);
172 #endif
173
174                                 (void)do_dec_stat(A_STR);
175                                 ident = TRUE;
176                                 break;
177                         }
178
179                         case SV_FOOD_SICKNESS:
180                         {
181 #ifdef JP
182                                 take_hit(DAMAGE_NOESCAPE, damroll(6, 6), "ÆÇÆþ¤ê¿©ÎÁ", -1);
183 #else
184                                 take_hit(DAMAGE_NOESCAPE, damroll(6, 6), "poisonous food", -1);
185 #endif
186
187                                 (void)do_dec_stat(A_CON);
188                                 ident = TRUE;
189                                 break;
190                         }
191
192                         case SV_FOOD_STUPIDITY:
193                         {
194 #ifdef JP
195                                 take_hit(DAMAGE_NOESCAPE, damroll(8, 8), "ÆÇÆþ¤ê¿©ÎÁ", -1);
196 #else
197                                 take_hit(DAMAGE_NOESCAPE, damroll(8, 8), "poisonous food", -1);
198 #endif
199
200                                 (void)do_dec_stat(A_INT);
201                                 ident = TRUE;
202                                 break;
203                         }
204
205                         case SV_FOOD_NAIVETY:
206                         {
207 #ifdef JP
208                                 take_hit(DAMAGE_NOESCAPE, damroll(8, 8), "ÆÇÆþ¤ê¿©ÎÁ", -1);
209 #else
210                                 take_hit(DAMAGE_NOESCAPE, damroll(8, 8), "poisonous food", -1);
211 #endif
212
213                                 (void)do_dec_stat(A_WIS);
214                                 ident = TRUE;
215                                 break;
216                         }
217
218                         case SV_FOOD_UNHEALTH:
219                         {
220 #ifdef JP
221                                 take_hit(DAMAGE_NOESCAPE, damroll(10, 10), "ÆÇÆþ¤ê¿©ÎÁ", -1);
222 #else
223                                 take_hit(DAMAGE_NOESCAPE, damroll(10, 10), "poisonous food", -1);
224 #endif
225
226                                 (void)do_dec_stat(A_CON);
227                                 ident = TRUE;
228                                 break;
229                         }
230
231                         case SV_FOOD_DISEASE:
232                         {
233 #ifdef JP
234                                 take_hit(DAMAGE_NOESCAPE, damroll(10, 10), "ÆÇÆþ¤ê¿©ÎÁ", -1);
235 #else
236                                 take_hit(DAMAGE_NOESCAPE, damroll(10, 10), "poisonous food", -1);
237 #endif
238
239                                 (void)do_dec_stat(A_STR);
240                                 ident = TRUE;
241                                 break;
242                         }
243
244                         case SV_FOOD_CURE_POISON:
245                         {
246                                 if (set_poisoned(0)) ident = TRUE;
247                                 break;
248                         }
249
250                         case SV_FOOD_CURE_BLINDNESS:
251                         {
252                                 if (set_blind(0)) ident = TRUE;
253                                 break;
254                         }
255
256                         case SV_FOOD_CURE_PARANOIA:
257                         {
258                                 if (set_afraid(0)) ident = TRUE;
259                                 break;
260                         }
261
262                         case SV_FOOD_CURE_CONFUSION:
263                         {
264                                 if (set_confused(0)) ident = TRUE;
265                                 break;
266                         }
267
268                         case SV_FOOD_CURE_SERIOUS:
269                         {
270                                 if (hp_player(damroll(4, 8))) ident = TRUE;
271                                 break;
272                         }
273
274                         case SV_FOOD_RESTORE_STR:
275                         {
276                                 if (do_res_stat(A_STR)) ident = TRUE;
277                                 break;
278                         }
279
280                         case SV_FOOD_RESTORE_CON:
281                         {
282                                 if (do_res_stat(A_CON)) ident = TRUE;
283                                 break;
284                         }
285
286                         case SV_FOOD_RESTORING:
287                         {
288                                 if (do_res_stat(A_STR)) ident = TRUE;
289                                 if (do_res_stat(A_INT)) ident = TRUE;
290                                 if (do_res_stat(A_WIS)) ident = TRUE;
291                                 if (do_res_stat(A_DEX)) ident = TRUE;
292                                 if (do_res_stat(A_CON)) ident = TRUE;
293                                 if (do_res_stat(A_CHR)) ident = TRUE;
294                                 break;
295                         }
296
297
298 #ifdef JP
299                         /* ¤½¤ì¤¾¤ì¤Î¿©¤Ùʪ¤Î´¶ÁÛ¤ò¥ª¥ê¥¸¥Ê¥ë¤è¤êºÙ¤«¤¯É½¸½ */
300                         case SV_FOOD_BISCUIT:
301                         {
302                                 msg_print("´Å¤¯¤Æ¥µ¥¯¥µ¥¯¤·¤Æ¤È¤Æ¤â¤ª¤¤¤·¤¤¡£");
303                                 ident = TRUE;
304                                 break;
305                         }
306
307                         case SV_FOOD_JERKY:
308                         {
309                                 msg_print("»õ¤´¤¿¤¨¤¬¤¢¤Ã¤Æ¤ª¤¤¤·¤¤¡£");
310                                 ident = TRUE;
311                                 break;
312                         }
313
314                         case SV_FOOD_SLIME_MOLD:
315                         {
316                                 msg_print("¤³¤ì¤Ï¤Ê¤ó¤È¤â·ÁÍƤ·¤¬¤¿¤¤Ì£¤À¡£");
317                                 ident = TRUE;
318                                 break;
319                         }
320
321                         case SV_FOOD_RATION:
322                         {
323                                 msg_print("¤³¤ì¤Ï¤ª¤¤¤·¤¤¡£");
324                                 ident = TRUE;
325                                 break;
326                         }
327 #else
328                         case SV_FOOD_RATION:
329                         case SV_FOOD_BISCUIT:
330                         case SV_FOOD_JERKY:
331                         case SV_FOOD_SLIME_MOLD:
332                         {
333                                 msg_print("That tastes good.");
334                                 ident = TRUE;
335                                 break;
336                         }
337 #endif
338
339
340                         case SV_FOOD_WAYBREAD:
341                         {
342 #ifdef JP
343                                 msg_print("¤³¤ì¤Ï¤Ò¤¸¤ç¤¦¤ËÈþÌ£¤À¡£");
344 #else
345                                 msg_print("That tastes good.");
346 #endif
347
348                                 (void)set_poisoned(0);
349                                 (void)hp_player(damroll(4, 8));
350                                 ident = TRUE;
351                                 break;
352                         }
353
354 #ifdef JP
355                         case SV_FOOD_PINT_OF_ALE:
356                         {
357                                 msg_print("¤Î¤É¤´¤·Á֤䤫¤À¡£");
358                                 ident = TRUE;
359                                 break;
360                         }
361
362                         case SV_FOOD_PINT_OF_WINE:
363                         {
364                                 msg_print("That tastes good.");
365                                 ident = TRUE;
366                                 break;
367                         }
368 #else
369                         case SV_FOOD_PINT_OF_ALE:
370                         case SV_FOOD_PINT_OF_WINE:
371                         {
372                                 msg_print("That tastes good.");
373                                 ident = TRUE;
374                                 break;
375                         }
376 #endif
377
378                 }
379         }
380
381         /* Combine / Reorder the pack (later) */
382         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
383
384         if (!(object_is_aware(o_ptr)))
385         {
386                 chg_virtue(V_KNOWLEDGE, -1);
387                 chg_virtue(V_PATIENCE, -1);
388                 chg_virtue(V_CHANCE, 1);
389         }
390
391         /* We have tried it */
392         if (o_ptr->tval == TV_FOOD) object_tried(o_ptr);
393
394         /* The player is now aware of the object */
395         if (ident && !object_is_aware(o_ptr))
396         {
397                 object_aware(o_ptr);
398                 gain_exp((lev + (p_ptr->lev >> 1)) / p_ptr->lev);
399         }
400
401         /* Window stuff */
402         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
403
404
405         /* Food can feed the player */
406         if (prace_is_(RACE_VAMPIRE) || (p_ptr->mimic_form == MIMIC_VAMPIRE))
407         {
408                 /* Reduced nutritional benefit */
409                 (void)set_food(p_ptr->food + (o_ptr->pval / 10));
410 #ifdef JP
411 msg_print("¤¢¤Ê¤¿¤Î¤è¤¦¤Ê¼Ô¤Ë¤È¤Ã¤Æ¿©ÎȤʤɶϤ«¤Ê±ÉÍܤˤ·¤«¤Ê¤é¤Ê¤¤¡£");
412 #else
413                 msg_print("Mere victuals hold scant sustenance for a being such as yourself.");
414 #endif
415
416                 if (p_ptr->food < PY_FOOD_ALERT)   /* Hungry */
417 #ifdef JP
418 msg_print("¤¢¤Ê¤¿¤Îµ²¤¨¤Ï¿·Á¯¤Ê·ì¤Ë¤è¤Ã¤Æ¤Î¤ßËþ¤¿¤µ¤ì¤ë¡ª");
419 #else
420                         msg_print("Your hunger can only be satisfied with fresh blood!");
421 #endif
422
423         }
424         else if ((prace_is_(RACE_SKELETON) ||
425                   prace_is_(RACE_GOLEM) ||
426                   prace_is_(RACE_ZOMBIE) ||
427                   prace_is_(RACE_SPECTRE)) &&
428                  (o_ptr->tval == TV_STAFF || o_ptr->tval == TV_WAND))
429         {
430                 cptr staff;
431
432                 if (o_ptr->tval == TV_STAFF &&
433                     (item < 0) && (o_ptr->number > 1))
434                 {
435 #ifdef JP
436                         msg_print("¤Þ¤º¤Ï¾ó¤ò½¦¤ï¤Ê¤±¤ì¤Ð¡£");
437 #else
438                         msg_print("You must first pick up the staffs.");
439 #endif
440                         return;
441                 }
442
443 #ifdef JP
444                 staff = (o_ptr->tval == TV_STAFF) ? "¾ó" : "ËâË¡ËÀ";
445 #else
446                 staff = (o_ptr->tval == TV_STAFF) ? "staff" : "wand";
447 #endif
448
449                 /* "Eat" charges */
450                 if (o_ptr->pval == 0)
451                 {
452 #ifdef JP
453                         msg_format("¤³¤Î%s¤Ë¤Ï¤â¤¦ËâÎϤ¬»Ä¤Ã¤Æ¤¤¤Ê¤¤¡£", staff);
454 #else
455                         msg_format("The %s has no charges left.", staff);
456 #endif
457
458                         o_ptr->ident |= (IDENT_EMPTY);
459
460                         /* Combine / Reorder the pack (later) */
461                         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
462                         p_ptr->window |= (PW_INVEN);
463
464                         return;
465                 }
466
467 #ifdef JP
468                 msg_format("¤¢¤Ê¤¿¤Ï%s¤ÎËâÎϤò¥¨¥Í¥ë¥®¡¼¸»¤È¤·¤ÆµÛ¼ý¤·¤¿¡£", staff);
469 #else
470                 msg_format("You absorb mana of the %s as your energy.", staff);
471 #endif
472
473                 /* Use a single charge */
474                 o_ptr->pval--;
475
476                 /* Eat a charge */
477                 set_food(p_ptr->food + 5000);
478
479                 /* XXX Hack -- unstack if necessary */
480                 if (o_ptr->tval == TV_STAFF &&
481                     (item >= 0) && (o_ptr->number > 1))
482                 {
483                         object_type forge;
484                         object_type *q_ptr;
485
486                         /* Get local object */
487                         q_ptr = &forge;
488
489                         /* Obtain a local object */
490                         object_copy(q_ptr, o_ptr);
491
492                         /* Modify quantity */
493                         q_ptr->number = 1;
494
495                         /* Restore the charges */
496                         o_ptr->pval++;
497
498                         /* Unstack the used item */
499                         o_ptr->number--;
500                         p_ptr->total_weight -= q_ptr->weight;
501                         item = inven_carry(q_ptr);
502
503                         /* Message */
504 #ifdef JP
505                         msg_format("¾ó¤ò¤Þ¤È¤á¤Ê¤ª¤·¤¿¡£");
506 #else
507                         msg_print("You unstack your staff.");
508 #endif
509                 }
510
511                 /* Describe charges in the pack */
512                 if (item >= 0)
513                 {
514                         inven_item_charges(item);
515                 }
516
517                 /* Describe charges on the floor */
518                 else
519                 {
520                         floor_item_charges(0 - item);
521                 }
522
523                 /* Window stuff */
524                 p_ptr->window |= (PW_INVEN | PW_EQUIP);
525
526                 /* Don't eat a staff/wand itself */
527                 return;
528         }
529         else if ((prace_is_(RACE_DEMON) ||
530                  (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_DEMON)) &&
531                  (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_CORPSE &&
532                   my_strchr("pht", r_info[o_ptr->pval].d_char)))
533         {
534                 /* Drain vitality of humanoids */
535                 char o_name[MAX_NLEN];
536
537                 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
538
539 #ifdef JP
540                 msg_format("%s¤Ïdz¤¨¾å¤ê³¥¤Ë¤Ê¤Ã¤¿¡£ÀºÎϤòµÛ¼ý¤·¤¿µ¤¤¬¤¹¤ë¡£", o_name);
541 #else
542                 msg_format("%^s is burnt to ashes.  You absorb its vitality!", o_name);
543 #endif
544                 (void)set_food(PY_FOOD_MAX - 1);
545         }
546         else if (prace_is_(RACE_SKELETON))
547         {
548 #if 0
549                 if (o_ptr->tval == TV_SKELETON ||
550                     (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_SKELETON))
551                 {
552 #ifdef JP
553                         msg_print("¤¢¤Ê¤¿¤Ï¹ü¤Ç¼«Ê¬¤ÎÂΤòÊä¤Ã¤¿¡£");
554 #else
555                         msg_print("Your body absorbs the bone.");
556 #endif
557                         set_food(p_ptr->food + 5000);
558                 }
559                 else 
560 #endif
561
562                 if (!((o_ptr->sval == SV_FOOD_WAYBREAD) ||
563                       (o_ptr->sval < SV_FOOD_BISCUIT)))
564                 {
565                         object_type forge;
566                         object_type *q_ptr = &forge;
567
568 #ifdef JP
569 msg_print("¿©¤Ùʪ¤¬¥¢¥´¤òÁÇÄ̤ꤷ¤ÆÍî¤Á¤¿¡ª");
570 #else
571                         msg_print("The food falls through your jaws!");
572 #endif
573
574
575                         /* Create the item */
576                         object_prep(q_ptr, lookup_kind(o_ptr->tval, o_ptr->sval));
577
578                         /* Drop the object from heaven */
579                         (void)drop_near(q_ptr, -1, py, px);
580                 }
581                 else
582                 {
583 #ifdef JP
584 msg_print("¿©¤Ùʪ¤¬¥¢¥´¤òÁÇÄ̤ꤷ¤ÆÍî¤Á¡¢¾Ã¤¨¤¿¡ª");
585 #else
586                         msg_print("The food falls through your jaws and vanishes!");
587 #endif
588
589                 }
590         }
591         else if (prace_is_(RACE_GOLEM) ||
592                  prace_is_(RACE_ZOMBIE) ||
593                  prace_is_(RACE_ENT) ||
594                  prace_is_(RACE_DEMON) ||
595                  prace_is_(RACE_ANDROID) ||
596                  prace_is_(RACE_SPECTRE) ||
597                  (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_NONLIVING))
598         {
599 #ifdef JP
600 msg_print("À¸¼Ô¤Î¿©Êª¤Ï¤¢¤Ê¤¿¤Ë¤È¤Ã¤Æ¤Û¤È¤ó¤É±ÉÍܤˤʤé¤Ê¤¤¡£");
601 #else
602                 msg_print("The food of mortals is poor sustenance for you.");
603 #endif
604
605                 set_food(p_ptr->food + ((o_ptr->pval) / 20));
606         }
607         else if (o_ptr->tval == TV_FOOD && o_ptr->sval == SV_FOOD_WAYBREAD)
608         {
609                 /* Waybread is always fully satisfying. */
610                 set_food(MAX(p_ptr->food, PY_FOOD_MAX - 1));
611         }
612         else
613         {
614                 /* Food can feed the player */
615                 (void)set_food(p_ptr->food + o_ptr->pval);
616         }
617
618         /* Destroy a food in the pack */
619         if (item >= 0)
620         {
621                 inven_item_increase(item, -1);
622                 inven_item_describe(item);
623                 inven_item_optimize(item);
624         }
625
626         /* Destroy a food on the floor */
627         else
628         {
629                 floor_item_increase(0 - item, -1);
630                 floor_item_describe(0 - item);
631                 floor_item_optimize(0 - item);
632         }
633 }
634
635
636 /*
637  * Hook to determine if an object is eatable
638  */
639 static bool item_tester_hook_eatable(object_type *o_ptr)
640 {
641         if (o_ptr->tval==TV_FOOD) return TRUE;
642
643 #if 0
644         if (prace_is_(RACE_SKELETON))
645         {
646                 if (o_ptr->tval == TV_SKELETON ||
647                     (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_SKELETON))
648                         return TRUE;
649         }
650         else 
651 #endif
652
653         if (prace_is_(RACE_SKELETON) ||
654             prace_is_(RACE_GOLEM) ||
655             prace_is_(RACE_ZOMBIE) ||
656             prace_is_(RACE_SPECTRE))
657         {
658                 if (o_ptr->tval == TV_STAFF || o_ptr->tval == TV_WAND)
659                         return TRUE;
660         }
661         else if (prace_is_(RACE_DEMON) ||
662                  (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_DEMON))
663         {
664                 if (o_ptr->tval == TV_CORPSE &&
665                     o_ptr->sval == SV_CORPSE &&
666                     my_strchr("pht", r_info[o_ptr->pval].d_char))
667                         return TRUE;
668         }
669
670         /* Assume not */
671         return (FALSE);
672 }
673
674
675 /*
676  * Eat some food (from the pack or floor)
677  */
678 void do_cmd_eat_food(void)
679 {
680         int         item;
681         cptr        q, s;
682
683
684         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
685         {
686                 set_action(ACTION_NONE);
687         }
688
689         /* Restrict choices to food */
690         item_tester_hook = item_tester_hook_eatable;
691
692         /* Get an item */
693 #ifdef JP
694         q = "¤É¤ì¤ò¿©¤Ù¤Þ¤¹¤«? ";
695         s = "¿©¤Ùʪ¤¬¤Ê¤¤¡£";
696 #else
697         q = "Eat which item? ";
698         s = "You have nothing to eat.";
699 #endif
700
701         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
702
703         /* Eat the object */
704         do_cmd_eat_food_aux(item);
705 }
706
707
708 /*
709  * Quaff a potion (from the pack or the floor)
710  */
711 static void do_cmd_quaff_potion_aux(int item)
712 {
713         int         ident, lev;
714         object_type *o_ptr;
715         object_type forge;
716         object_type *q_ptr;
717
718
719         /* Take a turn */
720         energy_use = 100;
721
722         if (world_player)
723         {
724                 if (flush_failure) flush();
725 #ifdef JP
726                 msg_print("ÉÓ¤«¤é¿å¤¬Î®¤ì½Ð¤Æ¤³¤Ê¤¤¡ª");
727 #else
728                 msg_print("The potion doesn't flow out from a bottle.");
729 #endif
730
731                 sound(SOUND_FAIL);
732                 return;
733         }
734
735         if (music_singing_any()) stop_singing();
736         if (hex_spelling_any())
737         {
738                 if (!hex_spelling(HEX_INHAIL)) stop_hex_spell_all();
739         }
740
741         /* Get the item (in the pack) */
742         if (item >= 0)
743         {
744                 o_ptr = &inventory[item];
745         }
746
747         /* Get the item (on the floor) */
748         else
749         {
750                 o_ptr = &o_list[0 - item];
751         }
752
753         /* Get local object */
754         q_ptr = &forge;
755
756         /* Obtain a local object */
757         object_copy(q_ptr, o_ptr);
758
759         /* Single object */
760         q_ptr->number = 1;
761
762         /* Reduce and describe inventory */
763         if (item >= 0)
764         {
765                 inven_item_increase(item, -1);
766                 inven_item_describe(item);
767                 inven_item_optimize(item);
768         }
769
770         /* Reduce and describe floor item */
771         else
772         {
773                 floor_item_increase(0 - item, -1);
774                 floor_item_describe(0 - item);
775                 floor_item_optimize(0 - item);
776         }
777
778         /* Sound */
779         sound(SOUND_QUAFF);
780
781
782         /* Not identified yet */
783         ident = FALSE;
784
785         /* Object level */
786         lev = k_info[q_ptr->k_idx].level;
787
788         /* Analyze the potion */
789         if (q_ptr->tval == TV_POTION)
790         {
791                 switch (q_ptr->sval)
792                 {
793 #ifdef JP
794                         /* °û¤ß¤´¤¿¤¨¤ò¥ª¥ê¥¸¥Ê¥ë¤è¤êºÙ¤«¤¯É½¸½ */
795                 case SV_POTION_WATER:
796                         msg_print("¸ý¤ÎÃ椬¤µ¤Ã¤Ñ¤ê¤·¤¿¡£");
797                         msg_print("¤Î¤É¤Î³é¤­¤¬¾¯¤·¤ª¤µ¤Þ¤Ã¤¿¡£");
798                         ident = TRUE;
799                         break;
800
801                 case SV_POTION_APPLE_JUICE:
802                         msg_print("´Å¤¯¤Æ¥µ¥Ã¥Ñ¥ê¤È¤·¤Æ¤¤¤Æ¡¢¤È¤Æ¤â¤ª¤¤¤·¤¤¡£");
803                         msg_print("¤Î¤É¤Î³é¤­¤¬¾¯¤·¤ª¤µ¤Þ¤Ã¤¿¡£");
804                         ident = TRUE;
805                         break;
806
807                 case SV_POTION_SLIME_MOLD:
808                         msg_print("¤Ê¤ó¤È¤âÉÔµ¤Ì£¤ÊÌ£¤À¡£");
809                         msg_print("¤Î¤É¤Î³é¤­¤¬¾¯¤·¤ª¤µ¤Þ¤Ã¤¿¡£");
810                         ident = TRUE;
811                         break;
812
813 #else
814                 case SV_POTION_WATER:
815                 case SV_POTION_APPLE_JUICE:
816                 case SV_POTION_SLIME_MOLD:
817                         msg_print("You feel less thirsty.");
818                         ident = TRUE;
819                         break;
820 #endif
821
822                 case SV_POTION_SLOWNESS:
823                         if (set_slow(randint1(25) + 15, FALSE)) ident = TRUE;
824                         break;
825
826                 case SV_POTION_SALT_WATER:
827 #ifdef JP
828                         msg_print("¤¦¤§¡ª»×¤ï¤ºÅǤ¤¤Æ¤·¤Þ¤Ã¤¿¡£");
829 #else
830                         msg_print("The potion makes you vomit!");
831 #endif
832
833                         if (!(prace_is_(RACE_GOLEM) ||
834                               prace_is_(RACE_ZOMBIE) ||
835                               prace_is_(RACE_DEMON) ||
836                               prace_is_(RACE_ANDROID) ||
837                               prace_is_(RACE_SPECTRE) ||
838                               (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_NONLIVING)))
839                         {
840                                 /* Only living creatures get thirsty */
841                                 (void)set_food(PY_FOOD_STARVE - 1);
842                         }
843
844                         (void)set_poisoned(0);
845                         (void)set_paralyzed(p_ptr->paralyzed + 4);
846                         ident = TRUE;
847                         break;
848
849                 case SV_POTION_POISON:
850                         if (!(p_ptr->resist_pois || IS_OPPOSE_POIS()))
851                         {
852                                 if (set_poisoned(p_ptr->poisoned + randint0(15) + 10))
853                                 {
854                                         ident = TRUE;
855                                 }
856                         }
857                         break;
858
859                 case SV_POTION_BLINDNESS:
860                         if (!p_ptr->resist_blind)
861                         {
862                                 if (set_blind(p_ptr->blind + randint0(100) + 100))
863                                 {
864                                         ident = TRUE;
865                                 }
866                         }
867                         break;
868
869                 case SV_POTION_CONFUSION: /* Booze */
870                         if (p_ptr->pclass != CLASS_MONK) chg_virtue(V_HARMONY, -1);
871                         else if (!p_ptr->resist_conf) p_ptr->special_attack |= ATTACK_SUIKEN;
872                         if (!p_ptr->resist_conf)
873                         {
874                                 if (set_confused(randint0(20) + 15))
875                                 {
876                                         ident = TRUE;
877                                 }
878                         }
879
880                         if (!p_ptr->resist_chaos)
881                         {
882                                 if (one_in_(2))
883                                 {
884                                         if (set_image(p_ptr->image + randint0(150) + 150))
885                                         {
886                                                 ident = TRUE;
887                                         }
888                                 }
889                                 if (one_in_(13) && (p_ptr->pclass != CLASS_MONK))
890                                 {
891                                         ident = TRUE;
892                                         if (one_in_(3)) lose_all_info();
893                                         else wiz_dark();
894                                         (void)teleport_player_aux(100, TELEPORT_NONMAGICAL | TELEPORT_PASSIVE);
895                                         wiz_dark();
896 #ifdef JP
897                                         msg_print("ÃΤé¤Ê¤¤¾ì½ê¤ÇÌܤ¬Àä᤿¡£Æ¬Äˤ¬¤¹¤ë¡£");
898                                         msg_print("²¿¤â»×¤¤½Ð¤»¤Ê¤¤¡£¤É¤¦¤ä¤Ã¤Æ¤³¤³¤ØÍ褿¤Î¤«¤âʬ¤«¤é¤Ê¤¤¡ª");
899 #else
900                                         msg_print("You wake up somewhere with a sore head...");
901                                         msg_print("You can't remember a thing, or how you got here!");
902 #endif
903
904                                 }
905                         }
906                         break;
907
908                 case SV_POTION_SLEEP:
909                         if (!p_ptr->free_act)
910                         {
911 #ifdef JP
912                 msg_print("¤¢¤Ê¤¿¤Ï̲¤Ã¤Æ¤·¤Þ¤Ã¤¿¡£");
913 #else
914                 msg_print("You fall asleep.");
915 #endif
916
917
918                                 if (ironman_nightmare)
919                                 {
920 #ifdef JP
921 msg_print("¶²¤í¤·¤¤¸÷·Ê¤¬Æ¬¤ËÉ⤫¤ó¤Ç¤­¤¿¡£");
922 #else
923                                         msg_print("A horrible vision enters your mind.");
924 #endif
925
926
927                                         /* Pick a nightmare */
928                                         get_mon_num_prep(get_nightmare, NULL);
929
930                                         /* Have some nightmares */
931                                         have_nightmare(get_mon_num(MAX_DEPTH));
932
933                                         /* Remove the monster restriction */
934                                         get_mon_num_prep(NULL, NULL);
935                                 }
936                                 if (set_paralyzed(p_ptr->paralyzed + randint0(4) + 4))
937                                 {
938                                         ident = TRUE;
939                                 }
940                         }
941                         break;
942
943                 case SV_POTION_LOSE_MEMORIES:
944                         if (!p_ptr->hold_life && (p_ptr->exp > 0))
945                         {
946 #ifdef JP
947                                 msg_print("²áµî¤Îµ­²±¤¬Çö¤ì¤Æ¤¤¤¯µ¤¤¬¤¹¤ë¡£");
948 #else
949                                 msg_print("You feel your memories fade.");
950 #endif
951                                 chg_virtue(V_KNOWLEDGE, -5);
952
953                                 lose_exp(p_ptr->exp / 4);
954                                 ident = TRUE;
955                         }
956                         break;
957
958                 case SV_POTION_RUINATION:
959 #ifdef JP
960                         msg_print("¿È¤â¿´¤â¼å¤Ã¤Æ¤­¤Æ¡¢Àºµ¤¤¬È´¤±¤Æ¤¤¤¯¤è¤¦¤À¡£");
961                         take_hit(DAMAGE_LOSELIFE, damroll(10, 10), "ÇËÌǤÎÌô", -1);
962 #else
963                         msg_print("Your nerves and muscles feel weak and lifeless!");
964                         take_hit(DAMAGE_LOSELIFE, damroll(10, 10), "a potion of Ruination", -1);
965 #endif
966
967                         (void)dec_stat(A_DEX, 25, TRUE);
968                         (void)dec_stat(A_WIS, 25, TRUE);
969                         (void)dec_stat(A_CON, 25, TRUE);
970                         (void)dec_stat(A_STR, 25, TRUE);
971                         (void)dec_stat(A_CHR, 25, TRUE);
972                         (void)dec_stat(A_INT, 25, TRUE);
973                         ident = TRUE;
974                         break;
975
976                 case SV_POTION_DEC_STR:
977                         if (do_dec_stat(A_STR)) ident = TRUE;
978                         break;
979
980                 case SV_POTION_DEC_INT:
981                         if (do_dec_stat(A_INT)) ident = TRUE;
982                         break;
983
984                 case SV_POTION_DEC_WIS:
985                         if (do_dec_stat(A_WIS)) ident = TRUE;
986                         break;
987
988                 case SV_POTION_DEC_DEX:
989                         if (do_dec_stat(A_DEX)) ident = TRUE;
990                         break;
991
992                 case SV_POTION_DEC_CON:
993                         if (do_dec_stat(A_CON)) ident = TRUE;
994                         break;
995
996                 case SV_POTION_DEC_CHR:
997                         if (do_dec_stat(A_CHR)) ident = TRUE;
998                         break;
999
1000                 case SV_POTION_DETONATIONS:
1001 #ifdef JP
1002                         msg_print("ÂΤÎÃæ¤Ç·ã¤·¤¤Çúȯ¤¬µ¯¤­¤¿¡ª");
1003                         take_hit(DAMAGE_NOESCAPE, damroll(50, 20), "Çúȯ¤ÎÌô", -1);
1004 #else
1005                         msg_print("Massive explosions rupture your body!");
1006                         take_hit(DAMAGE_NOESCAPE, damroll(50, 20), "a potion of Detonation", -1);
1007 #endif
1008
1009                         (void)set_stun(p_ptr->stun + 75);
1010                         (void)set_cut(p_ptr->cut + 5000);
1011                         ident = TRUE;
1012                         break;
1013
1014                 case SV_POTION_DEATH:
1015                         chg_virtue(V_VITALITY, -1);
1016                         chg_virtue(V_UNLIFE, 5);
1017 #ifdef JP
1018                         msg_print("»à¤Îͽ´¶¤¬ÂÎÃæ¤ò¶î¤±¤á¤°¤Ã¤¿¡£");
1019                         take_hit(DAMAGE_LOSELIFE, 5000, "»à¤ÎÌô", -1);
1020 #else
1021                         msg_print("A feeling of Death flows through your body.");
1022                         take_hit(DAMAGE_LOSELIFE, 5000, "a potion of Death", -1);
1023 #endif
1024
1025                         ident = TRUE;
1026                         break;
1027
1028                 case SV_POTION_INFRAVISION:
1029                         if (set_tim_infra(p_ptr->tim_infra + 100 + randint1(100), FALSE))
1030                         {
1031                                 ident = TRUE;
1032                         }
1033                         break;
1034
1035                 case SV_POTION_DETECT_INVIS:
1036                         if (set_tim_invis(p_ptr->tim_invis + 12 + randint1(12), FALSE))
1037                         {
1038                                 ident = TRUE;
1039                         }
1040                         break;
1041
1042                 case SV_POTION_SLOW_POISON:
1043                         if (set_poisoned(p_ptr->poisoned / 2)) ident = TRUE;
1044                         break;
1045
1046                 case SV_POTION_CURE_POISON:
1047                         if (set_poisoned(0)) ident = TRUE;
1048                         break;
1049
1050                 case SV_POTION_BOLDNESS:
1051                         if (set_afraid(0)) ident = TRUE;
1052                         break;
1053
1054                 case SV_POTION_SPEED:
1055                         if (!p_ptr->fast)
1056                         {
1057                                 if (set_fast(randint1(25) + 15, FALSE)) ident = TRUE;
1058                         }
1059                         else
1060                         {
1061                                 (void)set_fast(p_ptr->fast + 5, FALSE);
1062                         }
1063                         break;
1064
1065                 case SV_POTION_RESIST_HEAT:
1066                         if (set_oppose_fire(p_ptr->oppose_fire + randint1(10) + 10, FALSE))
1067                         {
1068                                 ident = TRUE;
1069                         }
1070                         break;
1071
1072                 case SV_POTION_RESIST_COLD:
1073                         if (set_oppose_cold(p_ptr->oppose_cold + randint1(10) + 10, FALSE))
1074                         {
1075                                 ident = TRUE;
1076                         }
1077                         break;
1078
1079                 case SV_POTION_HEROISM:
1080                         if (set_afraid(0)) ident = TRUE;
1081                         if (set_hero(p_ptr->hero + randint1(25) + 25, FALSE)) ident = TRUE;
1082                         if (hp_player(10)) ident = TRUE;
1083                         break;
1084
1085                 case SV_POTION_BESERK_STRENGTH:
1086                         if (set_afraid(0)) ident = TRUE;
1087                         if (set_shero(p_ptr->shero + randint1(25) + 25, FALSE)) ident = TRUE;
1088                         if (hp_player(30)) ident = TRUE;
1089                         break;
1090
1091                 case SV_POTION_CURE_LIGHT:
1092                         if (hp_player(damroll(2, 8))) ident = TRUE;
1093                         if (set_blind(0)) ident = TRUE;
1094                         if (set_cut(p_ptr->cut - 10)) ident = TRUE;
1095                         if (set_shero(0,TRUE)) ident = TRUE;
1096                         break;
1097
1098                 case SV_POTION_CURE_SERIOUS:
1099                         if (hp_player(damroll(4, 8))) ident = TRUE;
1100                         if (set_blind(0)) ident = TRUE;
1101                         if (set_confused(0)) ident = TRUE;
1102                         if (set_cut((p_ptr->cut / 2) - 50)) ident = TRUE;
1103                         if (set_shero(0,TRUE)) ident = TRUE;
1104                         break;
1105
1106                 case SV_POTION_CURE_CRITICAL:
1107                         if (hp_player(damroll(6, 8))) ident = TRUE;
1108                         if (set_blind(0)) ident = TRUE;
1109                         if (set_confused(0)) ident = TRUE;
1110                         if (set_poisoned(0)) ident = TRUE;
1111                         if (set_stun(0)) ident = TRUE;
1112                         if (set_cut(0)) ident = TRUE;
1113                         if (set_shero(0,TRUE)) ident = TRUE;
1114                         break;
1115
1116                 case SV_POTION_HEALING:
1117                         if (hp_player(300)) ident = TRUE;
1118                         if (set_blind(0)) ident = TRUE;
1119                         if (set_confused(0)) ident = TRUE;
1120                         if (set_poisoned(0)) ident = TRUE;
1121                         if (set_stun(0)) ident = TRUE;
1122                         if (set_cut(0)) ident = TRUE;
1123                         if (set_shero(0,TRUE)) ident = TRUE;
1124                         break;
1125
1126                 case SV_POTION_STAR_HEALING:
1127                         if (hp_player(1200)) ident = TRUE;
1128                         if (set_blind(0)) ident = TRUE;
1129                         if (set_confused(0)) ident = TRUE;
1130                         if (set_poisoned(0)) ident = TRUE;
1131                         if (set_stun(0)) ident = TRUE;
1132                         if (set_cut(0)) ident = TRUE;
1133                         if (set_shero(0,TRUE)) ident = TRUE;
1134                         break;
1135
1136                 case SV_POTION_LIFE:
1137                         chg_virtue(V_VITALITY, 1);
1138                         chg_virtue(V_UNLIFE, -5);
1139 #ifdef JP
1140                         msg_print("ÂÎÃæ¤ËÀ¸Ì¿ÎϤ¬Ëþ¤Á¤¢¤Õ¤ì¤Æ¤­¤¿¡ª");
1141 #else
1142                         msg_print("You feel life flow through your body!");
1143 #endif
1144
1145                         restore_level();
1146                         (void)set_poisoned(0);
1147                         (void)set_blind(0);
1148                         (void)set_confused(0);
1149                         (void)set_image(0);
1150                         (void)set_stun(0);
1151                         (void)set_cut(0);
1152                         (void)do_res_stat(A_STR);
1153                         (void)do_res_stat(A_CON);
1154                         (void)do_res_stat(A_DEX);
1155                         (void)do_res_stat(A_WIS);
1156                         (void)do_res_stat(A_INT);
1157                         (void)do_res_stat(A_CHR);
1158                         (void)set_shero(0,TRUE);
1159                         update_stuff();
1160                         hp_player(5000);
1161                         ident = TRUE;
1162                         break;
1163
1164                 case SV_POTION_RESTORE_MANA:
1165                         if (p_ptr->pclass == CLASS_MAGIC_EATER)
1166                         {
1167                                 int i;
1168                                 for (i = 0; i < EATER_EXT*2; i++)
1169                                 {
1170                                         p_ptr->magic_num1[i] += (p_ptr->magic_num2[i] < 10) ? EATER_CHARGE * 3 : p_ptr->magic_num2[i]*EATER_CHARGE/3;
1171                                         if (p_ptr->magic_num1[i] > p_ptr->magic_num2[i]*EATER_CHARGE) p_ptr->magic_num1[i] = p_ptr->magic_num2[i]*EATER_CHARGE;
1172                                 }
1173                                 for (; i < EATER_EXT*3; i++)
1174                                 {
1175                                         int k_idx = lookup_kind(TV_ROD, i-EATER_EXT*2);
1176                                         p_ptr->magic_num1[i] -= ((p_ptr->magic_num2[i] < 10) ? EATER_ROD_CHARGE*3 : p_ptr->magic_num2[i]*EATER_ROD_CHARGE/3)*k_info[k_idx].pval;
1177                                         if (p_ptr->magic_num1[i] < 0) p_ptr->magic_num1[i] = 0;
1178                                 }
1179 #ifdef JP
1180                                 msg_print("Ƭ¤¬¥Ï¥Ã¥­¥ê¤È¤·¤¿¡£");
1181 #else
1182                                 msg_print("You feel your head clear.");
1183 #endif
1184                                 p_ptr->window |= (PW_PLAYER);
1185                                 ident = TRUE;
1186                         }
1187                         else if (p_ptr->csp < p_ptr->msp)
1188                         {
1189                                 p_ptr->csp = p_ptr->msp;
1190                                 p_ptr->csp_frac = 0;
1191 #ifdef JP
1192                                 msg_print("Ƭ¤¬¥Ï¥Ã¥­¥ê¤È¤·¤¿¡£");
1193 #else
1194                                 msg_print("You feel your head clear.");
1195 #endif
1196
1197                                 p_ptr->redraw |= (PR_MANA);
1198                                 p_ptr->window |= (PW_PLAYER);
1199                                 p_ptr->window |= (PW_SPELL);
1200                                 ident = TRUE;
1201                         }
1202                         if (set_shero(0,TRUE)) ident = TRUE;
1203                         break;
1204
1205                 case SV_POTION_RESTORE_EXP:
1206                         if (restore_level()) ident = TRUE;
1207                         break;
1208
1209                 case SV_POTION_RES_STR:
1210                         if (do_res_stat(A_STR)) ident = TRUE;
1211                         break;
1212
1213                 case SV_POTION_RES_INT:
1214                         if (do_res_stat(A_INT)) ident = TRUE;
1215                         break;
1216
1217                 case SV_POTION_RES_WIS:
1218                         if (do_res_stat(A_WIS)) ident = TRUE;
1219                         break;
1220
1221                 case SV_POTION_RES_DEX:
1222                         if (do_res_stat(A_DEX)) ident = TRUE;
1223                         break;
1224
1225                 case SV_POTION_RES_CON:
1226                         if (do_res_stat(A_CON)) ident = TRUE;
1227                         break;
1228
1229                 case SV_POTION_RES_CHR:
1230                         if (do_res_stat(A_CHR)) ident = TRUE;
1231                         break;
1232
1233                 case SV_POTION_INC_STR:
1234                         if (do_inc_stat(A_STR)) ident = TRUE;
1235                         break;
1236
1237                 case SV_POTION_INC_INT:
1238                         if (do_inc_stat(A_INT)) ident = TRUE;
1239                         break;
1240
1241                 case SV_POTION_INC_WIS:
1242                         if (do_inc_stat(A_WIS)) ident = TRUE;
1243                         break;
1244
1245                 case SV_POTION_INC_DEX:
1246                         if (do_inc_stat(A_DEX)) ident = TRUE;
1247                         break;
1248
1249                 case SV_POTION_INC_CON:
1250                         if (do_inc_stat(A_CON)) ident = TRUE;
1251                         break;
1252
1253                 case SV_POTION_INC_CHR:
1254                         if (do_inc_stat(A_CHR)) ident = TRUE;
1255                         break;
1256
1257                 case SV_POTION_AUGMENTATION:
1258                         if (do_inc_stat(A_STR)) ident = TRUE;
1259                         if (do_inc_stat(A_INT)) ident = TRUE;
1260                         if (do_inc_stat(A_WIS)) ident = TRUE;
1261                         if (do_inc_stat(A_DEX)) ident = TRUE;
1262                         if (do_inc_stat(A_CON)) ident = TRUE;
1263                         if (do_inc_stat(A_CHR)) ident = TRUE;
1264                         break;
1265
1266                 case SV_POTION_ENLIGHTENMENT:
1267 #ifdef JP
1268                         msg_print("¼«Ê¬¤ÎÃÖ¤«¤ì¤Æ¤¤¤ë¾õ¶·¤¬Ç¾Î¢¤ËÉ⤫¤ó¤Ç¤­¤¿...");
1269 #else
1270                         msg_print("An image of your surroundings forms in your mind...");
1271 #endif
1272
1273                         chg_virtue(V_KNOWLEDGE, 1);
1274                         chg_virtue(V_ENLIGHTEN, 1);
1275                         wiz_lite(FALSE);
1276                         ident = TRUE;
1277                         break;
1278
1279                 case SV_POTION_STAR_ENLIGHTENMENT:
1280 #ifdef JP
1281                         msg_print("¹¹¤Ê¤ë·¼Ìؤò´¶¤¸¤¿...");
1282 #else
1283                         msg_print("You begin to feel more enlightened...");
1284 #endif
1285
1286                         chg_virtue(V_KNOWLEDGE, 1);
1287                         chg_virtue(V_ENLIGHTEN, 2);
1288                         msg_print(NULL);
1289                         wiz_lite(FALSE);
1290                         (void)do_inc_stat(A_INT);
1291                         (void)do_inc_stat(A_WIS);
1292                         (void)detect_traps(DETECT_RAD_DEFAULT, TRUE);
1293                         (void)detect_doors(DETECT_RAD_DEFAULT);
1294                         (void)detect_stairs(DETECT_RAD_DEFAULT);
1295                         (void)detect_treasure(DETECT_RAD_DEFAULT);
1296                         (void)detect_objects_gold(DETECT_RAD_DEFAULT);
1297                         (void)detect_objects_normal(DETECT_RAD_DEFAULT);
1298                         identify_pack();
1299                         self_knowledge();
1300                         ident = TRUE;
1301                         break;
1302
1303                 case SV_POTION_SELF_KNOWLEDGE:
1304 #ifdef JP
1305                         msg_print("¼«Ê¬¼«¿È¤Î¤³¤È¤¬¾¯¤·¤Ïʬ¤«¤Ã¤¿µ¤¤¬¤¹¤ë...");
1306 #else
1307                         msg_print("You begin to know yourself a little better...");
1308 #endif
1309
1310                         msg_print(NULL);
1311                         self_knowledge();
1312                         ident = TRUE;
1313                         break;
1314
1315                 case SV_POTION_EXPERIENCE:
1316                         if (p_ptr->prace == RACE_ANDROID) break;
1317                         chg_virtue(V_ENLIGHTEN, 1);
1318                         if (p_ptr->exp < PY_MAX_EXP)
1319                         {
1320                                 s32b ee = (p_ptr->exp / 2) + 10;
1321                                 if (ee > 100000L) ee = 100000L;
1322 #ifdef JP
1323                                 msg_print("¹¹¤Ë·Ð¸³¤òÀѤó¤À¤è¤¦¤Êµ¤¤¬¤¹¤ë¡£");
1324 #else
1325                                 msg_print("You feel more experienced.");
1326 #endif
1327
1328                                 gain_exp(ee);
1329                                 ident = TRUE;
1330                         }
1331                         break;
1332
1333                 case SV_POTION_RESISTANCE:
1334                         (void)set_oppose_acid(p_ptr->oppose_acid + randint1(20) + 20, FALSE);
1335                         (void)set_oppose_elec(p_ptr->oppose_elec + randint1(20) + 20, FALSE);
1336                         (void)set_oppose_fire(p_ptr->oppose_fire + randint1(20) + 20, FALSE);
1337                         (void)set_oppose_cold(p_ptr->oppose_cold + randint1(20) + 20, FALSE);
1338                         (void)set_oppose_pois(p_ptr->oppose_pois + randint1(20) + 20, FALSE);
1339                         ident = TRUE;
1340                         break;
1341
1342                 case SV_POTION_CURING:
1343                         if (hp_player(50)) ident = TRUE;
1344                         if (set_blind(0)) ident = TRUE;
1345                         if (set_poisoned(0)) ident = TRUE;
1346                         if (set_confused(0)) ident = TRUE;
1347                         if (set_stun(0)) ident = TRUE;
1348                         if (set_cut(0)) ident = TRUE;
1349                         if (set_image(0)) ident = TRUE;
1350                         break;
1351
1352                 case SV_POTION_INVULNERABILITY:
1353                         (void)set_invuln(p_ptr->invuln + randint1(4) + 4, FALSE);
1354                         ident = TRUE;
1355                         break;
1356
1357                 case SV_POTION_NEW_LIFE:
1358                         do_cmd_rerate(FALSE);
1359                         get_max_stats();
1360                         p_ptr->update |= PU_BONUS;
1361                         if (p_ptr->muta1 || p_ptr->muta2 || p_ptr->muta3)
1362                         {
1363                                 chg_virtue(V_CHANCE, -5);
1364 #ifdef JP
1365 msg_print("Á´¤Æ¤ÎÆÍÁ³ÊÑ°Û¤¬¼£¤Ã¤¿¡£");
1366 #else
1367                                 msg_print("You are cured of all mutations.");
1368 #endif
1369
1370                                 p_ptr->muta1 = p_ptr->muta2 = p_ptr->muta3 = 0;
1371                                 p_ptr->update |= PU_BONUS;
1372                                 handle_stuff();
1373                                 mutant_regenerate_mod = calc_mutant_regenerate_mod();
1374                         }
1375                         ident = TRUE;
1376                         break;
1377
1378                 case SV_POTION_NEO_TSUYOSHI:
1379                         (void)set_image(0);
1380                         (void)set_tsuyoshi(p_ptr->tsuyoshi + randint1(100) + 100, FALSE);
1381                         ident = TRUE;
1382                         break;
1383
1384                 case SV_POTION_TSUYOSHI:
1385 #ifdef JP
1386 msg_print("¡Ö¥ª¥¯¥ì·»¤µ¤ó¡ª¡×");
1387 #else
1388                         msg_print("Brother OKURE!");
1389 #endif
1390                         msg_print(NULL);
1391                         p_ptr->tsuyoshi = 1;
1392                         (void)set_tsuyoshi(0, TRUE);
1393                         if (!p_ptr->resist_chaos)
1394                         {
1395                                 (void)set_image(50 + randint1(50));
1396                         }
1397                         ident = TRUE;
1398                         break;
1399                 
1400                 case SV_POTION_POLYMORPH:
1401                         if ((p_ptr->muta1 || p_ptr->muta2 || p_ptr->muta3) && one_in_(23))
1402                         {
1403                                 chg_virtue(V_CHANCE, -5);
1404 #ifdef JP
1405 msg_print("Á´¤Æ¤ÎÆÍÁ³ÊÑ°Û¤¬¼£¤Ã¤¿¡£");
1406 #else
1407                                 msg_print("You are cured of all mutations.");
1408 #endif
1409
1410                                 p_ptr->muta1 = p_ptr->muta2 = p_ptr->muta3 = 0;
1411                                 p_ptr->update |= PU_BONUS;
1412                                 handle_stuff();
1413                         }
1414                         else
1415                         {
1416                                 do
1417                                 {
1418                                         if (one_in_(2))
1419                                         {
1420                                                 if(gain_random_mutation(0)) ident = TRUE;
1421                                         }
1422                                         else if (lose_mutation(0)) ident = TRUE;
1423                                 } while(!ident || one_in_(2));
1424                         }
1425                         break;
1426                 }
1427         }
1428
1429         if (prace_is_(RACE_SKELETON))
1430         {
1431 #ifdef JP
1432 msg_print("±ÕÂΤΰìÉô¤Ï¤¢¤Ê¤¿¤Î¥¢¥´¤òÁÇÄ̤ꤷ¤ÆÍî¤Á¤¿¡ª");
1433 #else
1434                 msg_print("Some of the fluid falls through your jaws!");
1435 #endif
1436
1437                 (void)potion_smash_effect(0, py, px, q_ptr->k_idx);
1438         }
1439
1440         /* Combine / Reorder the pack (later) */
1441         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
1442
1443         if (!(object_is_aware(q_ptr)))
1444         {
1445                 chg_virtue(V_PATIENCE, -1);
1446                 chg_virtue(V_CHANCE, 1);
1447                 chg_virtue(V_KNOWLEDGE, -1);
1448         }
1449
1450         /* The item has been tried */
1451         object_tried(q_ptr);
1452
1453         /* An identification was made */
1454         if (ident && !object_is_aware(q_ptr))
1455         {
1456                 object_aware(q_ptr);
1457                 gain_exp((lev + (p_ptr->lev >> 1)) / p_ptr->lev);
1458         }
1459
1460         /* Window stuff */
1461         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
1462
1463         /* Potions can feed the player */
1464         switch (p_ptr->mimic_form)
1465         {
1466         case MIMIC_NONE:
1467                 switch (p_ptr->prace)
1468                 {
1469                         case RACE_VAMPIRE:
1470                                 (void)set_food(p_ptr->food + (q_ptr->pval / 10));
1471                                 break;
1472                         case RACE_SKELETON:
1473                                 /* Do nothing */
1474                                 break;
1475                         case RACE_GOLEM:
1476                         case RACE_ZOMBIE:
1477                         case RACE_DEMON:
1478                         case RACE_SPECTRE:
1479                                 set_food(p_ptr->food + ((q_ptr->pval) / 20));
1480                                 break;
1481                         case RACE_ANDROID:
1482                                 if (q_ptr->tval == TV_FLASK)
1483                                 {
1484 #ifdef JP
1485                                         msg_print("¥ª¥¤¥ë¤òÊäµë¤·¤¿¡£");
1486 #else
1487                                         msg_print("You replenish yourself with the oil.");
1488 #endif
1489                                         set_food(p_ptr->food + 5000);
1490                                 }
1491                                 else
1492                                 {
1493                                         set_food(p_ptr->food + ((q_ptr->pval) / 20));
1494                                 }
1495                                 break;
1496                         case RACE_ENT:
1497 #ifdef JP
1498                                 msg_print("¿åʬ¤ò¼è¤ê¹þ¤ó¤À¡£");
1499 #else
1500                                 msg_print("You are moistened.");
1501 #endif
1502                                 set_food(MIN(p_ptr->food + q_ptr->pval + MAX(0, q_ptr->pval * 10) + 2000, PY_FOOD_MAX - 1));
1503                                 break;
1504                         default:
1505                                 (void)set_food(p_ptr->food + q_ptr->pval);
1506                                 break;
1507                 }
1508                 break;
1509         case MIMIC_DEMON:
1510         case MIMIC_DEMON_LORD:
1511                 set_food(p_ptr->food + ((q_ptr->pval) / 20));
1512                 break;
1513         case MIMIC_VAMPIRE:
1514                 (void)set_food(p_ptr->food + (q_ptr->pval / 10));
1515                 break;
1516         default:
1517                 (void)set_food(p_ptr->food + q_ptr->pval);
1518                 break;
1519         }
1520 }
1521
1522
1523 /*
1524  * Hook to determine if an object can be quaffed
1525  */
1526 static bool item_tester_hook_quaff(object_type *o_ptr)
1527 {
1528         if (o_ptr->tval == TV_POTION) return TRUE;
1529
1530         if (prace_is_(RACE_ANDROID))
1531         {
1532                 if (o_ptr->tval == TV_FLASK && o_ptr->sval == SV_FLASK_OIL)
1533                         return TRUE;
1534         }
1535
1536         return FALSE;
1537 }
1538
1539
1540 /*
1541  * Quaff some potion (from the pack or floor)
1542  */
1543 void do_cmd_quaff_potion(void)
1544 {
1545         int  item;
1546         cptr q, s;
1547
1548         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
1549         {
1550                 set_action(ACTION_NONE);
1551         }
1552
1553         /* Restrict choices to potions */
1554         item_tester_hook = item_tester_hook_quaff;
1555
1556         /* Get an item */
1557 #ifdef JP
1558         q = "¤É¤ÎÌô¤ò°û¤ß¤Þ¤¹¤«? ";
1559         s = "°û¤á¤ëÌô¤¬¤Ê¤¤¡£";
1560 #else
1561         q = "Quaff which potion? ";
1562         s = "You have no potions to quaff.";
1563 #endif
1564
1565         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
1566
1567         /* Quaff the potion */
1568         do_cmd_quaff_potion_aux(item);
1569 }
1570
1571
1572 /*
1573  * Read a scroll (from the pack or floor).
1574  *
1575  * Certain scrolls can be "aborted" without losing the scroll.  These
1576  * include scrolls with no effects but recharge or identify, which are
1577  * cancelled before use.  XXX Reading them still takes a turn, though.
1578  */
1579 static void do_cmd_read_scroll_aux(int item, bool known)
1580 {
1581         int         k, used_up, ident, lev;
1582         object_type *o_ptr;
1583         char        Rumor[1024];
1584
1585
1586         /* Get the item (in the pack) */
1587         if (item >= 0)
1588         {
1589                 o_ptr = &inventory[item];
1590         }
1591
1592         /* Get the item (on the floor) */
1593         else
1594         {
1595                 o_ptr = &o_list[0 - item];
1596         }
1597
1598
1599         /* Take a turn */
1600         energy_use = 100;
1601
1602         if (world_player)
1603         {
1604                 if (flush_failure) flush();
1605 #ifdef JP
1606                 msg_print("»ß¤Þ¤Ã¤¿»þ¤ÎÃæ¤Ç¤Ï¤¦¤Þ¤¯Æ¯¤«¤Ê¤¤¤è¤¦¤À¡£");
1607 #else
1608                 msg_print("Nothing happen.");
1609 #endif
1610
1611                 sound(SOUND_FAIL);
1612                 return;
1613         }
1614
1615         if (p_ptr->pclass == CLASS_BERSERKER)
1616         {
1617 #ifdef JP
1618                 msg_print("´¬Êª¤Ê¤ó¤ÆÆɤá¤Ê¤¤¡£");
1619 #else
1620                 msg_print("You cannot read.");
1621 #endif
1622                 return;
1623         }
1624
1625         if (music_singing_any()) stop_singing();
1626
1627         /* Hex */
1628         if (hex_spelling_any() && ((p_ptr->lev < 35) || hex_spell_fully())) stop_hex_spell_all();
1629
1630         /* Not identified yet */
1631         ident = FALSE;
1632
1633         /* Object level */
1634         lev = k_info[o_ptr->k_idx].level;
1635
1636         /* Assume the scroll will get used up */
1637         used_up = TRUE;
1638
1639         if (o_ptr->tval == TV_SCROLL)
1640         {
1641         /* Analyze the scroll */
1642         switch (o_ptr->sval)
1643         {
1644                 case SV_SCROLL_DARKNESS:
1645                 {
1646                         if (!(p_ptr->resist_blind) && !(p_ptr->resist_dark))
1647                         {
1648                                 (void)set_blind(p_ptr->blind + 3 + randint1(5));
1649                         }
1650                         if (unlite_area(10, 3)) ident = TRUE;
1651                         break;
1652                 }
1653
1654                 case SV_SCROLL_AGGRAVATE_MONSTER:
1655                 {
1656 #ifdef JP
1657                         msg_print("¥«¥ó¹â¤¯¤¦¤Ê¤ëÍͤʲ»¤¬ÊÕ¤ê¤òʤ¤Ã¤¿¡£");
1658 #else
1659                         msg_print("There is a high pitched humming noise.");
1660 #endif
1661
1662                         aggravate_monsters(0);
1663                         ident = TRUE;
1664                         break;
1665                 }
1666
1667                 case SV_SCROLL_CURSE_ARMOR:
1668                 {
1669                         if (curse_armor()) ident = TRUE;
1670                         break;
1671                 }
1672
1673                 case SV_SCROLL_CURSE_WEAPON:
1674                 {
1675                         k = 0;
1676                         if (buki_motteruka(INVEN_RARM))
1677                         {
1678                                 k = INVEN_RARM;
1679                                 if (buki_motteruka(INVEN_LARM) && one_in_(2)) k = INVEN_LARM;
1680                         }
1681                         else if (buki_motteruka(INVEN_LARM)) k = INVEN_LARM;
1682                         if (k && curse_weapon(FALSE, k)) ident = TRUE;
1683                         break;
1684                 }
1685
1686                 case SV_SCROLL_SUMMON_MONSTER:
1687                 {
1688                         for (k = 0; k < randint1(3); k++)
1689                         {
1690                                 if (summon_specific(0, py, px, dun_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
1691                                 {
1692                                         ident = TRUE;
1693                                 }
1694                         }
1695                         break;
1696                 }
1697
1698                 case SV_SCROLL_SUMMON_UNDEAD:
1699                 {
1700                         for (k = 0; k < randint1(3); k++)
1701                         {
1702                                 if (summon_specific(0, py, px, dun_level, SUMMON_UNDEAD, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
1703                                 {
1704                                         ident = TRUE;
1705                                 }
1706                         }
1707                         break;
1708                 }
1709
1710                 case SV_SCROLL_SUMMON_PET:
1711                 {
1712                         if (summon_specific(-1, py, px, dun_level, 0, (PM_ALLOW_GROUP | PM_FORCE_PET)))
1713                         {
1714                                 ident = TRUE;
1715                         }
1716                         break;
1717                 }
1718
1719                 case SV_SCROLL_SUMMON_KIN:
1720                 {
1721                         if (summon_kin_player(p_ptr->lev, py, px, (PM_FORCE_PET | PM_ALLOW_GROUP)))
1722                         {
1723                                 ident = TRUE;
1724                         }
1725                         break;
1726                 }
1727
1728                 case SV_SCROLL_TRAP_CREATION:
1729                 {
1730                         if (trap_creation(py, px)) ident = TRUE;
1731                         break;
1732                 }
1733
1734                 case SV_SCROLL_PHASE_DOOR:
1735                 {
1736                         teleport_player(10, 0L);
1737                         ident = TRUE;
1738                         break;
1739                 }
1740
1741                 case SV_SCROLL_TELEPORT:
1742                 {
1743                         teleport_player(100, 0L);
1744                         ident = TRUE;
1745                         break;
1746                 }
1747
1748                 case SV_SCROLL_TELEPORT_LEVEL:
1749                 {
1750                         (void)teleport_level(0);
1751                         ident = TRUE;
1752                         break;
1753                 }
1754
1755                 case SV_SCROLL_WORD_OF_RECALL:
1756                 {
1757                         if (!word_of_recall()) used_up = FALSE;
1758                         ident = TRUE;
1759                         break;
1760                 }
1761
1762                 case SV_SCROLL_IDENTIFY:
1763                 {
1764                         if (!ident_spell(FALSE)) used_up = FALSE;
1765                         ident = TRUE;
1766                         break;
1767                 }
1768
1769                 case SV_SCROLL_STAR_IDENTIFY:
1770                 {
1771                         if (!identify_fully(FALSE)) used_up = FALSE;
1772                         ident = TRUE;
1773                         break;
1774                 }
1775
1776                 case SV_SCROLL_REMOVE_CURSE:
1777                 {
1778                         if (remove_curse())
1779                         {
1780 #ifdef JP
1781                                 msg_print("狼¤Ë¸«¼é¤é¤ì¤Æ¤¤¤ë¤è¤¦¤Êµ¤¤¬¤¹¤ë¡£");
1782 #else
1783                                 msg_print("You feel as if someone is watching over you.");
1784 #endif
1785
1786                                 ident = TRUE;
1787                         }
1788                         break;
1789                 }
1790
1791                 case SV_SCROLL_STAR_REMOVE_CURSE:
1792                 {
1793                         if (remove_all_curse())
1794                         {
1795 #ifdef JP
1796                                 msg_print("狼¤Ë¸«¼é¤é¤ì¤Æ¤¤¤ë¤è¤¦¤Êµ¤¤¬¤¹¤ë¡£");
1797 #else
1798                                 msg_print("You feel as if someone is watching over you.");
1799 #endif
1800                         }
1801                         ident = TRUE;
1802                         break;
1803                 }
1804
1805                 case SV_SCROLL_ENCHANT_ARMOR:
1806                 {
1807                         ident = TRUE;
1808                         if (!enchant_spell(0, 0, 1)) used_up = FALSE;
1809                         break;
1810                 }
1811
1812                 case SV_SCROLL_ENCHANT_WEAPON_TO_HIT:
1813                 {
1814                         if (!enchant_spell(1, 0, 0)) used_up = FALSE;
1815                         ident = TRUE;
1816                         break;
1817                 }
1818
1819                 case SV_SCROLL_ENCHANT_WEAPON_TO_DAM:
1820                 {
1821                         if (!enchant_spell(0, 1, 0)) used_up = FALSE;
1822                         ident = TRUE;
1823                         break;
1824                 }
1825
1826                 case SV_SCROLL_STAR_ENCHANT_ARMOR:
1827                 {
1828                         if (!enchant_spell(0, 0, randint1(3) + 2)) used_up = FALSE;
1829                         ident = TRUE;
1830                         break;
1831                 }
1832
1833                 case SV_SCROLL_STAR_ENCHANT_WEAPON:
1834                 {
1835                         if (!enchant_spell(randint1(3), randint1(3), 0)) used_up = FALSE;
1836                         ident = TRUE;
1837                         break;
1838                 }
1839
1840                 case SV_SCROLL_RECHARGING:
1841                 {
1842                         if (!recharge(130)) used_up = FALSE;
1843                         ident = TRUE;
1844                         break;
1845                 }
1846
1847                 case SV_SCROLL_MUNDANITY:
1848                 {
1849                         ident = TRUE;
1850                         if (!mundane_spell(FALSE)) used_up = FALSE;
1851                         break;
1852                 }
1853
1854                 case SV_SCROLL_LIGHT:
1855                 {
1856                         if (lite_area(damroll(2, 8), 2)) ident = TRUE;
1857                         break;
1858                 }
1859
1860                 case SV_SCROLL_MAPPING:
1861                 {
1862                         map_area(DETECT_RAD_MAP);
1863                         ident = TRUE;
1864                         break;
1865                 }
1866
1867                 case SV_SCROLL_DETECT_GOLD:
1868                 {
1869                         if (detect_treasure(DETECT_RAD_DEFAULT)) ident = TRUE;
1870                         if (detect_objects_gold(DETECT_RAD_DEFAULT)) ident = TRUE;
1871                         break;
1872                 }
1873
1874                 case SV_SCROLL_DETECT_ITEM:
1875                 {
1876                         if (detect_objects_normal(DETECT_RAD_DEFAULT)) ident = TRUE;
1877                         break;
1878                 }
1879
1880                 case SV_SCROLL_DETECT_TRAP:
1881                 {
1882                         if (detect_traps(DETECT_RAD_DEFAULT, known)) ident = TRUE;
1883                         break;
1884                 }
1885
1886                 case SV_SCROLL_DETECT_DOOR:
1887                 {
1888                         if (detect_doors(DETECT_RAD_DEFAULT)) ident = TRUE;
1889                         if (detect_stairs(DETECT_RAD_DEFAULT)) ident = TRUE;
1890                         break;
1891                 }
1892
1893                 case SV_SCROLL_DETECT_INVIS:
1894                 {
1895                         if (detect_monsters_invis(DETECT_RAD_DEFAULT)) ident = TRUE;
1896                         break;
1897                 }
1898
1899                 case SV_SCROLL_SATISFY_HUNGER:
1900                 {
1901                         if (set_food(PY_FOOD_MAX - 1)) ident = TRUE;
1902                         break;
1903                 }
1904
1905                 case SV_SCROLL_BLESSING:
1906                 {
1907                         if (set_blessed(p_ptr->blessed + randint1(12) + 6, FALSE)) ident = TRUE;
1908                         break;
1909                 }
1910
1911                 case SV_SCROLL_HOLY_CHANT:
1912                 {
1913                         if (set_blessed(p_ptr->blessed + randint1(24) + 12, FALSE)) ident = TRUE;
1914                         break;
1915                 }
1916
1917                 case SV_SCROLL_HOLY_PRAYER:
1918                 {
1919                         if (set_blessed(p_ptr->blessed + randint1(48) + 24, FALSE)) ident = TRUE;
1920                         break;
1921                 }
1922
1923                 case SV_SCROLL_MONSTER_CONFUSION:
1924                 {
1925                         if (!(p_ptr->special_attack & ATTACK_CONFUSE))
1926                         {
1927 #ifdef JP
1928                                 msg_print("¼ê¤¬µ±¤­»Ï¤á¤¿¡£");
1929 #else
1930                                 msg_print("Your hands begin to glow.");
1931 #endif
1932
1933                                 p_ptr->special_attack |= ATTACK_CONFUSE;
1934                                 p_ptr->redraw |= (PR_STATUS);
1935                                 ident = TRUE;
1936                         }
1937                         break;
1938                 }
1939
1940                 case SV_SCROLL_PROTECTION_FROM_EVIL:
1941                 {
1942                         k = 3 * p_ptr->lev;
1943                         if (set_protevil(p_ptr->protevil + randint1(25) + k, FALSE)) ident = TRUE;
1944                         break;
1945                 }
1946
1947                 case SV_SCROLL_RUNE_OF_PROTECTION:
1948                 {
1949                         warding_glyph();
1950                         ident = TRUE;
1951                         break;
1952                 }
1953
1954                 case SV_SCROLL_TRAP_DOOR_DESTRUCTION:
1955                 {
1956                         if (destroy_doors_touch()) ident = TRUE;
1957                         break;
1958                 }
1959
1960                 case SV_SCROLL_STAR_DESTRUCTION:
1961                 {
1962                         if (destroy_area(py, px, 13 + randint0(5), FALSE))
1963                                 ident = TRUE;
1964                         else
1965 #ifdef JP
1966 msg_print("¥À¥ó¥¸¥ç¥ó¤¬Íɤ줿...");
1967 #else
1968                                 msg_print("The dungeon trembles...");
1969 #endif
1970
1971
1972                         break;
1973                 }
1974
1975                 case SV_SCROLL_DISPEL_UNDEAD:
1976                 {
1977                         if (dispel_undead(80)) ident = TRUE;
1978                         break;
1979                 }
1980
1981                 case SV_SCROLL_SPELL:
1982                 {
1983                         if ((p_ptr->pclass == CLASS_WARRIOR) ||
1984                                 (p_ptr->pclass == CLASS_IMITATOR) ||
1985                                 (p_ptr->pclass == CLASS_MINDCRAFTER) ||
1986                                 (p_ptr->pclass == CLASS_SORCERER) ||
1987                                 (p_ptr->pclass == CLASS_ARCHER) ||
1988                                 (p_ptr->pclass == CLASS_MAGIC_EATER) ||
1989                                 (p_ptr->pclass == CLASS_RED_MAGE) ||
1990                                 (p_ptr->pclass == CLASS_SAMURAI) ||
1991                                 (p_ptr->pclass == CLASS_BLUE_MAGE) ||
1992                                 (p_ptr->pclass == CLASS_CAVALRY) ||
1993                                 (p_ptr->pclass == CLASS_BERSERKER) ||
1994                                 (p_ptr->pclass == CLASS_SMITH) ||
1995                                 (p_ptr->pclass == CLASS_MIRROR_MASTER) ||
1996                                 (p_ptr->pclass == CLASS_NINJA) ||
1997                                 (p_ptr->pclass == CLASS_SNIPER)) break;
1998                         p_ptr->add_spells++;
1999                         p_ptr->update |= (PU_SPELLS);
2000                         ident = TRUE;
2001                         break;
2002                 }
2003
2004                 case SV_SCROLL_GENOCIDE:
2005                 {
2006                         (void)symbol_genocide(300, TRUE);
2007                         ident = TRUE;
2008                         break;
2009                 }
2010
2011                 case SV_SCROLL_MASS_GENOCIDE:
2012                 {
2013                         (void)mass_genocide(300, TRUE);
2014                         ident = TRUE;
2015                         break;
2016                 }
2017
2018                 case SV_SCROLL_ACQUIREMENT:
2019                 {
2020                         acquirement(py, px, 1, TRUE, FALSE);
2021                         ident = TRUE;
2022                         break;
2023                 }
2024
2025                 case SV_SCROLL_STAR_ACQUIREMENT:
2026                 {
2027                         acquirement(py, px, randint1(2) + 1, TRUE, FALSE);
2028                         ident = TRUE;
2029                         break;
2030                 }
2031
2032                 /* New Hengband scrolls */
2033                 case SV_SCROLL_FIRE:
2034                 {
2035                         fire_ball(GF_FIRE, 0, 666, 4);
2036                         /* Note: "Double" damage since it is centered on the player ... */
2037                         if (!(IS_OPPOSE_FIRE() || p_ptr->resist_fire || p_ptr->immune_fire))
2038 #ifdef JP
2039 take_hit(DAMAGE_NOESCAPE, 50+randint1(50), "±ê¤Î´¬Êª", -1);
2040 #else
2041                                 take_hit(DAMAGE_NOESCAPE, 50 + randint1(50), "a Scroll of Fire", -1);
2042 #endif
2043
2044                         ident = TRUE;
2045                         break;
2046                 }
2047
2048
2049                 case SV_SCROLL_ICE:
2050                 {
2051                         fire_ball(GF_ICE, 0, 777, 4);
2052                         if (!(IS_OPPOSE_COLD() || p_ptr->resist_cold || p_ptr->immune_cold))
2053 #ifdef JP
2054 take_hit(DAMAGE_NOESCAPE, 100+randint1(100), "ɹ¤Î´¬Êª", -1);
2055 #else
2056                                 take_hit(DAMAGE_NOESCAPE, 100 + randint1(100), "a Scroll of Ice", -1);
2057 #endif
2058
2059                         ident = TRUE;
2060                         break;
2061                 }
2062
2063                 case SV_SCROLL_CHAOS:
2064                 {
2065                         fire_ball(GF_CHAOS, 0, 1000, 4);
2066                         if (!p_ptr->resist_chaos)
2067 #ifdef JP
2068 take_hit(DAMAGE_NOESCAPE, 111+randint1(111), "¥í¥°¥ë¥¹¤Î´¬Êª", -1);
2069 #else
2070                                 take_hit(DAMAGE_NOESCAPE, 111 + randint1(111), "a Scroll of Logrus", -1);
2071 #endif
2072
2073                         ident = TRUE;
2074                         break;
2075                 }
2076
2077                 case SV_SCROLL_RUMOR:
2078                 {
2079 #ifdef JP
2080                         msg_print("´¬Êª¤Ë¤Ï¥á¥Ã¥»¡¼¥¸¤¬½ñ¤«¤ì¤Æ¤¤¤ë:");
2081 #else
2082                         msg_print("There is message on the scroll. It says:");
2083 #endif
2084
2085                         msg_print(NULL);
2086                         display_rumor(TRUE);
2087                         msg_print(NULL);
2088 #ifdef JP
2089                         msg_print("´¬Êª¤Ï±ì¤òΩ¤Æ¤Æ¾Ã¤¨µî¤Ã¤¿¡ª");
2090 #else
2091                         msg_print("The scroll disappears in a puff of smoke!");
2092 #endif
2093
2094                         ident = TRUE;
2095                         break;
2096                 }
2097
2098                 case SV_SCROLL_ARTIFACT:
2099                 {
2100                         ident = TRUE;
2101                         if (!artifact_scroll()) used_up = FALSE;
2102                         break;
2103                 }
2104
2105                 case SV_SCROLL_RESET_RECALL:
2106                 {
2107                         ident = TRUE;
2108                         if (!reset_recall()) used_up = FALSE;
2109                         break;
2110                 }
2111
2112                 case SV_SCROLL_AMUSEMENT:
2113                 {
2114                         ident = TRUE;
2115                         amusement(py, px, 1, FALSE);
2116                         break;
2117                 }
2118         }
2119         }
2120         else if (o_ptr->name1 == ART_GHB)
2121         {
2122 #ifdef JP
2123                 msg_print("»ä¤Ï¶ìÏ«¤·¤Æ¡Ø¥°¥ì¡¼¥¿¡¼¡¦¥Ø¥ë=¥Ó¡¼¥¹¥È¡Ù¤òÅݤ·¤¿¡£");
2124                 msg_print("¤·¤«¤·¼ê¤ËÆþ¤Ã¤¿¤Î¤Ï¤³¤Î¤­¤¿¤Ê¤¤£Ô¥·¥ã¥Ä¤À¤±¤À¤Ã¤¿¡£");
2125 #else
2126                 msg_print("I had a very hard time to kill the Greater hell-beast, ");
2127                 msg_print("but all I got was this lousy t-shirt!");
2128 #endif
2129                 used_up = FALSE;
2130         }
2131         else if (o_ptr->name1 == ART_POWER)
2132         {
2133 #ifdef JP
2134                 msg_print("¡Ö°ì¤Ä¤Î»ØÎؤÏÁ´¤Æ¤òÅý¤Ù¡¢");
2135                 msg_print(NULL);
2136                 msg_print("°ì¤Ä¤Î»ØÎؤÏÁ´¤Æ¤ò¸«¤Ä¤±¡¢");
2137                 msg_print(NULL);
2138                 msg_print("°ì¤Ä¤Î»ØÎؤÏÁ´¤Æ¤òÊá¤é¤¨¤Æ");
2139                 msg_print(NULL);
2140                 msg_print("°Å°Ç¤ÎÃæ¤Ë·Ò¤®¤È¤á¤ë¡£¡×");
2141 #else
2142                 msg_print("'One Ring to rule them all, ");
2143                 msg_print(NULL);
2144                 msg_print("One Ring to find them, ");
2145                 msg_print(NULL);
2146                 msg_print("One Ring to bring them all ");
2147                 msg_print(NULL);
2148                 msg_print("and in the darkness bind them.'");
2149 #endif
2150                 used_up = FALSE;
2151         }
2152         else if (o_ptr->tval==TV_PARCHMENT)
2153         {
2154                 cptr q;
2155                 char o_name[MAX_NLEN];
2156                 char buf[1024];
2157
2158                 /* Save screen */
2159                 screen_save();
2160
2161                 q=format("book-%d_jp.txt",o_ptr->sval);
2162
2163                 /* Display object description */
2164                 object_desc(o_name, o_ptr, OD_NAME_ONLY);
2165
2166                 /* Build the filename */
2167                 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, q);
2168
2169                 /* Peruse the help file */
2170                 (void)show_file(TRUE, buf, o_name, 0, 0);
2171
2172                 /* Load screen */
2173                 screen_load();
2174
2175                 used_up=FALSE;
2176         }
2177
2178
2179         /* Combine / Reorder the pack (later) */
2180         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
2181
2182         if (!(object_is_aware(o_ptr)))
2183         {
2184                 chg_virtue(V_PATIENCE, -1);
2185                 chg_virtue(V_CHANCE, 1);
2186                 chg_virtue(V_KNOWLEDGE, -1);
2187         }
2188
2189         /* The item was tried */
2190         object_tried(o_ptr);
2191
2192         /* An identification was made */
2193         if (ident && !object_is_aware(o_ptr))
2194         {
2195                 object_aware(o_ptr);
2196                 gain_exp((lev + (p_ptr->lev >> 1)) / p_ptr->lev);
2197         }
2198
2199         /* Window stuff */
2200         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
2201
2202
2203         /* Hack -- allow certain scrolls to be "preserved" */
2204         if (!used_up)
2205         {
2206                 return;
2207         }
2208
2209         sound(SOUND_SCROLL);
2210
2211         /* Destroy a scroll in the pack */
2212         if (item >= 0)
2213         {
2214                 inven_item_increase(item, -1);
2215                 inven_item_describe(item);
2216                 inven_item_optimize(item);
2217         }
2218
2219         /* Destroy a scroll on the floor */
2220         else
2221         {
2222                 floor_item_increase(0 - item, -1);
2223                 floor_item_describe(0 - item);
2224                 floor_item_optimize(0 - item);
2225         }
2226 }
2227
2228
2229 /*
2230  * Hook to determine if an object is readable
2231  */
2232 static bool item_tester_hook_readable(object_type *o_ptr)
2233 {
2234         if ((o_ptr->tval==TV_SCROLL) || (o_ptr->tval==TV_PARCHMENT) || (o_ptr->name1 == ART_GHB) || (o_ptr->name1 == ART_POWER)) return (TRUE);
2235
2236         /* Assume not */
2237         return (FALSE);
2238 }
2239
2240
2241 void do_cmd_read_scroll(void)
2242 {
2243         object_type *o_ptr;
2244         int  item;
2245         cptr q, s;
2246
2247         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
2248         {
2249                 set_action(ACTION_NONE);
2250         }
2251
2252         /* Check some conditions */
2253         if (p_ptr->blind)
2254         {
2255 #ifdef JP
2256                 msg_print("Ìܤ¬¸«¤¨¤Ê¤¤¡£");
2257 #else
2258                 msg_print("You can't see anything.");
2259 #endif
2260
2261                 return;
2262         }
2263         if (no_lite())
2264         {
2265 #ifdef JP
2266                 msg_print("ÌÀ¤«¤ê¤¬¤Ê¤¤¤Î¤Ç¡¢°Å¤¯¤ÆÆɤá¤Ê¤¤¡£");
2267 #else
2268                 msg_print("You have no light to read by.");
2269 #endif
2270
2271                 return;
2272         }
2273         if (p_ptr->confused)
2274         {
2275 #ifdef JP
2276                 msg_print("º®Í𤷤Ƥ¤¤ÆÆɤá¤Ê¤¤¡£");
2277 #else
2278                 msg_print("You are too confused!");
2279 #endif
2280
2281                 return;
2282         }
2283
2284
2285         /* Restrict choices to scrolls */
2286         item_tester_hook = item_tester_hook_readable;
2287
2288         /* Get an item */
2289 #ifdef JP
2290         q = "¤É¤Î´¬Êª¤òÆɤߤޤ¹¤«? ";
2291         s = "Æɤá¤ë´¬Êª¤¬¤Ê¤¤¡£";
2292 #else
2293         q = "Read which scroll? ";
2294         s = "You have no scrolls to read.";
2295 #endif
2296
2297         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
2298
2299         /* Get the item (in the pack) */
2300         if (item >= 0)
2301         {
2302                 o_ptr = &inventory[item];
2303         }
2304
2305         /* Get the item (on the floor) */
2306         else
2307         {
2308                 o_ptr = &o_list[0 - item];
2309         }
2310
2311         /* Read the scroll */
2312         do_cmd_read_scroll_aux(item, object_is_aware(o_ptr));
2313 }
2314
2315
2316 static int staff_effect(int sval, bool *use_charge, bool powerful, bool magic, bool known)
2317 {
2318         int k;
2319         int ident = FALSE;
2320         int lev = powerful ? p_ptr->lev * 2 : p_ptr->lev;
2321         int detect_rad = powerful ? DETECT_RAD_DEFAULT * 3 / 2 : DETECT_RAD_DEFAULT;
2322
2323         /* Analyze the staff */
2324         switch (sval)
2325         {
2326                 case SV_STAFF_DARKNESS:
2327                 {
2328                         if (!(p_ptr->resist_blind) && !(p_ptr->resist_dark))
2329                         {
2330                                 if (set_blind(p_ptr->blind + 3 + randint1(5))) ident = TRUE;
2331                         }
2332                         if (unlite_area(10, (powerful ? 6 : 3))) ident = TRUE;
2333                         break;
2334                 }
2335
2336                 case SV_STAFF_SLOWNESS:
2337                 {
2338                         if (set_slow(p_ptr->slow + randint1(30) + 15, FALSE)) ident = TRUE;
2339                         break;
2340                 }
2341
2342                 case SV_STAFF_HASTE_MONSTERS:
2343                 {
2344                         if (speed_monsters()) ident = TRUE;
2345                         break;
2346                 }
2347
2348                 case SV_STAFF_SUMMONING:
2349                 {
2350                         const int times = randint1(powerful ? 8 : 4);
2351                         for (k = 0; k < times; k++)
2352                         {
2353                                 if (summon_specific(0, py, px, dun_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
2354                                 {
2355                                         ident = TRUE;
2356                                 }
2357                         }
2358                         break;
2359                 }
2360
2361                 case SV_STAFF_TELEPORTATION:
2362                 {
2363                         teleport_player((powerful ? 150 : 100), 0L);
2364                         ident = TRUE;
2365                         break;
2366                 }
2367
2368                 case SV_STAFF_IDENTIFY:
2369                 {
2370                         if (powerful) {
2371                                 if (!identify_fully(FALSE)) *use_charge = FALSE;
2372                         } else {
2373                                 if (!ident_spell(FALSE)) *use_charge = FALSE;
2374                         }
2375                         ident = TRUE;
2376                         break;
2377                 }
2378
2379                 case SV_STAFF_REMOVE_CURSE:
2380                 {
2381                         bool result = powerful ? remove_all_curse() : remove_curse();
2382                         if (result)
2383                         {
2384                                 if (magic)
2385                                 {
2386 #ifdef JP
2387                                         msg_print("狼¤Ë¸«¼é¤é¤ì¤Æ¤¤¤ë¤è¤¦¤Êµ¤¤¬¤¹¤ë¡£");
2388 #else
2389                                         msg_print("You feel as if someone is watching over you.");
2390 #endif
2391                                 }
2392                                 else if (!p_ptr->blind)
2393                                 {
2394 #ifdef JP
2395                                         msg_print("¾ó¤Ï°ì½Ö¥Ö¥ë¡¼¤Ëµ±¤¤¤¿...");
2396 #else
2397                                         msg_print("The staff glows blue for a moment...");
2398 #endif
2399
2400                                 }
2401                                 ident = TRUE;
2402                         }
2403                         break;
2404                 }
2405
2406                 case SV_STAFF_STARLITE:
2407                 {
2408                         int num = damroll(5, 3);
2409                         int y, x;
2410                         int attempts;
2411
2412                         if (!p_ptr->blind && !magic)
2413                         {
2414 #ifdef JP
2415                                 msg_print("¾ó¤ÎÀ褬ÌÀ¤ë¤¯µ±¤¤¤¿...");
2416 #else
2417                                 msg_print("The end of the staff glows brightly...");
2418 #endif
2419
2420                         }
2421                         for (k = 0; k < num; k++)
2422                         {
2423                                 attempts = 1000;
2424
2425                                 while (attempts--)
2426                                 {
2427                                         scatter(&y, &x, py, px, 4, 0);
2428
2429                                         if (!cave_have_flag_bold(y, x, FF_PROJECT)) continue;
2430
2431                                         if (!player_bold(y, x)) break;
2432                                 }
2433
2434                                 project(0, 0, y, x, damroll(6 + lev / 8, 10), GF_LITE_WEAK,
2435                                                   (PROJECT_BEAM | PROJECT_THRU | PROJECT_GRID | PROJECT_KILL), -1);
2436                         }
2437                         ident = TRUE;
2438                         break;
2439                 }
2440
2441                 case SV_STAFF_LITE:
2442                 {
2443                         if (lite_area(damroll(2, 8), (powerful ? 4 : 2))) ident = TRUE;
2444                         break;
2445                 }
2446
2447                 case SV_STAFF_MAPPING:
2448                 {
2449                         map_area(powerful ? DETECT_RAD_MAP * 3 / 2 : DETECT_RAD_MAP);
2450                         ident = TRUE;
2451                         break;
2452                 }
2453
2454                 case SV_STAFF_DETECT_GOLD:
2455                 {
2456                         if (detect_treasure(detect_rad)) ident = TRUE;
2457                         if (detect_objects_gold(detect_rad)) ident = TRUE;
2458                         break;
2459                 }
2460
2461                 case SV_STAFF_DETECT_ITEM:
2462                 {
2463                         if (detect_objects_normal(detect_rad)) ident = TRUE;
2464                         break;
2465                 }
2466
2467                 case SV_STAFF_DETECT_TRAP:
2468                 {
2469                         if (detect_traps(detect_rad, known)) ident = TRUE;
2470                         break;
2471                 }
2472
2473                 case SV_STAFF_DETECT_DOOR:
2474                 {
2475                         if (detect_doors(detect_rad)) ident = TRUE;
2476                         if (detect_stairs(detect_rad)) ident = TRUE;
2477                         break;
2478                 }
2479
2480                 case SV_STAFF_DETECT_INVIS:
2481                 {
2482                         if (detect_monsters_invis(detect_rad)) ident = TRUE;
2483                         break;
2484                 }
2485
2486                 case SV_STAFF_DETECT_EVIL:
2487                 {
2488                         if (detect_monsters_evil(detect_rad)) ident = TRUE;
2489                         break;
2490                 }
2491
2492                 case SV_STAFF_CURE_LIGHT:
2493                 {
2494                         if (hp_player(damroll((powerful ? 4 : 2), 8))) ident = TRUE;
2495                         if (powerful) {
2496                                 if (set_blind(0)) ident = TRUE;
2497                                 if (set_poisoned(0)) ident = TRUE;
2498                                 if (set_cut(p_ptr->cut - 10)) ident = TRUE;
2499                         }
2500                         if (set_shero(0,TRUE)) ident = TRUE;
2501                         break;
2502                 }
2503
2504                 case SV_STAFF_CURING:
2505                 {
2506                         if (set_blind(0)) ident = TRUE;
2507                         if (set_poisoned(0)) ident = TRUE;
2508                         if (set_confused(0)) ident = TRUE;
2509                         if (set_stun(0)) ident = TRUE;
2510                         if (set_cut(0)) ident = TRUE;
2511                         if (set_image(0)) ident = TRUE;
2512                         if (set_shero(0,TRUE)) ident = TRUE;
2513                         break;
2514                 }
2515
2516                 case SV_STAFF_HEALING:
2517                 {
2518                         if (hp_player(powerful ? 500 : 300)) ident = TRUE;
2519                         if (set_stun(0)) ident = TRUE;
2520                         if (set_cut(0)) ident = TRUE;
2521                         if (set_shero(0,TRUE)) ident = TRUE;
2522                         break;
2523                 }
2524
2525                 case SV_STAFF_THE_MAGI:
2526                 {
2527                         if (do_res_stat(A_INT)) ident = TRUE;
2528                         if (p_ptr->csp < p_ptr->msp)
2529                         {
2530                                 p_ptr->csp = p_ptr->msp;
2531                                 p_ptr->csp_frac = 0;
2532                                 ident = TRUE;
2533 #ifdef JP
2534                                 msg_print("Ƭ¤¬¥Ï¥Ã¥­¥ê¤È¤·¤¿¡£");
2535 #else
2536                                 msg_print("You feel your head clear.");
2537 #endif
2538
2539                                 p_ptr->redraw |= (PR_MANA);
2540                                 p_ptr->window |= (PW_PLAYER);
2541                                 p_ptr->window |= (PW_SPELL);
2542                         }
2543                         if (set_shero(0,TRUE)) ident = TRUE;
2544                         break;
2545                 }
2546
2547                 case SV_STAFF_SLEEP_MONSTERS:
2548                 {
2549                         if (sleep_monsters(lev)) ident = TRUE;
2550                         break;
2551                 }
2552
2553                 case SV_STAFF_SLOW_MONSTERS:
2554                 {
2555                         if (slow_monsters(lev)) ident = TRUE;
2556                         break;
2557                 }
2558
2559                 case SV_STAFF_SPEED:
2560                 {
2561                         if (set_fast(randint1(30) + (powerful ? 30 : 15), FALSE)) ident = TRUE;
2562                         break;
2563                 }
2564
2565                 case SV_STAFF_PROBING:
2566                 {
2567                         probing();
2568                         ident = TRUE;
2569                         break;
2570                 }
2571
2572                 case SV_STAFF_DISPEL_EVIL:
2573                 {
2574                         if (dispel_evil(powerful ? 120 : 80)) ident = TRUE;
2575                         break;
2576                 }
2577
2578                 case SV_STAFF_POWER:
2579                 {
2580                         if (dispel_monsters(powerful ? 225 : 150)) ident = TRUE;
2581                         break;
2582                 }
2583
2584                 case SV_STAFF_HOLINESS:
2585                 {
2586                         if (dispel_evil(powerful ? 225 : 150)) ident = TRUE;
2587                         k = 3 * lev;
2588                         if (set_protevil((magic ? 0 : p_ptr->protevil) + randint1(25) + k, FALSE)) ident = TRUE;
2589                         if (set_poisoned(0)) ident = TRUE;
2590                         if (set_afraid(0)) ident = TRUE;
2591                         if (hp_player(50)) ident = TRUE;
2592                         if (set_stun(0)) ident = TRUE;
2593                         if (set_cut(0)) ident = TRUE;
2594                         break;
2595                 }
2596
2597                 case SV_STAFF_GENOCIDE:
2598                 {
2599                         (void)symbol_genocide((magic ? lev + 50 : 200), TRUE);
2600                         ident = TRUE;
2601                         break;
2602                 }
2603
2604                 case SV_STAFF_EARTHQUAKES:
2605                 {
2606                         if (earthquake(py, px, (powerful ? 15 : 10)))
2607                                 ident = TRUE;
2608                         else
2609 #ifdef JP
2610 msg_print("¥À¥ó¥¸¥ç¥ó¤¬Íɤ줿¡£");
2611 #else
2612                                 msg_print("The dungeon trembles.");
2613 #endif
2614
2615
2616                         break;
2617                 }
2618
2619                 case SV_STAFF_DESTRUCTION:
2620                 {
2621                         if (destroy_area(py, px, (powerful ? 18 : 13) + randint0(5), FALSE))
2622                                 ident = TRUE;
2623
2624                         break;
2625                 }
2626
2627                 case SV_STAFF_ANIMATE_DEAD:
2628                 {
2629                         if (animate_dead(0, py, px))
2630                                 ident = TRUE;
2631
2632                         break;
2633                 }
2634
2635                 case SV_STAFF_MSTORM:
2636                 {
2637 #ifdef JP
2638                         msg_print("¶¯ÎϤÊËâÎϤ¬Å¨¤ò°ú¤­Îö¤¤¤¿¡ª");
2639 #else
2640                         msg_print("Mighty magics rend your enemies!");
2641 #endif
2642                         project(0, (powerful ? 7 : 5), py, px,
2643                                 (randint1(200) + (powerful ? 500 : 300)) * 2, GF_MANA, PROJECT_KILL | PROJECT_ITEM | PROJECT_GRID, -1);
2644                         if ((p_ptr->pclass != CLASS_MAGE) && (p_ptr->pclass != CLASS_HIGH_MAGE) && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_MAGIC_EATER) && (p_ptr->pclass != CLASS_BLUE_MAGE))
2645                         {
2646 #ifdef JP
2647                                 (void)take_hit(DAMAGE_NOESCAPE, 50, "¥³¥ó¥È¥í¡¼¥ë¤·Æñ¤¤¶¯ÎϤÊËâÎϤβòÊü", -1);
2648 #else
2649                                 (void)take_hit(DAMAGE_NOESCAPE, 50, "unleashing magics too mighty to control", -1);
2650 #endif
2651                         }
2652                         ident = TRUE;
2653
2654                         break;
2655                 }
2656
2657                 case SV_STAFF_NOTHING:
2658                 {
2659 #ifdef JP
2660                         msg_print("²¿¤âµ¯¤é¤Ê¤«¤Ã¤¿¡£");
2661 #else
2662                         msg_print("Nothing happen.");
2663 #endif
2664                         if (prace_is_(RACE_SKELETON) || prace_is_(RACE_GOLEM) ||
2665                                 prace_is_(RACE_ZOMBIE) || prace_is_(RACE_SPECTRE))
2666 #ifdef JP
2667                                 msg_print("¤â¤Ã¤¿¤¤¤Ê¤¤»ö¤ò¤·¤¿¤è¤¦¤Êµ¤¤¬¤¹¤ë¡£¿©¤Ùʪ¤ÏÂçÀڤˤ·¤Ê¤¯¤Æ¤Ï¡£");
2668 #else
2669                                 msg_print("What a waste.  It's your food!");
2670 #endif
2671                         break;
2672                 }
2673         }
2674         return ident;
2675 }
2676
2677 /*
2678  * Use a staff.                 -RAK-
2679  *
2680  * One charge of one staff disappears.
2681  *
2682  * Hack -- staffs of identify can be "cancelled".
2683  */
2684 static void do_cmd_use_staff_aux(int item)
2685 {
2686         int         ident, chance, lev;
2687         object_type *o_ptr;
2688
2689
2690         /* Hack -- let staffs of identify get aborted */
2691         bool use_charge = TRUE;
2692
2693
2694         /* Get the item (in the pack) */
2695         if (item >= 0)
2696         {
2697                 o_ptr = &inventory[item];
2698         }
2699
2700         /* Get the item (on the floor) */
2701         else
2702         {
2703                 o_ptr = &o_list[0 - item];
2704         }
2705
2706
2707         /* Mega-Hack -- refuse to use a pile from the ground */
2708         if ((item < 0) && (o_ptr->number > 1))
2709         {
2710 #ifdef JP
2711                 msg_print("¤Þ¤º¤Ï¾ó¤ò½¦¤ï¤Ê¤±¤ì¤Ð¡£");
2712 #else
2713                 msg_print("You must first pick up the staffs.");
2714 #endif
2715
2716                 return;
2717         }
2718
2719
2720         /* Take a turn */
2721         energy_use = 100;
2722
2723         /* Extract the item level */
2724         lev = k_info[o_ptr->k_idx].level;
2725         if (lev > 50) lev = 50 + (lev - 50)/2;
2726
2727         /* Base chance of success */
2728         chance = p_ptr->skill_dev;
2729
2730         /* Confusion hurts skill */
2731         if (p_ptr->confused) chance = chance / 2;
2732
2733         /* Hight level objects are harder */
2734         chance = chance - lev;
2735
2736         /* Give everyone a (slight) chance */
2737         if ((chance < USE_DEVICE) && one_in_(USE_DEVICE - chance + 1))
2738         {
2739                 chance = USE_DEVICE;
2740         }
2741
2742         if (world_player)
2743         {
2744                 if (flush_failure) flush();
2745 #ifdef JP
2746                 msg_print("»ß¤Þ¤Ã¤¿»þ¤ÎÃæ¤Ç¤Ï¤¦¤Þ¤¯Æ¯¤«¤Ê¤¤¤è¤¦¤À¡£");
2747 #else
2748                 msg_print("Nothing happen. Maybe this staff is freezing too.");
2749 #endif
2750
2751                 sound(SOUND_FAIL);
2752                 return;
2753         }
2754
2755         /* Roll for usage */
2756         if ((chance < USE_DEVICE) || (randint1(chance) < USE_DEVICE) || (p_ptr->pclass == CLASS_BERSERKER))
2757         {
2758                 if (flush_failure) flush();
2759 #ifdef JP
2760                 msg_print("¾ó¤ò¤¦¤Þ¤¯»È¤¨¤Ê¤«¤Ã¤¿¡£");
2761 #else
2762                 msg_print("You failed to use the staff properly.");
2763 #endif
2764
2765                 sound(SOUND_FAIL);
2766                 return;
2767         }
2768
2769         /* Notice empty staffs */
2770         if (o_ptr->pval <= 0)
2771         {
2772                 if (flush_failure) flush();
2773 #ifdef JP
2774                 msg_print("¤³¤Î¾ó¤Ë¤Ï¤â¤¦ËâÎϤ¬»Ä¤Ã¤Æ¤¤¤Ê¤¤¡£");
2775 #else
2776                 msg_print("The staff has no charges left.");
2777 #endif
2778
2779                 o_ptr->ident |= (IDENT_EMPTY);
2780
2781                 /* Combine / Reorder the pack (later) */
2782                 p_ptr->notice |= (PN_COMBINE | PN_REORDER);
2783                 p_ptr->window |= (PW_INVEN);
2784
2785                 return;
2786         }
2787
2788
2789         /* Sound */
2790         sound(SOUND_ZAP);
2791
2792         ident = staff_effect(o_ptr->sval, &use_charge, FALSE, FALSE, object_is_aware(o_ptr));
2793
2794         if (!(object_is_aware(o_ptr)))
2795         {
2796                 chg_virtue(V_PATIENCE, -1);
2797                 chg_virtue(V_CHANCE, 1);
2798                 chg_virtue(V_KNOWLEDGE, -1);
2799         }
2800
2801         /* Combine / Reorder the pack (later) */
2802         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
2803
2804         /* Tried the item */
2805         object_tried(o_ptr);
2806
2807         /* An identification was made */
2808         if (ident && !object_is_aware(o_ptr))
2809         {
2810                 object_aware(o_ptr);
2811                 gain_exp((lev + (p_ptr->lev >> 1)) / p_ptr->lev);
2812         }
2813
2814         /* Window stuff */
2815         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
2816
2817
2818         /* Hack -- some uses are "free" */
2819         if (!use_charge) return;
2820
2821
2822         /* Use a single charge */
2823         o_ptr->pval--;
2824
2825         /* XXX Hack -- unstack if necessary */
2826         if ((item >= 0) && (o_ptr->number > 1))
2827         {
2828                 object_type forge;
2829                 object_type *q_ptr;
2830
2831                 /* Get local object */
2832                 q_ptr = &forge;
2833
2834                 /* Obtain a local object */
2835                 object_copy(q_ptr, o_ptr);
2836
2837                 /* Modify quantity */
2838                 q_ptr->number = 1;
2839
2840                 /* Restore the charges */
2841                 o_ptr->pval++;
2842
2843                 /* Unstack the used item */
2844                 o_ptr->number--;
2845                 p_ptr->total_weight -= q_ptr->weight;
2846                 item = inven_carry(q_ptr);
2847
2848                 /* Message */
2849 #ifdef JP
2850                 msg_print("¾ó¤ò¤Þ¤È¤á¤Ê¤ª¤·¤¿¡£");
2851 #else
2852                 msg_print("You unstack your staff.");
2853 #endif
2854
2855         }
2856
2857         /* Describe charges in the pack */
2858         if (item >= 0)
2859         {
2860                 inven_item_charges(item);
2861         }
2862
2863         /* Describe charges on the floor */
2864         else
2865         {
2866                 floor_item_charges(0 - item);
2867         }
2868 }
2869
2870
2871 void do_cmd_use_staff(void)
2872 {
2873         int  item;
2874         cptr q, s;
2875
2876         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
2877         {
2878                 set_action(ACTION_NONE);
2879         }
2880
2881         /* Restrict choices to wands */
2882         item_tester_tval = TV_STAFF;
2883
2884         /* Get an item */
2885 #ifdef JP
2886         q = "¤É¤Î¾ó¤ò»È¤¤¤Þ¤¹¤«? ";
2887         s = "»È¤¨¤ë¾ó¤¬¤Ê¤¤¡£";
2888 #else
2889         q = "Use which staff? ";
2890         s = "You have no staff to use.";
2891 #endif
2892
2893         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
2894
2895         do_cmd_use_staff_aux(item);
2896 }
2897
2898
2899 static int wand_effect(int sval, int dir, bool powerful, bool magic)
2900 {
2901         int ident = FALSE;
2902         int lev = powerful ? p_ptr->lev * 2 : p_ptr->lev;
2903         int rad = powerful ? 3 : 2;
2904
2905         /* XXX Hack -- Wand of wonder can do anything before it */
2906         if (sval == SV_WAND_WONDER)
2907         {
2908                 int vir = virtue_number(V_CHANCE);
2909                 sval = randint0(SV_WAND_WONDER);
2910
2911                 if (vir)
2912                 {
2913                         if (p_ptr->virtues[vir - 1] > 0)
2914                         {
2915                                 while (randint1(300) < p_ptr->virtues[vir - 1]) sval++;
2916                                 if (sval > SV_WAND_COLD_BALL) sval = randint0(4) + SV_WAND_ACID_BALL;
2917                         }
2918                         else
2919                         {
2920                                 while (randint1(300) < (0-p_ptr->virtues[vir - 1])) sval--;
2921                                 if (sval < SV_WAND_HEAL_MONSTER) sval = randint0(3) + SV_WAND_HEAL_MONSTER;
2922                         }
2923                 }
2924                 if (sval < SV_WAND_TELEPORT_AWAY)
2925                         chg_virtue(V_CHANCE, 1);
2926         }
2927
2928         /* Analyze the wand */
2929         switch (sval)
2930         {
2931                 case SV_WAND_HEAL_MONSTER:
2932                 {
2933                         int dam = damroll((powerful ? 20 : 10), 10);
2934                         if (heal_monster(dir, dam)) ident = TRUE;
2935                         break;
2936                 }
2937
2938                 case SV_WAND_HASTE_MONSTER:
2939                 {
2940                         if (speed_monster(dir, lev)) ident = TRUE;
2941                         break;
2942                 }
2943
2944                 case SV_WAND_CLONE_MONSTER:
2945                 {
2946                         if (clone_monster(dir)) ident = TRUE;
2947                         break;
2948                 }
2949
2950                 case SV_WAND_TELEPORT_AWAY:
2951                 {
2952                         int distance = MAX_SIGHT * (powerful ? 8 : 5);
2953                         if (teleport_monster(dir, distance)) ident = TRUE;
2954                         break;
2955                 }
2956
2957                 case SV_WAND_DISARMING:
2958                 {
2959                         if (disarm_trap(dir)) ident = TRUE;
2960                         if (powerful && disarm_traps_touch()) ident = TRUE;
2961                         break;
2962                 }
2963
2964                 case SV_WAND_TRAP_DOOR_DEST:
2965                 {
2966                         if (destroy_door(dir)) ident = TRUE;
2967                         if (powerful && destroy_doors_touch()) ident = TRUE;
2968                         break;
2969                 }
2970
2971                 case SV_WAND_STONE_TO_MUD:
2972                 {
2973                         int dam = powerful ? 40 + randint1(60) : 20 + randint1(30);
2974                         if (wall_to_mud(dir, dam)) ident = TRUE;
2975                         break;
2976                 }
2977
2978                 case SV_WAND_LITE:
2979                 {
2980                         int dam = damroll((powerful ? 12 : 6), 8);
2981 #ifdef JP
2982                         msg_print("ÀĤ¯µ±¤¯¸÷Àþ¤¬Êü¤¿¤ì¤¿¡£");
2983 #else
2984                         msg_print("A line of blue shimmering light appears.");
2985 #endif
2986
2987                         (void)lite_line(dir, dam);
2988                         ident = TRUE;
2989                         break;
2990                 }
2991
2992                 case SV_WAND_SLEEP_MONSTER:
2993                 {
2994                         if (sleep_monster(dir, lev)) ident = TRUE;
2995                         break;
2996                 }
2997
2998                 case SV_WAND_SLOW_MONSTER:
2999                 {
3000                         if (slow_monster(dir, lev)) ident = TRUE;
3001                         break;
3002                 }
3003
3004                 case SV_WAND_CONFUSE_MONSTER:
3005                 {
3006                         if (confuse_monster(dir, lev)) ident = TRUE;
3007                         break;
3008                 }
3009
3010                 case SV_WAND_FEAR_MONSTER:
3011                 {
3012                         if (fear_monster(dir, lev)) ident = TRUE;
3013                         break;
3014                 }
3015
3016                 case SV_WAND_DRAIN_LIFE:
3017                 {
3018                         if (drain_life(dir, 80 + lev)) ident = TRUE;
3019                         break;
3020                 }
3021
3022                 case SV_WAND_POLYMORPH:
3023                 {
3024                         if (poly_monster(dir, lev)) ident = TRUE;
3025                         break;
3026                 }
3027
3028                 case SV_WAND_STINKING_CLOUD:
3029                 {
3030                         fire_ball(GF_POIS, dir, 12 + lev / 4, rad);
3031                         ident = TRUE;
3032                         break;
3033                 }
3034
3035                 case SV_WAND_MAGIC_MISSILE:
3036                 {
3037                         fire_bolt_or_beam(20, GF_MISSILE, dir, damroll(2 + lev / 10, 6));
3038                         ident = TRUE;
3039                         break;
3040                 }
3041
3042                 case SV_WAND_ACID_BOLT:
3043                 {
3044                         fire_bolt_or_beam(20, GF_ACID, dir, damroll(6 + lev / 7, 8));
3045                         ident = TRUE;
3046                         break;
3047                 }
3048
3049                 case SV_WAND_CHARM_MONSTER:
3050                 {
3051                         if (charm_monster(dir, MAX(20, lev)))
3052                         ident = TRUE;
3053                         break;
3054                 }
3055
3056                 case SV_WAND_FIRE_BOLT:
3057                 {
3058                         fire_bolt_or_beam(20, GF_FIRE, dir, damroll(7 + lev / 6, 8));
3059                         ident = TRUE;
3060                         break;
3061                 }
3062
3063                 case SV_WAND_COLD_BOLT:
3064                 {
3065                         fire_bolt_or_beam(20, GF_COLD, dir, damroll(5 + lev / 8, 8));
3066                         ident = TRUE;
3067                         break;
3068                 }
3069
3070                 case SV_WAND_ACID_BALL:
3071                 {
3072                         fire_ball(GF_ACID, dir, 60 + 3 * lev / 4, rad);
3073                         ident = TRUE;
3074                         break;
3075                 }
3076
3077                 case SV_WAND_ELEC_BALL:
3078                 {
3079                         fire_ball(GF_ELEC, dir, 40 + 3 * lev / 4, rad);
3080                         ident = TRUE;
3081                         break;
3082                 }
3083
3084                 case SV_WAND_FIRE_BALL:
3085                 {
3086                         fire_ball(GF_FIRE, dir, 70 + 3 * lev / 4, rad);
3087                         ident = TRUE;
3088                         break;
3089                 }
3090
3091                 case SV_WAND_COLD_BALL:
3092                 {
3093                         fire_ball(GF_COLD, dir, 50 + 3 * lev / 4, rad);
3094                         ident = TRUE;
3095                         break;
3096                 }
3097
3098                 case SV_WAND_WONDER:
3099                 {
3100 #ifdef JP
3101                         msg_print("¤ª¤Ã¤È¡¢Ææ¤ÎËâË¡ËÀ¤ò»ÏÆ°¤µ¤»¤¿¡£");
3102 #else
3103                         msg_print("Oops.  Wand of wonder activated.");
3104 #endif
3105
3106                         break;
3107                 }
3108
3109                 case SV_WAND_DRAGON_FIRE:
3110                 {
3111                         fire_ball(GF_FIRE, dir, (powerful ? 300 : 200), -3);
3112                         ident = TRUE;
3113                         break;
3114                 }
3115
3116                 case SV_WAND_DRAGON_COLD:
3117                 {
3118                         fire_ball(GF_COLD, dir, (powerful ? 270 : 180), -3);
3119                         ident = TRUE;
3120                         break;
3121                 }
3122
3123                 case SV_WAND_DRAGON_BREATH:
3124                 {
3125                         int dam;
3126                         int typ;
3127
3128                         switch (randint1(5))
3129                         {
3130                                 case 1:
3131                                         dam = 240;
3132                                         typ = GF_ACID;
3133                                         break;
3134                                 case 2:
3135                                         dam = 210;
3136                                         typ = GF_ELEC;
3137                                         break;
3138                                 case 3:
3139                                         dam = 240;
3140                                         typ = GF_FIRE;
3141                                         break;
3142                                 case 4:
3143                                         dam = 210;
3144                                         typ = GF_COLD;
3145                                         break;
3146                                 default:
3147                                         dam = 180;
3148                                         typ = GF_POIS;
3149                                         break;
3150                         }
3151
3152                         if (powerful) dam = (dam * 3) / 2;
3153
3154                         fire_ball(typ, dir, dam, -3);
3155
3156                         ident = TRUE;
3157                         break;
3158                 }
3159
3160                 case SV_WAND_DISINTEGRATE:
3161                 {
3162                         fire_ball(GF_DISINTEGRATE, dir, 200 + randint1(lev * 2), rad);
3163                         ident = TRUE;
3164                         break;
3165                 }
3166
3167                 case SV_WAND_ROCKETS:
3168                 {
3169 #ifdef JP
3170 msg_print("¥í¥±¥Ã¥È¤òȯ¼Í¤·¤¿¡ª");
3171 #else
3172                         msg_print("You launch a rocket!");
3173 #endif
3174
3175                         fire_rocket(GF_ROCKET, dir, 250 + lev * 3, rad);
3176                         ident = TRUE;
3177                         break;
3178                 }
3179
3180                 case SV_WAND_STRIKING:
3181                 {
3182                         fire_bolt(GF_METEOR, dir, damroll(15 + lev / 3, 13));
3183                         ident = TRUE;
3184                         break;
3185                 }
3186
3187                 case SV_WAND_GENOCIDE:
3188                 {
3189                         fire_ball_hide(GF_GENOCIDE, dir, magic ? lev + 50 : 250, 0);
3190                         ident = TRUE;
3191                         break;
3192                 }
3193         }
3194         return ident;
3195 }
3196
3197
3198 /*
3199  * Aim a wand (from the pack or floor).
3200  *
3201  * Use a single charge from a single item.
3202  * Handle "unstacking" in a logical manner.
3203  *
3204  * For simplicity, you cannot use a stack of items from the
3205  * ground.  This would require too much nasty code.
3206  *
3207  * There are no wands which can "destroy" themselves, in the inventory
3208  * or on the ground, so we can ignore this possibility.  Note that this
3209  * required giving "wand of wonder" the ability to ignore destruction
3210  * by electric balls.
3211  *
3212  * All wands can be "cancelled" at the "Direction?" prompt for free.
3213  *
3214  * Note that the basic "bolt" wands do slightly less damage than the
3215  * basic "bolt" rods, but the basic "ball" wands do the same damage
3216  * as the basic "ball" rods.
3217  */
3218 static void do_cmd_aim_wand_aux(int item)
3219 {
3220         int         lev, ident, chance, dir;
3221         object_type *o_ptr;
3222         bool old_target_pet = target_pet;
3223
3224         /* Get the item (in the pack) */
3225         if (item >= 0)
3226         {
3227                 o_ptr = &inventory[item];
3228         }
3229
3230         /* Get the item (on the floor) */
3231         else
3232         {
3233                 o_ptr = &o_list[0 - item];
3234         }
3235
3236         /* Mega-Hack -- refuse to aim a pile from the ground */
3237         if ((item < 0) && (o_ptr->number > 1))
3238         {
3239 #ifdef JP
3240                 msg_print("¤Þ¤º¤ÏËâË¡ËÀ¤ò½¦¤ï¤Ê¤±¤ì¤Ð¡£");
3241 #else
3242                 msg_print("You must first pick up the wands.");
3243 #endif
3244
3245                 return;
3246         }
3247
3248
3249         /* Allow direction to be cancelled for free */
3250         if (object_is_aware(o_ptr) && (o_ptr->sval == SV_WAND_HEAL_MONSTER
3251                                       || o_ptr->sval == SV_WAND_HASTE_MONSTER))
3252                         target_pet = TRUE;
3253         if (!get_aim_dir(&dir))
3254         {
3255                 target_pet = old_target_pet;
3256                 return;
3257         }
3258         target_pet = old_target_pet;
3259
3260         /* Take a turn */
3261         energy_use = 100;
3262
3263         /* Get the level */
3264         lev = k_info[o_ptr->k_idx].level;
3265         if (lev > 50) lev = 50 + (lev - 50)/2;
3266
3267         /* Base chance of success */
3268         chance = p_ptr->skill_dev;
3269
3270         /* Confusion hurts skill */
3271         if (p_ptr->confused) chance = chance / 2;
3272
3273         /* Hight level objects are harder */
3274         chance = chance - lev;
3275
3276         /* Give everyone a (slight) chance */
3277         if ((chance < USE_DEVICE) && one_in_(USE_DEVICE - chance + 1))
3278         {
3279                 chance = USE_DEVICE;
3280         }
3281
3282         if (world_player)
3283         {
3284                 if (flush_failure) flush();
3285 #ifdef JP
3286                 msg_print("»ß¤Þ¤Ã¤¿»þ¤ÎÃæ¤Ç¤Ï¤¦¤Þ¤¯Æ¯¤«¤Ê¤¤¤è¤¦¤À¡£");
3287 #else
3288                 msg_print("Nothing happen. Maybe this wand is freezing too.");
3289 #endif
3290
3291                 sound(SOUND_FAIL);
3292                 return;
3293         }
3294
3295         /* Roll for usage */
3296         if ((chance < USE_DEVICE) || (randint1(chance) < USE_DEVICE) || (p_ptr->pclass == CLASS_BERSERKER))
3297         {
3298                 if (flush_failure) flush();
3299 #ifdef JP
3300                 msg_print("ËâË¡ËÀ¤ò¤¦¤Þ¤¯»È¤¨¤Ê¤«¤Ã¤¿¡£");
3301 #else
3302                 msg_print("You failed to use the wand properly.");
3303 #endif
3304
3305                 sound(SOUND_FAIL);
3306                 return;
3307         }
3308
3309         /* The wand is already empty! */
3310         if (o_ptr->pval <= 0)
3311         {
3312                 if (flush_failure) flush();
3313 #ifdef JP
3314                 msg_print("¤³¤ÎËâË¡ËÀ¤Ë¤Ï¤â¤¦ËâÎϤ¬»Ä¤Ã¤Æ¤¤¤Ê¤¤¡£");
3315 #else
3316                 msg_print("The wand has no charges left.");
3317 #endif
3318
3319                 o_ptr->ident |= (IDENT_EMPTY);
3320
3321                 /* Combine / Reorder the pack (later) */
3322                 p_ptr->notice |= (PN_COMBINE | PN_REORDER);
3323                 p_ptr->window |= (PW_INVEN);
3324
3325                 return;
3326         }
3327
3328         /* Sound */
3329         sound(SOUND_ZAP);
3330
3331         ident = wand_effect(o_ptr->sval, dir, FALSE, FALSE);
3332
3333         /* Combine / Reorder the pack (later) */
3334         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
3335
3336         if (!(object_is_aware(o_ptr)))
3337         {
3338                 chg_virtue(V_PATIENCE, -1);
3339                 chg_virtue(V_CHANCE, 1);
3340                 chg_virtue(V_KNOWLEDGE, -1);
3341         }
3342
3343         /* Mark it as tried */
3344         object_tried(o_ptr);
3345
3346         /* Apply identification */
3347         if (ident && !object_is_aware(o_ptr))
3348         {
3349                 object_aware(o_ptr);
3350                 gain_exp((lev + (p_ptr->lev >> 1)) / p_ptr->lev);
3351         }
3352
3353         /* Window stuff */
3354         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
3355
3356
3357         /* Use a single charge */
3358         o_ptr->pval--;
3359
3360         /* Describe the charges in the pack */
3361         if (item >= 0)
3362         {
3363                 inven_item_charges(item);
3364         }
3365
3366         /* Describe the charges on the floor */
3367         else
3368         {
3369                 floor_item_charges(0 - item);
3370         }
3371 }
3372
3373
3374 void do_cmd_aim_wand(void)
3375 {
3376         int     item;
3377         cptr    q, s;
3378
3379         /* Restrict choices to wands */
3380         item_tester_tval = TV_WAND;
3381
3382         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
3383         {
3384                 set_action(ACTION_NONE);
3385         }
3386
3387         /* Get an item */
3388 #ifdef JP
3389         q = "¤É¤ÎËâË¡ËÀ¤ÇÁÀ¤¤¤Þ¤¹¤«? ";
3390         s = "»È¤¨¤ëËâË¡ËÀ¤¬¤Ê¤¤¡£";
3391 #else
3392         q = "Aim which wand? ";
3393         s = "You have no wand to aim.";
3394 #endif
3395
3396         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
3397
3398         /* Aim the wand */
3399         do_cmd_aim_wand_aux(item);
3400 }
3401
3402
3403 static int rod_effect(int sval, int dir, bool *use_charge, bool powerful, bool magic)
3404 {
3405         int ident = FALSE;
3406         int lev = powerful ? p_ptr->lev * 2 : p_ptr->lev;
3407         int detect_rad = powerful ? DETECT_RAD_DEFAULT * 3 / 2 : DETECT_RAD_DEFAULT;
3408         int rad = powerful ? 3 : 2;
3409
3410         /* Unused */
3411         (void)magic;
3412
3413         /* Analyze the rod */
3414         switch (sval)
3415         {
3416                 case SV_ROD_DETECT_TRAP:
3417                 {
3418                         if (detect_traps(detect_rad, (bool)(dir ? FALSE : TRUE))) ident = TRUE;
3419                         break;
3420                 }
3421
3422                 case SV_ROD_DETECT_DOOR:
3423                 {
3424                         if (detect_doors(detect_rad)) ident = TRUE;
3425                         if (detect_stairs(detect_rad)) ident = TRUE;
3426                         break;
3427                 }
3428
3429                 case SV_ROD_IDENTIFY:
3430                 {
3431                         if (powerful) {
3432                                 if (!identify_fully(FALSE)) *use_charge = FALSE;
3433                         } else {
3434                                 if (!ident_spell(FALSE)) *use_charge = FALSE;
3435                         }
3436                         ident = TRUE;
3437                         break;
3438                 }
3439
3440                 case SV_ROD_RECALL:
3441                 {
3442                         if (!word_of_recall()) *use_charge = FALSE;
3443                         ident = TRUE;
3444                         break;
3445                 }
3446
3447                 case SV_ROD_ILLUMINATION:
3448                 {
3449                         if (lite_area(damroll(2, 8), (powerful ? 4 : 2))) ident = TRUE;
3450                         break;
3451                 }
3452
3453                 case SV_ROD_MAPPING:
3454                 {
3455                         map_area(powerful ? DETECT_RAD_MAP * 3 / 2 : DETECT_RAD_MAP);
3456                         ident = TRUE;
3457                         break;
3458                 }
3459
3460                 case SV_ROD_DETECTION:
3461                 {
3462                         detect_all(detect_rad);
3463                         ident = TRUE;
3464                         break;
3465                 }
3466
3467                 case SV_ROD_PROBING:
3468                 {
3469                         probing();
3470                         ident = TRUE;
3471                         break;
3472                 }
3473
3474                 case SV_ROD_CURING:
3475                 {
3476                         if (set_blind(0)) ident = TRUE;
3477                         if (set_poisoned(0)) ident = TRUE;
3478                         if (set_confused(0)) ident = TRUE;
3479                         if (set_stun(0)) ident = TRUE;
3480                         if (set_cut(0)) ident = TRUE;
3481                         if (set_image(0)) ident = TRUE;
3482                         if (set_shero(0,TRUE)) ident = TRUE;
3483                         break;
3484                 }
3485
3486                 case SV_ROD_HEALING:
3487                 {
3488                         if (hp_player(powerful ? 750 : 500)) ident = TRUE;
3489                         if (set_stun(0)) ident = TRUE;
3490                         if (set_cut(0)) ident = TRUE;
3491                         if (set_shero(0,TRUE)) ident = TRUE;
3492                         break;
3493                 }
3494
3495                 case SV_ROD_RESTORATION:
3496                 {
3497                         if (restore_level()) ident = TRUE;
3498                         if (do_res_stat(A_STR)) ident = TRUE;
3499                         if (do_res_stat(A_INT)) ident = TRUE;
3500                         if (do_res_stat(A_WIS)) ident = TRUE;
3501                         if (do_res_stat(A_DEX)) ident = TRUE;
3502                         if (do_res_stat(A_CON)) ident = TRUE;
3503                         if (do_res_stat(A_CHR)) ident = TRUE;
3504                         break;
3505                 }
3506
3507                 case SV_ROD_SPEED:
3508                 {
3509                         if (set_fast(randint1(30) + (powerful ? 30 : 15), FALSE)) ident = TRUE;
3510                         break;
3511                 }
3512
3513                 case SV_ROD_PESTICIDE:
3514                 {
3515                         if (dispel_monsters(powerful ? 8 : 4)) ident = TRUE;
3516                         break;
3517                 }
3518
3519                 case SV_ROD_TELEPORT_AWAY:
3520                 {
3521                         int distance = MAX_SIGHT * (powerful ? 8 : 5);
3522                         if (teleport_monster(dir, distance)) ident = TRUE;
3523                         break;
3524                 }
3525
3526                 case SV_ROD_DISARMING:
3527                 {
3528                         if (disarm_trap(dir)) ident = TRUE;
3529                         if (powerful && disarm_traps_touch()) ident = TRUE;
3530                         break;
3531                 }
3532
3533                 case SV_ROD_LITE:
3534                 {
3535                         int dam = damroll((powerful ? 12 : 6), 8);
3536 #ifdef JP
3537                         msg_print("ÀĤ¯µ±¤¯¸÷Àþ¤¬Êü¤¿¤ì¤¿¡£");
3538 #else
3539                         msg_print("A line of blue shimmering light appears.");
3540 #endif
3541
3542                         (void)lite_line(dir, dam);
3543                         ident = TRUE;
3544                         break;
3545                 }
3546
3547                 case SV_ROD_SLEEP_MONSTER:
3548                 {
3549                         if (sleep_monster(dir, lev)) ident = TRUE;
3550                         break;
3551                 }
3552
3553                 case SV_ROD_SLOW_MONSTER:
3554                 {
3555                         if (slow_monster(dir, lev)) ident = TRUE;
3556                         break;
3557                 }
3558
3559                 case SV_ROD_DRAIN_LIFE:
3560                 {
3561                         if (drain_life(dir, 70 + 3 * lev / 2)) ident = TRUE;
3562                         break;
3563                 }
3564
3565                 case SV_ROD_POLYMORPH:
3566                 {
3567                         if (poly_monster(dir, lev)) ident = TRUE;
3568                         break;
3569                 }
3570
3571                 case SV_ROD_ACID_BOLT:
3572                 {
3573                         fire_bolt_or_beam(10, GF_ACID, dir, damroll(6 + lev / 7, 8));
3574                         ident = TRUE;
3575                         break;
3576                 }
3577
3578                 case SV_ROD_ELEC_BOLT:
3579                 {
3580                         fire_bolt_or_beam(10, GF_ELEC, dir, damroll(4 + lev / 9, 8));
3581                         ident = TRUE;
3582                         break;
3583                 }
3584
3585                 case SV_ROD_FIRE_BOLT:
3586                 {
3587                         fire_bolt_or_beam(10, GF_FIRE, dir, damroll(7 + lev / 6, 8));
3588                         ident = TRUE;
3589                         break;
3590                 }
3591
3592                 case SV_ROD_COLD_BOLT:
3593                 {
3594                         fire_bolt_or_beam(10, GF_COLD, dir, damroll(5 + lev / 8, 8));
3595                         ident = TRUE;
3596                         break;
3597                 }
3598
3599                 case SV_ROD_ACID_BALL:
3600                 {
3601                         fire_ball(GF_ACID, dir, 60 + lev, rad);
3602                         ident = TRUE;
3603                         break;
3604                 }
3605
3606                 case SV_ROD_ELEC_BALL:
3607                 {
3608                         fire_ball(GF_ELEC, dir, 40 + lev, rad);
3609                         ident = TRUE;
3610                         break;
3611                 }
3612
3613                 case SV_ROD_FIRE_BALL:
3614                 {
3615                         fire_ball(GF_FIRE, dir, 70 + lev, rad);
3616                         ident = TRUE;
3617                         break;
3618                 }
3619
3620                 case SV_ROD_COLD_BALL:
3621                 {
3622                         fire_ball(GF_COLD, dir, 50 + lev, rad);
3623                         ident = TRUE;
3624                         break;
3625                 }
3626
3627                 case SV_ROD_HAVOC:
3628                 {
3629                         call_chaos();
3630                         ident = TRUE;
3631                         break;
3632                 }
3633
3634                 case SV_ROD_STONE_TO_MUD:
3635                 {
3636                         int dam = powerful ? 40 + randint1(60) : 20 + randint1(30);
3637                         if (wall_to_mud(dir, dam)) ident = TRUE;
3638                         break;
3639                 }
3640
3641                 case SV_ROD_AGGRAVATE:
3642                 {
3643                         aggravate_monsters(0);
3644                         ident = TRUE;
3645                         break;
3646                 }
3647         }
3648         return ident;
3649 }
3650
3651 /*
3652  * Activate (zap) a Rod
3653  *
3654  * Unstack fully charged rods as needed.
3655  *
3656  * Hack -- rods of perception/genocide can be "cancelled"
3657  * All rods can be cancelled at the "Direction?" prompt
3658  *
3659  * pvals are defined for each rod in k_info. -LM-
3660  */
3661 static void do_cmd_zap_rod_aux(int item)
3662 {
3663         int ident, chance, lev, fail;
3664         int dir = 0;
3665         object_type *o_ptr;
3666         bool success;
3667
3668         /* Hack -- let perception get aborted */
3669         bool use_charge = TRUE;
3670
3671         object_kind *k_ptr;
3672
3673         /* Get the item (in the pack) */
3674         if (item >= 0)
3675         {
3676                 o_ptr = &inventory[item];
3677         }
3678
3679         /* Get the item (on the floor) */
3680         else
3681         {
3682                 o_ptr = &o_list[0 - item];
3683         }
3684
3685
3686         /* Mega-Hack -- refuse to zap a pile from the ground */
3687         if ((item < 0) && (o_ptr->number > 1))
3688         {
3689 #ifdef JP
3690                 msg_print("¤Þ¤º¤Ï¥í¥Ã¥É¤ò½¦¤ï¤Ê¤±¤ì¤Ð¡£");
3691 #else
3692                 msg_print("You must first pick up the rods.");
3693 #endif
3694
3695                 return;
3696         }
3697
3698
3699         /* Get a direction (unless KNOWN not to need it) */
3700         if (((o_ptr->sval >= SV_ROD_MIN_DIRECTION) && (o_ptr->sval != SV_ROD_HAVOC) && (o_ptr->sval != SV_ROD_AGGRAVATE) && (o_ptr->sval != SV_ROD_PESTICIDE)) ||
3701              !object_is_aware(o_ptr))
3702         {
3703                 /* Get a direction, allow cancel */
3704                 if (!get_aim_dir(&dir)) return;
3705         }
3706
3707
3708         /* Take a turn */
3709         energy_use = 100;
3710
3711         /* Extract the item level */
3712         lev = k_info[o_ptr->k_idx].level;
3713
3714         /* Base chance of success */
3715         chance = p_ptr->skill_dev;
3716
3717         /* Confusion hurts skill */
3718         if (p_ptr->confused) chance = chance / 2;
3719
3720         fail = lev+5;
3721         if (chance > fail) fail -= (chance - fail)*2;
3722         else chance -= (fail - chance)*2;
3723         if (fail < USE_DEVICE) fail = USE_DEVICE;
3724         if (chance < USE_DEVICE) chance = USE_DEVICE;
3725
3726         if (world_player)
3727         {
3728                 if (flush_failure) flush();
3729 #ifdef JP
3730                 msg_print("»ß¤Þ¤Ã¤¿»þ¤ÎÃæ¤Ç¤Ï¤¦¤Þ¤¯Æ¯¤«¤Ê¤¤¤è¤¦¤À¡£");
3731 #else
3732                 msg_print("Nothing happen. Maybe this rod is freezing too.");
3733 #endif
3734
3735                 sound(SOUND_FAIL);
3736                 return;
3737         }
3738
3739         if (p_ptr->pclass == CLASS_BERSERKER) success = FALSE;
3740         else if (chance > fail)
3741         {
3742                 if (randint0(chance*2) < fail) success = FALSE;
3743                 else success = TRUE;
3744         }
3745         else
3746         {
3747                 if (randint0(fail*2) < chance) success = TRUE;
3748                 else success = FALSE;
3749         }
3750
3751         /* Roll for usage */
3752         if (!success)
3753         {
3754                 if (flush_failure) flush();
3755 #ifdef JP
3756                 msg_print("¤¦¤Þ¤¯¥í¥Ã¥É¤ò»È¤¨¤Ê¤«¤Ã¤¿¡£");
3757 #else
3758                 msg_print("You failed to use the rod properly.");
3759 #endif
3760
3761                 sound(SOUND_FAIL);
3762                 return;
3763         }
3764
3765         k_ptr = &k_info[o_ptr->k_idx];
3766
3767         /* A single rod is still charging */
3768         if ((o_ptr->number == 1) && (o_ptr->timeout))
3769         {
3770                 if (flush_failure) flush();
3771 #ifdef JP
3772                 msg_print("¤³¤Î¥í¥Ã¥É¤Ï¤Þ¤ÀËâÎϤò½¼Å¶¤·¤Æ¤¤¤ëºÇÃæ¤À¡£");
3773 #else
3774                 msg_print("The rod is still charging.");
3775 #endif
3776
3777                 return;
3778         }
3779         /* A stack of rods lacks enough energy. */
3780         else if ((o_ptr->number > 1) && (o_ptr->timeout > k_ptr->pval * (o_ptr->number - 1)))
3781         {
3782                 if (flush_failure) flush();
3783 #ifdef JP
3784 msg_print("¤½¤Î¥í¥Ã¥É¤Ï¤Þ¤À½¼Å¶Ãæ¤Ç¤¹¡£");
3785 #else
3786                 msg_print("The rods are all still charging.");
3787 #endif
3788
3789                 return;
3790         }
3791
3792         /* Sound */
3793         sound(SOUND_ZAP);
3794
3795         ident = rod_effect(o_ptr->sval, dir, &use_charge, FALSE, FALSE);
3796
3797         /* Increase the timeout by the rod kind's pval. -LM- */
3798         if (use_charge) o_ptr->timeout += k_ptr->pval;
3799
3800         /* Combine / Reorder the pack (later) */
3801         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
3802
3803         if (!(object_is_aware(o_ptr)))
3804         {
3805                 chg_virtue(V_PATIENCE, -1);
3806                 chg_virtue(V_CHANCE, 1);
3807                 chg_virtue(V_KNOWLEDGE, -1);
3808         }
3809
3810         /* Tried the object */
3811         object_tried(o_ptr);
3812
3813         /* Successfully determined the object function */
3814         if (ident && !object_is_aware(o_ptr))
3815         {
3816                 object_aware(o_ptr);
3817                 gain_exp((lev + (p_ptr->lev >> 1)) / p_ptr->lev);
3818         }
3819
3820         /* Window stuff */
3821         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
3822 }
3823
3824
3825 void do_cmd_zap_rod(void)
3826 {
3827         int item;
3828         cptr q, s;
3829
3830         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
3831         {
3832                 set_action(ACTION_NONE);
3833         }
3834
3835         /* Restrict choices to rods */
3836         item_tester_tval = TV_ROD;
3837
3838         /* Get an item */
3839 #ifdef JP
3840         q = "¤É¤Î¥í¥Ã¥É¤ò¿¶¤ê¤Þ¤¹¤«? ";
3841         s = "»È¤¨¤ë¥í¥Ã¥É¤¬¤Ê¤¤¡£";
3842 #else
3843         q = "Zap which rod? ";
3844         s = "You have no rod to zap.";
3845 #endif
3846
3847         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
3848
3849         /* Zap the rod */
3850         do_cmd_zap_rod_aux(item);
3851 }
3852
3853
3854 /*
3855  * Hook to determine if an object is activatable
3856  */
3857 static bool item_tester_hook_activate(object_type *o_ptr)
3858 {
3859         u32b flgs[TR_FLAG_SIZE];
3860
3861         /* Not known */
3862         if (!object_is_known(o_ptr)) return (FALSE);
3863
3864         /* Extract the flags */
3865         object_flags(o_ptr, flgs);
3866
3867         /* Check activation flag */
3868         if (have_flag(flgs, TR_ACTIVATE)) return (TRUE);
3869
3870         /* Assume not */
3871         return (FALSE);
3872 }
3873
3874
3875 /*
3876  * Hack -- activate the ring of power
3877  */
3878 void ring_of_power(int dir)
3879 {
3880         /* Pick a random effect */
3881         switch (randint1(10))
3882         {
3883                 case 1:
3884                 case 2:
3885                 {
3886                         /* Message */
3887 #ifdef JP
3888                         msg_print("¤¢¤Ê¤¿¤Ï°­À­¤Î¥ª¡¼¥é¤ËÊñ¤ß¹þ¤Þ¤ì¤¿¡£");
3889 #else
3890                         msg_print("You are surrounded by a malignant aura.");
3891 #endif
3892
3893                         sound(SOUND_EVIL);
3894
3895                         /* Decrease all stats (permanently) */
3896                         (void)dec_stat(A_STR, 50, TRUE);
3897                         (void)dec_stat(A_INT, 50, TRUE);
3898                         (void)dec_stat(A_WIS, 50, TRUE);
3899                         (void)dec_stat(A_DEX, 50, TRUE);
3900                         (void)dec_stat(A_CON, 50, TRUE);
3901                         (void)dec_stat(A_CHR, 50, TRUE);
3902
3903                         /* Lose some experience (permanently) */
3904                         p_ptr->exp -= (p_ptr->exp / 4);
3905                         p_ptr->max_exp -= (p_ptr->exp / 4);
3906                         check_experience();
3907
3908                         break;
3909                 }
3910
3911                 case 3:
3912                 {
3913                         /* Message */
3914 #ifdef JP
3915                         msg_print("¤¢¤Ê¤¿¤Ï¶¯ÎϤʥª¡¼¥é¤ËÊñ¤ß¹þ¤Þ¤ì¤¿¡£");
3916 #else
3917                         msg_print("You are surrounded by a powerful aura.");
3918 #endif
3919
3920
3921                         /* Dispel monsters */
3922                         dispel_monsters(1000);
3923
3924                         break;
3925                 }
3926
3927                 case 4:
3928                 case 5:
3929                 case 6:
3930                 {
3931                         /* Mana Ball */
3932                         fire_ball(GF_MANA, dir, 600, 3);
3933
3934                         break;
3935                 }
3936
3937                 case 7:
3938                 case 8:
3939                 case 9:
3940                 case 10:
3941                 {
3942                         /* Mana Bolt */
3943                         fire_bolt(GF_MANA, dir, 500);
3944
3945                         break;
3946                 }
3947         }
3948 }
3949
3950
3951 static bool ang_sort_comp_pet(vptr u, vptr v, int a, int b)
3952 {
3953         u16b *who = (u16b*)(u);
3954
3955         int w1 = who[a];
3956         int w2 = who[b];
3957
3958         monster_type *m_ptr1 = &m_list[w1];
3959         monster_type *m_ptr2 = &m_list[w2];
3960         monster_race *r_ptr1 = &r_info[m_ptr1->r_idx];
3961         monster_race *r_ptr2 = &r_info[m_ptr2->r_idx];
3962
3963         /* Unused */
3964         (void)v;
3965
3966         if (m_ptr1->nickname && !m_ptr2->nickname) return TRUE;
3967         if (m_ptr2->nickname && !m_ptr1->nickname) return FALSE;
3968
3969         if ((r_ptr1->flags1 & RF1_UNIQUE) && !(r_ptr2->flags1 & RF1_UNIQUE)) return TRUE;
3970         if ((r_ptr2->flags1 & RF1_UNIQUE) && !(r_ptr1->flags1 & RF1_UNIQUE)) return FALSE;
3971
3972         if (r_ptr1->level > r_ptr2->level) return TRUE;
3973         if (r_ptr2->level > r_ptr1->level) return FALSE;
3974
3975         if (m_ptr1->hp > m_ptr2->hp) return TRUE;
3976         if (m_ptr2->hp > m_ptr1->hp) return FALSE;
3977         
3978         return w1 <= w2;
3979 }
3980
3981
3982 /*
3983  * Activate a wielded object.  Wielded objects never stack.
3984  * And even if they did, activatable objects never stack.
3985  *
3986  * Currently, only (some) artifacts, and Dragon Scale Mail, can be activated.
3987  * But one could, for example, easily make an activatable "Ring of Plasma".
3988  *
3989  * Note that it always takes a turn to activate an artifact, even if
3990  * the user hits "escape" at the "direction" prompt.
3991  */
3992 static void do_cmd_activate_aux(int item)
3993 {
3994         int         k, dir, lev, chance, fail;
3995         object_type *o_ptr;
3996         bool success;
3997
3998
3999         /* Get the item (in the pack) */
4000         if (item >= 0)
4001         {
4002                 o_ptr = &inventory[item];
4003         }
4004
4005         /* Get the item (on the floor) */
4006         else
4007         {
4008                 o_ptr = &o_list[0 - item];
4009         }
4010
4011         /* Take a turn */
4012         energy_use = 100;
4013
4014         /* Extract the item level */
4015         lev = k_info[o_ptr->k_idx].level;
4016
4017         /* Hack -- use artifact level instead */
4018         if (object_is_fixed_artifact(o_ptr)) lev = a_info[o_ptr->name1].level;
4019         else if (object_is_random_artifact(o_ptr))
4020         {
4021                 const activation_type* const act_ptr = find_activation_info(o_ptr);
4022                 if (act_ptr) {
4023                         lev = act_ptr->level;
4024                 }
4025         }
4026         else if (((o_ptr->tval == TV_RING) || (o_ptr->tval == TV_AMULET)) && o_ptr->name2) lev = e_info[o_ptr->name2].level;
4027
4028         /* Base chance of success */
4029         chance = p_ptr->skill_dev;
4030
4031         /* Confusion hurts skill */
4032         if (p_ptr->confused) chance = chance / 2;
4033
4034         fail = lev+5;
4035         if (chance > fail) fail -= (chance - fail)*2;
4036         else chance -= (fail - chance)*2;
4037         if (fail < USE_DEVICE) fail = USE_DEVICE;
4038         if (chance < USE_DEVICE) chance = USE_DEVICE;
4039
4040         if (world_player)
4041         {
4042                 if (flush_failure) flush();
4043 #ifdef JP
4044                 msg_print("»ß¤Þ¤Ã¤¿»þ¤ÎÃæ¤Ç¤Ï¤¦¤Þ¤¯Æ¯¤«¤Ê¤¤¤è¤¦¤À¡£");
4045 #else
4046                 msg_print("It shows no reaction.");
4047 #endif
4048                 sound(SOUND_FAIL);
4049                 return;
4050         }
4051
4052         if (p_ptr->pclass == CLASS_BERSERKER) success = FALSE;
4053         else if (chance > fail)
4054         {
4055                 if (randint0(chance*2) < fail) success = FALSE;
4056                 else success = TRUE;
4057         }
4058         else
4059         {
4060                 if (randint0(fail*2) < chance) success = TRUE;
4061                 else success = FALSE;
4062         }
4063
4064         /* Roll for usage */
4065         if (!success)
4066         {
4067                 if (flush_failure) flush();
4068 #ifdef JP
4069                 msg_print("¤¦¤Þ¤¯»ÏÆ°¤µ¤»¤ë¤³¤È¤¬¤Ç¤­¤Ê¤«¤Ã¤¿¡£");
4070 #else
4071                 msg_print("You failed to activate it properly.");
4072 #endif
4073                 sound(SOUND_FAIL);
4074                 return;
4075         }
4076
4077         /* Check the recharge */
4078         if (o_ptr->timeout)
4079         {
4080 #ifdef JP
4081                 msg_print("¤½¤ì¤ÏÈù¤«¤Ë²»¤òΩ¤Æ¡¢µ±¤­¡¢¾Ã¤¨¤¿...");
4082 #else
4083                 msg_print("It whines, glows and fades...");
4084 #endif
4085                 return;
4086         }
4087
4088         /* Some lights need enough fuel for activation */
4089         if (!o_ptr->xtra4 && (o_ptr->tval == TV_FLASK) &&
4090                 ((o_ptr->sval == SV_LITE_TORCH) || (o_ptr->sval == SV_LITE_LANTERN)))
4091         {
4092 #ifdef JP
4093                 msg_print("dzÎÁ¤¬¤Ê¤¤¡£");
4094 #else
4095                 msg_print("It has no fuel.");
4096 #endif
4097                 energy_use = 0;
4098                 return;
4099         }
4100
4101         /* Activate the artifact */
4102 #ifdef JP
4103         msg_print("»ÏÆ°¤µ¤»¤¿...");
4104 #else
4105         msg_print("You activate it...");
4106 #endif
4107
4108
4109         /* Sound */
4110         sound(SOUND_ZAP);
4111
4112         /* Activate object */
4113         if (activation_index(o_ptr))
4114         {
4115                 (void)activate_random_artifact(o_ptr);
4116
4117                 /* Window stuff */
4118                 p_ptr->window |= (PW_INVEN | PW_EQUIP);
4119
4120                 /* Success */
4121                 return;
4122         }
4123
4124         /* Special items */
4125         else if (o_ptr->tval == TV_WHISTLE)
4126         {
4127                 if (music_singing_any()) stop_singing();
4128                 if (hex_spelling_any()) stop_hex_spell_all();
4129
4130 #if 0
4131                 if (object_is_cursed(o_ptr))
4132                 {
4133 #ifdef JP
4134                         msg_print("¥«¥ó¹â¤¤²»¤¬¶Á¤­ÅϤä¿¡£");
4135 #else
4136                         msg_print("You produce a shrill whistling sound.");
4137 #endif
4138                         aggravate_monsters(0);
4139                 }
4140                 else
4141 #endif
4142                 {
4143                         int pet_ctr, i;
4144                         u16b *who;
4145                         int max_pet = 0;
4146                         u16b dummy_why;
4147
4148                         /* Allocate the "who" array */
4149                         C_MAKE(who, max_m_idx, u16b);
4150
4151                         /* Process the monsters (backwards) */
4152                         for (pet_ctr = m_max - 1; pet_ctr >= 1; pet_ctr--)
4153                         {
4154                                 if (is_pet(&m_list[pet_ctr]) && (p_ptr->riding != pet_ctr))
4155                                   who[max_pet++] = pet_ctr;
4156                         }
4157
4158                         /* Select the sort method */
4159                         ang_sort_comp = ang_sort_comp_pet;
4160                         ang_sort_swap = ang_sort_swap_hook;
4161
4162                         ang_sort(who, &dummy_why, max_pet);
4163
4164                         /* Process the monsters (backwards) */
4165                         for (i = 0; i < max_pet; i++)
4166                         {
4167                                 pet_ctr = who[i];
4168                                 teleport_monster_to(pet_ctr, py, px, 100, TELEPORT_PASSIVE);
4169                         }
4170
4171                         /* Free the "who" array */
4172                         C_KILL(who, max_m_idx, u16b);
4173                 }
4174                 o_ptr->timeout = 100+randint1(100);
4175                 return;
4176         }
4177         else if (o_ptr->tval == TV_CAPTURE)
4178         {
4179                 if(!o_ptr->pval)
4180                 {
4181                         bool old_target_pet = target_pet;
4182                         target_pet = TRUE;
4183                         if (!get_aim_dir(&dir))
4184                         {
4185                                 target_pet = old_target_pet;
4186                                 return;
4187                         }
4188                         target_pet = old_target_pet;
4189
4190                         if(fire_ball(GF_CAPTURE, dir, 0, 0))
4191                         {
4192                                 o_ptr->pval = cap_mon;
4193                                 o_ptr->xtra3 = cap_mspeed;
4194                                 o_ptr->xtra4 = cap_hp;
4195                                 o_ptr->xtra5 = cap_maxhp;
4196                                 if (cap_nickname)
4197                                 {
4198                                         cptr t;
4199                                         char *s;
4200                                         char buf[80] = "";
4201
4202                                         if (o_ptr->inscription)
4203                                                 strcpy(buf, quark_str(o_ptr->inscription));
4204                                         s = buf;
4205                                         for (s = buf;*s && (*s != '#'); s++)
4206                                         {
4207 #ifdef JP
4208                                                 if (iskanji(*s)) s++;
4209 #endif
4210                                         }
4211                                         *s = '#';
4212                                         s++;
4213 #ifdef JP
4214  /*nothing*/
4215 #else
4216                                         *s++ = '\'';
4217 #endif
4218                                         t = quark_str(cap_nickname);
4219                                         while (*t)
4220                                         {
4221                                                 *s = *t;
4222                                                 s++;
4223                                                 t++;
4224                                         }
4225 #ifdef JP
4226  /*nothing*/
4227 #else
4228                                         *s++ = '\'';
4229 #endif
4230                                         *s = '\0';
4231                                         o_ptr->inscription = quark_add(buf);
4232                                 }
4233                         }
4234                 }
4235                 else
4236                 {
4237                         bool success = FALSE;
4238                         if (!get_rep_dir2(&dir)) return;
4239                         if (monster_can_enter(py + ddy[dir], px + ddx[dir], &r_info[o_ptr->pval], 0))
4240                         {
4241                                 if (place_monster_aux(0, py + ddy[dir], px + ddx[dir], o_ptr->pval, (PM_FORCE_PET | PM_NO_KAGE)))
4242                                 {
4243                                         if (o_ptr->xtra3) m_list[hack_m_idx_ii].mspeed = o_ptr->xtra3;
4244                                         if (o_ptr->xtra5) m_list[hack_m_idx_ii].max_maxhp = o_ptr->xtra5;
4245                                         if (o_ptr->xtra4) m_list[hack_m_idx_ii].hp = o_ptr->xtra4;
4246                                         m_list[hack_m_idx_ii].maxhp = m_list[hack_m_idx_ii].max_maxhp;
4247                                         if (o_ptr->inscription)
4248                                         {
4249                                                 char buf[80];
4250                                                 cptr t;
4251 #ifndef JP
4252                                                 bool quote = FALSE;
4253 #endif
4254
4255                                                 t = quark_str(o_ptr->inscription);
4256                                                 for (t = quark_str(o_ptr->inscription);*t && (*t != '#'); t++)
4257                                                 {
4258 #ifdef JP
4259                                                         if (iskanji(*t)) t++;
4260 #endif
4261                                                 }
4262                                                 if (*t)
4263                                                 {
4264                                                         char *s = buf;
4265                                                         t++;
4266 #ifdef JP
4267                                                         /* nothing */
4268 #else
4269                                                         if (*t =='\'')
4270                                                         {
4271                                                                 t++;
4272                                                                 quote = TRUE;
4273                                                         }
4274 #endif
4275                                                         while(*t)
4276                                                         {
4277                                                                 *s = *t;
4278                                                                 t++;
4279                                                                 s++;
4280                                                         }
4281 #ifdef JP
4282                                                         /* nothing */
4283 #else
4284                                                         if (quote && *(s-1) =='\'')
4285                                                                 s--;
4286 #endif
4287                                                         *s = '\0';
4288                                                         m_list[hack_m_idx_ii].nickname = quark_add(buf);
4289                                                         t = quark_str(o_ptr->inscription);
4290                                                         s = buf;
4291                                                         while(*t && (*t != '#'))
4292                                                         {
4293                                                                 *s = *t;
4294                                                                 t++;
4295                                                                 s++;
4296                                                         }
4297                                                         *s = '\0';
4298                                                         o_ptr->inscription = quark_add(buf);
4299                                                 }
4300                                         }
4301                                         o_ptr->pval = 0;
4302                                         o_ptr->xtra3 = 0;
4303                                         o_ptr->xtra4 = 0;
4304                                         o_ptr->xtra5 = 0;
4305                                         success = TRUE;
4306                                 }
4307                         }
4308                         if (!success)
4309 #ifdef JP
4310                                 msg_print("¤ª¤Ã¤È¡¢²òÊü¤Ë¼ºÇÔ¤·¤¿¡£");
4311 #else
4312                                 msg_print("Oops.  You failed to release your pet.");
4313 #endif
4314                 }
4315                 return;
4316         }
4317
4318         /* Mistake */
4319 #ifdef JP
4320         msg_print("¤ª¤Ã¤È¡¢¤³¤Î¥¢¥¤¥Æ¥à¤Ï»ÏÆ°¤Ç¤­¤Ê¤¤¡£");
4321 #else
4322         msg_print("Oops.  That object cannot be activated.");
4323 #endif
4324
4325 }
4326
4327
4328 void do_cmd_activate(void)
4329 {
4330         int     item;
4331         cptr    q, s;
4332
4333
4334         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
4335         {
4336                 set_action(ACTION_NONE);
4337         }
4338
4339         item_tester_no_ryoute = TRUE;
4340         /* Prepare the hook */
4341         item_tester_hook = item_tester_hook_activate;
4342
4343         /* Get an item */
4344 #ifdef JP
4345         q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò»ÏÆ°¤µ¤»¤Þ¤¹¤«? ";
4346         s = "»ÏÆ°¤Ç¤­¤ë¥¢¥¤¥Æ¥à¤òÁõÈ÷¤·¤Æ¤¤¤Ê¤¤¡£";
4347 #else
4348         q = "Activate which item? ";
4349         s = "You have nothing to activate.";
4350 #endif
4351
4352         if (!get_item(&item, q, s, (USE_EQUIP))) return;
4353
4354         /* Activate the item */
4355         do_cmd_activate_aux(item);
4356 }
4357
4358
4359 /*
4360  * Hook to determine if an object is useable
4361  */
4362 static bool item_tester_hook_use(object_type *o_ptr)
4363 {
4364         u32b flgs[TR_FLAG_SIZE];
4365
4366         /* Ammo */
4367         if (o_ptr->tval == p_ptr->tval_ammo)
4368                 return (TRUE);
4369
4370         /* Useable object */
4371         switch (o_ptr->tval)
4372         {
4373                 case TV_SPIKE:
4374                 case TV_STAFF:
4375                 case TV_WAND:
4376                 case TV_ROD:
4377                 case TV_SCROLL:
4378                 case TV_POTION:
4379                 case TV_FOOD:
4380                 {
4381                         return (TRUE);
4382                 }
4383
4384                 default:
4385                 {
4386                         int i;
4387
4388                         /* Not known */
4389                         if (!object_is_known(o_ptr)) return (FALSE);
4390
4391                         /* HACK - only items from the equipment can be activated */
4392                         for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
4393                         {
4394                                 if (&inventory[i] == o_ptr)
4395                                 {
4396                                         /* Extract the flags */
4397                                         object_flags(o_ptr, flgs);
4398
4399                                         /* Check activation flag */
4400                                         if (have_flag(flgs, TR_ACTIVATE)) return (TRUE);
4401                                 }
4402                         }
4403                 }
4404         }
4405
4406         /* Assume not */
4407         return (FALSE);
4408 }
4409
4410
4411 /*
4412  * Use an item
4413  * XXX - Add actions for other item types
4414  */
4415 void do_cmd_use(void)
4416 {
4417         int         item;
4418         object_type *o_ptr;
4419         cptr        q, s;
4420
4421         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
4422         {
4423                 set_action(ACTION_NONE);
4424         }
4425
4426         item_tester_no_ryoute = TRUE;
4427         /* Prepare the hook */
4428         item_tester_hook = item_tester_hook_use;
4429
4430         /* Get an item */
4431 #ifdef JP
4432 q = "¤É¤ì¤ò»È¤¤¤Þ¤¹¤«¡©";
4433 s = "»È¤¨¤ë¤â¤Î¤¬¤¢¤ê¤Þ¤»¤ó¡£";
4434 #else
4435         q = "Use which item? ";
4436         s = "You have nothing to use.";
4437 #endif
4438
4439         if (!get_item(&item, q, s, (USE_INVEN | USE_EQUIP | USE_FLOOR))) return;
4440
4441         /* Get the item (in the pack) */
4442         if (item >= 0)
4443         {
4444                 o_ptr = &inventory[item];
4445         }
4446         /* Get the item (on the floor) */
4447         else
4448         {
4449                 o_ptr = &o_list[0 - item];
4450         }
4451
4452         switch (o_ptr->tval)
4453         {
4454                 /* Spike a door */
4455                 case TV_SPIKE:
4456                 {
4457                         do_cmd_spike();
4458                         break;
4459                 }
4460
4461                 /* Eat some food */
4462                 case TV_FOOD:
4463                 {
4464                         do_cmd_eat_food_aux(item);
4465                         break;
4466                 }
4467
4468                 /* Aim a wand */
4469                 case TV_WAND:
4470                 {
4471                         do_cmd_aim_wand_aux(item);
4472                         break;
4473                 }
4474
4475                 /* Use a staff */
4476                 case TV_STAFF:
4477                 {
4478                         do_cmd_use_staff_aux(item);
4479                         break;
4480                 }
4481
4482                 /* Zap a rod */
4483                 case TV_ROD:
4484                 {
4485                         do_cmd_zap_rod_aux(item);
4486                         break;
4487                 }
4488
4489                 /* Quaff a potion */
4490                 case TV_POTION:
4491                 {
4492                         do_cmd_quaff_potion_aux(item);
4493                         break;
4494                 }
4495
4496                 /* Read a scroll */
4497                 case TV_SCROLL:
4498                 {
4499                         /* Check some conditions */
4500                         if (p_ptr->blind)
4501                         {
4502 #ifdef JP
4503 msg_print("Ìܤ¬¸«¤¨¤Ê¤¤¡£");
4504 #else
4505                                 msg_print("You can't see anything.");
4506 #endif
4507
4508                                 return;
4509                         }
4510                         if (no_lite())
4511                         {
4512 #ifdef JP
4513 msg_print("ÌÀ¤«¤ê¤¬¤Ê¤¤¤Î¤Ç¡¢°Å¤¯¤ÆÆɤá¤Ê¤¤¡£");
4514 #else
4515                                 msg_print("You have no light to read by.");
4516 #endif
4517
4518                                 return;
4519                         }
4520                         if (p_ptr->confused)
4521                         {
4522 #ifdef JP
4523 msg_print("º®Í𤷤Ƥ¤¤ÆÆɤá¤Ê¤¤¡ª");
4524 #else
4525                                 msg_print("You are too confused!");
4526 #endif
4527
4528                                 return;
4529                         }
4530
4531                   do_cmd_read_scroll_aux(item, TRUE);
4532                   break;
4533                 }
4534
4535                 /* Fire ammo */
4536                 case TV_SHOT:
4537                 case TV_ARROW:
4538                 case TV_BOLT:
4539                 {
4540                         do_cmd_fire_aux(item, &inventory[INVEN_BOW]);
4541                         break;
4542                 }
4543
4544                 /* Activate an artifact */
4545                 default:
4546                 {
4547                         do_cmd_activate_aux(item);
4548                         break;
4549                 }
4550         }
4551 }
4552
4553 static int select_magic_eater(bool only_browse)
4554 {
4555         int ext=0;
4556         char choice;
4557         bool flag, request_list;
4558         int tval = 0;
4559         int             ask = TRUE, i = 0;
4560         char            out_val[160];
4561
4562         int menu_line = (use_menu ? 1 : 0);
4563
4564 #ifdef ALLOW_REPEAT
4565         int sn;
4566         if (repeat_pull(&sn))
4567         {
4568                 /* Verify the spell */
4569                 if (sn >= EATER_EXT*2 && !(p_ptr->magic_num1[sn] > k_info[lookup_kind(TV_ROD, sn-EATER_EXT*2)].pval * (p_ptr->magic_num2[sn] - 1) * EATER_ROD_CHARGE))
4570                         return sn;
4571                 else if (sn < EATER_EXT*2 && !(p_ptr->magic_num1[sn] < EATER_CHARGE))
4572                         return sn;
4573         }
4574         
4575 #endif /* ALLOW_REPEAT */
4576
4577         for (i = 0; i < 108; i++)
4578         {
4579                 if (p_ptr->magic_num2[i]) break;
4580         }
4581         if (i == 108)
4582         {
4583 #ifdef JP
4584                 msg_print("ËâË¡¤ò³Ð¤¨¤Æ¤¤¤Ê¤¤¡ª");
4585 #else
4586                 msg_print("You don't have any magic!");
4587 #endif
4588                 return -1;
4589         }
4590
4591         if (use_menu)
4592         {
4593                 screen_save();
4594
4595                 while(!tval)
4596                 {
4597 #ifdef JP
4598                         prt(format(" %s ¾ó", (menu_line == 1) ? "¡Õ" : "  "), 2, 14);
4599                         prt(format(" %s ËâË¡ËÀ", (menu_line == 2) ? "¡Õ" : "  "), 3, 14);
4600                         prt(format(" %s ¥í¥Ã¥É", (menu_line == 3) ? "¡Õ" : "  "), 4, 14);
4601 #else
4602                         prt(format(" %s staff", (menu_line == 1) ? "> " : "  "), 2, 14);
4603                         prt(format(" %s wand", (menu_line == 2) ? "> " : "  "), 3, 14);
4604                         prt(format(" %s rod", (menu_line == 3) ? "> " : "  "), 4, 14);
4605 #endif
4606
4607                         if (only_browse) prt(_("¤É¤Î¼ïÎà¤ÎËâË¡¤ò¸«¤Þ¤¹¤«¡©", "Which type of magic do you browse?"), 0, 0);
4608                         else prt(_("¤É¤Î¼ïÎà¤ÎËâË¡¤ò»È¤¤¤Þ¤¹¤«¡©", "Which type of magic do you use?"), 0, 0);
4609
4610                         choice = inkey();
4611                         switch(choice)
4612                         {
4613                         case ESCAPE:
4614                         case 'z':
4615                         case 'Z':
4616                                 screen_load();
4617                                 return -1;
4618                         case '2':
4619                         case 'j':
4620                         case 'J':
4621                                 menu_line++;
4622                                 break;
4623                         case '8':
4624                         case 'k':
4625                         case 'K':
4626                                 menu_line+= 2;
4627                                 break;
4628                         case '\r':
4629                         case 'x':
4630                         case 'X':
4631                                 ext = (menu_line-1)*EATER_EXT;
4632                                 if (menu_line == 1) tval = TV_STAFF;
4633                                 else if (menu_line == 2) tval = TV_WAND;
4634                                 else tval = TV_ROD;
4635                                 break;
4636                         }
4637                         if (menu_line > 3) menu_line -= 3;
4638                 }
4639                 screen_load();
4640         }
4641         else
4642         {
4643         while (TRUE)
4644         {
4645 #ifdef JP
4646                 if (!get_com("[A] ¾ó, [B] ËâË¡ËÀ, [C] ¥í¥Ã¥É:", &choice, TRUE))
4647 #else
4648                 if (!get_com("[A] staff, [B] wand, [C] rod:", &choice, TRUE))
4649 #endif
4650                 {
4651                         return -1;
4652                 }
4653                 if (choice == 'A' || choice == 'a')
4654                 {
4655                         ext = 0;
4656                         tval = TV_STAFF;
4657                         break;
4658                 }
4659                 if (choice == 'B' || choice == 'b')
4660                 {
4661                         ext = EATER_EXT;
4662                         tval = TV_WAND;
4663                         break;
4664                 }
4665                 if (choice == 'C' || choice == 'c')
4666                 {
4667                         ext = EATER_EXT*2;
4668                         tval = TV_ROD;
4669                         break;
4670                 }
4671         }
4672         }
4673         for (i = ext; i < ext + EATER_EXT; i++)
4674         {
4675                 if (p_ptr->magic_num2[i])
4676                 {
4677                         if (use_menu) menu_line = i-ext+1;
4678                         break;
4679                 }
4680         }
4681         if (i == ext+EATER_EXT)
4682         {
4683 #ifdef JP
4684                 msg_print("¤½¤Î¼ïÎà¤ÎËâË¡¤Ï³Ð¤¨¤Æ¤¤¤Ê¤¤¡ª");
4685 #else
4686                 msg_print("You don't have that type of magic!");
4687 #endif
4688                 return -1;
4689         }
4690
4691         /* Nothing chosen yet */
4692         flag = FALSE;
4693
4694         /* Build a prompt */
4695         if (only_browse) strnfmt(out_val, 78, _("('*'¤Ç°ìÍ÷, ESC¤ÇÃæÃÇ) ¤É¤ÎËâÎϤò¸«¤Þ¤¹¤«¡©",
4696                                                                                         "(*=List, ESC=exit) Browse which power? "));
4697         else strnfmt(out_val, 78, _("('*'¤Ç°ìÍ÷, ESC¤ÇÃæÃÇ) ¤É¤ÎËâÎϤò»È¤¤¤Þ¤¹¤«¡©",
4698                                                                 "(*=List, ESC=exit) Use which power? "));
4699         
4700         /* Save the screen */
4701         screen_save();
4702
4703         request_list = always_show_list;
4704
4705         /* Get a spell from the user */
4706         while (!flag)
4707         {
4708                 /* Show the list */
4709                 if (request_list || use_menu)
4710                 {
4711                         byte y, x = 0;
4712                         int ctr, chance;
4713                         int k_idx;
4714                         char dummy[80];
4715                         int x1, y1, level;
4716                         byte col;
4717
4718                         strcpy(dummy, "");
4719
4720                         for (y = 1; y < 20; y++)
4721                                 prt("", y, x);
4722
4723                         y = 1;
4724
4725                         /* Print header(s) */
4726 #ifdef JP
4727                         prt(format("                           %s ¼ºÎ¨                           %s ¼ºÎ¨", (tval == TV_ROD ? "  ¾õÂÖ  " : "»ÈÍѲó¿ô"), (tval == TV_ROD ? "  ¾õÂÖ  " : "»ÈÍѲó¿ô")), y++, x);
4728 #else
4729                         prt(format("                           %s Fail                           %s Fail", (tval == TV_ROD ? "  Stat  " : " Charges"), (tval == TV_ROD ? "  Stat  " : " Charges")), y++, x);
4730 #endif
4731
4732                         /* Print list */
4733                         for (ctr = 0; ctr < EATER_EXT; ctr++)
4734                         {
4735                                 if (!p_ptr->magic_num2[ctr+ext]) continue;
4736
4737                                 k_idx = lookup_kind(tval, ctr);
4738
4739                                 if (use_menu)
4740                                 {
4741                                         if (ctr == (menu_line-1))
4742 #ifdef JP
4743                                                 strcpy(dummy, "¡Õ");
4744 #else
4745                                         strcpy(dummy, "> ");
4746 #endif
4747                                         else strcpy(dummy, "  ");
4748                                                 
4749                                 }
4750                                 /* letter/number for power selection */
4751                                 else
4752                                 {
4753                                         char letter;
4754                                         if (ctr < 26)
4755                                                 letter = I2A(ctr);
4756                                         else
4757                                                 letter = '0' + ctr - 26;
4758                                         sprintf(dummy, "%c)",letter);
4759                                 }
4760                                 x1 = ((ctr < EATER_EXT/2) ? x : x + 40);
4761                                 y1 = ((ctr < EATER_EXT/2) ? y + ctr : y + ctr - EATER_EXT/2);
4762                                 level = (tval == TV_ROD ? k_info[k_idx].level * 5 / 6 - 5 : k_info[k_idx].level);
4763                                 chance = level * 4 / 5 + 20;
4764                                 chance -= 3 * (adj_mag_stat[p_ptr->stat_ind[mp_ptr->spell_stat]] - 1);
4765                                 level /= 2;
4766                                 if (p_ptr->lev > level)
4767                                 {
4768                                         chance -= 3 * (p_ptr->lev - level);
4769                                 }
4770                                 chance = mod_spell_chance_1(chance);
4771                                 chance = MAX(chance, adj_mag_fail[p_ptr->stat_ind[mp_ptr->spell_stat]]);
4772                                 /* Stunning makes spells harder */
4773                                 if (p_ptr->stun > 50) chance += 25;
4774                                 else if (p_ptr->stun) chance += 15;
4775
4776                                 if (chance > 95) chance = 95;
4777
4778                                 chance = mod_spell_chance_2(chance);
4779
4780                                 col = TERM_WHITE;
4781
4782                                 if (k_idx)
4783                                 {
4784                                         if (tval == TV_ROD)
4785                                         {
4786                                                 strcat(dummy, format(
4787 #ifdef JP
4788                                                                " %-22.22s ½¼Å¶:%2d/%2d%3d%%",
4789 #else
4790                                                                " %-22.22s   (%2d/%2d) %3d%%",
4791 #endif
4792                                                                k_name + k_info[k_idx].name, 
4793                                                                p_ptr->magic_num1[ctr+ext] ? 
4794                                                                (p_ptr->magic_num1[ctr+ext] - 1) / (EATER_ROD_CHARGE * k_info[k_idx].pval) +1 : 0, 
4795                                                                p_ptr->magic_num2[ctr+ext], chance));
4796                                                 if (p_ptr->magic_num1[ctr+ext] > k_info[k_idx].pval * (p_ptr->magic_num2[ctr+ext]-1) * EATER_ROD_CHARGE) col = TERM_RED;
4797                                         }
4798                                         else
4799                                         {
4800                                                 strcat(dummy, format(" %-22.22s    %2d/%2d %3d%%", k_name + k_info[k_idx].name, (s16b)(p_ptr->magic_num1[ctr+ext]/EATER_CHARGE), p_ptr->magic_num2[ctr+ext], chance));
4801                                                 if (p_ptr->magic_num1[ctr+ext] < EATER_CHARGE) col = TERM_RED;
4802                                         }
4803                                 }
4804                                 else
4805                                         strcpy(dummy, "");
4806                                 c_prt(col, dummy, y1, x1);
4807                         }
4808                 }
4809
4810                 if (!get_com(out_val, &choice, FALSE)) break;
4811
4812                 if (use_menu && choice != ' ')
4813                 {
4814                         switch (choice)
4815                         {
4816                                 case '0':
4817                                 {
4818                                         screen_load();
4819                                         return 0;
4820                                 }
4821
4822                                 case '8':
4823                                 case 'k':
4824                                 case 'K':
4825                                 {
4826                                         do
4827                                         {
4828                                                 menu_line += EATER_EXT - 1;
4829                                                 if (menu_line > EATER_EXT) menu_line -= EATER_EXT;
4830                                         } while(!p_ptr->magic_num2[menu_line+ext-1]);
4831                                         break;
4832                                 }
4833
4834                                 case '2':
4835                                 case 'j':
4836                                 case 'J':
4837                                 {
4838                                         do
4839                                         {
4840                                                 menu_line++;
4841                                                 if (menu_line > EATER_EXT) menu_line -= EATER_EXT;
4842                                         } while(!p_ptr->magic_num2[menu_line+ext-1]);
4843                                         break;
4844                                 }
4845
4846                                 case '4':
4847                                 case 'h':
4848                                 case 'H':
4849                                 case '6':
4850                                 case 'l':
4851                                 case 'L':
4852                                 {
4853                                         bool reverse = FALSE;
4854                                         if ((choice == '4') || (choice == 'h') || (choice == 'H')) reverse = TRUE;
4855                                         if (menu_line > EATER_EXT/2)
4856                                         {
4857                                                 menu_line -= EATER_EXT/2;
4858                                                 reverse = TRUE;
4859                                         }
4860                                         else menu_line+=EATER_EXT/2;
4861                                         while(!p_ptr->magic_num2[menu_line+ext-1])
4862                                         {
4863                                                 if (reverse)
4864                                                 {
4865                                                         menu_line--;
4866                                                         if (menu_line < 2) reverse = FALSE;
4867                                                 }
4868                                                 else
4869                                                 {
4870                                                         menu_line++;
4871                                                         if (menu_line > EATER_EXT-1) reverse = TRUE;
4872                                                 }
4873                                         }
4874                                         break;
4875                                 }
4876
4877                                 case 'x':
4878                                 case 'X':
4879                                 case '\r':
4880                                 {
4881                                         i = menu_line - 1;
4882                                         ask = FALSE;
4883                                         break;
4884                                 }
4885                         }
4886                 }
4887
4888                 /* Request redraw */
4889                 if (use_menu && ask) continue;
4890
4891                 /* Request redraw */
4892                 if (!use_menu && ((choice == ' ') || (choice == '*') || (choice == '?')))
4893                 {
4894                         /* Hide the list */
4895                         if (request_list)
4896                         {
4897                                 /* Hide list */
4898                                 request_list = FALSE;
4899                                 
4900                                 /* Restore the screen */
4901                                 screen_load();
4902                                 screen_save();
4903                         }
4904                         else
4905                                 request_list = TRUE;
4906
4907                         /* Redo asking */
4908                         continue;
4909                 }
4910
4911                 if (!use_menu)
4912                 {
4913                         if (isalpha(choice))
4914                         {
4915                                 /* Note verify */
4916                                 ask = (isupper(choice));
4917
4918                                 /* Lowercase */
4919                                 if (ask) choice = tolower(choice);
4920
4921                                 /* Extract request */
4922                                 i = (islower(choice) ? A2I(choice) : -1);
4923                         }
4924                         else
4925                         {
4926                                 ask = FALSE; /* Can't uppercase digits */
4927
4928                                 i = choice - '0' + 26;
4929                         }
4930                 }
4931
4932                 /* Totally Illegal */
4933                 if ((i < 0) || (i > EATER_EXT) || !p_ptr->magic_num2[i+ext])
4934                 {
4935                         bell();
4936                         continue;
4937                 }
4938
4939                 if (!only_browse)
4940                 {
4941                         /* Verify it */
4942                         if (ask)
4943                         {
4944                                 char tmp_val[160];
4945
4946                                 /* Prompt */
4947 #ifdef JP
4948                                 (void) strnfmt(tmp_val, 78, "%s¤ò»È¤¤¤Þ¤¹¤«¡© ", k_name + k_info[lookup_kind(tval ,i)].name);
4949 #else
4950                                 (void) strnfmt(tmp_val, 78, "Use %s?", k_name + k_info[lookup_kind(tval ,i)].name);
4951 #endif
4952
4953                                 /* Belay that order */
4954                                 if (!get_check(tmp_val)) continue;
4955                         }
4956                         if (tval == TV_ROD)
4957                         {
4958                                 if (p_ptr->magic_num1[ext+i]  > k_info[lookup_kind(tval, i)].pval * (p_ptr->magic_num2[ext+i] - 1) * EATER_ROD_CHARGE)
4959                                 {
4960 #ifdef JP
4961                                         msg_print("¤½¤ÎËâË¡¤Ï¤Þ¤À½¼Å¶¤·¤Æ¤¤¤ëºÇÃæ¤À¡£");
4962 #else
4963                                         msg_print("The magic are still charging.");
4964 #endif
4965                                         msg_print(NULL);
4966                                         if (use_menu) ask = TRUE;
4967                                         continue;
4968                                 }
4969                         }
4970                         else
4971                         {
4972                                 if (p_ptr->magic_num1[ext+i] < EATER_CHARGE)
4973                                 {
4974 #ifdef JP
4975                                         msg_print("¤½¤ÎËâË¡¤Ï»ÈÍѲó¿ô¤¬ÀÚ¤ì¤Æ¤¤¤ë¡£");
4976 #else
4977                                         msg_print("The magic has no charges left.");
4978 #endif
4979                                         msg_print(NULL);
4980                                         if (use_menu) ask = TRUE;
4981                                         continue;
4982                                 }
4983                         }
4984                 }
4985
4986                 /* Browse */
4987                 else
4988                 {
4989                         int line, j;
4990                         char temp[70 * 20];
4991
4992                         /* Clear lines, position cursor  (really should use strlen here) */
4993                         Term_erase(7, 23, 255);
4994                         Term_erase(7, 22, 255);
4995                         Term_erase(7, 21, 255);
4996                         Term_erase(7, 20, 255);
4997
4998                         roff_to_buf(k_text + k_info[lookup_kind(tval, i)].text, 62, temp, sizeof(temp));
4999                         for (j = 0, line = 21; temp[j]; j += 1 + strlen(&temp[j]))
5000                         {
5001                                 prt(&temp[j], line, 10);
5002                                 line++;
5003                         }
5004
5005                         continue;
5006                 }
5007
5008                 /* Stop the loop */
5009                 flag = TRUE;
5010         }
5011
5012         /* Restore the screen */
5013         screen_load();
5014
5015         if (!flag) return -1;
5016
5017 #ifdef ALLOW_REPEAT
5018         repeat_push(ext+i);
5019 #endif /* ALLOW_REPEAT */
5020         return ext+i;
5021 }
5022
5023
5024 /*
5025  *  Use eaten rod, wand or staff
5026  */
5027 bool do_cmd_magic_eater(bool only_browse, bool powerful)
5028 {
5029         int item, chance, level, k_idx, tval, sval;
5030         bool use_charge = TRUE;
5031
5032         /* Not when confused */
5033         if (!only_browse && p_ptr->confused)
5034         {
5035 #ifdef JP
5036 msg_print("º®Í𤷤Ƥ¤¤Æ¾§¤¨¤é¤ì¤Ê¤¤¡ª");
5037 #else
5038                 msg_print("You are too confused!");
5039 #endif
5040
5041                 return FALSE;
5042         }
5043
5044         item = select_magic_eater(only_browse);
5045         if (item == -1)
5046         {
5047                 energy_use = 0;
5048                 return FALSE;
5049         }
5050         if (item >= EATER_EXT*2) {tval = TV_ROD;sval = item - EATER_EXT*2;}
5051         else if (item >= EATER_EXT) {tval = TV_WAND;sval = item - EATER_EXT;}
5052         else {tval = TV_STAFF;sval = item;}
5053         k_idx = lookup_kind(tval, sval);
5054
5055         level = (tval == TV_ROD ? k_info[k_idx].level * 5 / 6 - 5 : k_info[k_idx].level);
5056         chance = level * 4 / 5 + 20;
5057         chance -= 3 * (adj_mag_stat[p_ptr->stat_ind[mp_ptr->spell_stat]] - 1);
5058         level /= 2;
5059         if (p_ptr->lev > level)
5060         {
5061                 chance -= 3 * (p_ptr->lev - level);
5062         }
5063         chance = mod_spell_chance_1(chance);
5064         chance = MAX(chance, adj_mag_fail[p_ptr->stat_ind[mp_ptr->spell_stat]]);
5065         /* Stunning makes spells harder */
5066         if (p_ptr->stun > 50) chance += 25;
5067         else if (p_ptr->stun) chance += 15;
5068
5069         if (chance > 95) chance = 95;
5070
5071         chance = mod_spell_chance_2(chance);
5072
5073         if (randint0(100) < chance)
5074         {
5075                 if (flush_failure) flush();
5076
5077 #ifdef JP
5078 msg_print("¼öʸ¤ò¤¦¤Þ¤¯¾§¤¨¤é¤ì¤Ê¤«¤Ã¤¿¡ª");
5079 #else
5080                 msg_format("You failed to get the magic off!");
5081 #endif
5082
5083                 sound(SOUND_FAIL);
5084                 if (randint1(100) >= chance)
5085                         chg_virtue(V_CHANCE,-1);
5086                 energy_use = 100;
5087
5088                 return TRUE;
5089         }
5090         else
5091         {
5092                 int dir = 0;
5093
5094                 if (tval == TV_ROD)
5095                 {
5096                         if ((sval >= SV_ROD_MIN_DIRECTION) && (sval != SV_ROD_HAVOC) && (sval != SV_ROD_AGGRAVATE) && (sval != SV_ROD_PESTICIDE))
5097                                 if (!get_aim_dir(&dir)) return FALSE;
5098                         rod_effect(sval, dir, &use_charge, powerful, TRUE);
5099                         if (!use_charge) return FALSE;
5100                 }
5101                 else if (tval == TV_WAND)
5102                 {
5103                         if (!get_aim_dir(&dir)) return FALSE;
5104                         wand_effect(sval, dir, powerful, TRUE);
5105                 }
5106                 else
5107                 {
5108                         staff_effect(sval, &use_charge, powerful, TRUE, TRUE);
5109                         if (!use_charge) return FALSE;
5110                 }
5111                 if (randint1(100) < chance)
5112                         chg_virtue(V_CHANCE,1);
5113         }
5114         energy_use = 100;
5115         if (tval == TV_ROD) p_ptr->magic_num1[item] += k_info[k_idx].pval * EATER_ROD_CHARGE;
5116         else p_ptr->magic_num1[item] -= EATER_CHARGE;
5117
5118         return TRUE;
5119 }