From cfdd59a3131b0c639074b00bdde3145148f02a1b Mon Sep 17 00:00:00 2001 From: Habu Date: Fri, 3 Sep 2021 00:15:27 +0900 Subject: [PATCH] =?utf8?q?[Refactor]=20=E4=B8=A1=E6=89=8B=E3=81=AE?= =?utf8?q?=E8=A3=85=E5=82=99=E3=81=AB=E3=82=A2=E3=82=AF=E3=82=BB=E3=82=B9?= =?utf8?q?=E3=81=99=E3=82=8B=E3=83=9D=E3=82=A4=E3=83=B3=E3=82=BF=E5=A4=89?= =?utf8?q?=E6=95=B0=E3=82=92=E4=BD=BF=E7=94=A8=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 何度も creature_ptr->inventory_list[INVEN_*_HAND] が出てきて読みづらい ので、一旦ポインタ変数に受けておき、ポインタ変数経由でアクセスする。 --- src/cmd-item/cmd-equipment.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/cmd-item/cmd-equipment.cpp b/src/cmd-item/cmd-equipment.cpp index b2771358e..a6382a56b 100644 --- a/src/cmd-item/cmd-equipment.cpp +++ b/src/cmd-item/cmd-equipment.cpp @@ -108,6 +108,9 @@ void do_cmd_wield(player_type *creature_ptr) slot = wield_slot(creature_ptr, o_ptr); + const auto o_ptr_mh = &creature_ptr->inventory_list[INVEN_MAIN_HAND]; + const auto o_ptr_sh = &creature_ptr->inventory_list[INVEN_SUB_HAND]; + switch (o_ptr->tval) { case TV_CAPTURE: case TV_SHIELD: @@ -122,8 +125,7 @@ void do_cmd_wield(player_type *creature_ptr) need_switch_wielding = INVEN_SUB_HAND; } else if (has_melee_weapon(creature_ptr, INVEN_SUB_HAND)) slot = INVEN_MAIN_HAND; - else if (creature_ptr->inventory_list[INVEN_MAIN_HAND].k_idx && !object_is_melee_weapon(&creature_ptr->inventory_list[INVEN_MAIN_HAND]) - && creature_ptr->inventory_list[INVEN_SUB_HAND].k_idx && !object_is_melee_weapon(&creature_ptr->inventory_list[INVEN_SUB_HAND])) { + else if (o_ptr_mh->k_idx && !object_is_melee_weapon(o_ptr_mh) && o_ptr_sh->k_idx && !object_is_melee_weapon(o_ptr_sh)) { q = _("どちらの手に装備しますか?", "Equip which hand? "); s = _("おっと。", "Oops."); if (!choose_object(creature_ptr, &slot, q, s, (USE_EQUIP), FuncItemTester(object_is_mochikae))) @@ -138,10 +140,10 @@ void do_cmd_wield(player_type *creature_ptr) if (slot == INVEN_SUB_HAND) { if (!get_check(_("二刀流で戦いますか?", "Dual wielding? "))) slot = INVEN_MAIN_HAND; - } else if (!creature_ptr->inventory_list[INVEN_MAIN_HAND].k_idx && has_melee_weapon(creature_ptr, INVEN_SUB_HAND)) { + } else if (!o_ptr_mh->k_idx && has_melee_weapon(creature_ptr, INVEN_SUB_HAND)) { if (!get_check(_("二刀流で戦いますか?", "Dual wielding? "))) slot = INVEN_SUB_HAND; - } else if (creature_ptr->inventory_list[INVEN_SUB_HAND].k_idx && creature_ptr->inventory_list[INVEN_MAIN_HAND].k_idx) { + } else if (o_ptr_mh->k_idx && o_ptr_sh->k_idx) { q = _("どちらの手に装備しますか?", "Equip which hand? "); s = _("おっと。", "Oops."); if (!choose_object(creature_ptr, &slot, q, s, (USE_EQUIP), FuncItemTester(object_is_mochikae))) -- 2.11.0