summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/losparam.h
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.h
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.h')
-rw-r--r--crawl-ref/source/losparam.h76
1 files changed, 76 insertions, 0 deletions
diff --git a/crawl-ref/source/losparam.h b/crawl-ref/source/losparam.h
new file mode 100644
index 0000000000..a31fbb46f5
--- /dev/null
+++ b/crawl-ref/source/losparam.h
@@ -0,0 +1,76 @@
+/*
+ * File: losparam.h
+ * Summary: Parameters for the LOS algorithm
+ */
+
+#ifndef LOSPARAM_H
+#define LOSPARAM_H
+
+enum opacity_type
+{
+ OPC_CLEAR,
+ OPC_HALF, // for opaque clouds; two or more block
+ OPC_OPAQUE,
+
+ NUM_OPACITIES
+};
+
+// Subclasses of this are passed to losight() to modify the
+// LOS calculation. Implementations will have to translate between
+// relative coordinates (-8,-8)..(8,8) and real coordinates,
+// specify how opaque the cells are and determine what values
+// are written to the visible cells.
+struct los_param
+{
+ virtual ~los_param() {}
+
+ // Whether the translated coordinate lies in the map (including boundary)
+ virtual bool map_bounds(const coord_def& p) const = 0;
+
+ // appearance(p) will be copied to show(p) for visible p.
+ virtual unsigned appearance(const coord_def& p) const = 0;
+
+ virtual opacity_type opacity(const coord_def& p) const = 0;
+};
+
+// Provides translation to given center and bounds checking.
+struct los_param_trans : los_param
+{
+ coord_def center;
+
+ los_param_trans(const coord_def& c);
+
+ coord_def trans(const coord_def& p) const;
+
+ bool map_bounds(const coord_def& p) const;
+};
+
+// A complete base implementation that does standard visibility
+// based on env.grid.
+struct los_param_base : los_param_trans
+{
+ los_param_base(const coord_def& c);
+
+ dungeon_feature_type feature(const coord_def& p) const;
+ unsigned appearance(const coord_def& p) const;
+ unsigned short cloud_idx(const coord_def& p) const;
+ opacity_type opacity(const coord_def& p) const;
+};
+
+// Provides a compatible set of parameters for use with the
+// legacy losight() function.
+struct los_param_compat : los_param_base
+{
+ feature_grid grid;
+ bool solid_blocks;
+ bool ignore_clouds;
+
+ los_param_compat(const feature_grid& gr, const coord_def& c,
+ bool sb, bool ic);
+
+ dungeon_feature_type feature(const coord_def& p) const;
+ unsigned appearance(const coord_def& p) const;
+ opacity_type opacity(const coord_def& p) const;
+};
+
+#endif