From ae5abcdab69c7caa0570e98378f864aaf07096d0 Mon Sep 17 00:00:00 2001 From: dshaligram Date: Fri, 1 Jun 2007 12:39:38 +0000 Subject: [1612448] Allow polearm users to attack monster submerged in shallow water. Need to update the AI so the monster either flees or unsubmerges and fights. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1501 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/acr.cc | 2 +- crawl-ref/source/defines.h | 1 + crawl-ref/source/delay.cc | 2 +- crawl-ref/source/externs.h | 3 +++ crawl-ref/source/fight.cc | 3 +++ crawl-ref/source/mon-util.cc | 5 +++++ crawl-ref/source/player.cc | 20 ++++++++++++++++++++ crawl-ref/source/player.h | 1 + crawl-ref/source/view.cc | 2 +- 9 files changed, 36 insertions(+), 3 deletions(-) (limited to 'crawl-ref') diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc index 8e6407e8d1..3979647aa0 100644 --- a/crawl-ref/source/acr.cc +++ b/crawl-ref/source/acr.cc @@ -2682,7 +2682,7 @@ static void open_door(int move_x, int move_y, bool check_confused) const int mon = mgrd[dx][dy]; - if (mon != NON_MONSTER && !mons_is_submerged(&menv[mon])) + if (mon != NON_MONSTER && player_can_hit_monster(&menv[mon])) { you_attack(mgrd[dx][dy], true); you.turn_is_over = true; diff --git a/crawl-ref/source/defines.h b/crawl-ref/source/defines.h index cf6e0f08e6..9ce64087e6 100644 --- a/crawl-ref/source/defines.h +++ b/crawl-ref/source/defines.h @@ -268,6 +268,7 @@ #define COLFLAG_MAYSTAB 0x0800 #define COLFLAG_STAIR_ITEM 0x1000 #define COLFLAG_REVERSE 0x2000 + #define COLFLAG_MASK 0xFF00 enum CHAR_ATTRIBUTES { diff --git a/crawl-ref/source/delay.cc b/crawl-ref/source/delay.cc index bf68aec5c8..469e225bf2 100644 --- a/crawl-ref/source/delay.cc +++ b/crawl-ref/source/delay.cc @@ -957,7 +957,7 @@ static void paranoid_option_disable( activity_interrupt_type ai, if (ai == AI_HIT_MONSTER || ai == AI_MONSTER_ATTACKS) { const monsters* mon = static_cast(at.data); - if (mon && !player_monster_visible(mon)) + if (mon && !player_monster_visible(mon) && !mons_is_submerged(mon)) { std::vector deactivatees; if (Options.autoprayer_on) diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h index 1d94adb686..c845e382f5 100644 --- a/crawl-ref/source/externs.h +++ b/crawl-ref/source/externs.h @@ -116,6 +116,7 @@ public: virtual coord_def pos() const = 0; virtual bool swimming() const = 0; + virtual bool submerged() const = 0; virtual bool floundering() const = 0; virtual size_type body_size(int psize = PSIZE_TORSO, @@ -743,6 +744,7 @@ public: coord_def pos() const; bool swimming() const; + bool submerged() const; bool floundering() const; size_type body_size(int psize = PSIZE_TORSO, bool base = false) const; int damage_type(int attk = -1); @@ -968,6 +970,7 @@ public: bool alive() const; coord_def pos() const; bool swimming() const; + bool submerged() const; bool can_drown() const; bool floundering() const; size_type body_size(int psize = PSIZE_TORSO, bool base = false) const; diff --git a/crawl-ref/source/fight.cc b/crawl-ref/source/fight.cc index 8eca25a856..1d50aecdcd 100644 --- a/crawl-ref/source/fight.cc +++ b/crawl-ref/source/fight.cc @@ -336,6 +336,9 @@ void melee_attack::init_attack() attacker_visible = attacker->visible(); defender_visible = defender && defender->visible(); needs_message = attacker_visible || defender_visible; + + if (defender && defender->submerged()) + unarmed_ok = false; } std::string melee_attack::actor_name(const actor *a, diff --git a/crawl-ref/source/mon-util.cc b/crawl-ref/source/mon-util.cc index 351ee05880..01e016e9c5 100644 --- a/crawl-ref/source/mon-util.cc +++ b/crawl-ref/source/mon-util.cc @@ -2223,6 +2223,11 @@ bool monsters::swimming() const return (grid_is_watery(grid) && monster_habitat(type) == DNGN_DEEP_WATER); } +bool monsters::submerged() const +{ + return (mons_is_submerged(this)); +} + bool monsters::floundering() const { const int grid = grd[x][y]; diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc index ccb9e67f32..2542bf2da0 100644 --- a/crawl-ref/source/player.cc +++ b/crawl-ref/source/player.cc @@ -319,6 +319,21 @@ bool move_player_to_grid( int x, int y, bool stepped, bool allow_shift, return (true); } +// Given an adjacent monster, returns true if the player can hit it (the +// monster should either not be submerged or submerged in shallow water, +// if the player has a polearm). +bool player_can_hit_monster(const monsters *mons) +{ + if (!mons_is_submerged(mons)) + return (true); + + if (grd(mons->pos()) != DNGN_SHALLOW_WATER) + return (false); + + const item_def *weapon = you.weapon(); + return (weapon && weapon_skill(*weapon) == SK_POLEARMS); +} + bool player_can_swim() { return you.can_swim(); @@ -4649,6 +4664,11 @@ bool player::swimming() const return in_water() && can_swim(); } +bool player::submerged() const +{ + return (false); +} + bool player::has_spell(int spell) const { for (int i = 0; i < 25; i++) diff --git a/crawl-ref/source/player.h b/crawl-ref/source/player.h index 2fab29c4a6..43123fddf2 100644 --- a/crawl-ref/source/player.h +++ b/crawl-ref/source/player.h @@ -28,6 +28,7 @@ int player_equip( int slot, int sub_type, bool calc_unid = true ); int player_equip_ego_type( int slot, int sub_type ); int player_damage_type( void ); int player_damage_brand( void ); +bool player_can_hit_monster(const monsters *mons); bool player_is_shapechanged(void); diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc index 651638be16..d297b4807e 100644 --- a/crawl-ref/source/view.cc +++ b/crawl-ref/source/view.cc @@ -299,7 +299,7 @@ static void get_symbol( int x, int y, { *ch = Feature[object].symbol; - const int colmask = *colour & CHATTR_COLMASK; + const int colmask = *colour & COLFLAG_MASK; // Don't clobber with BLACK, because the colour should be already set. if (Feature[object].colour != BLACK) *colour = Feature[object].colour | colmask; -- cgit v1.2.3-54-g00ecf