OSDN Git Service

[Refactor] #38662 Moved util.* to util/
[hengband/hengband.git] / src / cmd / cmd-spell.c
index 5bae1f9..b7ebd72 100644 (file)
@@ -6,43 +6,36 @@
     2013 Deskull rearranged comment for Doxygen.
  */
 
-#include "angband.h"
-#include "core.h"
-#include "util.h"
-#include "cmd-spell.h"
-
-#include "cmd-dump.h"
-#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"
-#include "player-status.h"
-#include "player-effects.h"
-#include "player-skill.h"
-#include "player-class.h"
-#include "player-inventory.h"
-#include "object-hook.h"
+#include "system/angband.h"
+#include "core/stuff-handler.h"
+#include "util/util.h"
+#include "main/sound-definitions-table.h"
+#include "cmd/cmd-spell.h"
+
+#include "io/write-diary.h"
+#include "cmd/cmd-dump.h"
+#include "player/selfinfo.h"
+#include "spell/technic-info-table.h"
+#include "spell/spells2.h"
+#include "spell/spells3.h"
+#include "spell/spells-summon.h"
+#include "realm/realm-hex.h"
+#include "mind/mind.h"
+#include "player/avatar.h"
+#include "player/player-damage.h"
+#include "player/player-status.h"
+#include "player/player-effects.h"
+#include "player/player-skill.h"
+#include "player/player-class.h"
+#include "inventory/player-inventory.h"
+#include "object/object-hook.h"
 #include "cmd-basic.h"
-#include "view-mainwindow.h"
-#include "floor.h"
-#include "autopick.h"
-#include "japanese.h"
+#include "view/display-main-window.h"
+#include "floor/floor.h"
+#include "autopick/autopick-reader-writer.h"
+#include "locale/japanese.h"
+#include "spell/spells-util.h"
+#include "spell/spells-execution.h"
 
  /*!
   * 魔法領域フラグ管理テーブル /
@@ -238,7 +231,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 +239,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 +258,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 +302,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 +333,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 +345,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 +489,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 +517,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;
@@ -589,7 +551,7 @@ static void confirm_use_force(player_type *caster_ptr, bool browse_only)
        /* 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();
@@ -639,6 +601,7 @@ void do_cmd_browse(player_type *caster_ptr)
        object_type *o_ptr;
 
        concptr q, s;
+       OBJECT_TYPE_VALUE tval = 0;
 
        /* Warriors are illiterate */
        if (!(caster_ptr->realm1 || caster_ptr->realm2) && (caster_ptr->pclass != CLASS_SORCERER) && (caster_ptr->pclass != CLASS_RED_MAGE))
@@ -662,13 +625,15 @@ void do_cmd_browse(player_type *caster_ptr)
        }
 
        /* Restrict choices to "useful" books */
-       if (caster_ptr->realm2 == REALM_NONE) item_tester_tval = mp_ptr->spell_book;
+       if (caster_ptr->realm2 == REALM_NONE) tval = mp_ptr->spell_book;
        else item_tester_hook = item_tester_learn_spell;
 
        q = _("どの本を読みますか? ", "Browse which book? ");
        s = _("読める本がない。", "You have no books that you can read.");
 
-       o_ptr = choose_object(caster_ptr, &item, q, s, (USE_INVEN | USE_FLOOR | (caster_ptr->pclass == CLASS_FORCETRAINER ? USE_FORCE : 0)), item_tester_tval);
+       o_ptr = choose_object(caster_ptr, &item, q, s, (USE_INVEN | USE_FLOOR | (caster_ptr->pclass == CLASS_FORCETRAINER ? USE_FORCE : 0)), tval);
+
+       item_tester_hook = NULL;
        if (!o_ptr)
        {
                if (item == INVEN_FORCE) /* the_force */
@@ -685,8 +650,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 +710,7 @@ void do_cmd_browse(player_type *caster_ptr)
 
 /*!
  * @brief プレイヤーの第二魔法領域を変更する /
+ * @param caster_ptr プレーヤーへの参照ポインタ
  * @param next_realm 変更先の魔法領域ID
  * @return なし
  */
@@ -769,17 +735,17 @@ static void change_realm2(player_type *caster_ptr, CHARACTER_IDX next_realm)
        caster_ptr->spell_worked2 = 0L;
        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);
+       sprintf(tmp, _("魔法の領域を%sから%sに変更した。", "changed magic realm from %s to %s."), realm_names[caster_ptr->realm2], realm_names[next_realm]);
+       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);
 }
 
 
@@ -801,6 +767,8 @@ void do_cmd_study(player_type *caster_ptr)
        concptr p = spell_category_name(mp_ptr->spell_book);
        object_type *o_ptr;
        concptr q, s;
+       OBJECT_TYPE_VALUE tval = 0;
+
 
        if (!caster_ptr->realm1)
        {
@@ -838,13 +806,14 @@ void do_cmd_study(player_type *caster_ptr)
 
 
        /* Restrict choices to "useful" books */
-       if (caster_ptr->realm2 == REALM_NONE) item_tester_tval = mp_ptr->spell_book;
+       if (caster_ptr->realm2 == REALM_NONE) tval = mp_ptr->spell_book;
        else item_tester_hook = item_tester_learn_spell;
 
        q = _("どの本から学びますか? ", "Study which book? ");
        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);
+       o_ptr = choose_object(caster_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), tval);
+
        if (!o_ptr) return;
 
        /* Access the item's sval */
@@ -859,8 +828,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)
@@ -1074,7 +1043,7 @@ void do_cmd_cast(player_type *caster_ptr)
                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(caster_ptr);
                        if (!flag) return;
@@ -1112,8 +1081,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;
@@ -1141,7 +1110,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;
@@ -1158,7 +1127,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)