From: Robert V. <rvo...@gm...> - 2009-09-27 21:12:30
|
The old, more efficient version (based on num_feats_between) remains as grid_probably_see_grid. This includes a modification to find_ray to allow specifying what features are blocking. The change from ignore_solid=true to min_block=NUM_FEATURES is of questionable elegance. --- crawl-ref/source/view.cc | 41 ++++++++++++++++++++++++++++++----------- crawl-ref/source/view.h | 6 +++++- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc index 6739eef..b09cd55 100644 --- a/crawl-ref/source/view.cc +++ b/crawl-ref/source/view.cc @@ -2695,10 +2695,12 @@ static bool _superior_ray(int shortest, int imbalance, // ray in that cycle direction. // If find_shortest is true, examine all rays that hit the target and // take the shortest (starting at ray.fullray_idx). - +// Blocking features are those between min_block and max_block (solid +// features by default). bool find_ray( const coord_def& source, const coord_def& target, bool allow_fallback, ray_def& ray, int cycle_dir, - bool find_shortest, bool ignore_solid ) + bool find_shortest, + dungeon_feature_type min_block, dungeon_feature_type max_block ) { int cellray, inray; @@ -2747,8 +2749,9 @@ bool find_ray( const coord_def& source, const coord_def& target, { const int xi = signx * ray_coord_x[inray + cur_offset]; const int yi = signy * ray_coord_y[inray + cur_offset]; - if (inray < cellray && !ignore_solid - && grid_is_solid(grd[sourcex + xi][sourcey + yi])) + if (inray < cellray + && grd[sourcex + xi][sourcey + yi] >= min_block + && grd[sourcex + xi][sourcey + yi] <= max_block) { blocked = true; break; @@ -2882,7 +2885,7 @@ int num_feats_between(const coord_def& source, const coord_def& target, ray.fullray_idx = -1; // to quiet valgrind // We don't need to find the shortest beam, any beam will suffice. - find_ray( source, target, true, ray, 0, false, true ); + find_ray( source, target, true, ray, 0, false, NUM_REAL_FEATURES ); if (exclude_endpoints && ray.pos() == source) { @@ -4174,14 +4177,14 @@ bool trans_wall_blocking( const coord_def &p ) return see_grid(p) && !see_grid_no_trans(p); } -// Usually calculates whether from one grid someone could see the other. +// An approximation to visibility: If this returns true, the cells can +// probably see each other. There can be both kinds of errors. +// // Depending on the viewer's habitat, 'allowed' can be set to DNGN_FLOOR, // DNGN_SHALLOW_WATER or DNGN_DEEP_WATER. // Yes, this ignores lava-loving monsters. -// XXX: It turns out the beams are not symmetrical, i.e. switching -// pos1 and pos2 may result in small variations. -bool grid_see_grid(const coord_def& p1, const coord_def& p2, - dungeon_feature_type allowed) +bool grid_probably_see_grid(const coord_def& p1, const coord_def& p2, + dungeon_feature_type allowed) { if (distance(p1, p2) > los_radius_squared) return (false); @@ -4195,6 +4198,22 @@ bool grid_see_grid(const coord_def& p1, const coord_def& p2, true, true)); } +// Determine whether p2 is visible from p1. +// Depending on the viewer's habitat, 'allowed' can be set to DNGN_FLOOR, +// DNGN_SHALLOW_WATER or DNGN_DEEP_WATER. +// Yes, this ignores lava-loving monsters. +bool grid_see_grid(const coord_def& p1, const coord_def& p2, + dungeon_feature_type allowed) +{ + ray_def ray; + + dungeon_feature_type max_disallowed = DNGN_MAXOPAQUE; + if (allowed != DNGN_UNSEEN) + max_disallowed = static_cast<dungeon_feature_type>(allowed - 1); + + return find_ray(p1, p2, false, ray, 0, false, DNGN_UNSEEN, max_disallowed); +} + // For order and meaning of symbols, see dungeon_char_type in enum.h. static const unsigned dchar_table[ NUM_CSET ][ NUM_DCHAR_TYPES ] = { @@ -6332,7 +6351,7 @@ void monster_los::check_los_beam(int dx, int dy) dist = 0; ray.fullray_idx = -1; // to quiet valgrind find_ray( coord_def(gridx, gridy), coord_def(tx, ty), - true, ray, 0, true, true ); + true, ray, 0, true, NUM_REAL_FEATURES ); if (ray.x() == gridx && ray.y() == gridy) ray.advance(true); diff --git a/crawl-ref/source/view.h b/crawl-ref/source/view.h index fd32f00..15e4e8d 100644 --- a/crawl-ref/source/view.h +++ b/crawl-ref/source/view.h @@ -187,6 +187,8 @@ bool see_grid( const env_show_grid &show, bool see_grid(const coord_def &p); bool see_grid_no_trans( const coord_def &p ); bool trans_wall_blocking( const coord_def &p ); +bool grid_probably_see_grid(const coord_def& p1, const coord_def& p2, + dungeon_feature_type allowed = DNGN_UNSEEN); bool grid_see_grid(const coord_def& p1, const coord_def& p2, dungeon_feature_type allowed = DNGN_UNSEEN); unsigned grid_character_at(const coord_def &c); @@ -228,7 +230,9 @@ void flush_comes_into_view(); struct ray_def; bool find_ray( const coord_def& source, const coord_def& target, bool allow_fallback, ray_def& ray, int cycle_dir = 0, - bool find_shortest = false, bool ignore_solid = false ); + bool find_shortest = false, + dungeon_feature_type min_block = DNGN_UNSEEN, + dungeon_feature_type max_block = DNGN_MAXSOLID ); int num_feats_between(const coord_def& source, const coord_def& target, dungeon_feature_type min_feat, -- 1.6.1.2 |