OSDN Git Service

7b76699d66da450876cbe116450a87a62dbcf633
[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 #include "cmd-zapwand.h"
63
64
65
66 /*!
67  * @brief ロッドの効果を発動する
68  * @param sval オブジェクトのsval
69  * @param dir 発動目標の方向ID
70  * @param use_charge チャージを消費したかどうかを返す参照ポインタ
71  * @param powerful 強力発動上の処理ならばTRUE
72  * @param magic 魔道具術上の処理ならばTRUE
73  * @return 発動により効果内容が確定したならばTRUEを返す
74  */
75 static int rod_effect(OBJECT_SUBTYPE_VALUE sval, int dir, bool *use_charge, bool powerful, bool magic)
76 {
77         int ident = FALSE;
78         int lev = powerful ? p_ptr->lev * 2 : p_ptr->lev;
79         int detect_rad = powerful ? DETECT_RAD_DEFAULT * 3 / 2 : DETECT_RAD_DEFAULT;
80         int rad = powerful ? 3 : 2;
81
82         /* Unused */
83         (void)magic;
84
85         /* Analyze the rod */
86         switch (sval)
87         {
88                 case SV_ROD_DETECT_TRAP:
89                 {
90                         if (detect_traps(detect_rad, (bool)(dir ? FALSE : TRUE))) ident = TRUE;
91                         break;
92                 }
93
94                 case SV_ROD_DETECT_DOOR:
95                 {
96                         if (detect_doors(detect_rad)) ident = TRUE;
97                         if (detect_stairs(detect_rad)) ident = TRUE;
98                         break;
99                 }
100
101                 case SV_ROD_IDENTIFY:
102                 {
103                         if (powerful) {
104                                 if (!identify_fully(FALSE)) *use_charge = FALSE;
105                         } else {
106                                 if (!ident_spell(FALSE)) *use_charge = FALSE;
107                         }
108                         ident = TRUE;
109                         break;
110                 }
111
112                 case SV_ROD_RECALL:
113                 {
114                         if (!word_of_recall()) *use_charge = FALSE;
115                         ident = TRUE;
116                         break;
117                 }
118
119                 case SV_ROD_ILLUMINATION:
120                 {
121                         if (lite_area(damroll(2, 8), (powerful ? 4 : 2))) ident = TRUE;
122                         break;
123                 }
124
125                 case SV_ROD_MAPPING:
126                 {
127                         map_area(powerful ? DETECT_RAD_MAP * 3 / 2 : DETECT_RAD_MAP);
128                         ident = TRUE;
129                         break;
130                 }
131
132                 case SV_ROD_DETECTION:
133                 {
134                         detect_all(detect_rad);
135                         ident = TRUE;
136                         break;
137                 }
138
139                 case SV_ROD_PROBING:
140                 {
141                         probing();
142                         ident = TRUE;
143                         break;
144                 }
145
146                 case SV_ROD_CURING:
147                 {
148                         if (set_blind(0)) ident = TRUE;
149                         if (set_poisoned(0)) ident = TRUE;
150                         if (set_confused(0)) ident = TRUE;
151                         if (set_stun(0)) ident = TRUE;
152                         if (set_cut(0)) ident = TRUE;
153                         if (set_image(0)) ident = TRUE;
154                         if (set_shero(0,TRUE)) ident = TRUE;
155                         break;
156                 }
157
158                 case SV_ROD_HEALING:
159                 {
160                         if (hp_player(powerful ? 750 : 500)) ident = TRUE;
161                         if (set_stun(0)) ident = TRUE;
162                         if (set_cut(0)) ident = TRUE;
163                         if (set_shero(0,TRUE)) ident = TRUE;
164                         break;
165                 }
166
167                 case SV_ROD_RESTORATION:
168                 {
169                         if (restore_level()) ident = TRUE;
170                         if (do_res_stat(A_STR)) ident = TRUE;
171                         if (do_res_stat(A_INT)) ident = TRUE;
172                         if (do_res_stat(A_WIS)) ident = TRUE;
173                         if (do_res_stat(A_DEX)) ident = TRUE;
174                         if (do_res_stat(A_CON)) ident = TRUE;
175                         if (do_res_stat(A_CHR)) ident = TRUE;
176                         break;
177                 }
178
179                 case SV_ROD_SPEED:
180                 {
181                         if (set_fast(randint1(30) + (powerful ? 30 : 15), FALSE)) ident = TRUE;
182                         break;
183                 }
184
185                 case SV_ROD_PESTICIDE:
186                 {
187                         if (dispel_monsters(powerful ? 8 : 4)) ident = TRUE;
188                         break;
189                 }
190
191                 case SV_ROD_TELEPORT_AWAY:
192                 {
193                         int distance = MAX_SIGHT * (powerful ? 8 : 5);
194                         if (teleport_monster(dir, distance)) ident = TRUE;
195                         break;
196                 }
197
198                 case SV_ROD_DISARMING:
199                 {
200                         if (disarm_trap(dir)) ident = TRUE;
201                         if (powerful && disarm_traps_touch()) ident = TRUE;
202                         break;
203                 }
204
205                 case SV_ROD_LITE:
206                 {
207                         HIT_POINT dam = damroll((powerful ? 12 : 6), 8);
208                         msg_print(_("青く輝く光線が放たれた。", "A line of blue shimmering light appears."));
209                         (void)lite_line(dir, dam);
210                         ident = TRUE;
211                         break;
212                 }
213
214                 case SV_ROD_SLEEP_MONSTER:
215                 {
216                         if (sleep_monster(dir, lev)) ident = TRUE;
217                         break;
218                 }
219
220                 case SV_ROD_SLOW_MONSTER:
221                 {
222                         if (slow_monster(dir, lev)) ident = TRUE;
223                         break;
224                 }
225
226                 case SV_ROD_HYPODYNAMIA:
227                 {
228                         if (hypodynamic_bolt(dir, 70 + 3 * lev / 2)) ident = TRUE;
229                         break;
230                 }
231
232                 case SV_ROD_POLYMORPH:
233                 {
234                         if (poly_monster(dir, lev)) ident = TRUE;
235                         break;
236                 }
237
238                 case SV_ROD_ACID_BOLT:
239                 {
240                         fire_bolt_or_beam(10, GF_ACID, dir, damroll(6 + lev / 7, 8));
241                         ident = TRUE;
242                         break;
243                 }
244
245                 case SV_ROD_ELEC_BOLT:
246                 {
247                         fire_bolt_or_beam(10, GF_ELEC, dir, damroll(4 + lev / 9, 8));
248                         ident = TRUE;
249                         break;
250                 }
251
252                 case SV_ROD_FIRE_BOLT:
253                 {
254                         fire_bolt_or_beam(10, GF_FIRE, dir, damroll(7 + lev / 6, 8));
255                         ident = TRUE;
256                         break;
257                 }
258
259                 case SV_ROD_COLD_BOLT:
260                 {
261                         fire_bolt_or_beam(10, GF_COLD, dir, damroll(5 + lev / 8, 8));
262                         ident = TRUE;
263                         break;
264                 }
265
266                 case SV_ROD_ACID_BALL:
267                 {
268                         fire_ball(GF_ACID, dir, 60 + lev, rad);
269                         ident = TRUE;
270                         break;
271                 }
272
273                 case SV_ROD_ELEC_BALL:
274                 {
275                         fire_ball(GF_ELEC, dir, 40 + lev, rad);
276                         ident = TRUE;
277                         break;
278                 }
279
280                 case SV_ROD_FIRE_BALL:
281                 {
282                         fire_ball(GF_FIRE, dir, 70 + lev, rad);
283                         ident = TRUE;
284                         break;
285                 }
286
287                 case SV_ROD_COLD_BALL:
288                 {
289                         fire_ball(GF_COLD, dir, 50 + lev, rad);
290                         ident = TRUE;
291                         break;
292                 }
293
294                 case SV_ROD_HAVOC:
295                 {
296                         call_chaos();
297                         ident = TRUE;
298                         break;
299                 }
300
301                 case SV_ROD_STONE_TO_MUD:
302                 {
303                         HIT_POINT dam = powerful ? 40 + randint1(60) : 20 + randint1(30);
304                         if (wall_to_mud(dir, dam)) ident = TRUE;
305                         break;
306                 }
307
308                 case SV_ROD_AGGRAVATE:
309                 {
310                         aggravate_monsters(0);
311                         ident = TRUE;
312                         break;
313                 }
314         }
315         return ident;
316 }
317
318 /*!
319  * @brief 魔法棒を使うコマンドのサブルーチン / 
320  * Activate (zap) a Rod
321  * @param item 使うオブジェクトの所持品ID
322  * @return なし
323  * @details
324  * <pre>
325  * Unstack fully charged rods as needed.
326  * Hack -- rods of perception/genocide can be "cancelled"
327  * All rods can be cancelled at the "Direction?" prompt
328  * pvals are defined for each rod in k_info. -LM-
329  * </pre>
330  */
331 static void do_cmd_zap_rod_aux(int item)
332 {
333         int ident, chance, lev, fail;
334         int dir = 0;
335         object_type *o_ptr;
336         bool success;
337
338         /* Hack -- let perception get aborted */
339         bool use_charge = TRUE;
340
341         object_kind *k_ptr;
342
343         /* Get the item (in the pack) */
344         if (item >= 0)
345         {
346                 o_ptr = &inventory[item];
347         }
348
349         /* Get the item (on the floor) */
350         else
351         {
352                 o_ptr = &o_list[0 - item];
353         }
354
355
356         /* Mega-Hack -- refuse to zap a pile from the ground */
357         if ((item < 0) && (o_ptr->number > 1))
358         {
359                 msg_print(_("まずはロッドを拾わなければ。", "You must first pick up the rods."));
360                 return;
361         }
362
363
364         /* Get a direction (unless KNOWN not to need it) */
365         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)) ||
366              !object_is_aware(o_ptr))
367         {
368                 /* Get a direction, allow cancel */
369                 if (!get_aim_dir(&dir)) return;
370         }
371
372
373         /* Take a turn */
374         p_ptr->energy_use = 100;
375
376         /* Extract the item level */
377         lev = k_info[o_ptr->k_idx].level;
378
379         /* Base chance of success */
380         chance = p_ptr->skill_dev;
381
382         /* Confusion hurts skill */
383         if (p_ptr->confused) chance = chance / 2;
384
385         fail = lev+5;
386         if (chance > fail) fail -= (chance - fail)*2;
387         else chance -= (fail - chance)*2;
388         if (fail < USE_DEVICE) fail = USE_DEVICE;
389         if (chance < USE_DEVICE) chance = USE_DEVICE;
390
391         if (world_player)
392         {
393                 if (flush_failure) flush();
394                 msg_print(_("止まった時の中ではうまく働かないようだ。", "Nothing happen. Maybe this rod is freezing too."));
395                 sound(SOUND_FAIL);
396                 return;
397         }
398
399         if (p_ptr->pclass == CLASS_BERSERKER) success = FALSE;
400         else if (chance > fail)
401         {
402                 if (randint0(chance*2) < fail) success = FALSE;
403                 else success = TRUE;
404         }
405         else
406         {
407                 if (randint0(fail*2) < chance) success = TRUE;
408                 else success = FALSE;
409         }
410
411         /* Roll for usage */
412         if (!success)
413         {
414                 if (flush_failure) flush();
415                 msg_print(_("うまくロッドを使えなかった。", "You failed to use the rod properly."));
416                 sound(SOUND_FAIL);
417                 return;
418         }
419
420         k_ptr = &k_info[o_ptr->k_idx];
421
422         /* A single rod is still charging */
423         if ((o_ptr->number == 1) && (o_ptr->timeout))
424         {
425                 if (flush_failure) flush();
426                 msg_print(_("このロッドはまだ魔力を充填している最中だ。", "The rod is still charging."));
427                 return;
428         }
429         /* A stack of rods lacks enough energy. */
430         else if ((o_ptr->number > 1) && (o_ptr->timeout > k_ptr->pval * (o_ptr->number - 1)))
431         {
432                 if (flush_failure) flush();
433                 msg_print(_("そのロッドはまだ充填中です。", "The rods are all still charging."));
434                 return;
435         }
436
437         /* Sound */
438         sound(SOUND_ZAP);
439
440         ident = rod_effect(o_ptr->sval, dir, &use_charge, FALSE, FALSE);
441
442         /* Increase the timeout by the rod kind's pval. -LM- */
443         if (use_charge) o_ptr->timeout += k_ptr->pval;
444
445         /* Combine / Reorder the pack (later) */
446         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
447
448         if (!(object_is_aware(o_ptr)))
449         {
450                 chg_virtue(V_PATIENCE, -1);
451                 chg_virtue(V_CHANCE, 1);
452                 chg_virtue(V_KNOWLEDGE, -1);
453         }
454
455         /* Tried the object */
456         object_tried(o_ptr);
457
458         /* Successfully determined the object function */
459         if (ident && !object_is_aware(o_ptr))
460         {
461                 object_aware(o_ptr);
462                 gain_exp((lev + (p_ptr->lev >> 1)) / p_ptr->lev);
463         }
464
465         /* Window stuff */
466         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
467 }
468
469 /*!
470  * @brief ロッドを使うコマンドのメインルーチン /
471  * @return なし
472  */
473 void do_cmd_zap_rod(void)
474 {
475         OBJECT_IDX item;
476         cptr q, s;
477
478         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
479         {
480                 set_action(ACTION_NONE);
481         }
482
483         /* Restrict choices to rods */
484         item_tester_tval = TV_ROD;
485
486         /* Get an item */
487         q = _("どのロッドを振りますか? ", "Zap which rod? ");
488         s = _("使えるロッドがない。", "You have no rod to zap.");
489
490         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
491
492         /* Zap the rod */
493         do_cmd_zap_rod_aux(item);
494 }
495
496 /*!
497  * @brief 『一つの指輪』の効果処理 /
498  * Hack -- activate the ring of power
499  * @param dir 発動の方向ID
500  * @return なし
501  */
502 void ring_of_power(int dir)
503 {
504         /* Pick a random effect */
505         switch (randint1(10))
506         {
507                 case 1:
508                 case 2:
509                 {
510                         /* Message */
511                         msg_print(_("あなたは悪性のオーラに包み込まれた。", "You are surrounded by a malignant aura."));
512                         sound(SOUND_EVIL);
513
514                         /* Decrease all stats (permanently) */
515                         (void)dec_stat(A_STR, 50, TRUE);
516                         (void)dec_stat(A_INT, 50, TRUE);
517                         (void)dec_stat(A_WIS, 50, TRUE);
518                         (void)dec_stat(A_DEX, 50, TRUE);
519                         (void)dec_stat(A_CON, 50, TRUE);
520                         (void)dec_stat(A_CHR, 50, TRUE);
521
522                         /* Lose some experience (permanently) */
523                         p_ptr->exp -= (p_ptr->exp / 4);
524                         p_ptr->max_exp -= (p_ptr->exp / 4);
525                         check_experience();
526
527                         break;
528                 }
529
530                 case 3:
531                 {
532                         /* Message */
533                         msg_print(_("あなたは強力なオーラに包み込まれた。", "You are surrounded by a powerful aura."));
534
535                         /* Dispel monsters */
536                         dispel_monsters(1000);
537
538                         break;
539                 }
540
541                 case 4:
542                 case 5:
543                 case 6:
544                 {
545                         /* Mana Ball */
546                         fire_ball(GF_MANA, dir, 600, 3);
547
548                         break;
549                 }
550
551                 case 7:
552                 case 8:
553                 case 9:
554                 case 10:
555                 {
556                         /* Mana Bolt */
557                         fire_bolt(GF_MANA, dir, 500);
558
559                         break;
560                 }
561         }
562 }
563
564 /*!
565  * @brief オブジェクトをプレイヤーが簡易使用コマンドで利用できるかを判定する /
566  * Hook to determine if an object is useable
567  * @param o_ptr 判定したいオブジェクトの構造体参照ポインタ
568  * @return 利用可能ならばTRUEを返す
569  */
570 static bool item_tester_hook_use(object_type *o_ptr)
571 {
572         u32b flgs[TR_FLAG_SIZE];
573
574         /* Ammo */
575         if (o_ptr->tval == p_ptr->tval_ammo)
576                 return (TRUE);
577
578         /* Useable object */
579         switch (o_ptr->tval)
580         {
581                 case TV_SPIKE:
582                 case TV_STAFF:
583                 case TV_WAND:
584                 case TV_ROD:
585                 case TV_SCROLL:
586                 case TV_POTION:
587                 case TV_FOOD:
588                 {
589                         return (TRUE);
590                 }
591
592                 default:
593                 {
594                         int i;
595
596                         /* Not known */
597                         if (!object_is_known(o_ptr)) return (FALSE);
598
599                         /* HACK - only items from the equipment can be activated */
600                         for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
601                         {
602                                 if (&inventory[i] == o_ptr)
603                                 {
604                                         /* Extract the flags */
605                                         object_flags(o_ptr, flgs);
606
607                                         /* Check activation flag */
608                                         if (have_flag(flgs, TR_ACTIVATE)) return (TRUE);
609                                 }
610                         }
611                 }
612         }
613
614         /* Assume not */
615         return (FALSE);
616 }
617
618
619 /*!
620  * @brief アイテムを汎用的に「使う」コマンドのメインルーチン /
621  * Use an item
622  * @return なし
623  * @details
624  * XXX - Add actions for other item types
625  */
626 void do_cmd_use(void)
627 {
628         OBJECT_IDX item;
629         object_type *o_ptr;
630         cptr        q, s;
631
632         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
633         {
634                 set_action(ACTION_NONE);
635         }
636
637         item_tester_no_ryoute = TRUE;
638         /* Prepare the hook */
639         item_tester_hook = item_tester_hook_use;
640
641         /* Get an item */
642         q = _("どれを使いますか?", "Use which item? ");
643         s = _("使えるものがありません。", "You have nothing to use.");
644
645         if (!get_item(&item, q, s, (USE_INVEN | USE_EQUIP | USE_FLOOR))) return;
646
647         /* Get the item (in the pack) */
648         if (item >= 0)
649         {
650                 o_ptr = &inventory[item];
651         }
652         /* Get the item (on the floor) */
653         else
654         {
655                 o_ptr = &o_list[0 - item];
656         }
657
658         switch (o_ptr->tval)
659         {
660                 /* Spike a door */
661                 case TV_SPIKE:
662                 {
663                         do_cmd_spike();
664                         break;
665                 }
666
667                 /* Eat some food */
668                 case TV_FOOD:
669                 {
670                         do_cmd_eat_food_aux(item);
671                         break;
672                 }
673
674                 /* Aim a wand */
675                 case TV_WAND:
676                 {
677                         do_cmd_aim_wand_aux(item);
678                         break;
679                 }
680
681                 /* Use a staff */
682                 case TV_STAFF:
683                 {
684                         do_cmd_use_staff_aux(item);
685                         break;
686                 }
687
688                 /* Zap a rod */
689                 case TV_ROD:
690                 {
691                         do_cmd_zap_rod_aux(item);
692                         break;
693                 }
694
695                 /* Quaff a potion */
696                 case TV_POTION:
697                 {
698                         do_cmd_quaff_potion_aux(item);
699                         break;
700                 }
701
702                 /* Read a scroll */
703                 case TV_SCROLL:
704                 {
705                         /* Check some conditions */
706                         if (p_ptr->blind)
707                         {
708                                 msg_print(_("目が見えない。", "You can't see anything."));
709                                 return;
710                         }
711                         if (no_lite())
712                         {
713                                 msg_print(_("明かりがないので、暗くて読めない。", "You have no light to read by."));
714                                 return;
715                         }
716                         if (p_ptr->confused)
717                         {
718                                 msg_print(_("混乱していて読めない!", "You are too confused!"));
719                                 return;
720                         }
721
722                   do_cmd_read_scroll_aux(item, TRUE);
723                   break;
724                 }
725
726                 /* Fire ammo */
727                 case TV_SHOT:
728                 case TV_ARROW:
729                 case TV_BOLT:
730                 {
731                         do_cmd_fire_aux(item, &inventory[INVEN_BOW]);
732                         break;
733                 }
734
735                 /* Activate an artifact */
736                 default:
737                 {
738                         do_cmd_activate_aux(item);
739                         break;
740                 }
741         }
742 }
743
744 /*!
745  * @brief 魔道具術師の取り込んだ魔力一覧から選択/閲覧する /
746  * @param only_browse 閲覧するだけならばTRUE
747  * @return 選択した魔力のID、キャンセルならば-1を返す
748  */
749 static OBJECT_SUBTYPE_VALUE select_magic_eater(bool only_browse)
750 {
751         OBJECT_SUBTYPE_VALUE ext = 0;
752         char choice;
753         bool flag, request_list;
754         OBJECT_TYPE_VALUE tval = 0;
755         int             ask = TRUE;
756         OBJECT_SUBTYPE_VALUE i = 0;
757         char            out_val[160];
758
759         int menu_line = (use_menu ? 1 : 0);
760
761 #ifdef ALLOW_REPEAT
762         COMMAND_CODE sn;
763         if (repeat_pull(&sn))
764         {
765                 /* Verify the spell */
766                 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))
767                         return sn;
768                 else if (sn < EATER_EXT*2 && !(p_ptr->magic_num1[sn] < EATER_CHARGE))
769                         return sn;
770         }
771         
772 #endif /* ALLOW_REPEAT */
773
774         for (i = 0; i < 108; i++)
775         {
776                 if (p_ptr->magic_num2[i]) break;
777         }
778         if (i == 108)
779         {
780                 msg_print(_("魔法を覚えていない!", "You don't have any magic!"));
781                 return -1;
782         }
783
784         if (use_menu)
785         {
786                 screen_save();
787
788                 while(!tval)
789                 {
790 #ifdef JP
791                         prt(format(" %s 杖", (menu_line == 1) ? "》" : "  "), 2, 14);
792                         prt(format(" %s 魔法棒", (menu_line == 2) ? "》" : "  "), 3, 14);
793                         prt(format(" %s ロッド", (menu_line == 3) ? "》" : "  "), 4, 14);
794 #else
795                         prt(format(" %s staff", (menu_line == 1) ? "> " : "  "), 2, 14);
796                         prt(format(" %s wand", (menu_line == 2) ? "> " : "  "), 3, 14);
797                         prt(format(" %s rod", (menu_line == 3) ? "> " : "  "), 4, 14);
798 #endif
799
800                         if (only_browse) prt(_("どの種類の魔法を見ますか?", "Which type of magic do you browse?"), 0, 0);
801                         else prt(_("どの種類の魔法を使いますか?", "Which type of magic do you use?"), 0, 0);
802
803                         choice = inkey();
804                         switch(choice)
805                         {
806                         case ESCAPE:
807                         case 'z':
808                         case 'Z':
809                                 screen_load();
810                                 return -1;
811                         case '2':
812                         case 'j':
813                         case 'J':
814                                 menu_line++;
815                                 break;
816                         case '8':
817                         case 'k':
818                         case 'K':
819                                 menu_line+= 2;
820                                 break;
821                         case '\r':
822                         case 'x':
823                         case 'X':
824                                 ext = (menu_line-1)*EATER_EXT;
825                                 if (menu_line == 1) tval = TV_STAFF;
826                                 else if (menu_line == 2) tval = TV_WAND;
827                                 else tval = TV_ROD;
828                                 break;
829                         }
830                         if (menu_line > 3) menu_line -= 3;
831                 }
832                 screen_load();
833         }
834         else
835         {
836         while (TRUE)
837         {
838                 if (!get_com(_("[A] 杖, [B] 魔法棒, [C] ロッド:", "[A] staff, [B] wand, [C] rod:"), &choice, TRUE))
839                 {
840                         return -1;
841                 }
842                 if (choice == 'A' || choice == 'a')
843                 {
844                         ext = 0;
845                         tval = TV_STAFF;
846                         break;
847                 }
848                 if (choice == 'B' || choice == 'b')
849                 {
850                         ext = EATER_EXT;
851                         tval = TV_WAND;
852                         break;
853                 }
854                 if (choice == 'C' || choice == 'c')
855                 {
856                         ext = EATER_EXT*2;
857                         tval = TV_ROD;
858                         break;
859                 }
860         }
861         }
862         for (i = ext; i < ext + EATER_EXT; i++)
863         {
864                 if (p_ptr->magic_num2[i])
865                 {
866                         if (use_menu) menu_line = i-ext+1;
867                         break;
868                 }
869         }
870         if (i == ext+EATER_EXT)
871         {
872                 msg_print(_("その種類の魔法は覚えていない!", "You don't have that type of magic!"));
873                 return -1;
874         }
875
876         /* Nothing chosen yet */
877         flag = FALSE;
878
879         /* Build a prompt */
880         if (only_browse) strnfmt(out_val, 78, _("('*'で一覧, ESCで中断) どの魔力を見ますか?",
881                                                                                         "(*=List, ESC=exit) Browse which power? "));
882         else strnfmt(out_val, 78, _("('*'で一覧, ESCで中断) どの魔力を使いますか?",
883                                                                 "(*=List, ESC=exit) Use which power? "));
884         
885         /* Save the screen */
886         screen_save();
887
888         request_list = always_show_list;
889
890         /* Get a spell from the user */
891         while (!flag)
892         {
893                 /* Show the list */
894                 if (request_list || use_menu)
895                 {
896                         byte y, x = 0;
897                         OBJECT_SUBTYPE_VALUE ctr;
898                         PERCENTAGE chance;
899                         IDX k_idx;
900                         char dummy[80];
901                         POSITION x1, y1;
902                         int level;
903                         byte col;
904
905                         strcpy(dummy, "");
906
907                         for (y = 1; y < 20; y++)
908                                 prt("", y, x);
909
910                         y = 1;
911
912                         /* Print header(s) */
913 #ifdef JP
914                         prt(format("                           %s 失率                           %s 失率", (tval == TV_ROD ? "  状態  " : "使用回数"), (tval == TV_ROD ? "  状態  " : "使用回数")), y++, x);
915 #else
916                         prt(format("                           %s Fail                           %s Fail", (tval == TV_ROD ? "  Stat  " : " Charges"), (tval == TV_ROD ? "  Stat  " : " Charges")), y++, x);
917 #endif
918
919                         /* Print list */
920                         for (ctr = 0; ctr < EATER_EXT; ctr++)
921                         {
922                                 if (!p_ptr->magic_num2[ctr+ext]) continue;
923
924                                 k_idx = lookup_kind(tval, ctr);
925
926                                 if (use_menu)
927                                 {
928                                         if (ctr == (menu_line-1))
929                                                 strcpy(dummy, _("》", "> "));
930                                         else
931                                                 strcpy(dummy, "  ");
932                                 }
933                                 /* letter/number for power selection */
934                                 else
935                                 {
936                                         char letter;
937                                         if (ctr < 26)
938                                                 letter = I2A(ctr);
939                                         else
940                                                 letter = '0' + ctr - 26;
941                                         sprintf(dummy, "%c)",letter);
942                                 }
943                                 x1 = ((ctr < EATER_EXT/2) ? x : x + 40);
944                                 y1 = ((ctr < EATER_EXT/2) ? y + ctr : y + ctr - EATER_EXT/2);
945                                 level = (tval == TV_ROD ? k_info[k_idx].level * 5 / 6 - 5 : k_info[k_idx].level);
946                                 chance = level * 4 / 5 + 20;
947                                 chance -= 3 * (adj_mag_stat[p_ptr->stat_ind[mp_ptr->spell_stat]] - 1);
948                                 level /= 2;
949                                 if (p_ptr->lev > level)
950                                 {
951                                         chance -= 3 * (p_ptr->lev - level);
952                                 }
953                                 chance = mod_spell_chance_1(chance);
954                                 chance = MAX(chance, adj_mag_fail[p_ptr->stat_ind[mp_ptr->spell_stat]]);
955                                 /* Stunning makes spells harder */
956                                 if (p_ptr->stun > 50) chance += 25;
957                                 else if (p_ptr->stun) chance += 15;
958
959                                 if (chance > 95) chance = 95;
960
961                                 chance = mod_spell_chance_2(chance);
962
963                                 col = TERM_WHITE;
964
965                                 if (k_idx)
966                                 {
967                                         if (tval == TV_ROD)
968                                         {
969                                                 strcat(dummy, format(
970                                                                _(" %-22.22s 充填:%2d/%2d%3d%%", " %-22.22s   (%2d/%2d) %3d%%"),
971                                                                k_name + k_info[k_idx].name, 
972                                                                p_ptr->magic_num1[ctr+ext] ? 
973                                                                (p_ptr->magic_num1[ctr+ext] - 1) / (EATER_ROD_CHARGE * k_info[k_idx].pval) +1 : 0, 
974                                                                p_ptr->magic_num2[ctr+ext], chance));
975                                                 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;
976                                         }
977                                         else
978                                         {
979                                                 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));
980                                                 if (p_ptr->magic_num1[ctr+ext] < EATER_CHARGE) col = TERM_RED;
981                                         }
982                                 }
983                                 else
984                                         strcpy(dummy, "");
985                                 c_prt(col, dummy, y1, x1);
986                         }
987                 }
988
989                 if (!get_com(out_val, &choice, FALSE)) break;
990
991                 if (use_menu && choice != ' ')
992                 {
993                         switch (choice)
994                         {
995                                 case '0':
996                                 {
997                                         screen_load();
998                                         return 0;
999                                 }
1000
1001                                 case '8':
1002                                 case 'k':
1003                                 case 'K':
1004                                 {
1005                                         do
1006                                         {
1007                                                 menu_line += EATER_EXT - 1;
1008                                                 if (menu_line > EATER_EXT) menu_line -= EATER_EXT;
1009                                         } while(!p_ptr->magic_num2[menu_line+ext-1]);
1010                                         break;
1011                                 }
1012
1013                                 case '2':
1014                                 case 'j':
1015                                 case 'J':
1016                                 {
1017                                         do
1018                                         {
1019                                                 menu_line++;
1020                                                 if (menu_line > EATER_EXT) menu_line -= EATER_EXT;
1021                                         } while(!p_ptr->magic_num2[menu_line+ext-1]);
1022                                         break;
1023                                 }
1024
1025                                 case '4':
1026                                 case 'h':
1027                                 case 'H':
1028                                 case '6':
1029                                 case 'l':
1030                                 case 'L':
1031                                 {
1032                                         bool reverse = FALSE;
1033                                         if ((choice == '4') || (choice == 'h') || (choice == 'H')) reverse = TRUE;
1034                                         if (menu_line > EATER_EXT/2)
1035                                         {
1036                                                 menu_line -= EATER_EXT/2;
1037                                                 reverse = TRUE;
1038                                         }
1039                                         else menu_line+=EATER_EXT/2;
1040                                         while(!p_ptr->magic_num2[menu_line+ext-1])
1041                                         {
1042                                                 if (reverse)
1043                                                 {
1044                                                         menu_line--;
1045                                                         if (menu_line < 2) reverse = FALSE;
1046                                                 }
1047                                                 else
1048                                                 {
1049                                                         menu_line++;
1050                                                         if (menu_line > EATER_EXT-1) reverse = TRUE;
1051                                                 }
1052                                         }
1053                                         break;
1054                                 }
1055
1056                                 case 'x':
1057                                 case 'X':
1058                                 case '\r':
1059                                 {
1060                                         i = menu_line - 1;
1061                                         ask = FALSE;
1062                                         break;
1063                                 }
1064                         }
1065                 }
1066
1067                 /* Request redraw */
1068                 if (use_menu && ask) continue;
1069
1070                 /* Request redraw */
1071                 if (!use_menu && ((choice == ' ') || (choice == '*') || (choice == '?')))
1072                 {
1073                         /* Hide the list */
1074                         if (request_list)
1075                         {
1076                                 /* Hide list */
1077                                 request_list = FALSE;
1078                                 
1079                                 /* Restore the screen */
1080                                 screen_load();
1081                                 screen_save();
1082                         }
1083                         else
1084                                 request_list = TRUE;
1085
1086                         /* Redo asking */
1087                         continue;
1088                 }
1089
1090                 if (!use_menu)
1091                 {
1092                         if (isalpha(choice))
1093                         {
1094                                 /* Note verify */
1095                                 ask = (isupper(choice));
1096
1097                                 /* Lowercase */
1098                                 if (ask) choice = (char)tolower(choice);
1099
1100                                 /* Extract request */
1101                                 i = (islower(choice) ? A2I(choice) : -1);
1102                         }
1103                         else
1104                         {
1105                                 ask = FALSE; /* Can't uppercase digits */
1106
1107                                 i = choice - '0' + 26;
1108                         }
1109                 }
1110
1111                 /* Totally Illegal */
1112                 if ((i < 0) || (i > EATER_EXT) || !p_ptr->magic_num2[i+ext])
1113                 {
1114                         bell();
1115                         continue;
1116                 }
1117
1118                 if (!only_browse)
1119                 {
1120                         /* Verify it */
1121                         if (ask)
1122                         {
1123                                 char tmp_val[160];
1124
1125                                 /* Prompt */
1126                                 (void) strnfmt(tmp_val, 78, _("%sを使いますか? ", "Use %s?"), k_name + k_info[lookup_kind(tval ,i)].name);
1127
1128                                 /* Belay that order */
1129                                 if (!get_check(tmp_val)) continue;
1130                         }
1131                         if (tval == TV_ROD)
1132                         {
1133                                 if (p_ptr->magic_num1[ext+i]  > k_info[lookup_kind(tval, i)].pval * (p_ptr->magic_num2[ext+i] - 1) * EATER_ROD_CHARGE)
1134                                 {
1135                                         msg_print(_("その魔法はまだ充填している最中だ。", "The magic are still charging."));
1136                                         msg_print(NULL);
1137                                         if (use_menu) ask = TRUE;
1138                                         continue;
1139                                 }
1140                         }
1141                         else
1142                         {
1143                                 if (p_ptr->magic_num1[ext+i] < EATER_CHARGE)
1144                                 {
1145                                         msg_print(_("その魔法は使用回数が切れている。", "The magic has no charges left."));
1146                                         msg_print(NULL);
1147                                         if (use_menu) ask = TRUE;
1148                                         continue;
1149                                 }
1150                         }
1151                 }
1152
1153                 /* Browse */
1154                 else
1155                 {
1156                         int line, j;
1157                         char temp[70 * 20];
1158
1159                         /* Clear lines, position cursor  (really should use strlen here) */
1160                         Term_erase(7, 23, 255);
1161                         Term_erase(7, 22, 255);
1162                         Term_erase(7, 21, 255);
1163                         Term_erase(7, 20, 255);
1164
1165                         roff_to_buf(k_text + k_info[lookup_kind(tval, i)].text, 62, temp, sizeof(temp));
1166                         for (j = 0, line = 21; temp[j]; j += 1 + strlen(&temp[j]))
1167                         {
1168                                 prt(&temp[j], line, 10);
1169                                 line++;
1170                         }
1171
1172                         continue;
1173                 }
1174
1175                 /* Stop the loop */
1176                 flag = TRUE;
1177         }
1178
1179         /* Restore the screen */
1180         screen_load();
1181
1182         if (!flag) return -1;
1183
1184 #ifdef ALLOW_REPEAT
1185         repeat_push(ext+i);
1186 #endif /* ALLOW_REPEAT */
1187         return ext+i;
1188 }
1189
1190
1191 /*!
1192  * @brief 取り込んだ魔力を利用するコマンドのメインルーチン /
1193  * Use eaten rod, wand or staff
1194  * @param only_browse 閲覧するだけならばTRUE
1195  * @param powerful 強力発動中の処理ならばTRUE
1196  * @return 実際にコマンドを実行したならばTRUEを返す。
1197  */
1198 bool do_cmd_magic_eater(bool only_browse, bool powerful)
1199 {
1200         OBJECT_SUBTYPE_VALUE item;
1201         PERCENTAGE chance;
1202         DEPTH level;
1203         IDX k_idx;
1204         OBJECT_TYPE_VALUE tval;
1205         OBJECT_SUBTYPE_VALUE sval;
1206         bool use_charge = TRUE;
1207
1208         /* Not when confused */
1209         if (!only_browse && p_ptr->confused)
1210         {
1211                 msg_print(_("混乱していて唱えられない!", "You are too confused!"));
1212                 return FALSE;
1213         }
1214
1215         item = select_magic_eater(only_browse);
1216         if (item == -1)
1217         {
1218                 p_ptr->energy_use = 0;
1219                 return FALSE;
1220         }
1221         if (item >= EATER_EXT*2) {tval = TV_ROD;sval = item - EATER_EXT*2;}
1222         else if (item >= EATER_EXT) {tval = TV_WAND;sval = item - EATER_EXT;}
1223         else {tval = TV_STAFF; sval = item;}
1224         k_idx = lookup_kind(tval, sval);
1225
1226         level = (tval == TV_ROD ? k_info[k_idx].level * 5 / 6 - 5 : k_info[k_idx].level);
1227         chance = level * 4 / 5 + 20;
1228         chance -= 3 * (adj_mag_stat[p_ptr->stat_ind[mp_ptr->spell_stat]] - 1);
1229         level /= 2;
1230         if (p_ptr->lev > level)
1231         {
1232                 chance -= 3 * (p_ptr->lev - level);
1233         }
1234         chance = mod_spell_chance_1(chance);
1235         chance = MAX(chance, adj_mag_fail[p_ptr->stat_ind[mp_ptr->spell_stat]]);
1236         /* Stunning makes spells harder */
1237         if (p_ptr->stun > 50) chance += 25;
1238         else if (p_ptr->stun) chance += 15;
1239
1240         if (chance > 95) chance = 95;
1241
1242         chance = mod_spell_chance_2(chance);
1243
1244         if (randint0(100) < chance)
1245         {
1246                 if (flush_failure) flush();
1247                 
1248                 msg_print(_("呪文をうまく唱えられなかった!", "You failed to get the magic off!"));
1249                 sound(SOUND_FAIL);
1250                 if (randint1(100) >= chance)
1251                         chg_virtue(V_CHANCE,-1);
1252                 p_ptr->energy_use = 100;
1253
1254                 return TRUE;
1255         }
1256         else
1257         {
1258                 int dir = 0;
1259
1260                 if (tval == TV_ROD)
1261                 {
1262                         if ((sval >= SV_ROD_MIN_DIRECTION) && (sval != SV_ROD_HAVOC) && (sval != SV_ROD_AGGRAVATE) && (sval != SV_ROD_PESTICIDE))
1263                                 if (!get_aim_dir(&dir)) return FALSE;
1264                         rod_effect(sval, dir, &use_charge, powerful, TRUE);
1265                         if (!use_charge) return FALSE;
1266                 }
1267                 else if (tval == TV_WAND)
1268                 {
1269                         if (!get_aim_dir(&dir)) return FALSE;
1270                         wand_effect(sval, dir, powerful, TRUE);
1271                 }
1272                 else
1273                 {
1274                         staff_effect(sval, &use_charge, powerful, TRUE, TRUE);
1275                         if (!use_charge) return FALSE;
1276                 }
1277                 if (randint1(100) < chance)
1278                         chg_virtue(V_CHANCE,1);
1279         }
1280         p_ptr->energy_use = 100;
1281         if (tval == TV_ROD) p_ptr->magic_num1[item] += k_info[k_idx].pval * EATER_ROD_CHARGE;
1282         else p_ptr->magic_num1[item] -= EATER_CHARGE;
1283
1284         return TRUE;
1285 }