OSDN Git Service

[Refactor] #1370 Moved calc_throw_grid() from cmd-throw.cpp to throw-util.cpp/h
authorHourier <grapefox.whitelucifer.0408@gmail.com>
Thu, 19 Aug 2021 15:23:34 +0000 (00:23 +0900)
committerHourier <grapefox.whitelucifer.0408@gmail.com>
Thu, 19 Aug 2021 15:23:34 +0000 (00:23 +0900)
src/action/throw-util.cpp
src/action/throw-util.h
src/cmd-item/cmd-throw.cpp

index 46b5d4d..ca94224 100644 (file)
@@ -7,9 +7,11 @@
 
 #include "action/throw-util.h"
 #include "combat/attack-power-table.h"
+#include "effect/spells-effect-util.h"
 #include "flavor/flavor-describer.h"
 #include "flavor/object-flavor-types.h"
 #include "floor/floor-object.h"
+#include "floor/geometry.h"
 #include "inventory/inventory-slot-types.h"
 #include "object-enchant/tr-types.h"
 #include "object-hook/hook-checker.h"
@@ -23,6 +25,8 @@
 #include "system/floor-type-definition.h"
 #include "system/object-type-definition.h"
 #include "system/player-type-definition.h"
+#include "target/target-checker.h"
+#include "target/target-getter.h"
 #include "term/screen-processor.h"
 #include "util/bit-flags-calculator.h"
 #include "view/display-messages.h"
@@ -77,6 +81,30 @@ void it_type::calc_throw_range()
         this->tdis = mul;
 }
 
+bool it_type::calc_throw_grid()
+{
+    if (this->shuriken >= 0) {
+        this->ty = randint0(101) - 50 + this->creature_ptr->y;
+        this->tx = randint0(101) - 50 + this->creature_ptr->x;
+        return true;
+    }
+
+    project_length = this->tdis + 1;
+    DIRECTION dir;
+    if (!get_aim_dir(this->creature_ptr, &dir))
+        return false;
+
+    this->tx = this->creature_ptr->x + 99 * ddx[dir];
+    this->ty = this->creature_ptr->y + 99 * ddy[dir];
+    if ((dir == 5) && target_okay(this->creature_ptr)) {
+        this->tx = target_col;
+        this->ty = target_row;
+    }
+
+    project_length = 0;
+    return true;
+}
+
 bool it_type::check_what_throw()
 {
     if (this->shuriken >= 0) {
index bb317c6..e564df5 100644 (file)
@@ -55,6 +55,7 @@ public:
 
     bool check_can_throw();
     void calc_throw_range();
+    bool calc_throw_grid();
 
 private:
     player_type *creature_ptr;
index 7ba3497..15b8c71 100644 (file)
@@ -70,30 +70,6 @@ ThrowCommand::ThrowCommand(player_type* creature_ptr)
 {
 }
 
-static bool calc_throw_grid(player_type *creature_ptr, it_type *it_ptr)
-{
-    if (it_ptr->shuriken >= 0) {
-        it_ptr->ty = randint0(101) - 50 + creature_ptr->y;
-        it_ptr->tx = randint0(101) - 50 + creature_ptr->x;
-        return true;
-    }
-
-    project_length = it_ptr->tdis + 1;
-    DIRECTION dir;
-    if (!get_aim_dir(creature_ptr, &dir))
-        return false;
-
-    it_ptr->tx = creature_ptr->x + 99 * ddx[dir];
-    it_ptr->ty = creature_ptr->y + 99 * ddy[dir];
-    if ((dir == 5) && target_okay(creature_ptr)) {
-        it_ptr->tx = target_col;
-        it_ptr->ty = target_row;
-    }
-
-    project_length = 0;
-    return true;
-}
-
 static void reflect_inventory_by_throw(player_type *creature_ptr, it_type *it_ptr)
 {
     if ((it_ptr->q_ptr->name1 == ART_MJOLLNIR) || (it_ptr->q_ptr->name1 == ART_AEGISFANG) || it_ptr->boomerang)
@@ -454,7 +430,7 @@ bool ThrowCommand::do_cmd_throw(int mult, bool boomerang, OBJECT_IDX shuriken)
         return false;
 
     it_ptr->calc_throw_range();
-    if (!calc_throw_grid(this->creature_ptr, it_ptr))
+    if (!it_ptr->calc_throw_grid())
         return false;
 
     reflect_inventory_by_throw(this->creature_ptr, it_ptr);