3 @brief 魔法のインターフェイスと発動 / Purpose: Do everything for each spell
6 2013 Deskull rearranged comment for Doxygen.
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"
27 #include "player-status.h"
28 #include "object-hook.h"
32 * 魔法の効果を「キャプション:ダイス+定数値」のフォーマットで出力する / Generate dice info string such as "foo 2d10"
37 * @return フォーマットに従い整形された文字列
39 concptr info_string_dice(concptr str, DICE_NUMBER dice, DICE_SID sides, int base)
43 return format("%s%d", str, base);
47 return format("%s%dd%d", str, dice, sides);
49 /* Dice plus base value */
51 return format("%s%dd%d%+d", str, dice, sides, base);
56 * @brief 魔法によるダメージを出力する / Generate damage-dice info string such as "dam 2d10"
60 * @return フォーマットに従い整形された文字列
62 concptr info_damage(DICE_NUMBER dice, DICE_SID sides, int base)
64 return info_string_dice(_("損傷:", "dam "), dice, sides, base);
68 * @brief 魔法の効果時間を出力する / Generate duration info string such as "dur 20+1d20"
71 * @return フォーマットに従い整形された文字列
73 concptr info_duration(int base, DICE_SID sides)
75 return format(_("期間:%d+1d%d", "dur %d+1d%d"), base, sides);
79 * @brief 魔法の効果範囲を出力する / Generate range info string such as "range 5"
81 * @return フォーマットに従い整形された文字列
83 concptr info_range(POSITION range)
85 return format(_("範囲:%d", "range %d"), range);
89 * @brief 魔法による回復量を出力する / Generate heal info string such as "heal 2d8"
93 * @return フォーマットに従い整形された文字列
95 concptr info_heal(DICE_NUMBER dice, DICE_SID sides, int base)
97 return info_string_dice(_("回復:", "heal "), dice, sides, base);
101 * @brief 魔法効果発動までの遅延ターンを出力する / Generate delay info string such as "delay 15+1d15"
104 * @return フォーマットに従い整形された文字列
106 concptr info_delay(int base, DICE_SID sides)
108 return format(_("遅延:%d+1d%d", "delay %d+1d%d"), base, sides);
113 * @brief 魔法によるダメージを出力する(固定値&複数回処理) / Generate multiple-damage info string such as "dam 25 each"
115 * @return フォーマットに従い整形された文字列
117 concptr info_multi_damage(HIT_POINT dam)
119 return format(_("損傷:各%d", "dam %d each"), dam);
124 * @brief 魔法によるダメージを出力する(ダイスのみ&複数回処理) / Generate multiple-damage-dice info string such as "dam 5d2 each"
127 * @return フォーマットに従い整形された文字列
129 concptr info_multi_damage_dice(DICE_NUMBER dice, DICE_SID sides)
131 return format(_("損傷:各%dd%d", "dam %dd%d each"), dice, sides);
135 * @brief 魔法による一般的な効力値を出力する(固定値) / Generate power info string such as "power 100"
137 * @return フォーマットに従い整形された文字列
139 concptr info_power(int power)
141 return format(_("効力:%d", "power %d"), power);
146 * @brief 魔法による一般的な効力値を出力する(ダイス値) / Generate power info string such as "power 100"
149 * @return フォーマットに従い整形された文字列
152 * Generate power info string such as "power 1d100"
154 concptr info_power_dice(DICE_NUMBER dice, DICE_SID sides)
156 return format(_("効力:%dd%d", "power %dd%d"), dice, sides);
161 * @brief 魔法の効果半径を出力する / Generate radius info string such as "rad 100"
163 * @return フォーマットに従い整形された文字列
165 concptr info_radius(POSITION rad)
167 return format(_("半径:%d", "rad %d"), rad);
172 * @brief 魔法効果の限界重量を出力する / Generate weight info string such as "max wgt 15"
174 * @return フォーマットに従い整形された文字列
176 concptr info_weight(WEIGHT weight)
179 return format("最大重量:%d.%dkg", lbtokg1(weight), lbtokg2(weight));
181 return format("max wgt %d", weight/10);
186 * @brief 魔法が利用可能かどうかを返す /
187 * Determine if a spell is "okay" for the player to cast or study
188 * The spell must be legible, not forgotten, and also, to cast,
189 * it must be known, and to study, it must not be known.
191 * @param learned 使用可能な判定ならばTRUE、学習可能かどうかの判定ならばFALSE
192 * @param study_pray 祈りの学習判定目的ならばTRUE
193 * @param use_realm 魔法領域ID
196 static bool spell_okay(int spell, bool learned, bool study_pray, int use_realm)
198 const magic_type *s_ptr;
200 /* Access the spell */
201 if (!is_magic(use_realm))
203 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
207 s_ptr = &mp_ptr->info[use_realm - 1][spell];
210 /* Spell is illegal */
211 if (s_ptr->slevel > p_ptr->lev) return (FALSE);
213 /* Spell is forgotten */
214 if ((use_realm == p_ptr->realm2) ?
215 (p_ptr->spell_forgotten2 & (1L << spell)) :
216 (p_ptr->spell_forgotten1 & (1L << spell)))
222 if (p_ptr->pclass == CLASS_SORCERER) return (TRUE);
223 if (p_ptr->pclass == CLASS_RED_MAGE) return (TRUE);
225 /* Spell is learned */
226 if ((use_realm == p_ptr->realm2) ?
227 (p_ptr->spell_learned2 & (1L << spell)) :
228 (p_ptr->spell_learned1 & (1L << spell)))
231 return (!study_pray);
234 /* Okay to study, not to cast */
240 * @brief 魔法処理のメインルーチン
241 * @param realm 魔法領域のID
242 * @param spell 各領域の魔法ID
244 * @return 各領域魔法に各種テキストを求めた場合は文字列参照ポインタ、そうでない場合はNULLポインタを返す。
246 concptr do_spell(REALM_IDX realm, SPELL_IDX spell, BIT_FLAGS mode)
250 case REALM_LIFE: return do_life_spell(spell, mode);
251 case REALM_SORCERY: return do_sorcery_spell(spell, mode);
252 case REALM_NATURE: return do_nature_spell(spell, mode);
253 case REALM_CHAOS: return do_chaos_spell(spell, mode);
254 case REALM_DEATH: return do_death_spell(spell, mode);
255 case REALM_TRUMP: return do_trump_spell(spell, mode);
256 case REALM_ARCANE: return do_arcane_spell(spell, mode);
257 case REALM_CRAFT: return do_craft_spell(spell, mode);
258 case REALM_DAEMON: return do_daemon_spell(spell, mode);
259 case REALM_CRUSADE: return do_crusade_spell(spell, mode);
260 case REALM_MUSIC: return do_music_spell(spell, mode);
261 case REALM_HISSATSU: return do_hissatsu_spell(spell, mode);
262 case REALM_HEX: return do_hex_spell(spell, mode);
270 * @brief 領域魔法の閲覧、学習、使用選択するインターフェイス処理
271 * Allow user to choose a spell/prayer from the given book.
272 * @param sn 選択した魔法IDを返す参照ポインタ
273 * @param prompt 魔法を利用する際の動詞表記
274 * @param sval 魔道書のsval
275 * @param learned 閲覧/使用選択ならばTRUE、学習処理ならFALSE
276 * @param use_realm 魔法領域ID
279 * If a valid spell is chosen, saves it in '*sn' and returns TRUE
280 * If the user hits escape, returns FALSE, and set '*sn' to -1
281 * If there are no legal choices, returns FALSE, and sets '*sn' to -2
282 * The "prompt" should be "cast", "recite", or "study"
283 * The "known" should be TRUE for cast/pray, FALSE for study
286 static int get_spell(SPELL_IDX *sn, concptr prompt, OBJECT_SUBTYPE_VALUE sval, bool learned, REALM_IDX use_realm)
289 SPELL_IDX spell = -1;
292 MANA_POINT need_mana;
293 SPELL_IDX spells[64];
294 bool flag, redraw, okay;
296 const magic_type *s_ptr;
303 int menu_line = (use_menu ? 1 : 0);
305 /* Get the spell, if available */
306 if (repeat_pull(&code))
308 *sn = (SPELL_IDX)code;
309 /* Verify the spell */
310 if (spell_okay(*sn, learned, FALSE, use_realm))
317 p = spell_category_name(mp_ptr->spell_book);
320 for (spell = 0; spell < 32; spell++)
322 /* Check for this spell */
323 if ((fake_spell_flags[sval] & (1L << spell)))
325 /* Collect this spell */
326 spells[num++] = spell;
330 /* Assume no usable spells */
333 /* Assume no spells available */
336 /* Check for "okay" spells */
337 for (i = 0; i < num; i++)
339 /* Look for "okay" spells */
340 if (spell_okay(spells[i], learned, FALSE, use_realm)) okay = TRUE;
343 /* No "okay" spells */
344 if (!okay) return (FALSE);
345 if (((use_realm) != p_ptr->realm1) && ((use_realm) != p_ptr->realm2) && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE)) return FALSE;
346 if (((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE)) && !is_magic(use_realm)) return FALSE;
347 if ((p_ptr->pclass == CLASS_RED_MAGE) && ((use_realm) != REALM_ARCANE) && (sval > 1)) return FALSE;
349 /* Assume cancelled */
352 /* Nothing chosen yet */
358 p_ptr->window |= (PW_SPELL);
361 /* Build a prompt (accept all spells) */
363 jverb(prompt, jverb_buf, JVERB_AND);
364 (void)strnfmt(out_val, 78, "(%^s:%c-%c, '*'で一覧, ESCで中断) どの%sを%^sますか? ",
365 p, I2A(0), I2A(num - 1), p, jverb_buf);
367 (void)strnfmt(out_val, 78, "(%^ss %c-%c, *=List, ESC=exit) %^s which %s? ",
368 p, I2A(0), I2A(num - 1), prompt, p);
371 choice = (always_show_list || use_menu) ? ESCAPE : 1;
374 if (choice == ESCAPE) choice = ' ';
375 else if (!get_com(out_val, &choice, TRUE))break;
377 if (use_menu && choice != ' ')
391 menu_line += (num - 1);
413 if (menu_line > num) menu_line -= num;
414 /* Display a list of spells */
415 print_spells(menu_line, spells, num, 1, 15, use_realm);
421 if ((choice == ' ') || (choice == '*') || (choice == '?'))
429 /* Display a list of spells */
430 print_spells(menu_line, spells, num, 1, 15, use_realm);
436 if (use_menu) continue;
449 ask = (isupper(choice));
452 if (ask) choice = (char)tolower(choice);
454 /* Extract request */
455 i = (islower(choice) ? A2I(choice) : -1);
458 /* Totally Illegal */
459 if ((i < 0) || (i >= num))
465 /* Save the spell index */
468 /* Require "okay" spells */
469 if (!spell_okay(spell, learned, FALSE, use_realm))
473 msg_format("その%sを%sことはできません。", p, prompt);
475 msg_format("You may not %s that %s.", prompt, p);
486 /* Access the spell */
487 if (!is_magic(use_realm))
489 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
493 s_ptr = &mp_ptr->info[use_realm - 1][spell];
496 /* Extract mana consumption rate */
497 if (use_realm == REALM_HISSATSU)
499 need_mana = s_ptr->smana;
503 need_mana = mod_need_mana(s_ptr->smana, spell, use_realm);
508 jverb(prompt, jverb_buf, JVERB_AND);
510 (void)strnfmt(tmp_val, 78, "%s(MP%d, 失敗率%d%%)を%sますか? ",
511 do_spell(use_realm, spell, SPELL_NAME), need_mana,
512 spell_chance(spell, use_realm), jverb_buf);
514 (void)strnfmt(tmp_val, 78, "%^s %s (%d mana, %d%% fail)? ",
515 prompt, do_spell(use_realm, spell, SPELL_NAME), need_mana,
516 spell_chance(spell, use_realm));
520 /* Belay that order */
521 if (!get_check(tmp_val)) continue;
528 if (redraw) screen_load();
530 p_ptr->window |= (PW_SPELL);
533 /* Abort if needed */
534 if (!flag) return FALSE;
536 /* Save the choice */
539 repeat_push((COMMAND_CODE)spell);
546 * @brief プレイヤーの職業が練気術師の時、領域魔法と練気術を切り換える処理のインターフェイス
547 * @param browse_only 魔法と技能の閲覧を行うならばTRUE
548 * @return 魔道書を一冊も持っていないならTRUEを返す
550 static void confirm_use_force(bool browse_only)
555 /* Get the item index */
556 if (repeat_pull(&code) && (code == INVEN_FORCE))
558 browse_only ? do_cmd_mind_browse() : do_cmd_mind();
562 /* Show the prompt */
563 prt(_("('w'練気術, ESC) 'w'かESCを押してください。 ", "(w for the Force, ESC) Hit 'w' or ESC. "), 0, 0);
570 if (which == ESCAPE) break;
571 else if (which == 'w')
573 repeat_push(INVEN_FORCE);
578 /* Clear the prompt line */
583 browse_only ? do_cmd_mind_browse() : do_cmd_mind();
589 * @brief プレイヤーの魔法と技能を閲覧するコマンドのメインルーチン /
590 * Peruse the spells/prayers in a book
594 * Note that *all* spells in the book are listed
596 * Note that browsing is allowed while confused or blind,
597 * and in the dark, primarily to allow browsing in stores.
600 void do_cmd_browse(void)
603 OBJECT_SUBTYPE_VALUE sval;
604 REALM_IDX use_realm = 0;
606 SPELL_IDX spell = -1;
609 SPELL_IDX spells[64];
616 /* Warriors are illiterate */
617 if (!(p_ptr->realm1 || p_ptr->realm2) && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE))
619 msg_print(_("本を読むことができない!", "You cannot read books!"));
623 if (p_ptr->special_defense & KATA_MUSOU)
625 set_action(ACTION_NONE);
628 if (p_ptr->pclass == CLASS_FORCETRAINER)
630 if (player_has_no_spellbooks())
632 confirm_use_force(TRUE);
637 /* Restrict choices to "useful" books */
638 if (p_ptr->realm2 == REALM_NONE) item_tester_tval = mp_ptr->spell_book;
639 else item_tester_hook = item_tester_learn_spell;
641 q = _("どの本を読みますか? ", "Browse which book? ");
642 s = _("読める本がない。", "You have no books that you can read.");
644 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR | (p_ptr->pclass == CLASS_FORCETRAINER ? USE_FORCE : 0)));
647 if (item == INVEN_FORCE) /* the_force */
649 do_cmd_mind_browse();
655 /* Access the item's sval */
658 use_realm = tval2realm(o_ptr->tval);
660 /* Track the object kind */
661 object_kind_track(o_ptr->k_idx);
665 for (spell = 0; spell < 32; spell++)
667 /* Check for this spell */
668 if ((fake_spell_flags[sval] & (1L << spell)))
670 /* Collect this spell */
671 spells[num++] = spell;
678 /* Keep browsing spells. Exit browsing on cancel. */
681 /* Ask for a spell, allow cancel */
682 if (!get_spell(&spell, _("読む", "browse"), o_ptr->sval, TRUE, use_realm))
684 /* If cancelled, leave immediately. */
685 if (spell == -1) break;
687 /* Display a list of spells */
688 print_spells(0, spells, num, 1, 15, use_realm);
690 /* Notify that there's nothing to see, and wait. */
691 if (use_realm == REALM_HISSATSU)
692 prt(_("読める技がない。", "No techniques to browse."), 0, 0);
694 prt(_("読める呪文がない。", "No spells to browse."), 0, 0);
702 /* Clear lines, position cursor (really should use strlen here) */
703 Term_erase(14, 14, 255);
704 Term_erase(14, 13, 255);
705 Term_erase(14, 12, 255);
706 Term_erase(14, 11, 255);
708 roff_to_buf(do_spell(use_realm, spell, SPELL_DESC), 62, temp, sizeof(temp));
710 for (j = 0, line = 11; temp[j]; j += 1 + strlen(&temp[j]))
712 prt(&temp[j], line, 15);
720 * @brief プレイヤーの第二魔法領域を変更する /
721 * @param next_realm 変更先の魔法領域ID
724 static void change_realm2(CHARACTER_IDX next_realm)
729 for (i = 0; i < 64; i++)
731 p_ptr->spell_order[j] = p_ptr->spell_order[i];
732 if (p_ptr->spell_order[i] < 32) j++;
735 p_ptr->spell_order[j] = 99;
737 for (i = 32; i < 64; i++)
739 p_ptr->spell_exp[i] = SPELL_EXP_UNSKILLED;
741 p_ptr->spell_learned2 = 0L;
742 p_ptr->spell_worked2 = 0L;
743 p_ptr->spell_forgotten2 = 0L;
745 sprintf(tmp, _("魔法の領域を%sから%sに変更した。", "change magic realm from %s to %s."), realm_names[p_ptr->realm2], realm_names[next_realm]);
746 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, tmp);
747 p_ptr->old_realm |= 1 << (p_ptr->realm2 - 1);
748 p_ptr->realm2 = next_realm;
750 p_ptr->update |= (PU_REORDER);
751 p_ptr->update |= (PU_SPELLS);
754 /* Load an autopick preference file */
755 autopick_load_pref(FALSE);
760 * @brief 魔法を学習するコマンドのメインルーチン /
761 * Study a book to gain a new spell/prayer
764 void do_cmd_study(void)
768 OBJECT_SUBTYPE_VALUE sval;
770 bool learned = FALSE;
772 /* Spells of realm2 will have an increment of +32 */
773 SPELL_IDX spell = -1;
775 concptr p = spell_category_name(mp_ptr->spell_book);
783 msg_print(_("本を読むことができない!", "You cannot read books!"));
787 if (p_ptr->blind || no_lite())
789 msg_print(_("目が見えない!", "You cannot see!"));
793 if (cmd_limit_confused(p_ptr)) return;
795 if (!(p_ptr->new_spells))
797 msg_format(_("新しい%sを覚えることはできない!", "You cannot learn any new %ss!"), p);
801 if (p_ptr->special_defense & KATA_MUSOU)
803 set_action(ACTION_NONE);
807 if (p_ptr->new_spells < 10) {
808 msg_format("あと %d つの%sを学べる。", p_ptr->new_spells, p);
811 msg_format("あと %d 個の%sを学べる。", p_ptr->new_spells, p);
814 msg_format("You can learn %d new %s%s.", p_ptr->new_spells, p,
815 (p_ptr->new_spells == 1 ? "" : "s"));
821 /* Restrict choices to "useful" books */
822 if (p_ptr->realm2 == REALM_NONE) item_tester_tval = mp_ptr->spell_book;
823 else item_tester_hook = item_tester_learn_spell;
825 q = _("どの本から学びますか? ", "Study which book? ");
826 s = _("読める本がない。", "You have no books that you can read.");
828 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR));
831 /* Access the item's sval */
834 if (o_ptr->tval == REALM2_BOOK) increment = 32;
835 else if (o_ptr->tval != REALM1_BOOK)
837 if (!get_check(_("本当に魔法の領域を変更しますか?", "Really, change magic realm? "))) return;
838 change_realm2(tval2realm(o_ptr->tval));
842 /* Track the object kind */
843 object_kind_track(o_ptr->k_idx);
846 /* Mage -- Learn a selected spell */
847 if (mp_ptr->spell_book != TV_LIFE_BOOK)
849 /* Ask for a spell, allow cancel */
850 if (!get_spell(&spell, _("学ぶ", "study"), sval, FALSE, o_ptr->tval - TV_LIFE_BOOK + 1) && (spell == -1)) return;
853 /* Priest -- Learn a random prayer */
860 for (spell = 0; spell < 32; spell++)
862 /* Check spells in the book */
863 if ((fake_spell_flags[sval] & (1L << spell)))
865 /* Skip non "okay" prayers */
866 if (!spell_okay(spell, FALSE, TRUE,
867 (increment ? p_ptr->realm2 : p_ptr->realm1))) continue;
869 /* Hack -- Prepare the randomizer */
872 /* Hack -- Apply the randomizer */
873 if (one_in_(k)) gift = spell;
881 /* Nothing to study */
884 msg_format(_("その本には学ぶべき%sがない。", "You cannot learn any %ss in that book."), p);
890 if (increment) spell += increment;
892 /* Learn the spell */
895 if (p_ptr->spell_learned1 & (1L << spell)) learned = TRUE;
896 else p_ptr->spell_learned1 |= (1L << spell);
900 if (p_ptr->spell_learned2 & (1L << (spell - 32))) learned = TRUE;
901 else p_ptr->spell_learned2 |= (1L << (spell - 32));
906 int max_exp = (spell < 32) ? SPELL_EXP_MASTER : SPELL_EXP_EXPERT;
907 int old_exp = p_ptr->spell_exp[spell];
908 int new_rank = EXP_LEVEL_UNSKILLED;
909 concptr name = do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME);
911 if (old_exp >= max_exp)
913 msg_format(_("その%sは完全に使いこなせるので学ぶ必要はない。", "You don't need to study this %s anymore."), p);
917 if (!get_check(format("%sの%sをさらに学びます。よろしいですか?", name, p)))
919 if (!get_check(format("You will study a %s of %s again. Are you sure? ", p, name)))
924 else if (old_exp >= SPELL_EXP_EXPERT)
926 p_ptr->spell_exp[spell] = SPELL_EXP_MASTER;
927 new_rank = EXP_LEVEL_MASTER;
929 else if (old_exp >= SPELL_EXP_SKILLED)
931 if (spell >= 32) p_ptr->spell_exp[spell] = SPELL_EXP_EXPERT;
932 else p_ptr->spell_exp[spell] += SPELL_EXP_EXPERT - SPELL_EXP_SKILLED;
933 new_rank = EXP_LEVEL_EXPERT;
935 else if (old_exp >= SPELL_EXP_BEGINNER)
937 p_ptr->spell_exp[spell] = SPELL_EXP_SKILLED + (old_exp - SPELL_EXP_BEGINNER) * 2 / 3;
938 new_rank = EXP_LEVEL_SKILLED;
942 p_ptr->spell_exp[spell] = SPELL_EXP_BEGINNER + old_exp / 3;
943 new_rank = EXP_LEVEL_BEGINNER;
945 msg_format(_("%sの熟練度が%sに上がった。", "Your proficiency of %s is now %s rank."), name, exp_level_str[new_rank]);
949 /* Find the next open entry in "p_ptr->spell_order[]" */
950 for (i = 0; i < 64; i++)
952 /* Stop at the first empty space */
953 if (p_ptr->spell_order[i] == 99) break;
956 /* Add the spell to the known list */
957 p_ptr->spell_order[i++] = spell;
959 /* Mention the result */
962 if (mp_ptr->spell_book == TV_MUSIC_BOOK)
964 msg_format("%sを学んだ。",
965 do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME));
969 msg_format("%sの%sを学んだ。",
970 do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME), p);
973 msg_format("You have learned the %s of %s.",
974 p, do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME));
978 take_turn(p_ptr, 100);
980 switch (mp_ptr->spell_book)
983 chg_virtue(V_FAITH, 1);
986 chg_virtue(V_UNLIFE, 1);
989 chg_virtue(V_NATURE, 1);
992 chg_virtue(V_KNOWLEDGE, 1);
998 /* One less spell available */
999 p_ptr->learned_spells++;
1002 p_ptr->update |= (PU_SPELLS);
1003 update_creature(p_ptr);
1005 /* Redraw object recall */
1006 p_ptr->window |= (PW_OBJECT);
1011 * @brief 魔法を詠唱するコマンドのメインルーチン /
1015 void do_cmd_cast(void)
1018 OBJECT_SUBTYPE_VALUE sval;
1023 REALM_IDX use_realm;
1024 MANA_POINT need_mana;
1028 const magic_type *s_ptr;
1031 bool over_exerted = FALSE;
1033 /* Require spell ability */
1034 if (!p_ptr->realm1 && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE))
1036 msg_print(_("呪文を唱えられない!", "You cannot cast spells!"));
1041 if (p_ptr->blind || no_lite())
1043 if (p_ptr->pclass == CLASS_FORCETRAINER) confirm_use_force(FALSE);
1046 msg_print(_("目が見えない!", "You cannot see!"));
1052 if (cmd_limit_confused(p_ptr)) return;
1055 if (p_ptr->realm1 == REALM_HEX)
1057 if (hex_spell_fully())
1060 msg_print(_("これ以上新しい呪文を詠唱することはできない。", "Can not spell new spells more."));
1062 if (p_ptr->lev >= 35) flag = stop_hex_spell();
1067 if (p_ptr->pclass == CLASS_FORCETRAINER)
1069 if (player_has_no_spellbooks())
1071 confirm_use_force(FALSE);
1076 prayer = spell_category_name(mp_ptr->spell_book);
1078 /* Restrict choices to spell books */
1079 item_tester_tval = mp_ptr->spell_book;
1081 q = _("どの呪文書を使いますか? ", "Use which book? ");
1082 s = _("呪文書がない!", "You have no spell books!");
1084 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR | (p_ptr->pclass == CLASS_FORCETRAINER ? USE_FORCE : 0)));
1087 if (item == INVEN_FORCE) /* the_force */
1095 /* Access the item's sval */
1098 if ((p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE) && (o_ptr->tval == REALM2_BOOK)) increment = 32;
1100 /* Track the object kind */
1101 object_kind_track(o_ptr->k_idx);
1104 if ((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE))
1105 realm = o_ptr->tval - TV_LIFE_BOOK + 1;
1106 else if (increment) realm = p_ptr->realm2;
1107 else realm = p_ptr->realm1;
1109 /* Ask for a spell */
1111 if (!get_spell(&spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "詠唱する" : (mp_ptr->spell_book == TV_MUSIC_BOOK) ? "歌う" : "唱える"),
1114 if (spell == -2) msg_format("その本には知っている%sがない。", prayer);
1118 if (!get_spell(&spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1122 msg_format("You don't know any %ss in that book.", prayer);
1128 use_realm = tval2realm(o_ptr->tval);
1131 if (use_realm == REALM_HEX)
1133 if (hex_spelling(spell))
1135 msg_print(_("その呪文はすでに詠唱中だ。", "You are already casting it."));
1140 if (!is_magic(use_realm))
1142 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
1146 s_ptr = &mp_ptr->info[realm - 1][spell];
1149 /* Extract mana consumption rate */
1150 need_mana = mod_need_mana(s_ptr->smana, spell, realm);
1152 /* Verify "dangerous" spells */
1153 if (need_mana > p_ptr->csp)
1155 if (flush_failure) flush();
1159 msg_format("その%sを%sのに十分なマジックポイントがない。", prayer,
1160 ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "詠唱する" : (mp_ptr->spell_book == TV_LIFE_BOOK) ? "歌う" : "唱える"));
1162 msg_format("You do not have enough mana to %s this %s.",
1163 ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1168 if (!over_exert) return;
1171 if (!get_check_strict(_("それでも挑戦しますか? ", "Attempt it anyway? "), CHECK_OKAY_CANCEL)) return;
1174 /* Spell failure chance */
1175 chance = spell_chance(spell, use_realm);
1177 /* Sufficient mana */
1178 if (need_mana <= p_ptr->csp)
1181 p_ptr->csp -= need_mana;
1183 else over_exerted = TRUE;
1184 p_ptr->redraw |= (PR_MANA);
1187 if (randint0(100) < chance)
1189 if (flush_failure) flush();
1191 msg_format(_("%sをうまく唱えられなかった!", "You failed to get the %s off!"), prayer);
1197 if (randint1(100) < chance) chg_virtue(V_VITALITY, -1);
1200 if (randint1(100) < chance) chg_virtue(V_UNLIFE, -1);
1203 if (randint1(100) < chance) chg_virtue(V_NATURE, -1);
1206 if (randint1(100) < chance) chg_virtue(V_JUSTICE, 1);
1209 if (randint1(100) < chance) chg_virtue(V_JUSTICE, -1);
1212 if (randint1(100) < chance) chg_virtue(V_COMPASSION, -1);
1215 if (randint1(100) < chance) chg_virtue(V_KNOWLEDGE, -1);
1219 /* Failure casting may activate some side effect */
1220 do_spell(realm, spell, SPELL_FAIL);
1223 if ((o_ptr->tval == TV_CHAOS_BOOK) && (randint1(100) < spell))
1225 msg_print(_("カオス的な効果を発生した!", "You produce a chaotic effect!"));
1228 else if ((o_ptr->tval == TV_DEATH_BOOK) && (randint1(100) < spell))
1230 if ((sval == 3) && one_in_(2))
1232 sanity_blast(0, TRUE);
1236 msg_print(_("痛い!", "It hurts!"));
1237 take_hit(DAMAGE_LOSELIFE, damroll(o_ptr->sval + 1, 6), _("暗黒魔法の逆流", "a miscast Death spell"), -1);
1239 if ((spell > 15) && one_in_(6) && !p_ptr->hold_exp)
1240 lose_exp(spell * 250);
1243 else if ((o_ptr->tval == TV_MUSIC_BOOK) && (randint1(200) < spell))
1245 msg_print(_("いやな音が響いた", "An infernal sound echoed."));
1246 aggravate_monsters(0);
1248 if (randint1(100) >= chance)
1249 chg_virtue(V_CHANCE, -1);
1255 /* Canceled spells cost neither a current_world_ptr->game_turn nor mana */
1256 if (!do_spell(realm, spell, SPELL_CAST)) return;
1258 if (randint1(100) < chance)
1259 chg_virtue(V_CHANCE, 1);
1261 /* A spell was cast */
1263 (p_ptr->spell_worked2 & (1L << spell)) :
1264 (p_ptr->spell_worked1 & (1L << spell)))
1265 && (p_ptr->pclass != CLASS_SORCERER)
1266 && (p_ptr->pclass != CLASS_RED_MAGE))
1268 int e = s_ptr->sexp;
1270 /* The spell worked */
1271 if (realm == p_ptr->realm1)
1273 p_ptr->spell_worked1 |= (1L << spell);
1277 p_ptr->spell_worked2 |= (1L << spell);
1280 /* Gain experience */
1281 gain_exp(e * s_ptr->slevel);
1283 /* Redraw object recall */
1284 p_ptr->window |= (PW_OBJECT);
1289 chg_virtue(V_TEMPERANCE, 1);
1290 chg_virtue(V_COMPASSION, 1);
1291 chg_virtue(V_VITALITY, 1);
1292 chg_virtue(V_DILIGENCE, 1);
1295 chg_virtue(V_UNLIFE, 1);
1296 chg_virtue(V_JUSTICE, -1);
1297 chg_virtue(V_FAITH, -1);
1298 chg_virtue(V_VITALITY, -1);
1301 chg_virtue(V_JUSTICE, -1);
1302 chg_virtue(V_FAITH, -1);
1303 chg_virtue(V_HONOUR, -1);
1304 chg_virtue(V_TEMPERANCE, -1);
1307 chg_virtue(V_FAITH, 1);
1308 chg_virtue(V_JUSTICE, 1);
1309 chg_virtue(V_SACRIFICE, 1);
1310 chg_virtue(V_HONOUR, 1);
1313 chg_virtue(V_NATURE, 1);
1314 chg_virtue(V_HARMONY, 1);
1317 chg_virtue(V_JUSTICE, -1);
1318 chg_virtue(V_FAITH, -1);
1319 chg_virtue(V_HONOUR, -1);
1320 chg_virtue(V_COMPASSION, -1);
1323 chg_virtue(V_KNOWLEDGE, 1);
1330 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_TEMPERANCE, 1);
1331 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_COMPASSION, 1);
1332 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_VITALITY, 1);
1333 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_DILIGENCE, 1);
1336 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_UNLIFE, 1);
1337 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1338 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1339 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_VITALITY, -1);
1342 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1343 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1344 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, -1);
1345 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_TEMPERANCE, -1);
1348 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, 1);
1349 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, 1);
1350 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_SACRIFICE, 1);
1351 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, 1);
1354 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_NATURE, 1);
1355 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HARMONY, 1);
1358 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1359 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1360 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, -1);
1361 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_COMPASSION, -1);
1364 if (mp_ptr->spell_xtra & MAGIC_GAIN_EXP)
1366 s16b cur_exp = p_ptr->spell_exp[(increment ? 32 : 0) + spell];
1369 if (cur_exp < SPELL_EXP_BEGINNER)
1371 else if (cur_exp < SPELL_EXP_SKILLED)
1373 if ((current_floor_ptr->dun_level > 4) && ((current_floor_ptr->dun_level + 10) > p_ptr->lev))
1376 else if (cur_exp < SPELL_EXP_EXPERT)
1378 if (((current_floor_ptr->dun_level + 5) > p_ptr->lev) && ((current_floor_ptr->dun_level + 5) > s_ptr->slevel))
1381 else if ((cur_exp < SPELL_EXP_MASTER) && !increment)
1383 if (((current_floor_ptr->dun_level + 5) > p_ptr->lev) && (current_floor_ptr->dun_level > s_ptr->slevel))
1386 p_ptr->spell_exp[(increment ? 32 : 0) + spell] += exp_gain;
1390 take_turn(p_ptr, 100);
1393 /* Over-exert the player */
1396 int oops = need_mana;
1400 p_ptr->csp_frac = 0;
1402 msg_print(_("精神を集中しすぎて気を失ってしまった!", "You faint from the effort!"));
1404 /* Hack -- Bypass free action */
1405 (void)set_paralyzed(p_ptr->paralyzed + randint1(5 * oops + 1));
1410 chg_virtue(V_VITALITY, -10);
1413 chg_virtue(V_UNLIFE, -10);
1416 chg_virtue(V_JUSTICE, 10);
1419 chg_virtue(V_NATURE, -10);
1422 chg_virtue(V_JUSTICE, -10);
1425 chg_virtue(V_COMPASSION, 10);
1428 chg_virtue(V_KNOWLEDGE, -10);
1432 /* Damage CON (possibly permanently) */
1433 if (randint0(100) < 50)
1435 bool perm = (randint0(100) < 25);
1437 msg_print(_("体を悪くしてしまった!", "You have damaged your health!"));
1439 /* Reduce constitution */
1440 (void)dec_stat(A_CON, 15 + randint1(10), perm);
1444 p_ptr->window |= (PW_PLAYER);
1445 p_ptr->window |= (PW_SPELL);