summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/mapmark.h
blob: 81c1e1d0608af87d8c9d21cf6783851efe9f317f (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
#ifndef __MAPMARK_H__
#define __MAPMARK_H__

#include "dungeon.h"
#include "dgnevent.h"
#include "clua.h"
#include "luadgn.h"

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

struct tagHeader;

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(tagHeader &) const;
    virtual void read(tagHeader &);
    virtual std::string debug_describe() const = 0;
    virtual std::string feature_description() const;
    virtual std::string property(const std::string &pname) const; 
   
    static map_marker *read_marker(tagHeader&);
    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)(tagHeader &, 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(tagHeader &) const;
    void read(tagHeader &);
    std::string debug_describe() const;
    map_marker *clone() const;
    static map_marker *read(tagHeader &, 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(tagHeader &) const;
    void read(tagHeader &);
    map_marker *clone() const;
    std::string debug_describe() const;

    static map_marker *read(tagHeader &, map_marker_type);

public:
    int duration, radius;
};

// A marker powered by Lua.
class map_lua_marker : public map_marker, public dgn_event_listener
{
public:
    map_lua_marker();
    map_lua_marker(const std::string &s, const std::string &ctx);
    ~map_lua_marker();

    void activate(bool verbose);

    void write(tagHeader &) const;
    void read(tagHeader &);
    map_marker *clone() const;
    std::string debug_describe() const;
    std::string feature_description() const;
    std::string property(const std::string &pname) const;
    
    void notify_dgn_event(const dgn_event &e);
    
    static map_marker *read(tagHeader &, map_marker_type);
    static map_marker *parse(const std::string &s, const std::string &)
        throw (std::string);
private:
    bool initialised;
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;
};

#endif