OSDN Git Service

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