summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/quiver.cc
diff options
context:
space:
mode:
authorj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2008-06-29 14:14:04 +0000
committerj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2008-06-29 14:14:04 +0000
commitf90424b8c2cb4d62ef5e34062cc6903918ecd37f (patch)
tree85a1868739f8ad9bb222cf527f823181af9e3153 /crawl-ref/source/quiver.cc
parenta2f0ab5525c06209f40a011bc7080c8b7d69b5e3 (diff)
downloadcrawl-ref-f90424b8c2cb4d62ef5e34062cc6903918ecd37f.tar.gz
crawl-ref-f90424b8c2cb4d62ef5e34062cc6903918ecd37f.zip
Force quiver to attempt to use the exact same item in inventory (slot
and all, if it still exists) before accepting any item that happens to have the same properties (base + subtype, plusses etc.) git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@6220 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/quiver.cc')
-rw-r--r--crawl-ref/source/quiver.cc24
1 files changed, 19 insertions, 5 deletions
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);
}