00001
00002
00003
00004
00005
00006
00007 #ifndef __MAPMARK_H__
00008 #define __MAPMARK_H__
00009
00010 #include "dgnevent.h"
00011 #include "clua.h"
00012 #include "dlua.h"
00013 #include <map>
00014 #include <string>
00015 #include <vector>
00016 #include <memory>
00017
00019
00020
00021 class reader;
00022 class writer;
00023
00024 void remove_markers_and_listeners_at(coord_def p);
00025
00026 bool marker_vetoes_operation(const char *op);
00027 bool feature_marker_at(const coord_def &pos, dungeon_feature_type feat);
00028 coord_def find_marker_position_by_prop(const std::string &prop,
00029 const std::string &expected = "");
00030 std::vector<coord_def> find_marker_positions_by_prop(
00031 const std::string &prop,
00032 const std::string &expected = "",
00033 unsigned maxresults = 0);
00034 std::vector<map_marker*> find_markers_by_prop(
00035 const std::string &prop,
00036 const std::string &expected = "",
00037 unsigned maxresults = 0);
00038
00039 class map_marker
00040 {
00041 public:
00042 map_marker(map_marker_type type, const coord_def &pos);
00043 virtual ~map_marker();
00044
00045 map_marker_type get_type() const { return type; }
00046
00047 virtual map_marker *clone() const = 0;
00048 virtual void activate(bool verbose = true);
00049 virtual void write(writer &) const;
00050 virtual void read(reader &);
00051 virtual std::string debug_describe() const = 0;
00052 virtual std::string property(const std::string &pname) const;
00053
00054 static map_marker *read_marker(reader &);
00055 static map_marker *parse_marker(const std::string &text,
00056 const std::string &ctx = "")
00057 throw (std::string);
00058
00059 public:
00060 coord_def pos;
00061
00062 protected:
00063 map_marker_type type;
00064
00065 typedef map_marker *(*marker_reader)(reader &, map_marker_type);
00066 typedef map_marker *(*marker_parser)(const std::string &,
00067 const std::string &);
00068 static marker_reader readers[NUM_MAP_MARKER_TYPES];
00069 static marker_parser parsers[NUM_MAP_MARKER_TYPES];
00070 };
00071
00072 class map_feature_marker : public map_marker
00073 {
00074 public:
00075 map_feature_marker(const coord_def &pos = coord_def(0, 0),
00076 dungeon_feature_type feat = DNGN_UNSEEN);
00077 map_feature_marker(const map_feature_marker &other);
00078 void write(writer &) const;
00079 void read(reader &);
00080 std::string debug_describe() const;
00081 map_marker *clone() const;
00082 static map_marker *read(reader &, map_marker_type);
00083 static map_marker *parse(const std::string &s, const std::string &)
00084 throw (std::string);
00085
00086 public:
00087 dungeon_feature_type feat;
00088 };
00089
00090 class map_corruption_marker : public map_marker
00091 {
00092 public:
00093 map_corruption_marker(const coord_def &pos = coord_def(0, 0),
00094 int dur = 0);
00095
00096 void write(writer &) const;
00097 void read(reader &);
00098 map_marker *clone() const;
00099 std::string debug_describe() const;
00100
00101 static map_marker *read(reader &, map_marker_type);
00102
00103 public:
00104 int duration;
00105 };
00106
00107 class map_tomb_marker : public map_marker
00108 {
00109 public:
00110 map_tomb_marker(const coord_def& pos = coord_def(0, 0),
00111 int dur = 0, int src = 0, int targ = 0);
00112
00113 void write(writer &) const;
00114 void read(reader &);
00115 map_marker *clone() const;
00116 std::string debug_describe() const;
00117
00118 static map_marker *read(reader &, map_marker_type);
00119
00120 public:
00121 int duration, source, target;
00122 };
00123
00124 class map_malign_gateway_marker : public map_marker
00125 {
00126 public:
00127 map_malign_gateway_marker (const coord_def& pos = coord_def(0, 0),
00128 int dur = 0, bool ip = false, std::string caster = "",
00129 beh_type bh = BEH_HOSTILE, god_type gd = GOD_NO_GOD,
00130 int pow = 0);
00131
00132 void write (writer &) const;
00133 void read (reader &);
00134 map_marker *clone() const;
00135 std::string debug_describe() const;
00136
00137 static map_marker *read(reader &, map_marker_type);
00138
00139 public:
00140 int duration;
00141 bool is_player;
00142 bool monster_summoned;
00143 std::string summoner_string;
00144 beh_type behaviour;
00145 god_type god;
00146 int power;
00147 };
00148
00149
00150 class map_lua_marker : public map_marker, public dgn_event_listener
00151 {
00152 public:
00153 map_lua_marker();
00154 map_lua_marker(const lua_datum &function);
00155 map_lua_marker(const std::string &s, const std::string &ctx,
00156 bool mapdef_marker = true);
00157 ~map_lua_marker();
00158
00159 void activate(bool verbose);
00160
00161 void write(writer &) const;
00162 void read(reader &);
00163 map_marker *clone() const;
00164 std::string debug_describe() const;
00165 std::string property(const std::string &pname) const;
00166
00167 bool notify_dgn_event(const dgn_event &e);
00168
00169 static map_marker *read(reader &, map_marker_type);
00170 static map_marker *parse(const std::string &s, const std::string &)
00171 throw (std::string);
00172
00173 std::string debug_to_string() const;
00174 private:
00175 bool initialised;
00176 std::auto_ptr<lua_datum> marker_table;
00177
00178 private:
00179 void check_register_table();
00180 bool get_table() const;
00181 void push_fn_args(const char *fn) const;
00182 bool callfn(const char *fn, bool warn_err = false, int args = -1) const;
00183 std::string call_str_fn(const char *fn) const;
00184 };
00185
00186 class map_wiz_props_marker : public map_marker
00187 {
00188 public:
00189 map_wiz_props_marker(const coord_def &pos = coord_def(0, 0));
00190 map_wiz_props_marker(const map_wiz_props_marker &other);
00191 void write(writer &) const;
00192 void read(reader &);
00193 std::string debug_describe() const;
00194 std::string property(const std::string &pname) const;
00195 std::string set_property(const std::string &key, const std::string &val);
00196 map_marker *clone() const;
00197 static map_marker *read(reader &, map_marker_type);
00198 static map_marker *parse(const std::string &s, const std::string &)
00199 throw (std::string);
00200
00201 public:
00202 std::map<std::string, std::string> properties;
00203 };
00204
00205 #endif