OSDN Git Service

[Refactor] #37353 REF_ITEM マクロを各所に適用.
authordeskull <deskull@users.sourceforge.jp>
Thu, 1 Aug 2019 14:23:50 +0000 (23:23 +0900)
committerdeskull <deskull@users.sourceforge.jp>
Thu, 1 Aug 2019 14:23:50 +0000 (23:23 +0900)
src/autopick.c
src/cmd-eat.c
src/cmd-item.h
src/cmd-quaff.c
src/cmd-read.c
src/cmd-usestaff.c
src/cmd-zaprod.c
src/cmd-zapwand.c
src/object.h
src/player-inventory.c

index 2cd22b6..a6c8159 100644 (file)
@@ -1639,11 +1639,7 @@ static void autopick_delayed_alter_aux(INVENTORY_IDX item)
 {
        object_type *o_ptr;
 
-       /* Get the item (in the pack) */
-       if (item >= 0) o_ptr = &p_ptr->inventory_list[item];
-
-       /* Get the item (on the floor) */
-       else o_ptr = &current_floor_ptr->o_list[0 - item];
+       o_ptr = REF_ITEM(p_ptr, current_floor_ptr, item);
 
        if (o_ptr->k_idx && (o_ptr->marked & OM_AUTODESTROY))
        {
@@ -1706,11 +1702,7 @@ void autopick_alter_item(INVENTORY_IDX item, bool destroy)
        object_type *o_ptr;
        int idx;
 
-       /* Get the item (in the pack) */
-       if (item >= 0) o_ptr = &p_ptr->inventory_list[item];
-
-       /* Get the item (on the floor) */
-       else o_ptr = &current_floor_ptr->o_list[0 - item];
+       o_ptr = REF_ITEM(p_ptr, current_floor_ptr, item);
 
        /* Get the index in the auto-pick/destroy list */
        idx = is_autopick(o_ptr);
index 86ae694..cc8a67b 100644 (file)
@@ -38,18 +38,7 @@ void exe_eat_food(player_type *creature_ptr, INVENTORY_IDX item)
 
        if (music_singing_any(creature_ptr)) stop_singing(creature_ptr);
        if (hex_spelling_any(creature_ptr)) stop_hex_spell_all();
-
-       /* Get the item (in the pack) */
-       if (item >= 0)
-       {
-               o_ptr = &creature_ptr->inventory_list[item];
-       }
-
-       /* Get the item (on the floor) */
-       else
-       {
-               o_ptr = &current_floor_ptr->o_list[0 - item];
-       }
+       o_ptr = REF_ITEM(creature_ptr, current_floor_ptr, item);
 
        sound(SOUND_EAT);
 
index ff3753f..e205349 100644 (file)
@@ -1,7 +1,5 @@
 /* cmd3-item.h */
 
-#define REF_ITEM(P_PTR, FLOOR_PTR, ID) ((ID > 0 ? &(P_PTR)->inventory_list[ID] : &(FLOOR_PTR)->o_list[0 - item]))
-
 extern void do_cmd_inven(void);
 extern void do_cmd_equip(void);
 extern void do_cmd_wield(void);
index 8bb39d0..145fc40 100644 (file)
@@ -61,17 +61,7 @@ void exe_quaff_potion(INVENTORY_IDX item)
                if (!hex_spelling(HEX_INHAIL)) stop_hex_spell_all();
        }
 
-       /* Get the item (in the pack) */
-       if (item >= 0)
-       {
-               o_ptr = &p_ptr->inventory_list[item];
-       }
-
-       /* Get the item (on the floor) */
-       else
-       {
-               o_ptr = &current_floor_ptr->o_list[0 - item];
-       }
+       o_ptr = REF_ITEM(p_ptr, current_floor_ptr, item);
        q_ptr = &forge;
        object_copy(q_ptr, o_ptr);
 
index 9eb9860..672ed50 100644 (file)
@@ -51,18 +51,7 @@ void exe_read(INVENTORY_IDX item, bool known)
        int         k, used_up, ident, lev;
        object_type *o_ptr;
 
-
-       /* Get the item (in the pack) */
-       if (item >= 0)
-       {
-               o_ptr = &p_ptr->inventory_list[item];
-       }
-
-       /* Get the item (on the floor) */
-       else
-       {
-               o_ptr = &current_floor_ptr->o_list[0 - item];
-       }
+       o_ptr = REF_ITEM(p_ptr, current_floor_ptr, item);
 
        take_turn(p_ptr, 100);
        if (cmd_limit_time_walk(p_ptr)) return;
index 9ff446a..77a8e94 100644 (file)
@@ -289,19 +289,7 @@ void exe_use_staff(INVENTORY_IDX item)
        /* Hack -- let staffs of identify get aborted */
        bool use_charge = TRUE;
 
-
-       /* Get the item (in the pack) */
-       if (item >= 0)
-       {
-               o_ptr = &p_ptr->inventory_list[item];
-       }
-
-       /* Get the item (on the floor) */
-       else
-       {
-               o_ptr = &current_floor_ptr->o_list[0 - item];
-       }
-
+       o_ptr = REF_ITEM(p_ptr, current_floor_ptr, item);
 
        /* Mega-Hack -- refuse to use a pile from the ground */
        if ((item < 0) && (o_ptr->number > 1))
index 2012eb0..96f9527 100644 (file)
@@ -280,18 +280,7 @@ void exe_zap_rod(INVENTORY_IDX item)
 
        object_kind *k_ptr;
 
-       /* Get the item (in the pack) */
-       if (item >= 0)
-       {
-               o_ptr = &p_ptr->inventory_list[item];
-       }
-
-       /* Get the item (on the floor) */
-       else
-       {
-               o_ptr = &current_floor_ptr->o_list[0 - item];
-       }
-
+       o_ptr = REF_ITEM(p_ptr, current_floor_ptr, item);
 
        /* Mega-Hack -- refuse to zap a pile from the ground */
        if ((item < 0) && (o_ptr->number > 1))
index a4b3ce9..cc106e6 100644 (file)
@@ -334,17 +334,7 @@ void exe_aim_wand(INVENTORY_IDX item)
        object_type *o_ptr;
        bool old_target_pet = target_pet;
 
-       /* Get the item (in the pack) */
-       if (item >= 0)
-       {
-               o_ptr = &p_ptr->inventory_list[item];
-       }
-
-       /* Get the item (on the floor) */
-       else
-       {
-               o_ptr = &current_floor_ptr->o_list[0 - item];
-       }
+       o_ptr = REF_ITEM(p_ptr, current_floor_ptr, item);
 
        /* Mega-Hack -- refuse to aim a pile from the ground */
        if ((item < 0) && (o_ptr->number > 1))
index caf1e74..33b898f 100644 (file)
@@ -423,6 +423,9 @@ extern bool check_book_realm(const OBJECT_TYPE_VALUE book_tval, const OBJECT_SUB
 #define USE_FULL  0x20 /*!< アイテム表示/選択範囲: 空欄まですべて表示する*/
 extern bool can_get_item(OBJECT_TYPE_VALUE tval);
 extern bool get_item(OBJECT_IDX *cp, concptr pmt, concptr str, BIT_FLAGS mode, OBJECT_TYPE_VALUE tval);
+
+#define REF_ITEM(P_PTR, FLOOR_PTR, ID) ((ID > 0 ? &(P_PTR)->inventory_list[ID] : &(FLOOR_PTR)->o_list[0 - item]))
+
 extern object_type *choose_object(OBJECT_IDX *idx, concptr q, concptr s, BIT_FLAGS option, OBJECT_TYPE_VALUE tval);
 
 extern int bow_tval_ammo(object_type *o_ptr);
index 729fe94..d0b04f6 100644 (file)
@@ -1629,14 +1629,8 @@ object_type *choose_object(OBJECT_IDX *idx, concptr q, concptr s, BIT_FLAGS opti
        OBJECT_IDX item;
        if (!get_item(&item, q, s, option, tval)) return NULL;
        if (idx) *idx = item;
-
        if (item == INVEN_FORCE) return NULL;
-
-       /* Get the item (in the pack) */
-       else if (item >= 0) return &p_ptr->inventory_list[item];
-
-       /* Get the item (on the floor) */
-       else return &current_floor_ptr->o_list[0 - item];
+       return REF_ITEM(p_ptr, current_floor_ptr, item);
 }