OSDN Git Service

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