OSDN Git Service

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