Apply the new ground_level method.
[crawl.git] / crawl-ref / source / mapmark.h
blob45490607c332b8ba8ba68942327abb3420cfaa38
1 /*
2 * File: mapmark.cc
3 * Summary: Level markers (annotations).
4 * Created by: dshaligram on Sat Jul 21 12:17:29 2007 UTC
5 */
7 #ifndef __MAPMARK_H__
8 #define __MAPMARK_H__
10 #include "dgnevent.h"
11 #include "clua.h"
12 #include "dlua.h"
13 #include <map>
14 #include <string>
15 #include <vector>
16 #include <memory>
18 //////////////////////////////////////////////////////////////////////////
19 // Map markers
21 class reader;
22 class writer;
24 void remove_markers_and_listeners_at(coord_def p);
26 bool marker_vetoes_operation(const char *op);
27 bool feature_marker_at(const coord_def &pos, dungeon_feature_type feat);
28 coord_def find_marker_position_by_prop(const std::string &prop,
29 const std::string &expected = "");
30 std::vector<coord_def> find_marker_positions_by_prop(
31 const std::string &prop,
32 const std::string &expected = "",
33 unsigned maxresults = 0);
34 std::vector<map_marker*> find_markers_by_prop(
35 const std::string &prop,
36 const std::string &expected = "",
37 unsigned maxresults = 0);
39 class map_marker
41 public:
42 map_marker(map_marker_type type, const coord_def &pos);
43 virtual ~map_marker();
45 map_marker_type get_type() const { return type; }
47 virtual map_marker *clone() const = 0;
48 virtual void activate(bool verbose = true);
49 virtual void write(writer &) const;
50 virtual void read(reader &);
51 virtual std::string debug_describe() const = 0;
52 virtual std::string property(const std::string &pname) const;
54 static map_marker *read_marker(reader &);
55 static map_marker *parse_marker(const std::string &text,
56 const std::string &ctx = "")
57 throw (std::string);
59 public:
60 coord_def pos;
62 protected:
63 map_marker_type type;
65 typedef map_marker *(*marker_reader)(reader &, map_marker_type);
66 typedef map_marker *(*marker_parser)(const std::string &,
67 const std::string &);
68 static marker_reader readers[NUM_MAP_MARKER_TYPES];
69 static marker_parser parsers[NUM_MAP_MARKER_TYPES];
72 class map_feature_marker : public map_marker
74 public:
75 map_feature_marker(const coord_def &pos = coord_def(0, 0),
76 dungeon_feature_type feat = DNGN_UNSEEN);
77 map_feature_marker(const map_feature_marker &other);
78 void write(writer &) const;
79 void read(reader &);
80 std::string debug_describe() const;
81 map_marker *clone() const;
82 static map_marker *read(reader &, map_marker_type);
83 static map_marker *parse(const std::string &s, const std::string &)
84 throw (std::string);
86 public:
87 dungeon_feature_type feat;
90 class map_corruption_marker : public map_marker
92 public:
93 map_corruption_marker(const coord_def &pos = coord_def(0, 0),
94 int dur = 0);
96 void write(writer &) const;
97 void read(reader &);
98 map_marker *clone() const;
99 std::string debug_describe() const;
101 static map_marker *read(reader &, map_marker_type);
103 public:
104 int duration;
107 class map_tomb_marker : public map_marker
109 public:
110 map_tomb_marker(const coord_def& pos = coord_def(0, 0),
111 int dur = 0, int src = 0, int targ = 0);
113 void write(writer &) const;
114 void read(reader &);
115 map_marker *clone() const;
116 std::string debug_describe() const;
118 static map_marker *read(reader &, map_marker_type);
120 public:
121 int duration, source, target;
124 class map_malign_gateway_marker : public map_marker
126 public:
127 map_malign_gateway_marker (const coord_def& pos = coord_def(0, 0),
128 int dur = 0, bool ip = false, std::string caster = "",
129 beh_type bh = BEH_HOSTILE, god_type gd = GOD_NO_GOD,
130 int pow = 0);
132 void write (writer &) const;
133 void read (reader &);
134 map_marker *clone() const;
135 std::string debug_describe() const;
137 static map_marker *read(reader &, map_marker_type);
139 public:
140 int duration;
141 bool is_player;
142 bool monster_summoned;
143 std::string summoner_string;
144 beh_type behaviour;
145 god_type god;
146 int power;
149 // A marker powered by Lua.
150 class map_lua_marker : public map_marker, public dgn_event_listener
152 public:
153 map_lua_marker();
154 map_lua_marker(const lua_datum &function);
155 map_lua_marker(const std::string &s, const std::string &ctx,
156 bool mapdef_marker = true);
157 ~map_lua_marker();
159 void activate(bool verbose);
161 void write(writer &) const;
162 void read(reader &);
163 map_marker *clone() const;
164 std::string debug_describe() const;
165 std::string property(const std::string &pname) const;
167 bool notify_dgn_event(const dgn_event &e);
169 static map_marker *read(reader &, map_marker_type);
170 static map_marker *parse(const std::string &s, const std::string &)
171 throw (std::string);
173 std::string debug_to_string() const;
174 private:
175 bool initialised;
176 std::auto_ptr<lua_datum> marker_table;
178 private:
179 void check_register_table();
180 bool get_table() const;
181 void push_fn_args(const char *fn) const;
182 bool callfn(const char *fn, bool warn_err = false, int args = -1) const;
183 std::string call_str_fn(const char *fn) const;
186 class map_wiz_props_marker : public map_marker
188 public:
189 map_wiz_props_marker(const coord_def &pos = coord_def(0, 0));
190 map_wiz_props_marker(const map_wiz_props_marker &other);
191 void write(writer &) const;
192 void read(reader &);
193 std::string debug_describe() const;
194 std::string property(const std::string &pname) const;
195 std::string set_property(const std::string &key, const std::string &val);
196 map_marker *clone() const;
197 static map_marker *read(reader &, map_marker_type);
198 static map_marker *parse(const std::string &s, const std::string &)
199 throw (std::string);
201 public:
202 std::map<std::string, std::string> properties;
205 #endif