diff options
author | Bardur Arantsson <bardur@scientician.net> | 2012-03-04 17:47:43 +0100 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2012-03-29 20:41:39 +0200 |
commit | 4d6770696a172bae4ef18a00cb1e59f06e641faf (patch) | |
tree | 6b6475485d731f4ad2a54c84dacfaafec347f8a9 /src/cmd3.c | |
parent | 120fed37d8974553e25e5c83ba74c1bb08d71404 (diff) |
Refactor: Remove duplicate code for accessing inventory/floor object
Diffstat (limited to 'src/cmd3.c')
-rw-r--r-- | src/cmd3.c | 119 |
1 files changed, 18 insertions, 101 deletions
@@ -220,17 +220,8 @@ void do_cmd_wield(void) s = "You have nothing you can wear or wield."; if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return; - /* Get the item (in the pack) */ - if (item >= 0) - { - o_ptr = &p_ptr->inventory[item]; - } - - /* Get the item (on the floor) */ - else - { - o_ptr = &o_list[0 - item]; - } + /* Get the item */ + o_ptr = get_object(item); /* Check the slot */ slot = wield_slot(o_ptr); @@ -473,17 +464,8 @@ void do_cmd_takeoff(void) s = "You are not wearing anything to take off."; if (!get_item(&item, q, s, (USE_EQUIP))) return; - /* Get the item (in the pack) */ - if (item >= 0) - { - o_ptr = &p_ptr->inventory[item]; - } - - /* Get the item (on the floor) */ - else - { - o_ptr = &o_list[0 - item]; - } + /* Get the item */ + o_ptr = get_object(item); /* Can we take it off */ if (process_hooks(HOOK_TAKEOFF, "(d)", item)) return; @@ -531,17 +513,8 @@ void do_cmd_drop(void) s = "You have nothing to drop."; if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN))) return; - /* Get the item (in the pack) */ - if (item >= 0) - { - o_ptr = &p_ptr->inventory[item]; - } - - /* Get the item (on the floor) */ - else - { - o_ptr = &o_list[0 - item]; - } + /* Get the item */ + o_ptr = get_object(item); object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); @@ -622,17 +595,8 @@ void do_cmd_destroy(void) s = "You have nothing to destroy."; if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_AUTO))) return; - /* Get the item (in the pack) */ - if (item >= 0) - { - o_ptr = &p_ptr->inventory[item]; - } - - /* Get the item (on the floor) */ - else - { - o_ptr = &o_list[0 - item]; - } + /* Get the item */ + o_ptr = get_object(item); /* See how many items */ @@ -755,17 +719,8 @@ void do_cmd_observe(void) s = "You have nothing to examine."; if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return; - /* Get the item (in the pack) */ - if (item >= 0) - { - o_ptr = &p_ptr->inventory[item]; - } - - /* Get the item (on the floor) */ - else - { - o_ptr = &o_list[0 - item]; - } + /* Get the item */ + o_ptr = get_object(item); /* Description */ object_desc(o_name, o_ptr, TRUE, 3); @@ -797,17 +752,8 @@ void do_cmd_uninscribe(void) s = "You have nothing to un-inscribe."; if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return; - /* Get the item (in the pack) */ - if (item >= 0) - { - o_ptr = &p_ptr->inventory[item]; - } - - /* Get the item (on the floor) */ - else - { - o_ptr = &o_list[0 - item]; - } + /* Get the item */ + o_ptr = get_object(item); /* Nothing to remove */ if (!o_ptr->note) @@ -851,17 +797,8 @@ void do_cmd_inscribe(void) s = "You have nothing to inscribe."; if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return; - /* Get the item (in the pack) */ - if (item >= 0) - { - o_ptr = &p_ptr->inventory[item]; - } - - /* Get the item (on the floor) */ - else - { - o_ptr = &o_list[0 - item]; - } + /* Get the item */ + o_ptr = get_object(item); /* Describe the activity */ object_desc(o_name, o_ptr, TRUE, 3); @@ -934,18 +871,8 @@ static void do_cmd_refill_lamp(void) s = "You have no flasks of oil."; if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return; - /* Get the item (in the pack) */ - if (item >= 0) - { - o_ptr = &p_ptr->inventory[item]; - } - - /* Get the item (on the floor) */ - else - { - o_ptr = &o_list[0 - item]; - } - + /* Get the item */ + o_ptr = get_object(item); /* Take a partial turn */ energy_use = 50; @@ -1013,18 +940,8 @@ static void do_cmd_refill_torch(void) s = "You have no extra torches."; if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return; - /* Get the item (in the pack) */ - if (item >= 0) - { - o_ptr = &p_ptr->inventory[item]; - } - - /* Get the item (on the floor) */ - else - { - o_ptr = &o_list[0 - item]; - } - + /* Get the item */ + o_ptr = get_object(item); /* Take a partial turn */ energy_use = 50; |