OSDN Git Service

[Fix] #40051 item_tester_tvalのリセットを追加して呪文学習後のアイテム処理ミスを修正. / Add reset of item_tester_...
[hengbandforosx/hengbandosx.git] / src / cmd / cmd-spell.c
index 901e061..1b628f3 100644 (file)
 #include "selfinfo.h"
 #include "spells.h"
 #include "spells-summon.h"
-#include "realm.h"
-#include "realm-arcane.h"
-#include "realm-chaos.h"
-#include "realm-craft.h"
-#include "realm-crusade.h"
-#include "realm-daemon.h"
-#include "realm-death.h"
 #include "realm-hex.h"
-#include "realm-hissatsu.h"
-#include "realm-life.h"
-#include "realm-nature.h"
-#include "realm-song.h"
-#include "realm-sorcery.h"
-#include "realm-trump.h"
 #include "mind.h"
 #include "avatar.h"
 #include "player-damage.h"
@@ -238,7 +225,7 @@ static bool spell_okay(player_type *caster_ptr, int spell, bool learned, bool st
        }
 
        /* Spell is illegal */
-       if (s_ptr->slevel > caster_ptr->lev) return (FALSE);
+       if (s_ptr->slevel > caster_ptr->lev) return FALSE;
 
        /* Spell is forgotten */
        if ((use_realm == caster_ptr->realm2) ?
@@ -246,11 +233,11 @@ static bool spell_okay(player_type *caster_ptr, int spell, bool learned, bool st
                (caster_ptr->spell_forgotten1 & (1L << spell)))
        {
                /* Never okay */
-               return (FALSE);
+               return FALSE;
        }
 
-       if (caster_ptr->pclass == CLASS_SORCERER) return (TRUE);
-       if (caster_ptr->pclass == CLASS_RED_MAGE) return (TRUE);
+       if (caster_ptr->pclass == CLASS_SORCERER) return TRUE;
+       if (caster_ptr->pclass == CLASS_RED_MAGE) return TRUE;
 
        /* Spell is learned */
        if ((use_realm == caster_ptr->realm2) ?
@@ -265,37 +252,6 @@ static bool spell_okay(player_type *caster_ptr, int spell, bool learned, bool st
        return (!learned);
 }
 
-
-/*!
- * @brief 魔法処理のメインルーチン
- * @param realm 魔法領域のID
- * @param spell 各領域の魔法ID
- * @param mode 求める処理
- * @return 各領域魔法に各種テキストを求めた場合は文字列参照ポインタ、そうでない場合はNULLポインタを返す。
- */
-concptr exe_spell(player_type *caster_ptr, REALM_IDX realm, SPELL_IDX spell, BIT_FLAGS mode)
-{
-       switch (realm)
-       {
-       case REALM_LIFE:     return do_life_spell(caster_ptr, spell, mode);
-       case REALM_SORCERY:  return do_sorcery_spell(caster_ptr, spell, mode);
-       case REALM_NATURE:   return do_nature_spell(caster_ptr, spell, mode);
-       case REALM_CHAOS:    return do_chaos_spell(caster_ptr, spell, mode);
-       case REALM_DEATH:    return do_death_spell(caster_ptr, spell, mode);
-       case REALM_TRUMP:    return do_trump_spell(caster_ptr, spell, mode);
-       case REALM_ARCANE:   return do_arcane_spell(caster_ptr, spell, mode);
-       case REALM_CRAFT:    return do_craft_spell(caster_ptr, spell, mode);
-       case REALM_DAEMON:   return do_daemon_spell(caster_ptr, spell, mode);
-       case REALM_CRUSADE:  return do_crusade_spell(caster_ptr, spell, mode);
-       case REALM_MUSIC:    return do_music_spell(caster_ptr, spell, mode);
-       case REALM_HISSATSU: return do_hissatsu_spell(caster_ptr, spell, mode);
-       case REALM_HEX:      return do_hex_spell(caster_ptr, spell, mode);
-       }
-
-       return NULL;
-}
-
-
 /*!
  * @brief 領域魔法の閲覧、学習、使用選択するインターフェイス処理
  * Allow user to choose a spell/prayer from the given book.
@@ -340,7 +296,7 @@ static int get_spell(player_type *caster_ptr, SPELL_IDX *sn, concptr prompt, OBJ
                if (spell_okay(caster_ptr, *sn, learned, FALSE, use_realm))
                {
                        /* Success */
-                       return (TRUE);
+                       return TRUE;
                }
        }
 
@@ -371,7 +327,7 @@ static int get_spell(player_type *caster_ptr, SPELL_IDX *sn, concptr prompt, OBJ
        }
 
        /* No "okay" spells */
-       if (!okay) return (FALSE);
+       if (!okay) return FALSE;
        if (((use_realm) != caster_ptr->realm1) && ((use_realm) != caster_ptr->realm2) && (caster_ptr->pclass != CLASS_SORCERER) && (caster_ptr->pclass != CLASS_RED_MAGE)) return FALSE;
        if (((caster_ptr->pclass == CLASS_SORCERER) || (caster_ptr->pclass == CLASS_RED_MAGE)) && !is_magic(use_realm)) return FALSE;
        if ((caster_ptr->pclass == CLASS_RED_MAGE) && ((use_realm) != REALM_ARCANE) && (sval > 1)) return FALSE;
@@ -383,7 +339,7 @@ static int get_spell(player_type *caster_ptr, SPELL_IDX *sn, concptr prompt, OBJ
        redraw = FALSE;
 
        caster_ptr->window |= (PW_SPELL);
-       handle_stuff();
+       handle_stuff(caster_ptr);
 
        /* Build a prompt (accept all spells) */
 #ifdef JP
@@ -527,7 +483,7 @@ static int get_spell(player_type *caster_ptr, SPELL_IDX *sn, concptr prompt, OBJ
                        }
                        else
                        {
-                               need_mana = mod_need_mana(s_ptr->smana, spell, use_realm);
+                               need_mana = mod_need_mana(caster_ptr, s_ptr->smana, spell, use_realm);
                        }
 
                        /* Prompt */
@@ -555,7 +511,7 @@ static int get_spell(player_type *caster_ptr, SPELL_IDX *sn, concptr prompt, OBJ
        if (redraw) screen_load();
 
        caster_ptr->window |= (PW_SPELL);
-       handle_stuff();
+       handle_stuff(caster_ptr);
 
        /* Abort if needed */
        if (!flag) return FALSE;
@@ -574,7 +530,7 @@ static int get_spell(player_type *caster_ptr, SPELL_IDX *sn, concptr prompt, OBJ
  * @param browse_only 魔法と技能の閲覧を行うならばTRUE
  * @return 魔道書を一冊も持っていないならTRUEを返す
  */
-static void confirm_use_force(bool browse_only)
+static void confirm_use_force(player_type *caster_ptr, bool browse_only)
 {
        char which;
        COMMAND_CODE code;
@@ -582,14 +538,14 @@ static void confirm_use_force(bool browse_only)
        /* Get the item index */
        if (repeat_pull(&code) && (code == INVEN_FORCE))
        {
-               browse_only ? do_cmd_mind_browse() : do_cmd_mind();
+               browse_only ? do_cmd_mind_browse(caster_ptr) : do_cmd_mind(caster_ptr);
                return;
        }
 
        /* Show the prompt */
        prt(_("('w'練気術, ESC) 'w'かESCを押してください。 ", "(w for the Force, ESC) Hit 'w' or ESC. "), 0, 0);
 
-       while (1)
+       while (TRUE)
        {
                /* Get a key */
                which = inkey();
@@ -607,7 +563,7 @@ static void confirm_use_force(bool browse_only)
 
        if (which == 'w')
        {
-               browse_only ? do_cmd_mind_browse() : do_cmd_mind();
+               browse_only ? do_cmd_mind_browse(caster_ptr) : do_cmd_mind(caster_ptr);
        }
 }
 
@@ -656,7 +612,7 @@ void do_cmd_browse(player_type *caster_ptr)
        {
                if (player_has_no_spellbooks(caster_ptr))
                {
-                       confirm_use_force(TRUE);
+                       confirm_use_force(caster_ptr, TRUE);
                        return;
                }
        }
@@ -673,7 +629,7 @@ void do_cmd_browse(player_type *caster_ptr)
        {
                if (item == INVEN_FORCE) /* the_force */
                {
-                       do_cmd_mind_browse();
+                       do_cmd_mind_browse(caster_ptr);
                        return;
                }
                return;
@@ -685,8 +641,8 @@ void do_cmd_browse(player_type *caster_ptr)
        use_realm = tval2realm(o_ptr->tval);
 
        /* Track the object kind */
-       object_kind_track(o_ptr->k_idx);
-       handle_stuff();
+       object_kind_track(caster_ptr, o_ptr->k_idx);
+       handle_stuff(caster_ptr);
 
        /* Extract spells */
        for (spell = 0; spell < 32; spell++)
@@ -745,6 +701,7 @@ void do_cmd_browse(player_type *caster_ptr)
 
 /*!
  * @brief プレイヤーの第二魔法領域を変更する /
+ * @param caster_ptr プレーヤーへの参照ポインタ
  * @param next_realm 変更先の魔法領域ID
  * @return なし
  */
@@ -770,16 +727,16 @@ static void change_realm2(player_type *caster_ptr, CHARACTER_IDX next_realm)
        caster_ptr->spell_forgotten2 = 0L;
 
        sprintf(tmp, _("魔法の領域を%sから%sに変更した。", "change magic realm from %s to %s."), realm_names[caster_ptr->realm2], realm_names[next_realm]);
-       exe_write_diary(caster_ptr, NIKKI_BUNSHOU, 0, tmp);
+       exe_write_diary(caster_ptr, DIARY_DESCRIPTION, 0, tmp);
        caster_ptr->old_realm |= 1 << (caster_ptr->realm2 - 1);
        caster_ptr->realm2 = next_realm;
 
        caster_ptr->update |= (PU_REORDER);
        caster_ptr->update |= (PU_SPELLS);
-       handle_stuff();
+       handle_stuff(caster_ptr);
 
        /* Load an autopick preference file */
-       autopick_load_pref(FALSE);
+       autopick_load_pref(caster_ptr, FALSE);
 }
 
 
@@ -845,6 +802,8 @@ void do_cmd_study(player_type *caster_ptr)
        s = _("読める本がない。", "You have no books that you can read.");
 
        o_ptr = choose_object(caster_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), item_tester_tval);
+
+       item_tester_tval = NULL;
        if (!o_ptr) return;
 
        /* Access the item's sval */
@@ -859,8 +818,8 @@ void do_cmd_study(player_type *caster_ptr)
        }
 
        /* Track the object kind */
-       object_kind_track(o_ptr->k_idx);
-       handle_stuff();
+       object_kind_track(caster_ptr, o_ptr->k_idx);
+       handle_stuff(caster_ptr);
 
        /* Mage -- Learn a selected spell */
        if (mp_ptr->spell_book != TV_LIFE_BOOK)
@@ -1029,6 +988,7 @@ void do_cmd_study(player_type *caster_ptr)
 /*!
  * @brief 魔法を詠唱するコマンドのメインルーチン /
  * Cast a spell
+ * @param caster_ptr プレーヤーへの参照ポインタ
  * @return なし
  */
 void do_cmd_cast(player_type *caster_ptr)
@@ -1056,9 +1016,9 @@ void do_cmd_cast(player_type *caster_ptr)
                return;
        }
 
-       if (caster_ptr->blind || no_lite())
+       if (caster_ptr->blind || no_lite(caster_ptr))
        {
-               if (caster_ptr->pclass == CLASS_FORCETRAINER) confirm_use_force(FALSE);
+               if (caster_ptr->pclass == CLASS_FORCETRAINER) confirm_use_force(caster_ptr, FALSE);
                else
                {
                        msg_print(_("目が見えない!", "You cannot see!"));
@@ -1070,12 +1030,12 @@ void do_cmd_cast(player_type *caster_ptr)
        if (cmd_limit_confused(caster_ptr)) return;
        if (caster_ptr->realm1 == REALM_HEX)
        {
-               if (hex_spell_fully())
+               if (hex_spell_fully(caster_ptr))
                {
                        bool flag = FALSE;
-                       msg_print(_("これ以上新しい呪文を詠唱することはできない。", "Can not spell new spells more."));
+                       msg_print(_("これ以上新しい呪文を詠唱することはできない。", "Can not cast more spells."));
                        flush();
-                       if (caster_ptr->lev >= 35) flag = stop_hex_spell();
+                       if (caster_ptr->lev >= 35) flag = stop_hex_spell(caster_ptr);
                        if (!flag) return;
                }
        }
@@ -1084,7 +1044,7 @@ void do_cmd_cast(player_type *caster_ptr)
        {
                if (player_has_no_spellbooks(caster_ptr))
                {
-                       confirm_use_force(FALSE);
+                       confirm_use_force(caster_ptr, FALSE);
                        return;
                }
        }
@@ -1099,7 +1059,7 @@ void do_cmd_cast(player_type *caster_ptr)
        {
                if (item == INVEN_FORCE) /* the_force */
                {
-                       do_cmd_mind();
+                       do_cmd_mind(caster_ptr);
                        return;
                }
                return;
@@ -1111,8 +1071,8 @@ void do_cmd_cast(player_type *caster_ptr)
        if ((caster_ptr->pclass != CLASS_SORCERER) && (caster_ptr->pclass != CLASS_RED_MAGE) && (o_ptr->tval == REALM2_BOOK)) increment = 32;
 
        /* Track the object kind */
-       object_kind_track(o_ptr->k_idx);
-       handle_stuff();
+       object_kind_track(caster_ptr, o_ptr->k_idx);
+       handle_stuff(caster_ptr);
 
        if ((caster_ptr->pclass == CLASS_SORCERER) || (caster_ptr->pclass == CLASS_RED_MAGE))
                realm = o_ptr->tval - TV_LIFE_BOOK + 1;
@@ -1140,7 +1100,7 @@ void do_cmd_cast(player_type *caster_ptr)
        use_realm = tval2realm(o_ptr->tval);
        if (use_realm == REALM_HEX)
        {
-               if (hex_spelling(spell))
+               if (hex_spelling(caster_ptr, spell))
                {
                        msg_print(_("その呪文はすでに詠唱中だ。", "You are already casting it."));
                        return;
@@ -1157,7 +1117,7 @@ void do_cmd_cast(player_type *caster_ptr)
        }
 
        /* Extract mana consumption rate */
-       need_mana = mod_need_mana(s_ptr->smana, spell, realm);
+       need_mana = mod_need_mana(caster_ptr, s_ptr->smana, spell, realm);
 
        /* Verify "dangerous" spells */
        if (need_mana > caster_ptr->csp)
@@ -1253,7 +1213,7 @@ void do_cmd_cast(player_type *caster_ptr)
                else if ((o_ptr->tval == TV_MUSIC_BOOK) && (randint1(200) < spell))
                {
                        msg_print(_("いやな音が響いた", "An infernal sound echoed."));
-                       aggravate_monsters(0);
+                       aggravate_monsters(caster_ptr, 0);
                }
                if (randint1(100) >= chance)
                        chg_virtue(caster_ptr, V_CHANCE, -1);