From f73c3b58867c46cf4adc347f66e6a38583ba2780 Mon Sep 17 00:00:00 2001 From: Deskull Date: Sat, 12 Jan 2019 18:07:17 +0900 Subject: [PATCH] =?utf8?q?[Refactor]=20#38824=20get=5Fitem()=20=E3=82=92?= =?utf8?q?=20choose=5Fobject()=20=E3=81=AB=E7=BD=AE=E6=8F=9B=E5=AE=8C?= =?utf8?q?=E4=BA=86=E3=80=82=20/=20Replaced=20get=5Fitem()=20to=20choose?= =?utf8?q?=5Fobject().?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/racial.c | 2 +- src/spells-summon.c | 15 ++------- src/spells3.c | 93 ++++++++--------------------------------------------- src/store.c | 17 ++-------- src/wizard2.c | 16 ++------- 5 files changed, 21 insertions(+), 122 deletions(-) diff --git a/src/racial.c b/src/racial.c index f0852e576..ae869d246 100644 --- a/src/racial.c +++ b/src/racial.c @@ -240,7 +240,7 @@ bool gain_magic(void) q = _("どのアイテムの魔力を取り込みますか? ", "Gain power of which item? "); s = _("魔力を取り込めるアイテムがない。", "You have nothing to gain power."); - o_ptr = choose_item(&item, q, s, (USE_INVEN | USE_FLOOR)); + o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR)); if (!o_ptr) return (FALSE); if (o_ptr->tval == TV_STAFF && o_ptr->sval == SV_STAFF_NOTHING) diff --git a/src/spells-summon.c b/src/spells-summon.c index 4b1ea0ab6..550a51fac 100644 --- a/src/spells-summon.c +++ b/src/spells-summon.c @@ -120,19 +120,8 @@ bool cast_summon_greater_demon(void) item_tester_hook = item_tester_offer; q = _("どの死体を捧げますか? ", "Sacrifice which corpse? "); s = _("捧げられる死体を持っていない。", "You have nothing to scrifice."); - if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return FALSE; - - /* Get the item (in the pack) */ - if (item >= 0) - { - o_ptr = &inventory[item]; - } - - /* Get the item (on the floor) */ - else - { - o_ptr = &o_list[0 - item]; - } + o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR)); + if (!o_ptr) return FALSE; summon_lev = plev * 2 / 3 + r_info[o_ptr->pval].level; diff --git a/src/spells3.c b/src/spells3.c index a01dd11e4..450cf071c 100644 --- a/src/spells3.c +++ b/src/spells3.c @@ -2139,7 +2139,7 @@ bool enchant_spell(HIT_PROB num_hit, HIT_POINT num_dam, ARMOUR_CLASS num_ac) q = _("どのアイテムを強化しますか? ", "Enchant which item? "); s = _("強化できるアイテムがない。", "You have nothing to enchant."); - o_ptr = get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT)); + o_ptr = choose_object(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT)); if (!o_ptr) return (FALSE); object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY)); @@ -2479,19 +2479,8 @@ bool identify_fully(bool only_equip) s = _("*鑑定*するべきアイテムがない。", "You have nothing to *identify*."); - if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT))) return (FALSE); - - /* Get the item (in the pack) */ - if (item >= 0) - { - o_ptr = &inventory[item]; - } - - /* Get the item (on the floor) */ - else - { - o_ptr = &o_list[0 - item]; - } + o_ptr = choose_object(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT)); + if (!o_ptr) return (FALSE); old_known = identify_item(o_ptr); @@ -2567,19 +2556,8 @@ bool recharge(int power) q = _("どのアイテムに魔力を充填しますか? ", "Recharge which item? "); s = _("魔力を充填すべきアイテムがない。", "You have nothing to recharge."); - if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return (FALSE); - - /* Get the item (in the pack) */ - if (item >= 0) - { - o_ptr = &inventory[item]; - } - - /* Get the item (on the floor) */ - else - { - o_ptr = &o_list[0 - item]; - } + o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR)); + if (!o_ptr) return (FALSE); /* Get the object kind. */ k_ptr = &k_info[o_ptr->k_idx]; @@ -2849,20 +2827,8 @@ bool bless_weapon(void) q = _("どのアイテムを祝福しますか?", "Bless which weapon? "); s = _("祝福できる武器がありません。", "You have weapon to bless."); - if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT))) - return FALSE; - - /* Get the item (in the pack) */ - if (item >= 0) - { - o_ptr = &inventory[item]; - } - - /* Get the item (on the floor) */ - else - { - o_ptr = &o_list[0 - item]; - } + o_ptr = choose_object(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT)); + if (!o_ptr) return FALSE; object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY)); @@ -3012,20 +2978,8 @@ bool pulish_shield(void) q = _("どの盾を磨きますか?", "Pulish which weapon? "); s = _("磨く盾がありません。", "You have weapon to pulish."); - if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT))) - return FALSE; - - /* Get the item (in the pack) */ - if (item >= 0) - { - o_ptr = &inventory[item]; - } - - /* Get the item (on the floor) */ - else - { - o_ptr = &o_list[0 - item]; - } + o_ptr = choose_object(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT)); + if (!o_ptr) return FALSE; object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY)); @@ -3891,7 +3845,7 @@ bool rustproof(void) OBJECT_IDX item; object_type *o_ptr; GAME_TEXT o_name[MAX_NLEN]; - cptr q, s; + cptr q, s; /* Select a piece of armour */ item_tester_hook = object_is_armour; @@ -3899,19 +3853,8 @@ bool rustproof(void) q = _("どの防具に錆止めをしますか?", "Rustproof which piece of armour? "); s = _("錆止めできるものがありません。", "You have nothing to rustproof."); - if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT))) return FALSE; - - /* Get the item (in the pack) */ - if (item >= 0) - { - o_ptr = &inventory[item]; - } - - /* Get the item (on the floor) */ - else - { - o_ptr = &o_list[0 - item]; - } + o_ptr = choose_object(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT)); + if (!o_ptr) return FALSE; object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY)); @@ -4380,16 +4323,8 @@ bool eat_magic(int power) q = _("どのアイテムから魔力を吸収しますか?", "Drain which item? "); s = _("魔力を吸収できるアイテムがありません。", "You have nothing to drain."); - if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return FALSE; - - if (item >= 0) - { - o_ptr = &inventory[item]; - } - else - { - o_ptr = &o_list[0 - item]; - } + o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR)); + if (!o_ptr) return FALSE; k_ptr = &k_info[o_ptr->k_idx]; lev = k_info[o_ptr->k_idx].level; diff --git a/src/store.c b/src/store.c index c3ed0bfa4..2114f7b97 100644 --- a/src/store.c +++ b/src/store.c @@ -3763,20 +3763,8 @@ static void store_sell(void) s = _("欲しい物がないですねえ。", "You have nothing that I want."); } - if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT))) return; - - /* Get the item (in the pack) */ - if (item >= 0) - { - o_ptr = &inventory[item]; - } - - /* Get the item (on the floor) */ - else - { - o_ptr = &o_list[0 - item]; - } - + o_ptr = choose_object(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT)); + if (!o_ptr) return; /* Hack -- Cannot remove cursed items */ if ((item >= INVEN_RARM) && object_is_cursed(o_ptr)) @@ -3785,7 +3773,6 @@ static void store_sell(void) return; } - /* Assume one item */ amt = 1; diff --git a/src/wizard2.c b/src/wizard2.c index a8b6a2e8d..885f658b8 100644 --- a/src/wizard2.c +++ b/src/wizard2.c @@ -1247,28 +1247,16 @@ static void do_cmd_wiz_play(void) object_type forge; object_type *q_ptr; object_type *o_ptr; - char ch; - bool changed; - cptr q, s; q = "Play with which object? "; s = "You have nothing to play with."; - if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT))) return; - /* Get the item (in the pack) */ - if (item >= 0) - { - o_ptr = &inventory[item]; - } + o_ptr = choose_object(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT)); - /* Get the item (on the floor) */ - else - { - o_ptr = &o_list[0 - item]; - } + if (!o_ptr) return; /* The item was not changed */ changed = FALSE; -- 2.11.0