From f6e6b6b7151af9290c0597acb1995ed157378529 Mon Sep 17 00:00:00 2001 From: Robert Vollmert Date: Fri, 16 Oct 2009 23:48:56 +0200 Subject: Rewrite cell_see_cell using exists_ray. For this, add new opacity_func that disregards half-opaque things. --- crawl-ref/source/los.cc | 8 ++------ crawl-ref/source/losparam.cc | 8 ++++++++ crawl-ref/source/losparam.h | 14 +++++++++++--- 3 files changed, 21 insertions(+), 9 deletions(-) (limited to 'crawl-ref') 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 -- cgit v1.2.3-54-g00ecf