File: losparam.cc

package info (click to toggle)
crawl 2%3A0.34.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 100,204 kB
  • sloc: cpp: 363,900; 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 (207 lines) | stat: -rw-r--r-- 5,956 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
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
/**
 * @file
 * @brief Parameters for the LOS algorithm
**/

#include "AppHdr.h"

#include "losparam.h"

#include "cloud.h"
#include "env.h"
#include "los.h"
#include "state.h"
#include "terrain.h"

const opacity_default opc_default = opacity_default();
const opacity_fullyopaque opc_fullyopaque = opacity_fullyopaque();
const opacity_no_trans opc_no_trans = opacity_no_trans();
const opacity_fully_no_trans opc_fully_no_trans = opacity_fully_no_trans();
const opacity_immob opc_immob = opacity_immob();
const opacity_solid opc_solid = opacity_solid();
const opacity_solid_see opc_solid_see = opacity_solid_see();
const opacity_no_actor opc_no_actor = opacity_no_actor();
const opacity_excl opc_excl = opacity_excl();
const opacity_map_default opc_map_default = opacity_map_default();
const opacity_map_no_trans opc_map_no_trans = opacity_map_no_trans();
const opacity_map_solid opc_map_solid = opacity_map_solid();
const opacity_map_solid_see opc_map_solid_see = opacity_map_solid_see();

opacity_type opacity_default::operator()(const coord_def& p) const
{
    dungeon_feature_type f = env.grid(p);
    if (feat_is_opaque(f))
        return OPC_OPAQUE;
    else if (is_opaque_cloud(cloud_type_at(p)))
        return OPC_HALF;
    else if (const monster *mon = monster_at(p))
        return mons_opacity(mon->type, LOS_DEFAULT);
    return OPC_CLEAR;
}

opacity_type opacity_fullyopaque::operator()(const coord_def& p) const
{
    if (feat_is_opaque(env.grid(p)))
        return OPC_OPAQUE;
    else
        return OPC_CLEAR;
}

opacity_type opacity_no_trans::operator()(const coord_def& p) const
{
    dungeon_feature_type f = env.grid(p);
    if (feat_is_opaque(f) || feat_is_wall(f) || feat_is_closed_door(f))
        return OPC_OPAQUE;
    else if (is_opaque_cloud(cloud_type_at(p)))
        return OPC_HALF;
    else if (const monster *mon = monster_at(p))
        return mons_opacity(mon->type, LOS_NO_TRANS);
    return OPC_CLEAR;
}

opacity_type opacity_fully_no_trans::operator()(const coord_def& p) const
{
    dungeon_feature_type f = env.grid(p);
    if (feat_is_opaque(f) || feat_is_wall(f) || feat_is_closed_door(f))
        return OPC_OPAQUE;
    return OPC_CLEAR;
}

opacity_type opacity_immob::operator()(const coord_def& p) const
{
    const monster* mons = monster_at(p);
    return (mons && mons->is_stationary()) ? OPC_OPAQUE : opc_no_trans(p);
}

opacity_type opacity_mons_immob::operator()(const coord_def& p) const
{
    const monster* other_mons = monster_at(p);
    const bool impassable = other_mons
                            && other_mons->is_stationary()
                            && mons_aligned(mon, other_mons);
    return impassable ? OPC_OPAQUE : opc_no_trans(p);
}

opacity_type opacity_solid::operator()(const coord_def& p) const
{
    dungeon_feature_type f = env.grid(p);
    if (feat_is_solid(f))
        return OPC_OPAQUE;

    return OPC_CLEAR;
}

// Make anything solid block in addition to normal LOS.
// That includes statues and grates in addition to opacity_no_trans.
opacity_type opacity_solid_see::operator()(const coord_def& p) const
{
    dungeon_feature_type f = env.grid(p);
    if (feat_is_solid(f))
        return OPC_OPAQUE;
    else if (is_opaque_cloud(cloud_type_at(p)))
        return OPC_HALF;
    else if (const monster *mon = monster_at(p))
        return mons_opacity(mon->type, LOS_SOLID_SEE);

    return OPC_CLEAR;
}

opacity_type opacity_monmove::operator()(const coord_def& p) const
{
    dungeon_feature_type feat = env.grid(p);
    if (feat_is_solid(feat) || !mon.can_pass_through_feat(feat))
        return OPC_OPAQUE;
    else
        return OPC_CLEAR;
}

opacity_type opacity_no_actor::operator()(const coord_def& p) const
{
    if (feat_is_solid(env.grid(p)) || actor_at(p))
        return OPC_OPAQUE;
    else
        return OPC_CLEAR;
}

opacity_type opacity_excl::operator()(const coord_def& p) const
{
    map_cell& cell = env.map_knowledge(p);
    if (!cell.known())
        return OPC_CLEAR;
    else if (!cell.changed())
        return feat_is_opaque(env.grid(p)) ? OPC_OPAQUE : OPC_CLEAR;
    else if (cell.feat() != DNGN_UNSEEN)
        return feat_is_opaque(cell.feat()) ? OPC_OPAQUE : OPC_CLEAR;
    else
        return OPC_CLEAR;
}

opacity_type opacity_map_default::operator()(const coord_def& p) const
{
    map_cell& cell = env.map_knowledge(p);
    dungeon_feature_type f = cell.feat();
    if (!cell.known() || f == DNGN_UNSEEN)
        return OPC_CLEAR;

    if (feat_is_opaque(f))
       return OPC_OPAQUE;

    if (is_opaque_cloud(cell.cloud()))
        return OPC_HALF;

    if (cell.monsterinfo())
        return mons_opacity(cell.monster(), LOS_DEFAULT);

    return OPC_CLEAR;
}

opacity_type opacity_map_no_trans::operator()(const coord_def& p) const
{
    map_cell& cell = env.map_knowledge(p);
    dungeon_feature_type f = cell.feat();
    if (!cell.known() || f == DNGN_UNSEEN)
        return OPC_CLEAR;

    if (feat_is_opaque(f) || feat_is_wall(f) || feat_is_closed_door(f))
        return OPC_OPAQUE;

    if (is_opaque_cloud(cell.cloud()))
        return OPC_HALF;

    if (cell.monsterinfo())
        return mons_opacity(cell.monster(), LOS_NO_TRANS);

    return OPC_CLEAR;
}

opacity_type opacity_map_solid::operator()(const coord_def& p) const
{
    map_cell& cell = env.map_knowledge(p);
    dungeon_feature_type f = cell.feat();
    if (!cell.known() || f == DNGN_UNSEEN)
        return OPC_CLEAR;

    if (feat_is_solid(f))
        return OPC_OPAQUE;

    return OPC_CLEAR;
}

opacity_type opacity_map_solid_see::operator()(const coord_def& p) const
{
    map_cell& cell = env.map_knowledge(p);
    dungeon_feature_type f = cell.feat();
    if (!cell.known() || f == DNGN_UNSEEN)
        return OPC_CLEAR;

    if (feat_is_solid(f))
        return OPC_OPAQUE;

    if (is_opaque_cloud(cell.cloud()))
        return OPC_HALF;

    if (cell.monsterinfo())
        return mons_opacity(cell.monster(), LOS_SOLID_SEE);

    return OPC_CLEAR;
}