summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/monster.cc
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 /crawl-ref/source/monster.cc
parent42ddfa208c630b2990b8ea407c6bd00b3dbd031a (diff)
downloadcrawl-ref-810044142f6bb87906e4ba88363e20704914ac64.tar.gz
crawl-ref-810044142f6bb87906e4ba88363e20704914ac64.zip
Don't mistake ranged weapons for melee weapons
Diffstat (limited to 'crawl-ref/source/monster.cc')
-rw-r--r--crawl-ref/source/monster.cc25
1 files changed, 25 insertions, 0 deletions
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
{