From 52bf2604c41538620933e401d51693111c2f0c9b Mon Sep 17 00:00:00 2001 From: Hourier Date: Sat, 8 Aug 2020 14:01:53 +0900 Subject: [PATCH] [Refactor] #39010 Separated check_what_throw() from do_cmd_throw() --- src/action/throw-util.c | 6 +++- src/action/throw-util.h | 6 +++- src/cmd-item/cmd-throw.c | 80 +++++++++++++++++++++++++++++------------------- 3 files changed, 58 insertions(+), 34 deletions(-) diff --git a/src/action/throw-util.c b/src/action/throw-util.c index c020821bc..5ed84c12e 100644 --- a/src/action/throw-util.c +++ b/src/action/throw-util.c @@ -1,7 +1,11 @@ #include "action/throw-util.h" -it_type *initialize_it_type(it_type *item_throw_ptr, object_type *q_ptr, const int delay_factor_val) +it_type *initialize_it_type( + it_type *item_throw_ptr, object_type *q_ptr, const int delay_factor_val, const int mult, const bool boomerang, const OBJECT_IDX shuriken) { + item_throw_ptr->mult = mult; + item_throw_ptr->boomerang = boomerang; + item_throw_ptr->shuriken = shuriken; item_throw_ptr->q_ptr = q_ptr; item_throw_ptr->hit_body = FALSE; item_throw_ptr->hit_wall = FALSE; diff --git a/src/action/throw-util.h b/src/action/throw-util.h index b3128ecff..67fdb16a3 100644 --- a/src/action/throw-util.h +++ b/src/action/throw-util.h @@ -5,6 +5,9 @@ // Item Throw. typedef struct it_type { + int mult; + bool boomerang; + OBJECT_IDX shuriken; OBJECT_IDX item; POSITION y; POSITION x; @@ -33,4 +36,5 @@ typedef struct it_type { bool do_drop; } it_type; -it_type *initialize_it_type(it_type *item_throw_ptr, object_type *q_ptr, const int delay_factor_val); +it_type *initialize_it_type( + it_type *item_throw_ptr, object_type *q_ptr, const int delay_factor_val, const int mult, const bool boomerang, const OBJECT_IDX shuriken); diff --git a/src/cmd-item/cmd-throw.c b/src/cmd-item/cmd-throw.c index 5623ec2c7..66ed982fd 100644 --- a/src/cmd-item/cmd-throw.c +++ b/src/cmd-item/cmd-throw.c @@ -58,6 +58,51 @@ #include "view/object-describer.h" #include "wizard/wizard-messages.h" +static bool check_what_throw(player_type *creature_ptr, it_type *it_ptr) +{ + if (it_ptr->shuriken >= 0) { + it_ptr->item = it_ptr->shuriken; + it_ptr->o_ptr = &creature_ptr->inventory_list[it_ptr->item]; + return TRUE; + } + + concptr q, s; + if (it_ptr->boomerang) { + if (has_melee_weapon(creature_ptr, INVEN_RARM) && has_melee_weapon(creature_ptr, INVEN_LARM)) { + item_tester_hook = item_tester_hook_boomerang; + q = _("どの武器を投げますか? ", "Throw which it_ptr->item? "); + s = _("投げる武器がない。", "You have nothing to throw."); + it_ptr->o_ptr = choose_object(creature_ptr, &it_ptr->item, q, s, USE_EQUIP, 0); + if (!it_ptr->o_ptr) { + flush(); + return FALSE; + } + + return TRUE; + } + + if (has_melee_weapon(creature_ptr, INVEN_LARM)) { + it_ptr->item = INVEN_LARM; + it_ptr->o_ptr = &creature_ptr->inventory_list[it_ptr->item]; + return TRUE; + } + + it_ptr->item = INVEN_RARM; + it_ptr->o_ptr = &creature_ptr->inventory_list[it_ptr->item]; + return TRUE; + } + + q = _("どのアイテムを投げますか? ", "Throw which it_ptr->item? "); + s = _("投げるアイテムがない。", "You have nothing to throw."); + it_ptr->o_ptr = choose_object(creature_ptr, &it_ptr->item, q, s, USE_INVEN | USE_FLOOR | USE_EQUIP, 0); + if (!it_ptr->o_ptr) { + flush(); + return FALSE; + } + + return TRUE; +} + /*! * @brief 投射処理メインルーチン / * Throw an object from the pack or floor. @@ -85,38 +130,9 @@ bool do_cmd_throw(player_type *creature_ptr, int mult, bool boomerang, OBJECT_ID it_type tmp_it; object_type tmp_object; - it_type *it_ptr = initialize_it_type(&tmp_it, &tmp_object, delay_factor); - - concptr q, s; - if (shuriken >= 0) { - it_ptr->item = shuriken; - it_ptr->o_ptr = &creature_ptr->inventory_list[it_ptr->item]; - } else if (boomerang) { - if (has_melee_weapon(creature_ptr, INVEN_RARM) && has_melee_weapon(creature_ptr, INVEN_LARM)) { - item_tester_hook = item_tester_hook_boomerang; - q = _("どの武器を投げますか? ", "Throw which it_ptr->item? "); - s = _("投げる武器がない。", "You have nothing to throw."); - it_ptr->o_ptr = choose_object(creature_ptr, &it_ptr->item, q, s, USE_EQUIP, 0); - if (!it_ptr->o_ptr) { - flush(); - return FALSE; - } - } else if (has_melee_weapon(creature_ptr, INVEN_LARM)) { - it_ptr->item = INVEN_LARM; - it_ptr->o_ptr = &creature_ptr->inventory_list[it_ptr->item]; - } else { - it_ptr->item = INVEN_RARM; - it_ptr->o_ptr = &creature_ptr->inventory_list[it_ptr->item]; - } - } else { - q = _("どのアイテムを投げますか? ", "Throw which it_ptr->item? "); - s = _("投げるアイテムがない。", "You have nothing to throw."); - it_ptr->o_ptr = choose_object(creature_ptr, &it_ptr->item, q, s, USE_INVEN | USE_FLOOR | USE_EQUIP, 0); - if (!it_ptr->o_ptr) { - flush(); - return FALSE; - } - } + it_type *it_ptr = initialize_it_type(&tmp_it, &tmp_object, delay_factor, mult, boomerang, shuriken); + if (!check_what_throw(creature_ptr, it_ptr)) + return FALSE; if (object_is_cursed(it_ptr->o_ptr) && (it_ptr->item >= INVEN_RARM)) { msg_print(_("ふーむ、どうやら呪われているようだ。", "Hmmm, it seems to be cursed.")); -- 2.11.0