File: viewchar.cc

package info (click to toggle)
crawl 2%3A0.34.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • 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 (177 lines) | stat: -rw-r--r-- 5,500 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
#include "AppHdr.h"

#include "viewchar.h"

#include "options.h"
#include "unicode.h"
#include "tag-version.h"

// For order and meaning of symbols see dungeon_char_type in dungeon_char_type.h
static const char32_t dchar_table[NUM_CSET][NUM_DCHAR_TYPES] =
{
    // CSET_DEFAULT
    // It must be limited to stuff present both in CP437 and WGL4.
    {
        // wall .. altar
         '#', U'\x2593', //▓
            '*',  '.',  ',', '\'',  '+',  '^',  '>',  '<', '#',  '_',
        // arch .. invis_exposed
         U'\x2229', //∩
            U'\x2320', //⌠
            U'\x2248', //≈
            '~', // sadly, ∼ (U+223C, not ascii ~) and ≃ are not in WGL4
            U'\x00df',  '{',
#if defined(TARGET_OS_WINDOWS) && !defined(USE_TILE_LOCAL)
         U'\x2302', //⌂ // CP437 but "optional" in WGL4
#else
         U'\x2206', //∆ // WGL4 and DEC
#endif
         '0', U'\x3c6', //φ
         ')',  '[',  '/',
#if TAG_MAJOR_VERSION == 34
         '%',
#endif
         '?',  '=',  '!',  '(', ':',  '|',
#if TAG_MAJOR_VERSION == 34
         '\\',
#endif
         '%', '}', U'\x2020', //%, }, †
            U'\xf7', //÷
            '$', U'\x2666', // ♦
         U'\x2022', // •
          '"',
         U'\xa7', U'\x263c', U'\x25CB', U'\xB0', // §, ☼, ○, °
            U'\x2663', //♣
#if TAG_MAJOR_VERSION == 34
         U'\xa9', //©
#endif
        // transporter .. frame_top_left
         U'\xa9', //©
            U'\xa9', //©
            ' ',  '#',  '*', U'\xf7', //÷
            'X',  '`',  '#', U'\x2550', //═
            U'\x2551', //║
            U'\x2554', //╔
        // frame_top_right .. draw_down
         U'\x2557', //╗
            U'\x255a', //╚
            U'\x255d', //╝
            U'\x2500', //─
            U'\x2502', //│
            '/', '\\', U'\x250c', //┌
            U'\x2510', //┐
            U'\x2514', //└
            U'\x2518', //┘
            'V',
        // draw_up .. draw_left
         U'\x39b', //Λ
            '>',  '<',
    },
    // CSET_ASCII
    {
        // wall .. altar
         '#',  '#',  '*',  '.',  ',', '\'',  '+',  '^',  '>',  '<',  '#',  '_',
        // arch .. item_wand
        '\\',  '-',  '~', '~', '8',  '{',  '{',  '{',  '}',  ')',  '[',  '/',
#if TAG_MAJOR_VERSION == 34
        '%', // food
#endif
        // item_scroll .. item_staff
         '?',  '=',  '!',  '(',  ':',  '|',
#if TAG_MAJOR_VERSION == 34
         '|', // rod
#endif
        // talisman .. amulet
         '|', '}',  '%',  '%',  '$',  '$',  '|',  '"',
        // cloud .. tree
         '0', '0', '0', '0', '7',
#if TAG_MAJOR_VERSION == 34
         '^',
#endif
        // transporter .. frame_top_left
         '^',  '^',  ' ',  '#',  '*',  '+',  'X',  '`',  '#',  '-',  '|',  '+',
        // frame_top_right .. draw_down
         '+',  '+',  '+',  '-',  '|',  '/', '\\',  '*',  '*',  '*',  '*',  'V',
        // draw_up .. draw_left
         '^',  '>',  '<'
    }
};
COMPILE_CHECK(ARRAYSZ(dchar_table) == NUM_CSET);
COMPILE_CHECK(ARRAYSZ(dchar_table[0]) == NUM_DCHAR_TYPES);
COMPILE_CHECK(ARRAYSZ(dchar_table[1]) == NUM_DCHAR_TYPES);

dungeon_char_type dchar_by_name(const string &name)
{
    static const char *dchar_names[] =
    {
        "wall", "permawall", "wall_magic", "floor", "floor_magic", "door_open",
        "door_closed", "trap", "stairs_down", "stairs_up", "grate", "altar",
        "arch", "fountain", "wavy", "shallow_wavy", "statue", "invis_exposed",
        "item_detected", "item_orb", "item_rune", "item_weapon", "item_armour",
        "item_wand",
#if TAG_MAJOR_VERSION == 34
        "item_food",
#endif
        "item_scroll", "item_ring", "item_potion", "item_missile", "item_book",
        "item_staff",
#if TAG_MAJOR_VERSION == 34
        "item_rod",
#endif
        "item_talisman", "item_miscellany", "item_corpse", "item_skeleton",
        "item_gold", "item_gem", "item_bauble", "item_amulet",
        "cloud", "cloud_weak", "cloud_fading", "cloud_terminal", "tree",
#if TAG_MAJOR_VERSION == 34
        "teleporter",
#endif
        "transporter", "transporter_landing", "space", "fired_bolt",
        "fired_zap", "fired_burst", "fired_debug", "fired_missile",
        "explosion", "frame_horiz", "frame_vert", "frame_top_left",
        "frame_top_right", "frame_bottom_left", "frame_bottom_right",
        "draw_horiz", "draw_vert", "draw_slash", "draw_backslash",
        "draw_top_left", "draw_top_right", "draw_bottom_left",
        "draw_bottom_right", "draw_down", "draw_up", "draw_right", "draw_left",
    };
    COMPILE_CHECK(ARRAYSZ(dchar_names) == NUM_DCHAR_TYPES);

    for (unsigned i = 0; i < ARRAYSZ(dchar_names); ++i)
        if (dchar_names[i] == name)
            return dungeon_char_type(i);

    return NUM_DCHAR_TYPES;
}

void init_char_table(char_set_type set)
{
    for (int i = 0; i < NUM_DCHAR_TYPES; i++)
    {
        char32_t c;
        if (Options.cset_override[i])
            c = Options.cset_override[i];
        else
            c = dchar_table[set][i];
        if (wcwidth(c) != 1)
            c = dchar_table[CSET_ASCII][i];
        Options.char_table[i] = c;
    }
}

char32_t dchar_glyph(dungeon_char_type dchar)
{
    if (dchar >= 0 && dchar < NUM_DCHAR_TYPES)
        return Options.char_table[dchar];
    else
        return 0;
}

string stringize_glyph(char32_t glyph)
{
    char buf[5];
    buf[wctoutf8(buf, glyph)] = 0;

    return buf;
}

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