1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
/*
* File: mapmark.cc
* Summary: Level markers (annotations).
* Created by: dshaligram on Sat Jul 21 12:17:29 2007 UTC
*/
#ifndef __MAPMARK_H__
#define __MAPMARK_H__
#include "dgnevent.h"
#include "clua.h"
#include "dlua.h"
#include <map>
#include <string>
#include <vector>
#include <memory>
//////////////////////////////////////////////////////////////////////////
// Map markers
class reader;
class writer;
bool marker_vetoes_operation(const char *op);
bool feature_marker_at(const coord_def &pos, dungeon_feature_type feat);
coord_def find_marker_position_by_prop(const std::string &prop,
const std::string &expected = "");
std::vector<coord_def> find_marker_positions_by_prop(
const std::string &prop,
const std::string &expected = "",
unsigned maxresults = 0);
std::vector<map_marker*> find_markers_by_prop(
const std::string &prop,
const std::string &expected = "",
unsigned maxresults = 0);
class map_marker
{
public:
map_marker(map_marker_type type, const coord_def &pos);
virtual ~map_marker();
map_marker_type get_type() const { return type; }
virtual map_marker *clone() const = 0;
virtual void activate(bool verbose = true);
virtual void write(writer &) const;
virtual void read(reader &);
virtual std::string debug_describe() const = 0;
virtual std::string property(const std::string &pname) const;
static map_marker *read_marker(reader &);
static map_marker *parse_marker(const std::string &text,
const std::string &ctx = "")
throw (std::string);
public:
coord_def pos;
protected:
map_marker_type type;
typedef map_marker *(*marker_reader)(reader &, map_marker_type);
typedef map_marker *(*marker_parser)(const std::string &,
const std::string &);
static marker_reader readers[NUM_MAP_MARKER_TYPES];
static marker_parser parsers[NUM_MAP_MARKER_TYPES];
};
class map_feature_marker : public map_marker
{
public:
map_feature_marker(const coord_def &pos = coord_def(0, 0),
dungeon_feature_type feat = DNGN_UNSEEN);
map_feature_marker(const map_feature_marker &other);
void write(writer &) const;
void read(reader &);
std::string debug_describe() const;
map_marker *clone() const;
static map_marker *read(reader &, map_marker_type);
static map_marker *parse(const std::string &s, const std::string &)
throw (std::string);
public:
dungeon_feature_type feat;
};
class map_corruption_marker : public map_marker
{
public:
map_corruption_marker(const coord_def &pos = coord_def(0, 0),
int dur = 0);
void write(writer &) const;
void read(reader &);
map_marker *clone() const;
std::string debug_describe() const;
static map_marker *read(reader &, map_marker_type);
public:
int duration;
};
class map_tomb_marker : public map_marker
{
public:
map_tomb_marker(const coord_def& pos = coord_def(0, 0),
int dur = 0, int src = 0, int targ = 0);
void write(writer &) const;
void read(reader &);
map_marker *clone() const;
std::string debug_describe() const;
static map_marker *read(reader &, map_marker_type);
public:
int duration, source, target;
};
// A marker powered by Lua.
class map_lua_marker : public map_marker, public dgn_event_listener
{
public:
map_lua_marker();
map_lua_marker(const lua_datum &function);
map_lua_marker(const std::string &s, const std::string &ctx,
bool mapdef_marker = true);
~map_lua_marker();
void activate(bool verbose);
void write(writer &) const;
void read(reader &);
map_marker *clone() const;
std::string debug_describe() const;
std::string property(const std::string &pname) const;
bool notify_dgn_event(const dgn_event &e);
static map_marker *read(reader &, map_marker_type);
static map_marker *parse(const std::string &s, const std::string &)
throw (std::string);
std::string debug_to_string() const;
private:
bool initialised;
std::auto_ptr<lua_datum> marker_table;
private:
void check_register_table();
bool get_table() const;
void push_fn_args(const char *fn) const;
bool callfn(const char *fn, bool warn_err = false, int args = -1) const;
std::string call_str_fn(const char *fn) const;
};
class map_wiz_props_marker : public map_marker
{
public:
map_wiz_props_marker(const coord_def &pos = coord_def(0, 0));
map_wiz_props_marker(const map_wiz_props_marker &other);
void write(writer &) const;
void read(reader &);
std::string debug_describe() const;
std::string property(const std::string &pname) const;
std::string set_property(const std::string &key, const std::string &val);
map_marker *clone() const;
static map_marker *read(reader &, map_marker_type);
static map_marker *parse(const std::string &s, const std::string &)
throw (std::string);
public:
std::map<std::string, std::string> properties;
};
#endif
|