diff options
author | Robert Vollmert <rvollmert@gmx.net> | 2009-10-16 23:48:56 +0200 |
---|---|---|
committer | Robert Vollmert <rvollmert@gmx.net> | 2009-10-16 23:49:51 +0200 |
commit | f6e6b6b7151af9290c0597acb1995ed157378529 (patch) | |
tree | c984c3816cc6a66118b8fc47b6e6984f1b1eba4d /crawl-ref | |
parent | 756894ef3f3dd9c70af6115be117bb09e4374342 (diff) | |
download | crawl-ref-f6e6b6b7151af9290c0597acb1995ed157378529.tar.gz crawl-ref-f6e6b6b7151af9290c0597acb1995ed157378529.zip |
Rewrite cell_see_cell using exists_ray.
For this, add new opacity_func that disregards half-opaque things.
Diffstat (limited to 'crawl-ref')
-rw-r--r-- | crawl-ref/source/los.cc | 8 | ||||
-rw-r--r-- | crawl-ref/source/losparam.cc | 8 | ||||
-rw-r--r-- | crawl-ref/source/losparam.h | 14 |
3 files changed, 21 insertions, 9 deletions
diff --git a/crawl-ref/source/los.cc b/crawl-ref/source/los.cc index 38de458419..9dbe3bc23d 100644 --- a/crawl-ref/source/los.cc +++ b/crawl-ref/source/los.cc @@ -775,14 +775,10 @@ int num_feats_between(const coord_def& source, const coord_def& target, return (count); } -// Is p2 visible from p1, disregarding clouds? -// XXX: Horribly inefficient since we do an entire LOS calculation; -// needs to be rewritten if it is used more. +// Is p2 visible from p1, disregarding half-opaque objects? bool cell_see_cell(const coord_def& p1, const coord_def& p2) { - env_show_grid show; - losight(show, p1); - return see_grid(show, p1, p2); + return exists_ray(p1, p2, opc_fullyopaque); } // We use raycasting. The algorithm: diff --git a/crawl-ref/source/losparam.cc b/crawl-ref/source/losparam.cc index f24acf4551..132c2005f2 100644 --- a/crawl-ref/source/losparam.cc +++ b/crawl-ref/source/losparam.cc @@ -30,6 +30,14 @@ opacity_type opacity_default::operator()(const coord_def& p) const return OPC_CLEAR; } +opacity_type opacity_fullyopaque::operator()(const coord_def& p) const +{ + if (grid_is_opaque(env.grid(p))) + return OPC_OPAQUE; + else + return OPC_CLEAR; +} + // Make anything solid block in addition to normal LOS. // XXX: Are trees, bushes solid? opacity_type opacity_solid::operator()(const coord_def& p) const diff --git a/crawl-ref/source/losparam.h b/crawl-ref/source/losparam.h index 505d0989ff..4d5bc141e1 100644 --- a/crawl-ref/source/losparam.h +++ b/crawl-ref/source/losparam.h @@ -34,7 +34,15 @@ struct opacity_default : opacity_func { opacity_type operator()(const coord_def& p) const; }; -static opacity_default opc_default = opacity_default(); +static opacity_default opc_default; + +// Default LOS rules, but only consider fully opaque features blocking. +// In particular, clouds don't affect the result. +struct opacity_fullyopaque : opacity_func +{ + opacity_type operator()(const coord_def& p) const; +}; +static opacity_fullyopaque opc_fullyopaque; // Make anything solid block in addition to normal LOS. // XXX: Are trees, bushes solid? @@ -42,7 +50,7 @@ struct opacity_solid : opacity_func { opacity_type operator()(const coord_def& p) const; }; -static opacity_solid opc_solid = opacity_solid(); +static opacity_solid opc_solid; // LOS bounded by fixed presquared radius. struct bounds_radius_sq : bounds_func @@ -58,7 +66,7 @@ struct bounds_los_radius : bounds_func { bool operator()(const coord_def& p) const; }; -static bounds_los_radius bds_default = bounds_los_radius(); +static bounds_los_radius bds_default; // Subclasses of this are passed to losight() to modify the // LOS calculation. Implementations will have to translate between |