OSDN Git Service

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