OSDN Git Service

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