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-23 21:30:08 +0000
committerj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2008-06-23 21:30:08 +0000
commit8bc8c04fbe230fb0f962f43da1acb3c51c4f88f0 (patch)
tree70f4c3d5336e09492f3c46b73c58c47014825e45 /crawl-ref/source/quiver.cc
parent7ace26d7f10f5eaefbe12f454183c88dbcb09b73 (diff)
downloadcrawl-ref-8bc8c04fbe230fb0f962f43da1acb3c51c4f88f0.tar.gz
crawl-ref-8bc8c04fbe230fb0f962f43da1acb3c51c4f88f0.zip
Fix monster emergency spells not checking for ENCH_TP, thus allowing
monsters to cancel their teleportation without meaning to. (BR 2000428) Fix the quiver not being cleared when wielding the only quiverable (and thus previously quivered) item. (Un)wielding such an item now switches nicely between "Nothing wielded" and "Nothing quivered", as it should be. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@6089 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/quiver.cc')
-rw-r--r--crawl-ref/source/quiver.cc84
1 files changed, 58 insertions, 26 deletions
diff --git a/crawl-ref/source/quiver.cc b/crawl-ref/source/quiver.cc
index 8f9bf95d1b..68f8b48e87 100644
--- a/crawl-ref/source/quiver.cc
+++ b/crawl-ref/source/quiver.cc
@@ -22,8 +22,10 @@
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 _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);
+
// ----------------------------------------------------------------------
// player_quiver
// ----------------------------------------------------------------------
@@ -57,7 +59,7 @@ void player_quiver::get_desired_item(const item_def** item_out, int* slot_out) c
}
else
{
- // Return the item in inv, since it will have an accurate count
+ // Return the item in inv, since it will have an accurate count.
if (item_out)
*item_out = &you.inv[slot];
}
@@ -168,7 +170,7 @@ void player_quiver::on_weapon_changed()
}
else
{
- if (! _items_similar(*weapon, m_last_weapon))
+ if (!_items_similar(*weapon, m_last_weapon))
{
m_last_weapon = *weapon;
m_last_used_type = _get_weapon_ammo_type(weapon);
@@ -194,13 +196,11 @@ void player_quiver::on_inv_quantity_changed(int slot, int amt)
else
{
// Maybe matches current stack. Redraw if so.
- //
const item_def* desired;
- int qv_slot; get_desired_item(&desired, &qv_slot);
+ int qv_slot;
+ get_desired_item(&desired, &qv_slot);
if (qv_slot == slot)
- {
you.redraw_quiver = true;
- }
}
}
@@ -209,13 +209,39 @@ void player_quiver::_maybe_fill_empty_slot()
{
const item_def* weapon = you.weapon();
const ammo_t slot = _get_weapon_ammo_type(weapon);
- if (! is_valid_item(m_last_used_of_type[slot]))
+#ifdef DEBUG_QUIVER
+ mprf(MSGCH_DIAGNOSTICS, "last quiver item: %s; link %d, wpn: %d",
+ m_last_used_of_type[slot].name(DESC_PLAIN).c_str(),
+ m_last_used_of_type[slot].link, you.equip[EQ_WEAPON]);
+#endif
+ bool unquiver_weapon = false;
+
+ if (is_valid_item(m_last_used_of_type[slot]))
+ {
+ // If we're wielding an item previously quivered, the quiver may need
+ // to be cleared. Else, any already quivered item is valid and we
+ // don't need to do anything else.
+ if (m_last_used_of_type[slot].link == you.equip[EQ_WEAPON])
+ unquiver_weapon = true;
+ else
+ return;
+ }
+
+#ifdef DEBUG_QUIVER
+ mpr("recalculating fire order...", MSGCH_DIAGNOSTICS);
+#endif
+ // const launch_retval desired_ret =
+ // (weapon && is_range_weapon(*weapon)) ? LRET_LAUNCHED : LRET_THROWN;
+ const launch_retval desired_ret =
+ (slot == AMMO_THROW ? LRET_THROWN : LRET_LAUNCHED);
+ std::vector<int> order; _get_fire_order(order, false, weapon);
+ if (unquiver_weapon && order.empty())
+ {
+// m_last_used_of_type[slot] = you.inv[order[i]];
+ m_last_used_of_type[slot].quantity = 0;
+ }
+ else
{
- // const launch_retval desired_ret =
- // (weapon && is_range_weapon(*weapon)) ? LRET_LAUNCHED : LRET_THROWN;
- const launch_retval desired_ret =
- (slot == AMMO_THROW ? LRET_THROWN : LRET_LAUNCHED);
- std::vector<int> order; _get_fire_order(order, false, weapon);
for (unsigned int i = 0; i < order.size(); i++)
{
if (is_launched(&you, weapon, you.inv[order[i]]) == desired_ret)
@@ -240,43 +266,49 @@ void player_quiver::get_fire_order(std::vector<int>& v) const
// fire order is empty.
//
// launcher determines what items match the 'launcher' fire_order type.
-void player_quiver::_get_fire_order(
- std::vector<int>& order,
- bool ignore_inscription_etc,
- const item_def* launcher) const
+void player_quiver::_get_fire_order( std::vector<int>& order,
+ bool ignore_inscription_etc,
+ const item_def* launcher) const
{
- const int inv_start = (ignore_inscription_etc ? 0 : Options.fire_items_start);
+ const int inv_start = (ignore_inscription_etc ? 0
+ : Options.fire_items_start);
// If in a net, cannot throw anything, and can only launch from blowgun.
if (you.attribute[ATTR_HELD])
{
if (launcher && launcher->sub_type == WPN_BLOWGUN)
- for (int i_inv=inv_start; i_inv<ENDOFPACK; i_inv++)
- if (is_valid_item(you.inv[i_inv]) && you.inv[i_inv].launched_by(*launcher))
+ {
+ for (int i_inv = inv_start; i_inv < ENDOFPACK; i_inv++)
+ if (is_valid_item(you.inv[i_inv])
+ && you.inv[i_inv].launched_by(*launcher))
+ {
order.push_back(i_inv);
+ }
+ }
return;
}
- for (int i_inv=inv_start; i_inv<ENDOFPACK; i_inv++)
+ for (int i_inv = inv_start; i_inv < ENDOFPACK; i_inv++)
{
const item_def& item = you.inv[i_inv];
if (!is_valid_item(item))
continue;
+
+ // Don't quiver wielded weapon.
if (you.equip[EQ_WEAPON] == i_inv)
continue;
// =f prevents item from being in fire order.
- if (!ignore_inscription_etc &&
- strstr(item.inscription.c_str(), "=f"))
+ if (!ignore_inscription_etc
+ && strstr(item.inscription.c_str(), "=f"))
{
continue;
}
- for (unsigned int i_flags = 0;
- i_flags < Options.fire_order.size();
+ for (unsigned int i_flags = 0; i_flags < Options.fire_order.size();
i_flags++)
{
- if (_item_matches(item, (fire_type)Options.fire_order[i_flags],
+ if (_item_matches(item, (fire_type) Options.fire_order[i_flags],
launcher))
{
order.push_back( (i_flags<<16) | (i_inv & 0xffff) );