OSDN Git Service

[Refactor] #37353 record_turn の宣言を gameoption.h へ移動.
[hengband/hengband.git] / src / cmd-spell.c
1 /*!
2     @file cmd-spell.c
3     @brief 魔法のインターフェイスと発動 / Purpose: Do everything for each spell
4     @date 2013/12/31
5     @author
6     2013 Deskull rearranged comment for Doxygen.
7  */
8
9 #include "angband.h"
10 #include "util.h"
11
12 #include "cmd-dump.h"
13 #include "selfinfo.h"
14 #include "spells.h"
15 #include "spells-summon.h"
16 #include "realm.h"
17 #include "realm-arcane.h"
18 #include "realm-chaos.h"
19 #include "realm-craft.h"
20 #include "realm-crusade.h"
21 #include "realm-daemon.h"
22 #include "realm-death.h"
23 #include "realm-hex.h"
24 #include "realm-hissatsu.h"
25 #include "realm-life.h"
26 #include "realm-nature.h"
27 #include "realm-song.h"
28 #include "realm-sorcery.h"
29 #include "realm-trump.h"
30 #include "mind.h"
31 #include "avatar.h"
32 #include "player-status.h"
33 #include "player-effects.h"
34 #include "player-skill.h"
35 #include "player-class.h"
36 #include "object-hook.h"
37 #include "cmd-basic.h"
38 #include "view-mainwindow.h"
39 #include "floor.h"
40 #include "autopick.h"
41
42  /*!
43   * 魔法領域フラグ管理テーブル /
44   * Zangband uses this array instead of the spell flags table, as there
45   * are 5 realms of magic, each with 4 spellbooks and 8 spells per book -- TY
46   */
47 const u32b fake_spell_flags[4] =
48 {
49         0x000000ff,
50         0x0000ff00,
51         0x00ff0000,
52         0xff000000
53 };
54
55 /*!
56  * @brief
57  * 魔法の効果を「キャプション:ダイス+定数値」のフォーマットで出力する / Generate dice info string such as "foo 2d10"
58  * @param str キャプション
59  * @param dice ダイス数
60  * @param sides ダイス目
61  * @param base 固定値
62  * @return フォーマットに従い整形された文字列
63  */
64 concptr info_string_dice(concptr str, DICE_NUMBER dice, DICE_SID sides, int base)
65 {
66         /* Fix value */
67         if (!dice)
68                 return format("%s%d", str, base);
69
70         /* Dice only */
71         else if (!base)
72                 return format("%s%dd%d", str, dice, sides);
73
74         /* Dice plus base value */
75         else
76                 return format("%s%dd%d%+d", str, dice, sides, base);
77 }
78
79
80 /*!
81  * @brief 魔法によるダメージを出力する / Generate damage-dice info string such as "dam 2d10"
82  * @param dice ダイス数
83  * @param sides ダイス目
84  * @param base 固定値
85  * @return フォーマットに従い整形された文字列
86  */
87 concptr info_damage(DICE_NUMBER dice, DICE_SID sides, int base)
88 {
89         return info_string_dice(_("損傷:", "dam "), dice, sides, base);
90 }
91
92 /*!
93  * @brief 魔法の効果時間を出力する / Generate duration info string such as "dur 20+1d20"
94  * @param base 固定値
95  * @param sides ダイス目
96  * @return フォーマットに従い整形された文字列
97  */
98 concptr info_duration(int base, DICE_SID sides)
99 {
100         return format(_("期間:%d+1d%d", "dur %d+1d%d"), base, sides);
101 }
102
103 /*!
104  * @brief 魔法の効果範囲を出力する / Generate range info string such as "range 5"
105  * @param range 効果範囲
106  * @return フォーマットに従い整形された文字列
107  */
108 concptr info_range(POSITION range)
109 {
110         return format(_("範囲:%d", "range %d"), range);
111 }
112
113 /*!
114  * @brief 魔法による回復量を出力する / Generate heal info string such as "heal 2d8"
115  * @param dice ダイス数
116  * @param sides ダイス目
117  * @param base 固定値
118  * @return フォーマットに従い整形された文字列
119  */
120 concptr info_heal(DICE_NUMBER dice, DICE_SID sides, int base)
121 {
122         return info_string_dice(_("回復:", "heal "), dice, sides, base);
123 }
124
125 /*!
126  * @brief 魔法効果発動までの遅延ターンを出力する / Generate delay info string such as "delay 15+1d15"
127  * @param base 固定値
128  * @param sides ダイス目
129  * @return フォーマットに従い整形された文字列
130  */
131 concptr info_delay(int base, DICE_SID sides)
132 {
133         return format(_("遅延:%d+1d%d", "delay %d+1d%d"), base, sides);
134 }
135
136
137 /*!
138  * @brief 魔法によるダメージを出力する(固定値&複数回処理) / Generate multiple-damage info string such as "dam 25 each"
139  * @param dam 固定値
140  * @return フォーマットに従い整形された文字列
141  */
142 concptr info_multi_damage(HIT_POINT dam)
143 {
144         return format(_("損傷:各%d", "dam %d each"), dam);
145 }
146
147
148 /*!
149  * @brief 魔法によるダメージを出力する(ダイスのみ&複数回処理) / Generate multiple-damage-dice info string such as "dam 5d2 each"
150  * @param dice ダイス数
151  * @param sides ダイス目
152  * @return フォーマットに従い整形された文字列
153  */
154 concptr info_multi_damage_dice(DICE_NUMBER dice, DICE_SID sides)
155 {
156         return format(_("損傷:各%dd%d", "dam %dd%d each"), dice, sides);
157 }
158
159 /*!
160  * @brief 魔法による一般的な効力値を出力する(固定値) / Generate power info string such as "power 100"
161  * @param power 固定値
162  * @return フォーマットに従い整形された文字列
163  */
164 concptr info_power(int power)
165 {
166         return format(_("効力:%d", "power %d"), power);
167 }
168
169
170 /*!
171  * @brief 魔法による一般的な効力値を出力する(ダイス値) / Generate power info string such as "power 100"
172  * @param dice ダイス数
173  * @param sides ダイス目
174  * @return フォーマットに従い整形された文字列
175  */
176 /*
177  * Generate power info string such as "power 1d100"
178  */
179 concptr info_power_dice(DICE_NUMBER dice, DICE_SID sides)
180 {
181         return format(_("効力:%dd%d", "power %dd%d"), dice, sides);
182 }
183
184
185 /*!
186  * @brief 魔法の効果半径を出力する / Generate radius info string such as "rad 100"
187  * @param rad 効果半径
188  * @return フォーマットに従い整形された文字列
189  */
190 concptr info_radius(POSITION rad)
191 {
192         return format(_("半径:%d", "rad %d"), rad);
193 }
194
195
196 /*!
197  * @brief 魔法効果の限界重量を出力する / Generate weight info string such as "max wgt 15"
198  * @param weight 最大重量
199  * @return フォーマットに従い整形された文字列
200  */
201 concptr info_weight(WEIGHT weight)
202 {
203 #ifdef JP
204         return format("最大重量:%d.%dkg", lbtokg1(weight), lbtokg2(weight));
205 #else
206         return format("max wgt %d", weight/10);
207 #endif
208 }
209
210 /*!
211  * @brief 魔法が利用可能かどうかを返す /
212  * Determine if a spell is "okay" for the player to cast or study
213  * The spell must be legible, not forgotten, and also, to cast,
214  * it must be known, and to study, it must not be known.
215  * @param spell 呪文ID
216  * @param learned 使用可能な判定ならばTRUE、学習可能かどうかの判定ならばFALSE
217  * @param study_pray 祈りの学習判定目的ならばTRUE
218  * @param use_realm 魔法領域ID
219  * @return 失敗率(%)
220  */
221 static bool spell_okay(int spell, bool learned, bool study_pray, int use_realm)
222 {
223         const magic_type *s_ptr;
224
225         /* Access the spell */
226         if (!is_magic(use_realm))
227         {
228                 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
229         }
230         else
231         {
232                 s_ptr = &mp_ptr->info[use_realm - 1][spell];
233         }
234
235         /* Spell is illegal */
236         if (s_ptr->slevel > p_ptr->lev) return (FALSE);
237
238         /* Spell is forgotten */
239         if ((use_realm == p_ptr->realm2) ?
240                 (p_ptr->spell_forgotten2 & (1L << spell)) :
241                 (p_ptr->spell_forgotten1 & (1L << spell)))
242         {
243                 /* Never okay */
244                 return (FALSE);
245         }
246
247         if (p_ptr->pclass == CLASS_SORCERER) return (TRUE);
248         if (p_ptr->pclass == CLASS_RED_MAGE) return (TRUE);
249
250         /* Spell is learned */
251         if ((use_realm == p_ptr->realm2) ?
252                 (p_ptr->spell_learned2 & (1L << spell)) :
253                 (p_ptr->spell_learned1 & (1L << spell)))
254         {
255                 /* Always true */
256                 return (!study_pray);
257         }
258
259         /* Okay to study, not to cast */
260         return (!learned);
261 }
262
263
264 /*!
265  * @brief 魔法処理のメインルーチン
266  * @param realm 魔法領域のID
267  * @param spell 各領域の魔法ID
268  * @param mode 求める処理
269  * @return 各領域魔法に各種テキストを求めた場合は文字列参照ポインタ、そうでない場合はNULLポインタを返す。
270  */
271 concptr do_spell(REALM_IDX realm, SPELL_IDX spell, BIT_FLAGS mode)
272 {
273         switch (realm)
274         {
275         case REALM_LIFE:     return do_life_spell(spell, mode);
276         case REALM_SORCERY:  return do_sorcery_spell(spell, mode);
277         case REALM_NATURE:   return do_nature_spell(spell, mode);
278         case REALM_CHAOS:    return do_chaos_spell(spell, mode);
279         case REALM_DEATH:    return do_death_spell(spell, mode);
280         case REALM_TRUMP:    return do_trump_spell(spell, mode);
281         case REALM_ARCANE:   return do_arcane_spell(spell, mode);
282         case REALM_CRAFT:    return do_craft_spell(spell, mode);
283         case REALM_DAEMON:   return do_daemon_spell(spell, mode);
284         case REALM_CRUSADE:  return do_crusade_spell(spell, mode);
285         case REALM_MUSIC:    return do_music_spell(spell, mode);
286         case REALM_HISSATSU: return do_hissatsu_spell(spell, mode);
287         case REALM_HEX:      return do_hex_spell(spell, mode);
288         }
289
290         return NULL;
291 }
292
293
294 /*!
295  * @brief 領域魔法の閲覧、学習、使用選択するインターフェイス処理
296  * Allow user to choose a spell/prayer from the given book.
297  * @param sn 選択した魔法IDを返す参照ポインタ
298  * @param prompt 魔法を利用する際の動詞表記
299  * @param sval 魔道書のsval
300  * @param learned 閲覧/使用選択ならばTRUE、学習処理ならFALSE
301  * @param use_realm 魔法領域ID
302  * @return
303  * <pre>
304  * If a valid spell is chosen, saves it in '*sn' and returns TRUE
305  * If the user hits escape, returns FALSE, and set '*sn' to -1
306  * If there are no legal choices, returns FALSE, and sets '*sn' to -2
307  * The "prompt" should be "cast", "recite", or "study"
308  * The "known" should be TRUE for cast/pray, FALSE for study
309  * </pre>
310  */
311 static int get_spell(SPELL_IDX *sn, concptr prompt, OBJECT_SUBTYPE_VALUE sval, bool learned, REALM_IDX use_realm)
312 {
313         int i;
314         SPELL_IDX spell = -1;
315         int num = 0;
316         int ask = TRUE;
317         MANA_POINT need_mana;
318         SPELL_IDX spells[64];
319         bool flag, redraw, okay;
320         char choice;
321         const magic_type  *s_ptr;
322         char out_val[160];
323         concptr p;
324         COMMAND_CODE code;
325 #ifdef JP
326         char jverb_buf[128];
327 #endif
328         int menu_line = (use_menu ? 1 : 0);
329
330         /* Get the spell, if available */
331         if (repeat_pull(&code))
332         {
333                 *sn = (SPELL_IDX)code;
334                 /* Verify the spell */
335                 if (spell_okay(*sn, learned, FALSE, use_realm))
336                 {
337                         /* Success */
338                         return (TRUE);
339                 }
340         }
341
342         p = spell_category_name(mp_ptr->spell_book);
343
344         /* Extract spells */
345         for (spell = 0; spell < 32; spell++)
346         {
347                 /* Check for this spell */
348                 if ((fake_spell_flags[sval] & (1L << spell)))
349                 {
350                         /* Collect this spell */
351                         spells[num++] = spell;
352                 }
353         }
354
355         /* Assume no usable spells */
356         okay = FALSE;
357
358         /* Assume no spells available */
359         (*sn) = -2;
360
361         /* Check for "okay" spells */
362         for (i = 0; i < num; i++)
363         {
364                 /* Look for "okay" spells */
365                 if (spell_okay(spells[i], learned, FALSE, use_realm)) okay = TRUE;
366         }
367
368         /* No "okay" spells */
369         if (!okay) return (FALSE);
370         if (((use_realm) != p_ptr->realm1) && ((use_realm) != p_ptr->realm2) && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE)) return FALSE;
371         if (((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE)) && !is_magic(use_realm)) return FALSE;
372         if ((p_ptr->pclass == CLASS_RED_MAGE) && ((use_realm) != REALM_ARCANE) && (sval > 1)) return FALSE;
373
374         /* Assume cancelled */
375         *sn = (-1);
376
377         /* Nothing chosen yet */
378         flag = FALSE;
379
380         /* No redraw yet */
381         redraw = FALSE;
382
383         p_ptr->window |= (PW_SPELL);
384         handle_stuff();
385
386         /* Build a prompt (accept all spells) */
387 #ifdef JP
388         jverb(prompt, jverb_buf, JVERB_AND);
389         (void)strnfmt(out_val, 78, "(%^s:%c-%c, '*'で一覧, ESCで中断) どの%sを%^sますか? ",
390                 p, I2A(0), I2A(num - 1), p, jverb_buf);
391 #else
392         (void)strnfmt(out_val, 78, "(%^ss %c-%c, *=List, ESC=exit) %^s which %s? ",
393                 p, I2A(0), I2A(num - 1), prompt, p);
394 #endif
395
396         choice = (always_show_list || use_menu) ? ESCAPE : 1;
397         while (!flag)
398         {
399                 if (choice == ESCAPE) choice = ' ';
400                 else if (!get_com(out_val, &choice, TRUE))break;
401
402                 if (use_menu && choice != ' ')
403                 {
404                         switch (choice)
405                         {
406                         case '0':
407                         {
408                                 screen_load();
409                                 return FALSE;
410                         }
411
412                         case '8':
413                         case 'k':
414                         case 'K':
415                         {
416                                 menu_line += (num - 1);
417                                 break;
418                         }
419
420                         case '2':
421                         case 'j':
422                         case 'J':
423                         {
424                                 menu_line++;
425                                 break;
426                         }
427
428                         case 'x':
429                         case 'X':
430                         case '\r':
431                         case '\n':
432                         {
433                                 i = menu_line - 1;
434                                 ask = FALSE;
435                                 break;
436                         }
437                         }
438                         if (menu_line > num) menu_line -= num;
439                         /* Display a list of spells */
440                         print_spells(menu_line, spells, num, 1, 15, use_realm);
441                         if (ask) continue;
442                 }
443                 else
444                 {
445                         /* Request redraw */
446                         if ((choice == ' ') || (choice == '*') || (choice == '?'))
447                         {
448                                 /* Show the list */
449                                 if (!redraw)
450                                 {
451                                         redraw = TRUE;
452                                         screen_save();
453
454                                         /* Display a list of spells */
455                                         print_spells(menu_line, spells, num, 1, 15, use_realm);
456                                 }
457
458                                 /* Hide the list */
459                                 else
460                                 {
461                                         if (use_menu) continue;
462
463                                         /* Hide list */
464                                         redraw = FALSE;
465                                         screen_load();
466                                 }
467
468                                 /* Redo asking */
469                                 continue;
470                         }
471
472
473                         /* Note verify */
474                         ask = (isupper(choice));
475
476                         /* Lowercase */
477                         if (ask) choice = (char)tolower(choice);
478
479                         /* Extract request */
480                         i = (islower(choice) ? A2I(choice) : -1);
481                 }
482
483                 /* Totally Illegal */
484                 if ((i < 0) || (i >= num))
485                 {
486                         bell();
487                         continue;
488                 }
489
490                 /* Save the spell index */
491                 spell = spells[i];
492
493                 /* Require "okay" spells */
494                 if (!spell_okay(spell, learned, FALSE, use_realm))
495                 {
496                         bell();
497 #ifdef JP
498                         msg_format("その%sを%sことはできません。", p, prompt);
499 #else
500                         msg_format("You may not %s that %s.", prompt, p);
501 #endif
502
503                         continue;
504                 }
505
506                 /* Verify it */
507                 if (ask)
508                 {
509                         char tmp_val[160];
510
511                         /* Access the spell */
512                         if (!is_magic(use_realm))
513                         {
514                                 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
515                         }
516                         else
517                         {
518                                 s_ptr = &mp_ptr->info[use_realm - 1][spell];
519                         }
520
521                         /* Extract mana consumption rate */
522                         if (use_realm == REALM_HISSATSU)
523                         {
524                                 need_mana = s_ptr->smana;
525                         }
526                         else
527                         {
528                                 need_mana = mod_need_mana(s_ptr->smana, spell, use_realm);
529                         }
530
531                         /* Prompt */
532 #ifdef JP
533                         jverb(prompt, jverb_buf, JVERB_AND);
534                         /* 英日切り替え機能に対応 */
535                         (void)strnfmt(tmp_val, 78, "%s(MP%d, 失敗率%d%%)を%sますか? ",
536                                 do_spell(use_realm, spell, SPELL_NAME), need_mana,
537                                 spell_chance(spell, use_realm), jverb_buf);
538 #else
539                         (void)strnfmt(tmp_val, 78, "%^s %s (%d mana, %d%% fail)? ",
540                                 prompt, do_spell(use_realm, spell, SPELL_NAME), need_mana,
541                                 spell_chance(spell, use_realm));
542 #endif
543
544
545                         /* Belay that order */
546                         if (!get_check(tmp_val)) continue;
547                 }
548
549                 /* Stop the loop */
550                 flag = TRUE;
551         }
552
553         if (redraw) screen_load();
554
555         p_ptr->window |= (PW_SPELL);
556         handle_stuff();
557
558         /* Abort if needed */
559         if (!flag) return FALSE;
560
561         /* Save the choice */
562         (*sn) = spell;
563
564         repeat_push((COMMAND_CODE)spell);
565
566         /* Success */
567         return TRUE;
568 }
569
570 /*!
571  * @brief プレイヤーの職業が練気術師の時、領域魔法と練気術を切り換える処理のインターフェイス
572  * @param browse_only 魔法と技能の閲覧を行うならばTRUE
573  * @return 魔道書を一冊も持っていないならTRUEを返す
574  */
575 static void confirm_use_force(bool browse_only)
576 {
577         char which;
578         COMMAND_CODE code;
579
580         /* Get the item index */
581         if (repeat_pull(&code) && (code == INVEN_FORCE))
582         {
583                 browse_only ? do_cmd_mind_browse() : do_cmd_mind();
584                 return;
585         }
586
587         /* Show the prompt */
588         prt(_("('w'練気術, ESC) 'w'かESCを押してください。 ", "(w for the Force, ESC) Hit 'w' or ESC. "), 0, 0);
589
590         while (1)
591         {
592                 /* Get a key */
593                 which = inkey();
594
595                 if (which == ESCAPE) break;
596                 else if (which == 'w')
597                 {
598                         repeat_push(INVEN_FORCE);
599                         break;
600                 }
601         }
602
603         /* Clear the prompt line */
604         prt("", 0, 0);
605
606         if (which == 'w')
607         {
608                 browse_only ? do_cmd_mind_browse() : do_cmd_mind();
609         }
610 }
611
612
613 /*!
614  * @brief プレイヤーの魔法と技能を閲覧するコマンドのメインルーチン /
615  * Peruse the spells/prayers in a book
616  * @return なし
617  * @details
618  * <pre>
619  * Note that *all* spells in the book are listed
620  *
621  * Note that browsing is allowed while confused or blind,
622  * and in the dark, primarily to allow browsing in stores.
623  * </pre>
624  */
625 void do_cmd_browse(void)
626 {
627         OBJECT_IDX item;
628         OBJECT_SUBTYPE_VALUE sval;
629         REALM_IDX use_realm = 0;
630         int j, line;
631         SPELL_IDX spell = -1;
632         int num = 0;
633
634         SPELL_IDX spells[64];
635         char temp[62 * 4];
636
637         object_type *o_ptr;
638
639         concptr q, s;
640
641         /* Warriors are illiterate */
642         if (!(p_ptr->realm1 || p_ptr->realm2) && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE))
643         {
644                 msg_print(_("本を読むことができない!", "You cannot read books!"));
645                 return;
646         }
647
648         if (p_ptr->special_defense & KATA_MUSOU)
649         {
650                 set_action(ACTION_NONE);
651         }
652
653         if (p_ptr->pclass == CLASS_FORCETRAINER)
654         {
655                 if (player_has_no_spellbooks())
656                 {
657                         confirm_use_force(TRUE);
658                         return;
659                 }
660         }
661
662         /* Restrict choices to "useful" books */
663         if (p_ptr->realm2 == REALM_NONE) item_tester_tval = mp_ptr->spell_book;
664         else item_tester_hook = item_tester_learn_spell;
665
666         q = _("どの本を読みますか? ", "Browse which book? ");
667         s = _("読める本がない。", "You have no books that you can read.");
668
669         o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR | (p_ptr->pclass == CLASS_FORCETRAINER ? USE_FORCE : 0)));
670         if (!o_ptr)
671         {
672                 if (item == INVEN_FORCE) /* the_force */
673                 {
674                         do_cmd_mind_browse();
675                         return;
676                 }
677                 return;
678         }
679
680         /* Access the item's sval */
681         sval = o_ptr->sval;
682
683         use_realm = tval2realm(o_ptr->tval);
684
685         /* Track the object kind */
686         object_kind_track(o_ptr->k_idx);
687         handle_stuff();
688
689         /* Extract spells */
690         for (spell = 0; spell < 32; spell++)
691         {
692                 /* Check for this spell */
693                 if ((fake_spell_flags[sval] & (1L << spell)))
694                 {
695                         /* Collect this spell */
696                         spells[num++] = spell;
697                 }
698         }
699
700         screen_save();
701         prt("", 0, 0);
702
703         /* Keep browsing spells.  Exit browsing on cancel. */
704         while (TRUE)
705         {
706                 /* Ask for a spell, allow cancel */
707                 if (!get_spell(&spell, _("読む", "browse"), o_ptr->sval, TRUE, use_realm))
708                 {
709                         /* If cancelled, leave immediately. */
710                         if (spell == -1) break;
711
712                         /* Display a list of spells */
713                         print_spells(0, spells, num, 1, 15, use_realm);
714
715                         /* Notify that there's nothing to see, and wait. */
716                         if (use_realm == REALM_HISSATSU)
717                                 prt(_("読める技がない。", "No techniques to browse."), 0, 0);
718                         else
719                                 prt(_("読める呪文がない。", "No spells to browse."), 0, 0);
720                         (void)inkey();
721
722                         screen_load();
723
724                         return;
725                 }
726
727                 /* Clear lines, position cursor  (really should use strlen here) */
728                 Term_erase(14, 14, 255);
729                 Term_erase(14, 13, 255);
730                 Term_erase(14, 12, 255);
731                 Term_erase(14, 11, 255);
732
733                 roff_to_buf(do_spell(use_realm, spell, SPELL_DESC), 62, temp, sizeof(temp));
734
735                 for (j = 0, line = 11; temp[j]; j += 1 + strlen(&temp[j]))
736                 {
737                         prt(&temp[j], line, 15);
738                         line++;
739                 }
740         }
741         screen_load();
742 }
743
744 /*!
745  * @brief プレイヤーの第二魔法領域を変更する /
746  * @param next_realm 変更先の魔法領域ID
747  * @return なし
748  */
749 static void change_realm2(CHARACTER_IDX next_realm)
750 {
751         int i, j = 0;
752         char tmp[80];
753
754         for (i = 0; i < 64; i++)
755         {
756                 p_ptr->spell_order[j] = p_ptr->spell_order[i];
757                 if (p_ptr->spell_order[i] < 32) j++;
758         }
759         for (; j < 64; j++)
760                 p_ptr->spell_order[j] = 99;
761
762         for (i = 32; i < 64; i++)
763         {
764                 p_ptr->spell_exp[i] = SPELL_EXP_UNSKILLED;
765         }
766         p_ptr->spell_learned2 = 0L;
767         p_ptr->spell_worked2 = 0L;
768         p_ptr->spell_forgotten2 = 0L;
769
770         sprintf(tmp, _("魔法の領域を%sから%sに変更した。", "change magic realm from %s to %s."), realm_names[p_ptr->realm2], realm_names[next_realm]);
771         do_cmd_write_nikki(NIKKI_BUNSHOU, 0, tmp);
772         p_ptr->old_realm |= 1 << (p_ptr->realm2 - 1);
773         p_ptr->realm2 = next_realm;
774
775         p_ptr->update |= (PU_REORDER);
776         p_ptr->update |= (PU_SPELLS);
777         handle_stuff();
778
779         /* Load an autopick preference file */
780         autopick_load_pref(FALSE);
781 }
782
783
784 /*!
785  * @brief 魔法を学習するコマンドのメインルーチン /
786  * Study a book to gain a new spell/prayer
787  * @return なし
788  */
789 void do_cmd_study(void)
790 {
791         int     i;
792         OBJECT_IDX item;
793         OBJECT_SUBTYPE_VALUE sval;
794         int     increment = 0;
795         bool    learned = FALSE;
796
797         /* Spells of realm2 will have an increment of +32 */
798         SPELL_IDX spell = -1;
799
800         concptr p = spell_category_name(mp_ptr->spell_book);
801
802         object_type *o_ptr;
803
804         concptr q, s;
805
806         if (!p_ptr->realm1)
807         {
808                 msg_print(_("本を読むことができない!", "You cannot read books!"));
809                 return;
810         }
811
812         if (p_ptr->blind || no_lite())
813         {
814                 msg_print(_("目が見えない!", "You cannot see!"));
815                 return;
816         }
817
818         if (cmd_limit_confused(p_ptr)) return;
819
820         if (!(p_ptr->new_spells))
821         {
822                 msg_format(_("新しい%sを覚えることはできない!", "You cannot learn any new %ss!"), p);
823                 return;
824         }
825
826         if (p_ptr->special_defense & KATA_MUSOU)
827         {
828                 set_action(ACTION_NONE);
829         }
830
831 #ifdef JP
832         if (p_ptr->new_spells < 10) {
833                 msg_format("あと %d つの%sを学べる。", p_ptr->new_spells, p);
834         }
835         else {
836                 msg_format("あと %d 個の%sを学べる。", p_ptr->new_spells, p);
837         }
838 #else
839         msg_format("You can learn %d new %s%s.", p_ptr->new_spells, p,
840                 (p_ptr->new_spells == 1 ? "" : "s"));
841 #endif
842
843         msg_print(NULL);
844
845
846         /* Restrict choices to "useful" books */
847         if (p_ptr->realm2 == REALM_NONE) item_tester_tval = mp_ptr->spell_book;
848         else item_tester_hook = item_tester_learn_spell;
849
850         q = _("どの本から学びますか? ", "Study which book? ");
851         s = _("読める本がない。", "You have no books that you can read.");
852
853         o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR));
854         if (!o_ptr) return;
855
856         /* Access the item's sval */
857         sval = o_ptr->sval;
858
859         if (o_ptr->tval == REALM2_BOOK) increment = 32;
860         else if (o_ptr->tval != REALM1_BOOK)
861         {
862                 if (!get_check(_("本当に魔法の領域を変更しますか?", "Really, change magic realm? "))) return;
863                 change_realm2(tval2realm(o_ptr->tval));
864                 increment = 32;
865         }
866
867         /* Track the object kind */
868         object_kind_track(o_ptr->k_idx);
869         handle_stuff();
870
871         /* Mage -- Learn a selected spell */
872         if (mp_ptr->spell_book != TV_LIFE_BOOK)
873         {
874                 /* Ask for a spell, allow cancel */
875                 if (!get_spell(&spell, _("学ぶ", "study"), sval, FALSE, o_ptr->tval - TV_LIFE_BOOK + 1) && (spell == -1)) return;
876         }
877
878         /* Priest -- Learn a random prayer */
879         else
880         {
881                 int k = 0;
882                 int gift = -1;
883
884                 /* Extract spells */
885                 for (spell = 0; spell < 32; spell++)
886                 {
887                         /* Check spells in the book */
888                         if ((fake_spell_flags[sval] & (1L << spell)))
889                         {
890                                 /* Skip non "okay" prayers */
891                                 if (!spell_okay(spell, FALSE, TRUE,
892                                         (increment ? p_ptr->realm2 : p_ptr->realm1))) continue;
893
894                                 /* Hack -- Prepare the randomizer */
895                                 k++;
896
897                                 /* Hack -- Apply the randomizer */
898                                 if (one_in_(k)) gift = spell;
899                         }
900                 }
901
902                 /* Accept gift */
903                 spell = gift;
904         }
905
906         /* Nothing to study */
907         if (spell < 0)
908         {
909                 msg_format(_("その本には学ぶべき%sがない。", "You cannot learn any %ss in that book."), p);
910
911                 /* Abort */
912                 return;
913         }
914
915         if (increment) spell += increment;
916
917         /* Learn the spell */
918         if (spell < 32)
919         {
920                 if (p_ptr->spell_learned1 & (1L << spell)) learned = TRUE;
921                 else p_ptr->spell_learned1 |= (1L << spell);
922         }
923         else
924         {
925                 if (p_ptr->spell_learned2 & (1L << (spell - 32))) learned = TRUE;
926                 else p_ptr->spell_learned2 |= (1L << (spell - 32));
927         }
928
929         if (learned)
930         {
931                 int max_exp = (spell < 32) ? SPELL_EXP_MASTER : SPELL_EXP_EXPERT;
932                 int old_exp = p_ptr->spell_exp[spell];
933                 int new_rank = EXP_LEVEL_UNSKILLED;
934                 concptr name = do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME);
935
936                 if (old_exp >= max_exp)
937                 {
938                         msg_format(_("その%sは完全に使いこなせるので学ぶ必要はない。", "You don't need to study this %s anymore."), p);
939                         return;
940                 }
941 #ifdef JP
942                 if (!get_check(format("%sの%sをさらに学びます。よろしいですか?", name, p)))
943 #else
944                 if (!get_check(format("You will study a %s of %s again. Are you sure? ", p, name)))
945 #endif
946                 {
947                         return;
948                 }
949                 else if (old_exp >= SPELL_EXP_EXPERT)
950                 {
951                         p_ptr->spell_exp[spell] = SPELL_EXP_MASTER;
952                         new_rank = EXP_LEVEL_MASTER;
953                 }
954                 else if (old_exp >= SPELL_EXP_SKILLED)
955                 {
956                         if (spell >= 32) p_ptr->spell_exp[spell] = SPELL_EXP_EXPERT;
957                         else p_ptr->spell_exp[spell] += SPELL_EXP_EXPERT - SPELL_EXP_SKILLED;
958                         new_rank = EXP_LEVEL_EXPERT;
959                 }
960                 else if (old_exp >= SPELL_EXP_BEGINNER)
961                 {
962                         p_ptr->spell_exp[spell] = SPELL_EXP_SKILLED + (old_exp - SPELL_EXP_BEGINNER) * 2 / 3;
963                         new_rank = EXP_LEVEL_SKILLED;
964                 }
965                 else
966                 {
967                         p_ptr->spell_exp[spell] = SPELL_EXP_BEGINNER + old_exp / 3;
968                         new_rank = EXP_LEVEL_BEGINNER;
969                 }
970                 msg_format(_("%sの熟練度が%sに上がった。", "Your proficiency of %s is now %s rank."), name, exp_level_str[new_rank]);
971         }
972         else
973         {
974                 /* Find the next open entry in "p_ptr->spell_order[]" */
975                 for (i = 0; i < 64; i++)
976                 {
977                         /* Stop at the first empty space */
978                         if (p_ptr->spell_order[i] == 99) break;
979                 }
980
981                 /* Add the spell to the known list */
982                 p_ptr->spell_order[i++] = spell;
983
984                 /* Mention the result */
985 #ifdef JP
986                 /* 英日切り替え機能に対応 */
987                 if (mp_ptr->spell_book == TV_MUSIC_BOOK)
988                 {
989                         msg_format("%sを学んだ。",
990                                 do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME));
991                 }
992                 else
993                 {
994                         msg_format("%sの%sを学んだ。",
995                                 do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME), p);
996                 }
997 #else
998                 msg_format("You have learned the %s of %s.",
999                         p, do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME));
1000 #endif
1001         }
1002
1003         take_turn(p_ptr, 100);
1004
1005         switch (mp_ptr->spell_book)
1006         {
1007         case TV_LIFE_BOOK:
1008                 chg_virtue(V_FAITH, 1);
1009                 break;
1010         case TV_DEATH_BOOK:
1011                 chg_virtue(V_UNLIFE, 1);
1012                 break;
1013         case TV_NATURE_BOOK:
1014                 chg_virtue(V_NATURE, 1);
1015                 break;
1016         default:
1017                 chg_virtue(V_KNOWLEDGE, 1);
1018                 break;
1019         }
1020
1021         sound(SOUND_STUDY);
1022
1023         /* One less spell available */
1024         p_ptr->learned_spells++;
1025
1026         /* Update Study */
1027         p_ptr->update |= (PU_SPELLS);
1028         update_creature(p_ptr);
1029
1030         /* Redraw object recall */
1031         p_ptr->window |= (PW_OBJECT);
1032 }
1033
1034
1035 /*!
1036  * @brief 魔法を詠唱するコマンドのメインルーチン /
1037  * Cast a spell
1038  * @return なし
1039  */
1040 void do_cmd_cast(void)
1041 {
1042         OBJECT_IDX item;
1043         OBJECT_SUBTYPE_VALUE sval;
1044         SPELL_IDX spell;
1045         REALM_IDX realm;
1046         int     chance;
1047         int     increment = 0;
1048         REALM_IDX use_realm;
1049         MANA_POINT need_mana;
1050
1051         concptr prayer;
1052         object_type *o_ptr;
1053         const magic_type *s_ptr;
1054         concptr q, s;
1055
1056         bool over_exerted = FALSE;
1057
1058         /* Require spell ability */
1059         if (!p_ptr->realm1 && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE))
1060         {
1061                 msg_print(_("呪文を唱えられない!", "You cannot cast spells!"));
1062                 return;
1063         }
1064
1065         /* Require lite */
1066         if (p_ptr->blind || no_lite())
1067         {
1068                 if (p_ptr->pclass == CLASS_FORCETRAINER) confirm_use_force(FALSE);
1069                 else
1070                 {
1071                         msg_print(_("目が見えない!", "You cannot see!"));
1072                         flush();
1073                 }
1074                 return;
1075         }
1076
1077         if (cmd_limit_confused(p_ptr)) return;
1078
1079         /* Hex */
1080         if (p_ptr->realm1 == REALM_HEX)
1081         {
1082                 if (hex_spell_fully())
1083                 {
1084                         bool flag = FALSE;
1085                         msg_print(_("これ以上新しい呪文を詠唱することはできない。", "Can not spell new spells more."));
1086                         flush();
1087                         if (p_ptr->lev >= 35) flag = stop_hex_spell();
1088                         if (!flag) return;
1089                 }
1090         }
1091
1092         if (p_ptr->pclass == CLASS_FORCETRAINER)
1093         {
1094                 if (player_has_no_spellbooks())
1095                 {
1096                         confirm_use_force(FALSE);
1097                         return;
1098                 }
1099         }
1100
1101         prayer = spell_category_name(mp_ptr->spell_book);
1102
1103         /* Restrict choices to spell books */
1104         item_tester_tval = mp_ptr->spell_book;
1105
1106         q = _("どの呪文書を使いますか? ", "Use which book? ");
1107         s = _("呪文書がない!", "You have no spell books!");
1108
1109         o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR | (p_ptr->pclass == CLASS_FORCETRAINER ? USE_FORCE : 0)));
1110         if (!o_ptr)
1111         {
1112                 if (item == INVEN_FORCE) /* the_force */
1113                 {
1114                         do_cmd_mind();
1115                         return;
1116                 }
1117                 return;
1118         }
1119
1120         /* Access the item's sval */
1121         sval = o_ptr->sval;
1122
1123         if ((p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE) && (o_ptr->tval == REALM2_BOOK)) increment = 32;
1124
1125         /* Track the object kind */
1126         object_kind_track(o_ptr->k_idx);
1127         handle_stuff();
1128
1129         if ((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE))
1130                 realm = o_ptr->tval - TV_LIFE_BOOK + 1;
1131         else if (increment) realm = p_ptr->realm2;
1132         else realm = p_ptr->realm1;
1133
1134         /* Ask for a spell */
1135 #ifdef JP
1136         if (!get_spell(&spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "詠唱する" : (mp_ptr->spell_book == TV_MUSIC_BOOK) ? "歌う" : "唱える"),
1137                 sval, TRUE, realm))
1138         {
1139                 if (spell == -2) msg_format("その本には知っている%sがない。", prayer);
1140                 return;
1141         }
1142 #else
1143         if (!get_spell(&spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1144                 sval, TRUE, realm))
1145         {
1146                 if (spell == -2)
1147                         msg_format("You don't know any %ss in that book.", prayer);
1148                 return;
1149         }
1150 #endif
1151
1152
1153         use_realm = tval2realm(o_ptr->tval);
1154
1155         /* Hex */
1156         if (use_realm == REALM_HEX)
1157         {
1158                 if (hex_spelling(spell))
1159                 {
1160                         msg_print(_("その呪文はすでに詠唱中だ。", "You are already casting it."));
1161                         return;
1162                 }
1163         }
1164
1165         if (!is_magic(use_realm))
1166         {
1167                 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
1168         }
1169         else
1170         {
1171                 s_ptr = &mp_ptr->info[realm - 1][spell];
1172         }
1173
1174         /* Extract mana consumption rate */
1175         need_mana = mod_need_mana(s_ptr->smana, spell, realm);
1176
1177         /* Verify "dangerous" spells */
1178         if (need_mana > p_ptr->csp)
1179         {
1180                 if (flush_failure) flush();
1181
1182                 /* Warning */
1183 #ifdef JP
1184                 msg_format("その%sを%sのに十分なマジックポイントがない。", prayer,
1185                         ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "詠唱する" : (mp_ptr->spell_book == TV_LIFE_BOOK) ? "歌う" : "唱える"));
1186 #else
1187                 msg_format("You do not have enough mana to %s this %s.",
1188                         ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1189                         prayer);
1190 #endif
1191
1192
1193                 if (!over_exert) return;
1194
1195                 /* Verify */
1196                 if (!get_check_strict(_("それでも挑戦しますか? ", "Attempt it anyway? "), CHECK_OKAY_CANCEL)) return;
1197         }
1198
1199         /* Spell failure chance */
1200         chance = spell_chance(spell, use_realm);
1201
1202         /* Sufficient mana */
1203         if (need_mana <= p_ptr->csp)
1204         {
1205                 /* Use some mana */
1206                 p_ptr->csp -= need_mana;
1207         }
1208         else over_exerted = TRUE;
1209         p_ptr->redraw |= (PR_MANA);
1210
1211         /* Failed spell */
1212         if (randint0(100) < chance)
1213         {
1214                 if (flush_failure) flush();
1215
1216                 msg_format(_("%sをうまく唱えられなかった!", "You failed to get the %s off!"), prayer);
1217                 sound(SOUND_FAIL);
1218
1219                 switch (realm)
1220                 {
1221                 case REALM_LIFE:
1222                         if (randint1(100) < chance) chg_virtue(V_VITALITY, -1);
1223                         break;
1224                 case REALM_DEATH:
1225                         if (randint1(100) < chance) chg_virtue(V_UNLIFE, -1);
1226                         break;
1227                 case REALM_NATURE:
1228                         if (randint1(100) < chance) chg_virtue(V_NATURE, -1);
1229                         break;
1230                 case REALM_DAEMON:
1231                         if (randint1(100) < chance) chg_virtue(V_JUSTICE, 1);
1232                         break;
1233                 case REALM_CRUSADE:
1234                         if (randint1(100) < chance) chg_virtue(V_JUSTICE, -1);
1235                         break;
1236                 case REALM_HEX:
1237                         if (randint1(100) < chance) chg_virtue(V_COMPASSION, -1);
1238                         break;
1239                 default:
1240                         if (randint1(100) < chance) chg_virtue(V_KNOWLEDGE, -1);
1241                         break;
1242                 }
1243
1244                 /* Failure casting may activate some side effect */
1245                 do_spell(realm, spell, SPELL_FAIL);
1246
1247
1248                 if ((o_ptr->tval == TV_CHAOS_BOOK) && (randint1(100) < spell))
1249                 {
1250                         msg_print(_("カオス的な効果を発生した!", "You produce a chaotic effect!"));
1251                         wild_magic(spell);
1252                 }
1253                 else if ((o_ptr->tval == TV_DEATH_BOOK) && (randint1(100) < spell))
1254                 {
1255                         if ((sval == 3) && one_in_(2))
1256                         {
1257                                 sanity_blast(0, TRUE);
1258                         }
1259                         else
1260                         {
1261                                 msg_print(_("痛い!", "It hurts!"));
1262                                 take_hit(DAMAGE_LOSELIFE, damroll(o_ptr->sval + 1, 6), _("暗黒魔法の逆流", "a miscast Death spell"), -1);
1263
1264                                 if ((spell > 15) && one_in_(6) && !p_ptr->hold_exp)
1265                                         lose_exp(spell * 250);
1266                         }
1267                 }
1268                 else if ((o_ptr->tval == TV_MUSIC_BOOK) && (randint1(200) < spell))
1269                 {
1270                         msg_print(_("いやな音が響いた", "An infernal sound echoed."));
1271                         aggravate_monsters(0);
1272                 }
1273                 if (randint1(100) >= chance)
1274                         chg_virtue(V_CHANCE, -1);
1275         }
1276
1277         /* Process spell */
1278         else
1279         {
1280                 /* Canceled spells cost neither a current_world_ptr->game_turn nor mana */
1281                 if (!do_spell(realm, spell, SPELL_CAST)) return;
1282
1283                 if (randint1(100) < chance)
1284                         chg_virtue(V_CHANCE, 1);
1285
1286                 /* A spell was cast */
1287                 if (!(increment ?
1288                         (p_ptr->spell_worked2 & (1L << spell)) :
1289                         (p_ptr->spell_worked1 & (1L << spell)))
1290                         && (p_ptr->pclass != CLASS_SORCERER)
1291                         && (p_ptr->pclass != CLASS_RED_MAGE))
1292                 {
1293                         int e = s_ptr->sexp;
1294
1295                         /* The spell worked */
1296                         if (realm == p_ptr->realm1)
1297                         {
1298                                 p_ptr->spell_worked1 |= (1L << spell);
1299                         }
1300                         else
1301                         {
1302                                 p_ptr->spell_worked2 |= (1L << spell);
1303                         }
1304
1305                         /* Gain experience */
1306                         gain_exp(e * s_ptr->slevel);
1307
1308                         /* Redraw object recall */
1309                         p_ptr->window |= (PW_OBJECT);
1310
1311                         switch (realm)
1312                         {
1313                         case REALM_LIFE:
1314                                 chg_virtue(V_TEMPERANCE, 1);
1315                                 chg_virtue(V_COMPASSION, 1);
1316                                 chg_virtue(V_VITALITY, 1);
1317                                 chg_virtue(V_DILIGENCE, 1);
1318                                 break;
1319                         case REALM_DEATH:
1320                                 chg_virtue(V_UNLIFE, 1);
1321                                 chg_virtue(V_JUSTICE, -1);
1322                                 chg_virtue(V_FAITH, -1);
1323                                 chg_virtue(V_VITALITY, -1);
1324                                 break;
1325                         case REALM_DAEMON:
1326                                 chg_virtue(V_JUSTICE, -1);
1327                                 chg_virtue(V_FAITH, -1);
1328                                 chg_virtue(V_HONOUR, -1);
1329                                 chg_virtue(V_TEMPERANCE, -1);
1330                                 break;
1331                         case REALM_CRUSADE:
1332                                 chg_virtue(V_FAITH, 1);
1333                                 chg_virtue(V_JUSTICE, 1);
1334                                 chg_virtue(V_SACRIFICE, 1);
1335                                 chg_virtue(V_HONOUR, 1);
1336                                 break;
1337                         case REALM_NATURE:
1338                                 chg_virtue(V_NATURE, 1);
1339                                 chg_virtue(V_HARMONY, 1);
1340                                 break;
1341                         case REALM_HEX:
1342                                 chg_virtue(V_JUSTICE, -1);
1343                                 chg_virtue(V_FAITH, -1);
1344                                 chg_virtue(V_HONOUR, -1);
1345                                 chg_virtue(V_COMPASSION, -1);
1346                                 break;
1347                         default:
1348                                 chg_virtue(V_KNOWLEDGE, 1);
1349                                 break;
1350                         }
1351                 }
1352                 switch (realm)
1353                 {
1354                 case REALM_LIFE:
1355                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_TEMPERANCE, 1);
1356                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_COMPASSION, 1);
1357                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_VITALITY, 1);
1358                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_DILIGENCE, 1);
1359                         break;
1360                 case REALM_DEATH:
1361                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_UNLIFE, 1);
1362                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1363                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1364                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_VITALITY, -1);
1365                         break;
1366                 case REALM_DAEMON:
1367                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1368                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1369                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, -1);
1370                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_TEMPERANCE, -1);
1371                         break;
1372                 case REALM_CRUSADE:
1373                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, 1);
1374                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, 1);
1375                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_SACRIFICE, 1);
1376                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, 1);
1377                         break;
1378                 case REALM_NATURE:
1379                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_NATURE, 1);
1380                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HARMONY, 1);
1381                         break;
1382                 case REALM_HEX:
1383                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1384                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1385                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, -1);
1386                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_COMPASSION, -1);
1387                         break;
1388                 }
1389                 if (mp_ptr->spell_xtra & MAGIC_GAIN_EXP)
1390                 {
1391                         s16b cur_exp = p_ptr->spell_exp[(increment ? 32 : 0) + spell];
1392                         s16b exp_gain = 0;
1393
1394                         if (cur_exp < SPELL_EXP_BEGINNER)
1395                                 exp_gain += 60;
1396                         else if (cur_exp < SPELL_EXP_SKILLED)
1397                         {
1398                                 if ((current_floor_ptr->dun_level > 4) && ((current_floor_ptr->dun_level + 10) > p_ptr->lev))
1399                                         exp_gain = 8;
1400                         }
1401                         else if (cur_exp < SPELL_EXP_EXPERT)
1402                         {
1403                                 if (((current_floor_ptr->dun_level + 5) > p_ptr->lev) && ((current_floor_ptr->dun_level + 5) > s_ptr->slevel))
1404                                         exp_gain = 2;
1405                         }
1406                         else if ((cur_exp < SPELL_EXP_MASTER) && !increment)
1407                         {
1408                                 if (((current_floor_ptr->dun_level + 5) > p_ptr->lev) && (current_floor_ptr->dun_level > s_ptr->slevel))
1409                                         exp_gain = 1;
1410                         }
1411                         p_ptr->spell_exp[(increment ? 32 : 0) + spell] += exp_gain;
1412                 }
1413         }
1414
1415         take_turn(p_ptr, 100);
1416
1417
1418         /* Over-exert the player */
1419         if (over_exerted)
1420         {
1421                 int oops = need_mana;
1422
1423                 /* No mana left */
1424                 p_ptr->csp = 0;
1425                 p_ptr->csp_frac = 0;
1426
1427                 msg_print(_("精神を集中しすぎて気を失ってしまった!", "You faint from the effort!"));
1428
1429                 /* Hack -- Bypass free action */
1430                 (void)set_paralyzed(p_ptr->paralyzed + randint1(5 * oops + 1));
1431
1432                 switch (realm)
1433                 {
1434                 case REALM_LIFE:
1435                         chg_virtue(V_VITALITY, -10);
1436                         break;
1437                 case REALM_DEATH:
1438                         chg_virtue(V_UNLIFE, -10);
1439                         break;
1440                 case REALM_DAEMON:
1441                         chg_virtue(V_JUSTICE, 10);
1442                         break;
1443                 case REALM_NATURE:
1444                         chg_virtue(V_NATURE, -10);
1445                         break;
1446                 case REALM_CRUSADE:
1447                         chg_virtue(V_JUSTICE, -10);
1448                         break;
1449                 case REALM_HEX:
1450                         chg_virtue(V_COMPASSION, 10);
1451                         break;
1452                 default:
1453                         chg_virtue(V_KNOWLEDGE, -10);
1454                         break;
1455                 }
1456
1457                 /* Damage CON (possibly permanently) */
1458                 if (randint0(100) < 50)
1459                 {
1460                         bool perm = (randint0(100) < 25);
1461
1462                         msg_print(_("体を悪くしてしまった!", "You have damaged your health!"));
1463
1464                         /* Reduce constitution */
1465                         (void)dec_stat(A_CON, 15 + randint1(10), perm);
1466                 }
1467         }
1468
1469         p_ptr->window |= (PW_PLAYER);
1470         p_ptr->window |= (PW_SPELL);
1471 }