OSDN Git Service

Rearrange header comments to cmd*.c
[hengband/hengband.git] / src / cmd6.c
1 /*!
2  *  @file cmd6.c
3  *  @brief ¥×¥ì¥¤¥ä¡¼¤Î¥¢¥¤¥Æ¥à¤Ë´Ø¤¹¤ë¥³¥Þ¥ó¥É¤Î¼ÂÁõ2 / Spell/Prayer commands
4  *  @date 2014/01/02
5  *  @author
6  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
7  *
8  * This software may be copied and distributed for educational, research,
9  * and not for profit purposes provided that this copyright and statement
10  * are included in all such copies.  Other copyrights may also apply.
11  */
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
1584
1585         /* Get the item (in the pack) */
1586         if (item >= 0)
1587         {
1588                 o_ptr = &inventory[item];
1589         }
1590
1591         /* Get the item (on the floor) */
1592         else
1593         {
1594                 o_ptr = &o_list[0 - item];
1595         }
1596
1597
1598         /* Take a turn */
1599         energy_use = 100;
1600
1601         if (world_player)
1602         {
1603                 if (flush_failure) flush();
1604 #ifdef JP
1605                 msg_print("»ß¤Þ¤Ã¤¿»þ¤ÎÃæ¤Ç¤Ï¤¦¤Þ¤¯Æ¯¤«¤Ê¤¤¤è¤¦¤À¡£");
1606 #else
1607                 msg_print("Nothing happen.");
1608 #endif
1609
1610                 sound(SOUND_FAIL);
1611                 return;
1612         }
1613
1614         if (p_ptr->pclass == CLASS_BERSERKER)
1615         {
1616 #ifdef JP
1617                 msg_print("´¬Êª¤Ê¤ó¤ÆÆɤá¤Ê¤¤¡£");
1618 #else
1619                 msg_print("You cannot read.");
1620 #endif
1621                 return;
1622         }
1623
1624         if (music_singing_any()) stop_singing();
1625
1626         /* Hex */
1627         if (hex_spelling_any() && ((p_ptr->lev < 35) || hex_spell_fully())) stop_hex_spell_all();
1628
1629         /* Not identified yet */
1630         ident = FALSE;
1631
1632         /* Object level */
1633         lev = k_info[o_ptr->k_idx].level;
1634
1635         /* Assume the scroll will get used up */
1636         used_up = TRUE;
1637
1638         if (o_ptr->tval == TV_SCROLL)
1639         {
1640         /* Analyze the scroll */
1641         switch (o_ptr->sval)
1642         {
1643                 case SV_SCROLL_DARKNESS:
1644                 {
1645                         if (!(p_ptr->resist_blind) && !(p_ptr->resist_dark))
1646                         {
1647                                 (void)set_blind(p_ptr->blind + 3 + randint1(5));
1648                         }
1649                         if (unlite_area(10, 3)) ident = TRUE;
1650                         break;
1651                 }
1652
1653                 case SV_SCROLL_AGGRAVATE_MONSTER:
1654                 {
1655 #ifdef JP
1656                         msg_print("¥«¥ó¹â¤¯¤¦¤Ê¤ëÍͤʲ»¤¬ÊÕ¤ê¤òʤ¤Ã¤¿¡£");
1657 #else
1658                         msg_print("There is a high pitched humming noise.");
1659 #endif
1660
1661                         aggravate_monsters(0);
1662                         ident = TRUE;
1663                         break;
1664                 }
1665
1666                 case SV_SCROLL_CURSE_ARMOR:
1667                 {
1668                         if (curse_armor()) ident = TRUE;
1669                         break;
1670                 }
1671
1672                 case SV_SCROLL_CURSE_WEAPON:
1673                 {
1674                         k = 0;
1675                         if (buki_motteruka(INVEN_RARM))
1676                         {
1677                                 k = INVEN_RARM;
1678                                 if (buki_motteruka(INVEN_LARM) && one_in_(2)) k = INVEN_LARM;
1679                         }
1680                         else if (buki_motteruka(INVEN_LARM)) k = INVEN_LARM;
1681                         if (k && curse_weapon(FALSE, k)) ident = TRUE;
1682                         break;
1683                 }
1684
1685                 case SV_SCROLL_SUMMON_MONSTER:
1686                 {
1687                         for (k = 0; k < randint1(3); k++)
1688                         {
1689                                 if (summon_specific(0, py, px, dun_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
1690                                 {
1691                                         ident = TRUE;
1692                                 }
1693                         }
1694                         break;
1695                 }
1696
1697                 case SV_SCROLL_SUMMON_UNDEAD:
1698                 {
1699                         for (k = 0; k < randint1(3); k++)
1700                         {
1701                                 if (summon_specific(0, py, px, dun_level, SUMMON_UNDEAD, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
1702                                 {
1703                                         ident = TRUE;
1704                                 }
1705                         }
1706                         break;
1707                 }
1708
1709                 case SV_SCROLL_SUMMON_PET:
1710                 {
1711                         if (summon_specific(-1, py, px, dun_level, 0, (PM_ALLOW_GROUP | PM_FORCE_PET)))
1712                         {
1713                                 ident = TRUE;
1714                         }
1715                         break;
1716                 }
1717
1718                 case SV_SCROLL_SUMMON_KIN:
1719                 {
1720                         if (summon_kin_player(p_ptr->lev, py, px, (PM_FORCE_PET | PM_ALLOW_GROUP)))
1721                         {
1722                                 ident = TRUE;
1723                         }
1724                         break;
1725                 }
1726
1727                 case SV_SCROLL_TRAP_CREATION:
1728                 {
1729                         if (trap_creation(py, px)) ident = TRUE;
1730                         break;
1731                 }
1732
1733                 case SV_SCROLL_PHASE_DOOR:
1734                 {
1735                         teleport_player(10, 0L);
1736                         ident = TRUE;
1737                         break;
1738                 }
1739
1740                 case SV_SCROLL_TELEPORT:
1741                 {
1742                         teleport_player(100, 0L);
1743                         ident = TRUE;
1744                         break;
1745                 }
1746
1747                 case SV_SCROLL_TELEPORT_LEVEL:
1748                 {
1749                         (void)teleport_level(0);
1750                         ident = TRUE;
1751                         break;
1752                 }
1753
1754                 case SV_SCROLL_WORD_OF_RECALL:
1755                 {
1756                         if (!word_of_recall()) used_up = FALSE;
1757                         ident = TRUE;
1758                         break;
1759                 }
1760
1761                 case SV_SCROLL_IDENTIFY:
1762                 {
1763                         if (!ident_spell(FALSE)) used_up = FALSE;
1764                         ident = TRUE;
1765                         break;
1766                 }
1767
1768                 case SV_SCROLL_STAR_IDENTIFY:
1769                 {
1770                         if (!identify_fully(FALSE)) used_up = FALSE;
1771                         ident = TRUE;
1772                         break;
1773                 }
1774
1775                 case SV_SCROLL_REMOVE_CURSE:
1776                 {
1777                         if (remove_curse())
1778                         {
1779 #ifdef JP
1780                                 msg_print("狼¤Ë¸«¼é¤é¤ì¤Æ¤¤¤ë¤è¤¦¤Êµ¤¤¬¤¹¤ë¡£");
1781 #else
1782                                 msg_print("You feel as if someone is watching over you.");
1783 #endif
1784
1785                                 ident = TRUE;
1786                         }
1787                         break;
1788                 }
1789
1790                 case SV_SCROLL_STAR_REMOVE_CURSE:
1791                 {
1792                         if (remove_all_curse())
1793                         {
1794 #ifdef JP
1795                                 msg_print("狼¤Ë¸«¼é¤é¤ì¤Æ¤¤¤ë¤è¤¦¤Êµ¤¤¬¤¹¤ë¡£");
1796 #else
1797                                 msg_print("You feel as if someone is watching over you.");
1798 #endif
1799                         }
1800                         ident = TRUE;
1801                         break;
1802                 }
1803
1804                 case SV_SCROLL_ENCHANT_ARMOR:
1805                 {
1806                         ident = TRUE;
1807                         if (!enchant_spell(0, 0, 1)) used_up = FALSE;
1808                         break;
1809                 }
1810
1811                 case SV_SCROLL_ENCHANT_WEAPON_TO_HIT:
1812                 {
1813                         if (!enchant_spell(1, 0, 0)) used_up = FALSE;
1814                         ident = TRUE;
1815                         break;
1816                 }
1817
1818                 case SV_SCROLL_ENCHANT_WEAPON_TO_DAM:
1819                 {
1820                         if (!enchant_spell(0, 1, 0)) used_up = FALSE;
1821                         ident = TRUE;
1822                         break;
1823                 }
1824
1825                 case SV_SCROLL_STAR_ENCHANT_ARMOR:
1826                 {
1827                         if (!enchant_spell(0, 0, randint1(3) + 2)) used_up = FALSE;
1828                         ident = TRUE;
1829                         break;
1830                 }
1831
1832                 case SV_SCROLL_STAR_ENCHANT_WEAPON:
1833                 {
1834                         if (!enchant_spell(randint1(3), randint1(3), 0)) used_up = FALSE;
1835                         ident = TRUE;
1836                         break;
1837                 }
1838
1839                 case SV_SCROLL_RECHARGING:
1840                 {
1841                         if (!recharge(130)) used_up = FALSE;
1842                         ident = TRUE;
1843                         break;
1844                 }
1845
1846                 case SV_SCROLL_MUNDANITY:
1847                 {
1848                         ident = TRUE;
1849                         if (!mundane_spell(FALSE)) used_up = FALSE;
1850                         break;
1851                 }
1852
1853                 case SV_SCROLL_LIGHT:
1854                 {
1855                         if (lite_area(damroll(2, 8), 2)) ident = TRUE;
1856                         break;
1857                 }
1858
1859                 case SV_SCROLL_MAPPING:
1860                 {
1861                         map_area(DETECT_RAD_MAP);
1862                         ident = TRUE;
1863                         break;
1864                 }
1865
1866                 case SV_SCROLL_DETECT_GOLD:
1867                 {
1868                         if (detect_treasure(DETECT_RAD_DEFAULT)) ident = TRUE;
1869                         if (detect_objects_gold(DETECT_RAD_DEFAULT)) ident = TRUE;
1870                         break;
1871                 }
1872
1873                 case SV_SCROLL_DETECT_ITEM:
1874                 {
1875                         if (detect_objects_normal(DETECT_RAD_DEFAULT)) ident = TRUE;
1876                         break;
1877                 }
1878
1879                 case SV_SCROLL_DETECT_TRAP:
1880                 {
1881                         if (detect_traps(DETECT_RAD_DEFAULT, known)) ident = TRUE;
1882                         break;
1883                 }
1884
1885                 case SV_SCROLL_DETECT_DOOR:
1886                 {
1887                         if (detect_doors(DETECT_RAD_DEFAULT)) ident = TRUE;
1888                         if (detect_stairs(DETECT_RAD_DEFAULT)) ident = TRUE;
1889                         break;
1890                 }
1891
1892                 case SV_SCROLL_DETECT_INVIS:
1893                 {
1894                         if (detect_monsters_invis(DETECT_RAD_DEFAULT)) ident = TRUE;
1895                         break;
1896                 }
1897
1898                 case SV_SCROLL_SATISFY_HUNGER:
1899                 {
1900                         if (set_food(PY_FOOD_MAX - 1)) ident = TRUE;
1901                         break;
1902                 }
1903
1904                 case SV_SCROLL_BLESSING:
1905                 {
1906                         if (set_blessed(p_ptr->blessed + randint1(12) + 6, FALSE)) ident = TRUE;
1907                         break;
1908                 }
1909
1910                 case SV_SCROLL_HOLY_CHANT:
1911                 {
1912                         if (set_blessed(p_ptr->blessed + randint1(24) + 12, FALSE)) ident = TRUE;
1913                         break;
1914                 }
1915
1916                 case SV_SCROLL_HOLY_PRAYER:
1917                 {
1918                         if (set_blessed(p_ptr->blessed + randint1(48) + 24, FALSE)) ident = TRUE;
1919                         break;
1920                 }
1921
1922                 case SV_SCROLL_MONSTER_CONFUSION:
1923                 {
1924                         if (!(p_ptr->special_attack & ATTACK_CONFUSE))
1925                         {
1926 #ifdef JP
1927                                 msg_print("¼ê¤¬µ±¤­»Ï¤á¤¿¡£");
1928 #else
1929                                 msg_print("Your hands begin to glow.");
1930 #endif
1931
1932                                 p_ptr->special_attack |= ATTACK_CONFUSE;
1933                                 p_ptr->redraw |= (PR_STATUS);
1934                                 ident = TRUE;
1935                         }
1936                         break;
1937                 }
1938
1939                 case SV_SCROLL_PROTECTION_FROM_EVIL:
1940                 {
1941                         k = 3 * p_ptr->lev;
1942                         if (set_protevil(p_ptr->protevil + randint1(25) + k, FALSE)) ident = TRUE;
1943                         break;
1944                 }
1945
1946                 case SV_SCROLL_RUNE_OF_PROTECTION:
1947                 {
1948                         warding_glyph();
1949                         ident = TRUE;
1950                         break;
1951                 }
1952
1953                 case SV_SCROLL_TRAP_DOOR_DESTRUCTION:
1954                 {
1955                         if (destroy_doors_touch()) ident = TRUE;
1956                         break;
1957                 }
1958
1959                 case SV_SCROLL_STAR_DESTRUCTION:
1960                 {
1961                         if (destroy_area(py, px, 13 + randint0(5), FALSE))
1962                                 ident = TRUE;
1963                         else
1964 #ifdef JP
1965 msg_print("¥À¥ó¥¸¥ç¥ó¤¬Íɤ줿...");
1966 #else
1967                                 msg_print("The dungeon trembles...");
1968 #endif
1969
1970
1971                         break;
1972                 }
1973
1974                 case SV_SCROLL_DISPEL_UNDEAD:
1975                 {
1976                         if (dispel_undead(80)) ident = TRUE;
1977                         break;
1978                 }
1979
1980                 case SV_SCROLL_SPELL:
1981                 {
1982                         if ((p_ptr->pclass == CLASS_WARRIOR) ||
1983                                 (p_ptr->pclass == CLASS_IMITATOR) ||
1984                                 (p_ptr->pclass == CLASS_MINDCRAFTER) ||
1985                                 (p_ptr->pclass == CLASS_SORCERER) ||
1986                                 (p_ptr->pclass == CLASS_ARCHER) ||
1987                                 (p_ptr->pclass == CLASS_MAGIC_EATER) ||
1988                                 (p_ptr->pclass == CLASS_RED_MAGE) ||
1989                                 (p_ptr->pclass == CLASS_SAMURAI) ||
1990                                 (p_ptr->pclass == CLASS_BLUE_MAGE) ||
1991                                 (p_ptr->pclass == CLASS_CAVALRY) ||
1992                                 (p_ptr->pclass == CLASS_BERSERKER) ||
1993                                 (p_ptr->pclass == CLASS_SMITH) ||
1994                                 (p_ptr->pclass == CLASS_MIRROR_MASTER) ||
1995                                 (p_ptr->pclass == CLASS_NINJA) ||
1996                                 (p_ptr->pclass == CLASS_SNIPER)) break;
1997                         p_ptr->add_spells++;
1998                         p_ptr->update |= (PU_SPELLS);
1999                         ident = TRUE;
2000                         break;
2001                 }
2002
2003                 case SV_SCROLL_GENOCIDE:
2004                 {
2005                         (void)symbol_genocide(300, TRUE);
2006                         ident = TRUE;
2007                         break;
2008                 }
2009
2010                 case SV_SCROLL_MASS_GENOCIDE:
2011                 {
2012                         (void)mass_genocide(300, TRUE);
2013                         ident = TRUE;
2014                         break;
2015                 }
2016
2017                 case SV_SCROLL_ACQUIREMENT:
2018                 {
2019                         acquirement(py, px, 1, TRUE, FALSE, FALSE);
2020                         ident = TRUE;
2021                         break;
2022                 }
2023
2024                 case SV_SCROLL_STAR_ACQUIREMENT:
2025                 {
2026                         acquirement(py, px, randint1(2) + 1, TRUE, FALSE, FALSE);
2027                         ident = TRUE;
2028                         break;
2029                 }
2030
2031                 /* New Hengband scrolls */
2032                 case SV_SCROLL_FIRE:
2033                 {
2034                         fire_ball(GF_FIRE, 0, 666, 4);
2035                         /* Note: "Double" damage since it is centered on the player ... */
2036                         if (!(IS_OPPOSE_FIRE() || p_ptr->resist_fire || p_ptr->immune_fire))
2037 #ifdef JP
2038 take_hit(DAMAGE_NOESCAPE, 50+randint1(50), "±ê¤Î´¬Êª", -1);
2039 #else
2040                                 take_hit(DAMAGE_NOESCAPE, 50 + randint1(50), "a Scroll of Fire", -1);
2041 #endif
2042
2043                         ident = TRUE;
2044                         break;
2045                 }
2046
2047
2048                 case SV_SCROLL_ICE:
2049                 {
2050                         fire_ball(GF_ICE, 0, 777, 4);
2051                         if (!(IS_OPPOSE_COLD() || p_ptr->resist_cold || p_ptr->immune_cold))
2052 #ifdef JP
2053 take_hit(DAMAGE_NOESCAPE, 100+randint1(100), "ɹ¤Î´¬Êª", -1);
2054 #else
2055                                 take_hit(DAMAGE_NOESCAPE, 100 + randint1(100), "a Scroll of Ice", -1);
2056 #endif
2057
2058                         ident = TRUE;
2059                         break;
2060                 }
2061
2062                 case SV_SCROLL_CHAOS:
2063                 {
2064                         fire_ball(GF_CHAOS, 0, 1000, 4);
2065                         if (!p_ptr->resist_chaos)
2066 #ifdef JP
2067 take_hit(DAMAGE_NOESCAPE, 111+randint1(111), "¥í¥°¥ë¥¹¤Î´¬Êª", -1);
2068 #else
2069                                 take_hit(DAMAGE_NOESCAPE, 111 + randint1(111), "a Scroll of Logrus", -1);
2070 #endif
2071
2072                         ident = TRUE;
2073                         break;
2074                 }
2075
2076                 case SV_SCROLL_RUMOR:
2077                 {
2078 #ifdef JP
2079                         msg_print("´¬Êª¤Ë¤Ï¥á¥Ã¥»¡¼¥¸¤¬½ñ¤«¤ì¤Æ¤¤¤ë:");
2080 #else
2081                         msg_print("There is message on the scroll. It says:");
2082 #endif
2083
2084                         msg_print(NULL);
2085                         display_rumor(TRUE);
2086                         msg_print(NULL);
2087 #ifdef JP
2088                         msg_print("´¬Êª¤Ï±ì¤òΩ¤Æ¤Æ¾Ã¤¨µî¤Ã¤¿¡ª");
2089 #else
2090                         msg_print("The scroll disappears in a puff of smoke!");
2091 #endif
2092
2093                         ident = TRUE;
2094                         break;
2095                 }
2096
2097                 case SV_SCROLL_ARTIFACT:
2098                 {
2099                         ident = TRUE;
2100                         if (!artifact_scroll()) used_up = FALSE;
2101                         break;
2102                 }
2103
2104                 case SV_SCROLL_RESET_RECALL:
2105                 {
2106                         ident = TRUE;
2107                         if (!reset_recall()) used_up = FALSE;
2108                         break;
2109                 }
2110
2111                 case SV_SCROLL_AMUSEMENT:
2112                 {
2113                         ident = TRUE;
2114                         amusement(py, px, 1, FALSE);
2115                         break;
2116                 }
2117
2118                 case SV_SCROLL_STAR_AMUSEMENT:
2119                 {
2120                         ident = TRUE;
2121                         amusement(py, px,  randint1(2) + 1, FALSE);
2122                         break;
2123                 }
2124         }
2125         }
2126         else if (o_ptr->name1 == ART_GHB)
2127         {
2128 #ifdef JP
2129                 msg_print("»ä¤Ï¶ìÏ«¤·¤Æ¡Ø¥°¥ì¡¼¥¿¡¼¡¦¥Ø¥ë=¥Ó¡¼¥¹¥È¡Ù¤òÅݤ·¤¿¡£");
2130                 msg_print("¤·¤«¤·¼ê¤ËÆþ¤Ã¤¿¤Î¤Ï¤³¤Î¤­¤¿¤Ê¤¤£Ô¥·¥ã¥Ä¤À¤±¤À¤Ã¤¿¡£");
2131 #else
2132                 msg_print("I had a very hard time to kill the Greater hell-beast, ");
2133                 msg_print("but all I got was this lousy t-shirt!");
2134 #endif
2135                 used_up = FALSE;
2136         }
2137         else if (o_ptr->name1 == ART_POWER)
2138         {
2139 #ifdef JP
2140                 msg_print("¡Ö°ì¤Ä¤Î»ØÎؤÏÁ´¤Æ¤òÅý¤Ù¡¢");
2141                 msg_print(NULL);
2142                 msg_print("°ì¤Ä¤Î»ØÎؤÏÁ´¤Æ¤ò¸«¤Ä¤±¡¢");
2143                 msg_print(NULL);
2144                 msg_print("°ì¤Ä¤Î»ØÎؤÏÁ´¤Æ¤òÊá¤é¤¨¤Æ");
2145                 msg_print(NULL);
2146                 msg_print("°Å°Ç¤ÎÃæ¤Ë·Ò¤®¤È¤á¤ë¡£¡×");
2147 #else
2148                 msg_print("'One Ring to rule them all, ");
2149                 msg_print(NULL);
2150                 msg_print("One Ring to find them, ");
2151                 msg_print(NULL);
2152                 msg_print("One Ring to bring them all ");
2153                 msg_print(NULL);
2154                 msg_print("and in the darkness bind them.'");
2155 #endif
2156                 used_up = FALSE;
2157         }
2158         else if (o_ptr->tval==TV_PARCHMENT)
2159         {
2160                 cptr q;
2161                 char o_name[MAX_NLEN];
2162                 char buf[1024];
2163
2164                 /* Save screen */
2165                 screen_save();
2166
2167                 q=format("book-%d_jp.txt",o_ptr->sval);
2168
2169                 /* Display object description */
2170                 object_desc(o_name, o_ptr, OD_NAME_ONLY);
2171
2172                 /* Build the filename */
2173                 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, q);
2174
2175                 /* Peruse the help file */
2176                 (void)show_file(TRUE, buf, o_name, 0, 0);
2177
2178                 /* Load screen */
2179                 screen_load();
2180
2181                 used_up=FALSE;
2182         }
2183
2184
2185         /* Combine / Reorder the pack (later) */
2186         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
2187
2188         if (!(object_is_aware(o_ptr)))
2189         {
2190                 chg_virtue(V_PATIENCE, -1);
2191                 chg_virtue(V_CHANCE, 1);
2192                 chg_virtue(V_KNOWLEDGE, -1);
2193         }
2194
2195         /* The item was tried */
2196         object_tried(o_ptr);
2197
2198         /* An identification was made */
2199         if (ident && !object_is_aware(o_ptr))
2200         {
2201                 object_aware(o_ptr);
2202                 gain_exp((lev + (p_ptr->lev >> 1)) / p_ptr->lev);
2203         }
2204
2205         /* Window stuff */
2206         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
2207
2208
2209         /* Hack -- allow certain scrolls to be "preserved" */
2210         if (!used_up)
2211         {
2212                 return;
2213         }
2214
2215         sound(SOUND_SCROLL);
2216
2217         /* Destroy a scroll in the pack */
2218         if (item >= 0)
2219         {
2220                 inven_item_increase(item, -1);
2221                 inven_item_describe(item);
2222                 inven_item_optimize(item);
2223         }
2224
2225         /* Destroy a scroll on the floor */
2226         else
2227         {
2228                 floor_item_increase(0 - item, -1);
2229                 floor_item_describe(0 - item);
2230                 floor_item_optimize(0 - item);
2231         }
2232 }
2233
2234
2235 /*
2236  * Hook to determine if an object is readable
2237  */
2238 static bool item_tester_hook_readable(object_type *o_ptr)
2239 {
2240         if ((o_ptr->tval==TV_SCROLL) || (o_ptr->tval==TV_PARCHMENT) || (o_ptr->name1 == ART_GHB) || (o_ptr->name1 == ART_POWER)) return (TRUE);
2241
2242         /* Assume not */
2243         return (FALSE);
2244 }
2245
2246
2247 void do_cmd_read_scroll(void)
2248 {
2249         object_type *o_ptr;
2250         int  item;
2251         cptr q, s;
2252
2253         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
2254         {
2255                 set_action(ACTION_NONE);
2256         }
2257
2258         /* Check some conditions */
2259         if (p_ptr->blind)
2260         {
2261 #ifdef JP
2262                 msg_print("Ìܤ¬¸«¤¨¤Ê¤¤¡£");
2263 #else
2264                 msg_print("You can't see anything.");
2265 #endif
2266
2267                 return;
2268         }
2269         if (no_lite())
2270         {
2271 #ifdef JP
2272                 msg_print("ÌÀ¤«¤ê¤¬¤Ê¤¤¤Î¤Ç¡¢°Å¤¯¤ÆÆɤá¤Ê¤¤¡£");
2273 #else
2274                 msg_print("You have no light to read by.");
2275 #endif
2276
2277                 return;
2278         }
2279         if (p_ptr->confused)
2280         {
2281 #ifdef JP
2282                 msg_print("º®Í𤷤Ƥ¤¤ÆÆɤá¤Ê¤¤¡£");
2283 #else
2284                 msg_print("You are too confused!");
2285 #endif
2286
2287                 return;
2288         }
2289
2290
2291         /* Restrict choices to scrolls */
2292         item_tester_hook = item_tester_hook_readable;
2293
2294         /* Get an item */
2295 #ifdef JP
2296         q = "¤É¤Î´¬Êª¤òÆɤߤޤ¹¤«? ";
2297         s = "Æɤá¤ë´¬Êª¤¬¤Ê¤¤¡£";
2298 #else
2299         q = "Read which scroll? ";
2300         s = "You have no scrolls to read.";
2301 #endif
2302
2303         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
2304
2305         /* Get the item (in the pack) */
2306         if (item >= 0)
2307         {
2308                 o_ptr = &inventory[item];
2309         }
2310
2311         /* Get the item (on the floor) */
2312         else
2313         {
2314                 o_ptr = &o_list[0 - item];
2315         }
2316
2317         /* Read the scroll */
2318         do_cmd_read_scroll_aux(item, object_is_aware(o_ptr));
2319 }
2320
2321
2322 static int staff_effect(int sval, bool *use_charge, bool powerful, bool magic, bool known)
2323 {
2324         int k;
2325         int ident = FALSE;
2326         int lev = powerful ? p_ptr->lev * 2 : p_ptr->lev;
2327         int detect_rad = powerful ? DETECT_RAD_DEFAULT * 3 / 2 : DETECT_RAD_DEFAULT;
2328
2329         /* Analyze the staff */
2330         switch (sval)
2331         {
2332                 case SV_STAFF_DARKNESS:
2333                 {
2334                         if (!(p_ptr->resist_blind) && !(p_ptr->resist_dark))
2335                         {
2336                                 if (set_blind(p_ptr->blind + 3 + randint1(5))) ident = TRUE;
2337                         }
2338                         if (unlite_area(10, (powerful ? 6 : 3))) ident = TRUE;
2339                         break;
2340                 }
2341
2342                 case SV_STAFF_SLOWNESS:
2343                 {
2344                         if (set_slow(p_ptr->slow + randint1(30) + 15, FALSE)) ident = TRUE;
2345                         break;
2346                 }
2347
2348                 case SV_STAFF_HASTE_MONSTERS:
2349                 {
2350                         if (speed_monsters()) ident = TRUE;
2351                         break;
2352                 }
2353
2354                 case SV_STAFF_SUMMONING:
2355                 {
2356                         const int times = randint1(powerful ? 8 : 4);
2357                         for (k = 0; k < times; k++)
2358                         {
2359                                 if (summon_specific(0, py, px, dun_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
2360                                 {
2361                                         ident = TRUE;
2362                                 }
2363                         }
2364                         break;
2365                 }
2366
2367                 case SV_STAFF_TELEPORTATION:
2368                 {
2369                         teleport_player((powerful ? 150 : 100), 0L);
2370                         ident = TRUE;
2371                         break;
2372                 }
2373
2374                 case SV_STAFF_IDENTIFY:
2375                 {
2376                         if (powerful) {
2377                                 if (!identify_fully(FALSE)) *use_charge = FALSE;
2378                         } else {
2379                                 if (!ident_spell(FALSE)) *use_charge = FALSE;
2380                         }
2381                         ident = TRUE;
2382                         break;
2383                 }
2384
2385                 case SV_STAFF_REMOVE_CURSE:
2386                 {
2387                         bool result = powerful ? remove_all_curse() : remove_curse();
2388                         if (result)
2389                         {
2390                                 if (magic)
2391                                 {
2392 #ifdef JP
2393                                         msg_print("狼¤Ë¸«¼é¤é¤ì¤Æ¤¤¤ë¤è¤¦¤Êµ¤¤¬¤¹¤ë¡£");
2394 #else
2395                                         msg_print("You feel as if someone is watching over you.");
2396 #endif
2397                                 }
2398                                 else if (!p_ptr->blind)
2399                                 {
2400 #ifdef JP
2401                                         msg_print("¾ó¤Ï°ì½Ö¥Ö¥ë¡¼¤Ëµ±¤¤¤¿...");
2402 #else
2403                                         msg_print("The staff glows blue for a moment...");
2404 #endif
2405
2406                                 }
2407                                 ident = TRUE;
2408                         }
2409                         break;
2410                 }
2411
2412                 case SV_STAFF_STARLITE:
2413                 {
2414                         int num = damroll(5, 3);
2415                         int y, x;
2416                         int attempts;
2417
2418                         if (!p_ptr->blind && !magic)
2419                         {
2420 #ifdef JP
2421                                 msg_print("¾ó¤ÎÀ褬ÌÀ¤ë¤¯µ±¤¤¤¿...");
2422 #else
2423                                 msg_print("The end of the staff glows brightly...");
2424 #endif
2425
2426                         }
2427                         for (k = 0; k < num; k++)
2428                         {
2429                                 attempts = 1000;
2430
2431                                 while (attempts--)
2432                                 {
2433                                         scatter(&y, &x, py, px, 4, 0);
2434
2435                                         if (!cave_have_flag_bold(y, x, FF_PROJECT)) continue;
2436
2437                                         if (!player_bold(y, x)) break;
2438                                 }
2439
2440                                 project(0, 0, y, x, damroll(6 + lev / 8, 10), GF_LITE_WEAK,
2441                                                   (PROJECT_BEAM | PROJECT_THRU | PROJECT_GRID | PROJECT_KILL), -1);
2442                         }
2443                         ident = TRUE;
2444                         break;
2445                 }
2446
2447                 case SV_STAFF_LITE:
2448                 {
2449                         if (lite_area(damroll(2, 8), (powerful ? 4 : 2))) ident = TRUE;
2450                         break;
2451                 }
2452
2453                 case SV_STAFF_MAPPING:
2454                 {
2455                         map_area(powerful ? DETECT_RAD_MAP * 3 / 2 : DETECT_RAD_MAP);
2456                         ident = TRUE;
2457                         break;
2458                 }
2459
2460                 case SV_STAFF_DETECT_GOLD:
2461                 {
2462                         if (detect_treasure(detect_rad)) ident = TRUE;
2463                         if (detect_objects_gold(detect_rad)) ident = TRUE;
2464                         break;
2465                 }
2466
2467                 case SV_STAFF_DETECT_ITEM:
2468                 {
2469                         if (detect_objects_normal(detect_rad)) ident = TRUE;
2470                         break;
2471                 }
2472
2473                 case SV_STAFF_DETECT_TRAP:
2474                 {
2475                         if (detect_traps(detect_rad, known)) ident = TRUE;
2476                         break;
2477                 }
2478
2479                 case SV_STAFF_DETECT_DOOR:
2480                 {
2481                         if (detect_doors(detect_rad)) ident = TRUE;
2482                         if (detect_stairs(detect_rad)) ident = TRUE;
2483                         break;
2484                 }
2485
2486                 case SV_STAFF_DETECT_INVIS:
2487                 {
2488                         if (detect_monsters_invis(detect_rad)) ident = TRUE;
2489                         break;
2490                 }
2491
2492                 case SV_STAFF_DETECT_EVIL:
2493                 {
2494                         if (detect_monsters_evil(detect_rad)) ident = TRUE;
2495                         break;
2496                 }
2497
2498                 case SV_STAFF_CURE_LIGHT:
2499                 {
2500                         if (hp_player(damroll((powerful ? 4 : 2), 8))) ident = TRUE;
2501                         if (powerful) {
2502                                 if (set_blind(0)) ident = TRUE;
2503                                 if (set_poisoned(0)) ident = TRUE;
2504                                 if (set_cut(p_ptr->cut - 10)) ident = TRUE;
2505                         }
2506                         if (set_shero(0,TRUE)) ident = TRUE;
2507                         break;
2508                 }
2509
2510                 case SV_STAFF_CURING:
2511                 {
2512                         if (set_blind(0)) ident = TRUE;
2513                         if (set_poisoned(0)) ident = TRUE;
2514                         if (set_confused(0)) ident = TRUE;
2515                         if (set_stun(0)) ident = TRUE;
2516                         if (set_cut(0)) ident = TRUE;
2517                         if (set_image(0)) ident = TRUE;
2518                         if (set_shero(0,TRUE)) ident = TRUE;
2519                         break;
2520                 }
2521
2522                 case SV_STAFF_HEALING:
2523                 {
2524                         if (hp_player(powerful ? 500 : 300)) ident = TRUE;
2525                         if (set_stun(0)) ident = TRUE;
2526                         if (set_cut(0)) ident = TRUE;
2527                         if (set_shero(0,TRUE)) ident = TRUE;
2528                         break;
2529                 }
2530
2531                 case SV_STAFF_THE_MAGI:
2532                 {
2533                         if (do_res_stat(A_INT)) ident = TRUE;
2534                         if (p_ptr->csp < p_ptr->msp)
2535                         {
2536                                 p_ptr->csp = p_ptr->msp;
2537                                 p_ptr->csp_frac = 0;
2538                                 ident = TRUE;
2539 #ifdef JP
2540                                 msg_print("Ƭ¤¬¥Ï¥Ã¥­¥ê¤È¤·¤¿¡£");
2541 #else
2542                                 msg_print("You feel your head clear.");
2543 #endif
2544
2545                                 p_ptr->redraw |= (PR_MANA);
2546                                 p_ptr->window |= (PW_PLAYER);
2547                                 p_ptr->window |= (PW_SPELL);
2548                         }
2549                         if (set_shero(0,TRUE)) ident = TRUE;
2550                         break;
2551                 }
2552
2553                 case SV_STAFF_SLEEP_MONSTERS:
2554                 {
2555                         if (sleep_monsters(lev)) ident = TRUE;
2556                         break;
2557                 }
2558
2559                 case SV_STAFF_SLOW_MONSTERS:
2560                 {
2561                         if (slow_monsters(lev)) ident = TRUE;
2562                         break;
2563                 }
2564
2565                 case SV_STAFF_SPEED:
2566                 {
2567                         if (set_fast(randint1(30) + (powerful ? 30 : 15), FALSE)) ident = TRUE;
2568                         break;
2569                 }
2570
2571                 case SV_STAFF_PROBING:
2572                 {
2573                         probing();
2574                         ident = TRUE;
2575                         break;
2576                 }
2577
2578                 case SV_STAFF_DISPEL_EVIL:
2579                 {
2580                         if (dispel_evil(powerful ? 120 : 80)) ident = TRUE;
2581                         break;
2582                 }
2583
2584                 case SV_STAFF_POWER:
2585                 {
2586                         if (dispel_monsters(powerful ? 225 : 150)) ident = TRUE;
2587                         break;
2588                 }
2589
2590                 case SV_STAFF_HOLINESS:
2591                 {
2592                         if (dispel_evil(powerful ? 225 : 150)) ident = TRUE;
2593                         k = 3 * lev;
2594                         if (set_protevil((magic ? 0 : p_ptr->protevil) + randint1(25) + k, FALSE)) ident = TRUE;
2595                         if (set_poisoned(0)) ident = TRUE;
2596                         if (set_afraid(0)) ident = TRUE;
2597                         if (hp_player(50)) ident = TRUE;
2598                         if (set_stun(0)) ident = TRUE;
2599                         if (set_cut(0)) ident = TRUE;
2600                         break;
2601                 }
2602
2603                 case SV_STAFF_GENOCIDE:
2604                 {
2605                         (void)symbol_genocide((magic ? lev + 50 : 200), TRUE);
2606                         ident = TRUE;
2607                         break;
2608                 }
2609
2610                 case SV_STAFF_EARTHQUAKES:
2611                 {
2612                         if (earthquake(py, px, (powerful ? 15 : 10)))
2613                                 ident = TRUE;
2614                         else
2615 #ifdef JP
2616 msg_print("¥À¥ó¥¸¥ç¥ó¤¬Íɤ줿¡£");
2617 #else
2618                                 msg_print("The dungeon trembles.");
2619 #endif
2620
2621
2622                         break;
2623                 }
2624
2625                 case SV_STAFF_DESTRUCTION:
2626                 {
2627                         if (destroy_area(py, px, (powerful ? 18 : 13) + randint0(5), FALSE))
2628                                 ident = TRUE;
2629
2630                         break;
2631                 }
2632
2633                 case SV_STAFF_ANIMATE_DEAD:
2634                 {
2635                         if (animate_dead(0, py, px))
2636                                 ident = TRUE;
2637
2638                         break;
2639                 }
2640
2641                 case SV_STAFF_MSTORM:
2642                 {
2643 #ifdef JP
2644                         msg_print("¶¯ÎϤÊËâÎϤ¬Å¨¤ò°ú¤­Îö¤¤¤¿¡ª");
2645 #else
2646                         msg_print("Mighty magics rend your enemies!");
2647 #endif
2648                         project(0, (powerful ? 7 : 5), py, px,
2649                                 (randint1(200) + (powerful ? 500 : 300)) * 2, GF_MANA, PROJECT_KILL | PROJECT_ITEM | PROJECT_GRID, -1);
2650                         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))
2651                         {
2652 #ifdef JP
2653                                 (void)take_hit(DAMAGE_NOESCAPE, 50, "¥³¥ó¥È¥í¡¼¥ë¤·Æñ¤¤¶¯ÎϤÊËâÎϤβòÊü", -1);
2654 #else
2655                                 (void)take_hit(DAMAGE_NOESCAPE, 50, "unleashing magics too mighty to control", -1);
2656 #endif
2657                         }
2658                         ident = TRUE;
2659
2660                         break;
2661                 }
2662
2663                 case SV_STAFF_NOTHING:
2664                 {
2665 #ifdef JP
2666                         msg_print("²¿¤âµ¯¤é¤Ê¤«¤Ã¤¿¡£");
2667 #else
2668                         msg_print("Nothing happen.");
2669 #endif
2670                         if (prace_is_(RACE_SKELETON) || prace_is_(RACE_GOLEM) ||
2671                                 prace_is_(RACE_ZOMBIE) || prace_is_(RACE_SPECTRE))
2672 #ifdef JP
2673                                 msg_print("¤â¤Ã¤¿¤¤¤Ê¤¤»ö¤ò¤·¤¿¤è¤¦¤Êµ¤¤¬¤¹¤ë¡£¿©¤Ùʪ¤ÏÂçÀڤˤ·¤Ê¤¯¤Æ¤Ï¡£");
2674 #else
2675                                 msg_print("What a waste.  It's your food!");
2676 #endif
2677                         break;
2678                 }
2679         }
2680         return ident;
2681 }
2682
2683 /*
2684  * Use a staff.                 -RAK-
2685  *
2686  * One charge of one staff disappears.
2687  *
2688  * Hack -- staffs of identify can be "cancelled".
2689  */
2690 static void do_cmd_use_staff_aux(int item)
2691 {
2692         int         ident, chance, lev;
2693         object_type *o_ptr;
2694
2695
2696         /* Hack -- let staffs of identify get aborted */
2697         bool use_charge = TRUE;
2698
2699
2700         /* Get the item (in the pack) */
2701         if (item >= 0)
2702         {
2703                 o_ptr = &inventory[item];
2704         }
2705
2706         /* Get the item (on the floor) */
2707         else
2708         {
2709                 o_ptr = &o_list[0 - item];
2710         }
2711
2712
2713         /* Mega-Hack -- refuse to use a pile from the ground */
2714         if ((item < 0) && (o_ptr->number > 1))
2715         {
2716 #ifdef JP
2717                 msg_print("¤Þ¤º¤Ï¾ó¤ò½¦¤ï¤Ê¤±¤ì¤Ð¡£");
2718 #else
2719                 msg_print("You must first pick up the staffs.");
2720 #endif
2721
2722                 return;
2723         }
2724
2725
2726         /* Take a turn */
2727         energy_use = 100;
2728
2729         /* Extract the item level */
2730         lev = k_info[o_ptr->k_idx].level;
2731         if (lev > 50) lev = 50 + (lev - 50)/2;
2732
2733         /* Base chance of success */
2734         chance = p_ptr->skill_dev;
2735
2736         /* Confusion hurts skill */
2737         if (p_ptr->confused) chance = chance / 2;
2738
2739         /* Hight level objects are harder */
2740         chance = chance - lev;
2741
2742         /* Give everyone a (slight) chance */
2743         if ((chance < USE_DEVICE) && one_in_(USE_DEVICE - chance + 1))
2744         {
2745                 chance = USE_DEVICE;
2746         }
2747
2748         if (world_player)
2749         {
2750                 if (flush_failure) flush();
2751 #ifdef JP
2752                 msg_print("»ß¤Þ¤Ã¤¿»þ¤ÎÃæ¤Ç¤Ï¤¦¤Þ¤¯Æ¯¤«¤Ê¤¤¤è¤¦¤À¡£");
2753 #else
2754                 msg_print("Nothing happen. Maybe this staff is freezing too.");
2755 #endif
2756
2757                 sound(SOUND_FAIL);
2758                 return;
2759         }
2760
2761         /* Roll for usage */
2762         if ((chance < USE_DEVICE) || (randint1(chance) < USE_DEVICE) || (p_ptr->pclass == CLASS_BERSERKER))
2763         {
2764                 if (flush_failure) flush();
2765 #ifdef JP
2766                 msg_print("¾ó¤ò¤¦¤Þ¤¯»È¤¨¤Ê¤«¤Ã¤¿¡£");
2767 #else
2768                 msg_print("You failed to use the staff properly.");
2769 #endif
2770
2771                 sound(SOUND_FAIL);
2772                 return;
2773         }
2774
2775         /* Notice empty staffs */
2776         if (o_ptr->pval <= 0)
2777         {
2778                 if (flush_failure) flush();
2779 #ifdef JP
2780                 msg_print("¤³¤Î¾ó¤Ë¤Ï¤â¤¦ËâÎϤ¬»Ä¤Ã¤Æ¤¤¤Ê¤¤¡£");
2781 #else
2782                 msg_print("The staff has no charges left.");
2783 #endif
2784
2785                 o_ptr->ident |= (IDENT_EMPTY);
2786
2787                 /* Combine / Reorder the pack (later) */
2788                 p_ptr->notice |= (PN_COMBINE | PN_REORDER);
2789                 p_ptr->window |= (PW_INVEN);
2790
2791                 return;
2792         }
2793
2794
2795         /* Sound */
2796         sound(SOUND_ZAP);
2797
2798         ident = staff_effect(o_ptr->sval, &use_charge, FALSE, FALSE, object_is_aware(o_ptr));
2799
2800         if (!(object_is_aware(o_ptr)))
2801         {
2802                 chg_virtue(V_PATIENCE, -1);
2803                 chg_virtue(V_CHANCE, 1);
2804                 chg_virtue(V_KNOWLEDGE, -1);
2805         }
2806
2807         /* Combine / Reorder the pack (later) */
2808         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
2809
2810         /* Tried the item */
2811         object_tried(o_ptr);
2812
2813         /* An identification was made */
2814         if (ident && !object_is_aware(o_ptr))
2815         {
2816                 object_aware(o_ptr);
2817                 gain_exp((lev + (p_ptr->lev >> 1)) / p_ptr->lev);
2818         }
2819
2820         /* Window stuff */
2821         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
2822
2823
2824         /* Hack -- some uses are "free" */
2825         if (!use_charge) return;
2826
2827
2828         /* Use a single charge */
2829         o_ptr->pval--;
2830
2831         /* XXX Hack -- unstack if necessary */
2832         if ((item >= 0) && (o_ptr->number > 1))
2833         {
2834                 object_type forge;
2835                 object_type *q_ptr;
2836
2837                 /* Get local object */
2838                 q_ptr = &forge;
2839
2840                 /* Obtain a local object */
2841                 object_copy(q_ptr, o_ptr);
2842
2843                 /* Modify quantity */
2844                 q_ptr->number = 1;
2845
2846                 /* Restore the charges */
2847                 o_ptr->pval++;
2848
2849                 /* Unstack the used item */
2850                 o_ptr->number--;
2851                 p_ptr->total_weight -= q_ptr->weight;
2852                 item = inven_carry(q_ptr);
2853
2854                 /* Message */
2855 #ifdef JP
2856                 msg_print("¾ó¤ò¤Þ¤È¤á¤Ê¤ª¤·¤¿¡£");
2857 #else
2858                 msg_print("You unstack your staff.");
2859 #endif
2860
2861         }
2862
2863         /* Describe charges in the pack */
2864         if (item >= 0)
2865         {
2866                 inven_item_charges(item);
2867         }
2868
2869         /* Describe charges on the floor */
2870         else
2871         {
2872                 floor_item_charges(0 - item);
2873         }
2874 }
2875
2876
2877 void do_cmd_use_staff(void)
2878 {
2879         int  item;
2880         cptr q, s;
2881
2882         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
2883         {
2884                 set_action(ACTION_NONE);
2885         }
2886
2887         /* Restrict choices to wands */
2888         item_tester_tval = TV_STAFF;
2889
2890         /* Get an item */
2891 #ifdef JP
2892         q = "¤É¤Î¾ó¤ò»È¤¤¤Þ¤¹¤«? ";
2893         s = "»È¤¨¤ë¾ó¤¬¤Ê¤¤¡£";
2894 #else
2895         q = "Use which staff? ";
2896         s = "You have no staff to use.";
2897 #endif
2898
2899         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
2900
2901         do_cmd_use_staff_aux(item);
2902 }
2903
2904
2905 static int wand_effect(int sval, int dir, bool powerful, bool magic)
2906 {
2907         int ident = FALSE;
2908         int lev = powerful ? p_ptr->lev * 2 : p_ptr->lev;
2909         int rad = powerful ? 3 : 2;
2910
2911         /* XXX Hack -- Wand of wonder can do anything before it */
2912         if (sval == SV_WAND_WONDER)
2913         {
2914                 int vir = virtue_number(V_CHANCE);
2915                 sval = randint0(SV_WAND_WONDER);
2916
2917                 if (vir)
2918                 {
2919                         if (p_ptr->virtues[vir - 1] > 0)
2920                         {
2921                                 while (randint1(300) < p_ptr->virtues[vir - 1]) sval++;
2922                                 if (sval > SV_WAND_COLD_BALL) sval = randint0(4) + SV_WAND_ACID_BALL;
2923                         }
2924                         else
2925                         {
2926                                 while (randint1(300) < (0-p_ptr->virtues[vir - 1])) sval--;
2927                                 if (sval < SV_WAND_HEAL_MONSTER) sval = randint0(3) + SV_WAND_HEAL_MONSTER;
2928                         }
2929                 }
2930                 if (sval < SV_WAND_TELEPORT_AWAY)
2931                         chg_virtue(V_CHANCE, 1);
2932         }
2933
2934         /* Analyze the wand */
2935         switch (sval)
2936         {
2937                 case SV_WAND_HEAL_MONSTER:
2938                 {
2939                         int dam = damroll((powerful ? 20 : 10), 10);
2940                         if (heal_monster(dir, dam)) ident = TRUE;
2941                         break;
2942                 }
2943
2944                 case SV_WAND_HASTE_MONSTER:
2945                 {
2946                         if (speed_monster(dir, lev)) ident = TRUE;
2947                         break;
2948                 }
2949
2950                 case SV_WAND_CLONE_MONSTER:
2951                 {
2952                         if (clone_monster(dir)) ident = TRUE;
2953                         break;
2954                 }
2955
2956                 case SV_WAND_TELEPORT_AWAY:
2957                 {
2958                         int distance = MAX_SIGHT * (powerful ? 8 : 5);
2959                         if (teleport_monster(dir, distance)) ident = TRUE;
2960                         break;
2961                 }
2962
2963                 case SV_WAND_DISARMING:
2964                 {
2965                         if (disarm_trap(dir)) ident = TRUE;
2966                         if (powerful && disarm_traps_touch()) ident = TRUE;
2967                         break;
2968                 }
2969
2970                 case SV_WAND_TRAP_DOOR_DEST:
2971                 {
2972                         if (destroy_door(dir)) ident = TRUE;
2973                         if (powerful && destroy_doors_touch()) ident = TRUE;
2974                         break;
2975                 }
2976
2977                 case SV_WAND_STONE_TO_MUD:
2978                 {
2979                         int dam = powerful ? 40 + randint1(60) : 20 + randint1(30);
2980                         if (wall_to_mud(dir, dam)) ident = TRUE;
2981                         break;
2982                 }
2983
2984                 case SV_WAND_LITE:
2985                 {
2986                         int dam = damroll((powerful ? 12 : 6), 8);
2987 #ifdef JP
2988                         msg_print("ÀĤ¯µ±¤¯¸÷Àþ¤¬Êü¤¿¤ì¤¿¡£");
2989 #else
2990                         msg_print("A line of blue shimmering light appears.");
2991 #endif
2992
2993                         (void)lite_line(dir, dam);
2994                         ident = TRUE;
2995                         break;
2996                 }
2997
2998                 case SV_WAND_SLEEP_MONSTER:
2999                 {
3000                         if (sleep_monster(dir, lev)) ident = TRUE;
3001                         break;
3002                 }
3003
3004                 case SV_WAND_SLOW_MONSTER:
3005                 {
3006                         if (slow_monster(dir, lev)) ident = TRUE;
3007                         break;
3008                 }
3009
3010                 case SV_WAND_CONFUSE_MONSTER:
3011                 {
3012                         if (confuse_monster(dir, lev)) ident = TRUE;
3013                         break;
3014                 }
3015
3016                 case SV_WAND_FEAR_MONSTER:
3017                 {
3018                         if (fear_monster(dir, lev)) ident = TRUE;
3019                         break;
3020                 }
3021
3022                 case SV_WAND_DRAIN_LIFE:
3023                 {
3024                         if (drain_life(dir, 80 + lev)) ident = TRUE;
3025                         break;
3026                 }
3027
3028                 case SV_WAND_POLYMORPH:
3029                 {
3030                         if (poly_monster(dir, lev)) ident = TRUE;
3031                         break;
3032                 }
3033
3034                 case SV_WAND_STINKING_CLOUD:
3035                 {
3036                         fire_ball(GF_POIS, dir, 12 + lev / 4, rad);
3037                         ident = TRUE;
3038                         break;
3039                 }
3040
3041                 case SV_WAND_MAGIC_MISSILE:
3042                 {
3043                         fire_bolt_or_beam(20, GF_MISSILE, dir, damroll(2 + lev / 10, 6));
3044                         ident = TRUE;
3045                         break;
3046                 }
3047
3048                 case SV_WAND_ACID_BOLT:
3049                 {
3050                         fire_bolt_or_beam(20, GF_ACID, dir, damroll(6 + lev / 7, 8));
3051                         ident = TRUE;
3052                         break;
3053                 }
3054
3055                 case SV_WAND_CHARM_MONSTER:
3056                 {
3057                         if (charm_monster(dir, MAX(20, lev)))
3058                         ident = TRUE;
3059                         break;
3060                 }
3061
3062                 case SV_WAND_FIRE_BOLT:
3063                 {
3064                         fire_bolt_or_beam(20, GF_FIRE, dir, damroll(7 + lev / 6, 8));
3065                         ident = TRUE;
3066                         break;
3067                 }
3068
3069                 case SV_WAND_COLD_BOLT:
3070                 {
3071                         fire_bolt_or_beam(20, GF_COLD, dir, damroll(5 + lev / 8, 8));
3072                         ident = TRUE;
3073                         break;
3074                 }
3075
3076                 case SV_WAND_ACID_BALL:
3077                 {
3078                         fire_ball(GF_ACID, dir, 60 + 3 * lev / 4, rad);
3079                         ident = TRUE;
3080                         break;
3081                 }
3082
3083                 case SV_WAND_ELEC_BALL:
3084                 {
3085                         fire_ball(GF_ELEC, dir, 40 + 3 * lev / 4, rad);
3086                         ident = TRUE;
3087                         break;
3088                 }
3089
3090                 case SV_WAND_FIRE_BALL:
3091                 {
3092                         fire_ball(GF_FIRE, dir, 70 + 3 * lev / 4, rad);
3093                         ident = TRUE;
3094                         break;
3095                 }
3096
3097                 case SV_WAND_COLD_BALL:
3098                 {
3099                         fire_ball(GF_COLD, dir, 50 + 3 * lev / 4, rad);
3100                         ident = TRUE;
3101                         break;
3102                 }
3103
3104                 case SV_WAND_WONDER:
3105                 {
3106 #ifdef JP
3107                         msg_print("¤ª¤Ã¤È¡¢Ææ¤ÎËâË¡ËÀ¤ò»ÏÆ°¤µ¤»¤¿¡£");
3108 #else
3109                         msg_print("Oops.  Wand of wonder activated.");
3110 #endif
3111
3112                         break;
3113                 }
3114
3115                 case SV_WAND_DRAGON_FIRE:
3116                 {
3117                         fire_ball(GF_FIRE, dir, (powerful ? 300 : 200), -3);
3118                         ident = TRUE;
3119                         break;
3120                 }
3121
3122                 case SV_WAND_DRAGON_COLD:
3123                 {
3124                         fire_ball(GF_COLD, dir, (powerful ? 270 : 180), -3);
3125                         ident = TRUE;
3126                         break;
3127                 }
3128
3129                 case SV_WAND_DRAGON_BREATH:
3130                 {
3131                         int dam;
3132                         int typ;
3133
3134                         switch (randint1(5))
3135                         {
3136                                 case 1:
3137                                         dam = 240;
3138                                         typ = GF_ACID;
3139                                         break;
3140                                 case 2:
3141                                         dam = 210;
3142                                         typ = GF_ELEC;
3143                                         break;
3144                                 case 3:
3145                                         dam = 240;
3146                                         typ = GF_FIRE;
3147                                         break;
3148                                 case 4:
3149                                         dam = 210;
3150                                         typ = GF_COLD;
3151                                         break;
3152                                 default:
3153                                         dam = 180;
3154                                         typ = GF_POIS;
3155                                         break;
3156                         }
3157
3158                         if (powerful) dam = (dam * 3) / 2;
3159
3160                         fire_ball(typ, dir, dam, -3);
3161
3162                         ident = TRUE;
3163                         break;
3164                 }
3165
3166                 case SV_WAND_DISINTEGRATE:
3167                 {
3168                         fire_ball(GF_DISINTEGRATE, dir, 200 + randint1(lev * 2), rad);
3169                         ident = TRUE;
3170                         break;
3171                 }
3172
3173                 case SV_WAND_ROCKETS:
3174                 {
3175 #ifdef JP
3176 msg_print("¥í¥±¥Ã¥È¤òȯ¼Í¤·¤¿¡ª");
3177 #else
3178                         msg_print("You launch a rocket!");
3179 #endif
3180
3181                         fire_rocket(GF_ROCKET, dir, 250 + lev * 3, rad);
3182                         ident = TRUE;
3183                         break;
3184                 }
3185
3186                 case SV_WAND_STRIKING:
3187                 {
3188                         fire_bolt(GF_METEOR, dir, damroll(15 + lev / 3, 13));
3189                         ident = TRUE;
3190                         break;
3191                 }
3192
3193                 case SV_WAND_GENOCIDE:
3194                 {
3195                         fire_ball_hide(GF_GENOCIDE, dir, magic ? lev + 50 : 250, 0);
3196                         ident = TRUE;
3197                         break;
3198                 }
3199         }
3200         return ident;
3201 }
3202
3203
3204 /*
3205  * Aim a wand (from the pack or floor).
3206  *
3207  * Use a single charge from a single item.
3208  * Handle "unstacking" in a logical manner.
3209  *
3210  * For simplicity, you cannot use a stack of items from the
3211  * ground.  This would require too much nasty code.
3212  *
3213  * There are no wands which can "destroy" themselves, in the inventory
3214  * or on the ground, so we can ignore this possibility.  Note that this
3215  * required giving "wand of wonder" the ability to ignore destruction
3216  * by electric balls.
3217  *
3218  * All wands can be "cancelled" at the "Direction?" prompt for free.
3219  *
3220  * Note that the basic "bolt" wands do slightly less damage than the
3221  * basic "bolt" rods, but the basic "ball" wands do the same damage
3222  * as the basic "ball" rods.
3223  */
3224 static void do_cmd_aim_wand_aux(int item)
3225 {
3226         int         lev, ident, chance, dir;
3227         object_type *o_ptr;
3228         bool old_target_pet = target_pet;
3229
3230         /* Get the item (in the pack) */
3231         if (item >= 0)
3232         {
3233                 o_ptr = &inventory[item];
3234         }
3235
3236         /* Get the item (on the floor) */
3237         else
3238         {
3239                 o_ptr = &o_list[0 - item];
3240         }
3241
3242         /* Mega-Hack -- refuse to aim a pile from the ground */
3243         if ((item < 0) && (o_ptr->number > 1))
3244         {
3245 #ifdef JP
3246                 msg_print("¤Þ¤º¤ÏËâË¡ËÀ¤ò½¦¤ï¤Ê¤±¤ì¤Ð¡£");
3247 #else
3248                 msg_print("You must first pick up the wands.");
3249 #endif
3250
3251                 return;
3252         }
3253
3254
3255         /* Allow direction to be cancelled for free */
3256         if (object_is_aware(o_ptr) && (o_ptr->sval == SV_WAND_HEAL_MONSTER
3257                                       || o_ptr->sval == SV_WAND_HASTE_MONSTER))
3258                         target_pet = TRUE;
3259         if (!get_aim_dir(&dir))
3260         {
3261                 target_pet = old_target_pet;
3262                 return;
3263         }
3264         target_pet = old_target_pet;
3265
3266         /* Take a turn */
3267         energy_use = 100;
3268
3269         /* Get the level */
3270         lev = k_info[o_ptr->k_idx].level;
3271         if (lev > 50) lev = 50 + (lev - 50)/2;
3272
3273         /* Base chance of success */
3274         chance = p_ptr->skill_dev;
3275
3276         /* Confusion hurts skill */
3277         if (p_ptr->confused) chance = chance / 2;
3278
3279         /* Hight level objects are harder */
3280         chance = chance - lev;
3281
3282         /* Give everyone a (slight) chance */
3283         if ((chance < USE_DEVICE) && one_in_(USE_DEVICE - chance + 1))
3284         {
3285                 chance = USE_DEVICE;
3286         }
3287
3288         if (world_player)
3289         {
3290                 if (flush_failure) flush();
3291 #ifdef JP
3292                 msg_print("»ß¤Þ¤Ã¤¿»þ¤ÎÃæ¤Ç¤Ï¤¦¤Þ¤¯Æ¯¤«¤Ê¤¤¤è¤¦¤À¡£");
3293 #else
3294                 msg_print("Nothing happen. Maybe this wand is freezing too.");
3295 #endif
3296
3297                 sound(SOUND_FAIL);
3298                 return;
3299         }
3300
3301         /* Roll for usage */
3302         if ((chance < USE_DEVICE) || (randint1(chance) < USE_DEVICE) || (p_ptr->pclass == CLASS_BERSERKER))
3303         {
3304                 if (flush_failure) flush();
3305 #ifdef JP
3306                 msg_print("ËâË¡ËÀ¤ò¤¦¤Þ¤¯»È¤¨¤Ê¤«¤Ã¤¿¡£");
3307 #else
3308                 msg_print("You failed to use the wand properly.");
3309 #endif
3310
3311                 sound(SOUND_FAIL);
3312                 return;
3313         }
3314
3315         /* The wand is already empty! */
3316         if (o_ptr->pval <= 0)
3317         {
3318                 if (flush_failure) flush();
3319 #ifdef JP
3320                 msg_print("¤³¤ÎËâË¡ËÀ¤Ë¤Ï¤â¤¦ËâÎϤ¬»Ä¤Ã¤Æ¤¤¤Ê¤¤¡£");
3321 #else
3322                 msg_print("The wand has no charges left.");
3323 #endif
3324
3325                 o_ptr->ident |= (IDENT_EMPTY);
3326
3327                 /* Combine / Reorder the pack (later) */
3328                 p_ptr->notice |= (PN_COMBINE | PN_REORDER);
3329                 p_ptr->window |= (PW_INVEN);
3330
3331                 return;
3332         }
3333
3334         /* Sound */
3335         sound(SOUND_ZAP);
3336
3337         ident = wand_effect(o_ptr->sval, dir, FALSE, FALSE);
3338
3339         /* Combine / Reorder the pack (later) */
3340         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
3341
3342         if (!(object_is_aware(o_ptr)))
3343         {
3344                 chg_virtue(V_PATIENCE, -1);
3345                 chg_virtue(V_CHANCE, 1);
3346                 chg_virtue(V_KNOWLEDGE, -1);
3347         }
3348
3349         /* Mark it as tried */
3350         object_tried(o_ptr);
3351
3352         /* Apply identification */
3353         if (ident && !object_is_aware(o_ptr))
3354         {
3355                 object_aware(o_ptr);
3356                 gain_exp((lev + (p_ptr->lev >> 1)) / p_ptr->lev);
3357         }
3358
3359         /* Window stuff */
3360         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
3361
3362
3363         /* Use a single charge */
3364         o_ptr->pval--;
3365
3366         /* Describe the charges in the pack */
3367         if (item >= 0)
3368         {
3369                 inven_item_charges(item);
3370         }
3371
3372         /* Describe the charges on the floor */
3373         else
3374         {
3375                 floor_item_charges(0 - item);
3376         }
3377 }
3378
3379
3380 void do_cmd_aim_wand(void)
3381 {
3382         int     item;
3383         cptr    q, s;
3384
3385         /* Restrict choices to wands */
3386         item_tester_tval = TV_WAND;
3387
3388         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
3389         {
3390                 set_action(ACTION_NONE);
3391         }
3392
3393         /* Get an item */
3394 #ifdef JP
3395         q = "¤É¤ÎËâË¡ËÀ¤ÇÁÀ¤¤¤Þ¤¹¤«? ";
3396         s = "»È¤¨¤ëËâË¡ËÀ¤¬¤Ê¤¤¡£";
3397 #else
3398         q = "Aim which wand? ";
3399         s = "You have no wand to aim.";
3400 #endif
3401
3402         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
3403
3404         /* Aim the wand */
3405         do_cmd_aim_wand_aux(item);
3406 }
3407
3408
3409 static int rod_effect(int sval, int dir, bool *use_charge, bool powerful, bool magic)
3410 {
3411         int ident = FALSE;
3412         int lev = powerful ? p_ptr->lev * 2 : p_ptr->lev;
3413         int detect_rad = powerful ? DETECT_RAD_DEFAULT * 3 / 2 : DETECT_RAD_DEFAULT;
3414         int rad = powerful ? 3 : 2;
3415
3416         /* Unused */
3417         (void)magic;
3418
3419         /* Analyze the rod */
3420         switch (sval)
3421         {
3422                 case SV_ROD_DETECT_TRAP:
3423                 {
3424                         if (detect_traps(detect_rad, (bool)(dir ? FALSE : TRUE))) ident = TRUE;
3425                         break;
3426                 }
3427
3428                 case SV_ROD_DETECT_DOOR:
3429                 {
3430                         if (detect_doors(detect_rad)) ident = TRUE;
3431                         if (detect_stairs(detect_rad)) ident = TRUE;
3432                         break;
3433                 }
3434
3435                 case SV_ROD_IDENTIFY:
3436                 {
3437                         if (powerful) {
3438                                 if (!identify_fully(FALSE)) *use_charge = FALSE;
3439                         } else {
3440                                 if (!ident_spell(FALSE)) *use_charge = FALSE;
3441                         }
3442                         ident = TRUE;
3443                         break;
3444                 }
3445
3446                 case SV_ROD_RECALL:
3447                 {
3448                         if (!word_of_recall()) *use_charge = FALSE;
3449                         ident = TRUE;
3450                         break;
3451                 }
3452
3453                 case SV_ROD_ILLUMINATION:
3454                 {
3455                         if (lite_area(damroll(2, 8), (powerful ? 4 : 2))) ident = TRUE;
3456                         break;
3457                 }
3458
3459                 case SV_ROD_MAPPING:
3460                 {
3461                         map_area(powerful ? DETECT_RAD_MAP * 3 / 2 : DETECT_RAD_MAP);
3462                         ident = TRUE;
3463                         break;
3464                 }
3465
3466                 case SV_ROD_DETECTION:
3467                 {
3468                         detect_all(detect_rad);
3469                         ident = TRUE;
3470                         break;
3471                 }
3472
3473                 case SV_ROD_PROBING:
3474                 {
3475                         probing();
3476                         ident = TRUE;
3477                         break;
3478                 }
3479
3480                 case SV_ROD_CURING:
3481                 {
3482                         if (set_blind(0)) ident = TRUE;
3483                         if (set_poisoned(0)) ident = TRUE;
3484                         if (set_confused(0)) ident = TRUE;
3485                         if (set_stun(0)) ident = TRUE;
3486                         if (set_cut(0)) ident = TRUE;
3487                         if (set_image(0)) ident = TRUE;
3488                         if (set_shero(0,TRUE)) ident = TRUE;
3489                         break;
3490                 }
3491
3492                 case SV_ROD_HEALING:
3493                 {
3494                         if (hp_player(powerful ? 750 : 500)) ident = TRUE;
3495                         if (set_stun(0)) ident = TRUE;
3496                         if (set_cut(0)) ident = TRUE;
3497                         if (set_shero(0,TRUE)) ident = TRUE;
3498                         break;
3499                 }
3500
3501                 case SV_ROD_RESTORATION:
3502                 {
3503                         if (restore_level()) ident = TRUE;
3504                         if (do_res_stat(A_STR)) ident = TRUE;
3505                         if (do_res_stat(A_INT)) ident = TRUE;
3506                         if (do_res_stat(A_WIS)) ident = TRUE;
3507                         if (do_res_stat(A_DEX)) ident = TRUE;
3508                         if (do_res_stat(A_CON)) ident = TRUE;
3509                         if (do_res_stat(A_CHR)) ident = TRUE;
3510                         break;
3511                 }
3512
3513                 case SV_ROD_SPEED:
3514                 {
3515                         if (set_fast(randint1(30) + (powerful ? 30 : 15), FALSE)) ident = TRUE;
3516                         break;
3517                 }
3518
3519                 case SV_ROD_PESTICIDE:
3520                 {
3521                         if (dispel_monsters(powerful ? 8 : 4)) ident = TRUE;
3522                         break;
3523                 }
3524
3525                 case SV_ROD_TELEPORT_AWAY:
3526                 {
3527                         int distance = MAX_SIGHT * (powerful ? 8 : 5);
3528                         if (teleport_monster(dir, distance)) ident = TRUE;
3529                         break;
3530                 }
3531
3532                 case SV_ROD_DISARMING:
3533                 {
3534                         if (disarm_trap(dir)) ident = TRUE;
3535                         if (powerful && disarm_traps_touch()) ident = TRUE;
3536                         break;
3537                 }
3538
3539                 case SV_ROD_LITE:
3540                 {
3541                         int dam = damroll((powerful ? 12 : 6), 8);
3542 #ifdef JP
3543                         msg_print("ÀĤ¯µ±¤¯¸÷Àþ¤¬Êü¤¿¤ì¤¿¡£");
3544 #else
3545                         msg_print("A line of blue shimmering light appears.");
3546 #endif
3547
3548                         (void)lite_line(dir, dam);
3549                         ident = TRUE;
3550                         break;
3551                 }
3552
3553                 case SV_ROD_SLEEP_MONSTER:
3554                 {
3555                         if (sleep_monster(dir, lev)) ident = TRUE;
3556                         break;
3557                 }
3558
3559                 case SV_ROD_SLOW_MONSTER:
3560                 {
3561                         if (slow_monster(dir, lev)) ident = TRUE;
3562                         break;
3563                 }
3564
3565                 case SV_ROD_DRAIN_LIFE:
3566                 {
3567                         if (drain_life(dir, 70 + 3 * lev / 2)) ident = TRUE;
3568                         break;
3569                 }
3570
3571                 case SV_ROD_POLYMORPH:
3572                 {
3573                         if (poly_monster(dir, lev)) ident = TRUE;
3574                         break;
3575                 }
3576
3577                 case SV_ROD_ACID_BOLT:
3578                 {
3579                         fire_bolt_or_beam(10, GF_ACID, dir, damroll(6 + lev / 7, 8));
3580                         ident = TRUE;
3581                         break;
3582                 }
3583
3584                 case SV_ROD_ELEC_BOLT:
3585                 {
3586                         fire_bolt_or_beam(10, GF_ELEC, dir, damroll(4 + lev / 9, 8));
3587                         ident = TRUE;
3588                         break;
3589                 }
3590
3591                 case SV_ROD_FIRE_BOLT:
3592                 {
3593                         fire_bolt_or_beam(10, GF_FIRE, dir, damroll(7 + lev / 6, 8));
3594                         ident = TRUE;
3595                         break;
3596                 }
3597
3598                 case SV_ROD_COLD_BOLT:
3599                 {
3600                         fire_bolt_or_beam(10, GF_COLD, dir, damroll(5 + lev / 8, 8));
3601                         ident = TRUE;
3602                         break;
3603                 }
3604
3605                 case SV_ROD_ACID_BALL:
3606                 {
3607                         fire_ball(GF_ACID, dir, 60 + lev, rad);
3608                         ident = TRUE;
3609                         break;
3610                 }
3611
3612                 case SV_ROD_ELEC_BALL:
3613                 {
3614                         fire_ball(GF_ELEC, dir, 40 + lev, rad);
3615                         ident = TRUE;
3616                         break;
3617                 }
3618
3619                 case SV_ROD_FIRE_BALL:
3620                 {
3621                         fire_ball(GF_FIRE, dir, 70 + lev, rad);
3622                         ident = TRUE;
3623                         break;
3624                 }
3625
3626                 case SV_ROD_COLD_BALL:
3627                 {
3628                         fire_ball(GF_COLD, dir, 50 + lev, rad);
3629                         ident = TRUE;
3630                         break;
3631                 }
3632
3633                 case SV_ROD_HAVOC:
3634                 {
3635                         call_chaos();
3636                         ident = TRUE;
3637                         break;
3638                 }
3639
3640                 case SV_ROD_STONE_TO_MUD:
3641                 {
3642                         int dam = powerful ? 40 + randint1(60) : 20 + randint1(30);
3643                         if (wall_to_mud(dir, dam)) ident = TRUE;
3644                         break;
3645                 }
3646
3647                 case SV_ROD_AGGRAVATE:
3648                 {
3649                         aggravate_monsters(0);
3650                         ident = TRUE;
3651                         break;
3652                 }
3653         }
3654         return ident;
3655 }
3656
3657 /*
3658  * Activate (zap) a Rod
3659  *
3660  * Unstack fully charged rods as needed.
3661  *
3662  * Hack -- rods of perception/genocide can be "cancelled"
3663  * All rods can be cancelled at the "Direction?" prompt
3664  *
3665  * pvals are defined for each rod in k_info. -LM-
3666  */
3667 static void do_cmd_zap_rod_aux(int item)
3668 {
3669         int ident, chance, lev, fail;
3670         int dir = 0;
3671         object_type *o_ptr;
3672         bool success;
3673
3674         /* Hack -- let perception get aborted */
3675         bool use_charge = TRUE;
3676
3677         object_kind *k_ptr;
3678
3679         /* Get the item (in the pack) */
3680         if (item >= 0)
3681         {
3682                 o_ptr = &inventory[item];
3683         }
3684
3685         /* Get the item (on the floor) */
3686         else
3687         {
3688                 o_ptr = &o_list[0 - item];
3689         }
3690
3691
3692         /* Mega-Hack -- refuse to zap a pile from the ground */
3693         if ((item < 0) && (o_ptr->number > 1))
3694         {
3695 #ifdef JP
3696                 msg_print("¤Þ¤º¤Ï¥í¥Ã¥É¤ò½¦¤ï¤Ê¤±¤ì¤Ð¡£");
3697 #else
3698                 msg_print("You must first pick up the rods.");
3699 #endif
3700
3701                 return;
3702         }
3703
3704
3705         /* Get a direction (unless KNOWN not to need it) */
3706         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)) ||
3707              !object_is_aware(o_ptr))
3708         {
3709                 /* Get a direction, allow cancel */
3710                 if (!get_aim_dir(&dir)) return;
3711         }
3712
3713
3714         /* Take a turn */
3715         energy_use = 100;
3716
3717         /* Extract the item level */
3718         lev = k_info[o_ptr->k_idx].level;
3719
3720         /* Base chance of success */
3721         chance = p_ptr->skill_dev;
3722
3723         /* Confusion hurts skill */
3724         if (p_ptr->confused) chance = chance / 2;
3725
3726         fail = lev+5;
3727         if (chance > fail) fail -= (chance - fail)*2;
3728         else chance -= (fail - chance)*2;
3729         if (fail < USE_DEVICE) fail = USE_DEVICE;
3730         if (chance < USE_DEVICE) chance = USE_DEVICE;
3731
3732         if (world_player)
3733         {
3734                 if (flush_failure) flush();
3735 #ifdef JP
3736                 msg_print("»ß¤Þ¤Ã¤¿»þ¤ÎÃæ¤Ç¤Ï¤¦¤Þ¤¯Æ¯¤«¤Ê¤¤¤è¤¦¤À¡£");
3737 #else
3738                 msg_print("Nothing happen. Maybe this rod is freezing too.");
3739 #endif
3740
3741                 sound(SOUND_FAIL);
3742                 return;
3743         }
3744
3745         if (p_ptr->pclass == CLASS_BERSERKER) success = FALSE;
3746         else if (chance > fail)
3747         {
3748                 if (randint0(chance*2) < fail) success = FALSE;
3749                 else success = TRUE;
3750         }
3751         else
3752         {
3753                 if (randint0(fail*2) < chance) success = TRUE;
3754                 else success = FALSE;
3755         }
3756
3757         /* Roll for usage */
3758         if (!success)
3759         {
3760                 if (flush_failure) flush();
3761 #ifdef JP
3762                 msg_print("¤¦¤Þ¤¯¥í¥Ã¥É¤ò»È¤¨¤Ê¤«¤Ã¤¿¡£");
3763 #else
3764                 msg_print("You failed to use the rod properly.");
3765 #endif
3766
3767                 sound(SOUND_FAIL);
3768                 return;
3769         }
3770
3771         k_ptr = &k_info[o_ptr->k_idx];
3772
3773         /* A single rod is still charging */
3774         if ((o_ptr->number == 1) && (o_ptr->timeout))
3775         {
3776                 if (flush_failure) flush();
3777 #ifdef JP
3778                 msg_print("¤³¤Î¥í¥Ã¥É¤Ï¤Þ¤ÀËâÎϤò½¼Å¶¤·¤Æ¤¤¤ëºÇÃæ¤À¡£");
3779 #else
3780                 msg_print("The rod is still charging.");
3781 #endif
3782
3783                 return;
3784         }
3785         /* A stack of rods lacks enough energy. */
3786         else if ((o_ptr->number > 1) && (o_ptr->timeout > k_ptr->pval * (o_ptr->number - 1)))
3787         {
3788                 if (flush_failure) flush();
3789 #ifdef JP
3790 msg_print("¤½¤Î¥í¥Ã¥É¤Ï¤Þ¤À½¼Å¶Ãæ¤Ç¤¹¡£");
3791 #else
3792                 msg_print("The rods are all still charging.");
3793 #endif
3794
3795                 return;
3796         }
3797
3798         /* Sound */
3799         sound(SOUND_ZAP);
3800
3801         ident = rod_effect(o_ptr->sval, dir, &use_charge, FALSE, FALSE);
3802
3803         /* Increase the timeout by the rod kind's pval. -LM- */
3804         if (use_charge) o_ptr->timeout += k_ptr->pval;
3805
3806         /* Combine / Reorder the pack (later) */
3807         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
3808
3809         if (!(object_is_aware(o_ptr)))
3810         {
3811                 chg_virtue(V_PATIENCE, -1);
3812                 chg_virtue(V_CHANCE, 1);
3813                 chg_virtue(V_KNOWLEDGE, -1);
3814         }
3815
3816         /* Tried the object */
3817         object_tried(o_ptr);
3818
3819         /* Successfully determined the object function */
3820         if (ident && !object_is_aware(o_ptr))
3821         {
3822                 object_aware(o_ptr);
3823                 gain_exp((lev + (p_ptr->lev >> 1)) / p_ptr->lev);
3824         }
3825
3826         /* Window stuff */
3827         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
3828 }
3829
3830
3831 void do_cmd_zap_rod(void)
3832 {
3833         int item;
3834         cptr q, s;
3835
3836         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
3837         {
3838                 set_action(ACTION_NONE);
3839         }
3840
3841         /* Restrict choices to rods */
3842         item_tester_tval = TV_ROD;
3843
3844         /* Get an item */
3845 #ifdef JP
3846         q = "¤É¤Î¥í¥Ã¥É¤ò¿¶¤ê¤Þ¤¹¤«? ";
3847         s = "»È¤¨¤ë¥í¥Ã¥É¤¬¤Ê¤¤¡£";
3848 #else
3849         q = "Zap which rod? ";
3850         s = "You have no rod to zap.";
3851 #endif
3852
3853         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
3854
3855         /* Zap the rod */
3856         do_cmd_zap_rod_aux(item);
3857 }
3858
3859
3860 /*
3861  * Hook to determine if an object is activatable
3862  */
3863 static bool item_tester_hook_activate(object_type *o_ptr)
3864 {
3865         u32b flgs[TR_FLAG_SIZE];
3866
3867         /* Not known */
3868         if (!object_is_known(o_ptr)) return (FALSE);
3869
3870         /* Extract the flags */
3871         object_flags(o_ptr, flgs);
3872
3873         /* Check activation flag */
3874         if (have_flag(flgs, TR_ACTIVATE)) return (TRUE);
3875
3876         /* Assume not */
3877         return (FALSE);
3878 }
3879
3880
3881 /*
3882  * Hack -- activate the ring of power
3883  */
3884 void ring_of_power(int dir)
3885 {
3886         /* Pick a random effect */
3887         switch (randint1(10))
3888         {
3889                 case 1:
3890                 case 2:
3891                 {
3892                         /* Message */
3893 #ifdef JP
3894                         msg_print("¤¢¤Ê¤¿¤Ï°­À­¤Î¥ª¡¼¥é¤ËÊñ¤ß¹þ¤Þ¤ì¤¿¡£");
3895 #else
3896                         msg_print("You are surrounded by a malignant aura.");
3897 #endif
3898
3899                         sound(SOUND_EVIL);
3900
3901                         /* Decrease all stats (permanently) */
3902                         (void)dec_stat(A_STR, 50, TRUE);
3903                         (void)dec_stat(A_INT, 50, TRUE);
3904                         (void)dec_stat(A_WIS, 50, TRUE);
3905                         (void)dec_stat(A_DEX, 50, TRUE);
3906                         (void)dec_stat(A_CON, 50, TRUE);
3907                         (void)dec_stat(A_CHR, 50, TRUE);
3908
3909                         /* Lose some experience (permanently) */
3910                         p_ptr->exp -= (p_ptr->exp / 4);
3911                         p_ptr->max_exp -= (p_ptr->exp / 4);
3912                         check_experience();
3913
3914                         break;
3915                 }
3916
3917                 case 3:
3918                 {
3919                         /* Message */
3920 #ifdef JP
3921                         msg_print("¤¢¤Ê¤¿¤Ï¶¯ÎϤʥª¡¼¥é¤ËÊñ¤ß¹þ¤Þ¤ì¤¿¡£");
3922 #else
3923                         msg_print("You are surrounded by a powerful aura.");
3924 #endif
3925
3926
3927                         /* Dispel monsters */
3928                         dispel_monsters(1000);
3929
3930                         break;
3931                 }
3932
3933                 case 4:
3934                 case 5:
3935                 case 6:
3936                 {
3937                         /* Mana Ball */
3938                         fire_ball(GF_MANA, dir, 600, 3);
3939
3940                         break;
3941                 }
3942
3943                 case 7:
3944                 case 8:
3945                 case 9:
3946                 case 10:
3947                 {
3948                         /* Mana Bolt */
3949                         fire_bolt(GF_MANA, dir, 500);
3950
3951                         break;
3952                 }
3953         }
3954 }
3955
3956
3957 static bool ang_sort_comp_pet(vptr u, vptr v, int a, int b)
3958 {
3959         u16b *who = (u16b*)(u);
3960
3961         int w1 = who[a];
3962         int w2 = who[b];
3963
3964         monster_type *m_ptr1 = &m_list[w1];
3965         monster_type *m_ptr2 = &m_list[w2];
3966         monster_race *r_ptr1 = &r_info[m_ptr1->r_idx];
3967         monster_race *r_ptr2 = &r_info[m_ptr2->r_idx];
3968
3969         /* Unused */
3970         (void)v;
3971
3972         if (m_ptr1->nickname && !m_ptr2->nickname) return TRUE;
3973         if (m_ptr2->nickname && !m_ptr1->nickname) return FALSE;
3974
3975         if ((r_ptr1->flags1 & RF1_UNIQUE) && !(r_ptr2->flags1 & RF1_UNIQUE)) return TRUE;
3976         if ((r_ptr2->flags1 & RF1_UNIQUE) && !(r_ptr1->flags1 & RF1_UNIQUE)) return FALSE;
3977
3978         if (r_ptr1->level > r_ptr2->level) return TRUE;
3979         if (r_ptr2->level > r_ptr1->level) return FALSE;
3980
3981         if (m_ptr1->hp > m_ptr2->hp) return TRUE;
3982         if (m_ptr2->hp > m_ptr1->hp) return FALSE;
3983         
3984         return w1 <= w2;
3985 }
3986
3987
3988 /*
3989  * Activate a wielded object.  Wielded objects never stack.
3990  * And even if they did, activatable objects never stack.
3991  *
3992  * Currently, only (some) artifacts, and Dragon Scale Mail, can be activated.
3993  * But one could, for example, easily make an activatable "Ring of Plasma".
3994  *
3995  * Note that it always takes a turn to activate an artifact, even if
3996  * the user hits "escape" at the "direction" prompt.
3997  */
3998 static void do_cmd_activate_aux(int item)
3999 {
4000         int         dir, lev, chance, fail;
4001         object_type *o_ptr;
4002         bool success;
4003
4004
4005         /* Get the item (in the pack) */
4006         if (item >= 0)
4007         {
4008                 o_ptr = &inventory[item];
4009         }
4010
4011         /* Get the item (on the floor) */
4012         else
4013         {
4014                 o_ptr = &o_list[0 - item];
4015         }
4016
4017         /* Take a turn */
4018         energy_use = 100;
4019
4020         /* Extract the item level */
4021         lev = k_info[o_ptr->k_idx].level;
4022
4023         /* Hack -- use artifact level instead */
4024         if (object_is_fixed_artifact(o_ptr)) lev = a_info[o_ptr->name1].level;
4025         else if (object_is_random_artifact(o_ptr))
4026         {
4027                 const activation_type* const act_ptr = find_activation_info(o_ptr);
4028                 if (act_ptr) {
4029                         lev = act_ptr->level;
4030                 }
4031         }
4032         else if (((o_ptr->tval == TV_RING) || (o_ptr->tval == TV_AMULET)) && o_ptr->name2) lev = e_info[o_ptr->name2].level;
4033
4034         /* Base chance of success */
4035         chance = p_ptr->skill_dev;
4036
4037         /* Confusion hurts skill */
4038         if (p_ptr->confused) chance = chance / 2;
4039
4040         fail = lev+5;
4041         if (chance > fail) fail -= (chance - fail)*2;
4042         else chance -= (fail - chance)*2;
4043         if (fail < USE_DEVICE) fail = USE_DEVICE;
4044         if (chance < USE_DEVICE) chance = USE_DEVICE;
4045
4046         if (world_player)
4047         {
4048                 if (flush_failure) flush();
4049 #ifdef JP
4050                 msg_print("»ß¤Þ¤Ã¤¿»þ¤ÎÃæ¤Ç¤Ï¤¦¤Þ¤¯Æ¯¤«¤Ê¤¤¤è¤¦¤À¡£");
4051 #else
4052                 msg_print("It shows no reaction.");
4053 #endif
4054                 sound(SOUND_FAIL);
4055                 return;
4056         }
4057
4058         if (p_ptr->pclass == CLASS_BERSERKER) success = FALSE;
4059         else if (chance > fail)
4060         {
4061                 if (randint0(chance*2) < fail) success = FALSE;
4062                 else success = TRUE;
4063         }
4064         else
4065         {
4066                 if (randint0(fail*2) < chance) success = TRUE;
4067                 else success = FALSE;
4068         }
4069
4070         /* Roll for usage */
4071         if (!success)
4072         {
4073                 if (flush_failure) flush();
4074 #ifdef JP
4075                 msg_print("¤¦¤Þ¤¯»ÏÆ°¤µ¤»¤ë¤³¤È¤¬¤Ç¤­¤Ê¤«¤Ã¤¿¡£");
4076 #else
4077                 msg_print("You failed to activate it properly.");
4078 #endif
4079                 sound(SOUND_FAIL);
4080                 return;
4081         }
4082
4083         /* Check the recharge */
4084         if (o_ptr->timeout)
4085         {
4086 #ifdef JP
4087                 msg_print("¤½¤ì¤ÏÈù¤«¤Ë²»¤òΩ¤Æ¡¢µ±¤­¡¢¾Ã¤¨¤¿...");
4088 #else
4089                 msg_print("It whines, glows and fades...");
4090 #endif
4091                 return;
4092         }
4093
4094         /* Some lights need enough fuel for activation */
4095         if (!o_ptr->xtra4 && (o_ptr->tval == TV_FLASK) &&
4096                 ((o_ptr->sval == SV_LITE_TORCH) || (o_ptr->sval == SV_LITE_LANTERN)))
4097         {
4098 #ifdef JP
4099                 msg_print("dzÎÁ¤¬¤Ê¤¤¡£");
4100 #else
4101                 msg_print("It has no fuel.");
4102 #endif
4103                 energy_use = 0;
4104                 return;
4105         }
4106
4107         /* Activate the artifact */
4108 #ifdef JP
4109         msg_print("»ÏÆ°¤µ¤»¤¿...");
4110 #else
4111         msg_print("You activate it...");
4112 #endif
4113
4114
4115         /* Sound */
4116         sound(SOUND_ZAP);
4117
4118         /* Activate object */
4119         if (activation_index(o_ptr))
4120         {
4121                 (void)activate_random_artifact(o_ptr);
4122
4123                 /* Window stuff */
4124                 p_ptr->window |= (PW_INVEN | PW_EQUIP);
4125
4126                 /* Success */
4127                 return;
4128         }
4129
4130         /* Special items */
4131         else if (o_ptr->tval == TV_WHISTLE)
4132         {
4133                 if (music_singing_any()) stop_singing();
4134                 if (hex_spelling_any()) stop_hex_spell_all();
4135
4136 #if 0
4137                 if (object_is_cursed(o_ptr))
4138                 {
4139 #ifdef JP
4140                         msg_print("¥«¥ó¹â¤¤²»¤¬¶Á¤­ÅϤä¿¡£");
4141 #else
4142                         msg_print("You produce a shrill whistling sound.");
4143 #endif
4144                         aggravate_monsters(0);
4145                 }
4146                 else
4147 #endif
4148                 {
4149                         int pet_ctr, i;
4150                         u16b *who;
4151                         int max_pet = 0;
4152                         u16b dummy_why;
4153
4154                         /* Allocate the "who" array */
4155                         C_MAKE(who, max_m_idx, u16b);
4156
4157                         /* Process the monsters (backwards) */
4158                         for (pet_ctr = m_max - 1; pet_ctr >= 1; pet_ctr--)
4159                         {
4160                                 if (is_pet(&m_list[pet_ctr]) && (p_ptr->riding != pet_ctr))
4161                                   who[max_pet++] = pet_ctr;
4162                         }
4163
4164                         /* Select the sort method */
4165                         ang_sort_comp = ang_sort_comp_pet;
4166                         ang_sort_swap = ang_sort_swap_hook;
4167
4168                         ang_sort(who, &dummy_why, max_pet);
4169
4170                         /* Process the monsters (backwards) */
4171                         for (i = 0; i < max_pet; i++)
4172                         {
4173                                 pet_ctr = who[i];
4174                                 teleport_monster_to(pet_ctr, py, px, 100, TELEPORT_PASSIVE);
4175                         }
4176
4177                         /* Free the "who" array */
4178                         C_KILL(who, max_m_idx, u16b);
4179                 }
4180                 o_ptr->timeout = 100+randint1(100);
4181                 return;
4182         }
4183         else if (o_ptr->tval == TV_CAPTURE)
4184         {
4185                 if(!o_ptr->pval)
4186                 {
4187                         bool old_target_pet = target_pet;
4188                         target_pet = TRUE;
4189                         if (!get_aim_dir(&dir))
4190                         {
4191                                 target_pet = old_target_pet;
4192                                 return;
4193                         }
4194                         target_pet = old_target_pet;
4195
4196                         if(fire_ball(GF_CAPTURE, dir, 0, 0))
4197                         {
4198                                 o_ptr->pval = cap_mon;
4199                                 o_ptr->xtra3 = cap_mspeed;
4200                                 o_ptr->xtra4 = cap_hp;
4201                                 o_ptr->xtra5 = cap_maxhp;
4202                                 if (cap_nickname)
4203                                 {
4204                                         cptr t;
4205                                         char *s;
4206                                         char buf[80] = "";
4207
4208                                         if (o_ptr->inscription)
4209                                                 strcpy(buf, quark_str(o_ptr->inscription));
4210                                         s = buf;
4211                                         for (s = buf;*s && (*s != '#'); s++)
4212                                         {
4213 #ifdef JP
4214                                                 if (iskanji(*s)) s++;
4215 #endif
4216                                         }
4217                                         *s = '#';
4218                                         s++;
4219 #ifdef JP
4220  /*nothing*/
4221 #else
4222                                         *s++ = '\'';
4223 #endif
4224                                         t = quark_str(cap_nickname);
4225                                         while (*t)
4226                                         {
4227                                                 *s = *t;
4228                                                 s++;
4229                                                 t++;
4230                                         }
4231 #ifdef JP
4232  /*nothing*/
4233 #else
4234                                         *s++ = '\'';
4235 #endif
4236                                         *s = '\0';
4237                                         o_ptr->inscription = quark_add(buf);
4238                                 }
4239                         }
4240                 }
4241                 else
4242                 {
4243                         bool success = FALSE;
4244                         if (!get_rep_dir2(&dir)) return;
4245                         if (monster_can_enter(py + ddy[dir], px + ddx[dir], &r_info[o_ptr->pval], 0))
4246                         {
4247                                 if (place_monster_aux(0, py + ddy[dir], px + ddx[dir], o_ptr->pval, (PM_FORCE_PET | PM_NO_KAGE)))
4248                                 {
4249                                         if (o_ptr->xtra3) m_list[hack_m_idx_ii].mspeed = o_ptr->xtra3;
4250                                         if (o_ptr->xtra5) m_list[hack_m_idx_ii].max_maxhp = o_ptr->xtra5;
4251                                         if (o_ptr->xtra4) m_list[hack_m_idx_ii].hp = o_ptr->xtra4;
4252                                         m_list[hack_m_idx_ii].maxhp = m_list[hack_m_idx_ii].max_maxhp;
4253                                         if (o_ptr->inscription)
4254                                         {
4255                                                 char buf[80];
4256                                                 cptr t;
4257 #ifndef JP
4258                                                 bool quote = FALSE;
4259 #endif
4260
4261                                                 t = quark_str(o_ptr->inscription);
4262                                                 for (t = quark_str(o_ptr->inscription);*t && (*t != '#'); t++)
4263                                                 {
4264 #ifdef JP
4265                                                         if (iskanji(*t)) t++;
4266 #endif
4267                                                 }
4268                                                 if (*t)
4269                                                 {
4270                                                         char *s = buf;
4271                                                         t++;
4272 #ifdef JP
4273                                                         /* nothing */
4274 #else
4275                                                         if (*t =='\'')
4276                                                         {
4277                                                                 t++;
4278                                                                 quote = TRUE;
4279                                                         }
4280 #endif
4281                                                         while(*t)
4282                                                         {
4283                                                                 *s = *t;
4284                                                                 t++;
4285                                                                 s++;
4286                                                         }
4287 #ifdef JP
4288                                                         /* nothing */
4289 #else
4290                                                         if (quote && *(s-1) =='\'')
4291                                                                 s--;
4292 #endif
4293                                                         *s = '\0';
4294                                                         m_list[hack_m_idx_ii].nickname = quark_add(buf);
4295                                                         t = quark_str(o_ptr->inscription);
4296                                                         s = buf;
4297                                                         while(*t && (*t != '#'))
4298                                                         {
4299                                                                 *s = *t;
4300                                                                 t++;
4301                                                                 s++;
4302                                                         }
4303                                                         *s = '\0';
4304                                                         o_ptr->inscription = quark_add(buf);
4305                                                 }
4306                                         }
4307                                         o_ptr->pval = 0;
4308                                         o_ptr->xtra3 = 0;
4309                                         o_ptr->xtra4 = 0;
4310                                         o_ptr->xtra5 = 0;
4311                                         success = TRUE;
4312                                 }
4313                         }
4314                         if (!success)
4315 #ifdef JP
4316                                 msg_print("¤ª¤Ã¤È¡¢²òÊü¤Ë¼ºÇÔ¤·¤¿¡£");
4317 #else
4318                                 msg_print("Oops.  You failed to release your pet.");
4319 #endif
4320                 }
4321                 return;
4322         }
4323
4324         /* Mistake */
4325 #ifdef JP
4326         msg_print("¤ª¤Ã¤È¡¢¤³¤Î¥¢¥¤¥Æ¥à¤Ï»ÏÆ°¤Ç¤­¤Ê¤¤¡£");
4327 #else
4328         msg_print("Oops.  That object cannot be activated.");
4329 #endif
4330
4331 }
4332
4333
4334 void do_cmd_activate(void)
4335 {
4336         int     item;
4337         cptr    q, s;
4338
4339
4340         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
4341         {
4342                 set_action(ACTION_NONE);
4343         }
4344
4345         item_tester_no_ryoute = TRUE;
4346         /* Prepare the hook */
4347         item_tester_hook = item_tester_hook_activate;
4348
4349         /* Get an item */
4350 #ifdef JP
4351         q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò»ÏÆ°¤µ¤»¤Þ¤¹¤«? ";
4352         s = "»ÏÆ°¤Ç¤­¤ë¥¢¥¤¥Æ¥à¤òÁõÈ÷¤·¤Æ¤¤¤Ê¤¤¡£";
4353 #else
4354         q = "Activate which item? ";
4355         s = "You have nothing to activate.";
4356 #endif
4357
4358         if (!get_item(&item, q, s, (USE_EQUIP))) return;
4359
4360         /* Activate the item */
4361         do_cmd_activate_aux(item);
4362 }
4363
4364
4365 /*
4366  * Hook to determine if an object is useable
4367  */
4368 static bool item_tester_hook_use(object_type *o_ptr)
4369 {
4370         u32b flgs[TR_FLAG_SIZE];
4371
4372         /* Ammo */
4373         if (o_ptr->tval == p_ptr->tval_ammo)
4374                 return (TRUE);
4375
4376         /* Useable object */
4377         switch (o_ptr->tval)
4378         {
4379                 case TV_SPIKE:
4380                 case TV_STAFF:
4381                 case TV_WAND:
4382                 case TV_ROD:
4383                 case TV_SCROLL:
4384                 case TV_POTION:
4385                 case TV_FOOD:
4386                 {
4387                         return (TRUE);
4388                 }
4389
4390                 default:
4391                 {
4392                         int i;
4393
4394                         /* Not known */
4395                         if (!object_is_known(o_ptr)) return (FALSE);
4396
4397                         /* HACK - only items from the equipment can be activated */
4398                         for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
4399                         {
4400                                 if (&inventory[i] == o_ptr)
4401                                 {
4402                                         /* Extract the flags */
4403                                         object_flags(o_ptr, flgs);
4404
4405                                         /* Check activation flag */
4406                                         if (have_flag(flgs, TR_ACTIVATE)) return (TRUE);
4407                                 }
4408                         }
4409                 }
4410         }
4411
4412         /* Assume not */
4413         return (FALSE);
4414 }
4415
4416
4417 /*
4418  * Use an item
4419  * XXX - Add actions for other item types
4420  */
4421 void do_cmd_use(void)
4422 {
4423         int         item;
4424         object_type *o_ptr;
4425         cptr        q, s;
4426
4427         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
4428         {
4429                 set_action(ACTION_NONE);
4430         }
4431
4432         item_tester_no_ryoute = TRUE;
4433         /* Prepare the hook */
4434         item_tester_hook = item_tester_hook_use;
4435
4436         /* Get an item */
4437 #ifdef JP
4438 q = "¤É¤ì¤ò»È¤¤¤Þ¤¹¤«¡©";
4439 s = "»È¤¨¤ë¤â¤Î¤¬¤¢¤ê¤Þ¤»¤ó¡£";
4440 #else
4441         q = "Use which item? ";
4442         s = "You have nothing to use.";
4443 #endif
4444
4445         if (!get_item(&item, q, s, (USE_INVEN | USE_EQUIP | USE_FLOOR))) return;
4446
4447         /* Get the item (in the pack) */
4448         if (item >= 0)
4449         {
4450                 o_ptr = &inventory[item];
4451         }
4452         /* Get the item (on the floor) */
4453         else
4454         {
4455                 o_ptr = &o_list[0 - item];
4456         }
4457
4458         switch (o_ptr->tval)
4459         {
4460                 /* Spike a door */
4461                 case TV_SPIKE:
4462                 {
4463                         do_cmd_spike();
4464                         break;
4465                 }
4466
4467                 /* Eat some food */
4468                 case TV_FOOD:
4469                 {
4470                         do_cmd_eat_food_aux(item);
4471                         break;
4472                 }
4473
4474                 /* Aim a wand */
4475                 case TV_WAND:
4476                 {
4477                         do_cmd_aim_wand_aux(item);
4478                         break;
4479                 }
4480
4481                 /* Use a staff */
4482                 case TV_STAFF:
4483                 {
4484                         do_cmd_use_staff_aux(item);
4485                         break;
4486                 }
4487
4488                 /* Zap a rod */
4489                 case TV_ROD:
4490                 {
4491                         do_cmd_zap_rod_aux(item);
4492                         break;
4493                 }
4494
4495                 /* Quaff a potion */
4496                 case TV_POTION:
4497                 {
4498                         do_cmd_quaff_potion_aux(item);
4499                         break;
4500                 }
4501
4502                 /* Read a scroll */
4503                 case TV_SCROLL:
4504                 {
4505                         /* Check some conditions */
4506                         if (p_ptr->blind)
4507                         {
4508 #ifdef JP
4509 msg_print("Ìܤ¬¸«¤¨¤Ê¤¤¡£");
4510 #else
4511                                 msg_print("You can't see anything.");
4512 #endif
4513
4514                                 return;
4515                         }
4516                         if (no_lite())
4517                         {
4518 #ifdef JP
4519 msg_print("ÌÀ¤«¤ê¤¬¤Ê¤¤¤Î¤Ç¡¢°Å¤¯¤ÆÆɤá¤Ê¤¤¡£");
4520 #else
4521                                 msg_print("You have no light to read by.");
4522 #endif
4523
4524                                 return;
4525                         }
4526                         if (p_ptr->confused)
4527                         {
4528 #ifdef JP
4529 msg_print("º®Í𤷤Ƥ¤¤ÆÆɤá¤Ê¤¤¡ª");
4530 #else
4531                                 msg_print("You are too confused!");
4532 #endif
4533
4534                                 return;
4535                         }
4536
4537                   do_cmd_read_scroll_aux(item, TRUE);
4538                   break;
4539                 }
4540
4541                 /* Fire ammo */
4542                 case TV_SHOT:
4543                 case TV_ARROW:
4544                 case TV_BOLT:
4545                 {
4546                         do_cmd_fire_aux(item, &inventory[INVEN_BOW]);
4547                         break;
4548                 }
4549
4550                 /* Activate an artifact */
4551                 default:
4552                 {
4553                         do_cmd_activate_aux(item);
4554                         break;
4555                 }
4556         }
4557 }
4558
4559 static int select_magic_eater(bool only_browse)
4560 {
4561         int ext=0;
4562         char choice;
4563         bool flag, request_list;
4564         int tval = 0;
4565         int             ask = TRUE, i = 0;
4566         char            out_val[160];
4567
4568         int menu_line = (use_menu ? 1 : 0);
4569
4570 #ifdef ALLOW_REPEAT
4571         int sn;
4572         if (repeat_pull(&sn))
4573         {
4574                 /* Verify the spell */
4575                 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))
4576                         return sn;
4577                 else if (sn < EATER_EXT*2 && !(p_ptr->magic_num1[sn] < EATER_CHARGE))
4578                         return sn;
4579         }
4580         
4581 #endif /* ALLOW_REPEAT */
4582
4583         for (i = 0; i < 108; i++)
4584         {
4585                 if (p_ptr->magic_num2[i]) break;
4586         }
4587         if (i == 108)
4588         {
4589 #ifdef JP
4590                 msg_print("ËâË¡¤ò³Ð¤¨¤Æ¤¤¤Ê¤¤¡ª");
4591 #else
4592                 msg_print("You don't have any magic!");
4593 #endif
4594                 return -1;
4595         }
4596
4597         if (use_menu)
4598         {
4599                 screen_save();
4600
4601                 while(!tval)
4602                 {
4603 #ifdef JP
4604                         prt(format(" %s ¾ó", (menu_line == 1) ? "¡Õ" : "  "), 2, 14);
4605                         prt(format(" %s ËâË¡ËÀ", (menu_line == 2) ? "¡Õ" : "  "), 3, 14);
4606                         prt(format(" %s ¥í¥Ã¥É", (menu_line == 3) ? "¡Õ" : "  "), 4, 14);
4607 #else
4608                         prt(format(" %s staff", (menu_line == 1) ? "> " : "  "), 2, 14);
4609                         prt(format(" %s wand", (menu_line == 2) ? "> " : "  "), 3, 14);
4610                         prt(format(" %s rod", (menu_line == 3) ? "> " : "  "), 4, 14);
4611 #endif
4612
4613                         if (only_browse) prt(_("¤É¤Î¼ïÎà¤ÎËâË¡¤ò¸«¤Þ¤¹¤«¡©", "Which type of magic do you browse?"), 0, 0);
4614                         else prt(_("¤É¤Î¼ïÎà¤ÎËâË¡¤ò»È¤¤¤Þ¤¹¤«¡©", "Which type of magic do you use?"), 0, 0);
4615
4616                         choice = inkey();
4617                         switch(choice)
4618                         {
4619                         case ESCAPE:
4620                         case 'z':
4621                         case 'Z':
4622                                 screen_load();
4623                                 return -1;
4624                         case '2':
4625                         case 'j':
4626                         case 'J':
4627                                 menu_line++;
4628                                 break;
4629                         case '8':
4630                         case 'k':
4631                         case 'K':
4632                                 menu_line+= 2;
4633                                 break;
4634                         case '\r':
4635                         case 'x':
4636                         case 'X':
4637                                 ext = (menu_line-1)*EATER_EXT;
4638                                 if (menu_line == 1) tval = TV_STAFF;
4639                                 else if (menu_line == 2) tval = TV_WAND;
4640                                 else tval = TV_ROD;
4641                                 break;
4642                         }
4643                         if (menu_line > 3) menu_line -= 3;
4644                 }
4645                 screen_load();
4646         }
4647         else
4648         {
4649         while (TRUE)
4650         {
4651 #ifdef JP
4652                 if (!get_com("[A] ¾ó, [B] ËâË¡ËÀ, [C] ¥í¥Ã¥É:", &choice, TRUE))
4653 #else
4654                 if (!get_com("[A] staff, [B] wand, [C] rod:", &choice, TRUE))
4655 #endif
4656                 {
4657                         return -1;
4658                 }
4659                 if (choice == 'A' || choice == 'a')
4660                 {
4661                         ext = 0;
4662                         tval = TV_STAFF;
4663                         break;
4664                 }
4665                 if (choice == 'B' || choice == 'b')
4666                 {
4667                         ext = EATER_EXT;
4668                         tval = TV_WAND;
4669                         break;
4670                 }
4671                 if (choice == 'C' || choice == 'c')
4672                 {
4673                         ext = EATER_EXT*2;
4674                         tval = TV_ROD;
4675                         break;
4676                 }
4677         }
4678         }
4679         for (i = ext; i < ext + EATER_EXT; i++)
4680         {
4681                 if (p_ptr->magic_num2[i])
4682                 {
4683                         if (use_menu) menu_line = i-ext+1;
4684                         break;
4685                 }
4686         }
4687         if (i == ext+EATER_EXT)
4688         {
4689 #ifdef JP
4690                 msg_print("¤½¤Î¼ïÎà¤ÎËâË¡¤Ï³Ð¤¨¤Æ¤¤¤Ê¤¤¡ª");
4691 #else
4692                 msg_print("You don't have that type of magic!");
4693 #endif
4694                 return -1;
4695         }
4696
4697         /* Nothing chosen yet */
4698         flag = FALSE;
4699
4700         /* Build a prompt */
4701         if (only_browse) strnfmt(out_val, 78, _("('*'¤Ç°ìÍ÷, ESC¤ÇÃæÃÇ) ¤É¤ÎËâÎϤò¸«¤Þ¤¹¤«¡©",
4702                                                                                         "(*=List, ESC=exit) Browse which power? "));
4703         else strnfmt(out_val, 78, _("('*'¤Ç°ìÍ÷, ESC¤ÇÃæÃÇ) ¤É¤ÎËâÎϤò»È¤¤¤Þ¤¹¤«¡©",
4704                                                                 "(*=List, ESC=exit) Use which power? "));
4705         
4706         /* Save the screen */
4707         screen_save();
4708
4709         request_list = always_show_list;
4710
4711         /* Get a spell from the user */
4712         while (!flag)
4713         {
4714                 /* Show the list */
4715                 if (request_list || use_menu)
4716                 {
4717                         byte y, x = 0;
4718                         int ctr, chance;
4719                         int k_idx;
4720                         char dummy[80];
4721                         int x1, y1, level;
4722                         byte col;
4723
4724                         strcpy(dummy, "");
4725
4726                         for (y = 1; y < 20; y++)
4727                                 prt("", y, x);
4728
4729                         y = 1;
4730
4731                         /* Print header(s) */
4732 #ifdef JP
4733                         prt(format("                           %s ¼ºÎ¨                           %s ¼ºÎ¨", (tval == TV_ROD ? "  ¾õÂÖ  " : "»ÈÍѲó¿ô"), (tval == TV_ROD ? "  ¾õÂÖ  " : "»ÈÍѲó¿ô")), y++, x);
4734 #else
4735                         prt(format("                           %s Fail                           %s Fail", (tval == TV_ROD ? "  Stat  " : " Charges"), (tval == TV_ROD ? "  Stat  " : " Charges")), y++, x);
4736 #endif
4737
4738                         /* Print list */
4739                         for (ctr = 0; ctr < EATER_EXT; ctr++)
4740                         {
4741                                 if (!p_ptr->magic_num2[ctr+ext]) continue;
4742
4743                                 k_idx = lookup_kind(tval, ctr);
4744
4745                                 if (use_menu)
4746                                 {
4747                                         if (ctr == (menu_line-1))
4748 #ifdef JP
4749                                                 strcpy(dummy, "¡Õ");
4750 #else
4751                                         strcpy(dummy, "> ");
4752 #endif
4753                                         else strcpy(dummy, "  ");
4754                                                 
4755                                 }
4756                                 /* letter/number for power selection */
4757                                 else
4758                                 {
4759                                         char letter;
4760                                         if (ctr < 26)
4761                                                 letter = I2A(ctr);
4762                                         else
4763                                                 letter = '0' + ctr - 26;
4764                                         sprintf(dummy, "%c)",letter);
4765                                 }
4766                                 x1 = ((ctr < EATER_EXT/2) ? x : x + 40);
4767                                 y1 = ((ctr < EATER_EXT/2) ? y + ctr : y + ctr - EATER_EXT/2);
4768                                 level = (tval == TV_ROD ? k_info[k_idx].level * 5 / 6 - 5 : k_info[k_idx].level);
4769                                 chance = level * 4 / 5 + 20;
4770                                 chance -= 3 * (adj_mag_stat[p_ptr->stat_ind[mp_ptr->spell_stat]] - 1);
4771                                 level /= 2;
4772                                 if (p_ptr->lev > level)
4773                                 {
4774                                         chance -= 3 * (p_ptr->lev - level);
4775                                 }
4776                                 chance = mod_spell_chance_1(chance);
4777                                 chance = MAX(chance, adj_mag_fail[p_ptr->stat_ind[mp_ptr->spell_stat]]);
4778                                 /* Stunning makes spells harder */
4779                                 if (p_ptr->stun > 50) chance += 25;
4780                                 else if (p_ptr->stun) chance += 15;
4781
4782                                 if (chance > 95) chance = 95;
4783
4784                                 chance = mod_spell_chance_2(chance);
4785
4786                                 col = TERM_WHITE;
4787
4788                                 if (k_idx)
4789                                 {
4790                                         if (tval == TV_ROD)
4791                                         {
4792                                                 strcat(dummy, format(
4793 #ifdef JP
4794                                                                " %-22.22s ½¼Å¶:%2d/%2d%3d%%",
4795 #else
4796                                                                " %-22.22s   (%2d/%2d) %3d%%",
4797 #endif
4798                                                                k_name + k_info[k_idx].name, 
4799                                                                p_ptr->magic_num1[ctr+ext] ? 
4800                                                                (p_ptr->magic_num1[ctr+ext] - 1) / (EATER_ROD_CHARGE * k_info[k_idx].pval) +1 : 0, 
4801                                                                p_ptr->magic_num2[ctr+ext], chance));
4802                                                 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;
4803                                         }
4804                                         else
4805                                         {
4806                                                 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));
4807                                                 if (p_ptr->magic_num1[ctr+ext] < EATER_CHARGE) col = TERM_RED;
4808                                         }
4809                                 }
4810                                 else
4811                                         strcpy(dummy, "");
4812                                 c_prt(col, dummy, y1, x1);
4813                         }
4814                 }
4815
4816                 if (!get_com(out_val, &choice, FALSE)) break;
4817
4818                 if (use_menu && choice != ' ')
4819                 {
4820                         switch (choice)
4821                         {
4822                                 case '0':
4823                                 {
4824                                         screen_load();
4825                                         return 0;
4826                                 }
4827
4828                                 case '8':
4829                                 case 'k':
4830                                 case 'K':
4831                                 {
4832                                         do
4833                                         {
4834                                                 menu_line += EATER_EXT - 1;
4835                                                 if (menu_line > EATER_EXT) menu_line -= EATER_EXT;
4836                                         } while(!p_ptr->magic_num2[menu_line+ext-1]);
4837                                         break;
4838                                 }
4839
4840                                 case '2':
4841                                 case 'j':
4842                                 case 'J':
4843                                 {
4844                                         do
4845                                         {
4846                                                 menu_line++;
4847                                                 if (menu_line > EATER_EXT) menu_line -= EATER_EXT;
4848                                         } while(!p_ptr->magic_num2[menu_line+ext-1]);
4849                                         break;
4850                                 }
4851
4852                                 case '4':
4853                                 case 'h':
4854                                 case 'H':
4855                                 case '6':
4856                                 case 'l':
4857                                 case 'L':
4858                                 {
4859                                         bool reverse = FALSE;
4860                                         if ((choice == '4') || (choice == 'h') || (choice == 'H')) reverse = TRUE;
4861                                         if (menu_line > EATER_EXT/2)
4862                                         {
4863                                                 menu_line -= EATER_EXT/2;
4864                                                 reverse = TRUE;
4865                                         }
4866                                         else menu_line+=EATER_EXT/2;
4867                                         while(!p_ptr->magic_num2[menu_line+ext-1])
4868                                         {
4869                                                 if (reverse)
4870                                                 {
4871                                                         menu_line--;
4872                                                         if (menu_line < 2) reverse = FALSE;
4873                                                 }
4874                                                 else
4875                                                 {
4876                                                         menu_line++;
4877                                                         if (menu_line > EATER_EXT-1) reverse = TRUE;
4878                                                 }
4879                                         }
4880                                         break;
4881                                 }
4882
4883                                 case 'x':
4884                                 case 'X':
4885                                 case '\r':
4886                                 {
4887                                         i = menu_line - 1;
4888                                         ask = FALSE;
4889                                         break;
4890                                 }
4891                         }
4892                 }
4893
4894                 /* Request redraw */
4895                 if (use_menu && ask) continue;
4896
4897                 /* Request redraw */
4898                 if (!use_menu && ((choice == ' ') || (choice == '*') || (choice == '?')))
4899                 {
4900                         /* Hide the list */
4901                         if (request_list)
4902                         {
4903                                 /* Hide list */
4904                                 request_list = FALSE;
4905                                 
4906                                 /* Restore the screen */
4907                                 screen_load();
4908                                 screen_save();
4909                         }
4910                         else
4911                                 request_list = TRUE;
4912
4913                         /* Redo asking */
4914                         continue;
4915                 }
4916
4917                 if (!use_menu)
4918                 {
4919                         if (isalpha(choice))
4920                         {
4921                                 /* Note verify */
4922                                 ask = (isupper(choice));
4923
4924                                 /* Lowercase */
4925                                 if (ask) choice = tolower(choice);
4926
4927                                 /* Extract request */
4928                                 i = (islower(choice) ? A2I(choice) : -1);
4929                         }
4930                         else
4931                         {
4932                                 ask = FALSE; /* Can't uppercase digits */
4933
4934                                 i = choice - '0' + 26;
4935                         }
4936                 }
4937
4938                 /* Totally Illegal */
4939                 if ((i < 0) || (i > EATER_EXT) || !p_ptr->magic_num2[i+ext])
4940                 {
4941                         bell();
4942                         continue;
4943                 }
4944
4945                 if (!only_browse)
4946                 {
4947                         /* Verify it */
4948                         if (ask)
4949                         {
4950                                 char tmp_val[160];
4951
4952                                 /* Prompt */
4953 #ifdef JP
4954                                 (void) strnfmt(tmp_val, 78, "%s¤ò»È¤¤¤Þ¤¹¤«¡© ", k_name + k_info[lookup_kind(tval ,i)].name);
4955 #else
4956                                 (void) strnfmt(tmp_val, 78, "Use %s?", k_name + k_info[lookup_kind(tval ,i)].name);
4957 #endif
4958
4959                                 /* Belay that order */
4960                                 if (!get_check(tmp_val)) continue;
4961                         }
4962                         if (tval == TV_ROD)
4963                         {
4964                                 if (p_ptr->magic_num1[ext+i]  > k_info[lookup_kind(tval, i)].pval * (p_ptr->magic_num2[ext+i] - 1) * EATER_ROD_CHARGE)
4965                                 {
4966 #ifdef JP
4967                                         msg_print("¤½¤ÎËâË¡¤Ï¤Þ¤À½¼Å¶¤·¤Æ¤¤¤ëºÇÃæ¤À¡£");
4968 #else
4969                                         msg_print("The magic are still charging.");
4970 #endif
4971                                         msg_print(NULL);
4972                                         if (use_menu) ask = TRUE;
4973                                         continue;
4974                                 }
4975                         }
4976                         else
4977                         {
4978                                 if (p_ptr->magic_num1[ext+i] < EATER_CHARGE)
4979                                 {
4980 #ifdef JP
4981                                         msg_print("¤½¤ÎËâË¡¤Ï»ÈÍѲó¿ô¤¬ÀÚ¤ì¤Æ¤¤¤ë¡£");
4982 #else
4983                                         msg_print("The magic has no charges left.");
4984 #endif
4985                                         msg_print(NULL);
4986                                         if (use_menu) ask = TRUE;
4987                                         continue;
4988                                 }
4989                         }
4990                 }
4991
4992                 /* Browse */
4993                 else
4994                 {
4995                         int line, j;
4996                         char temp[70 * 20];
4997
4998                         /* Clear lines, position cursor  (really should use strlen here) */
4999                         Term_erase(7, 23, 255);
5000                         Term_erase(7, 22, 255);
5001                         Term_erase(7, 21, 255);
5002                         Term_erase(7, 20, 255);
5003
5004                         roff_to_buf(k_text + k_info[lookup_kind(tval, i)].text, 62, temp, sizeof(temp));
5005                         for (j = 0, line = 21; temp[j]; j += 1 + strlen(&temp[j]))
5006                         {
5007                                 prt(&temp[j], line, 10);
5008                                 line++;
5009                         }
5010
5011                         continue;
5012                 }
5013
5014                 /* Stop the loop */
5015                 flag = TRUE;
5016         }
5017
5018         /* Restore the screen */
5019         screen_load();
5020
5021         if (!flag) return -1;
5022
5023 #ifdef ALLOW_REPEAT
5024         repeat_push(ext+i);
5025 #endif /* ALLOW_REPEAT */
5026         return ext+i;
5027 }
5028
5029
5030 /*
5031  *  Use eaten rod, wand or staff
5032  */
5033 bool do_cmd_magic_eater(bool only_browse, bool powerful)
5034 {
5035         int item, chance, level, k_idx, tval, sval;
5036         bool use_charge = TRUE;
5037
5038         /* Not when confused */
5039         if (!only_browse && p_ptr->confused)
5040         {
5041 #ifdef JP
5042 msg_print("º®Í𤷤Ƥ¤¤Æ¾§¤¨¤é¤ì¤Ê¤¤¡ª");
5043 #else
5044                 msg_print("You are too confused!");
5045 #endif
5046
5047                 return FALSE;
5048         }
5049
5050         item = select_magic_eater(only_browse);
5051         if (item == -1)
5052         {
5053                 energy_use = 0;
5054                 return FALSE;
5055         }
5056         if (item >= EATER_EXT*2) {tval = TV_ROD;sval = item - EATER_EXT*2;}
5057         else if (item >= EATER_EXT) {tval = TV_WAND;sval = item - EATER_EXT;}
5058         else {tval = TV_STAFF;sval = item;}
5059         k_idx = lookup_kind(tval, sval);
5060
5061         level = (tval == TV_ROD ? k_info[k_idx].level * 5 / 6 - 5 : k_info[k_idx].level);
5062         chance = level * 4 / 5 + 20;
5063         chance -= 3 * (adj_mag_stat[p_ptr->stat_ind[mp_ptr->spell_stat]] - 1);
5064         level /= 2;
5065         if (p_ptr->lev > level)
5066         {
5067                 chance -= 3 * (p_ptr->lev - level);
5068         }
5069         chance = mod_spell_chance_1(chance);
5070         chance = MAX(chance, adj_mag_fail[p_ptr->stat_ind[mp_ptr->spell_stat]]);
5071         /* Stunning makes spells harder */
5072         if (p_ptr->stun > 50) chance += 25;
5073         else if (p_ptr->stun) chance += 15;
5074
5075         if (chance > 95) chance = 95;
5076
5077         chance = mod_spell_chance_2(chance);
5078
5079         if (randint0(100) < chance)
5080         {
5081                 if (flush_failure) flush();
5082
5083 #ifdef JP
5084 msg_print("¼öʸ¤ò¤¦¤Þ¤¯¾§¤¨¤é¤ì¤Ê¤«¤Ã¤¿¡ª");
5085 #else
5086                 msg_format("You failed to get the magic off!");
5087 #endif
5088
5089                 sound(SOUND_FAIL);
5090                 if (randint1(100) >= chance)
5091                         chg_virtue(V_CHANCE,-1);
5092                 energy_use = 100;
5093
5094                 return TRUE;
5095         }
5096         else
5097         {
5098                 int dir = 0;
5099
5100                 if (tval == TV_ROD)
5101                 {
5102                         if ((sval >= SV_ROD_MIN_DIRECTION) && (sval != SV_ROD_HAVOC) && (sval != SV_ROD_AGGRAVATE) && (sval != SV_ROD_PESTICIDE))
5103                                 if (!get_aim_dir(&dir)) return FALSE;
5104                         rod_effect(sval, dir, &use_charge, powerful, TRUE);
5105                         if (!use_charge) return FALSE;
5106                 }
5107                 else if (tval == TV_WAND)
5108                 {
5109                         if (!get_aim_dir(&dir)) return FALSE;
5110                         wand_effect(sval, dir, powerful, TRUE);
5111                 }
5112                 else
5113                 {
5114                         staff_effect(sval, &use_charge, powerful, TRUE, TRUE);
5115                         if (!use_charge) return FALSE;
5116                 }
5117                 if (randint1(100) < chance)
5118                         chg_virtue(V_CHANCE,1);
5119         }
5120         energy_use = 100;
5121         if (tval == TV_ROD) p_ptr->magic_num1[item] += k_info[k_idx].pval * EATER_ROD_CHARGE;
5122         else p_ptr->magic_num1[item] -= EATER_CHARGE;
5123
5124         return TRUE;
5125 }