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 | |
parent | 120fed37d8974553e25e5c83ba74c1bb08d71404 (diff) |
Refactor: Remove duplicate code for accessing inventory/floor object
Diffstat (limited to 'src')
-rw-r--r-- | src/cmd2.c | 22 | ||||
-rw-r--r-- | src/cmd3.c | 119 | ||||
-rw-r--r-- | src/cmd5.c | 26 | ||||
-rw-r--r-- | src/cmd6.c | 145 | ||||
-rw-r--r-- | src/cmd7.c | 140 | ||||
-rw-r--r-- | src/object1.c | 26 | ||||
-rw-r--r-- | src/powers.c | 12 | ||||
-rw-r--r-- | src/q_narsil.c | 14 | ||||
-rw-r--r-- | src/q_one.c | 12 | ||||
-rw-r--r-- | src/q_ultrag.c | 2 | ||||
-rw-r--r-- | src/randart.c | 14 | ||||
-rw-r--r-- | src/spells2.c | 81 | ||||
-rw-r--r-- | src/store.c | 14 | ||||
-rw-r--r-- | src/wizard2.c | 13 |
14 files changed, 95 insertions, 545 deletions
@@ -3103,15 +3103,8 @@ void do_cmd_fire(void) if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return; - /* Access the item (if in the pack) */ - if (item >= 0) - { - o_ptr = &p_ptr->inventory[item]; - } - else - { - o_ptr = &o_list[0 - item]; - } + /* Access the item */ + o_ptr = get_object(item); } @@ -3523,15 +3516,8 @@ void do_cmd_throw(void) s = "You have nothing to throw."; if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return; - /* Access the item (if in the pack) */ - if (item >= 0) - { - o_ptr = &p_ptr->inventory[item]; - } - else - { - o_ptr = &o_list[0 - item]; - } + /* Access the item */ + o_ptr = get_object(item); object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); @@ -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; @@ -131,17 +131,8 @@ void do_cmd_browse(void) s = "You have no books that you can read."; if (!get_item(&item, q, s, (USE_INVEN | USE_EQUIP | 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); do_cmd_browse_aux(o_ptr); } @@ -2198,17 +2189,8 @@ s32b get_school_spell(cptr do_what, cptr check_fct, s16b force_book) sprintf(buf3, "%s from which book?", do_what); if (!get_item(&item, buf3, buf2, USE_INVEN | USE_EQUIP | USE_EXTRA )) return -1; - /* 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); @@ -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); @@ -3672,16 +3672,9 @@ void do_cmd_alchemist(void) 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); + /* Create an artifact from an ego or double ego item, * from a previous artifact, or finish an artifact */ @@ -4010,15 +4003,8 @@ void do_cmd_alchemist(void) s = "You have no item to extract power from."; 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]; - } - else - { - o_ptr = &o_list[0 - item]; - } + /* Get the item */ + o_ptr = get_object(item); /* This is to prevent creating magic essences by extracting * from a recharged wand of dragon breath or something. @@ -4239,14 +4225,7 @@ void do_cmd_alchemist(void) /* reset o_ptr to the original stack, * which contains at least another item */ - if (item >= 0) - { - o_ptr = &p_ptr->inventory[item]; - } - else - { - o_ptr = &o_list[0 - item]; - } + o_ptr = get_object(item); } } } @@ -4277,17 +4256,8 @@ void do_cmd_alchemist(void) s = "You have no rechargable items."; 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); /* Make sure we have enough essences to recharge this */ if (!alchemist_items_check(o_ptr->tval, o_ptr->sval, 0, 0, TRUE)) @@ -5182,18 +5152,6 @@ void do_cmd_archer(void) s = "You have no item to convert."; if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return; - /* Get the item (in the pack) */ - if (item >= 0) - { - q_ptr = &p_ptr->inventory[item]; - } - - /* Get the item (on the floor) */ - else - { - q_ptr = &o_list[0 - item]; - } - /* Get local object */ q_ptr = &forge; @@ -5232,18 +5190,6 @@ void do_cmd_archer(void) s = "You have no item to convert."; if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return; - /* Get the item (in the pack) */ - if (item >= 0) - { - q_ptr = &p_ptr->inventory[item]; - } - - /* Get the item (on the floor) */ - else - { - q_ptr = &o_list[0 - item]; - } - /* Get local object */ q_ptr = &forge; @@ -6048,17 +5994,8 @@ bool_ get_runespell(rune_spell *spell) s = "You have no rune to use."; if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return FALSE; - /* 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); type = o_ptr->sval; while (1) @@ -6070,17 +6007,9 @@ bool_ get_runespell(rune_spell *spell) if (OK) break; - /* Get the item (in the pack) */ - if (item >= 0) - { - o_ptr = &p_ptr->inventory[item]; - } + /* Get the item */ + o_ptr = get_object(item); - /* Get the item (on the floor) */ - else - { - o_ptr = &o_list[0 - item]; - } rune_combine |= 1 << o_ptr->sval; rune2 |= 1 << o_ptr->sval; } @@ -6466,16 +6395,8 @@ void do_cmd_runestone() s = "You have no runestone to cast from."; 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); s_ptr.type = o_ptr->pval; s_ptr.rune2 = o_ptr->pval2; @@ -6585,16 +6506,8 @@ void do_cmd_rune_carve() s = "You have no runestone to use."; 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); o_ptr->pval = s_ptr.type; o_ptr->pval2 = s_ptr.rune2; @@ -6959,17 +6872,9 @@ void do_cmd_summoner_extract() s = "You have no corpse to use."; 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 */ + o_ptr = get_object(item); - /* Get the item (on the floor) */ - else - { - o_ptr = &o_list[0 - item]; - } if (r_info[o_ptr->pval2].flags1 & RF1_UNIQUE) { @@ -7131,14 +7036,7 @@ void do_cmd_summoner_summon() if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return; /* Access the item */ - if (item >= 0) - { - o_ptr = &p_ptr->inventory[item]; - } - else - { - o_ptr = &o_list[0 - item]; - } + o_ptr = get_object(item); /* Take a turn */ energy_use = 100; diff --git a/src/object1.c b/src/object1.c index fe91b805..fef7fb85 100644 --- a/src/object1.c +++ b/src/object1.c @@ -4899,17 +4899,8 @@ bool_ verify(cptr prompt, int item) object_type *o_ptr; - /* Inventory */ - if (item >= 0) - { - o_ptr = &p_ptr->inventory[item]; - } - - /* Floor */ - else - { - o_ptr = &o_list[0 - item]; - } + /* Get object */ + o_ptr = get_object(item); /* Describe */ object_desc(o_name, o_ptr, TRUE, 3); @@ -4933,17 +4924,8 @@ static bool_ get_item_allow(int item) object_type *o_ptr; - /* Inventory */ - if (item >= 0) - { - o_ptr = &p_ptr->inventory[item]; - } - - /* Floor */ - else - { - o_ptr = &o_list[0 - item]; - } + /* Get object */ + o_ptr = get_object(item); /* No inscription */ if (!o_ptr->note) return (TRUE); diff --git a/src/powers.c b/src/powers.c index 26e5f6e3..b38b671f 100644 --- a/src/powers.c +++ b/src/powers.c @@ -296,8 +296,7 @@ static void power_activate(int power) { ok = 0; - if (item >= 0) o2_ptr = &p_ptr->inventory[item]; - else o2_ptr = &o_list[0 - item]; + o2_ptr = get_object(item); /* Is the item cursed? */ if ((item >= INVEN_WIELD) && cursed_p(o2_ptr)) @@ -1064,14 +1063,7 @@ static void power_activate(int power) s = "You have nothing to drain."; if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) break; - if (item >= 0) - { - o_ptr = &p_ptr->inventory[item]; - } - else - { - o_ptr = &o_list[0 - item]; - } + o_ptr = get_object(item); lev = k_info[o_ptr->k_idx].level; diff --git a/src/q_narsil.c b/src/q_narsil.c index e96814dd..27ec218e 100644 --- a/src/q_narsil.c +++ b/src/q_narsil.c @@ -20,7 +20,7 @@ bool_ quest_narsil_move_hook(char *fmt) /* Look out for Narsil */ for (i = 0; i < INVEN_TOTAL; i++) { - o_ptr = &p_ptr->inventory[i]; + o_ptr = get_object(i); if (!o_ptr->k_idx) continue; @@ -74,17 +74,7 @@ bool_ quest_narsil_identify_hook(char *fmt) item = get_next_arg(fmt); - /* Inventory */ - if (item >= 0) - { - o_ptr = &p_ptr->inventory[item]; - } - - /* Floor */ - else - { - o_ptr = &o_list[0 - item]; - } + o_ptr = get_object(item); if (o_ptr->name1 == ART_NARSIL) { diff --git a/src/q_one.c b/src/q_one.c index 14c5343d..4bfeaf3e 100644 --- a/src/q_one.c +++ b/src/q_one.c @@ -199,17 +199,7 @@ bool_ quest_one_identify_hook(char *fmt) { object_type *o_ptr; - /* Inventory */ - if (item >= 0) - { - o_ptr = &p_ptr->inventory[item]; - } - - /* Floor */ - else - { - o_ptr = &o_list[0 - item]; - } + o_ptr = get_object(item); if ((o_ptr->name1 == ART_POWER) && (!object_known_p(o_ptr))) { diff --git a/src/q_ultrag.c b/src/q_ultrag.c index 12df5efb..a5a09f2d 100644 --- a/src/q_ultrag.c +++ b/src/q_ultrag.c @@ -109,7 +109,7 @@ bool_ quest_ultra_good_stair_hook(char *fmt) for (i = INVEN_WIELD; i < INVEN_TOTAL; i++) { u32b f1, f2, f3, f4, f5, esp; - object_type *o_ptr = &p_ptr->inventory[i]; + object_type *o_ptr = get_object(i); if (!o_ptr->k_idx) continue; diff --git a/src/randart.c b/src/randart.c index 70d350ad..298ee83a 100644 --- a/src/randart.c +++ b/src/randart.c @@ -419,18 +419,8 @@ bool_ artifact_scroll(void) s = "You have nothing to enchant."; if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return (FALSE); - /* 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, FALSE, 0); diff --git a/src/spells2.c b/src/spells2.c index d6bfe629..924c5b39 100644 --- a/src/spells2.c +++ b/src/spells2.c @@ -580,17 +580,8 @@ bool_ alchemy(void) /* Turns an object into gold, gain some of its value in a sh s = "You have nothing to turn to gold."; if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return (FALSE); - /* 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 */ @@ -3152,18 +3143,8 @@ bool_ enchant_spell(int num_hit, int num_dam, int num_ac, int num_pval) s = "You have nothing to enchant."; if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return (FALSE); - /* 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, FALSE, 0); @@ -4264,18 +4245,8 @@ bool_ ident_spell(void) s = "You have nothing to identify."; if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return (FALSE); - /* 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); /* Identify it fully */ object_aware(o_ptr); @@ -4393,17 +4364,8 @@ bool_ identify_fully(void) s = "You have nothing to identify."; if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return (FALSE); - /* 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); /* Do the identification */ make_item_fully_identified(o_ptr); @@ -4533,17 +4495,8 @@ bool_ recharge(int power) s = "You have nothing to recharge."; if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return (FALSE); - /* 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 the flags */ object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); @@ -7388,18 +7341,8 @@ void bless_weapon(void) s = "You have weapon to bless."; 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, FALSE, 0); diff --git a/src/store.c b/src/store.c index 979c955a..78120846 100644 --- a/src/store.c +++ b/src/store.c @@ -2968,18 +2968,8 @@ void store_sell(void) } 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); diff --git a/src/wizard2.c b/src/wizard2.c index 824bc724..f606fd72 100644 --- a/src/wizard2.c +++ b/src/wizard2.c @@ -1157,17 +1157,8 @@ static void do_cmd_wiz_play(void) s = "You have nothing to play with."; 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); /* The item was not changed */ |