File: losparam.h

package info (click to toggle)
crawl 2%3A0.34.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 100,188 kB
  • sloc: cpp: 363,709; ansic: 27,765; javascript: 9,516; python: 8,463; perl: 3,293; java: 3,132; xml: 2,380; makefile: 1,835; sh: 611; objc: 250; cs: 15; sed: 9; lisp: 3
file content (178 lines) | stat: -rw-r--r-- 4,497 bytes parent folder | download | duplicates (2)
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
 * @brief Parameters for the LOS algorithm
**/

#pragma once

// Note: find_ray relies on the fact that 2*OPC_HALF == OPC_OPAQUE.
// On the other hand, losight tracks this explicitly.
enum opacity_type
{
    OPC_CLEAR  = 0,
    OPC_HALF   = 1,    // for opaque clouds; two or more block
    OPC_OPAQUE = 2,

    NUM_OPACITIES
};

class opacity_func
{
public:
    virtual opacity_type operator()(const coord_def& p) const = 0;
    virtual ~opacity_func() {}
    virtual opacity_func* clone() const = 0;
};

#define CLONE(typename) \
    typename* clone() const override \
    { \
        return new typename(*this); \
    }

// Default LOS rules.
class opacity_default : public opacity_func
{
public:
    CLONE(opacity_default)

    opacity_type operator()(const coord_def& p) const override;
};
extern const opacity_default opc_default;

// Default LOS rules, but only consider fully opaque features blocking.
// In particular, clouds don't affect the result.
class opacity_fullyopaque : public opacity_func
{
public:
    CLONE(opacity_fullyopaque)

    opacity_type operator()(const coord_def& p) const override;
};
extern const opacity_fullyopaque opc_fullyopaque;

// Make transparent features block in addition to normal LOS.
// * Translocations opacity: blink, apportation, portal projectile.
// * Various "I feel safe"-related stuff.
class opacity_no_trans : public opacity_func
{
public:
    CLONE(opacity_no_trans)

    opacity_type operator()(const coord_def& p) const override;
};
extern const opacity_no_trans opc_no_trans;

// Like opacity_no_trans, but only fully opaque (e.g. non-cloud) features
// block.
class opacity_fully_no_trans : public opacity_func
{
public:
    CLONE(opacity_fully_no_trans)

    opacity_type operator()(const coord_def& p) const override;
};
extern const opacity_fully_no_trans opc_fully_no_trans;

// Make immobile monsters block in addition to no_trans.
// This is used for spellspark servitor AI.
// XXX: could use opacity_mons_immob? should?
class opacity_immob : public opacity_func
{
public:
    CLONE(opacity_immob)

    opacity_type operator()(const coord_def& p) const override;
};
extern const opacity_immob opc_immob;

// Make aligned immobile monsters block in addition to no_trans.
// This is used for monster movement.
class opacity_mons_immob : public opacity_func
{
public:
    opacity_mons_immob(const monster* mons) : mon(mons) {}
    opacity_func* clone() const override
    {
        return new opacity_mons_immob(mon);
    }

    opacity_type operator()(const coord_def& p) const override;
private:
    const monster* mon;
};

// Line of effect.
class opacity_solid : public opacity_func
{
public:
    CLONE(opacity_solid)

    opacity_type operator()(const coord_def& p) const override;
};
extern const opacity_solid opc_solid;

// Both line of sight and line of effect.
class opacity_solid_see : public opacity_func
{
public:
    CLONE(opacity_solid_see)

    opacity_type operator()(const coord_def& p) const override;
};
extern const opacity_solid_see opc_solid_see;

// Opacity for monster movement, based on the late monster_los.
class opacity_monmove : public opacity_func
{
public:
    opacity_monmove(const monster& m)
        : mon(m)
    {
    }

    CLONE(opacity_monmove)

    opacity_type operator()(const coord_def& p) const override;
private:
    const monster& mon;
};

// Make any actor (as well as solid features) block.
// Note that the blocking actors are still "visible".
class opacity_no_actor : public opacity_func
{
public:
    CLONE(opacity_no_actor)

    opacity_type operator()(const coord_def& p) const override;
};
extern const opacity_no_actor opc_no_actor;

// A cell is considered clear unless the player knows it's
// opaque.
class opacity_excl : public opacity_func
{
public:
    CLONE(opacity_excl)

    opacity_type operator()(const coord_def& p) const override;
};
extern const opacity_excl opc_excl;

// Subclasses of this are passed to losight() to modify the
// LOS calculation. Implementations will have to translate between
// relative coordinates (-8,-8)..(8,8) and real coordinates,
// specify how opaque the cells are and determine what values
// are written to the visible cells.
class los_param
{
public:
    virtual ~los_param() {}

    // Whether the translated coordinate lies within the map
    // (including boundary) and within the LOS area
    virtual bool los_bounds(const coord_def& p) const = 0;

    virtual opacity_type opacity(const coord_def& p) const = 0;
};