summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/exclude.h
blob: 0889d4679fa2ded3bec036bbc2afd6d2892cc102 (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
#ifndef EXCLUDE_H
#define EXCLUDE_H

#include "los_def.h"

bool need_auto_exclude(const monsters *mon, bool sleepy = false);
void set_auto_exclude(const monsters *mon);
void remove_auto_exclude(const monsters *mon, bool sleepy = false);

void init_exclusion_los();
void update_exclusion_los(std::vector<coord_def> changed);
void deferred_exclude_update();

bool is_exclude_root(const coord_def &p);
void cycle_exclude_radius(const coord_def &p);
void del_exclude(const coord_def &p);
void set_exclude(const coord_def &p, int radius = LOS_RADIUS,
                 bool autoexcl = false, bool vaultexcl = false,
                 bool defer_updates = false);
void maybe_remove_autoexclusion(const coord_def &p);
void clear_excludes();

class travel_exclude
{
public:
    coord_def     pos;          // exclusion centre
    int           radius;       // exclusion radius
    los_def       los;          // los from exclusion centre
    bool          uptodate;     // Is los up to date?
    bool          autoex;       // Was set automatically.
    std::string   desc;         // Exclusion description.
    bool          vault;        // Is this exclusion set by a vault?

    travel_exclude(const coord_def &p, int r = LOS_RADIUS,
                   bool autoex = false, std::string desc = "",
                   bool vault = false);
    // For exclude_map[p] = foo;
    travel_exclude();

    int radius_sq() const;
    bool in_bounds(const coord_def& p) const;
    bool affects(const coord_def& p) const;

private:
    void set_los();

    friend class exclude_set;
};

class exclude_set
{
public:
    exclude_set();

    typedef std::map<coord_def, travel_exclude> exclmap;
    typedef exclmap::iterator       iterator;
    typedef exclmap::const_iterator const_iterator;

    void clear();

    void erase(const coord_def &p);
    void add_exclude(travel_exclude &ex);
    void add_exclude(const coord_def &p, int radius = LOS_RADIUS,
                     bool autoexcl = false,
                     std::string desc = "",
                     bool vaultexcl = false);

    void update_excluded_points();
    void recompute_excluded_points(bool recompute_los = false);

    travel_exclude* get_exclude_root(const coord_def &p);

    bool is_excluded(const coord_def &p) const;
    bool is_exclude_root(const coord_def &p) const;
    std::string get_exclusion_desc();

    size_t size()  const;
    bool   empty() const;

    const_iterator begin() const;
    const_iterator end() const;

    iterator  begin();
    iterator  end();

private:
    typedef std::set<coord_def> exclset;

    exclmap exclude_roots;
    exclset exclude_points;

private:
    void add_exclude_points(travel_exclude& ex);
};

extern exclude_set curr_excludes; // in travel.cc

bool is_excluded(const coord_def &p, const exclude_set &exc = curr_excludes);

class writer;
class reader;
void marshallExcludes(writer& outf, const exclude_set& excludes);
void unmarshallExcludes(reader& inf, char minorVersion, exclude_set& excludes);

#endif