OSDN Git Service

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