summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/showsymb.cc
blob: eb815c41e8086eec8b2d0b9fed41be8dbef16f1a (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
/*
 * 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 <stdint.h> // For uint32_t

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

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

    if (object.cls < SH_MONSTER)
    {
        const feature_def &fdef = get_feature_def(object);
        *ch = fdef.symbol;
    }
    else
    {
        ASSERT(object.cls == SH_MONSTER);
        *ch = mons_char(object.mons);
    }

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

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);
}

static 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())
    {
        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);
}

unsigned get_feat_symbol(dungeon_feature_type feat)
{
    return (get_feature_def(feat).symbol);
}

unsigned get_item_symbol(show_item_type it)
{
    return (get_feature_def(show_type(it)).symbol);
}

glyph get_item_glyph(const item_def *item)
{
    glyph g;
    g.ch = get_feature_def(show_type(*item)).symbol;
    g.col = item->colour;
    return (g);
}

glyph get_mons_glyph(const monsters *mons)
{
    glyph g;
    g.ch = mons_char(mons->type);
    g.col = _get_mons_colour(mons);
    return (g);
}

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

    show_type object = env.show(ep);

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

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