diff options
author | Bardur Arantsson <bardur@scientician.net> | 2012-03-04 14:48:15 +0100 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2012-03-29 20:41:39 +0200 |
commit | 120fed37d8974553e25e5c83ba74c1bb08d71404 (patch) | |
tree | 3153c48c7a0e8283ce108577bd6160add7b437e6 | |
parent | a27236516b0aa8761f70f009c78f4272dc0b735d (diff) |
Refactor: Remove duplicate code for reducing item stacks
-rw-r--r-- | src/bldg.c | 8 | ||||
-rw-r--r-- | src/cmd1.c | 12 | ||||
-rw-r--r-- | src/cmd2.c | 44 | ||||
-rw-r--r-- | src/cmd3.c | 66 | ||||
-rw-r--r-- | src/cmd6.c | 113 | ||||
-rw-r--r-- | src/cmd7.c | 114 | ||||
-rw-r--r-- | src/dungeon.c | 13 | ||||
-rw-r--r-- | src/externs.h | 8 | ||||
-rw-r--r-- | src/melee1.c | 6 | ||||
-rw-r--r-- | src/object1.c | 1 | ||||
-rw-r--r-- | src/object2.c | 49 | ||||
-rw-r--r-- | src/powers.c | 13 | ||||
-rw-r--r-- | src/q_hobbit.c | 4 | ||||
-rw-r--r-- | src/q_one.c | 3 | ||||
-rw-r--r-- | src/q_shroom.c | 3 | ||||
-rw-r--r-- | src/spells1.c | 6 | ||||
-rw-r--r-- | src/spells2.c | 49 | ||||
-rw-r--r-- | src/store.c | 20 | ||||
-rw-r--r-- | src/traps.c | 34 |
19 files changed, 141 insertions, 425 deletions
@@ -1365,9 +1365,7 @@ static void sell_corpses(void) /* Increase the number of collected bounties */ total_bounties++; - inven_item_increase(item, -1); - inven_item_describe(item); - inven_item_optimize(item); + inc_stack_size(item, -1); return; } @@ -1538,9 +1536,7 @@ static void sell_quest_monster(void) msg_print(NULL); } - inven_item_increase(item, -1); - inven_item_describe(item); - inven_item_optimize(item); + inc_stack_size(item, -1); } @@ -2070,8 +2070,8 @@ void do_nazgul(int *k, int *num, int num_blow, int weap, monster_race *r_ptr, { msg_print("Your weapon *DISINTEGRATES*!"); *k = 0; - inven_item_increase(INVEN_WIELD + weap, -1); - inven_item_optimize(INVEN_WIELD + weap); + + inc_stack_size_ex(INVEN_WIELD + weap, -1, OPTIMIZE, NO_DESCRIBE); /* To stop attacking */ *num = num_blow; @@ -2089,8 +2089,8 @@ void do_nazgul(int *k, int *num, int num_blow, int weap, monster_race *r_ptr, if (magik(25) && allow_shatter) { msg_print("Your weapon is destroyed!"); - inven_item_increase(INVEN_WIELD + weap, -1); - inven_item_optimize(INVEN_WIELD + weap); + + inc_stack_size_ex(INVEN_WIELD + weap, -1, OPTIMIZE, NO_DESCRIBE); /* To stop attacking */ *num = num_blow; @@ -2111,8 +2111,8 @@ void do_nazgul(int *k, int *num, int num_blow, int weap, monster_race *r_ptr, if (!rand_int(1000) && allow_shatter) { msg_print("Your weapon is destroyed!"); - inven_item_increase(INVEN_WIELD + weap, -1); - inven_item_optimize(INVEN_WIELD + weap); + + inc_stack_size_ex(INVEN_WIELD + weap, -1, OPTIMIZE, NO_DESCRIBE); /* To stop attacking */ *num = num_blow; @@ -2618,9 +2618,7 @@ void do_cmd_spike(void) if (c_ptr->feat < FEAT_DOOR_TAIL) c_ptr->feat++; /* Use up, and describe, a single spike, from the bottom */ - inven_item_increase(item, -1); - inven_item_describe(item); - inven_item_optimize(item); + inc_stack_size(item, -1); } } } @@ -3130,20 +3128,8 @@ void do_cmd_fire(void) /* Single object */ q_ptr->number = 1; - /* Reduce and describe p_ptr->inventory */ - if (item >= 0) - { - inven_item_increase(item, -1); - inven_item_describe(item); - inven_item_optimize(item); - } - - /* Reduce and describe floor item */ - else - { - floor_item_increase(0 - item, -1); - floor_item_optimize(0 - item); - } + /* Reduce stack and describe */ + inc_stack_size(item, -1); /* Break goi/manashield */ if (p_ptr->invuln) @@ -3600,21 +3586,8 @@ void do_cmd_throw(void) /* Single object */ q_ptr->number = 1; - /* Reduce and describe p_ptr->inventory */ - if (item >= 0) - { - inven_item_increase(item, -1); - inven_item_describe(item); - inven_item_optimize(item); - } - - /* Reduce and describe floor item */ - else - { - floor_item_increase(0 - item, -1); - floor_item_optimize(0 - item); - } - + /* Reduce stack and describe */ + inc_stack_size(item, -1); /* Description */ object_desc(o_name, q_ptr, FALSE, 3); @@ -4168,8 +4141,7 @@ void do_cmd_boomerang(void) (rand_int(100) < j)) { msg_print(format("Your %s is destroyed.", o_name)); - inven_item_increase(INVEN_BOW, -1); - inven_item_optimize(INVEN_BOW); + inc_stack_size_ex(INVEN_BOW, -1, OPTIMIZE, NO_DESCRIBE); } } @@ -4717,9 +4689,7 @@ void do_cmd_sacrifice(void) } /* Remove the item */ - inven_item_increase(item, -1); - inven_item_describe(item); - inven_item_optimize(item); + inc_stack_size(item, -1); } } else @@ -345,19 +345,8 @@ void do_cmd_wield(void) /* Modify quantity */ q_ptr->number = num; - /* Decrease the item (from the pack) */ - if (item >= 0) - { - inven_item_increase(item, -num); - inven_item_optimize(item); - } - - /* Decrease the item (from the floor) */ - else - { - floor_item_increase(0 - item, -num); - floor_item_optimize(0 - item); - } + /* Decrease the item */ + inc_stack_size_ex(item, -num, OPTIMIZE, NO_DESCRIBE); /* Access the wield slot */ o_ptr = &p_ptr->inventory[slot]; @@ -742,21 +731,8 @@ void do_cmd_destroy(void) if (f3 & TR3_BLESSED) inc_piety(GOD_ERU, -10 * k_info[o_ptr->k_idx].level); - /* Eliminate the item (from the pack) */ - if (item >= 0) - { - inven_item_increase(item, -amt); - inven_item_describe(item); - inven_item_optimize(item); - } - - /* Eliminate the item (from the floor) */ - else - { - floor_item_increase(0 - item, -amt); - floor_item_describe(0 - item); - floor_item_optimize(0 - item); - } + /* Eliminate the item */ + inc_stack_size(item, -amt); } @@ -993,21 +969,8 @@ static void do_cmd_refill_lamp(void) msg_print("Your lamp is full."); } - /* Decrease the item (from the pack) */ - if (item >= 0) - { - inven_item_increase(item, -1); - inven_item_describe(item); - inven_item_optimize(item); - } - - /* Decrease the item (from the floor) */ - else - { - floor_item_increase(0 - item, -1); - floor_item_describe(0 - item); - floor_item_optimize(0 - item); - } + /* Decrease the item stack */ + inc_stack_size(item, -1); /* Recalculate torch */ p_ptr->update |= (PU_TORCH); @@ -1088,21 +1051,8 @@ static void do_cmd_refill_torch(void) msg_print("Your torch glows more brightly."); } - /* Decrease the item (from the pack) */ - if (item >= 0) - { - inven_item_increase(item, -1); - inven_item_describe(item); - inven_item_optimize(item); - } - - /* Decrease the item (from the floor) */ - else - { - floor_item_increase(0 - item, -1); - floor_item_describe(0 - item); - floor_item_optimize(0 - item); - } + /* Decrease the item stack */ + inc_stack_size(item, -1); /* Recalculate torch */ p_ptr->update |= (PU_TORCH); @@ -1483,23 +1483,10 @@ void do_cmd_eat_food(void) } - /* Destroy a food in the pack */ + /* Destroy food? */ if (destroy) { - 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); - floor_item_describe(0 - item); - floor_item_optimize(0 - item); - } + inc_stack_size(item, -1); } } @@ -1771,21 +1758,8 @@ void do_cmd_cure_meat(void) if (o_ptr->timeout > o_ptr->pval) o_ptr->timeout = o_ptr->pval; - /* Use up the potions in the pack */ - if (item >= 0) - { - inven_item_increase(item, 0 - num); - inven_item_describe(item); - inven_item_optimize(item); - } - - /* Use up the potions on the floor */ - else - { - floor_item_increase(0 - item, 0 - num); - floor_item_describe(0 - item); - floor_item_optimize(0 - item); - } + /* Use up the potions */ + inc_stack_size(item, -num); } @@ -2596,21 +2570,8 @@ void do_cmd_quaff_potion(void) (void)set_food(p_ptr->food + o_ptr->pval); - /* Destroy a potion in the pack */ - if (item >= 0) - { - inven_item_increase(item, -1); - inven_item_describe(item); - inven_item_optimize(item); - } - - /* Destroy a potion on the floor */ - else - { - floor_item_increase(0 - item, -1); - floor_item_describe(0 - item); - floor_item_optimize(0 - item); - } + /* Destroy potion */ + inc_stack_size(item, -1); } @@ -2747,21 +2708,8 @@ void do_cmd_fill_bottle(void) if (amt > c_ptr->special2) amt = c_ptr->special2; - /* Destroy bottles in the pack */ - if (item >= 0) - { - inven_item_increase(item, -amt); - inven_item_describe(item); - inven_item_optimize(item); - } - - /* Destroy bottles on the floor */ - else - { - floor_item_increase(0 - item, -amt); - floor_item_describe(0 - item); - floor_item_optimize(0 - item); - } + /* Destroy bottles */ + inc_stack_size(item, -amt); /* Create the potion */ q_ptr = &forge; @@ -3696,21 +3644,8 @@ void do_cmd_read_scroll(void) sound(SOUND_SCROLL); - /* Destroy a scroll in the pack */ - if (item >= 0) - { - inven_item_increase(item, -1); - inven_item_describe(item); - inven_item_optimize(item); - } - - /* Destroy a scroll on the floor */ - else - { - floor_item_increase(0 - item, -1); - floor_item_describe(0 - item); - floor_item_optimize(0 - item); - } + /* Destroy scroll */ + inc_stack_size(item, -1); if (get_skill(SKILL_ALCHEMY)) { @@ -4212,20 +4147,8 @@ void zap_combine_rod_tip(object_type *q_ptr, int tip_item) /* Attach the tip to the rod */ o_ptr->pval = q_ptr->sval; - /* Destroy a rod tip in the pack */ - if (tip_item >= 0) - { - inven_item_increase(tip_item, -1); - inven_item_describe(tip_item); - inven_item_optimize(tip_item); - } - /* Destroy a rod tip on the floor */ - else - { - floor_item_increase(0 - tip_item, -1); - floor_item_describe(0 - tip_item); - floor_item_optimize(0 - tip_item); - } + /* Destroy rod tip */ + inc_stack_size(tip_item, -1); } @@ -7592,16 +7515,8 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) /* It explodes, doesn't it ? */ take_hit(damroll(2, 10), "an exploding ring"); - if ( item > 0) - { - inven_item_increase(item, -255); - inven_item_optimize(item); - } - else - { - floor_item_increase( -item, -255); - floor_item_optimize( -item); - } + + inc_stack_size_ex(item, -255, OPTIMIZE, NO_DESCRIBE); } break; @@ -1545,15 +1545,7 @@ int check_artifact_items(int pval, int oldpval, int mode) if ( mode == 1 ) { - inven_item_increase(k, -trqty); - inven_item_describe(k); - /* - if we optimize this now, it moves everything after it - in the p_ptr->inventory up one, and the pointer to the item - being artifactized now points to something else. - DON'T DO IT! - inven_item_optimize(k); - */ + inc_stack_size_ex(k, -trqty, NO_OPTIMIZE, DESCRIBE); } }/* if p_ptr->inventory item is acceptable */ @@ -1756,13 +1748,8 @@ bool_ artifact_display_or_use(int pval, int oldpval, bool_ use) { int num = p_ptr->inventory[k].number; - inven_item_increase(k, MAX( -essence[i], -num)); - inven_item_describe(k); - /* - messy bug, don't optimize here because it - rearanges the p_ptr->inventory. - inven_item_optimize(k); - */ + inc_stack_size_ex(k, MAX( -essence[i], -num), NO_OPTIMIZE, DESCRIBE); + essence[i] -= MIN(num, essence[i]); } @@ -1914,9 +1901,7 @@ bool_ magic_essence(int num) * artifactable object should come before the essences. */ j -= o_ptr->number; - inven_item_increase(i, -num); - inven_item_describe(i); - inven_item_optimize(i); + inc_stack_size(i, -num); num = j; if (num <= 0) break; /* Stay on this slot; do not increment i. */ @@ -2746,10 +2731,7 @@ bool_ alchemist_items_check(int tval, int sval, int ego, int tocreate, bool_ mes /* At this point, the item is required, destroy it. */ if ( tocreate ) { - inven_item_increase(j, 0 - rqty); - if ( message) - inven_item_describe(j); - inven_item_optimize(j); + inc_stack_size_ex(j, 0 - rqty, OPTIMIZE, message ? DESCRIBE : NO_DESCRIBE); } /* When we find enough of the item, break out of the @@ -3818,19 +3800,7 @@ void do_cmd_alchemist(void) carry_o_ptr = TRUE; /* Destroy the initial object */ - if (item >= 0) - { - /* Destroy an item in the pack */ - inven_item_increase(item, -qty); - inven_item_describe(item); - } - else - { - /* Destroy an item on the floor */ - floor_item_increase(0 - item, -qty); - floor_item_describe(0 - item); - floor_item_optimize(0 - item); - } + inc_stack_size(item, -qty); if ( ego ) @@ -4260,18 +4230,7 @@ void do_cmd_alchemist(void) if (o_ptr->number == 1) repeat = 0; - if (item >= 0) - { - inven_item_increase(item, ( -1)); - inven_item_describe(item); - inven_item_optimize(item); - } - else - { - floor_item_increase(0 - item, ( -1)); - floor_item_describe(0 - item); - floor_item_optimize(0 - item); - } + inc_stack_size(item, -1); } else { @@ -5254,18 +5213,7 @@ void do_cmd_archer(void) msg_print("You make some ammo."); - if (item >= 0) - { - inven_item_increase(item, -1); - inven_item_describe(item); - inven_item_optimize(item); - } - else - { - floor_item_increase(0 - item, -1); - floor_item_describe(0 - item); - floor_item_optimize(0 - item); - } + inc_stack_size(item, -1); (void)inven_carry(q_ptr, FALSE); } @@ -5315,18 +5263,7 @@ void do_cmd_archer(void) msg_print("You make some ammo."); - if (item >= 0) - { - inven_item_increase(item, -1); - inven_item_describe(item); - inven_item_optimize(item); - } - else - { - floor_item_increase(0 - item, -1); - floor_item_describe(0 - item); - floor_item_optimize(0 - item); - } + inc_stack_size(item, -1); (void)inven_carry(q_ptr, FALSE); } @@ -6700,8 +6637,7 @@ void do_cmd_rune_carve() if (do_del) { - inven_item_increase(i, -1); - inven_item_optimize(i); + inc_stack_size_ex(i, -1, OPTIMIZE, NO_DESCRIBE); } } } @@ -7046,18 +6982,7 @@ void do_cmd_summoner_extract() r = o_ptr->pval2; - if (item > 0) - { - inven_item_increase(item, -1); - inven_item_describe(item); - inven_item_optimize(item); - } - else - { - floor_item_increase( -item, -1); - floor_item_describe( -item); - floor_item_optimize( -item); - } + inc_stack_size(item, -1); if (magik(r_info[o_ptr->pval2].level - get_skill(SKILL_SUMMON))) { @@ -7178,21 +7103,8 @@ void summon_true(int r_idx, int item) /* Destroy the totem if the used flag is set */ if (used) { - /* Eliminate the totem (from the pack) */ - if (item >= 0) - { - inven_item_increase(item, -1); - inven_item_describe(item); - inven_item_optimize(item); - } - - /* Eliminate the totem (from the floor) */ - else - { - floor_item_increase(0 - item, -1); - floor_item_describe(0 - item); - floor_item_optimize(0 - item); - } + /* Eliminate the totem */ + inc_stack_size(item, -1); } /* Done */ diff --git a/src/dungeon.c b/src/dungeon.c index f5de2a61..c45a5b2e 100644 --- a/src/dungeon.c +++ b/src/dungeon.c @@ -2831,9 +2831,7 @@ static void process_world(void) if (o_ptr->timeout <= 0) { - inven_item_increase(i, -99); - inven_item_describe(i); - inven_item_optimize(i); + inc_stack_size(i, -99); /* Combine and Reorder pack */ p_ptr->notice |= (PN_COMBINE | PN_REORDER); @@ -2935,9 +2933,8 @@ static void process_world(void) m_ptr->status = MSTATUS_COMPANION; } - inven_item_increase(i, -1); - inven_item_describe(i); - inven_item_optimize(i); + inc_stack_size(i, -1); + j++; } } @@ -4471,9 +4468,7 @@ void process_player(void) drop_near(o_ptr, 0, p_ptr->py, p_ptr->px); /* Modify, Describe, Optimize */ - inven_item_increase(item, -255); - inven_item_describe(item); - inven_item_optimize(item); + inc_stack_size(item, -255); /* Notice stuff (if needed) */ if (p_ptr->notice) notice_stuff(); diff --git a/src/externs.h b/src/externs.h index 1c0c63e2..42ac1612 100644 --- a/src/externs.h +++ b/src/externs.h @@ -7,6 +7,12 @@ * (z-virt.h, z-util.h, z-form.h, term.h, random.h) */ +/* + * Options for inc_stack_size_ex + */ +typedef enum { OPTIMIZE, NO_OPTIMIZE } optimize_flag; +typedef enum { DESCRIBE, NO_DESCRIBE } describe_flag; + /* * Automatically generated "variable" declarations @@ -1093,6 +1099,8 @@ extern bool_ is_enemy(monster_type *m_ptr, monster_type *t_ptr); /* object2.c */ extern byte get_item_letter_color(object_type *o_ptr); extern void describe_device(object_type *o_ptr); +extern void inc_stack_size(int item, int delta); +extern void inc_stack_size_ex(int item, int delta, optimize_flag opt, describe_flag desc); extern void object_pickup(int this_o_idx); extern int get_slot(int slot); extern bool_ apply_flags_set(s16b a_idx, s16b set_idx, u32b *f1, u32b *f2, u32b *f3, u32b *f4, u32b *f5, u32b *esp); diff --git a/src/melee1.c b/src/melee1.c index 1a3fa526..4e5d3208 100644 --- a/src/melee1.c +++ b/src/melee1.c @@ -2174,8 +2174,7 @@ bool_ make_attack_normal(int m_idx, byte divis) } /* Steal the items */ - inven_item_increase(i, -1); - inven_item_optimize(i); + inc_stack_size_ex(i, -1, OPTIMIZE, NO_DESCRIBE); /* Obvious */ obvious = TRUE; @@ -2219,8 +2218,7 @@ bool_ make_attack_normal(int m_idx, byte divis) o_name, index_to_label(i)); /* Steal the items */ - inven_item_increase(i, -1); - inven_item_optimize(i); + inc_stack_size_ex(i, -1, OPTIMIZE, NO_DESCRIBE); /* Obvious */ obvious = TRUE; diff --git a/src/object1.c b/src/object1.c index 084f225b..fe91b805 100644 --- a/src/object1.c +++ b/src/object1.c @@ -6685,4 +6685,3 @@ bool_ apply_flags_set(s16b a_idx, s16b set_idx, - diff --git a/src/object2.c b/src/object2.c index 625e1ecd..a5e013a0 100644 --- a/src/object2.c +++ b/src/object2.c @@ -5695,6 +5695,45 @@ void floor_item_optimize(int item) } +/* + * Increase stack size for item, describe and optimize. + */ +void inc_stack_size(int item, int delta) { + inc_stack_size_ex(item, delta, OPTIMIZE, DESCRIBE); +} + +/* + * Increase stack size for item. + */ +void inc_stack_size_ex(int item, int delta, optimize_flag opt, describe_flag desc) { + /* Pack item? */ + if (item >= 0) + { + inven_item_increase(item, -1); + if (desc == DESCRIBE) + { + inven_item_describe(item); + } + if (opt == OPTIMIZE) + { + inven_item_optimize(item); + } + } + + /* Floor item? */ + else + { + floor_item_increase(0 - item, -1); + if (desc == DESCRIBE) + { + floor_item_describe(0 - item); + } + if (opt == OPTIMIZE) + { + floor_item_optimize(0 - item); + } + } +} @@ -5977,8 +6016,7 @@ s16b inven_takeoff(int item, int amt, bool_ force_drop) } /* Modify, Optimize */ - inven_item_increase(item, -amt); - inven_item_optimize(item); + inc_stack_size_ex(item, -amt, OPTIMIZE, NO_DESCRIBE); if ((item == INVEN_CARRY) && (get_skill(SKILL_SYMBIOTIC))) { @@ -6080,9 +6118,7 @@ void inven_drop(int item, int amt, int dy, int dx, bool_ silent) drop_near(q_ptr, 0, dy, dx); /* Modify, Describe, Optimize */ - inven_item_increase(item, -amt); - inven_item_describe(item); - inven_item_optimize(item); + inc_stack_size(item, -amt); } } @@ -6423,8 +6459,7 @@ void pack_decay(int item) wt = r_ptr->weight; /* Get rid of decayed object */ - inven_item_increase(item, -amt); - inven_item_optimize(item); + inc_stack_size_ex(item, -amt, OPTIMIZE, NO_DESCRIBE); if (i_ptr->tval == TV_CORPSE) { diff --git a/src/powers.c b/src/powers.c index f51b09b3..26e5f6e3 100644 --- a/src/powers.c +++ b/src/powers.c @@ -346,18 +346,7 @@ static void power_activate(int power) } /* Destroy item */ - if (item >= 0) - { - inven_item_increase(item, -1); - inven_item_describe(item); - inven_item_optimize(item); - } - else - { - inven_item_increase(0 - item, -1); - inven_item_describe(0 - item); - inven_item_optimize(0 - item); - } + inc_stack_size(item, -1); } } } diff --git a/src/q_hobbit.c b/src/q_hobbit.c index 4ac1f35f..f3b7d856 100644 --- a/src/q_hobbit.c +++ b/src/q_hobbit.c @@ -80,8 +80,8 @@ bool_ quest_hobbit_give_hook(char *fmt) msg_print("Merton Proudfoot reads the scroll and is recalled to the safety of his home."); delete_monster_idx(m_idx); - inven_item_increase(item, -1); - inven_item_optimize(item); + + inc_stack_size_ex(item, -1, OPTIMIZE, NO_DESCRIBE); cquest.status = QUEST_STATUS_COMPLETED; diff --git a/src/q_one.c b/src/q_one.c index ec301c5d..14c5343d 100644 --- a/src/q_one.c +++ b/src/q_one.c @@ -84,8 +84,7 @@ bool_ quest_one_drop_hook(char *fmt) cmsg_print(TERM_YELLOW, "You feel the powers of evil weakening."); cmsg_print(TERM_YELLOW, "Now you can go onto the hunt for Sauron!"); - inven_item_increase(o_idx, -99); - inven_item_optimize(o_idx); + inc_stack_size_ex(o_idx, -99, OPTIMIZE, NO_DESCRIBE); abandon_god(GOD_MELKOR); diff --git a/src/q_shroom.c b/src/q_shroom.c index 6a93f13d..b6e26cdf 100644 --- a/src/q_shroom.c +++ b/src/q_shroom.c @@ -133,8 +133,7 @@ bool_ quest_shroom_give_hook(char *fmt) if ((o_ptr->tval != TV_FOOD) || (o_ptr->pval2 != 1)) return (FALSE); /* Take a mushroom */ - inven_item_increase(item, -1); - inven_item_optimize(item); + inc_stack_size_ex(item, -1, OPTIMIZE, NO_DESCRIBE); cquest.data[0]++; if (cquest.data[0] == cquest.data[1]) diff --git a/src/spells1.c b/src/spells1.c index b38fa854..fa2a846f 100644 --- a/src/spells1.c +++ b/src/spells1.c @@ -1326,8 +1326,7 @@ void take_hit(int damage, cptr hit_from) cmsg_format(TERM_L_RED, "%s dies from protecting you, you feel very sad...", sym_name); - inven_item_increase(INVEN_CARRY, -1); - inven_item_optimize(INVEN_CARRY); + inc_stack_size_ex(INVEN_CARRY, -1, OPTIMIZE, NO_DESCRIBE); damage -= o_ptr->pval2; o_ptr->pval2 = 0; p_ptr->redraw |= PR_MH; @@ -1884,8 +1883,7 @@ static int inven_damage(inven_func typ, int perc) } /* Destroy "amt" items */ - inven_item_increase(i, -amt); - inven_item_optimize(i); + inc_stack_size_ex(i, -amt, OPTIMIZE, NO_DESCRIBE); /* Count the casualties */ k += amt; diff --git a/src/spells2.c b/src/spells2.c index c365bb5b..d6bfe629 100644 --- a/src/spells2.c +++ b/src/spells2.c @@ -670,21 +670,8 @@ bool_ alchemy(void) /* Turns an object into gold, gain some of its value in a sh } - /* Eliminate the item (from the pack) */ - if (item >= 0) - { - inven_item_increase(item, -amt); - inven_item_describe(item); - inven_item_optimize(item); - } - - /* Eliminate the item (from the floor) */ - else - { - floor_item_increase(0 - item, -amt); - floor_item_describe(0 - item); - floor_item_optimize(0 - item); - } + /* Eliminate the item */ + inc_stack_size(item, -amt); return TRUE; } @@ -4758,21 +4745,8 @@ bool_ recharge(int power) /* Reduce rod stack maximum timeout, drain wands. */ if (o_ptr->tval == TV_WAND) o_ptr->pval = 0; - /* Reduce and describe inventory */ - if (item >= 0) - { - inven_item_increase(item, -1); - inven_item_describe(item); - inven_item_optimize(item); - } - - /* Reduce and describe floor item */ - else - { - floor_item_increase(0 - item, -1); - floor_item_describe(0 - item); - floor_item_optimize(0 - item); - } + /* Reduce and describe */ + inc_stack_size(item, -1); } /* Destroy all memebers of a stack of objects. */ @@ -4785,20 +4759,7 @@ bool_ recharge(int power) /* Reduce and describe inventory */ - if (item >= 0) - { - inven_item_increase(item, -999); - inven_item_describe(item); - inven_item_optimize(item); - } - - /* Reduce and describe floor item */ - else - { - floor_item_increase(0 - item, -999); - floor_item_describe(0 - item); - floor_item_optimize(0 - item); - } + inc_stack_size(item, -999); } } } diff --git a/src/store.c b/src/store.c index 7da01b87..979c955a 100644 --- a/src/store.c +++ b/src/store.c @@ -3143,9 +3143,7 @@ void store_sell(void) } /* Take the item from the player, describe the result */ - inven_item_increase(item, -amt); - inven_item_describe(item); - inven_item_optimize(item); + inc_stack_size(item, -amt); /* Handle stuff */ handle_stuff(); @@ -3194,9 +3192,7 @@ void store_sell(void) choice = 0; /* Take it from the players inventory */ - inven_item_increase(item, -amt); - inven_item_describe(item); - inven_item_optimize(item); + inc_stack_size(item, -amt); /* Handle stuff */ handle_stuff(); @@ -3230,9 +3226,7 @@ void store_sell(void) } /* Take it from the players inventory */ - inven_item_increase(item, -amt); - inven_item_describe(item); - inven_item_optimize(item); + inc_stack_size(item, -amt); /* Handle stuff */ handle_stuff(); @@ -3877,9 +3871,7 @@ void do_cmd_store(void) msg_format("You drop %s (%c).", o_name, index_to_label(item)); /* Remove it from the players inventory */ - inven_item_increase(item, -255); - inven_item_describe(item); - inven_item_optimize(item); + inc_stack_size(item, -255); /* Handle stuff */ handle_stuff(); @@ -4356,9 +4348,7 @@ void do_cmd_home_trump(void) msg_format("You drop %s (%c).", o_name, index_to_label(item)); /* Remove it from the players inventory */ - inven_item_increase(item, -255); - inven_item_describe(item); - inven_item_optimize(item); + inc_stack_size(item, -255); /* Handle stuff */ handle_stuff(); diff --git a/src/traps.c b/src/traps.c index 64a89374..ed93aabe 100644 --- a/src/traps.c +++ b/src/traps.c @@ -803,8 +803,8 @@ bool_ player_activate_trap_type(s16b y, s16b x, object_type *i_ptr, s16b item) /* Drop it somewhere */ do_trap_teleport_away(q_ptr, y, x); - inven_item_increase(i, -1); - inven_item_optimize(i); + inc_stack_size_ex(i, -1, OPTIMIZE, NO_DESCRIBE); + ident = TRUE; } break; @@ -932,10 +932,11 @@ bool_ player_activate_trap_type(s16b y, s16b x, object_type *i_ptr, s16b item) if ((j_ptr->tval == TV_SCROLL) && (j_ptr->sval == SV_SCROLL_WORD_OF_RECALL)) { - inven_item_increase(j, -j_ptr->number); - inven_item_optimize(j); + inc_stack_size_ex(j, -j_ptr->number, OPTIMIZE, NO_DESCRIBE); + combine_pack(); reorder_pack(); + if (!ident) { msg_print("A small fire works its way through your backpack. " @@ -1317,8 +1318,8 @@ bool_ player_activate_trap_type(s16b y, s16b x, object_type *i_ptr, s16b item) if (!cave_floor_bold(cy, cx)) continue; object_copy(j_ptr, &p_ptr->inventory[i]); - inven_item_increase(i, -999); - inven_item_optimize(i); + + inc_stack_size_ex(i, -999, OPTIMIZE, NO_DESCRIBE); p_ptr->notice |= (PN_COMBINE | PN_REORDER); @@ -1571,8 +1572,9 @@ bool_ player_activate_trap_type(s16b y, s16b x, object_type *i_ptr, s16b item) /* drop carefully */ drop_near(&tmp_obj, 0, y, x); - inven_item_increase(i, -999); - inven_item_optimize(i); + + inc_stack_size_ex(i, -999, OPTIMIZE, NO_DESCRIBE); + p_ptr->notice |= (PN_COMBINE | PN_REORDER); if (!message) @@ -1606,8 +1608,9 @@ bool_ player_activate_trap_type(s16b y, s16b x, object_type *i_ptr, s16b item) /* drop carefully */ drop_near(&tmp_obj, 0, y, x); - inven_item_increase(i, -999); - inven_item_optimize(i); + + inc_stack_size_ex(i, -999, OPTIMIZE, NO_DESCRIBE); + p_ptr->notice |= (PN_COMBINE | PN_REORDER); if (!message) @@ -1640,8 +1643,9 @@ bool_ player_activate_trap_type(s16b y, s16b x, object_type *i_ptr, s16b item) /* drop carefully */ drop_near(&tmp_obj, 0, y, x); - inven_item_increase(i, -999); - inven_item_optimize(i); + + inc_stack_size_ex(i, -999, OPTIMIZE, NO_DESCRIBE); + p_ptr->notice |= (PN_COMBINE | PN_REORDER); if (!message) @@ -2277,10 +2281,8 @@ void do_cmd_set_trap(void) cave[p_ptr->py][p_ptr->px].special2 = floor_carry(p_ptr->py, p_ptr->px, i_ptr); /* Modify, Describe, Optimize */ - inven_item_increase(item_kit, -1); - inven_item_describe(item_kit); - inven_item_increase(item_load, -num); - inven_item_describe(item_load); + inc_stack_size_ex(item_kit, -1, NO_OPTIMIZE, DESCRIBE); + inc_stack_size_ex(item_load, -num, NO_OPTIMIZE, DESCRIBE); for (i = 0; i < INVEN_WIELD; i++) { |