From dac84d3345e678e512593f7652dd59a3fde355c1 Mon Sep 17 00:00:00 2001 From: dshaligram Date: Sun, 2 Dec 2007 13:23:51 +0000 Subject: Trunk->0.3 merge (2920): Fixed monster raise dead using player LOS. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/branches/stone_soup-0.3@2973 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/abl-show.cc | 2 +- crawl-ref/source/externs.h | 7 +++++-- crawl-ref/source/it_use3.cc | 2 +- crawl-ref/source/monstuff.cc | 3 ++- crawl-ref/source/mstuff2.cc | 3 ++- crawl-ref/source/spells2.cc | 42 ++++++++++++++++++++++++------------------ crawl-ref/source/spells2.h | 4 +++- crawl-ref/source/spl-cast.cc | 2 +- crawl-ref/source/view.cc | 31 +++++++++++++++++-------------- crawl-ref/source/view.h | 14 ++++++++++---- 10 files changed, 66 insertions(+), 44 deletions(-) diff --git a/crawl-ref/source/abl-show.cc b/crawl-ref/source/abl-show.cc index d9f27b19dc..2b38957221 100644 --- a/crawl-ref/source/abl-show.cc +++ b/crawl-ref/source/abl-show.cc @@ -1412,7 +1412,7 @@ static bool do_ability(const ability_def& abil) case ABIL_YRED_ANIMATE_DEAD: mpr("You call on the dead to walk for you..."); - animate_dead( 1 + you.skills[SK_INVOCATIONS], BEH_FRIENDLY, + animate_dead( &you, 1 + you.skills[SK_INVOCATIONS], BEH_FRIENDLY, you.pet_target, 1 ); exercise(SK_INVOCATIONS, 2 + random2(4)); diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h index d815a2f1e6..3c1b6b4370 100644 --- a/crawl-ref/source/externs.h +++ b/crawl-ref/source/externs.h @@ -1211,6 +1211,8 @@ private: }; typedef FixedArray feature_grid; +typedef FixedArray + env_show_grid; struct crawl_environment { @@ -1229,8 +1231,9 @@ public: FixedArray< map_cell, GXM, GYM > map; // discovered terrain - FixedArray - show; // view window char + // Glyphs of squares that are in LOS. + env_show_grid show; + FixedArray show_col; // view window colour diff --git a/crawl-ref/source/it_use3.cc b/crawl-ref/source/it_use3.cc index e3d33d45d8..56e90774cf 100644 --- a/crawl-ref/source/it_use3.cc +++ b/crawl-ref/source/it_use3.cc @@ -197,7 +197,7 @@ void special_wielded() case SPWLD_ZONGULDROK: if (one_chance_in(5)) { - animate_dead( 1 + random2(3), BEH_HOSTILE, MHITYOU, 1 ); + animate_dead( &you, 1 + random2(3), BEH_HOSTILE, MHITYOU, 1 ); did_god_conduct( DID_NECROMANCY, 1 ); } break; diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc index 2ed1f64598..cd5b730a45 100644 --- a/crawl-ref/source/monstuff.cc +++ b/crawl-ref/source/monstuff.cc @@ -3572,7 +3572,8 @@ static bool handle_spell( monsters *monster, bolt & beem ) // Try to animate dead: if nothing rises, pretend we didn't cast it if (spell_cast == SPELL_ANIMATE_DEAD - && !animate_dead( 100, SAME_ATTITUDE(monster), monster->foe, 0 )) + && !animate_dead( monster, 100, SAME_ATTITUDE(monster), + monster->foe, 0 )) { return (false); } diff --git a/crawl-ref/source/mstuff2.cc b/crawl-ref/source/mstuff2.cc index 48ed1c91be..f47bf1fa81 100644 --- a/crawl-ref/source/mstuff2.cc +++ b/crawl-ref/source/mstuff2.cc @@ -565,7 +565,8 @@ void mons_cast(monsters *monster, bolt &pbolt, spell_type spell_cast) case SPELL_ANIMATE_DEAD: // see special handling in monstuff::handle_spell {dlb} - animate_dead( 5 + random2(5), SAME_ATTITUDE(monster), monster->foe, 1 ); + animate_dead( monster, 5 + random2(5), SAME_ATTITUDE(monster), + monster->foe, 1 ); return; case SPELL_CALL_IMP: // class 5 demons diff --git a/crawl-ref/source/spells2.cc b/crawl-ref/source/spells2.cc index 3c13e1d31e..aaaba42552 100644 --- a/crawl-ref/source/spells2.cc +++ b/crawl-ref/source/spells2.cc @@ -295,17 +295,17 @@ int corpse_rot(int power) return 0; } // end corpse_rot() -int animate_dead( int power, beh_type corps_beh, int corps_hit, int actual ) +int animate_dead( actor *caster, int power, beh_type corps_beh, + int corps_hit, int actual ) { UNUSED( power ); + static env_show_grid losgrid; - int adx = 0; - int ady = 0; - - int minx = you.x_pos - 6; - int maxx = you.x_pos + 7; - int miny = you.y_pos - 6; - int maxy = you.y_pos + 7; + const coord_def c(caster->pos()); + int minx = c.x - 6; + int maxx = c.x + 7; + int miny = c.y - 6; + int maxy = c.y + 7; int xinc = 1; int yinc = 1; @@ -313,27 +313,33 @@ int animate_dead( int power, beh_type corps_beh, int corps_hit, int actual ) if (coinflip()) { - minx = you.x_pos + 6; - maxx = you.x_pos - 7; + minx = c.x + 6; + maxx = c.x - 7; xinc = -1; } if (coinflip()) { - miny = you.y_pos + 6; - maxy = you.y_pos - 7; + miny = c.y + 6; + maxy = c.y - 7; yinc = -1; } - for (adx = minx; adx != maxx; adx += xinc) + if (caster != &you) + losight(losgrid, grd, c.x, c.y); + + env_show_grid &los(caster == &you? env.show : losgrid); + + coord_def a; + for (a.x = minx; a.x != maxx; a.x += xinc) { - for (ady = miny; ady != maxy; ady += yinc) + for (a.y = miny; a.y != maxy; a.y += yinc) { - if (see_grid(adx, ady)) + if (in_bounds(a) && see_grid(los, c, a)) { - if (igrd[adx][ady] != NON_ITEM) + if (igrd(a) != NON_ITEM) { - int objl = igrd[adx][ady]; + int objl = igrd(a); int hrg = 0; // This searches all the items on the ground for a corpse @@ -342,7 +348,7 @@ int animate_dead( int power, beh_type corps_beh, int corps_hit, int actual ) if (is_animatable_corpse(mitm[objl]) && !is_being_butchered(mitm[objl])) { - number_raised += raise_corpse(objl, adx, ady, + number_raised += raise_corpse(objl, a.x, a.y, corps_beh, corps_hit, actual); break; } diff --git a/crawl-ref/source/spells2.h b/crawl-ref/source/spells2.h index a19c83a76f..f42f3faa26 100644 --- a/crawl-ref/source/spells2.h +++ b/crawl-ref/source/spells2.h @@ -14,6 +14,7 @@ #define SPELLS2_H #include "enum.h" +#include "externs.h" struct dist; @@ -36,7 +37,8 @@ int animate_a_corpse(int axps, int ayps, beh_type corps_beh, /* *********************************************************************** * called from: ability - it_use3 - monstuff - mstuff2 - spell * *********************************************************************** */ -int animate_dead(int power, beh_type corps_beh, int corps_hit, int actual); +int animate_dead(actor *caster, int power, beh_type corps_beh, + int corps_hit, int actual); // last updated 24may2000 {dlb} diff --git a/crawl-ref/source/spl-cast.cc b/crawl-ref/source/spl-cast.cc index 2480ba424c..7f54a2223d 100644 --- a/crawl-ref/source/spl-cast.cc +++ b/crawl-ref/source/spl-cast.cc @@ -1296,7 +1296,7 @@ spret_type your_spells( spell_type spell, int powc, bool allow_fail ) case SPELL_ANIMATE_DEAD: mpr("You call on the dead to walk for you."); - animate_dead(powc + 1, BEH_FRIENDLY, you.pet_target, 1); + animate_dead(&you, powc + 1, BEH_FRIENDLY, you.pet_target, 1); break; case SPELL_PAIN: diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc index 2cf125566c..eae73efd67 100644 --- a/crawl-ref/source/view.cc +++ b/crawl-ref/source/view.cc @@ -2159,8 +2159,8 @@ bool find_ray( int sourcex, int sourcey, int targetx, int targety, // IMPROVEMENTS: // Smoke will now only block LOS after two cells of smoke. This is // done by updating with a second array. -void losight(FixedArray < unsigned int, 19, 19 > &sh, - FixedArray < dungeon_feature_type, 80, 70 > &gr, int x_p, int y_p) +void losight(env_show_grid &sh, + feature_grid &gr, int x_p, int y_p) { raycast(); // go quadrant by quadrant @@ -3181,25 +3181,28 @@ bool mons_near(const monsters *monster, unsigned int foe) return (false); } // end mons_near() -// answers the question: "Is a grid within character's line of sight?" -bool see_grid( int grx, int gry ) +bool see_grid( const env_show_grid &show, + const coord_def &c, + const coord_def &pos ) { - // rare case: can player see self? (of course!) - if (grx == you.x_pos && gry == you.y_pos) + if (c == pos) return (true); - // check env.show array - if (grid_distance( grx, gry, you.x_pos, you.y_pos ) < 9) + const coord_def ip = pos - c; + if (ip.rdist() < ENV_SHOW_OFFSET) { - const int ex = grx - you.x_pos + 9; - const int ey = gry - you.y_pos + 9; - - if (env.show[ex][ey]) + const coord_def sp(ip + coord_def(ENV_SHOW_OFFSET, ENV_SHOW_OFFSET)); + if (show(sp)) return (true); } - return (false); -} // end see_grid() +} + +// answers the question: "Is a grid within character's line of sight?" +bool see_grid( const coord_def &p ) +{ + return see_grid(env.show, you.pos(), p); +} static const unsigned table[ NUM_CSET ][ NUM_DCHAR_TYPES ] = { diff --git a/crawl-ref/source/view.h b/crawl-ref/source/view.h index 3d13f5b7be..7d0c72fb28 100644 --- a/crawl-ref/source/view.h +++ b/crawl-ref/source/view.h @@ -94,8 +94,7 @@ void find_features(const std::vector& features, /* *********************************************************************** * called from: direct - monstufff - view * *********************************************************************** */ -void losight(FixedArray& sh, - FixedArray& gr, +void losight(env_show_grid &sh, feature_grid &gr, int x_p, int y_p); @@ -184,8 +183,15 @@ void add_feature_override(const std::string &text); void clear_cset_overrides(); void add_cset_override(char_set_type set, const std::string &overrides); -bool see_grid( int grx, int gry ); -inline bool see_grid(const coord_def &p) { return see_grid(p.x, p.y); } +bool see_grid( const env_show_grid &show, + const coord_def &c, + const coord_def &pos ); +bool see_grid(const coord_def &p); + +inline bool see_grid( int grx, int gry ) +{ + return see_grid(coord_def(grx, gry)); +} std::string screenshot(bool fullscreen = false); -- cgit v1.2.3-54-g00ecf