OSDN Git Service

1c066bc3faa88b0ec0cc10c1b26592d23c930887
[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 #include "selfinfo.h"
57 #include "cmd-activate.h"
58 #include "cmd-eat.h"
59 #include "cmd-quaff.h"
60 #include "cmd-read.h"
61 #include "cmd-usestaff.h"
62
63
64
65 /*!
66  * @brief 魔法棒の効果を発動する
67  * @param sval オブジェクトのsval
68  * @param dir 発動の方向ID
69  * @param powerful 強力発動上の処理ならばTRUE
70  * @param magic 魔道具術上の処理ならばTRUE
71  * @return 発動により効果内容が確定したならばTRUEを返す
72  */
73 static int wand_effect(OBJECT_SUBTYPE_VALUE sval, int dir, bool powerful, bool magic)
74 {
75         int ident = FALSE;
76         int lev = powerful ? p_ptr->lev * 2 : p_ptr->lev;
77         int rad = powerful ? 3 : 2;
78
79         /* XXX Hack -- Wand of wonder can do anything before it */
80         if (sval == SV_WAND_WONDER)
81         {
82                 int vir = virtue_number(V_CHANCE);
83                 sval = (OBJECT_SUBTYPE_VALUE)randint0(SV_WAND_WONDER);
84
85                 if (vir)
86                 {
87                         if (p_ptr->virtues[vir - 1] > 0)
88                         {
89                                 while (randint1(300) < p_ptr->virtues[vir - 1]) sval++;
90                                 if (sval > SV_WAND_COLD_BALL) sval = randint0(4) + SV_WAND_ACID_BALL;
91                         }
92                         else
93                         {
94                                 while (randint1(300) < (0-p_ptr->virtues[vir - 1])) sval--;
95                                 if (sval < SV_WAND_HEAL_MONSTER) sval = randint0(3) + SV_WAND_HEAL_MONSTER;
96                         }
97                 }
98                 if (sval < SV_WAND_TELEPORT_AWAY)
99                         chg_virtue(V_CHANCE, 1);
100         }
101
102         /* Analyze the wand */
103         switch (sval)
104         {
105                 case SV_WAND_HEAL_MONSTER:
106                 {
107                         HIT_POINT dam = damroll((powerful ? 20 : 10), 10);
108                         if (heal_monster(dir, dam)) ident = TRUE;
109                         break;
110                 }
111
112                 case SV_WAND_HASTE_MONSTER:
113                 {
114                         if (speed_monster(dir, lev)) ident = TRUE;
115                         break;
116                 }
117
118                 case SV_WAND_CLONE_MONSTER:
119                 {
120                         if (clone_monster(dir)) ident = TRUE;
121                         break;
122                 }
123
124                 case SV_WAND_TELEPORT_AWAY:
125                 {
126                         int distance = MAX_SIGHT * (powerful ? 8 : 5);
127                         if (teleport_monster(dir, distance)) ident = TRUE;
128                         break;
129                 }
130
131                 case SV_WAND_DISARMING:
132                 {
133                         if (disarm_trap(dir)) ident = TRUE;
134                         if (powerful && disarm_traps_touch()) ident = TRUE;
135                         break;
136                 }
137
138                 case SV_WAND_TRAP_DOOR_DEST:
139                 {
140                         if (destroy_door(dir)) ident = TRUE;
141                         if (powerful && destroy_doors_touch()) ident = TRUE;
142                         break;
143                 }
144
145                 case SV_WAND_STONE_TO_MUD:
146                 {
147                         HIT_POINT dam = powerful ? 40 + randint1(60) : 20 + randint1(30);
148                         if (wall_to_mud(dir, dam)) ident = TRUE;
149                         break;
150                 }
151
152                 case SV_WAND_LITE:
153                 {
154                         HIT_POINT dam = damroll((powerful ? 12 : 6), 8);
155                         msg_print(_("青く輝く光線が放たれた。", "A line of blue shimmering light appears."));
156                         (void)lite_line(dir, dam);
157                         ident = TRUE;
158                         break;
159                 }
160
161                 case SV_WAND_SLEEP_MONSTER:
162                 {
163                         if (sleep_monster(dir, lev)) ident = TRUE;
164                         break;
165                 }
166
167                 case SV_WAND_SLOW_MONSTER:
168                 {
169                         if (slow_monster(dir, lev)) ident = TRUE;
170                         break;
171                 }
172
173                 case SV_WAND_CONFUSE_MONSTER:
174                 {
175                         if (confuse_monster(dir, lev)) ident = TRUE;
176                         break;
177                 }
178
179                 case SV_WAND_FEAR_MONSTER:
180                 {
181                         if (fear_monster(dir, lev)) ident = TRUE;
182                         break;
183                 }
184
185                 case SV_WAND_HYPODYNAMIA:
186                 {
187                         if (hypodynamic_bolt(dir, 80 + lev)) ident = TRUE;
188                         break;
189                 }
190
191                 case SV_WAND_POLYMORPH:
192                 {
193                         if (poly_monster(dir, lev)) ident = TRUE;
194                         break;
195                 }
196
197                 case SV_WAND_STINKING_CLOUD:
198                 {
199                         fire_ball(GF_POIS, dir, 12 + lev / 4, rad);
200                         ident = TRUE;
201                         break;
202                 }
203
204                 case SV_WAND_MAGIC_MISSILE:
205                 {
206                         fire_bolt_or_beam(20, GF_MISSILE, dir, damroll(2 + lev / 10, 6));
207                         ident = TRUE;
208                         break;
209                 }
210
211                 case SV_WAND_ACID_BOLT:
212                 {
213                         fire_bolt_or_beam(20, GF_ACID, dir, damroll(6 + lev / 7, 8));
214                         ident = TRUE;
215                         break;
216                 }
217
218                 case SV_WAND_CHARM_MONSTER:
219                 {
220                         if (charm_monster(dir, MAX(20, lev)))
221                         ident = TRUE;
222                         break;
223                 }
224
225                 case SV_WAND_FIRE_BOLT:
226                 {
227                         fire_bolt_or_beam(20, GF_FIRE, dir, damroll(7 + lev / 6, 8));
228                         ident = TRUE;
229                         break;
230                 }
231
232                 case SV_WAND_COLD_BOLT:
233                 {
234                         fire_bolt_or_beam(20, GF_COLD, dir, damroll(5 + lev / 8, 8));
235                         ident = TRUE;
236                         break;
237                 }
238
239                 case SV_WAND_ACID_BALL:
240                 {
241                         fire_ball(GF_ACID, dir, 60 + 3 * lev / 4, rad);
242                         ident = TRUE;
243                         break;
244                 }
245
246                 case SV_WAND_ELEC_BALL:
247                 {
248                         fire_ball(GF_ELEC, dir, 40 + 3 * lev / 4, rad);
249                         ident = TRUE;
250                         break;
251                 }
252
253                 case SV_WAND_FIRE_BALL:
254                 {
255                         fire_ball(GF_FIRE, dir, 70 + 3 * lev / 4, rad);
256                         ident = TRUE;
257                         break;
258                 }
259
260                 case SV_WAND_COLD_BALL:
261                 {
262                         fire_ball(GF_COLD, dir, 50 + 3 * lev / 4, rad);
263                         ident = TRUE;
264                         break;
265                 }
266
267                 case SV_WAND_WONDER:
268                 {
269                         msg_print(_("おっと、謎の魔法棒を始動させた。", "Oops.  Wand of wonder activated."));
270                         break;
271                 }
272
273                 case SV_WAND_DRAGON_FIRE:
274                 {
275                         fire_breath(GF_FIRE, dir, (powerful ? 300 : 200), 3);
276                         ident = TRUE;
277                         break;
278                 }
279
280                 case SV_WAND_DRAGON_COLD:
281                 {
282                         fire_breath(GF_COLD, dir, (powerful ? 270 : 180), 3);
283                         ident = TRUE;
284                         break;
285                 }
286
287                 case SV_WAND_DRAGON_BREATH:
288                 {
289                         HIT_POINT dam;
290                         int typ;
291
292                         switch (randint1(5))
293                         {
294                                 case 1:
295                                         dam = 240;
296                                         typ = GF_ACID;
297                                         break;
298                                 case 2:
299                                         dam = 210;
300                                         typ = GF_ELEC;
301                                         break;
302                                 case 3:
303                                         dam = 240;
304                                         typ = GF_FIRE;
305                                         break;
306                                 case 4:
307                                         dam = 210;
308                                         typ = GF_COLD;
309                                         break;
310                                 default:
311                                         dam = 180;
312                                         typ = GF_POIS;
313                                         break;
314                         }
315
316                         if (powerful) dam = (dam * 3) / 2;
317
318                         fire_ball(typ, dir, dam, -3);
319
320                         ident = TRUE;
321                         break;
322                 }
323
324                 case SV_WAND_DISINTEGRATE:
325                 {
326                         fire_ball(GF_DISINTEGRATE, dir, 200 + randint1(lev * 2), rad);
327                         ident = TRUE;
328                         break;
329                 }
330
331                 case SV_WAND_ROCKETS:
332                 {
333                         msg_print(_("ロケットを発射した!", "You launch a rocket!"));
334                         fire_rocket(GF_ROCKET, dir, 250 + lev * 3, rad);
335                         ident = TRUE;
336                         break;
337                 }
338
339                 case SV_WAND_STRIKING:
340                 {
341                         fire_bolt(GF_METEOR, dir, damroll(15 + lev / 3, 13));
342                         ident = TRUE;
343                         break;
344                 }
345
346                 case SV_WAND_GENOCIDE:
347                 {
348                         fire_ball_hide(GF_GENOCIDE, dir, magic ? lev + 50 : 250, 0);
349                         ident = TRUE;
350                         break;
351                 }
352         }
353         return ident;
354 }
355
356 /*!
357  * @brief 魔法棒を使うコマンドのサブルーチン / 
358  * Aim a wand (from the pack or floor).
359  * @param item 使うオブジェクトの所持品ID
360  * @return なし
361  * @details
362  * <pre>
363  * Use a single charge from a single item.
364  * Handle "unstacking" in a logical manner.
365  * For simplicity, you cannot use a stack of items from the
366  * ground.  This would require too much nasty code.
367  * There are no wands which can "destroy" themselves, in the inventory
368  * or on the ground, so we can ignore this possibility.  Note that this
369  * required giving "wand of wonder" the ability to ignore destruction
370  * by electric balls.
371  * All wands can be "cancelled" at the "Direction?" prompt for free.
372  * Note that the basic "bolt" wands do slightly less damage than the
373  * basic "bolt" rods, but the basic "ball" wands do the same damage
374  * as the basic "ball" rods.
375  * </pre>
376  */
377 static void do_cmd_aim_wand_aux(int item)
378 {
379         int         lev, ident, chance, dir;
380         object_type *o_ptr;
381         bool old_target_pet = target_pet;
382
383         /* Get the item (in the pack) */
384         if (item >= 0)
385         {
386                 o_ptr = &inventory[item];
387         }
388
389         /* Get the item (on the floor) */
390         else
391         {
392                 o_ptr = &o_list[0 - item];
393         }
394
395         /* Mega-Hack -- refuse to aim a pile from the ground */
396         if ((item < 0) && (o_ptr->number > 1))
397         {
398                 msg_print(_("まずは魔法棒を拾わなければ。", "You must first pick up the wands."));
399                 return;
400         }
401
402
403         /* Allow direction to be cancelled for free */
404         if (object_is_aware(o_ptr) && (o_ptr->sval == SV_WAND_HEAL_MONSTER
405                                       || o_ptr->sval == SV_WAND_HASTE_MONSTER))
406                         target_pet = TRUE;
407         if (!get_aim_dir(&dir))
408         {
409                 target_pet = old_target_pet;
410                 return;
411         }
412         target_pet = old_target_pet;
413
414         /* Take a turn */
415         p_ptr->energy_use = 100;
416
417         /* Get the level */
418         lev = k_info[o_ptr->k_idx].level;
419         if (lev > 50) lev = 50 + (lev - 50)/2;
420
421         /* Base chance of success */
422         chance = p_ptr->skill_dev;
423
424         /* Confusion hurts skill */
425         if (p_ptr->confused) chance = chance / 2;
426
427         /* Hight level objects are harder */
428         chance = chance - lev;
429
430         /* Give everyone a (slight) chance */
431         if ((chance < USE_DEVICE) && one_in_(USE_DEVICE - chance + 1))
432         {
433                 chance = USE_DEVICE;
434         }
435
436         if (world_player)
437         {
438                 if (flush_failure) flush();
439                 msg_print(_("止まった時の中ではうまく働かないようだ。", "Nothing happen. Maybe this wand is freezing too."));
440                 sound(SOUND_FAIL);
441                 return;
442         }
443
444         /* Roll for usage */
445         if ((chance < USE_DEVICE) || (randint1(chance) < USE_DEVICE) || (p_ptr->pclass == CLASS_BERSERKER))
446         {
447                 if (flush_failure) flush();
448                 msg_print(_("魔法棒をうまく使えなかった。", "You failed to use the wand properly."));
449                 sound(SOUND_FAIL);
450                 return;
451         }
452
453         /* The wand is already empty! */
454         if (o_ptr->pval <= 0)
455         {
456                 if (flush_failure) flush();
457                 msg_print(_("この魔法棒にはもう魔力が残っていない。", "The wand has no charges left."));
458                 o_ptr->ident |= (IDENT_EMPTY);
459
460                 /* Combine / Reorder the pack (later) */
461                 p_ptr->notice |= (PN_COMBINE | PN_REORDER);
462                 p_ptr->window |= (PW_INVEN);
463
464                 return;
465         }
466
467         /* Sound */
468         sound(SOUND_ZAP);
469
470         ident = wand_effect(o_ptr->sval, dir, FALSE, FALSE);
471
472         /* Combine / Reorder the pack (later) */
473         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
474
475         if (!(object_is_aware(o_ptr)))
476         {
477                 chg_virtue(V_PATIENCE, -1);
478                 chg_virtue(V_CHANCE, 1);
479                 chg_virtue(V_KNOWLEDGE, -1);
480         }
481
482         /* Mark it as tried */
483         object_tried(o_ptr);
484
485         /* Apply identification */
486         if (ident && !object_is_aware(o_ptr))
487         {
488                 object_aware(o_ptr);
489                 gain_exp((lev + (p_ptr->lev >> 1)) / p_ptr->lev);
490         }
491
492         /* Window stuff */
493         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
494
495
496         /* Use a single charge */
497         o_ptr->pval--;
498
499         /* Describe the charges in the pack */
500         if (item >= 0)
501         {
502                 inven_item_charges(item);
503         }
504
505         /* Describe the charges on the floor */
506         else
507         {
508                 floor_item_charges(0 - item);
509         }
510 }
511
512 /*!
513  * @brief 魔法棒を使うコマンドのメインルーチン /
514  * @return なし
515  */
516 void do_cmd_aim_wand(void)
517 {
518         OBJECT_IDX item;
519         cptr    q, s;
520
521         /* Restrict choices to wands */
522         item_tester_tval = TV_WAND;
523
524         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
525         {
526                 set_action(ACTION_NONE);
527         }
528
529         /* Get an item */
530         q = _("どの魔法棒で狙いますか? ", "Aim which wand? ");
531         s = _("使える魔法棒がない。", "You have no wand to aim.");
532         
533         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
534
535         /* Aim the wand */
536         do_cmd_aim_wand_aux(item);
537 }
538
539 /*!
540  * @brief ロッドの効果を発動する
541  * @param sval オブジェクトのsval
542  * @param dir 発動目標の方向ID
543  * @param use_charge チャージを消費したかどうかを返す参照ポインタ
544  * @param powerful 強力発動上の処理ならばTRUE
545  * @param magic 魔道具術上の処理ならばTRUE
546  * @return 発動により効果内容が確定したならばTRUEを返す
547  */
548 static int rod_effect(OBJECT_SUBTYPE_VALUE sval, int dir, bool *use_charge, bool powerful, bool magic)
549 {
550         int ident = FALSE;
551         int lev = powerful ? p_ptr->lev * 2 : p_ptr->lev;
552         int detect_rad = powerful ? DETECT_RAD_DEFAULT * 3 / 2 : DETECT_RAD_DEFAULT;
553         int rad = powerful ? 3 : 2;
554
555         /* Unused */
556         (void)magic;
557
558         /* Analyze the rod */
559         switch (sval)
560         {
561                 case SV_ROD_DETECT_TRAP:
562                 {
563                         if (detect_traps(detect_rad, (bool)(dir ? FALSE : TRUE))) ident = TRUE;
564                         break;
565                 }
566
567                 case SV_ROD_DETECT_DOOR:
568                 {
569                         if (detect_doors(detect_rad)) ident = TRUE;
570                         if (detect_stairs(detect_rad)) ident = TRUE;
571                         break;
572                 }
573
574                 case SV_ROD_IDENTIFY:
575                 {
576                         if (powerful) {
577                                 if (!identify_fully(FALSE)) *use_charge = FALSE;
578                         } else {
579                                 if (!ident_spell(FALSE)) *use_charge = FALSE;
580                         }
581                         ident = TRUE;
582                         break;
583                 }
584
585                 case SV_ROD_RECALL:
586                 {
587                         if (!word_of_recall()) *use_charge = FALSE;
588                         ident = TRUE;
589                         break;
590                 }
591
592                 case SV_ROD_ILLUMINATION:
593                 {
594                         if (lite_area(damroll(2, 8), (powerful ? 4 : 2))) ident = TRUE;
595                         break;
596                 }
597
598                 case SV_ROD_MAPPING:
599                 {
600                         map_area(powerful ? DETECT_RAD_MAP * 3 / 2 : DETECT_RAD_MAP);
601                         ident = TRUE;
602                         break;
603                 }
604
605                 case SV_ROD_DETECTION:
606                 {
607                         detect_all(detect_rad);
608                         ident = TRUE;
609                         break;
610                 }
611
612                 case SV_ROD_PROBING:
613                 {
614                         probing();
615                         ident = TRUE;
616                         break;
617                 }
618
619                 case SV_ROD_CURING:
620                 {
621                         if (set_blind(0)) ident = TRUE;
622                         if (set_poisoned(0)) ident = TRUE;
623                         if (set_confused(0)) ident = TRUE;
624                         if (set_stun(0)) ident = TRUE;
625                         if (set_cut(0)) ident = TRUE;
626                         if (set_image(0)) ident = TRUE;
627                         if (set_shero(0,TRUE)) ident = TRUE;
628                         break;
629                 }
630
631                 case SV_ROD_HEALING:
632                 {
633                         if (hp_player(powerful ? 750 : 500)) ident = TRUE;
634                         if (set_stun(0)) ident = TRUE;
635                         if (set_cut(0)) ident = TRUE;
636                         if (set_shero(0,TRUE)) ident = TRUE;
637                         break;
638                 }
639
640                 case SV_ROD_RESTORATION:
641                 {
642                         if (restore_level()) ident = TRUE;
643                         if (do_res_stat(A_STR)) ident = TRUE;
644                         if (do_res_stat(A_INT)) ident = TRUE;
645                         if (do_res_stat(A_WIS)) ident = TRUE;
646                         if (do_res_stat(A_DEX)) ident = TRUE;
647                         if (do_res_stat(A_CON)) ident = TRUE;
648                         if (do_res_stat(A_CHR)) ident = TRUE;
649                         break;
650                 }
651
652                 case SV_ROD_SPEED:
653                 {
654                         if (set_fast(randint1(30) + (powerful ? 30 : 15), FALSE)) ident = TRUE;
655                         break;
656                 }
657
658                 case SV_ROD_PESTICIDE:
659                 {
660                         if (dispel_monsters(powerful ? 8 : 4)) ident = TRUE;
661                         break;
662                 }
663
664                 case SV_ROD_TELEPORT_AWAY:
665                 {
666                         int distance = MAX_SIGHT * (powerful ? 8 : 5);
667                         if (teleport_monster(dir, distance)) ident = TRUE;
668                         break;
669                 }
670
671                 case SV_ROD_DISARMING:
672                 {
673                         if (disarm_trap(dir)) ident = TRUE;
674                         if (powerful && disarm_traps_touch()) ident = TRUE;
675                         break;
676                 }
677
678                 case SV_ROD_LITE:
679                 {
680                         HIT_POINT dam = damroll((powerful ? 12 : 6), 8);
681                         msg_print(_("青く輝く光線が放たれた。", "A line of blue shimmering light appears."));
682                         (void)lite_line(dir, dam);
683                         ident = TRUE;
684                         break;
685                 }
686
687                 case SV_ROD_SLEEP_MONSTER:
688                 {
689                         if (sleep_monster(dir, lev)) ident = TRUE;
690                         break;
691                 }
692
693                 case SV_ROD_SLOW_MONSTER:
694                 {
695                         if (slow_monster(dir, lev)) ident = TRUE;
696                         break;
697                 }
698
699                 case SV_ROD_HYPODYNAMIA:
700                 {
701                         if (hypodynamic_bolt(dir, 70 + 3 * lev / 2)) ident = TRUE;
702                         break;
703                 }
704
705                 case SV_ROD_POLYMORPH:
706                 {
707                         if (poly_monster(dir, lev)) ident = TRUE;
708                         break;
709                 }
710
711                 case SV_ROD_ACID_BOLT:
712                 {
713                         fire_bolt_or_beam(10, GF_ACID, dir, damroll(6 + lev / 7, 8));
714                         ident = TRUE;
715                         break;
716                 }
717
718                 case SV_ROD_ELEC_BOLT:
719                 {
720                         fire_bolt_or_beam(10, GF_ELEC, dir, damroll(4 + lev / 9, 8));
721                         ident = TRUE;
722                         break;
723                 }
724
725                 case SV_ROD_FIRE_BOLT:
726                 {
727                         fire_bolt_or_beam(10, GF_FIRE, dir, damroll(7 + lev / 6, 8));
728                         ident = TRUE;
729                         break;
730                 }
731
732                 case SV_ROD_COLD_BOLT:
733                 {
734                         fire_bolt_or_beam(10, GF_COLD, dir, damroll(5 + lev / 8, 8));
735                         ident = TRUE;
736                         break;
737                 }
738
739                 case SV_ROD_ACID_BALL:
740                 {
741                         fire_ball(GF_ACID, dir, 60 + lev, rad);
742                         ident = TRUE;
743                         break;
744                 }
745
746                 case SV_ROD_ELEC_BALL:
747                 {
748                         fire_ball(GF_ELEC, dir, 40 + lev, rad);
749                         ident = TRUE;
750                         break;
751                 }
752
753                 case SV_ROD_FIRE_BALL:
754                 {
755                         fire_ball(GF_FIRE, dir, 70 + lev, rad);
756                         ident = TRUE;
757                         break;
758                 }
759
760                 case SV_ROD_COLD_BALL:
761                 {
762                         fire_ball(GF_COLD, dir, 50 + lev, rad);
763                         ident = TRUE;
764                         break;
765                 }
766
767                 case SV_ROD_HAVOC:
768                 {
769                         call_chaos();
770                         ident = TRUE;
771                         break;
772                 }
773
774                 case SV_ROD_STONE_TO_MUD:
775                 {
776                         HIT_POINT dam = powerful ? 40 + randint1(60) : 20 + randint1(30);
777                         if (wall_to_mud(dir, dam)) ident = TRUE;
778                         break;
779                 }
780
781                 case SV_ROD_AGGRAVATE:
782                 {
783                         aggravate_monsters(0);
784                         ident = TRUE;
785                         break;
786                 }
787         }
788         return ident;
789 }
790
791 /*!
792  * @brief 魔法棒を使うコマンドのサブルーチン / 
793  * Activate (zap) a Rod
794  * @param item 使うオブジェクトの所持品ID
795  * @return なし
796  * @details
797  * <pre>
798  * Unstack fully charged rods as needed.
799  * Hack -- rods of perception/genocide can be "cancelled"
800  * All rods can be cancelled at the "Direction?" prompt
801  * pvals are defined for each rod in k_info. -LM-
802  * </pre>
803  */
804 static void do_cmd_zap_rod_aux(int item)
805 {
806         int ident, chance, lev, fail;
807         int dir = 0;
808         object_type *o_ptr;
809         bool success;
810
811         /* Hack -- let perception get aborted */
812         bool use_charge = TRUE;
813
814         object_kind *k_ptr;
815
816         /* Get the item (in the pack) */
817         if (item >= 0)
818         {
819                 o_ptr = &inventory[item];
820         }
821
822         /* Get the item (on the floor) */
823         else
824         {
825                 o_ptr = &o_list[0 - item];
826         }
827
828
829         /* Mega-Hack -- refuse to zap a pile from the ground */
830         if ((item < 0) && (o_ptr->number > 1))
831         {
832                 msg_print(_("まずはロッドを拾わなければ。", "You must first pick up the rods."));
833                 return;
834         }
835
836
837         /* Get a direction (unless KNOWN not to need it) */
838         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)) ||
839              !object_is_aware(o_ptr))
840         {
841                 /* Get a direction, allow cancel */
842                 if (!get_aim_dir(&dir)) return;
843         }
844
845
846         /* Take a turn */
847         p_ptr->energy_use = 100;
848
849         /* Extract the item level */
850         lev = k_info[o_ptr->k_idx].level;
851
852         /* Base chance of success */
853         chance = p_ptr->skill_dev;
854
855         /* Confusion hurts skill */
856         if (p_ptr->confused) chance = chance / 2;
857
858         fail = lev+5;
859         if (chance > fail) fail -= (chance - fail)*2;
860         else chance -= (fail - chance)*2;
861         if (fail < USE_DEVICE) fail = USE_DEVICE;
862         if (chance < USE_DEVICE) chance = USE_DEVICE;
863
864         if (world_player)
865         {
866                 if (flush_failure) flush();
867                 msg_print(_("止まった時の中ではうまく働かないようだ。", "Nothing happen. Maybe this rod is freezing too."));
868                 sound(SOUND_FAIL);
869                 return;
870         }
871
872         if (p_ptr->pclass == CLASS_BERSERKER) success = FALSE;
873         else if (chance > fail)
874         {
875                 if (randint0(chance*2) < fail) success = FALSE;
876                 else success = TRUE;
877         }
878         else
879         {
880                 if (randint0(fail*2) < chance) success = TRUE;
881                 else success = FALSE;
882         }
883
884         /* Roll for usage */
885         if (!success)
886         {
887                 if (flush_failure) flush();
888                 msg_print(_("うまくロッドを使えなかった。", "You failed to use the rod properly."));
889                 sound(SOUND_FAIL);
890                 return;
891         }
892
893         k_ptr = &k_info[o_ptr->k_idx];
894
895         /* A single rod is still charging */
896         if ((o_ptr->number == 1) && (o_ptr->timeout))
897         {
898                 if (flush_failure) flush();
899                 msg_print(_("このロッドはまだ魔力を充填している最中だ。", "The rod is still charging."));
900                 return;
901         }
902         /* A stack of rods lacks enough energy. */
903         else if ((o_ptr->number > 1) && (o_ptr->timeout > k_ptr->pval * (o_ptr->number - 1)))
904         {
905                 if (flush_failure) flush();
906                 msg_print(_("そのロッドはまだ充填中です。", "The rods are all still charging."));
907                 return;
908         }
909
910         /* Sound */
911         sound(SOUND_ZAP);
912
913         ident = rod_effect(o_ptr->sval, dir, &use_charge, FALSE, FALSE);
914
915         /* Increase the timeout by the rod kind's pval. -LM- */
916         if (use_charge) o_ptr->timeout += k_ptr->pval;
917
918         /* Combine / Reorder the pack (later) */
919         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
920
921         if (!(object_is_aware(o_ptr)))
922         {
923                 chg_virtue(V_PATIENCE, -1);
924                 chg_virtue(V_CHANCE, 1);
925                 chg_virtue(V_KNOWLEDGE, -1);
926         }
927
928         /* Tried the object */
929         object_tried(o_ptr);
930
931         /* Successfully determined the object function */
932         if (ident && !object_is_aware(o_ptr))
933         {
934                 object_aware(o_ptr);
935                 gain_exp((lev + (p_ptr->lev >> 1)) / p_ptr->lev);
936         }
937
938         /* Window stuff */
939         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
940 }
941
942 /*!
943  * @brief ロッドを使うコマンドのメインルーチン /
944  * @return なし
945  */
946 void do_cmd_zap_rod(void)
947 {
948         OBJECT_IDX item;
949         cptr q, s;
950
951         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
952         {
953                 set_action(ACTION_NONE);
954         }
955
956         /* Restrict choices to rods */
957         item_tester_tval = TV_ROD;
958
959         /* Get an item */
960         q = _("どのロッドを振りますか? ", "Zap which rod? ");
961         s = _("使えるロッドがない。", "You have no rod to zap.");
962
963         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
964
965         /* Zap the rod */
966         do_cmd_zap_rod_aux(item);
967 }
968
969 /*!
970  * @brief 『一つの指輪』の効果処理 /
971  * Hack -- activate the ring of power
972  * @param dir 発動の方向ID
973  * @return なし
974  */
975 void ring_of_power(int dir)
976 {
977         /* Pick a random effect */
978         switch (randint1(10))
979         {
980                 case 1:
981                 case 2:
982                 {
983                         /* Message */
984                         msg_print(_("あなたは悪性のオーラに包み込まれた。", "You are surrounded by a malignant aura."));
985                         sound(SOUND_EVIL);
986
987                         /* Decrease all stats (permanently) */
988                         (void)dec_stat(A_STR, 50, TRUE);
989                         (void)dec_stat(A_INT, 50, TRUE);
990                         (void)dec_stat(A_WIS, 50, TRUE);
991                         (void)dec_stat(A_DEX, 50, TRUE);
992                         (void)dec_stat(A_CON, 50, TRUE);
993                         (void)dec_stat(A_CHR, 50, TRUE);
994
995                         /* Lose some experience (permanently) */
996                         p_ptr->exp -= (p_ptr->exp / 4);
997                         p_ptr->max_exp -= (p_ptr->exp / 4);
998                         check_experience();
999
1000                         break;
1001                 }
1002
1003                 case 3:
1004                 {
1005                         /* Message */
1006                         msg_print(_("あなたは強力なオーラに包み込まれた。", "You are surrounded by a powerful aura."));
1007
1008                         /* Dispel monsters */
1009                         dispel_monsters(1000);
1010
1011                         break;
1012                 }
1013
1014                 case 4:
1015                 case 5:
1016                 case 6:
1017                 {
1018                         /* Mana Ball */
1019                         fire_ball(GF_MANA, dir, 600, 3);
1020
1021                         break;
1022                 }
1023
1024                 case 7:
1025                 case 8:
1026                 case 9:
1027                 case 10:
1028                 {
1029                         /* Mana Bolt */
1030                         fire_bolt(GF_MANA, dir, 500);
1031
1032                         break;
1033                 }
1034         }
1035 }
1036
1037 /*!
1038  * @brief オブジェクトをプレイヤーが簡易使用コマンドで利用できるかを判定する /
1039  * Hook to determine if an object is useable
1040  * @param o_ptr 判定したいオブジェクトの構造体参照ポインタ
1041  * @return 利用可能ならばTRUEを返す
1042  */
1043 static bool item_tester_hook_use(object_type *o_ptr)
1044 {
1045         u32b flgs[TR_FLAG_SIZE];
1046
1047         /* Ammo */
1048         if (o_ptr->tval == p_ptr->tval_ammo)
1049                 return (TRUE);
1050
1051         /* Useable object */
1052         switch (o_ptr->tval)
1053         {
1054                 case TV_SPIKE:
1055                 case TV_STAFF:
1056                 case TV_WAND:
1057                 case TV_ROD:
1058                 case TV_SCROLL:
1059                 case TV_POTION:
1060                 case TV_FOOD:
1061                 {
1062                         return (TRUE);
1063                 }
1064
1065                 default:
1066                 {
1067                         int i;
1068
1069                         /* Not known */
1070                         if (!object_is_known(o_ptr)) return (FALSE);
1071
1072                         /* HACK - only items from the equipment can be activated */
1073                         for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
1074                         {
1075                                 if (&inventory[i] == o_ptr)
1076                                 {
1077                                         /* Extract the flags */
1078                                         object_flags(o_ptr, flgs);
1079
1080                                         /* Check activation flag */
1081                                         if (have_flag(flgs, TR_ACTIVATE)) return (TRUE);
1082                                 }
1083                         }
1084                 }
1085         }
1086
1087         /* Assume not */
1088         return (FALSE);
1089 }
1090
1091
1092 /*!
1093  * @brief アイテムを汎用的に「使う」コマンドのメインルーチン /
1094  * Use an item
1095  * @return なし
1096  * @details
1097  * XXX - Add actions for other item types
1098  */
1099 void do_cmd_use(void)
1100 {
1101         OBJECT_IDX item;
1102         object_type *o_ptr;
1103         cptr        q, s;
1104
1105         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
1106         {
1107                 set_action(ACTION_NONE);
1108         }
1109
1110         item_tester_no_ryoute = TRUE;
1111         /* Prepare the hook */
1112         item_tester_hook = item_tester_hook_use;
1113
1114         /* Get an item */
1115         q = _("どれを使いますか?", "Use which item? ");
1116         s = _("使えるものがありません。", "You have nothing to use.");
1117
1118         if (!get_item(&item, q, s, (USE_INVEN | USE_EQUIP | USE_FLOOR))) return;
1119
1120         /* Get the item (in the pack) */
1121         if (item >= 0)
1122         {
1123                 o_ptr = &inventory[item];
1124         }
1125         /* Get the item (on the floor) */
1126         else
1127         {
1128                 o_ptr = &o_list[0 - item];
1129         }
1130
1131         switch (o_ptr->tval)
1132         {
1133                 /* Spike a door */
1134                 case TV_SPIKE:
1135                 {
1136                         do_cmd_spike();
1137                         break;
1138                 }
1139
1140                 /* Eat some food */
1141                 case TV_FOOD:
1142                 {
1143                         do_cmd_eat_food_aux(item);
1144                         break;
1145                 }
1146
1147                 /* Aim a wand */
1148                 case TV_WAND:
1149                 {
1150                         do_cmd_aim_wand_aux(item);
1151                         break;
1152                 }
1153
1154                 /* Use a staff */
1155                 case TV_STAFF:
1156                 {
1157                         do_cmd_use_staff_aux(item);
1158                         break;
1159                 }
1160
1161                 /* Zap a rod */
1162                 case TV_ROD:
1163                 {
1164                         do_cmd_zap_rod_aux(item);
1165                         break;
1166                 }
1167
1168                 /* Quaff a potion */
1169                 case TV_POTION:
1170                 {
1171                         do_cmd_quaff_potion_aux(item);
1172                         break;
1173                 }
1174
1175                 /* Read a scroll */
1176                 case TV_SCROLL:
1177                 {
1178                         /* Check some conditions */
1179                         if (p_ptr->blind)
1180                         {
1181                                 msg_print(_("目が見えない。", "You can't see anything."));
1182                                 return;
1183                         }
1184                         if (no_lite())
1185                         {
1186                                 msg_print(_("明かりがないので、暗くて読めない。", "You have no light to read by."));
1187                                 return;
1188                         }
1189                         if (p_ptr->confused)
1190                         {
1191                                 msg_print(_("混乱していて読めない!", "You are too confused!"));
1192                                 return;
1193                         }
1194
1195                   do_cmd_read_scroll_aux(item, TRUE);
1196                   break;
1197                 }
1198
1199                 /* Fire ammo */
1200                 case TV_SHOT:
1201                 case TV_ARROW:
1202                 case TV_BOLT:
1203                 {
1204                         do_cmd_fire_aux(item, &inventory[INVEN_BOW]);
1205                         break;
1206                 }
1207
1208                 /* Activate an artifact */
1209                 default:
1210                 {
1211                         do_cmd_activate_aux(item);
1212                         break;
1213                 }
1214         }
1215 }
1216
1217 /*!
1218  * @brief 魔道具術師の取り込んだ魔力一覧から選択/閲覧する /
1219  * @param only_browse 閲覧するだけならばTRUE
1220  * @return 選択した魔力のID、キャンセルならば-1を返す
1221  */
1222 static OBJECT_SUBTYPE_VALUE select_magic_eater(bool only_browse)
1223 {
1224         OBJECT_SUBTYPE_VALUE ext = 0;
1225         char choice;
1226         bool flag, request_list;
1227         OBJECT_TYPE_VALUE tval = 0;
1228         int             ask = TRUE;
1229         OBJECT_SUBTYPE_VALUE i = 0;
1230         char            out_val[160];
1231
1232         int menu_line = (use_menu ? 1 : 0);
1233
1234 #ifdef ALLOW_REPEAT
1235         COMMAND_CODE sn;
1236         if (repeat_pull(&sn))
1237         {
1238                 /* Verify the spell */
1239                 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))
1240                         return sn;
1241                 else if (sn < EATER_EXT*2 && !(p_ptr->magic_num1[sn] < EATER_CHARGE))
1242                         return sn;
1243         }
1244         
1245 #endif /* ALLOW_REPEAT */
1246
1247         for (i = 0; i < 108; i++)
1248         {
1249                 if (p_ptr->magic_num2[i]) break;
1250         }
1251         if (i == 108)
1252         {
1253                 msg_print(_("魔法を覚えていない!", "You don't have any magic!"));
1254                 return -1;
1255         }
1256
1257         if (use_menu)
1258         {
1259                 screen_save();
1260
1261                 while(!tval)
1262                 {
1263 #ifdef JP
1264                         prt(format(" %s 杖", (menu_line == 1) ? "》" : "  "), 2, 14);
1265                         prt(format(" %s 魔法棒", (menu_line == 2) ? "》" : "  "), 3, 14);
1266                         prt(format(" %s ロッド", (menu_line == 3) ? "》" : "  "), 4, 14);
1267 #else
1268                         prt(format(" %s staff", (menu_line == 1) ? "> " : "  "), 2, 14);
1269                         prt(format(" %s wand", (menu_line == 2) ? "> " : "  "), 3, 14);
1270                         prt(format(" %s rod", (menu_line == 3) ? "> " : "  "), 4, 14);
1271 #endif
1272
1273                         if (only_browse) prt(_("どの種類の魔法を見ますか?", "Which type of magic do you browse?"), 0, 0);
1274                         else prt(_("どの種類の魔法を使いますか?", "Which type of magic do you use?"), 0, 0);
1275
1276                         choice = inkey();
1277                         switch(choice)
1278                         {
1279                         case ESCAPE:
1280                         case 'z':
1281                         case 'Z':
1282                                 screen_load();
1283                                 return -1;
1284                         case '2':
1285                         case 'j':
1286                         case 'J':
1287                                 menu_line++;
1288                                 break;
1289                         case '8':
1290                         case 'k':
1291                         case 'K':
1292                                 menu_line+= 2;
1293                                 break;
1294                         case '\r':
1295                         case 'x':
1296                         case 'X':
1297                                 ext = (menu_line-1)*EATER_EXT;
1298                                 if (menu_line == 1) tval = TV_STAFF;
1299                                 else if (menu_line == 2) tval = TV_WAND;
1300                                 else tval = TV_ROD;
1301                                 break;
1302                         }
1303                         if (menu_line > 3) menu_line -= 3;
1304                 }
1305                 screen_load();
1306         }
1307         else
1308         {
1309         while (TRUE)
1310         {
1311                 if (!get_com(_("[A] 杖, [B] 魔法棒, [C] ロッド:", "[A] staff, [B] wand, [C] rod:"), &choice, TRUE))
1312                 {
1313                         return -1;
1314                 }
1315                 if (choice == 'A' || choice == 'a')
1316                 {
1317                         ext = 0;
1318                         tval = TV_STAFF;
1319                         break;
1320                 }
1321                 if (choice == 'B' || choice == 'b')
1322                 {
1323                         ext = EATER_EXT;
1324                         tval = TV_WAND;
1325                         break;
1326                 }
1327                 if (choice == 'C' || choice == 'c')
1328                 {
1329                         ext = EATER_EXT*2;
1330                         tval = TV_ROD;
1331                         break;
1332                 }
1333         }
1334         }
1335         for (i = ext; i < ext + EATER_EXT; i++)
1336         {
1337                 if (p_ptr->magic_num2[i])
1338                 {
1339                         if (use_menu) menu_line = i-ext+1;
1340                         break;
1341                 }
1342         }
1343         if (i == ext+EATER_EXT)
1344         {
1345                 msg_print(_("その種類の魔法は覚えていない!", "You don't have that type of magic!"));
1346                 return -1;
1347         }
1348
1349         /* Nothing chosen yet */
1350         flag = FALSE;
1351
1352         /* Build a prompt */
1353         if (only_browse) strnfmt(out_val, 78, _("('*'で一覧, ESCで中断) どの魔力を見ますか?",
1354                                                                                         "(*=List, ESC=exit) Browse which power? "));
1355         else strnfmt(out_val, 78, _("('*'で一覧, ESCで中断) どの魔力を使いますか?",
1356                                                                 "(*=List, ESC=exit) Use which power? "));
1357         
1358         /* Save the screen */
1359         screen_save();
1360
1361         request_list = always_show_list;
1362
1363         /* Get a spell from the user */
1364         while (!flag)
1365         {
1366                 /* Show the list */
1367                 if (request_list || use_menu)
1368                 {
1369                         byte y, x = 0;
1370                         OBJECT_SUBTYPE_VALUE ctr;
1371                         PERCENTAGE chance;
1372                         IDX k_idx;
1373                         char dummy[80];
1374                         POSITION x1, y1;
1375                         int level;
1376                         byte col;
1377
1378                         strcpy(dummy, "");
1379
1380                         for (y = 1; y < 20; y++)
1381                                 prt("", y, x);
1382
1383                         y = 1;
1384
1385                         /* Print header(s) */
1386 #ifdef JP
1387                         prt(format("                           %s 失率                           %s 失率", (tval == TV_ROD ? "  状態  " : "使用回数"), (tval == TV_ROD ? "  状態  " : "使用回数")), y++, x);
1388 #else
1389                         prt(format("                           %s Fail                           %s Fail", (tval == TV_ROD ? "  Stat  " : " Charges"), (tval == TV_ROD ? "  Stat  " : " Charges")), y++, x);
1390 #endif
1391
1392                         /* Print list */
1393                         for (ctr = 0; ctr < EATER_EXT; ctr++)
1394                         {
1395                                 if (!p_ptr->magic_num2[ctr+ext]) continue;
1396
1397                                 k_idx = lookup_kind(tval, ctr);
1398
1399                                 if (use_menu)
1400                                 {
1401                                         if (ctr == (menu_line-1))
1402                                                 strcpy(dummy, _("》", "> "));
1403                                         else
1404                                                 strcpy(dummy, "  ");
1405                                 }
1406                                 /* letter/number for power selection */
1407                                 else
1408                                 {
1409                                         char letter;
1410                                         if (ctr < 26)
1411                                                 letter = I2A(ctr);
1412                                         else
1413                                                 letter = '0' + ctr - 26;
1414                                         sprintf(dummy, "%c)",letter);
1415                                 }
1416                                 x1 = ((ctr < EATER_EXT/2) ? x : x + 40);
1417                                 y1 = ((ctr < EATER_EXT/2) ? y + ctr : y + ctr - EATER_EXT/2);
1418                                 level = (tval == TV_ROD ? k_info[k_idx].level * 5 / 6 - 5 : k_info[k_idx].level);
1419                                 chance = level * 4 / 5 + 20;
1420                                 chance -= 3 * (adj_mag_stat[p_ptr->stat_ind[mp_ptr->spell_stat]] - 1);
1421                                 level /= 2;
1422                                 if (p_ptr->lev > level)
1423                                 {
1424                                         chance -= 3 * (p_ptr->lev - level);
1425                                 }
1426                                 chance = mod_spell_chance_1(chance);
1427                                 chance = MAX(chance, adj_mag_fail[p_ptr->stat_ind[mp_ptr->spell_stat]]);
1428                                 /* Stunning makes spells harder */
1429                                 if (p_ptr->stun > 50) chance += 25;
1430                                 else if (p_ptr->stun) chance += 15;
1431
1432                                 if (chance > 95) chance = 95;
1433
1434                                 chance = mod_spell_chance_2(chance);
1435
1436                                 col = TERM_WHITE;
1437
1438                                 if (k_idx)
1439                                 {
1440                                         if (tval == TV_ROD)
1441                                         {
1442                                                 strcat(dummy, format(
1443                                                                _(" %-22.22s 充填:%2d/%2d%3d%%", " %-22.22s   (%2d/%2d) %3d%%"),
1444                                                                k_name + k_info[k_idx].name, 
1445                                                                p_ptr->magic_num1[ctr+ext] ? 
1446                                                                (p_ptr->magic_num1[ctr+ext] - 1) / (EATER_ROD_CHARGE * k_info[k_idx].pval) +1 : 0, 
1447                                                                p_ptr->magic_num2[ctr+ext], chance));
1448                                                 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;
1449                                         }
1450                                         else
1451                                         {
1452                                                 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));
1453                                                 if (p_ptr->magic_num1[ctr+ext] < EATER_CHARGE) col = TERM_RED;
1454                                         }
1455                                 }
1456                                 else
1457                                         strcpy(dummy, "");
1458                                 c_prt(col, dummy, y1, x1);
1459                         }
1460                 }
1461
1462                 if (!get_com(out_val, &choice, FALSE)) break;
1463
1464                 if (use_menu && choice != ' ')
1465                 {
1466                         switch (choice)
1467                         {
1468                                 case '0':
1469                                 {
1470                                         screen_load();
1471                                         return 0;
1472                                 }
1473
1474                                 case '8':
1475                                 case 'k':
1476                                 case 'K':
1477                                 {
1478                                         do
1479                                         {
1480                                                 menu_line += EATER_EXT - 1;
1481                                                 if (menu_line > EATER_EXT) menu_line -= EATER_EXT;
1482                                         } while(!p_ptr->magic_num2[menu_line+ext-1]);
1483                                         break;
1484                                 }
1485
1486                                 case '2':
1487                                 case 'j':
1488                                 case 'J':
1489                                 {
1490                                         do
1491                                         {
1492                                                 menu_line++;
1493                                                 if (menu_line > EATER_EXT) menu_line -= EATER_EXT;
1494                                         } while(!p_ptr->magic_num2[menu_line+ext-1]);
1495                                         break;
1496                                 }
1497
1498                                 case '4':
1499                                 case 'h':
1500                                 case 'H':
1501                                 case '6':
1502                                 case 'l':
1503                                 case 'L':
1504                                 {
1505                                         bool reverse = FALSE;
1506                                         if ((choice == '4') || (choice == 'h') || (choice == 'H')) reverse = TRUE;
1507                                         if (menu_line > EATER_EXT/2)
1508                                         {
1509                                                 menu_line -= EATER_EXT/2;
1510                                                 reverse = TRUE;
1511                                         }
1512                                         else menu_line+=EATER_EXT/2;
1513                                         while(!p_ptr->magic_num2[menu_line+ext-1])
1514                                         {
1515                                                 if (reverse)
1516                                                 {
1517                                                         menu_line--;
1518                                                         if (menu_line < 2) reverse = FALSE;
1519                                                 }
1520                                                 else
1521                                                 {
1522                                                         menu_line++;
1523                                                         if (menu_line > EATER_EXT-1) reverse = TRUE;
1524                                                 }
1525                                         }
1526                                         break;
1527                                 }
1528
1529                                 case 'x':
1530                                 case 'X':
1531                                 case '\r':
1532                                 {
1533                                         i = menu_line - 1;
1534                                         ask = FALSE;
1535                                         break;
1536                                 }
1537                         }
1538                 }
1539
1540                 /* Request redraw */
1541                 if (use_menu && ask) continue;
1542
1543                 /* Request redraw */
1544                 if (!use_menu && ((choice == ' ') || (choice == '*') || (choice == '?')))
1545                 {
1546                         /* Hide the list */
1547                         if (request_list)
1548                         {
1549                                 /* Hide list */
1550                                 request_list = FALSE;
1551                                 
1552                                 /* Restore the screen */
1553                                 screen_load();
1554                                 screen_save();
1555                         }
1556                         else
1557                                 request_list = TRUE;
1558
1559                         /* Redo asking */
1560                         continue;
1561                 }
1562
1563                 if (!use_menu)
1564                 {
1565                         if (isalpha(choice))
1566                         {
1567                                 /* Note verify */
1568                                 ask = (isupper(choice));
1569
1570                                 /* Lowercase */
1571                                 if (ask) choice = (char)tolower(choice);
1572
1573                                 /* Extract request */
1574                                 i = (islower(choice) ? A2I(choice) : -1);
1575                         }
1576                         else
1577                         {
1578                                 ask = FALSE; /* Can't uppercase digits */
1579
1580                                 i = choice - '0' + 26;
1581                         }
1582                 }
1583
1584                 /* Totally Illegal */
1585                 if ((i < 0) || (i > EATER_EXT) || !p_ptr->magic_num2[i+ext])
1586                 {
1587                         bell();
1588                         continue;
1589                 }
1590
1591                 if (!only_browse)
1592                 {
1593                         /* Verify it */
1594                         if (ask)
1595                         {
1596                                 char tmp_val[160];
1597
1598                                 /* Prompt */
1599                                 (void) strnfmt(tmp_val, 78, _("%sを使いますか? ", "Use %s?"), k_name + k_info[lookup_kind(tval ,i)].name);
1600
1601                                 /* Belay that order */
1602                                 if (!get_check(tmp_val)) continue;
1603                         }
1604                         if (tval == TV_ROD)
1605                         {
1606                                 if (p_ptr->magic_num1[ext+i]  > k_info[lookup_kind(tval, i)].pval * (p_ptr->magic_num2[ext+i] - 1) * EATER_ROD_CHARGE)
1607                                 {
1608                                         msg_print(_("その魔法はまだ充填している最中だ。", "The magic are still charging."));
1609                                         msg_print(NULL);
1610                                         if (use_menu) ask = TRUE;
1611                                         continue;
1612                                 }
1613                         }
1614                         else
1615                         {
1616                                 if (p_ptr->magic_num1[ext+i] < EATER_CHARGE)
1617                                 {
1618                                         msg_print(_("その魔法は使用回数が切れている。", "The magic has no charges left."));
1619                                         msg_print(NULL);
1620                                         if (use_menu) ask = TRUE;
1621                                         continue;
1622                                 }
1623                         }
1624                 }
1625
1626                 /* Browse */
1627                 else
1628                 {
1629                         int line, j;
1630                         char temp[70 * 20];
1631
1632                         /* Clear lines, position cursor  (really should use strlen here) */
1633                         Term_erase(7, 23, 255);
1634                         Term_erase(7, 22, 255);
1635                         Term_erase(7, 21, 255);
1636                         Term_erase(7, 20, 255);
1637
1638                         roff_to_buf(k_text + k_info[lookup_kind(tval, i)].text, 62, temp, sizeof(temp));
1639                         for (j = 0, line = 21; temp[j]; j += 1 + strlen(&temp[j]))
1640                         {
1641                                 prt(&temp[j], line, 10);
1642                                 line++;
1643                         }
1644
1645                         continue;
1646                 }
1647
1648                 /* Stop the loop */
1649                 flag = TRUE;
1650         }
1651
1652         /* Restore the screen */
1653         screen_load();
1654
1655         if (!flag) return -1;
1656
1657 #ifdef ALLOW_REPEAT
1658         repeat_push(ext+i);
1659 #endif /* ALLOW_REPEAT */
1660         return ext+i;
1661 }
1662
1663
1664 /*!
1665  * @brief 取り込んだ魔力を利用するコマンドのメインルーチン /
1666  * Use eaten rod, wand or staff
1667  * @param only_browse 閲覧するだけならばTRUE
1668  * @param powerful 強力発動中の処理ならばTRUE
1669  * @return 実際にコマンドを実行したならばTRUEを返す。
1670  */
1671 bool do_cmd_magic_eater(bool only_browse, bool powerful)
1672 {
1673         OBJECT_SUBTYPE_VALUE item;
1674         PERCENTAGE chance;
1675         DEPTH level;
1676         IDX k_idx;
1677         OBJECT_TYPE_VALUE tval;
1678         OBJECT_SUBTYPE_VALUE sval;
1679         bool use_charge = TRUE;
1680
1681         /* Not when confused */
1682         if (!only_browse && p_ptr->confused)
1683         {
1684                 msg_print(_("混乱していて唱えられない!", "You are too confused!"));
1685                 return FALSE;
1686         }
1687
1688         item = select_magic_eater(only_browse);
1689         if (item == -1)
1690         {
1691                 p_ptr->energy_use = 0;
1692                 return FALSE;
1693         }
1694         if (item >= EATER_EXT*2) {tval = TV_ROD;sval = item - EATER_EXT*2;}
1695         else if (item >= EATER_EXT) {tval = TV_WAND;sval = item - EATER_EXT;}
1696         else {tval = TV_STAFF; sval = item;}
1697         k_idx = lookup_kind(tval, sval);
1698
1699         level = (tval == TV_ROD ? k_info[k_idx].level * 5 / 6 - 5 : k_info[k_idx].level);
1700         chance = level * 4 / 5 + 20;
1701         chance -= 3 * (adj_mag_stat[p_ptr->stat_ind[mp_ptr->spell_stat]] - 1);
1702         level /= 2;
1703         if (p_ptr->lev > level)
1704         {
1705                 chance -= 3 * (p_ptr->lev - level);
1706         }
1707         chance = mod_spell_chance_1(chance);
1708         chance = MAX(chance, adj_mag_fail[p_ptr->stat_ind[mp_ptr->spell_stat]]);
1709         /* Stunning makes spells harder */
1710         if (p_ptr->stun > 50) chance += 25;
1711         else if (p_ptr->stun) chance += 15;
1712
1713         if (chance > 95) chance = 95;
1714
1715         chance = mod_spell_chance_2(chance);
1716
1717         if (randint0(100) < chance)
1718         {
1719                 if (flush_failure) flush();
1720                 
1721                 msg_print(_("呪文をうまく唱えられなかった!", "You failed to get the magic off!"));
1722                 sound(SOUND_FAIL);
1723                 if (randint1(100) >= chance)
1724                         chg_virtue(V_CHANCE,-1);
1725                 p_ptr->energy_use = 100;
1726
1727                 return TRUE;
1728         }
1729         else
1730         {
1731                 int dir = 0;
1732
1733                 if (tval == TV_ROD)
1734                 {
1735                         if ((sval >= SV_ROD_MIN_DIRECTION) && (sval != SV_ROD_HAVOC) && (sval != SV_ROD_AGGRAVATE) && (sval != SV_ROD_PESTICIDE))
1736                                 if (!get_aim_dir(&dir)) return FALSE;
1737                         rod_effect(sval, dir, &use_charge, powerful, TRUE);
1738                         if (!use_charge) return FALSE;
1739                 }
1740                 else if (tval == TV_WAND)
1741                 {
1742                         if (!get_aim_dir(&dir)) return FALSE;
1743                         wand_effect(sval, dir, powerful, TRUE);
1744                 }
1745                 else
1746                 {
1747                         staff_effect(sval, &use_charge, powerful, TRUE, TRUE);
1748                         if (!use_charge) return FALSE;
1749                 }
1750                 if (randint1(100) < chance)
1751                         chg_virtue(V_CHANCE,1);
1752         }
1753         p_ptr->energy_use = 100;
1754         if (tval == TV_ROD) p_ptr->magic_num1[item] += k_info[k_idx].pval * EATER_ROD_CHARGE;
1755         else p_ptr->magic_num1[item] -= EATER_CHARGE;
1756
1757         return TRUE;
1758 }