summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/view.cc
diff options
context:
space:
mode:
authorj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2008-05-27 20:15:24 +0000
committerj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2008-05-27 20:15:24 +0000
commit66c149dbd38eca4599dd015b9271d2e1bcf46472 (patch)
tree160ae3e19f11630e8d0333b5b43098ef5a72773b /crawl-ref/source/view.cc
parent70ce5c5c0ce725bdb808bc5d5e7b216a7707e911 (diff)
downloadcrawl-ref-66c149dbd38eca4599dd015b9271d2e1bcf46472.tar.gz
crawl-ref-66c149dbd38eca4599dd015b9271d2e1bcf46472.zip
Modify num_feats_between to return early if a feature has been
encountered and we're only interested in whether the path is clear or not. Also, more whitespace/comment changes. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@5298 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/view.cc')
-rw-r--r--crawl-ref/source/view.cc30
1 files changed, 19 insertions, 11 deletions
diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc
index 019ea1605f..86e18f81bf 100644
--- a/crawl-ref/source/view.cc
+++ b/crawl-ref/source/view.cc
@@ -2439,10 +2439,12 @@ bool find_ray( int sourcex, int sourcey, int targetx, int targety,
// Count the number of matching features between two points along
// a beam-like path; the path will pass through solid features.
// By default, it excludes end points from the count.
+// If just_check is true, the function will return early once one
+// such feature is encountered.
int num_feats_between(int sourcex, int sourcey, int targetx, int targety,
dungeon_feature_type min_feat,
dungeon_feature_type max_feat,
- bool exclude_endpoints)
+ bool exclude_endpoints, bool just_check)
{
ray_def ray;
int count = 0;
@@ -2458,24 +2460,30 @@ int num_feats_between(int sourcex, int sourcey, int targetx, int targety,
}
int dist = 0;
+ bool reached_target = false;
while (dist++ <= max_dist)
{
dungeon_feature_type feat = grd[ray.x()][ray.y()];
- if (feat >= min_feat && feat <= max_feat)
- count++;
-
if (ray.x() == targetx && ray.y() == targety)
+ reached_target = true;
+
+ if (feat >= min_feat && feat <= max_feat
+ && (!exclude_endpoints || !reached_target))
{
- if (exclude_endpoints && feat >= min_feat && feat <= max_feat)
- count--;
+ count++;
- break;
+ if (just_check) // Only needs to be > 0.
+ return (count);
}
+
+ if (reached_target)
+ break;
+
ray.advance(true);
}
- return count;
+ return (count);
}
// The rule behind LOS is:
@@ -2989,7 +2997,7 @@ static void _draw_level_map(int start_x, int start_y, bool travel_mode)
static void _reset_travel_colours(std::vector<coord_def> &features)
{
- // We now need to redo travel colours
+ // We now need to redo travel colours.
features.clear();
find_travel_pos(you.x_pos, you.y_pos, NULL, NULL, &features);
// Sort features into the order the player is likely to prefer.
@@ -3660,8 +3668,8 @@ bool grid_see_grid(int posx_1, int posy_1, int posx_2, int posy_2,
max_disallowed = static_cast<dungeon_feature_type>(allowed - 1);
// XXX: Ignoring clouds for now.
- return (num_feats_between(posx_1, posy_1, posx_2, posy_2, DNGN_UNSEEN,
- max_disallowed) == 0);
+ return (!num_feats_between(posx_1, posy_1, posx_2, posy_2, DNGN_UNSEEN,
+ max_disallowed, true, true));
}
static const unsigned dchar_table[ NUM_CSET ][ NUM_DCHAR_TYPES ] =