3 @brief 魔法のインターフェイスと発動 / Purpose: Do everything for each spell
6 2013 Deskull rearranged comment for Doxygen.
15 #include "spells-summon.h"
17 #include "realm-arcane.h"
18 #include "realm-chaos.h"
19 #include "realm-craft.h"
20 #include "realm-crusade.h"
21 #include "realm-daemon.h"
22 #include "realm-death.h"
23 #include "realm-hex.h"
24 #include "realm-hissatsu.h"
25 #include "realm-life.h"
26 #include "realm-nature.h"
27 #include "realm-song.h"
28 #include "realm-sorcery.h"
29 #include "realm-trump.h"
32 #include "player-status.h"
33 #include "player-effects.h"
34 #include "player-skill.h"
35 #include "player-class.h"
36 #include "object-hook.h"
37 #include "cmd-basic.h"
38 #include "view-mainwindow.h"
45 * Zangband uses this array instead of the spell flags table, as there
46 * are 5 realms of magic, each with 4 spellbooks and 8 spells per book -- TY
48 const u32b fake_spell_flags[4] =
58 * 魔法の効果を「キャプション:ダイス+定数値」のフォーマットで出力する / Generate dice info string such as "foo 2d10"
63 * @return フォーマットに従い整形された文字列
65 concptr info_string_dice(concptr str, DICE_NUMBER dice, DICE_SID sides, int base)
69 return format("%s%d", str, base);
73 return format("%s%dd%d", str, dice, sides);
75 /* Dice plus base value */
77 return format("%s%dd%d%+d", str, dice, sides, base);
82 * @brief 魔法によるダメージを出力する / Generate damage-dice info string such as "dam 2d10"
86 * @return フォーマットに従い整形された文字列
88 concptr info_damage(DICE_NUMBER dice, DICE_SID sides, int base)
90 return info_string_dice(_("損傷:", "dam "), dice, sides, base);
94 * @brief 魔法の効果時間を出力する / Generate duration info string such as "dur 20+1d20"
97 * @return フォーマットに従い整形された文字列
99 concptr info_duration(int base, DICE_SID sides)
101 return format(_("期間:%d+1d%d", "dur %d+1d%d"), base, sides);
105 * @brief 魔法の効果範囲を出力する / Generate range info string such as "range 5"
107 * @return フォーマットに従い整形された文字列
109 concptr info_range(POSITION range)
111 return format(_("範囲:%d", "range %d"), range);
115 * @brief 魔法による回復量を出力する / Generate heal info string such as "heal 2d8"
119 * @return フォーマットに従い整形された文字列
121 concptr info_heal(DICE_NUMBER dice, DICE_SID sides, int base)
123 return info_string_dice(_("回復:", "heal "), dice, sides, base);
127 * @brief 魔法効果発動までの遅延ターンを出力する / Generate delay info string such as "delay 15+1d15"
130 * @return フォーマットに従い整形された文字列
132 concptr info_delay(int base, DICE_SID sides)
134 return format(_("遅延:%d+1d%d", "delay %d+1d%d"), base, sides);
139 * @brief 魔法によるダメージを出力する(固定値&複数回処理) / Generate multiple-damage info string such as "dam 25 each"
141 * @return フォーマットに従い整形された文字列
143 concptr info_multi_damage(HIT_POINT dam)
145 return format(_("損傷:各%d", "dam %d each"), dam);
150 * @brief 魔法によるダメージを出力する(ダイスのみ&複数回処理) / Generate multiple-damage-dice info string such as "dam 5d2 each"
153 * @return フォーマットに従い整形された文字列
155 concptr info_multi_damage_dice(DICE_NUMBER dice, DICE_SID sides)
157 return format(_("損傷:各%dd%d", "dam %dd%d each"), dice, sides);
161 * @brief 魔法による一般的な効力値を出力する(固定値) / Generate power info string such as "power 100"
163 * @return フォーマットに従い整形された文字列
165 concptr info_power(int power)
167 return format(_("効力:%d", "power %d"), power);
172 * @brief 魔法による一般的な効力値を出力する(ダイス値) / Generate power info string such as "power 100"
175 * @return フォーマットに従い整形された文字列
178 * Generate power info string such as "power 1d100"
180 concptr info_power_dice(DICE_NUMBER dice, DICE_SID sides)
182 return format(_("効力:%dd%d", "power %dd%d"), dice, sides);
187 * @brief 魔法の効果半径を出力する / Generate radius info string such as "rad 100"
189 * @return フォーマットに従い整形された文字列
191 concptr info_radius(POSITION rad)
193 return format(_("半径:%d", "rad %d"), rad);
198 * @brief 魔法効果の限界重量を出力する / Generate weight info string such as "max wgt 15"
200 * @return フォーマットに従い整形された文字列
202 concptr info_weight(WEIGHT weight)
205 return format("最大重量:%d.%dkg", lbtokg1(weight), lbtokg2(weight));
207 return format("max wgt %d", weight/10);
212 * @brief 魔法が利用可能かどうかを返す /
213 * Determine if a spell is "okay" for the player to cast or study
214 * The spell must be legible, not forgotten, and also, to cast,
215 * it must be known, and to study, it must not be known.
217 * @param learned 使用可能な判定ならばTRUE、学習可能かどうかの判定ならばFALSE
218 * @param study_pray 祈りの学習判定目的ならばTRUE
219 * @param use_realm 魔法領域ID
222 static bool spell_okay(int spell, bool learned, bool study_pray, int use_realm)
224 const magic_type *s_ptr;
226 /* Access the spell */
227 if (!is_magic(use_realm))
229 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
233 s_ptr = &mp_ptr->info[use_realm - 1][spell];
236 /* Spell is illegal */
237 if (s_ptr->slevel > p_ptr->lev) return (FALSE);
239 /* Spell is forgotten */
240 if ((use_realm == p_ptr->realm2) ?
241 (p_ptr->spell_forgotten2 & (1L << spell)) :
242 (p_ptr->spell_forgotten1 & (1L << spell)))
248 if (p_ptr->pclass == CLASS_SORCERER) return (TRUE);
249 if (p_ptr->pclass == CLASS_RED_MAGE) return (TRUE);
251 /* Spell is learned */
252 if ((use_realm == p_ptr->realm2) ?
253 (p_ptr->spell_learned2 & (1L << spell)) :
254 (p_ptr->spell_learned1 & (1L << spell)))
257 return (!study_pray);
260 /* Okay to study, not to cast */
266 * @brief 魔法処理のメインルーチン
267 * @param realm 魔法領域のID
268 * @param spell 各領域の魔法ID
270 * @return 各領域魔法に各種テキストを求めた場合は文字列参照ポインタ、そうでない場合はNULLポインタを返す。
272 concptr do_spell(REALM_IDX realm, SPELL_IDX spell, BIT_FLAGS mode)
276 case REALM_LIFE: return do_life_spell(spell, mode);
277 case REALM_SORCERY: return do_sorcery_spell(spell, mode);
278 case REALM_NATURE: return do_nature_spell(spell, mode);
279 case REALM_CHAOS: return do_chaos_spell(spell, mode);
280 case REALM_DEATH: return do_death_spell(spell, mode);
281 case REALM_TRUMP: return do_trump_spell(spell, mode);
282 case REALM_ARCANE: return do_arcane_spell(spell, mode);
283 case REALM_CRAFT: return do_craft_spell(spell, mode);
284 case REALM_DAEMON: return do_daemon_spell(spell, mode);
285 case REALM_CRUSADE: return do_crusade_spell(spell, mode);
286 case REALM_MUSIC: return do_music_spell(spell, mode);
287 case REALM_HISSATSU: return do_hissatsu_spell(spell, mode);
288 case REALM_HEX: return do_hex_spell(spell, mode);
296 * @brief 領域魔法の閲覧、学習、使用選択するインターフェイス処理
297 * Allow user to choose a spell/prayer from the given book.
298 * @param sn 選択した魔法IDを返す参照ポインタ
299 * @param prompt 魔法を利用する際の動詞表記
300 * @param sval 魔道書のsval
301 * @param learned 閲覧/使用選択ならばTRUE、学習処理ならFALSE
302 * @param use_realm 魔法領域ID
305 * If a valid spell is chosen, saves it in '*sn' and returns TRUE
306 * If the user hits escape, returns FALSE, and set '*sn' to -1
307 * If there are no legal choices, returns FALSE, and sets '*sn' to -2
308 * The "prompt" should be "cast", "recite", or "study"
309 * The "known" should be TRUE for cast/pray, FALSE for study
312 static int get_spell(SPELL_IDX *sn, concptr prompt, OBJECT_SUBTYPE_VALUE sval, bool learned, REALM_IDX use_realm)
315 SPELL_IDX spell = -1;
318 MANA_POINT need_mana;
319 SPELL_IDX spells[64];
320 bool flag, redraw, okay;
322 const magic_type *s_ptr;
329 int menu_line = (use_menu ? 1 : 0);
331 /* Get the spell, if available */
332 if (repeat_pull(&code))
334 *sn = (SPELL_IDX)code;
335 /* Verify the spell */
336 if (spell_okay(*sn, learned, FALSE, use_realm))
343 p = spell_category_name(mp_ptr->spell_book);
346 for (spell = 0; spell < 32; spell++)
348 /* Check for this spell */
349 if ((fake_spell_flags[sval] & (1L << spell)))
351 /* Collect this spell */
352 spells[num++] = spell;
356 /* Assume no usable spells */
359 /* Assume no spells available */
362 /* Check for "okay" spells */
363 for (i = 0; i < num; i++)
365 /* Look for "okay" spells */
366 if (spell_okay(spells[i], learned, FALSE, use_realm)) okay = TRUE;
369 /* No "okay" spells */
370 if (!okay) return (FALSE);
371 if (((use_realm) != p_ptr->realm1) && ((use_realm) != p_ptr->realm2) && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE)) return FALSE;
372 if (((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE)) && !is_magic(use_realm)) return FALSE;
373 if ((p_ptr->pclass == CLASS_RED_MAGE) && ((use_realm) != REALM_ARCANE) && (sval > 1)) return FALSE;
375 /* Assume cancelled */
378 /* Nothing chosen yet */
384 p_ptr->window |= (PW_SPELL);
387 /* Build a prompt (accept all spells) */
389 jverb(prompt, jverb_buf, JVERB_AND);
390 (void)strnfmt(out_val, 78, "(%^s:%c-%c, '*'で一覧, ESCで中断) どの%sを%^sますか? ",
391 p, I2A(0), I2A(num - 1), p, jverb_buf);
393 (void)strnfmt(out_val, 78, "(%^ss %c-%c, *=List, ESC=exit) %^s which %s? ",
394 p, I2A(0), I2A(num - 1), prompt, p);
397 choice = (always_show_list || use_menu) ? ESCAPE : 1;
400 if (choice == ESCAPE) choice = ' ';
401 else if (!get_com(out_val, &choice, TRUE))break;
403 if (use_menu && choice != ' ')
417 menu_line += (num - 1);
439 if (menu_line > num) menu_line -= num;
440 /* Display a list of spells */
441 print_spells(menu_line, spells, num, 1, 15, use_realm);
447 if ((choice == ' ') || (choice == '*') || (choice == '?'))
455 /* Display a list of spells */
456 print_spells(menu_line, spells, num, 1, 15, use_realm);
462 if (use_menu) continue;
475 ask = (isupper(choice));
478 if (ask) choice = (char)tolower(choice);
480 /* Extract request */
481 i = (islower(choice) ? A2I(choice) : -1);
484 /* Totally Illegal */
485 if ((i < 0) || (i >= num))
491 /* Save the spell index */
494 /* Require "okay" spells */
495 if (!spell_okay(spell, learned, FALSE, use_realm))
499 msg_format("その%sを%sことはできません。", p, prompt);
501 msg_format("You may not %s that %s.", prompt, p);
512 /* Access the spell */
513 if (!is_magic(use_realm))
515 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
519 s_ptr = &mp_ptr->info[use_realm - 1][spell];
522 /* Extract mana consumption rate */
523 if (use_realm == REALM_HISSATSU)
525 need_mana = s_ptr->smana;
529 need_mana = mod_need_mana(s_ptr->smana, spell, use_realm);
534 jverb(prompt, jverb_buf, JVERB_AND);
536 (void)strnfmt(tmp_val, 78, "%s(MP%d, 失敗率%d%%)を%sますか? ",
537 do_spell(use_realm, spell, SPELL_NAME), need_mana,
538 spell_chance(spell, use_realm), jverb_buf);
540 (void)strnfmt(tmp_val, 78, "%^s %s (%d mana, %d%% fail)? ",
541 prompt, do_spell(use_realm, spell, SPELL_NAME), need_mana,
542 spell_chance(spell, use_realm));
546 /* Belay that order */
547 if (!get_check(tmp_val)) continue;
554 if (redraw) screen_load();
556 p_ptr->window |= (PW_SPELL);
559 /* Abort if needed */
560 if (!flag) return FALSE;
562 /* Save the choice */
565 repeat_push((COMMAND_CODE)spell);
572 * @brief プレイヤーの職業が練気術師の時、領域魔法と練気術を切り換える処理のインターフェイス
573 * @param browse_only 魔法と技能の閲覧を行うならばTRUE
574 * @return 魔道書を一冊も持っていないならTRUEを返す
576 static void confirm_use_force(bool browse_only)
581 /* Get the item index */
582 if (repeat_pull(&code) && (code == INVEN_FORCE))
584 browse_only ? do_cmd_mind_browse() : do_cmd_mind();
588 /* Show the prompt */
589 prt(_("('w'練気術, ESC) 'w'かESCを押してください。 ", "(w for the Force, ESC) Hit 'w' or ESC. "), 0, 0);
596 if (which == ESCAPE) break;
597 else if (which == 'w')
599 repeat_push(INVEN_FORCE);
604 /* Clear the prompt line */
609 browse_only ? do_cmd_mind_browse() : do_cmd_mind();
615 * @brief プレイヤーの魔法と技能を閲覧するコマンドのメインルーチン /
616 * Peruse the spells/prayers in a book
620 * Note that *all* spells in the book are listed
622 * Note that browsing is allowed while confused or blind,
623 * and in the dark, primarily to allow browsing in stores.
626 void do_cmd_browse(void)
629 OBJECT_SUBTYPE_VALUE sval;
630 REALM_IDX use_realm = 0;
632 SPELL_IDX spell = -1;
635 SPELL_IDX spells[64];
642 /* Warriors are illiterate */
643 if (!(p_ptr->realm1 || p_ptr->realm2) && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE))
645 msg_print(_("本を読むことができない!", "You cannot read books!"));
649 if (p_ptr->special_defense & KATA_MUSOU)
651 set_action(ACTION_NONE);
654 if (p_ptr->pclass == CLASS_FORCETRAINER)
656 if (player_has_no_spellbooks())
658 confirm_use_force(TRUE);
663 /* Restrict choices to "useful" books */
664 if (p_ptr->realm2 == REALM_NONE) item_tester_tval = mp_ptr->spell_book;
665 else item_tester_hook = item_tester_learn_spell;
667 q = _("どの本を読みますか? ", "Browse which book? ");
668 s = _("読める本がない。", "You have no books that you can read.");
670 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR | (p_ptr->pclass == CLASS_FORCETRAINER ? USE_FORCE : 0)));
673 if (item == INVEN_FORCE) /* the_force */
675 do_cmd_mind_browse();
681 /* Access the item's sval */
684 use_realm = tval2realm(o_ptr->tval);
686 /* Track the object kind */
687 object_kind_track(o_ptr->k_idx);
691 for (spell = 0; spell < 32; spell++)
693 /* Check for this spell */
694 if ((fake_spell_flags[sval] & (1L << spell)))
696 /* Collect this spell */
697 spells[num++] = spell;
704 /* Keep browsing spells. Exit browsing on cancel. */
707 /* Ask for a spell, allow cancel */
708 if (!get_spell(&spell, _("読む", "browse"), o_ptr->sval, TRUE, use_realm))
710 /* If cancelled, leave immediately. */
711 if (spell == -1) break;
713 /* Display a list of spells */
714 print_spells(0, spells, num, 1, 15, use_realm);
716 /* Notify that there's nothing to see, and wait. */
717 if (use_realm == REALM_HISSATSU)
718 prt(_("読める技がない。", "No techniques to browse."), 0, 0);
720 prt(_("読める呪文がない。", "No spells to browse."), 0, 0);
728 /* Clear lines, position cursor (really should use strlen here) */
729 Term_erase(14, 14, 255);
730 Term_erase(14, 13, 255);
731 Term_erase(14, 12, 255);
732 Term_erase(14, 11, 255);
734 roff_to_buf(do_spell(use_realm, spell, SPELL_DESC), 62, temp, sizeof(temp));
736 for (j = 0, line = 11; temp[j]; j += 1 + strlen(&temp[j]))
738 prt(&temp[j], line, 15);
746 * @brief プレイヤーの第二魔法領域を変更する /
747 * @param next_realm 変更先の魔法領域ID
750 static void change_realm2(CHARACTER_IDX next_realm)
755 for (i = 0; i < 64; i++)
757 p_ptr->spell_order[j] = p_ptr->spell_order[i];
758 if (p_ptr->spell_order[i] < 32) j++;
761 p_ptr->spell_order[j] = 99;
763 for (i = 32; i < 64; i++)
765 p_ptr->spell_exp[i] = SPELL_EXP_UNSKILLED;
767 p_ptr->spell_learned2 = 0L;
768 p_ptr->spell_worked2 = 0L;
769 p_ptr->spell_forgotten2 = 0L;
771 sprintf(tmp, _("魔法の領域を%sから%sに変更した。", "change magic realm from %s to %s."), realm_names[p_ptr->realm2], realm_names[next_realm]);
772 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, tmp);
773 p_ptr->old_realm |= 1 << (p_ptr->realm2 - 1);
774 p_ptr->realm2 = next_realm;
776 p_ptr->update |= (PU_REORDER);
777 p_ptr->update |= (PU_SPELLS);
780 /* Load an autopick preference file */
781 autopick_load_pref(FALSE);
786 * @brief 魔法を学習するコマンドのメインルーチン /
787 * Study a book to gain a new spell/prayer
790 void do_cmd_study(void)
794 OBJECT_SUBTYPE_VALUE sval;
796 bool learned = FALSE;
798 /* Spells of realm2 will have an increment of +32 */
799 SPELL_IDX spell = -1;
801 concptr p = spell_category_name(mp_ptr->spell_book);
809 msg_print(_("本を読むことができない!", "You cannot read books!"));
813 if (p_ptr->blind || no_lite())
815 msg_print(_("目が見えない!", "You cannot see!"));
819 if (cmd_limit_confused(p_ptr)) return;
821 if (!(p_ptr->new_spells))
823 msg_format(_("新しい%sを覚えることはできない!", "You cannot learn any new %ss!"), p);
827 if (p_ptr->special_defense & KATA_MUSOU)
829 set_action(ACTION_NONE);
833 if (p_ptr->new_spells < 10) {
834 msg_format("あと %d つの%sを学べる。", p_ptr->new_spells, p);
837 msg_format("あと %d 個の%sを学べる。", p_ptr->new_spells, p);
840 msg_format("You can learn %d new %s%s.", p_ptr->new_spells, p,
841 (p_ptr->new_spells == 1 ? "" : "s"));
847 /* Restrict choices to "useful" books */
848 if (p_ptr->realm2 == REALM_NONE) item_tester_tval = mp_ptr->spell_book;
849 else item_tester_hook = item_tester_learn_spell;
851 q = _("どの本から学びますか? ", "Study which book? ");
852 s = _("読める本がない。", "You have no books that you can read.");
854 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR));
857 /* Access the item's sval */
860 if (o_ptr->tval == REALM2_BOOK) increment = 32;
861 else if (o_ptr->tval != REALM1_BOOK)
863 if (!get_check(_("本当に魔法の領域を変更しますか?", "Really, change magic realm? "))) return;
864 change_realm2(tval2realm(o_ptr->tval));
868 /* Track the object kind */
869 object_kind_track(o_ptr->k_idx);
872 /* Mage -- Learn a selected spell */
873 if (mp_ptr->spell_book != TV_LIFE_BOOK)
875 /* Ask for a spell, allow cancel */
876 if (!get_spell(&spell, _("学ぶ", "study"), sval, FALSE, o_ptr->tval - TV_LIFE_BOOK + 1) && (spell == -1)) return;
879 /* Priest -- Learn a random prayer */
886 for (spell = 0; spell < 32; spell++)
888 /* Check spells in the book */
889 if ((fake_spell_flags[sval] & (1L << spell)))
891 /* Skip non "okay" prayers */
892 if (!spell_okay(spell, FALSE, TRUE,
893 (increment ? p_ptr->realm2 : p_ptr->realm1))) continue;
895 /* Hack -- Prepare the randomizer */
898 /* Hack -- Apply the randomizer */
899 if (one_in_(k)) gift = spell;
907 /* Nothing to study */
910 msg_format(_("その本には学ぶべき%sがない。", "You cannot learn any %ss in that book."), p);
916 if (increment) spell += increment;
918 /* Learn the spell */
921 if (p_ptr->spell_learned1 & (1L << spell)) learned = TRUE;
922 else p_ptr->spell_learned1 |= (1L << spell);
926 if (p_ptr->spell_learned2 & (1L << (spell - 32))) learned = TRUE;
927 else p_ptr->spell_learned2 |= (1L << (spell - 32));
932 int max_exp = (spell < 32) ? SPELL_EXP_MASTER : SPELL_EXP_EXPERT;
933 int old_exp = p_ptr->spell_exp[spell];
934 int new_rank = EXP_LEVEL_UNSKILLED;
935 concptr name = do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME);
937 if (old_exp >= max_exp)
939 msg_format(_("その%sは完全に使いこなせるので学ぶ必要はない。", "You don't need to study this %s anymore."), p);
943 if (!get_check(format("%sの%sをさらに学びます。よろしいですか?", name, p)))
945 if (!get_check(format("You will study a %s of %s again. Are you sure? ", p, name)))
950 else if (old_exp >= SPELL_EXP_EXPERT)
952 p_ptr->spell_exp[spell] = SPELL_EXP_MASTER;
953 new_rank = EXP_LEVEL_MASTER;
955 else if (old_exp >= SPELL_EXP_SKILLED)
957 if (spell >= 32) p_ptr->spell_exp[spell] = SPELL_EXP_EXPERT;
958 else p_ptr->spell_exp[spell] += SPELL_EXP_EXPERT - SPELL_EXP_SKILLED;
959 new_rank = EXP_LEVEL_EXPERT;
961 else if (old_exp >= SPELL_EXP_BEGINNER)
963 p_ptr->spell_exp[spell] = SPELL_EXP_SKILLED + (old_exp - SPELL_EXP_BEGINNER) * 2 / 3;
964 new_rank = EXP_LEVEL_SKILLED;
968 p_ptr->spell_exp[spell] = SPELL_EXP_BEGINNER + old_exp / 3;
969 new_rank = EXP_LEVEL_BEGINNER;
971 msg_format(_("%sの熟練度が%sに上がった。", "Your proficiency of %s is now %s rank."), name, exp_level_str[new_rank]);
975 /* Find the next open entry in "p_ptr->spell_order[]" */
976 for (i = 0; i < 64; i++)
978 /* Stop at the first empty space */
979 if (p_ptr->spell_order[i] == 99) break;
982 /* Add the spell to the known list */
983 p_ptr->spell_order[i++] = spell;
985 /* Mention the result */
988 if (mp_ptr->spell_book == TV_MUSIC_BOOK)
990 msg_format("%sを学んだ。",
991 do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME));
995 msg_format("%sの%sを学んだ。",
996 do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME), p);
999 msg_format("You have learned the %s of %s.",
1000 p, do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME));
1004 take_turn(p_ptr, 100);
1006 switch (mp_ptr->spell_book)
1009 chg_virtue(V_FAITH, 1);
1012 chg_virtue(V_UNLIFE, 1);
1014 case TV_NATURE_BOOK:
1015 chg_virtue(V_NATURE, 1);
1018 chg_virtue(V_KNOWLEDGE, 1);
1024 /* One less spell available */
1025 p_ptr->learned_spells++;
1028 p_ptr->update |= (PU_SPELLS);
1029 update_creature(p_ptr);
1031 /* Redraw object recall */
1032 p_ptr->window |= (PW_OBJECT);
1037 * @brief 魔法を詠唱するコマンドのメインルーチン /
1041 void do_cmd_cast(void)
1044 OBJECT_SUBTYPE_VALUE sval;
1049 REALM_IDX use_realm;
1050 MANA_POINT need_mana;
1054 const magic_type *s_ptr;
1057 bool over_exerted = FALSE;
1059 /* Require spell ability */
1060 if (!p_ptr->realm1 && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE))
1062 msg_print(_("呪文を唱えられない!", "You cannot cast spells!"));
1067 if (p_ptr->blind || no_lite())
1069 if (p_ptr->pclass == CLASS_FORCETRAINER) confirm_use_force(FALSE);
1072 msg_print(_("目が見えない!", "You cannot see!"));
1078 if (cmd_limit_confused(p_ptr)) return;
1081 if (p_ptr->realm1 == REALM_HEX)
1083 if (hex_spell_fully())
1086 msg_print(_("これ以上新しい呪文を詠唱することはできない。", "Can not spell new spells more."));
1088 if (p_ptr->lev >= 35) flag = stop_hex_spell();
1093 if (p_ptr->pclass == CLASS_FORCETRAINER)
1095 if (player_has_no_spellbooks())
1097 confirm_use_force(FALSE);
1102 prayer = spell_category_name(mp_ptr->spell_book);
1104 /* Restrict choices to spell books */
1105 item_tester_tval = mp_ptr->spell_book;
1107 q = _("どの呪文書を使いますか? ", "Use which book? ");
1108 s = _("呪文書がない!", "You have no spell books!");
1110 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR | (p_ptr->pclass == CLASS_FORCETRAINER ? USE_FORCE : 0)));
1113 if (item == INVEN_FORCE) /* the_force */
1121 /* Access the item's sval */
1124 if ((p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE) && (o_ptr->tval == REALM2_BOOK)) increment = 32;
1126 /* Track the object kind */
1127 object_kind_track(o_ptr->k_idx);
1130 if ((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE))
1131 realm = o_ptr->tval - TV_LIFE_BOOK + 1;
1132 else if (increment) realm = p_ptr->realm2;
1133 else realm = p_ptr->realm1;
1135 /* Ask for a spell */
1137 if (!get_spell(&spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "詠唱する" : (mp_ptr->spell_book == TV_MUSIC_BOOK) ? "歌う" : "唱える"),
1140 if (spell == -2) msg_format("その本には知っている%sがない。", prayer);
1144 if (!get_spell(&spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1148 msg_format("You don't know any %ss in that book.", prayer);
1154 use_realm = tval2realm(o_ptr->tval);
1157 if (use_realm == REALM_HEX)
1159 if (hex_spelling(spell))
1161 msg_print(_("その呪文はすでに詠唱中だ。", "You are already casting it."));
1166 if (!is_magic(use_realm))
1168 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
1172 s_ptr = &mp_ptr->info[realm - 1][spell];
1175 /* Extract mana consumption rate */
1176 need_mana = mod_need_mana(s_ptr->smana, spell, realm);
1178 /* Verify "dangerous" spells */
1179 if (need_mana > p_ptr->csp)
1181 if (flush_failure) flush();
1185 msg_format("その%sを%sのに十分なマジックポイントがない。", prayer,
1186 ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "詠唱する" : (mp_ptr->spell_book == TV_LIFE_BOOK) ? "歌う" : "唱える"));
1188 msg_format("You do not have enough mana to %s this %s.",
1189 ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1194 if (!over_exert) return;
1197 if (!get_check_strict(_("それでも挑戦しますか? ", "Attempt it anyway? "), CHECK_OKAY_CANCEL)) return;
1200 /* Spell failure chance */
1201 chance = spell_chance(spell, use_realm);
1203 /* Sufficient mana */
1204 if (need_mana <= p_ptr->csp)
1207 p_ptr->csp -= need_mana;
1209 else over_exerted = TRUE;
1210 p_ptr->redraw |= (PR_MANA);
1213 if (randint0(100) < chance)
1215 if (flush_failure) flush();
1217 msg_format(_("%sをうまく唱えられなかった!", "You failed to get the %s off!"), prayer);
1223 if (randint1(100) < chance) chg_virtue(V_VITALITY, -1);
1226 if (randint1(100) < chance) chg_virtue(V_UNLIFE, -1);
1229 if (randint1(100) < chance) chg_virtue(V_NATURE, -1);
1232 if (randint1(100) < chance) chg_virtue(V_JUSTICE, 1);
1235 if (randint1(100) < chance) chg_virtue(V_JUSTICE, -1);
1238 if (randint1(100) < chance) chg_virtue(V_COMPASSION, -1);
1241 if (randint1(100) < chance) chg_virtue(V_KNOWLEDGE, -1);
1245 /* Failure casting may activate some side effect */
1246 do_spell(realm, spell, SPELL_FAIL);
1249 if ((o_ptr->tval == TV_CHAOS_BOOK) && (randint1(100) < spell))
1251 msg_print(_("カオス的な効果を発生した!", "You produce a chaotic effect!"));
1254 else if ((o_ptr->tval == TV_DEATH_BOOK) && (randint1(100) < spell))
1256 if ((sval == 3) && one_in_(2))
1258 sanity_blast(0, TRUE);
1262 msg_print(_("痛い!", "It hurts!"));
1263 take_hit(DAMAGE_LOSELIFE, damroll(o_ptr->sval + 1, 6), _("暗黒魔法の逆流", "a miscast Death spell"), -1);
1265 if ((spell > 15) && one_in_(6) && !p_ptr->hold_exp)
1266 lose_exp(spell * 250);
1269 else if ((o_ptr->tval == TV_MUSIC_BOOK) && (randint1(200) < spell))
1271 msg_print(_("いやな音が響いた", "An infernal sound echoed."));
1272 aggravate_monsters(0);
1274 if (randint1(100) >= chance)
1275 chg_virtue(V_CHANCE, -1);
1281 /* Canceled spells cost neither a current_world_ptr->game_turn nor mana */
1282 if (!do_spell(realm, spell, SPELL_CAST)) return;
1284 if (randint1(100) < chance)
1285 chg_virtue(V_CHANCE, 1);
1287 /* A spell was cast */
1289 (p_ptr->spell_worked2 & (1L << spell)) :
1290 (p_ptr->spell_worked1 & (1L << spell)))
1291 && (p_ptr->pclass != CLASS_SORCERER)
1292 && (p_ptr->pclass != CLASS_RED_MAGE))
1294 int e = s_ptr->sexp;
1296 /* The spell worked */
1297 if (realm == p_ptr->realm1)
1299 p_ptr->spell_worked1 |= (1L << spell);
1303 p_ptr->spell_worked2 |= (1L << spell);
1306 /* Gain experience */
1307 gain_exp(e * s_ptr->slevel);
1309 /* Redraw object recall */
1310 p_ptr->window |= (PW_OBJECT);
1315 chg_virtue(V_TEMPERANCE, 1);
1316 chg_virtue(V_COMPASSION, 1);
1317 chg_virtue(V_VITALITY, 1);
1318 chg_virtue(V_DILIGENCE, 1);
1321 chg_virtue(V_UNLIFE, 1);
1322 chg_virtue(V_JUSTICE, -1);
1323 chg_virtue(V_FAITH, -1);
1324 chg_virtue(V_VITALITY, -1);
1327 chg_virtue(V_JUSTICE, -1);
1328 chg_virtue(V_FAITH, -1);
1329 chg_virtue(V_HONOUR, -1);
1330 chg_virtue(V_TEMPERANCE, -1);
1333 chg_virtue(V_FAITH, 1);
1334 chg_virtue(V_JUSTICE, 1);
1335 chg_virtue(V_SACRIFICE, 1);
1336 chg_virtue(V_HONOUR, 1);
1339 chg_virtue(V_NATURE, 1);
1340 chg_virtue(V_HARMONY, 1);
1343 chg_virtue(V_JUSTICE, -1);
1344 chg_virtue(V_FAITH, -1);
1345 chg_virtue(V_HONOUR, -1);
1346 chg_virtue(V_COMPASSION, -1);
1349 chg_virtue(V_KNOWLEDGE, 1);
1356 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_TEMPERANCE, 1);
1357 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_COMPASSION, 1);
1358 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_VITALITY, 1);
1359 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_DILIGENCE, 1);
1362 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_UNLIFE, 1);
1363 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1364 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1365 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_VITALITY, -1);
1368 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1369 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1370 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, -1);
1371 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_TEMPERANCE, -1);
1374 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, 1);
1375 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, 1);
1376 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_SACRIFICE, 1);
1377 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, 1);
1380 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_NATURE, 1);
1381 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HARMONY, 1);
1384 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1385 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1386 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, -1);
1387 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_COMPASSION, -1);
1390 if (mp_ptr->spell_xtra & MAGIC_GAIN_EXP)
1392 s16b cur_exp = p_ptr->spell_exp[(increment ? 32 : 0) + spell];
1395 if (cur_exp < SPELL_EXP_BEGINNER)
1397 else if (cur_exp < SPELL_EXP_SKILLED)
1399 if ((current_floor_ptr->dun_level > 4) && ((current_floor_ptr->dun_level + 10) > p_ptr->lev))
1402 else if (cur_exp < SPELL_EXP_EXPERT)
1404 if (((current_floor_ptr->dun_level + 5) > p_ptr->lev) && ((current_floor_ptr->dun_level + 5) > s_ptr->slevel))
1407 else if ((cur_exp < SPELL_EXP_MASTER) && !increment)
1409 if (((current_floor_ptr->dun_level + 5) > p_ptr->lev) && (current_floor_ptr->dun_level > s_ptr->slevel))
1412 p_ptr->spell_exp[(increment ? 32 : 0) + spell] += exp_gain;
1416 take_turn(p_ptr, 100);
1419 /* Over-exert the player */
1422 int oops = need_mana;
1426 p_ptr->csp_frac = 0;
1428 msg_print(_("精神を集中しすぎて気を失ってしまった!", "You faint from the effort!"));
1430 /* Hack -- Bypass free action */
1431 (void)set_paralyzed(p_ptr->paralyzed + randint1(5 * oops + 1));
1436 chg_virtue(V_VITALITY, -10);
1439 chg_virtue(V_UNLIFE, -10);
1442 chg_virtue(V_JUSTICE, 10);
1445 chg_virtue(V_NATURE, -10);
1448 chg_virtue(V_JUSTICE, -10);
1451 chg_virtue(V_COMPASSION, 10);
1454 chg_virtue(V_KNOWLEDGE, -10);
1458 /* Damage CON (possibly permanently) */
1459 if (randint0(100) < 50)
1461 bool perm = (randint0(100) < 25);
1463 msg_print(_("体を悪くしてしまった!", "You have damaged your health!"));
1465 /* Reduce constitution */
1466 (void)dec_stat(A_CON, 15 + randint1(10), perm);
1470 p_ptr->window |= (PW_PLAYER);
1471 p_ptr->window |= (PW_SPELL);