OSDN Git Service

[Refactor] #37353 REF_ITEM マクロ定義.
authordeskull <deskull@users.sourceforge.jp>
Thu, 1 Aug 2019 14:14:02 +0000 (23:14 +0900)
committerdeskull <deskull@users.sourceforge.jp>
Thu, 1 Aug 2019 14:14:02 +0000 (23:14 +0900)
src/cmd-activate.c
src/cmd-eat.c
src/cmd-item.h

index 37eb608..ff06281 100644 (file)
@@ -10,6 +10,7 @@
 #include "util.h"
 
 #include "cmd-activate.h"
+#include "cmd-item.h"
 #include "cmd-basic.h"
 #include "floor.h"
 #include "object-hook.h"
@@ -353,20 +354,8 @@ void exe_activate(player_type *user_ptr, INVENTORY_IDX item)
        object_type *o_ptr;
        bool success;
 
-       /* Get the item (in the pack) */
-       if (item >= 0)
-       {
-               o_ptr = &user_ptr->inventory_list[item];
-       }
-
-       /* Get the item (on the floor) */
-       else
-       {
-               o_ptr = &current_floor_ptr->o_list[0 - item];
-       }
-
+       o_ptr = REF_ITEM(user_ptr, current_floor_ptr, item);
        take_turn(user_ptr, 100);
-
        lev = k_info[o_ptr->k_idx].level;
 
        /* Hack -- use artifact level instead */
index a1595ae..86ae694 100644 (file)
@@ -472,15 +472,12 @@ void exe_eat_food(player_type *creature_ptr, INVENTORY_IDX item)
                (void)set_food(creature_ptr, creature_ptr->food + o_ptr->pval);
        }
 
-       /* Destroy a food in the pack */
        if (item >= 0)
        {
                inven_item_increase(item, -1);
                inven_item_describe(item);
                inven_item_optimize(item);
        }
-
-       /* Destroy a food on the floor */
        else
        {
                floor_item_increase(0 - item, -1);
@@ -505,7 +502,6 @@ void do_cmd_eat_food(player_type *creature_ptr)
                set_action(creature_ptr, ACTION_NONE);
        }
 
-       /* Restrict choices to food */
        item_tester_hook = item_tester_hook_eatable;
 
        q = _("どれを食べますか? ", "Eat which item? ");
@@ -513,7 +509,6 @@ void do_cmd_eat_food(player_type *creature_ptr)
 
        if (!choose_object(&item, q, s, (USE_INVEN | USE_FLOOR), 0)) return;
 
-       /* Eat the object */
        exe_eat_food(creature_ptr, item);
 }
 
index e205349..ff3753f 100644 (file)
@@ -1,5 +1,7 @@
 /* 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);