summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/losparam.cc
diff options
context:
space:
mode:
authorRobert Vollmert <rvollmert@gmx.net>2009-10-08 16:47:06 +0200
committerRobert Vollmert <rvollmert@gmx.net>2009-10-08 18:31:55 +0200
commitefbe1be543f6781d73b056d0acab3143dfde704f (patch)
tree5b9d5186a99f920fa6be0f8c15c43744ea85f3fc /crawl-ref/source/losparam.cc
parented5f5311c213fb847bc37293e4330aa268a406ed (diff)
downloadcrawl-ref-efbe1be543f6781d73b056d0acab3143dfde704f.tar.gz
crawl-ref-efbe1be543f6781d73b056d0acab3143dfde704f.zip
A rewrite of losight() to allow future generalization.
Parameters relevant to the LOS calculation are now passed as an object los_param that takes care of coordinate translation, bounds checking, opacity of cells and what is written to the output array. A check for in_bounds was changed to map_bounds for simlicity; this should not have any effect. Special casing for arena was removed from losight; instead calc_show_los now calls the new losight_permissive.
Diffstat (limited to 'crawl-ref/source/losparam.cc')
-rw-r--r--crawl-ref/source/losparam.cc88
1 files changed, 88 insertions, 0 deletions
diff --git a/crawl-ref/source/losparam.cc b/crawl-ref/source/losparam.cc
new file mode 100644
index 0000000000..dc22990ee0
--- /dev/null
+++ b/crawl-ref/source/losparam.cc
@@ -0,0 +1,88 @@
+/*
+ * File: losparam.h
+ * Summary: Parameters for the LOS algorithm
+ */
+
+#include "AppHdr.h"
+REVISION("$Rev$");
+
+#include "losparam.h"
+
+#include "cloud.h"
+#include "externs.h"
+#include "stuff.h"
+#include "terrain.h"
+
+los_param_trans::los_param_trans(const coord_def& c)
+ : center(c)
+{
+}
+
+coord_def los_param_trans::trans(const coord_def& p) const
+{
+ return p + center;
+}
+
+bool los_param_trans::map_bounds(const coord_def& p) const
+{
+ return ::map_bounds(trans(p));
+}
+
+los_param_base::los_param_base(const coord_def& c)
+ : los_param_trans(c)
+{
+}
+
+dungeon_feature_type los_param_base::feature(const coord_def& p) const
+{
+ return env.grid(trans(p));
+}
+
+unsigned los_param_base::appearance(const coord_def& p) const
+{
+ return grid_appearance(trans(p));
+}
+
+unsigned short los_param_base::cloud_idx(const coord_def& p) const
+{
+ return env.cgrid(trans(p));
+}
+
+opacity_type los_param_base::opacity(const coord_def& p) const
+{
+ dungeon_feature_type f = feature(p);
+ if (grid_is_opaque(f))
+ return OPC_OPAQUE;
+ else if (is_opaque_cloud(cloud_idx(p)))
+ return OPC_HALF;
+ else
+ return OPC_CLEAR;
+}
+
+los_param_compat::los_param_compat(const feature_grid& gr, const coord_def& c,
+ bool sb, bool ic)
+ : los_param_base(c), grid(gr), solid_blocks(sb), ignore_clouds(ic)
+{
+}
+
+dungeon_feature_type los_param_compat::feature(const coord_def& p) const
+{
+ return grid(trans(p));
+}
+
+unsigned los_param_compat::appearance(const coord_def& p) const
+{
+ return grid_appearance(grid, trans(p));
+}
+
+opacity_type los_param_compat::opacity(const coord_def& p) const
+{
+ dungeon_feature_type f = feature(p);
+ if (grid_is_opaque(f) || solid_blocks && grid_is_solid(f))
+ return OPC_OPAQUE;
+ else if (!ignore_clouds && is_opaque_cloud(cloud_idx(p)))
+ return OPC_HALF;
+ else
+ return OPC_CLEAR;
+}
+