OSDN Git Service

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