summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/mapmark.h
blob: d02d0718c804d9b3da48240671c380ef38a5c459 (plain) (blame)
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
/**
 * @file
 * @brief Level markers (annotations).
**/

#ifndef __MAPMARK_H__
#define __MAPMARK_H__

#include "dgnevent.h"
#include "clua.h"
#include <map>
#include <string>
#include <vector>
#include <memory>

//////////////////////////////////////////////////////////////////////////
// Map markers

class reader;
class writer;

void remove_markers_and_listeners_at(coord_def p);

bool marker_vetoes_operation(const char *op);
coord_def find_marker_position_by_prop(const string &prop,
                                       const string &expected = "");
vector<coord_def> find_marker_positions_by_prop(const string &prop,
                                                const string &expected = "",
                                                unsigned maxresults = 0);
vector<map_marker*> find_markers_by_prop(const string &prop,
                                         const 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 string debug_describe() const = 0;
    virtual string property(const string &pname) const;

    static map_marker *read_marker(reader &);
    static map_marker *parse_marker(const string &text,
                                    const string &ctx = "") throw (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 string &, const 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 &);
    string debug_describe() const;
    map_marker *clone() const;
    static map_marker *read(reader &, map_marker_type);
    static map_marker *parse(const string &s, const string &) throw (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;
    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;
    string debug_describe() const;

    static map_marker *read(reader &, map_marker_type);

public:
    int duration, source, target;
};

class map_malign_gateway_marker : public map_marker
{
public:
    map_malign_gateway_marker (const coord_def& pos = coord_def(0, 0),
                    int dur = 0, bool ip = false, string caster = "",
                    beh_type bh = BEH_HOSTILE, god_type gd = GOD_NO_GOD,
                    int pow = 0);

    void write (writer &) const;
    void read (reader &);
    map_marker *clone() const;
    string debug_describe() const;

    static map_marker *read(reader &, map_marker_type);

public:
    int duration;
    bool is_player;
    bool monster_summoned;
    string summoner_string;
    beh_type behaviour;
    god_type god;
    int power;
};

#if TAG_MAJOR_VERSION == 34
// A marker powered by phoenixes!
class map_phoenix_marker : public map_marker
{
public:
    map_phoenix_marker (const coord_def& pos = coord_def(0, 0),
                    int dur = 0, int mnum = 0, beh_type bh = BEH_HOSTILE,
                    mon_attitude_type at = ATT_HOSTILE, god_type gd = GOD_NO_GOD,
                    coord_def cp = coord_def(-1, -1)
                    );

    void write (writer &) const;
    void read (reader &);
    map_marker *clone() const;
    string debug_describe() const;

    static map_marker *read(reader &, map_marker_type);

public:
    int duration;
    int mon_num;
    beh_type behaviour;
    mon_attitude_type attitude;
    god_type god;
    coord_def corpse_pos;
};


// A marker for sealed doors
class map_door_seal_marker : public map_marker
{
public:
    map_door_seal_marker (const coord_def& pos = coord_def(0, 0),
                    int dur = 0, int mnum = 0,
                    dungeon_feature_type oldfeat = DNGN_CLOSED_DOOR);

    void write (writer &) const;
    void read (reader &);
    map_marker *clone() const;
    string debug_describe() const;

    static map_marker *read(reader &, map_marker_type);

public:
    int duration;
    int mon_num;
    dungeon_feature_type old_feature;
};
#endif

// A marker for temporary terrain changes
class map_terrain_change_marker : public map_marker
{
public:
    map_terrain_change_marker (const coord_def& pos = coord_def(0, 0),
                    dungeon_feature_type oldfeat = DNGN_FLOOR,
                    dungeon_feature_type newfeat = DNGN_FLOOR,
                    int dur = 0, terrain_change_type type = TERRAIN_CHANGE_GENERIC,
                    int mnum = 0, int oldcol = BLACK);

    void write (writer &) const;
    void read (reader &);
    map_marker *clone() const;
    string debug_describe() const;

    static map_marker *read(reader &, map_marker_type);

public:
    int duration;
    int mon_num;
    dungeon_feature_type old_feature;
    dungeon_feature_type new_feature;
    terrain_change_type  change_type;
    int colour;
};

class map_cloud_spreader_marker : public map_marker
{
public:
    map_cloud_spreader_marker(const coord_def &pos = coord_def(0, 0),
                              cloud_type type = CLOUD_NONE,
                              int speed = 10, int amount = 35,
                              int max_radius = LOS_RADIUS, int dur = 10,
                              actor* agent = NULL);

    void write(writer &) const;
    void read(reader &);
    map_marker *clone() const;
    string debug_describe() const;

    static map_marker *read(reader &, map_marker_type);

public:
    cloud_type ctype;
    int speed;
    int remaining;
    int max_rad;
    int duration;
    int speed_increment;
    mid_t agent_mid;
    kill_category kcat;
};

// 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 string &s, const string &ctx,
                   bool mapdef_marker = true);
    ~map_lua_marker();

    void activate(bool verbose);

    void write(writer &) const;
    void read(reader &);
    map_marker *clone() const;
    string debug_describe() const;
    string property(const string &pname) const;

    bool notify_dgn_event(const dgn_event &e);

    static map_marker *read(reader &, map_marker_type);
    static map_marker *parse(const string &s, const string &) throw (string);

    string debug_to_string() const;
private:
    bool initialised;
    unique_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;
    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 &);
    string debug_describe() const;
    string property(const string &pname) const;
    string set_property(const string &key, const string &val);
    map_marker *clone() const;
    static map_marker *read(reader &, map_marker_type);
    static map_marker *parse(const string &s, const string &) throw (string);

public:
    map<string, string> properties;
};

class map_position_marker : public map_marker
{
public:
    map_position_marker(const coord_def &pos = coord_def(0, 0),
                        const coord_def _dest = INVALID_COORD);
    map_position_marker(const map_position_marker &other);
    void write(writer &) const;
    void read(reader &);
    string debug_describe() const;
    map_marker *clone() const;
    static map_marker *read(reader &, map_marker_type);

public:
    coord_def dest;
};

#endif