OSDN Git Service

[Refactor] #40030 Separaterd monster-util.c/h from monster-process.c/h
authorHourier <hourier@users.sourceforge.jp>
Sat, 7 Mar 2020 14:21:57 +0000 (23:21 +0900)
committerHourier <hourier@users.sourceforge.jp>
Sat, 7 Mar 2020 14:21:57 +0000 (23:21 +0900)
Hengband_vcs2017/Hengband/Hengband.vcxproj
Hengband_vcs2017/Hengband/Hengband.vcxproj.filters
src/Makefile.am
src/monster-process.c
src/monster-process.h
src/monster/monster-util.c [new file with mode: 0644]
src/monster/monster-util.h [new file with mode: 0644]

index e256c2c..b5270d7 100644 (file)
     <ClCompile Include="..\..\src\monster-status.c" />\r
     <ClCompile Include="..\..\src\monsterrace-hook.c" />\r
     <ClCompile Include="..\..\src\monsterrace.c" />\r
+    <ClCompile Include="..\..\src\monster\monster-util.c" />\r
     <ClCompile Include="..\..\src\monster\quantum-effect.c" />\r
     <ClCompile Include="..\..\src\object-boost.c" />\r
     <ClCompile Include="..\..\src\object-curse.c" />\r
     <ClInclude Include="..\..\src\io\special-class-dump.h" />\r
     <ClInclude Include="..\..\src\io\tokenizer.h" />\r
     <ClInclude Include="..\..\src\monster-dist-offsets.h" />\r
+    <ClInclude Include="..\..\src\monster\monster-util.h" />\r
     <ClInclude Include="..\..\src\monster\quantum-effect.h" />\r
     <ClInclude Include="..\..\src\object-flavor.h" />\r
     <ClInclude Include="..\..\src\player-inventory.h" />\r
index e17d8eb..3633bb5 100644 (file)
     <ClCompile Include="..\..\src\io\player-status-dump.c">
       <Filter>io</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\monster\monster-util.c">
+      <Filter>monster</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\src\gamevalue.h" />
     <ClInclude Include="..\..\src\io\player-status-dump.h">
       <Filter>io</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\monster\monster-util.h">
+      <Filter>monster</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\src\wall.bmp" />
index 21d217f..4a7138c 100644 (file)
@@ -58,6 +58,7 @@ hengband_SOURCES = \
        mind.c mind.h \
        \
        monster.h monsterrace.c monsterrace.h \
+       monster/monster-util.c monster/monster-util.c \
        monster/quantum-effect.c monster/quantum-effect.c \
        monsterrace-hook.c monsterrace-hook.h \
        monster-dist-offsets.c monster-dist-offsets.h \
@@ -145,7 +146,7 @@ EXTRA_DIST = \
 CFLAGS += $(XFT_CFLAGS)
 LIBS += $(XFT_LIBS)
 COMPILE = $(srcdir)/gcc-wrap $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
-       $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -Icmd -Icombat -Iio -Iplayer -Iview
+       $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -Icmd -Icombat -Icore -Iio -Imonster -Iplayer -Iview
 
 install-exec-hook:
 if SET_GID
index c946348..eb272f6 100644 (file)
@@ -15,6 +15,7 @@
 
 #include "angband.h"
 #include "util.h"
+#include "monster/monster-util.h"
 #include "monster/quantum-effect.h"
 
 #include "cmd-dump.h"
 #include "files.h"
 #include "view-mainwindow.h"
 
-typedef struct {
-       bool see_m;
-       bool aware;
-       bool is_riding_mon;
-       bool do_turn;
-       bool do_move;
-       bool do_view;
-       bool do_take;
-       bool must_alter_to_move;
-
-       bool did_open_door;
-       bool did_bash_door;
-       bool did_take_item;
-       bool did_kill_item;
-       bool did_move_body;
-       bool did_pass_wall;
-       bool did_kill_wall;
-} turn_flags;
-
-typedef struct {
-       BIT_FLAGS old_r_flags1;
-       BIT_FLAGS old_r_flags2;
-       BIT_FLAGS old_r_flags3;
-       BIT_FLAGS old_r_flags4;
-       BIT_FLAGS old_r_flags5;
-       BIT_FLAGS old_r_flags6;
-       BIT_FLAGS old_r_flagsr;
-
-       byte old_r_blows0;
-       byte old_r_blows1;
-       byte old_r_blows2;
-       byte old_r_blows3;
-
-       byte old_r_cast_spell;
-} old_race_flags;
-
-typedef struct {
-       POSITION gy;
-       POSITION gx;
-       POSITION gdis;
-} coordinate_candidate;
-
-turn_flags *init_turn_flags(player_type *target_ptr, MONSTER_IDX m_idx, turn_flags *turn_flags_ptr);
-old_race_flags *init_old_race_flags(old_race_flags *old_race_flags_ptr);
-
 bool get_enemy_dir(player_type *target_ptr, MONSTER_IDX m_idx, int *mm);
 void decide_enemy_approch_direction(player_type *target_ptr, MONSTER_IDX m_idx, int start, int plus, POSITION *y, POSITION *x);
 bool decide_pet_approch_direction(player_type *target_ptr, monster_type *m_ptr, monster_type *t_ptr);
-void store_enemy_approch_direction(int *mm, POSITION y, POSITION x);
 
 bool find_safety(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp);
 coordinate_candidate sweep_safe_coordinate(player_type *target_ptr, MONSTER_IDX m_idx, const POSITION *y_offsets, const POSITION *x_offsets, int d);
@@ -269,66 +224,6 @@ bool decide_pet_approch_direction(player_type *target_ptr, monster_type *m_ptr,
 
 
 /*!
- * @brief モンスターの移動方向を保存する
- * @param mm 移動方向
- * @param y 移動先Y座標
- * @param x 移動先X座標
- */
-void store_enemy_approch_direction(int *mm, POSITION y, POSITION x)
-{
-       /* North, South, East, West, North-West, North-East, South-West, South-East */
-       if ((y < 0) && (x == 0))
-       {
-               mm[0] = 8;
-               mm[1] = 7;
-               mm[2] = 9;
-       }
-       else if ((y > 0) && (x == 0))
-       {
-               mm[0] = 2;
-               mm[1] = 1;
-               mm[2] = 3;
-       }
-       else if ((x > 0) && (y == 0))
-       {
-               mm[0] = 6;
-               mm[1] = 9;
-               mm[2] = 3;
-       }
-       else if ((x < 0) && (y == 0))
-       {
-               mm[0] = 4;
-               mm[1] = 7;
-               mm[2] = 1;
-       }
-       else if ((y < 0) && (x < 0))
-       {
-               mm[0] = 7;
-               mm[1] = 4;
-               mm[2] = 8;
-       }
-       else if ((y < 0) && (x > 0))
-       {
-               mm[0] = 9;
-               mm[1] = 6;
-               mm[2] = 8;
-       }
-       else if ((y > 0) && (x < 0))
-       {
-               mm[0] = 1;
-               mm[1] = 4;
-               mm[2] = 2;
-       }
-       else if ((y > 0) && (x > 0))
-       {
-               mm[0] = 3;
-               mm[1] = 6;
-               mm[2] = 2;
-       }
-}
-
-
-/*!
  * @brief モンスターがプレイヤーから逃走するかどうかを返す /
  * Returns whether a given monster will try to run from the player.
  * @param m_idx 逃走するモンスターの参照ID
@@ -602,15 +497,6 @@ static bool get_fear_moves_aux(floor_type *floor_ptr, MONSTER_IDX m_idx, POSITIO
 }
 
 
-coordinate_candidate init_coordinate_candidate(void)
-{
-       coordinate_candidate candidate;
-       candidate.gy = 0;
-       candidate.gx = 0;
-       candidate.gdis = 0;
-       return candidate;
-}
-
 /*!
  * @brief モンスターが逃げ込める安全な地点を返す /
  * Choose a "safe" location near a monster for it to run toward.
@@ -1107,7 +993,7 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
        monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
        turn_flags tmp_flags;
-       turn_flags *turn_flags_ptr = init_turn_flags(target_ptr, m_idx, &tmp_flags);
+       turn_flags *turn_flags_ptr = init_turn_flags(target_ptr->riding, m_idx, &tmp_flags);
        turn_flags_ptr->see_m = is_seen(m_ptr);
 
        decide_drop_from_monster(target_ptr, m_idx, turn_flags_ptr->is_riding_mon);
@@ -1178,30 +1064,6 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
 
 
 /*!
- * @brief ターン経過フラグ構造体の初期化
- * @param target_ptr プレーヤーへの参照ポインタ
- * @param m_idx モンスターID
- * @return 初期化済のターン経過フラグ
- */
-turn_flags *init_turn_flags(player_type *target_ptr, MONSTER_IDX m_idx, turn_flags *turn_flags_ptr)
-{
-       turn_flags_ptr->is_riding_mon = (m_idx == target_ptr->riding);
-       turn_flags_ptr->do_turn = FALSE;
-       turn_flags_ptr->do_move = FALSE;
-       turn_flags_ptr->do_view = FALSE;
-       turn_flags_ptr->must_alter_to_move = FALSE;
-       turn_flags_ptr->did_open_door = FALSE;
-       turn_flags_ptr->did_bash_door = FALSE;
-       turn_flags_ptr->did_take_item = FALSE;
-       turn_flags_ptr->did_kill_item = FALSE;
-       turn_flags_ptr->did_move_body = FALSE;
-       turn_flags_ptr->did_pass_wall = FALSE;
-       turn_flags_ptr->did_kill_wall = FALSE;
-       return turn_flags_ptr;
-}
-
-
-/*!
  * @brief 超隠密処理
  * @param target_ptr プレーヤーへの参照ポインタ
  * @param m_idx モンスターID
@@ -2562,29 +2424,6 @@ void process_monsters(player_type *target_ptr)
 
 
 /*!
- * @brief old_race_flags_ptr の初期化
- */
-old_race_flags *init_old_race_flags(old_race_flags *old_race_flags_ptr)
-{
-       old_race_flags_ptr->old_r_flags1 = 0L;
-       old_race_flags_ptr->old_r_flags2 = 0L;
-       old_race_flags_ptr->old_r_flags3 = 0L;
-       old_race_flags_ptr->old_r_flags4 = 0L;
-       old_race_flags_ptr->old_r_flags5 = 0L;
-       old_race_flags_ptr->old_r_flags6 = 0L;
-       old_race_flags_ptr->old_r_flagsr = 0L;
-
-       old_race_flags_ptr->old_r_blows0 = 0;
-       old_race_flags_ptr->old_r_blows1 = 0;
-       old_race_flags_ptr->old_r_blows2 = 0;
-       old_race_flags_ptr->old_r_blows3 = 0;
-
-       old_race_flags_ptr->old_r_cast_spell = 0;
-       return old_race_flags_ptr;
-}
-
-
-/*!
  * @brief 古いモンスター情報の保存
  * @param target_ptr プレーヤーへの参照ポインタ
  * @param old_race_flags_ptr モンスターフラグへの参照ポインタ
index 89517c1..96ae546 100644 (file)
@@ -1,5 +1,4 @@
 #pragma once
 
-/* monster-process.c */
 extern void process_monsters(player_type *target_ptr);
 extern void process_monster(player_type *target_ptr, MONSTER_IDX m_idx);
diff --git a/src/monster/monster-util.c b/src/monster/monster-util.c
new file mode 100644 (file)
index 0000000..a3b320f
--- /dev/null
@@ -0,0 +1,132 @@
+/*!
+ * @brief monster-processのための構造体群初期化処理と共通性の極めて高い処理
+ * @date 2020/03/07
+ * @author Hourier
+ * @details
+ * 概ね、player_type 構造体が引数でない場合はここへ移動させることを検討しても良い
+ * 引数に入っていたらここには移動させないこと
+ */
+
+#include "angband.h"
+#include "monster-util.h"
+
+ /*!
+  * @brief ターン経過フラグ構造体の初期化
+  * @param riding_idx 乗馬中のモンスターID
+  * @param m_idx モンスターID
+  * @return 初期化済のターン経過フラグ
+  */
+turn_flags *init_turn_flags(MONSTER_IDX riding_idx, MONSTER_IDX m_idx, turn_flags *turn_flags_ptr)
+{
+       turn_flags_ptr->is_riding_mon = (m_idx == riding_idx);
+       turn_flags_ptr->do_turn = FALSE;
+       turn_flags_ptr->do_move = FALSE;
+       turn_flags_ptr->do_view = FALSE;
+       turn_flags_ptr->must_alter_to_move = FALSE;
+       turn_flags_ptr->did_open_door = FALSE;
+       turn_flags_ptr->did_bash_door = FALSE;
+       turn_flags_ptr->did_take_item = FALSE;
+       turn_flags_ptr->did_kill_item = FALSE;
+       turn_flags_ptr->did_move_body = FALSE;
+       turn_flags_ptr->did_pass_wall = FALSE;
+       turn_flags_ptr->did_kill_wall = FALSE;
+       return turn_flags_ptr;
+}
+
+
+/*!
+ * @brief old_race_flags_ptr の初期化
+ */
+old_race_flags *init_old_race_flags(old_race_flags *old_race_flags_ptr)
+{
+       old_race_flags_ptr->old_r_flags1 = 0L;
+       old_race_flags_ptr->old_r_flags2 = 0L;
+       old_race_flags_ptr->old_r_flags3 = 0L;
+       old_race_flags_ptr->old_r_flags4 = 0L;
+       old_race_flags_ptr->old_r_flags5 = 0L;
+       old_race_flags_ptr->old_r_flags6 = 0L;
+       old_race_flags_ptr->old_r_flagsr = 0L;
+
+       old_race_flags_ptr->old_r_blows0 = 0;
+       old_race_flags_ptr->old_r_blows1 = 0;
+       old_race_flags_ptr->old_r_blows2 = 0;
+       old_race_flags_ptr->old_r_blows3 = 0;
+
+       old_race_flags_ptr->old_r_cast_spell = 0;
+       return old_race_flags_ptr;
+}
+
+
+/*!
+ * @brief coordinate_candidate の初期化
+ * @param なし
+ * @return 初期化済の構造体
+ */
+coordinate_candidate init_coordinate_candidate(void)
+{
+       coordinate_candidate candidate;
+       candidate.gy = 0;
+       candidate.gx = 0;
+       candidate.gdis = 0;
+       return candidate;
+}
+
+
+/*!
+ * @brief モンスターの移動方向を保存する
+ * @param mm 移動方向
+ * @param y 移動先Y座標
+ * @param x 移動先X座標
+ */
+void store_enemy_approch_direction(int *mm, POSITION y, POSITION x)
+{
+       /* North, South, East, West, North-West, North-East, South-West, South-East */
+       if ((y < 0) && (x == 0))
+       {
+               mm[0] = 8;
+               mm[1] = 7;
+               mm[2] = 9;
+       }
+       else if ((y > 0) && (x == 0))
+       {
+               mm[0] = 2;
+               mm[1] = 1;
+               mm[2] = 3;
+       }
+       else if ((x > 0) && (y == 0))
+       {
+               mm[0] = 6;
+               mm[1] = 9;
+               mm[2] = 3;
+       }
+       else if ((x < 0) && (y == 0))
+       {
+               mm[0] = 4;
+               mm[1] = 7;
+               mm[2] = 1;
+       }
+       else if ((y < 0) && (x < 0))
+       {
+               mm[0] = 7;
+               mm[1] = 4;
+               mm[2] = 8;
+       }
+       else if ((y < 0) && (x > 0))
+       {
+               mm[0] = 9;
+               mm[1] = 6;
+               mm[2] = 8;
+       }
+       else if ((y > 0) && (x < 0))
+       {
+               mm[0] = 1;
+               mm[1] = 4;
+               mm[2] = 2;
+       }
+       else if ((y > 0) && (x > 0))
+       {
+               mm[0] = 3;
+               mm[1] = 6;
+               mm[2] = 2;
+       }
+}
diff --git a/src/monster/monster-util.h b/src/monster/monster-util.h
new file mode 100644 (file)
index 0000000..7637280
--- /dev/null
@@ -0,0 +1,55 @@
+/*!
+ * @brief monster-processのための構造体群
+ * @date 2020/03/07
+ * @author Hourier
+ */
+
+#pragma once
+
+typedef struct {
+       bool see_m;
+       bool aware;
+       bool is_riding_mon;
+       bool do_turn;
+       bool do_move;
+       bool do_view;
+       bool do_take;
+       bool must_alter_to_move;
+
+       bool did_open_door;
+       bool did_bash_door;
+       bool did_take_item;
+       bool did_kill_item;
+       bool did_move_body;
+       bool did_pass_wall;
+       bool did_kill_wall;
+} turn_flags;
+
+typedef struct {
+       BIT_FLAGS old_r_flags1;
+       BIT_FLAGS old_r_flags2;
+       BIT_FLAGS old_r_flags3;
+       BIT_FLAGS old_r_flags4;
+       BIT_FLAGS old_r_flags5;
+       BIT_FLAGS old_r_flags6;
+       BIT_FLAGS old_r_flagsr;
+
+       byte old_r_blows0;
+       byte old_r_blows1;
+       byte old_r_blows2;
+       byte old_r_blows3;
+
+       byte old_r_cast_spell;
+} old_race_flags;
+
+typedef struct {
+       POSITION gy;
+       POSITION gx;
+       POSITION gdis;
+} coordinate_candidate;
+
+turn_flags *init_turn_flags(MONSTER_IDX riding_idx, MONSTER_IDX m_idx, turn_flags *turn_flags_ptr);
+old_race_flags *init_old_race_flags(old_race_flags *old_race_flags_ptr);
+coordinate_candidate init_coordinate_candidate(void);
+
+void store_enemy_approch_direction(int *mm, POSITION y, POSITION x);