summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-10-22 16:13:40 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-10-22 16:13:40 +0000
commitaa1ef7b743654c99bca7b4dfc6f7d7bfd50307a0 (patch)
treef85f286f22c0b92a9843ddfc6ff1237229ed6ae5
parentff6bdc3daff822e5b59b9fbb48b2f74a2d1d9c30 (diff)
downloadcrawl-ref-aa1ef7b743654c99bca7b4dfc6f7d7bfd50307a0.tar.gz
crawl-ref-aa1ef7b743654c99bca7b4dfc6f7d7bfd50307a0.zip
Fixed monsters wearing shields and other inappropriate armour as body armour.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2516 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r--crawl-ref/source/externs.h4
-rw-r--r--crawl-ref/source/items.cc8
-rw-r--r--crawl-ref/source/mon-util.cc33
3 files changed, 44 insertions, 1 deletions
diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h
index c42e4cd503..2765c45562 100644
--- a/crawl-ref/source/externs.h
+++ b/crawl-ref/source/externs.h
@@ -386,6 +386,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;
@@ -1053,6 +1055,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);
@@ -1155,6 +1158,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 a172aa1938..14377c9976 100644
--- a/crawl-ref/source/items.cc
+++ b/crawl-ref/source/items.cc
@@ -3256,3 +3256,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 8c34bda8d5..95ac1f840e 100644
--- a/crawl-ref/source/mon-util.cc
+++ b/crawl-ref/source/mon-util.cc
@@ -3094,6 +3094,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))
@@ -3206,7 +3237,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: