summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/showsymb.cc
blob: eef0dc76364efc2224e52a354571ecc141a015e9 (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
/*
 * File:     showsymb.cc
 * Summary:  Rendering of show info to glyph and colour.
 *
 * Eventually, this should only need the information within
 * one object of type show_type (or show_info).
 */

#include "AppHdr.h"

#include "showsymb.h"

#include "colour.h"
#include "env.h"
#include "envmap.h"
#include "mon-util.h"
#include "monster.h"
#include "options.h"
#include "overmap.h"
#include "random.h"
#include "show.h"
#include "spells3.h"
#include "state.h"
#include "stuff.h"
#include "terrain.h"
#include "viewchar.h"
#include "viewgeom.h"
#include "viewmap.h"

static bool _show_bloodcovered(const coord_def& where)
{
    if (!is_bloodcovered(where))
        return (false);

    dungeon_feature_type feat = env.grid(where);

    // Altars, stairs (of any kind) and traps should not be coloured red.
    return (!is_critical_feature(feat) && !feat_is_trap(feat));
}

static unsigned short _tree_colour(const coord_def& where)
{
    uint32_t h = where.x;
    h+=h<<10; h^=h>>6;
    h += where.y;
    h+=h<<10; h^=h>>6;
    h+=h<<3; h^=h>>11; h+=h<<15;
    return (h>>30) ? GREEN : LIGHTGREEN;
}

static unsigned short _feat_colour(const coord_def &where,
                                   const dungeon_feature_type feat,
                                   unsigned short colour)
{
    const feature_def &fdef = get_feature_def(feat);
    // TODO: consolidate with feat_is_stair etc.
    bool excluded_stairs = (feat >= DNGN_STONE_STAIRS_DOWN_I
                            && feat <= DNGN_ESCAPE_HATCH_UP
                            && is_exclude_root(where));

    if (excluded_stairs)
        colour = Options.tc_excluded;
    else if (feat >= DNGN_MINMOVE && you.get_beholder(where))
    {
        // Colour grids that cannot be reached due to beholders
        // dark grey.
        colour = DARKGREY;
    }
    else if (feat >= DNGN_MINMOVE && is_sanctuary(where))
    {
        if (testbits(env.map(where).property, FPROP_SANCTUARY_1))
            colour = YELLOW;
        else if (testbits(env.map(where).property, FPROP_SANCTUARY_2))
        {
            if (!one_chance_in(4))
                colour = WHITE;     // 3/4
            else if (!one_chance_in(3))
                colour = LIGHTCYAN; // 1/6
            else
                colour = LIGHTGREY; // 1/12
        }
    }
    else if (_show_bloodcovered(where))
        colour = RED;
    else if (env.grid_colours(where))
        colour = env.grid_colours(where);
    else
    {
        // Don't clobber with BLACK, because the colour should be
        // already set.
        if (fdef.colour != BLACK)
            colour = fdef.colour;
        else if (feat == DNGN_TREES)
            colour = _tree_colour(where);

        if (fdef.em_colour && fdef.em_colour != fdef.colour &&
            emphasise(where, feat))
        {
            colour = fdef.em_colour;
        }
    }

    // TODO: should be a feat_is_whatever(feat)
    if (feat >= DNGN_FLOOR_MIN && feat <= DNGN_FLOOR_MAX
        || feat == DNGN_UNDISCOVERED_TRAP)
    {
        if (inside_halo(where))
        {
            if (silenced(where))
                colour = LIGHTCYAN;
            else
                colour = YELLOW;
        }
        else if (silenced(where))
            colour = CYAN;
    }
    return (colour);
}

void get_symbol(const coord_def& where,
                show_type object, unsigned *ch,
                unsigned short *colour,
                bool magic_mapped)
{
    ASSERT(ch != NULL);

    if (object.cls < SH_MONSTER)
    {

        // Don't recolor items
        if (colour && object.cls == SH_FEATURE)
        {
            const int colmask = *colour & COLFLAG_MASK;
            *colour = _feat_colour(where, object.feat, *colour) | colmask;
        }

        const feature_def &fdef = get_feature_def(object);
        *ch = magic_mapped ? fdef.magic_symbol
                           : fdef.symbol;

        // Note anything we see that's notable
        if (!where.origin() && fdef.is_notable())
        {
            if (object.cls == SH_FEATURE)
                seen_notable_thing(object.feat, where);
        }
    }
    else
    {
        ASSERT(object.cls == SH_MONSTER);
        *ch = mons_char(object.mons);
    }

    if (colour)
        *colour = real_colour(*colour);
}

unsigned get_symbol(show_type object, unsigned short *colour,
                    bool magic_mapped)
{
    unsigned ch;
    get_symbol(coord_def(0,0), object, &ch, NULL, magic_mapped);
    return (ch);
}

void get_show_symbol(show_type object, unsigned *ch,
                     unsigned short *colour)
{
    if (object.cls < SH_MONSTER)
    {
        *ch = get_feature_def(object).symbol;

        // Don't clobber with BLACK, because the colour should be already set.
        if (get_feature_def(object).colour != BLACK)
            *colour = get_feature_def(object).colour;
    }
    *colour = real_colour(*colour);
}

unsigned grid_character_at(const coord_def &c)
{
    unsigned glych;
    unsigned short glycol = 0;

    get_symbol(c, grd(c), &glych, &glycol);
    return glych;
}

dungeon_char_type get_feature_dchar(dungeon_feature_type feat)
{
    return (get_feature_def(feat).dchar);
}

int get_mons_colour(const monsters *mons)
{
    int col = mons->colour;

    if (mons->berserk())
        col = RED;

    if (mons->friendly())
    {
        col |= COLFLAG_FRIENDLY_MONSTER;
    }
    else if (mons_neutral(mons))
    {
        col |= COLFLAG_NEUTRAL_MONSTER;
    }
    else if (Options.stab_brand != CHATTR_NORMAL
             && mons_looks_stabbable(mons))
    {
        col |= COLFLAG_WILLSTAB;
    }
    else if (Options.may_stab_brand != CHATTR_NORMAL
             && mons_looks_distracted(mons))
    {
        col |= COLFLAG_MAYSTAB;
    }
    else if (mons_is_stationary(mons))
    {
        if (Options.feature_item_brand != CHATTR_NORMAL
            && is_critical_feature(grd(mons->pos()))
            && feat_stair_direction(grd(mons->pos())) != CMD_NO_CMD)
        {
            col |= COLFLAG_FEATURE_ITEM;
        }
        else if (Options.heap_brand != CHATTR_NORMAL
                 && igrd(mons->pos()) != NON_ITEM
                 && !crawl_state.arena)
        {
            col |= COLFLAG_ITEM_HEAP;
        }
    }

    // Backlit monsters are fuzzy and override brands.
    if (!you.can_see_invisible() && mons->has_ench(ENCH_INVIS)
        && mons->backlit())
    {
        col = DARKGREY;
    }

    return (col);
}

void get_item_glyph(const item_def *item, unsigned *glych,
                    unsigned short *glycol)
{
    *glycol = item->colour;
    get_symbol(coord_def(0,0), show_type(*item), glych, glycol);
}

void get_mons_glyph(const monsters *mons, unsigned *glych,
                    unsigned short *glycol)
{
    *glycol = get_mons_colour(mons);
    get_symbol(coord_def(0,0), show_type(mons), glych, glycol);
}

unsigned get_screen_glyph( int x, int y )
{
    return get_screen_glyph(coord_def(x,y));
}

unsigned get_screen_glyph(const coord_def& p)
{
    const coord_def ep = view2show(grid2view(p));

    show_type object = env.show(ep);
    unsigned short  colour = object.colour;
    unsigned        ch;

    if (!object)
        return get_envmap_char(p.x, p.y);

    get_symbol(p, object, &ch, &colour);
    return (ch);
}