OSDN Git Service

[Refactor] #40030 Separated monster-attack.c/h from monster-process.c
authorHourier <hourier@users.sourceforge.jp>
Sun, 8 Mar 2020 00:54:41 +0000 (09:54 +0900)
committerHourier <hourier@users.sourceforge.jp>
Sun, 8 Mar 2020 00:54:41 +0000 (09:54 +0900)
Hengband_vcs2017/Hengband/Hengband.vcxproj
Hengband_vcs2017/Hengband/Hengband.vcxproj.filters
src/Makefile.am
src/monster-process.c
src/monster/monster-attack.c [new file with mode: 0644]
src/monster/monster-attack.h [new file with mode: 0644]

index 24e4348..f4b5a43 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-attack.c" />\r
     <ClCompile Include="..\..\src\monster\monster-object.c" />\r
     <ClCompile Include="..\..\src\monster\monster-util.c" />\r
     <ClCompile Include="..\..\src\monster\quantum-effect.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-attack.h" />\r
     <ClInclude Include="..\..\src\monster\monster-object.h" />\r
     <ClInclude Include="..\..\src\monster\monster-util.h" />\r
     <ClInclude Include="..\..\src\monster\quantum-effect.h" />\r
index e429990..4f3ced5 100644 (file)
     <ClCompile Include="..\..\src\monster\monster-object.c">
       <Filter>monster</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\monster\monster-attack.c">
+      <Filter>monster</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\src\gamevalue.h" />
     <ClInclude Include="..\..\src\monster\monster-object.h">
       <Filter>monster</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\monster\monster-attack.h">
+      <Filter>monster</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\src\wall.bmp" />
index 9b9e5fb..8fba906 100644 (file)
@@ -59,6 +59,7 @@ hengband_SOURCES = \
        \
        monster.h monsterrace.c monsterrace.h \
        monster/monster-util.c monster/monster-util.h \
+       monster/monster-attack.c monster/monster-attack.h \
        monster/monster-object.c monster/monster-object.h \
        monster/quantum-effect.c monster/quantum-effect.h \
        monsterrace-hook.c monsterrace-hook.h \
index 73b8fc9..d990dd8 100644 (file)
@@ -15,6 +15,7 @@
 
 #include "angband.h"
 #include "util.h"
+#include "monster/monster-attack.h"
 #include "monster/monster-object.h"
 #include "monster/monster-util.h"
 #include "monster/quantum-effect.h"
@@ -75,10 +76,6 @@ void bash_glass_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monste
 bool process_protection_rune(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
 bool process_explosive_rune(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
 
-void exe_monster_attack_to_player(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx);
-bool process_monster_attack_to_monster(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, grid_type *g_ptr, bool can_cross);
-bool exe_monster_attack_to_monster(player_type *target_ptr, MONSTER_IDX m_idx, grid_type *g_ptr);
-
 bool process_monster_movement(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, DIRECTION *mm, POSITION oy, POSITION ox, int *count);
 bool process_post_dig_wall(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
 bool update_riding_monster(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox, POSITION ny, POSITION nx);
@@ -1958,122 +1955,6 @@ bool process_explosive_rune(player_type *target_ptr, turn_flags *turn_flags_ptr,
 
 
 /*!
- * @brief モンスターが移動した結果、そこにプレーヤーがいたら直接攻撃を行う
- * @param target_ptr プレーヤーへの参照ポインタ
- * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
- * @param m_idx モンスターID
- * @param ny 移動後の、モンスターのY座標
- * @param nx 移動後の、モンスターのX座標
- * @return なし
- * @details
- * 反攻撃の洞窟など、直接攻撃ができない場所では処理をスキップする
- */
-void exe_monster_attack_to_player(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx)
-{
-       monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
-       monster_race *r_ptr = &r_info[m_ptr->r_idx];
-       if (!turn_flags_ptr->do_move || !player_bold(target_ptr, ny, nx))
-               return;
-
-       if (r_ptr->flags1 & RF1_NEVER_BLOW)
-       {
-               if (is_original_ap_and_seen(target_ptr, m_ptr))
-                       r_ptr->r_flags1 |= (RF1_NEVER_BLOW);
-
-               turn_flags_ptr->do_move = FALSE;
-       }
-
-       if (turn_flags_ptr->do_move && ((d_info[target_ptr->dungeon_idx].flags1 & DF1_NO_MELEE) != 0) && !MON_CONFUSED(m_ptr))
-       {
-               if (!(r_ptr->flags2 & RF2_STUPID))
-                       turn_flags_ptr->do_move = FALSE;
-               else if (is_original_ap_and_seen(target_ptr, m_ptr))
-                       r_ptr->r_flags2 |= (RF2_STUPID);
-       }
-
-       if (!turn_flags_ptr->do_move) return;
-
-       if (!target_ptr->riding || one_in_(2))
-       {
-               (void)make_attack_normal(target_ptr, m_idx);
-               turn_flags_ptr->do_move = FALSE;
-               turn_flags_ptr->do_turn = TRUE;
-       }
-}
-
-
-/*!
- * @brief モンスターからモンスターへの攻撃処理
- * @param target_ptr プレーヤーへの参照ポインタ
- * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
- * @param m_idx モンスターID
- * @param g_ptr グリッドへの参照ポインタ
- * @param can_cross モンスターが地形を踏破できるならばTRUE
- * @return ターン消費が発生したらTRUE
- */
-bool process_monster_attack_to_monster(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, grid_type *g_ptr, bool can_cross)
-{
-       monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
-       monster_race *r_ptr = &r_info[m_ptr->r_idx];
-       monster_type *y_ptr;
-       y_ptr = &target_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
-       if (!turn_flags_ptr->do_move || (g_ptr->m_idx == 0)) return FALSE;
-
-       monster_race *z_ptr = &r_info[y_ptr->r_idx];
-       turn_flags_ptr->do_move = FALSE;
-       if ((((r_ptr->flags2 & RF2_KILL_BODY) != 0) && ((r_ptr->flags1 & RF1_NEVER_BLOW) == 0) &&
-               (r_ptr->mexp * r_ptr->level > z_ptr->mexp * z_ptr->level) &&
-               can_cross && (g_ptr->m_idx != target_ptr->riding)) ||
-               are_enemies(target_ptr, m_ptr, y_ptr) || MON_CONFUSED(m_ptr))
-       {
-               return exe_monster_attack_to_monster(target_ptr, m_idx, g_ptr);
-       }
-
-       if (((r_ptr->flags2 & RF2_MOVE_BODY) != 0) && ((r_ptr->flags1 & RF1_NEVER_MOVE) == 0) &&
-               (r_ptr->mexp > z_ptr->mexp) &&
-               can_cross && (g_ptr->m_idx != target_ptr->riding) &&
-               monster_can_cross_terrain(target_ptr, target_ptr->current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, z_ptr, 0))
-       {
-               turn_flags_ptr->do_move = TRUE;
-               turn_flags_ptr->did_move_body = TRUE;
-               (void)set_monster_csleep(target_ptr, g_ptr->m_idx, 0);
-       }
-
-       return FALSE;
-}
-
-
-/*!
- * @brief モンスターからモンスターへの直接攻撃を実行する
- * @param target_ptr プレーヤーへの参照ポインタ
- * @param m_idx モンスターID
- * @param g_ptr グリッドへの参照ポインタ
- */
-bool exe_monster_attack_to_monster(player_type *target_ptr, MONSTER_IDX m_idx, grid_type *g_ptr)
-{
-       monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
-       monster_race *r_ptr = &r_info[m_ptr->r_idx];
-       monster_type *y_ptr;
-       y_ptr = &target_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
-       if ((r_ptr->flags1 & RF1_NEVER_BLOW) != 0) return FALSE;
-
-       if (((r_ptr->flags2 & RF2_KILL_BODY) == 0) && is_original_ap_and_seen(target_ptr, m_ptr))
-               r_ptr->r_flags2 |= (RF2_KILL_BODY);
-
-       if ((y_ptr->r_idx == 0) || (y_ptr->hp < 0)) return FALSE;
-       if (monst_attack_monst(target_ptr, m_idx, g_ptr->m_idx)) return TRUE;
-       if ((d_info[target_ptr->dungeon_idx].flags1 & DF1_NO_MELEE) == 0) return FALSE;
-       if (MON_CONFUSED(m_ptr)) return TRUE;
-       if ((r_ptr->flags2 & RF2_STUPID) == 0) return FALSE;
-
-       if (is_original_ap_and_seen(target_ptr, m_ptr))
-               r_ptr->r_flags2 |= (RF2_STUPID);
-
-       return TRUE;
-}
-
-
-/*!
  * @brief モンスターが壁を掘った後続処理を実行する
  * @param target_ptr プレーヤーへの参照ポインタ
  * @turn_flags_ptr ターン経過処理フラグへの参照ポインタ
diff --git a/src/monster/monster-attack.c b/src/monster/monster-attack.c
new file mode 100644 (file)
index 0000000..bb9b5be
--- /dev/null
@@ -0,0 +1,125 @@
+/*!
+ * @brief モンスターの攻撃に関する処理
+ * @date 2020/03/08
+ * @author Hourier
+ */
+
+#include "monster/monster-attack.h"
+#include "monster-status.h"
+#include "dungeon.h"
+#include "combat/melee.h" // 暫定。後で引っ越し.
+
+ /*!
+  * @brief モンスターが移動した結果、そこにプレーヤーがいたら直接攻撃を行う
+  * @param target_ptr プレーヤーへの参照ポインタ
+  * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
+  * @param m_idx モンスターID
+  * @param ny 移動後の、モンスターのY座標
+  * @param nx 移動後の、モンスターのX座標
+  * @return なし
+  * @details
+  * 反攻撃の洞窟など、直接攻撃ができない場所では処理をスキップする
+  */
+void exe_monster_attack_to_player(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx)
+{
+       monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
+       monster_race *r_ptr = &r_info[m_ptr->r_idx];
+       if (!turn_flags_ptr->do_move || !player_bold(target_ptr, ny, nx))
+               return;
+
+       if (r_ptr->flags1 & RF1_NEVER_BLOW)
+       {
+               if (is_original_ap_and_seen(target_ptr, m_ptr))
+                       r_ptr->r_flags1 |= (RF1_NEVER_BLOW);
+
+               turn_flags_ptr->do_move = FALSE;
+       }
+
+       if (turn_flags_ptr->do_move && ((d_info[target_ptr->dungeon_idx].flags1 & DF1_NO_MELEE) != 0) && !MON_CONFUSED(m_ptr))
+       {
+               if (!(r_ptr->flags2 & RF2_STUPID))
+                       turn_flags_ptr->do_move = FALSE;
+               else if (is_original_ap_and_seen(target_ptr, m_ptr))
+                       r_ptr->r_flags2 |= (RF2_STUPID);
+       }
+
+       if (!turn_flags_ptr->do_move) return;
+
+       if (!target_ptr->riding || one_in_(2))
+       {
+               (void)make_attack_normal(target_ptr, m_idx);
+               turn_flags_ptr->do_move = FALSE;
+               turn_flags_ptr->do_turn = TRUE;
+       }
+}
+
+
+/*!
+ * @brief モンスターからモンスターへの直接攻撃を実行する
+ * @param target_ptr プレーヤーへの参照ポインタ
+ * @param m_idx モンスターID
+ * @param g_ptr グリッドへの参照ポインタ
+ */
+static bool exe_monster_attack_to_monster(player_type *target_ptr, MONSTER_IDX m_idx, grid_type *g_ptr)
+{
+       monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
+       monster_race *r_ptr = &r_info[m_ptr->r_idx];
+       monster_type *y_ptr;
+       y_ptr = &target_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
+       if ((r_ptr->flags1 & RF1_NEVER_BLOW) != 0) return FALSE;
+
+       if (((r_ptr->flags2 & RF2_KILL_BODY) == 0) && is_original_ap_and_seen(target_ptr, m_ptr))
+               r_ptr->r_flags2 |= (RF2_KILL_BODY);
+
+       if ((y_ptr->r_idx == 0) || (y_ptr->hp < 0)) return FALSE;
+       if (monst_attack_monst(target_ptr, m_idx, g_ptr->m_idx)) return TRUE;
+       if ((d_info[target_ptr->dungeon_idx].flags1 & DF1_NO_MELEE) == 0) return FALSE;
+       if (MON_CONFUSED(m_ptr)) return TRUE;
+       if ((r_ptr->flags2 & RF2_STUPID) == 0) return FALSE;
+
+       if (is_original_ap_and_seen(target_ptr, m_ptr))
+               r_ptr->r_flags2 |= (RF2_STUPID);
+
+       return TRUE;
+}
+
+
+/*!
+  * @brief モンスターからモンスターへの攻撃処理
+  * @param target_ptr プレーヤーへの参照ポインタ
+  * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
+  * @param m_idx モンスターID
+  * @param g_ptr グリッドへの参照ポインタ
+  * @param can_cross モンスターが地形を踏破できるならばTRUE
+  * @return ターン消費が発生したらTRUE
+  */
+bool process_monster_attack_to_monster(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, grid_type *g_ptr, bool can_cross)
+{
+       monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
+       monster_race *r_ptr = &r_info[m_ptr->r_idx];
+       monster_type *y_ptr;
+       y_ptr = &target_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
+       if (!turn_flags_ptr->do_move || (g_ptr->m_idx == 0)) return FALSE;
+
+       monster_race *z_ptr = &r_info[y_ptr->r_idx];
+       turn_flags_ptr->do_move = FALSE;
+       if ((((r_ptr->flags2 & RF2_KILL_BODY) != 0) && ((r_ptr->flags1 & RF1_NEVER_BLOW) == 0) &&
+               (r_ptr->mexp * r_ptr->level > z_ptr->mexp * z_ptr->level) &&
+               can_cross && (g_ptr->m_idx != target_ptr->riding)) ||
+               are_enemies(target_ptr, m_ptr, y_ptr) || MON_CONFUSED(m_ptr))
+       {
+               return exe_monster_attack_to_monster(target_ptr, m_idx, g_ptr);
+       }
+
+       if (((r_ptr->flags2 & RF2_MOVE_BODY) != 0) && ((r_ptr->flags1 & RF1_NEVER_MOVE) == 0) &&
+               (r_ptr->mexp > z_ptr->mexp) &&
+               can_cross && (g_ptr->m_idx != target_ptr->riding) &&
+               monster_can_cross_terrain(target_ptr, target_ptr->current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, z_ptr, 0))
+       {
+               turn_flags_ptr->do_move = TRUE;
+               turn_flags_ptr->did_move_body = TRUE;
+               (void)set_monster_csleep(target_ptr, g_ptr->m_idx, 0);
+       }
+
+       return FALSE;
+}
diff --git a/src/monster/monster-attack.h b/src/monster/monster-attack.h
new file mode 100644 (file)
index 0000000..a462d46
--- /dev/null
@@ -0,0 +1,7 @@
+#pragma once
+
+#include "angband.h"
+#include "monster/monster-util.h"
+
+void exe_monster_attack_to_player(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx);
+bool process_monster_attack_to_monster(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, grid_type *g_ptr, bool can_cross);