summaryrefslogtreecommitdiff
path: root/src/spells2.c
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2012-03-04 17:47:43 +0100
committerBardur Arantsson <bardur@scientician.net>2012-03-29 20:41:39 +0200
commit4d6770696a172bae4ef18a00cb1e59f06e641faf (patch)
tree6b6475485d731f4ad2a54c84dacfaafec347f8a9 /src/spells2.c
parent120fed37d8974553e25e5c83ba74c1bb08d71404 (diff)
Refactor: Remove duplicate code for accessing inventory/floor object
Diffstat (limited to 'src/spells2.c')
-rw-r--r--src/spells2.c81
1 files changed, 12 insertions, 69 deletions
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);