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/cmd6.c | |
parent | 120fed37d8974553e25e5c83ba74c1bb08d71404 (diff) |
Refactor: Remove duplicate code for accessing inventory/floor object
Diffstat (limited to 'src/cmd6.c')
-rw-r--r-- | src/cmd6.c | 145 |
1 files changed, 22 insertions, 123 deletions
@@ -946,17 +946,8 @@ void do_cmd_eat_food(void) s = "You have nothing to eat."; if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EXTRA))) 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); /* Sound */ sound(SOUND_EAT); @@ -1517,17 +1508,8 @@ void do_cmd_cut_corpse(void) s = "You have no corpses."; 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); r_ptr = &r_info[o_ptr->pval2]; @@ -1630,17 +1612,8 @@ void do_cmd_cure_meat(void) s = "You have no meat to cure."; 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); /* Restrict choices to potions */ item_tester_tval = TV_POTION; @@ -1650,17 +1623,8 @@ void do_cmd_cure_meat(void) s = "You have no potions to use."; if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return; - /* Get the item (in the pack) */ - if (item >= 0) - { - i_ptr = &p_ptr->inventory[item]; - } - - /* Get the item (on the floor) */ - else - { - i_ptr = &o_list[0 - item]; - } + /* Get the item */ + i_ptr = get_object(item); if (i_ptr->number > 1) { @@ -2497,17 +2461,8 @@ void do_cmd_quaff_potion(void) s = "You have no potions to quaff."; if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EXTRA))) 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); /* Sound */ @@ -2929,18 +2884,8 @@ void do_cmd_read_scroll(void) s = "You have no scrolls to read."; if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EXTRA))) 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 turn */ energy_use = 100; @@ -3718,18 +3663,8 @@ void do_cmd_use_staff(void) s = "You have no staff to use."; if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EXTRA))) 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); /* Mega-Hack -- refuse to use a pile from the ground */ if ((item < 0) && (o_ptr->number > 1)) @@ -3921,17 +3856,8 @@ void do_cmd_aim_wand(void) s = "You have no wand to aim."; if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EXTRA))) 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); /* Mega-Hack -- refuse to aim a pile from the ground */ @@ -4111,17 +4037,8 @@ void zap_combine_rod_tip(object_type *q_ptr, int tip_item) s = "You have no rod to attach to."; if (!get_item(&item, q, s, (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); /* Examine the rod */ object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); @@ -4195,17 +4112,8 @@ void do_cmd_zap_rod(void) s = "You have no rod to zap."; if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EXTRA))) 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); /* "Zapping" a Rod Tip on rod of nothing will attach it */ @@ -4847,17 +4755,8 @@ void do_cmd_activate(void) s = "You have nothing to activate."; 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); /* Extract object flags */ object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); |