summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Feinberg <pleasingfung@gmail.com>2014-06-24 21:02:08 -0700
committerNicholas Feinberg <pleasingfung@gmail.com>2014-06-24 21:41:22 -0700
commit810044142f6bb87906e4ba88363e20704914ac64 (patch)
tree4807e8b7eba995d84736cb41dd5904872b6f01e8
parent42ddfa208c630b2990b8ea407c6bd00b3dbd031a (diff)
downloadcrawl-ref-810044142f6bb87906e4ba88363e20704914ac64.tar.gz
crawl-ref-810044142f6bb87906e4ba88363e20704914ac64.zip
Don't mistake ranged weapons for melee weapons
-rw-r--r--crawl-ref/source/bless.cc4
-rw-r--r--crawl-ref/source/monster.cc25
-rw-r--r--crawl-ref/source/monster.h1
3 files changed, 28 insertions, 2 deletions
diff --git a/crawl-ref/source/bless.cc b/crawl-ref/source/bless.cc
index a975dc6683..1ff5b6ddf1 100644
--- a/crawl-ref/source/bless.cc
+++ b/crawl-ref/source/bless.cc
@@ -173,7 +173,7 @@ static void _gift_ammo_to_orc(monster* orc, bool initial_gift = false)
*/
static string _beogh_bless_melee_weapon(monster* mon)
{
- item_def* wpn_ptr = mon->weapon();
+ item_def* wpn_ptr = mon->melee_weapon();
ASSERT(wpn_ptr != NULL);
item_def& wpn = *wpn_ptr;
@@ -255,7 +255,7 @@ static string _beogh_bless_ranged_weapon(monster* mon)
*/
static string _beogh_bless_weapon(monster* mon)
{
- const item_def* wpn_ptr = mon->weapon();
+ const item_def* wpn_ptr = mon->melee_weapon();
if (wpn_ptr == NULL)
{
_gift_weapon_to_orc(mon);
diff --git a/crawl-ref/source/monster.cc b/crawl-ref/source/monster.cc
index 2bc212a56b..15d7d62633 100644
--- a/crawl-ref/source/monster.cc
+++ b/crawl-ref/source/monster.cc
@@ -537,6 +537,31 @@ item_def *monster::weapon(int which_attack) const
return weap == NON_ITEM ? NULL : &mitm[weap];
}
+/**
+ * Find a monster's melee weapon, if any.
+ *
+ * Finds melee weapons carried in the primary or aux slot; if the monster has
+ * both (dual-wielding), choose one with a coinflip.
+ *
+ * @return A melee weapon that the monster is holding, or null.
+ */
+item_def *monster::melee_weapon() const
+{
+ item_def* primary_weapon = mslot_item(MSLOT_WEAPON);
+ item_def* secondary_weapon = mslot_item(MSLOT_ALT_WEAPON);
+ const bool primary_is_melee = primary_weapon
+ && !is_range_weapon(*primary_weapon);
+ const bool secondary_is_melee = secondary_weapon
+ && !is_range_weapon(*secondary_weapon);
+ if (primary_is_melee && secondary_is_melee)
+ return coinflip() ? primary_weapon : secondary_weapon;
+ if (primary_is_melee)
+ return primary_weapon;
+ if (secondary_is_melee)
+ return secondary_weapon;
+ return NULL;
+}
+
// Give hands required to wield weapon.
hands_reqd_type monster::hands_reqd(const item_def &item) const
{
diff --git a/crawl-ref/source/monster.h b/crawl-ref/source/monster.h
index 3b131772b8..06a2bcb861 100644
--- a/crawl-ref/source/monster.h
+++ b/crawl-ref/source/monster.h
@@ -240,6 +240,7 @@ public:
item_def *mslot_item(mon_inv_type sl) const;
item_def *weapon(int which_attack = -1) const;
item_def *launcher();
+ item_def *melee_weapon() const;
item_def *missiles();
item_def *shield() const;