diff options
author | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-10-23 14:22:06 +0000 |
---|---|---|
committer | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-10-23 14:22:06 +0000 |
commit | 17717c03ff836658253a133691f2277f308c7617 (patch) | |
tree | ad718025505767a6e0fe8638987574da8d68a97b | |
parent | 7859dd43a57685d205f28f4a1cc5a8dc27d7de25 (diff) | |
download | crawl-ref-17717c03ff836658253a133691f2277f308c7617.tar.gz crawl-ref-17717c03ff836658253a133691f2277f308c7617.zip |
Trunk->0.3 merge: r2516, monster armour fix.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/branches/stone_soup-0.3@2520 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r-- | crawl-ref/source/externs.h | 4 | ||||
-rw-r--r-- | crawl-ref/source/items.cc | 8 | ||||
-rw-r--r-- | crawl-ref/source/mon-util.cc | 33 |
3 files changed, 44 insertions, 1 deletions
diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h index a9f9f5ff3a..7c6a19c529 100644 --- a/crawl-ref/source/externs.h +++ b/crawl-ref/source/externs.h @@ -362,6 +362,8 @@ public: // Returns index in mitm array. Results are undefined if this item is // not in the array! int index() const; + + int armour_rating() const; bool launched_by(const item_def &launcher) const; @@ -994,6 +996,7 @@ public: bool pickup_melee_weapon(item_def &item, int near); bool pickup_throwable_weapon(item_def &item, int near); bool pickup_weapon(item_def &item, int near, bool force); + bool pickup_armour(item_def &item, int near, bool force); bool pickup_misc(item_def &item, int near); bool pickup_missile(item_def &item, int near, bool force); bool eat_corpse(item_def &carrion, int near); @@ -1090,6 +1093,7 @@ private: bool drop_item(int eslot, int near); bool wants_weapon(const item_def &item) const; + bool wants_armour(const item_def &item) const; bool can_throw_rocks() const; void lose_pickup_energy(); bool check_set_valid_home(const coord_def &place, diff --git a/crawl-ref/source/items.cc b/crawl-ref/source/items.cc index 9d17d4d2a3..7a1e980a98 100644 --- a/crawl-ref/source/items.cc +++ b/crawl-ref/source/items.cc @@ -3059,3 +3059,11 @@ int item_def::index() const { return (this - mitm.buffer()); } + +int item_def::armour_rating() const +{ + if (!is_valid_item(*this) || base_type != OBJ_ARMOUR) + return (0); + + return (property(*this, PARM_AC) + plus); +} diff --git a/crawl-ref/source/mon-util.cc b/crawl-ref/source/mon-util.cc index 41d85c85a1..5f73bc91df 100644 --- a/crawl-ref/source/mon-util.cc +++ b/crawl-ref/source/mon-util.cc @@ -2881,6 +2881,37 @@ bool monsters::wants_weapon(const item_def &weap) const return (true); } +bool monsters::wants_armour(const item_def &item) const +{ + // FIXME: Need monster body-size handling. For now, never attempt to + // change armour. + return (!mslot_item(MSLOT_ARMOUR)); +} + +bool monsters::pickup_armour(item_def &item, int near, bool force) +{ + ASSERT(item.base_type == OBJ_ARMOUR); + + if (!force && !wants_armour(item)) + return (false); + + // XXX: Monsters can only equip body armour (as of 0.3). + if (get_armour_slot(item) != EQ_BODY_ARMOUR) + return (false); + + // XXX: Very simplistic armour evaluation for the moment. + if (const item_def *existing_armour = slot_item(EQ_BODY_ARMOUR)) + { + if (!force && existing_armour->armour_rating() >= item.armour_rating()) + return (false); + + if (!drop_item(MSLOT_ARMOUR, near)) + return (false); + } + + return pickup(item, MSLOT_ARMOUR, near); +} + bool monsters::pickup_weapon(item_def &item, int near, bool force) { if (!force && !wants_weapon(item)) @@ -2993,7 +3024,7 @@ bool monsters::pickup_item(item_def &item, int near, bool force) case OBJ_WEAPONS: return pickup_weapon(item, near, force); case OBJ_ARMOUR: - return pickup(item, MSLOT_ARMOUR, near); + return pickup_armour(item, near, force); case OBJ_MISSILES: return pickup_missile(item, near, force); case OBJ_WANDS: |