OSDN Git Service

[Refactor] #38997 gain_exp() に player_type * 引数を追加.
[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 "core.h"
11 #include "util.h"
12 #include "cmd-spell.h"
13
14 #include "cmd-dump.h"
15 #include "selfinfo.h"
16 #include "spells.h"
17 #include "spells-summon.h"
18 #include "realm.h"
19 #include "realm-arcane.h"
20 #include "realm-chaos.h"
21 #include "realm-craft.h"
22 #include "realm-crusade.h"
23 #include "realm-daemon.h"
24 #include "realm-death.h"
25 #include "realm-hex.h"
26 #include "realm-hissatsu.h"
27 #include "realm-life.h"
28 #include "realm-nature.h"
29 #include "realm-song.h"
30 #include "realm-sorcery.h"
31 #include "realm-trump.h"
32 #include "mind.h"
33 #include "avatar.h"
34 #include "player-damage.h"
35 #include "player-status.h"
36 #include "player-effects.h"
37 #include "player-skill.h"
38 #include "player-class.h"
39 #include "object-hook.h"
40 #include "cmd-basic.h"
41 #include "view-mainwindow.h"
42 #include "floor.h"
43 #include "autopick.h"
44 #include "japanese.h"
45
46  /*!
47   * 魔法領域フラグ管理テーブル /
48   * Zangband uses this array instead of the spell flags table, as there
49   * are 5 realms of magic, each with 4 spellbooks and 8 spells per book -- TY
50   */
51 const u32b fake_spell_flags[4] =
52 {
53         0x000000ff,
54         0x0000ff00,
55         0x00ff0000,
56         0xff000000
57 };
58
59 /*!
60  * @brief
61  * 魔法の効果を「キャプション:ダイス+定数値」のフォーマットで出力する / Generate dice info string such as "foo 2d10"
62  * @param str キャプション
63  * @param dice ダイス数
64  * @param sides ダイス目
65  * @param base 固定値
66  * @return フォーマットに従い整形された文字列
67  */
68 concptr info_string_dice(concptr str, DICE_NUMBER dice, DICE_SID sides, int base)
69 {
70         /* Fix value */
71         if (!dice)
72                 return format("%s%d", str, base);
73
74         /* Dice only */
75         else if (!base)
76                 return format("%s%dd%d", str, dice, sides);
77
78         /* Dice plus base value */
79         else
80                 return format("%s%dd%d%+d", str, dice, sides, base);
81 }
82
83
84 /*!
85  * @brief 魔法によるダメージを出力する / Generate damage-dice info string such as "dam 2d10"
86  * @param dice ダイス数
87  * @param sides ダイス目
88  * @param base 固定値
89  * @return フォーマットに従い整形された文字列
90  */
91 concptr info_damage(DICE_NUMBER dice, DICE_SID sides, int base)
92 {
93         return info_string_dice(_("損傷:", "dam "), dice, sides, base);
94 }
95
96 /*!
97  * @brief 魔法の効果時間を出力する / Generate duration info string such as "dur 20+1d20"
98  * @param base 固定値
99  * @param sides ダイス目
100  * @return フォーマットに従い整形された文字列
101  */
102 concptr info_duration(int base, DICE_SID sides)
103 {
104         return format(_("期間:%d+1d%d", "dur %d+1d%d"), base, sides);
105 }
106
107 /*!
108  * @brief 魔法の効果範囲を出力する / Generate range info string such as "range 5"
109  * @param range 効果範囲
110  * @return フォーマットに従い整形された文字列
111  */
112 concptr info_range(POSITION range)
113 {
114         return format(_("範囲:%d", "range %d"), range);
115 }
116
117 /*!
118  * @brief 魔法による回復量を出力する / Generate heal info string such as "heal 2d8"
119  * @param dice ダイス数
120  * @param sides ダイス目
121  * @param base 固定値
122  * @return フォーマットに従い整形された文字列
123  */
124 concptr info_heal(DICE_NUMBER dice, DICE_SID sides, int base)
125 {
126         return info_string_dice(_("回復:", "heal "), dice, sides, base);
127 }
128
129 /*!
130  * @brief 魔法効果発動までの遅延ターンを出力する / Generate delay info string such as "delay 15+1d15"
131  * @param base 固定値
132  * @param sides ダイス目
133  * @return フォーマットに従い整形された文字列
134  */
135 concptr info_delay(int base, DICE_SID sides)
136 {
137         return format(_("遅延:%d+1d%d", "delay %d+1d%d"), base, sides);
138 }
139
140
141 /*!
142  * @brief 魔法によるダメージを出力する(固定値&複数回処理) / Generate multiple-damage info string such as "dam 25 each"
143  * @param dam 固定値
144  * @return フォーマットに従い整形された文字列
145  */
146 concptr info_multi_damage(HIT_POINT dam)
147 {
148         return format(_("損傷:各%d", "dam %d each"), dam);
149 }
150
151
152 /*!
153  * @brief 魔法によるダメージを出力する(ダイスのみ&複数回処理) / Generate multiple-damage-dice info string such as "dam 5d2 each"
154  * @param dice ダイス数
155  * @param sides ダイス目
156  * @return フォーマットに従い整形された文字列
157  */
158 concptr info_multi_damage_dice(DICE_NUMBER dice, DICE_SID sides)
159 {
160         return format(_("損傷:各%dd%d", "dam %dd%d each"), dice, sides);
161 }
162
163 /*!
164  * @brief 魔法による一般的な効力値を出力する(固定値) / Generate power info string such as "power 100"
165  * @param power 固定値
166  * @return フォーマットに従い整形された文字列
167  */
168 concptr info_power(int power)
169 {
170         return format(_("効力:%d", "power %d"), power);
171 }
172
173
174 /*!
175  * @brief 魔法による一般的な効力値を出力する(ダイス値) / Generate power info string such as "power 100"
176  * @param dice ダイス数
177  * @param sides ダイス目
178  * @return フォーマットに従い整形された文字列
179  */
180 /*
181  * Generate power info string such as "power 1d100"
182  */
183 concptr info_power_dice(DICE_NUMBER dice, DICE_SID sides)
184 {
185         return format(_("効力:%dd%d", "power %dd%d"), dice, sides);
186 }
187
188
189 /*!
190  * @brief 魔法の効果半径を出力する / Generate radius info string such as "rad 100"
191  * @param rad 効果半径
192  * @return フォーマットに従い整形された文字列
193  */
194 concptr info_radius(POSITION rad)
195 {
196         return format(_("半径:%d", "rad %d"), rad);
197 }
198
199
200 /*!
201  * @brief 魔法効果の限界重量を出力する / Generate weight info string such as "max wgt 15"
202  * @param weight 最大重量
203  * @return フォーマットに従い整形された文字列
204  */
205 concptr info_weight(WEIGHT weight)
206 {
207 #ifdef JP
208         return format("最大重量:%d.%dkg", lbtokg1(weight), lbtokg2(weight));
209 #else
210         return format("max wgt %d", weight/10);
211 #endif
212 }
213
214 /*!
215  * @brief 魔法が利用可能かどうかを返す /
216  * Determine if a spell is "okay" for the player to cast or study
217  * The spell must be legible, not forgotten, and also, to cast,
218  * it must be known, and to study, it must not be known.
219  * @param spell 呪文ID
220  * @param learned 使用可能な判定ならばTRUE、学習可能かどうかの判定ならばFALSE
221  * @param study_pray 祈りの学習判定目的ならばTRUE
222  * @param use_realm 魔法領域ID
223  * @return 失敗率(%)
224  */
225 static bool spell_okay(int spell, bool learned, bool study_pray, int use_realm)
226 {
227         const magic_type *s_ptr;
228
229         /* Access the spell */
230         if (!is_magic(use_realm))
231         {
232                 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
233         }
234         else
235         {
236                 s_ptr = &mp_ptr->info[use_realm - 1][spell];
237         }
238
239         /* Spell is illegal */
240         if (s_ptr->slevel > p_ptr->lev) return (FALSE);
241
242         /* Spell is forgotten */
243         if ((use_realm == p_ptr->realm2) ?
244                 (p_ptr->spell_forgotten2 & (1L << spell)) :
245                 (p_ptr->spell_forgotten1 & (1L << spell)))
246         {
247                 /* Never okay */
248                 return (FALSE);
249         }
250
251         if (p_ptr->pclass == CLASS_SORCERER) return (TRUE);
252         if (p_ptr->pclass == CLASS_RED_MAGE) return (TRUE);
253
254         /* Spell is learned */
255         if ((use_realm == p_ptr->realm2) ?
256                 (p_ptr->spell_learned2 & (1L << spell)) :
257                 (p_ptr->spell_learned1 & (1L << spell)))
258         {
259                 /* Always true */
260                 return (!study_pray);
261         }
262
263         /* Okay to study, not to cast */
264         return (!learned);
265 }
266
267
268 /*!
269  * @brief 魔法処理のメインルーチン
270  * @param realm 魔法領域のID
271  * @param spell 各領域の魔法ID
272  * @param mode 求める処理
273  * @return 各領域魔法に各種テキストを求めた場合は文字列参照ポインタ、そうでない場合はNULLポインタを返す。
274  */
275 concptr do_spell(REALM_IDX realm, SPELL_IDX spell, BIT_FLAGS mode)
276 {
277         switch (realm)
278         {
279         case REALM_LIFE:     return do_life_spell(spell, mode);
280         case REALM_SORCERY:  return do_sorcery_spell(spell, mode);
281         case REALM_NATURE:   return do_nature_spell(spell, mode);
282         case REALM_CHAOS:    return do_chaos_spell(spell, mode);
283         case REALM_DEATH:    return do_death_spell(spell, mode);
284         case REALM_TRUMP:    return do_trump_spell(spell, mode);
285         case REALM_ARCANE:   return do_arcane_spell(spell, mode);
286         case REALM_CRAFT:    return do_craft_spell(spell, mode);
287         case REALM_DAEMON:   return do_daemon_spell(spell, mode);
288         case REALM_CRUSADE:  return do_crusade_spell(spell, mode);
289         case REALM_MUSIC:    return do_music_spell(spell, mode);
290         case REALM_HISSATSU: return do_hissatsu_spell(spell, mode);
291         case REALM_HEX:      return do_hex_spell(spell, mode);
292         }
293
294         return NULL;
295 }
296
297
298 /*!
299  * @brief 領域魔法の閲覧、学習、使用選択するインターフェイス処理
300  * Allow user to choose a spell/prayer from the given book.
301  * @param sn 選択した魔法IDを返す参照ポインタ
302  * @param prompt 魔法を利用する際の動詞表記
303  * @param sval 魔道書のsval
304  * @param learned 閲覧/使用選択ならばTRUE、学習処理ならFALSE
305  * @param use_realm 魔法領域ID
306  * @return
307  * <pre>
308  * If a valid spell is chosen, saves it in '*sn' and returns TRUE
309  * If the user hits escape, returns FALSE, and set '*sn' to -1
310  * If there are no legal choices, returns FALSE, and sets '*sn' to -2
311  * The "prompt" should be "cast", "recite", or "study"
312  * The "known" should be TRUE for cast/pray, FALSE for study
313  * </pre>
314  */
315 static int get_spell(SPELL_IDX *sn, concptr prompt, OBJECT_SUBTYPE_VALUE sval, bool learned, REALM_IDX use_realm)
316 {
317         int i;
318         SPELL_IDX spell = -1;
319         int num = 0;
320         int ask = TRUE;
321         MANA_POINT need_mana;
322         SPELL_IDX spells[64];
323         bool flag, redraw, okay;
324         char choice;
325         const magic_type  *s_ptr;
326         char out_val[160];
327         concptr p;
328         COMMAND_CODE code;
329 #ifdef JP
330         char jverb_buf[128];
331 #endif
332         int menu_line = (use_menu ? 1 : 0);
333
334         /* Get the spell, if available */
335         if (repeat_pull(&code))
336         {
337                 *sn = (SPELL_IDX)code;
338                 /* Verify the spell */
339                 if (spell_okay(*sn, learned, FALSE, use_realm))
340                 {
341                         /* Success */
342                         return (TRUE);
343                 }
344         }
345
346         p = spell_category_name(mp_ptr->spell_book);
347
348         /* Extract spells */
349         for (spell = 0; spell < 32; spell++)
350         {
351                 /* Check for this spell */
352                 if ((fake_spell_flags[sval] & (1L << spell)))
353                 {
354                         /* Collect this spell */
355                         spells[num++] = spell;
356                 }
357         }
358
359         /* Assume no usable spells */
360         okay = FALSE;
361
362         /* Assume no spells available */
363         (*sn) = -2;
364
365         /* Check for "okay" spells */
366         for (i = 0; i < num; i++)
367         {
368                 /* Look for "okay" spells */
369                 if (spell_okay(spells[i], learned, FALSE, use_realm)) okay = TRUE;
370         }
371
372         /* No "okay" spells */
373         if (!okay) return (FALSE);
374         if (((use_realm) != p_ptr->realm1) && ((use_realm) != p_ptr->realm2) && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE)) return FALSE;
375         if (((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE)) && !is_magic(use_realm)) return FALSE;
376         if ((p_ptr->pclass == CLASS_RED_MAGE) && ((use_realm) != REALM_ARCANE) && (sval > 1)) return FALSE;
377
378         /* Assume cancelled */
379         *sn = (-1);
380
381         /* Nothing chosen yet */
382         flag = FALSE;
383
384         /* No redraw yet */
385         redraw = FALSE;
386
387         p_ptr->window |= (PW_SPELL);
388         handle_stuff();
389
390         /* Build a prompt (accept all spells) */
391 #ifdef JP
392         jverb(prompt, jverb_buf, JVERB_AND);
393         (void)strnfmt(out_val, 78, "(%^s:%c-%c, '*'で一覧, ESCで中断) どの%sを%^sますか? ",
394                 p, I2A(0), I2A(num - 1), p, jverb_buf);
395 #else
396         (void)strnfmt(out_val, 78, "(%^ss %c-%c, *=List, ESC=exit) %^s which %s? ",
397                 p, I2A(0), I2A(num - 1), prompt, p);
398 #endif
399
400         choice = (always_show_list || use_menu) ? ESCAPE : 1;
401         while (!flag)
402         {
403                 if (choice == ESCAPE) choice = ' ';
404                 else if (!get_com(out_val, &choice, TRUE))break;
405
406                 if (use_menu && choice != ' ')
407                 {
408                         switch (choice)
409                         {
410                         case '0':
411                         {
412                                 screen_load();
413                                 return FALSE;
414                         }
415
416                         case '8':
417                         case 'k':
418                         case 'K':
419                         {
420                                 menu_line += (num - 1);
421                                 break;
422                         }
423
424                         case '2':
425                         case 'j':
426                         case 'J':
427                         {
428                                 menu_line++;
429                                 break;
430                         }
431
432                         case 'x':
433                         case 'X':
434                         case '\r':
435                         case '\n':
436                         {
437                                 i = menu_line - 1;
438                                 ask = FALSE;
439                                 break;
440                         }
441                         }
442                         if (menu_line > num) menu_line -= num;
443                         /* Display a list of spells */
444                         print_spells(menu_line, spells, num, 1, 15, use_realm);
445                         if (ask) continue;
446                 }
447                 else
448                 {
449                         /* Request redraw */
450                         if ((choice == ' ') || (choice == '*') || (choice == '?'))
451                         {
452                                 /* Show the list */
453                                 if (!redraw)
454                                 {
455                                         redraw = TRUE;
456                                         screen_save();
457
458                                         /* Display a list of spells */
459                                         print_spells(menu_line, spells, num, 1, 15, use_realm);
460                                 }
461
462                                 /* Hide the list */
463                                 else
464                                 {
465                                         if (use_menu) continue;
466
467                                         /* Hide list */
468                                         redraw = FALSE;
469                                         screen_load();
470                                 }
471
472                                 /* Redo asking */
473                                 continue;
474                         }
475
476
477                         /* Note verify */
478                         ask = (isupper(choice));
479
480                         /* Lowercase */
481                         if (ask) choice = (char)tolower(choice);
482
483                         /* Extract request */
484                         i = (islower(choice) ? A2I(choice) : -1);
485                 }
486
487                 /* Totally Illegal */
488                 if ((i < 0) || (i >= num))
489                 {
490                         bell();
491                         continue;
492                 }
493
494                 /* Save the spell index */
495                 spell = spells[i];
496
497                 /* Require "okay" spells */
498                 if (!spell_okay(spell, learned, FALSE, use_realm))
499                 {
500                         bell();
501 #ifdef JP
502                         msg_format("その%sを%sことはできません。", p, prompt);
503 #else
504                         msg_format("You may not %s that %s.", prompt, p);
505 #endif
506
507                         continue;
508                 }
509
510                 /* Verify it */
511                 if (ask)
512                 {
513                         char tmp_val[160];
514
515                         /* Access the spell */
516                         if (!is_magic(use_realm))
517                         {
518                                 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
519                         }
520                         else
521                         {
522                                 s_ptr = &mp_ptr->info[use_realm - 1][spell];
523                         }
524
525                         /* Extract mana consumption rate */
526                         if (use_realm == REALM_HISSATSU)
527                         {
528                                 need_mana = s_ptr->smana;
529                         }
530                         else
531                         {
532                                 need_mana = mod_need_mana(s_ptr->smana, spell, use_realm);
533                         }
534
535                         /* Prompt */
536 #ifdef JP
537                         jverb(prompt, jverb_buf, JVERB_AND);
538                         /* 英日切り替え機能に対応 */
539                         (void)strnfmt(tmp_val, 78, "%s(MP%d, 失敗率%d%%)を%sますか? ",
540                                 do_spell(use_realm, spell, SPELL_NAME), need_mana,
541                                 spell_chance(spell, use_realm), jverb_buf);
542 #else
543                         (void)strnfmt(tmp_val, 78, "%^s %s (%d mana, %d%% fail)? ",
544                                 prompt, do_spell(use_realm, spell, SPELL_NAME), need_mana,
545                                 spell_chance(spell, use_realm));
546 #endif
547
548
549                         /* Belay that order */
550                         if (!get_check(tmp_val)) continue;
551                 }
552
553                 /* Stop the loop */
554                 flag = TRUE;
555         }
556
557         if (redraw) screen_load();
558
559         p_ptr->window |= (PW_SPELL);
560         handle_stuff();
561
562         /* Abort if needed */
563         if (!flag) return FALSE;
564
565         /* Save the choice */
566         (*sn) = spell;
567
568         repeat_push((COMMAND_CODE)spell);
569
570         /* Success */
571         return TRUE;
572 }
573
574 /*!
575  * @brief プレイヤーの職業が練気術師の時、領域魔法と練気術を切り換える処理のインターフェイス
576  * @param browse_only 魔法と技能の閲覧を行うならばTRUE
577  * @return 魔道書を一冊も持っていないならTRUEを返す
578  */
579 static void confirm_use_force(bool browse_only)
580 {
581         char which;
582         COMMAND_CODE code;
583
584         /* Get the item index */
585         if (repeat_pull(&code) && (code == INVEN_FORCE))
586         {
587                 browse_only ? do_cmd_mind_browse() : do_cmd_mind();
588                 return;
589         }
590
591         /* Show the prompt */
592         prt(_("('w'練気術, ESC) 'w'かESCを押してください。 ", "(w for the Force, ESC) Hit 'w' or ESC. "), 0, 0);
593
594         while (1)
595         {
596                 /* Get a key */
597                 which = inkey();
598
599                 if (which == ESCAPE) break;
600                 else if (which == 'w')
601                 {
602                         repeat_push(INVEN_FORCE);
603                         break;
604                 }
605         }
606
607         /* Clear the prompt line */
608         prt("", 0, 0);
609
610         if (which == 'w')
611         {
612                 browse_only ? do_cmd_mind_browse() : do_cmd_mind();
613         }
614 }
615
616
617 /*!
618  * @brief プレイヤーの魔法と技能を閲覧するコマンドのメインルーチン /
619  * Peruse the spells/prayers in a book
620  * @return なし
621  * @details
622  * <pre>
623  * Note that *all* spells in the book are listed
624  *
625  * Note that browsing is allowed while confused or blind,
626  * and in the dark, primarily to allow browsing in stores.
627  * </pre>
628  */
629 void do_cmd_browse(void)
630 {
631         OBJECT_IDX item;
632         OBJECT_SUBTYPE_VALUE sval;
633         REALM_IDX use_realm = 0;
634         int j, line;
635         SPELL_IDX spell = -1;
636         int num = 0;
637
638         SPELL_IDX spells[64];
639         char temp[62 * 4];
640
641         object_type *o_ptr;
642
643         concptr q, s;
644
645         /* Warriors are illiterate */
646         if (!(p_ptr->realm1 || p_ptr->realm2) && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE))
647         {
648                 msg_print(_("本を読むことができない!", "You cannot read books!"));
649                 return;
650         }
651
652         if (p_ptr->special_defense & KATA_MUSOU)
653         {
654                 set_action(ACTION_NONE);
655         }
656
657         if (p_ptr->pclass == CLASS_FORCETRAINER)
658         {
659                 if (player_has_no_spellbooks())
660                 {
661                         confirm_use_force(TRUE);
662                         return;
663                 }
664         }
665
666         /* Restrict choices to "useful" books */
667         if (p_ptr->realm2 == REALM_NONE) item_tester_tval = mp_ptr->spell_book;
668         else item_tester_hook = item_tester_learn_spell;
669
670         q = _("どの本を読みますか? ", "Browse which book? ");
671         s = _("読める本がない。", "You have no books that you can read.");
672
673         o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR | (p_ptr->pclass == CLASS_FORCETRAINER ? USE_FORCE : 0)), item_tester_tval);
674         if (!o_ptr)
675         {
676                 if (item == INVEN_FORCE) /* the_force */
677                 {
678                         do_cmd_mind_browse();
679                         return;
680                 }
681                 return;
682         }
683
684         /* Access the item's sval */
685         sval = o_ptr->sval;
686
687         use_realm = tval2realm(o_ptr->tval);
688
689         /* Track the object kind */
690         object_kind_track(o_ptr->k_idx);
691         handle_stuff();
692
693         /* Extract spells */
694         for (spell = 0; spell < 32; spell++)
695         {
696                 /* Check for this spell */
697                 if ((fake_spell_flags[sval] & (1L << spell)))
698                 {
699                         /* Collect this spell */
700                         spells[num++] = spell;
701                 }
702         }
703
704         screen_save();
705         prt("", 0, 0);
706
707         /* Keep browsing spells.  Exit browsing on cancel. */
708         while (TRUE)
709         {
710                 /* Ask for a spell, allow cancel */
711                 if (!get_spell(&spell, _("読む", "browse"), o_ptr->sval, TRUE, use_realm))
712                 {
713                         /* If cancelled, leave immediately. */
714                         if (spell == -1) break;
715
716                         /* Display a list of spells */
717                         print_spells(0, spells, num, 1, 15, use_realm);
718
719                         /* Notify that there's nothing to see, and wait. */
720                         if (use_realm == REALM_HISSATSU)
721                                 prt(_("読める技がない。", "No techniques to browse."), 0, 0);
722                         else
723                                 prt(_("読める呪文がない。", "No spells to browse."), 0, 0);
724                         (void)inkey();
725
726                         screen_load();
727
728                         return;
729                 }
730
731                 /* Clear lines, position cursor  (really should use strlen here) */
732                 Term_erase(14, 14, 255);
733                 Term_erase(14, 13, 255);
734                 Term_erase(14, 12, 255);
735                 Term_erase(14, 11, 255);
736
737                 roff_to_buf(do_spell(use_realm, spell, SPELL_DESC), 62, temp, sizeof(temp));
738
739                 for (j = 0, line = 11; temp[j]; j += 1 + strlen(&temp[j]))
740                 {
741                         prt(&temp[j], line, 15);
742                         line++;
743                 }
744         }
745         screen_load();
746 }
747
748 /*!
749  * @brief プレイヤーの第二魔法領域を変更する /
750  * @param next_realm 変更先の魔法領域ID
751  * @return なし
752  */
753 static void change_realm2(CHARACTER_IDX next_realm)
754 {
755         int i, j = 0;
756         char tmp[80];
757
758         for (i = 0; i < 64; i++)
759         {
760                 p_ptr->spell_order[j] = p_ptr->spell_order[i];
761                 if (p_ptr->spell_order[i] < 32) j++;
762         }
763         for (; j < 64; j++)
764                 p_ptr->spell_order[j] = 99;
765
766         for (i = 32; i < 64; i++)
767         {
768                 p_ptr->spell_exp[i] = SPELL_EXP_UNSKILLED;
769         }
770         p_ptr->spell_learned2 = 0L;
771         p_ptr->spell_worked2 = 0L;
772         p_ptr->spell_forgotten2 = 0L;
773
774         sprintf(tmp, _("魔法の領域を%sから%sに変更した。", "change magic realm from %s to %s."), realm_names[p_ptr->realm2], realm_names[next_realm]);
775         do_cmd_write_nikki(NIKKI_BUNSHOU, 0, tmp);
776         p_ptr->old_realm |= 1 << (p_ptr->realm2 - 1);
777         p_ptr->realm2 = next_realm;
778
779         p_ptr->update |= (PU_REORDER);
780         p_ptr->update |= (PU_SPELLS);
781         handle_stuff();
782
783         /* Load an autopick preference file */
784         autopick_load_pref(FALSE);
785 }
786
787
788 /*!
789  * @brief 魔法を学習するコマンドのメインルーチン /
790  * Study a book to gain a new spell/prayer
791  * @return なし
792  */
793 void do_cmd_study(void)
794 {
795         int     i;
796         OBJECT_IDX item;
797         OBJECT_SUBTYPE_VALUE sval;
798         int     increment = 0;
799         bool    learned = FALSE;
800
801         /* Spells of realm2 will have an increment of +32 */
802         SPELL_IDX spell = -1;
803
804         concptr p = spell_category_name(mp_ptr->spell_book);
805
806         object_type *o_ptr;
807
808         concptr q, s;
809
810         if (!p_ptr->realm1)
811         {
812                 msg_print(_("本を読むことができない!", "You cannot read books!"));
813                 return;
814         }
815
816         if (p_ptr->blind || no_lite())
817         {
818                 msg_print(_("目が見えない!", "You cannot see!"));
819                 return;
820         }
821
822         if (cmd_limit_confused(p_ptr)) return;
823
824         if (!(p_ptr->new_spells))
825         {
826                 msg_format(_("新しい%sを覚えることはできない!", "You cannot learn any new %ss!"), p);
827                 return;
828         }
829
830         if (p_ptr->special_defense & KATA_MUSOU)
831         {
832                 set_action(ACTION_NONE);
833         }
834
835 #ifdef JP
836         if (p_ptr->new_spells < 10) {
837                 msg_format("あと %d つの%sを学べる。", p_ptr->new_spells, p);
838         }
839         else {
840                 msg_format("あと %d 個の%sを学べる。", p_ptr->new_spells, p);
841         }
842 #else
843         msg_format("You can learn %d new %s%s.", p_ptr->new_spells, p,
844                 (p_ptr->new_spells == 1 ? "" : "s"));
845 #endif
846
847         msg_print(NULL);
848
849
850         /* Restrict choices to "useful" books */
851         if (p_ptr->realm2 == REALM_NONE) item_tester_tval = mp_ptr->spell_book;
852         else item_tester_hook = item_tester_learn_spell;
853
854         q = _("どの本から学びますか? ", "Study which book? ");
855         s = _("読める本がない。", "You have no books that you can read.");
856
857         o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR), item_tester_tval);
858         if (!o_ptr) return;
859
860         /* Access the item's sval */
861         sval = o_ptr->sval;
862
863         if (o_ptr->tval == REALM2_BOOK) increment = 32;
864         else if (o_ptr->tval != REALM1_BOOK)
865         {
866                 if (!get_check(_("本当に魔法の領域を変更しますか?", "Really, change magic realm? "))) return;
867                 change_realm2(tval2realm(o_ptr->tval));
868                 increment = 32;
869         }
870
871         /* Track the object kind */
872         object_kind_track(o_ptr->k_idx);
873         handle_stuff();
874
875         /* Mage -- Learn a selected spell */
876         if (mp_ptr->spell_book != TV_LIFE_BOOK)
877         {
878                 /* Ask for a spell, allow cancel */
879                 if (!get_spell(&spell, _("学ぶ", "study"), sval, FALSE, o_ptr->tval - TV_LIFE_BOOK + 1) && (spell == -1)) return;
880         }
881
882         /* Priest -- Learn a random prayer */
883         else
884         {
885                 int k = 0;
886                 int gift = -1;
887
888                 /* Extract spells */
889                 for (spell = 0; spell < 32; spell++)
890                 {
891                         /* Check spells in the book */
892                         if ((fake_spell_flags[sval] & (1L << spell)))
893                         {
894                                 /* Skip non "okay" prayers */
895                                 if (!spell_okay(spell, FALSE, TRUE,
896                                         (increment ? p_ptr->realm2 : p_ptr->realm1))) continue;
897
898                                 /* Hack -- Prepare the randomizer */
899                                 k++;
900
901                                 /* Hack -- Apply the randomizer */
902                                 if (one_in_(k)) gift = spell;
903                         }
904                 }
905
906                 /* Accept gift */
907                 spell = gift;
908         }
909
910         /* Nothing to study */
911         if (spell < 0)
912         {
913                 msg_format(_("その本には学ぶべき%sがない。", "You cannot learn any %ss in that book."), p);
914
915                 /* Abort */
916                 return;
917         }
918
919         if (increment) spell += increment;
920
921         /* Learn the spell */
922         if (spell < 32)
923         {
924                 if (p_ptr->spell_learned1 & (1L << spell)) learned = TRUE;
925                 else p_ptr->spell_learned1 |= (1L << spell);
926         }
927         else
928         {
929                 if (p_ptr->spell_learned2 & (1L << (spell - 32))) learned = TRUE;
930                 else p_ptr->spell_learned2 |= (1L << (spell - 32));
931         }
932
933         if (learned)
934         {
935                 int max_exp = (spell < 32) ? SPELL_EXP_MASTER : SPELL_EXP_EXPERT;
936                 int old_exp = p_ptr->spell_exp[spell];
937                 int new_rank = EXP_LEVEL_UNSKILLED;
938                 concptr name = do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME);
939
940                 if (old_exp >= max_exp)
941                 {
942                         msg_format(_("その%sは完全に使いこなせるので学ぶ必要はない。", "You don't need to study this %s anymore."), p);
943                         return;
944                 }
945 #ifdef JP
946                 if (!get_check(format("%sの%sをさらに学びます。よろしいですか?", name, p)))
947 #else
948                 if (!get_check(format("You will study a %s of %s again. Are you sure? ", p, name)))
949 #endif
950                 {
951                         return;
952                 }
953                 else if (old_exp >= SPELL_EXP_EXPERT)
954                 {
955                         p_ptr->spell_exp[spell] = SPELL_EXP_MASTER;
956                         new_rank = EXP_LEVEL_MASTER;
957                 }
958                 else if (old_exp >= SPELL_EXP_SKILLED)
959                 {
960                         if (spell >= 32) p_ptr->spell_exp[spell] = SPELL_EXP_EXPERT;
961                         else p_ptr->spell_exp[spell] += SPELL_EXP_EXPERT - SPELL_EXP_SKILLED;
962                         new_rank = EXP_LEVEL_EXPERT;
963                 }
964                 else if (old_exp >= SPELL_EXP_BEGINNER)
965                 {
966                         p_ptr->spell_exp[spell] = SPELL_EXP_SKILLED + (old_exp - SPELL_EXP_BEGINNER) * 2 / 3;
967                         new_rank = EXP_LEVEL_SKILLED;
968                 }
969                 else
970                 {
971                         p_ptr->spell_exp[spell] = SPELL_EXP_BEGINNER + old_exp / 3;
972                         new_rank = EXP_LEVEL_BEGINNER;
973                 }
974                 msg_format(_("%sの熟練度が%sに上がった。", "Your proficiency of %s is now %s rank."), name, exp_level_str[new_rank]);
975         }
976         else
977         {
978                 /* Find the next open entry in "p_ptr->spell_order[]" */
979                 for (i = 0; i < 64; i++)
980                 {
981                         /* Stop at the first empty space */
982                         if (p_ptr->spell_order[i] == 99) break;
983                 }
984
985                 /* Add the spell to the known list */
986                 p_ptr->spell_order[i++] = spell;
987
988                 /* Mention the result */
989 #ifdef JP
990                 /* 英日切り替え機能に対応 */
991                 if (mp_ptr->spell_book == TV_MUSIC_BOOK)
992                 {
993                         msg_format("%sを学んだ。",
994                                 do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME));
995                 }
996                 else
997                 {
998                         msg_format("%sの%sを学んだ。",
999                                 do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME), p);
1000                 }
1001 #else
1002                 msg_format("You have learned the %s of %s.",
1003                         p, do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME));
1004 #endif
1005         }
1006
1007         take_turn(p_ptr, 100);
1008
1009         switch (mp_ptr->spell_book)
1010         {
1011         case TV_LIFE_BOOK:
1012                 chg_virtue(V_FAITH, 1);
1013                 break;
1014         case TV_DEATH_BOOK:
1015                 chg_virtue(V_UNLIFE, 1);
1016                 break;
1017         case TV_NATURE_BOOK:
1018                 chg_virtue(V_NATURE, 1);
1019                 break;
1020         default:
1021                 chg_virtue(V_KNOWLEDGE, 1);
1022                 break;
1023         }
1024
1025         sound(SOUND_STUDY);
1026
1027         /* One less spell available */
1028         p_ptr->learned_spells++;
1029
1030         /* Update Study */
1031         p_ptr->update |= (PU_SPELLS);
1032         update_creature(p_ptr);
1033
1034         /* Redraw object recall */
1035         p_ptr->window |= (PW_OBJECT);
1036 }
1037
1038
1039 /*!
1040  * @brief 魔法を詠唱するコマンドのメインルーチン /
1041  * Cast a spell
1042  * @return なし
1043  */
1044 void do_cmd_cast(void)
1045 {
1046         OBJECT_IDX item;
1047         OBJECT_SUBTYPE_VALUE sval;
1048         SPELL_IDX spell;
1049         REALM_IDX realm;
1050         int     chance;
1051         int     increment = 0;
1052         REALM_IDX use_realm;
1053         MANA_POINT need_mana;
1054
1055         concptr prayer;
1056         object_type *o_ptr;
1057         const magic_type *s_ptr;
1058         concptr q, s;
1059
1060         bool over_exerted = FALSE;
1061
1062         /* Require spell ability */
1063         if (!p_ptr->realm1 && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE))
1064         {
1065                 msg_print(_("呪文を唱えられない!", "You cannot cast spells!"));
1066                 return;
1067         }
1068
1069         /* Require lite */
1070         if (p_ptr->blind || no_lite())
1071         {
1072                 if (p_ptr->pclass == CLASS_FORCETRAINER) confirm_use_force(FALSE);
1073                 else
1074                 {
1075                         msg_print(_("目が見えない!", "You cannot see!"));
1076                         flush();
1077                 }
1078                 return;
1079         }
1080
1081         if (cmd_limit_confused(p_ptr)) return;
1082
1083         /* Hex */
1084         if (p_ptr->realm1 == REALM_HEX)
1085         {
1086                 if (hex_spell_fully())
1087                 {
1088                         bool flag = FALSE;
1089                         msg_print(_("これ以上新しい呪文を詠唱することはできない。", "Can not spell new spells more."));
1090                         flush();
1091                         if (p_ptr->lev >= 35) flag = stop_hex_spell();
1092                         if (!flag) return;
1093                 }
1094         }
1095
1096         if (p_ptr->pclass == CLASS_FORCETRAINER)
1097         {
1098                 if (player_has_no_spellbooks())
1099                 {
1100                         confirm_use_force(FALSE);
1101                         return;
1102                 }
1103         }
1104
1105         prayer = spell_category_name(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)), mp_ptr->spell_book);
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(p_ptr, 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(p_ptr, 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, 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(p_ptr, A_CON, 15 + randint1(10), perm);
1467                 }
1468         }
1469
1470         p_ptr->window |= (PW_PLAYER);
1471         p_ptr->window |= (PW_SPELL);
1472 }