diff options
-rw-r--r-- | crawl-ref/source/item_use.cc | 7 | ||||
-rw-r--r-- | crawl-ref/source/items.cc | 33 | ||||
-rw-r--r-- | crawl-ref/source/items.h | 3 | ||||
-rw-r--r-- | crawl-ref/source/quiver.cc | 24 |
4 files changed, 39 insertions, 28 deletions
diff --git a/crawl-ref/source/item_use.cc b/crawl-ref/source/item_use.cc index becf94c833..9581778641 100644 --- a/crawl-ref/source/item_use.cc +++ b/crawl-ref/source/item_use.cc @@ -1276,17 +1276,10 @@ int get_next_fire_item(int current, int direction) for (unsigned i = 0; i < fire_order.size(); i++) { -#ifdef DEBUG_QUIVER - mprf(MSGCH_DIAGNOSTICS, "i: %d, slot: %d", i, fire_order[i]); -#endif if (fire_order[i] == current) { unsigned next = (i + direction + fire_order.size()) % fire_order.size(); -#ifdef DEBUG_QUIVER - mprf(MSGCH_DIAGNOSTICS, "i: %d (%d), next: %d (%d), size: %d", - i, current, next, fire_order[next], fire_order.size()); -#endif return fire_order[next]; } } diff --git a/crawl-ref/source/items.cc b/crawl-ref/source/items.cc index 690e072ed7..38ba9d2681 100644 --- a/crawl-ref/source/items.cc +++ b/crawl-ref/source/items.cc @@ -1297,33 +1297,23 @@ unsigned long ident_flags(const item_def &item) return (flags); } -bool items_stack( const item_def &item1, const item_def &item2, - bool force_merge ) +bool items_similar(const item_def &item1, const item_def &item2) { - // both items must be stackable - if (!force_merge - && (!is_stackable_item( item1 ) || !is_stackable_item( item2 ))) - { - return (false); - } - - // base and sub-types must always be the same to stack + // Base and sub-types must always be the same to stack. if (item1.base_type != item2.base_type || item1.sub_type != item2.sub_type) return (false); - ASSERT(force_merge || item1.base_type != OBJ_WEAPONS); - if (item1.base_type == OBJ_GOLD) return (true); - // These classes also require pluses and special + // These classes also require pluses and special. if (item1.base_type == OBJ_WEAPONS // only throwing weapons || item1.base_type == OBJ_MISSILES || item1.base_type == OBJ_MISCELLANY) // only runes { if (item1.plus != item2.plus - || item1.plus2 != item2.plus2 - || item1.special != item2.special) + || item1.plus2 != item2.plus2 + || item1.special != item2.special) { return (false); } @@ -1366,6 +1356,19 @@ bool items_stack( const item_def &item1, const item_def &item2, return (true); } +bool items_stack( const item_def &item1, const item_def &item2, + bool force_merge ) +{ + // Both items must be stackable. + if (!force_merge + && (!is_stackable_item( item1 ) || !is_stackable_item( item2 ))) + { + return (false); + } + + return items_similar(item1, item2); +} + static int _userdef_find_free_slot(const item_def &i) { #ifdef CLUA_BINDINGS diff --git a/crawl-ref/source/items.h b/crawl-ref/source/items.h index 1be9387d4d..bdccd3bc43 100644 --- a/crawl-ref/source/items.h +++ b/crawl-ref/source/items.h @@ -42,8 +42,9 @@ void move_item_stack_to_grid( int x, int y, int targ_x, int targ_y ); int move_item_to_player( int obj, int quant_got, bool quiet = false ); void mark_items_non_pickup_at(const coord_def &pos); bool is_stackable_item( const item_def &item ); +bool items_similar( const item_def &item1, const item_def &item2 ); bool items_stack( const item_def &item1, const item_def &item2, - bool force = false ); + bool force_merge = false ); item_def find_item_type(object_class_type base_type, std::string name); item_def *find_floor_item(object_class_type cls, int sub_type); diff --git a/crawl-ref/source/quiver.cc b/crawl-ref/source/quiver.cc index 8bf0761065..011976e6fa 100644 --- a/crawl-ref/source/quiver.cc +++ b/crawl-ref/source/quiver.cc @@ -25,7 +25,8 @@ static int _get_pack_slot(const item_def&); static ammo_t _get_weapon_ammo_type(const item_def*); static bool _item_matches(const item_def &item, fire_type types, const item_def* launcher); -static bool _items_similar(const item_def& a, const item_def& b); +static bool _items_similar(const item_def& a, const item_def& b, + bool force = true); // ---------------------------------------------------------------------- // player_quiver @@ -270,6 +271,7 @@ void player_quiver::on_weapon_changed() { if (!_items_similar(*weapon, m_last_weapon)) { + // Weapon type changed. m_last_weapon = *weapon; m_last_used_type = _get_weapon_ammo_type(weapon); } @@ -328,7 +330,7 @@ void player_quiver::_maybe_fill_empty_slot() } #ifdef DEBUG_QUIVER - mpr("recalculating fire order...", MSGCH_DIAGNOSTICS); + mpr("Recalculating fire order...", MSGCH_DIAGNOSTICS); #endif const launch_retval desired_ret = @@ -559,10 +561,19 @@ static int _get_pack_slot(const item_def& item) if (! is_valid_item(item)) return -1; + // First try to find the exact same item. for (int i = 0; i < ENDOFPACK; i++) { const item_def& inv_item = you.inv[i]; - if (inv_item.quantity && _items_similar(item, you.inv[i])) + if (inv_item.quantity && _items_similar(item, you.inv[i], false)) + return i; + } + + // If that fails, try to find an item sufficiently similar. + for (int i = 0; i < ENDOFPACK; i++) + { + const item_def& inv_item = you.inv[i]; + if (inv_item.quantity && _items_similar(item, you.inv[i], true)) return i; } @@ -596,8 +607,11 @@ static ammo_t _get_weapon_ammo_type(const item_def* weapon) } } -static bool _items_similar(const item_def& a, const item_def& b) +static bool _items_similar(const item_def& a, const item_def& b, bool force) { + if (!force) + return (items_similar(a, b) && a.slot == b.slot); + // This is a reasonable implementation for now. - return items_stack(a, b, true); + return items_stack(a, b, force); } |