summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crawl-ref/source/externs.h9
-rw-r--r--crawl-ref/source/mon-util.cc17
-rw-r--r--crawl-ref/source/mon-util.h1
-rw-r--r--crawl-ref/source/monstuff.cc24
-rw-r--r--crawl-ref/source/monstuff.h2
-rw-r--r--crawl-ref/source/player.cc20
-rw-r--r--crawl-ref/source/player.h2
7 files changed, 56 insertions, 19 deletions
diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h
index 3c8a6700d3..51a3c46b4c 100644
--- a/crawl-ref/source/externs.h
+++ b/crawl-ref/source/externs.h
@@ -1044,8 +1044,8 @@ public:
size_type body_size(int psize = PSIZE_TORSO, bool base = false) const;
int body_weight() const;
int total_weight() const;
- int damage_brand(int attk = -1);
- int damage_type(int attk = -1);
+ int damage_brand(int which_attack = -1);
+ int damage_type(int which_attack = -1);
int has_claws(bool allow_tran = true) const;
bool has_usable_claws(bool allow_tran = true) const;
item_def *weapon(int which_attack = -1);
@@ -1390,8 +1390,8 @@ public:
size_type body_size(int psize = PSIZE_TORSO, bool base = false) const;
int body_weight() const;
int total_weight() const;
- int damage_brand(int attk = -1);
- int damage_type(int attk = -1);
+ int damage_brand(int which_attack = -1);
+ int damage_type(int which_attack = -1);
item_def *slot_item(equipment_type eq);
item_def *mslot_item(mon_inv_type sl) const;
@@ -1503,6 +1503,7 @@ public:
bool has_spell(spell_type spell) const;
bool has_attack_flavour(int flavour) const;
+ bool has_damage_type(int dam_type);
bool can_throw_large_rocks() const;
diff --git a/crawl-ref/source/mon-util.cc b/crawl-ref/source/mon-util.cc
index e6c1ac97d6..885ed6eb37 100644
--- a/crawl-ref/source/mon-util.cc
+++ b/crawl-ref/source/mon-util.cc
@@ -3972,6 +3972,7 @@ int monsters::missile_count()
{
if (const item_def *missile = missiles())
return (missile->quantity);
+
return (0);
}
@@ -3991,7 +3992,7 @@ item_def *monsters::weapon(int which_attack)
if (attk.type != AT_HIT)
return (NULL);
- // Even/odd attacks use main/offhand weapon
+ // Even/odd attacks use main/offhand weapon.
if (which_attack > 1)
which_attack &= 1;
@@ -5411,7 +5412,7 @@ void monsters::wield_melee_weapon(int near)
item_def *monsters::slot_item(equipment_type eq)
{
- return mslot_item(equip_slot_to_mslot(eq));
+ return (mslot_item(equip_slot_to_mslot(eq)));
}
item_def *monsters::mslot_item(mon_inv_type mslot) const
@@ -5925,6 +5926,18 @@ bool monsters::has_attack_flavour(int flavour) const
return (false);
}
+bool monsters::has_damage_type(int dam_type)
+{
+ for (int i = 0; i < 4; ++i)
+ {
+ const int dmg_type = damage_type(i);
+ if (dmg_type == dam_type)
+ return (true);
+ }
+
+ return (false);
+}
+
bool monsters::visible() const
{
return (mons_near(this) && player_monster_visible(this));
diff --git a/crawl-ref/source/mon-util.h b/crawl-ref/source/mon-util.h
index ff4bba2228..1366f6042d 100644
--- a/crawl-ref/source/mon-util.h
+++ b/crawl-ref/source/mon-util.h
@@ -720,6 +720,7 @@ void define_monster(monsters &mons);
* *********************************************************************** */
void mons_pacify(monsters *mon);
+
// last updated 4jan2001 (gdl)
/* ***********************************************************************
* called from: monstuff
diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc
index 9a2e180e1c..f528547519 100644
--- a/crawl-ref/source/monstuff.cc
+++ b/crawl-ref/source/monstuff.cc
@@ -2788,6 +2788,24 @@ bool swap_check(monsters *monster, coord_def &loc, bool quiet)
return (swap);
}
+// Given an adjacent monster, returns true if the monster can hit it
+// (the monster should not be submerged, be submerged in shallow water
+// if the monster has a polearm, or be submerged in anything if the
+// monster has tentacles).
+bool monster_can_hit_monster(monsters *monster, const monsters *targ)
+{
+ if (!mons_is_submerged(targ))
+ return (true);
+
+ if (grd(targ->pos()) == DNGN_SHALLOW_WATER)
+ {
+ item_def *weapon = monster->weapon();
+ return (weapon && weapon_skill(*weapon) == SK_POLEARMS);
+ }
+
+ return (monster->has_damage_type(DVORP_TENTACLE));
+}
+
void mons_get_damage_level(const monsters* monster, std::string& desc,
mon_dam_level_type& dam_level)
{
@@ -7802,13 +7820,11 @@ static void _handle_monster_move(monsters *monster)
}
// See if we move into (and fight) an unfriendly monster.
- // FIXME: looks like the lack of a check on 'submerged' here
- // is the reason monsters can attack submerged monsters they
- // happen to walk into. -cao
monsters* targ = monster_at(monster->pos() + mmov);
if (targ
&& targ != monster
- && !mons_aligned(monster->mindex(), targ->mindex()))
+ && !mons_aligned(monster->mindex(), targ->mindex())
+ && monster_can_hit_monster(monster, targ))
{
// Maybe they can swap places?
if (_swap_monsters(monster, targ))
diff --git a/crawl-ref/source/monstuff.h b/crawl-ref/source/monstuff.h
index cfe656ddcc..5bb6a4b011 100644
--- a/crawl-ref/source/monstuff.h
+++ b/crawl-ref/source/monstuff.h
@@ -174,6 +174,8 @@ bool message_current_target(void);
unsigned int monster_index(const monsters *monster);
+bool monster_can_hit_monster(monsters *monster, const monsters *targ);
+
void mons_get_damage_level(const monsters*, std::string& desc,
mon_dam_level_type&);
diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc
index b44093e7a4..a362419d2a 100644
--- a/crawl-ref/source/player.cc
+++ b/crawl-ref/source/player.cc
@@ -771,13 +771,13 @@ bool you_tran_can_wear(int eq, bool check_mutation)
// eq must be in [EQ_WEAPON, EQ_AMULET], or bad things will happen.
item_def *player_slot_item(equipment_type eq)
{
- return you.slot_item(eq);
+ return (you.slot_item(eq));
}
// Returns the item in the player's weapon slot.
item_def *player_weapon()
{
- return you.weapon();
+ return (you.weapon());
}
bool player_weapon_wielded()
@@ -1093,11 +1093,13 @@ bool player_can_hit_monster(const monsters *mon)
if (!mons_is_submerged(mon))
return (true);
- if (grd(mon->pos()) != DNGN_SHALLOW_WATER)
- return (false);
+ if (grd(mon->pos()) == DNGN_SHALLOW_WATER)
+ {
+ const item_def *weapon = you.weapon();
+ return (weapon && weapon_skill(*weapon) == SK_POLEARMS);
+ }
- const item_def *weapon = you.weapon();
- return (weapon && weapon_skill(*weapon) == SK_POLEARMS);
+ return (false);
}
int player_teleport(bool calc_unid)
@@ -6441,13 +6443,13 @@ item_def *player::slot_item(equipment_type eq)
ASSERT(eq >= EQ_WEAPON && eq <= EQ_AMULET);
const int item = equip[eq];
- return (item == -1? NULL : &inv[item]);
+ return (item == -1 ? NULL : &inv[item]);
}
// Returns the item in the player's weapon slot.
item_def *player::weapon(int /* which_attack */)
{
- return slot_item(EQ_WEAPON);
+ return (slot_item(EQ_WEAPON));
}
bool actor::can_wield(const item_def* item, bool ignore_curse,
@@ -6510,7 +6512,7 @@ item_def *player::shield()
if (!you_tran_can_wear(EQ_SHIELD))
return (NULL);
- return slot_item(EQ_SHIELD);
+ return (slot_item(EQ_SHIELD));
}
std::string player::name(description_level_type type, bool) const
diff --git a/crawl-ref/source/player.h b/crawl-ref/source/player.h
index 58bda4f796..bb11ff8512 100644
--- a/crawl-ref/source/player.h
+++ b/crawl-ref/source/player.h
@@ -442,6 +442,8 @@ bool rot_player(int amount);
bool player_has_spell(spell_type spell);
size_type player_size(int psize = PSIZE_TORSO, bool base = false);
+item_def *player_slot_item(equipment_type eq);
+
bool player_weapon_wielded();
item_def *player_weapon();
item_def *player_shield();