OSDN Git Service

[Refactor] #40416 Separated blood-sucking-processor.c/h from player-attack.c
authorHourier <hourier@users.sourceforge.jp>
Sat, 23 May 2020 10:32:26 +0000 (19:32 +0900)
committerHourier <hourier@users.sourceforge.jp>
Sat, 23 May 2020 10:32:26 +0000 (19:32 +0900)
Hengband/Hengband/Hengband.vcxproj
Hengband/Hengband/Hengband.vcxproj.filters
src/Makefile.am
src/combat/blood-sucking-processor.c [new file with mode: 0644]
src/combat/blood-sucking-processor.h [new file with mode: 0644]
src/combat/player-attack.c

index af4d13c..8eccb37 100644 (file)
     <ClCompile Include="..\..\src\combat\attack-accuracy.c" />\r
     <ClCompile Include="..\..\src\combat\player-attack.c" />\r
     <ClCompile Include="..\..\src\combat\slaying.c" />\r
+    <ClCompile Include="..\..\src\combat\blood-sucking-processor.c" />\r
     <ClCompile Include="..\..\src\inventory\inventory-damage.c" />\r
     <ClCompile Include="..\..\src\io\pref-file-expressor.c" />\r
     <ClCompile Include="..\..\src\market\arena.c" />\r
     <ClInclude Include="..\..\src\cmd\cmd-menu-content-table.h" />\r
     <ClInclude Include="..\..\src\combat\attack-criticality.h" />\r
     <ClInclude Include="..\..\src\combat\attack-power-table.h" />\r
+    <ClInclude Include="..\..\src\combat\blood-sucking-processor.h" />\r
     <ClInclude Include="..\..\src\combat\combat-options-type.h" />\r
     <ClInclude Include="..\..\src\combat\hallucination-attacks-table.h" />\r
     <ClInclude Include="..\..\src\combat\insults-moans.h" />\r
index ca9153a..e8a2a12 100644 (file)
     <ClCompile Include="..\..\src\mind\monk-attack.c">
       <Filter>mind</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\combat\blood-sucking-processor.c">
+      <Filter>combat</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\src\cmd\cmd-activate.h">
     <ClInclude Include="..\..\src\mind\monk-attack.h">
       <Filter>mind</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\combat\blood-sucking-processor.h">
+      <Filter>combat</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\src\wall.bmp" />
index 33314b6..0548fc6 100644 (file)
@@ -352,6 +352,7 @@ hengband_SOURCES = \
        combat/combat-options-type.h \
        combat/attack-criticality.c combat/attack-criticality.h \
        combat/player-attack.c combat/player-attack.h \
+       combat/blood-sucking-processor.c combat/blood-sucking-processor.h \
        combat/shoot.c combat/shoot.h \
        combat/snipe.c combat/snipe.h \
        \
diff --git a/src/combat/blood-sucking-processor.c b/src/combat/blood-sucking-processor.c
new file mode 100644 (file)
index 0000000..3276dbf
--- /dev/null
@@ -0,0 +1,135 @@
+/*!
+ * @brief 吸血処理
+ * @date 2020/05/23
+ * @author Hourier
+ */
+
+#include "combat/blood-sucking-processor.h"
+#include "object/artifact.h"
+#include "player/player-effects.h"
+#include "realm/realm-hex.h"
+
+/*!
+ * @brief 吸血量を計算する
+ * @param pa_ptr 直接攻撃構造体への参照ポインタ
+ * @return なし
+ */
+void calc_drain(player_attack_type *pa_ptr)
+{
+    if (pa_ptr->attack_damage <= 0)
+        pa_ptr->can_drain = FALSE;
+
+    if (pa_ptr->drain_result > pa_ptr->m_ptr->hp)
+        pa_ptr->drain_result = pa_ptr->m_ptr->hp;
+}
+
+/*!
+ * @brief 村正による吸血処理
+ * @param attacker_ptr プレーヤーへの参照ポインタ
+ * @param pa_ptr 直接攻撃構造体への参照ポインタ
+ * @param is_human モンスターが人間かどうか
+ * @return なし
+ */
+static void drain_muramasa(player_type *attacker_ptr, player_attack_type *pa_ptr, const bool is_human)
+{
+    if (!is_human)
+        return;
+
+    object_type *o_ptr = &attacker_ptr->inventory_list[INVEN_RARM + pa_ptr->hand];
+    HIT_PROB to_h = o_ptr->to_h;
+    HIT_POINT to_d = o_ptr->to_d;
+    bool flag = TRUE;
+    for (int i = 0; i < to_h + 3; i++)
+        if (one_in_(4))
+            flag = FALSE;
+
+    if (flag)
+        to_h++;
+
+    flag = TRUE;
+    for (int i = 0; i < to_d + 3; i++)
+        if (one_in_(4))
+            flag = FALSE;
+
+    if (flag)
+        to_d++;
+
+    if ((o_ptr->to_h == to_h) && (o_ptr->to_d == to_d))
+        return;
+
+    msg_print(_("妖刀は血を吸って強くなった!", "Muramasa sucked blood, and became more powerful!"));
+    o_ptr->to_h = to_h;
+    o_ptr->to_d = to_d;
+}
+
+/*!
+ * @brief 吸血武器による吸血処理
+ * @param attacker_ptr プレーヤーへの参照ポインタ
+ * @param pa_ptr 直接攻撃構造体への参照ポインタ
+ * @param drain_msg 吸血をした旨のメッセージを表示するかどうか
+ * @return なし
+ * @details 1行目の5がマジックナンバーで良く分からなかったので、取り敢えず元々あったコメントをベースに定数宣言しておいた
+ */
+static void drain_result(player_type *attacker_ptr, player_attack_type *pa_ptr, bool *drain_msg)
+{
+    const int real_drain = 5;
+    if (pa_ptr->drain_result <= real_drain)
+        return;
+
+    int drain_heal = damroll(2, pa_ptr->drain_result / 6);
+
+    if (hex_spelling(attacker_ptr, HEX_VAMP_BLADE))
+        drain_heal *= 2;
+
+    if (cheat_xtra) {
+        msg_format(_("Draining left: %d", "Draining left: %d"), pa_ptr->drain_left);
+    }
+
+    if (pa_ptr->drain_left == 0)
+        return;
+
+    if (drain_heal < pa_ptr->drain_left) {
+        pa_ptr->drain_left -= drain_heal;
+    } else {
+        drain_heal = pa_ptr->drain_left;
+        pa_ptr->drain_left = 0;
+    }
+
+    if (*drain_msg) {
+        msg_format(_("刃が%sから生命力を吸い取った!", "Your weapon drains life from %s!"), pa_ptr->m_name);
+        *drain_msg = FALSE;
+    }
+
+    drain_heal = (drain_heal * attacker_ptr->mutant_regenerate_mod) / 100;
+    hp_player(attacker_ptr, drain_heal);
+}
+
+/*!
+ * @brief 吸血処理のメインルーチン
+ * @param attacker_ptr プレーヤーへの参照ポインタ
+ * @param pa_ptr 直接攻撃構造体への参照ポインタ
+ * @param is_human 人間かどうか(村正用フラグ)
+ * @param drain_msg 吸血をした旨のメッセージを表示するかどうか
+ * @return なし
+ * @details モンスターが死んだ場合、(ゲームのフレーバー的に)吸血しない
+ */
+void process_drain(player_type *attacker_ptr, player_attack_type *pa_ptr, const bool is_human, bool *drain_msg)
+{
+    if (!pa_ptr->can_drain || (pa_ptr->drain_result <= 0))
+        return;
+
+    object_type *o_ptr = &attacker_ptr->inventory_list[INVEN_RARM + pa_ptr->hand];
+    if (o_ptr->name1 == ART_MURAMASA)
+        drain_muramasa(attacker_ptr, pa_ptr, is_human);
+    else
+        drain_result(attacker_ptr, pa_ptr, drain_msg);
+
+    pa_ptr->m_ptr->maxhp -= (pa_ptr->attack_damage + 7) / 8;
+    if (pa_ptr->m_ptr->hp > pa_ptr->m_ptr->maxhp)
+        pa_ptr->m_ptr->hp = pa_ptr->m_ptr->maxhp;
+
+    if (pa_ptr->m_ptr->maxhp < 1)
+        pa_ptr->m_ptr->maxhp = 1;
+
+    pa_ptr->weak = TRUE;
+}
diff --git a/src/combat/blood-sucking-processor.h b/src/combat/blood-sucking-processor.h
new file mode 100644 (file)
index 0000000..4c9bc11
--- /dev/null
@@ -0,0 +1,7 @@
+#pragma once
+
+#include "system/angband.h"
+#include "combat/player-attack-util.h"
+
+void calc_drain(player_attack_type *pa_ptr);
+void process_drain(player_type *attacker_ptr, player_attack_type *pa_ptr, const bool is_human, bool *drain_msg);
index 99d9c1d..42210da 100644 (file)
@@ -7,6 +7,7 @@
 #include "combat/player-attack.h"
 #include "combat/attack-accuracy.h"
 #include "combat/attack-criticality.h"
+#include "combat/blood-sucking-processor.h"
 #include "combat/martial-arts-table.h"
 #include "combat/player-attack-util.h"
 #include "combat/slaying.h"
@@ -22,7 +23,6 @@
 #include "object/object-hook.h"
 #include "player/avatar.h"
 #include "player/player-damage.h"
-#include "player/player-effects.h"
 #include "player/player-skill.h"
 #include "realm/realm-hex.h"
 #include "spell/spells-floor.h"
@@ -466,131 +466,6 @@ static bool check_fear_death(player_type *attacker_ptr, player_attack_type *pa_p
 }
 
 /*!
- * @brief 吸血量を計算する
- * @param pa_ptr 直接攻撃構造体への参照ポインタ
- * @return なし
- */
-static void calc_drain(player_attack_type *pa_ptr)
-{
-    if (pa_ptr->attack_damage <= 0)
-        pa_ptr->can_drain = FALSE;
-
-    if (pa_ptr->drain_result > pa_ptr->m_ptr->hp)
-        pa_ptr->drain_result = pa_ptr->m_ptr->hp;
-}
-
-/*!
- * @brief 村正による吸血処理
- * @param attacker_ptr プレーヤーへの参照ポインタ
- * @param pa_ptr 直接攻撃構造体への参照ポインタ
- * @param is_human モンスターが人間かどうか
- * @return なし
- */
-static void drain_muramasa(player_type *attacker_ptr, player_attack_type *pa_ptr, const bool is_human)
-{
-    if (!is_human)
-        return;
-
-    object_type *o_ptr = &attacker_ptr->inventory_list[INVEN_RARM + pa_ptr->hand];
-    HIT_PROB to_h = o_ptr->to_h;
-    HIT_POINT to_d = o_ptr->to_d;
-    bool flag = TRUE;
-    for (int i = 0; i < to_h + 3; i++)
-        if (one_in_(4))
-            flag = FALSE;
-
-    if (flag)
-        to_h++;
-
-    flag = TRUE;
-    for (int i = 0; i < to_d + 3; i++)
-        if (one_in_(4))
-            flag = FALSE;
-
-    if (flag)
-        to_d++;
-
-    if ((o_ptr->to_h == to_h) && (o_ptr->to_d == to_d))
-        return;
-
-    msg_print(_("妖刀は血を吸って強くなった!", "Muramasa sucked blood, and became more powerful!"));
-    o_ptr->to_h = to_h;
-    o_ptr->to_d = to_d;
-}
-
-/*!
- * @brief 吸血武器による吸血処理
- * @param attacker_ptr プレーヤーへの参照ポインタ
- * @param pa_ptr 直接攻撃構造体への参照ポインタ
- * @param drain_msg 吸血をした旨のメッセージを表示するかどうか
- * @return なし
- * @details 1行目の5がマジックナンバーで良く分からなかったので、取り敢えず元々あったコメントをベースに定数宣言しておいた
- */
-static void drain_result(player_type *attacker_ptr, player_attack_type *pa_ptr, bool *drain_msg)
-{
-    const int real_drain = 5;
-    if (pa_ptr->drain_result <= real_drain)
-        return;
-
-    int drain_heal = damroll(2, pa_ptr->drain_result / 6);
-
-    if (hex_spelling(attacker_ptr, HEX_VAMP_BLADE))
-        drain_heal *= 2;
-
-    if (cheat_xtra) {
-        msg_format(_("Draining left: %d", "Draining left: %d"), pa_ptr->drain_left);
-    }
-
-    if (pa_ptr->drain_left == 0)
-        return;
-
-    if (drain_heal < pa_ptr->drain_left) {
-        pa_ptr->drain_left -= drain_heal;
-    } else {
-        drain_heal = pa_ptr->drain_left;
-        pa_ptr->drain_left = 0;
-    }
-
-    if (*drain_msg) {
-        msg_format(_("刃が%sから生命力を吸い取った!", "Your weapon drains life from %s!"), pa_ptr->m_name);
-        *drain_msg = FALSE;
-    }
-
-    drain_heal = (drain_heal * attacker_ptr->mutant_regenerate_mod) / 100;
-    hp_player(attacker_ptr, drain_heal);
-}
-
-/*!
- * @brief 吸血処理のメインルーチン
- * @param attacker_ptr プレーヤーへの参照ポインタ
- * @param pa_ptr 直接攻撃構造体への参照ポインタ
- * @param is_human 人間かどうか(村正用フラグ)
- * @param drain_msg 吸血をした旨のメッセージを表示するかどうか
- * @return なし
- * @details モンスターが死んだ場合、(ゲームのフレーバー的に)吸血しない
- */
-static void process_drain(player_type *attacker_ptr, player_attack_type *pa_ptr, const bool is_human, bool *drain_msg)
-{
-    if (!pa_ptr->can_drain || (pa_ptr->drain_result <= 0))
-        return;
-
-    object_type *o_ptr = &attacker_ptr->inventory_list[INVEN_RARM + pa_ptr->hand];
-    if (o_ptr->name1 == ART_MURAMASA)
-        drain_muramasa(attacker_ptr, pa_ptr, is_human);
-    else
-        drain_result(attacker_ptr, pa_ptr, drain_msg);
-
-    pa_ptr->m_ptr->maxhp -= (pa_ptr->attack_damage + 7) / 8;
-    if (pa_ptr->m_ptr->hp > pa_ptr->m_ptr->maxhp)
-        pa_ptr->m_ptr->hp = pa_ptr->m_ptr->maxhp;
-
-    if (pa_ptr->m_ptr->maxhp < 1)
-        pa_ptr->m_ptr->maxhp = 1;
-
-    pa_ptr->weak = TRUE;
-}
-
-/*!
  * @brief プレイヤーの打撃処理サブルーチン /
  * Player attacks a (poor, defenseless) creature        -RAK-
  * @param y 攻撃目標のY座標