From 2a7749287d20c3b2a1502f6725ce6d295d4278cf Mon Sep 17 00:00:00 2001 From: Hourier Date: Fri, 20 Aug 2021 00:23:34 +0900 Subject: [PATCH] [Refactor] #1370 Moved calc_throw_grid() from cmd-throw.cpp to throw-util.cpp/h --- src/action/throw-util.cpp | 28 ++++++++++++++++++++++++++++ src/action/throw-util.h | 1 + src/cmd-item/cmd-throw.cpp | 26 +------------------------- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/action/throw-util.cpp b/src/action/throw-util.cpp index 46b5d4dc9..ca9422452 100644 --- a/src/action/throw-util.cpp +++ b/src/action/throw-util.cpp @@ -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) { diff --git a/src/action/throw-util.h b/src/action/throw-util.h index bb317c6a7..e564df58e 100644 --- a/src/action/throw-util.h +++ b/src/action/throw-util.h @@ -55,6 +55,7 @@ public: bool check_can_throw(); void calc_throw_range(); + bool calc_throw_grid(); private: player_type *creature_ptr; diff --git a/src/cmd-item/cmd-throw.cpp b/src/cmd-item/cmd-throw.cpp index 7ba3497ac..15b8c71bb 100644 --- a/src/cmd-item/cmd-throw.cpp +++ b/src/cmd-item/cmd-throw.cpp @@ -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); -- 2.11.0