1 #include "AppHdr.h"
2 
3 #include "viewchar.h"
4 
5 #include "options.h"
6 #include "unicode.h"
7 #include "tag-version.h"
8 
9 // For order and meaning of symbols see dungeon_char_type in dungeon_char_type.h
10 static const char32_t dchar_table[NUM_CSET][NUM_DCHAR_TYPES] =
11 {
12     // CSET_DEFAULT
13     // It must be limited to stuff present both in CP437 and WGL4.
14     {
15         // wall .. altar
16          '#', U'\x2593', //▓
17             '*',  '.',  ',', '\'',  '+',  '^',  '>',  '<', '#',  '_',
18         // arch .. invis_exposed
19          U'\x2229', //∩
20             U'\x2320', //⌠
21             U'\x2248', //≈
22             '8',  '{',
23 #if defined(TARGET_OS_WINDOWS) && !defined(USE_TILE_LOCAL)
24          U'\x2302', //⌂ // CP437 but "optional" in WGL4
25 #else
26          U'\x2206', //∆ // WGL4 and DEC
27 #endif
28          '0', U'\x3c6', //φ
29          ')',  '[',  '/',
30 #if TAG_MAJOR_VERSION == 34
31          '%',
32 #endif
33          '?',  '=',  '!',  '(', ':',  '|',
34 #if TAG_MAJOR_VERSION == 34
35          '\\',
36 #endif
37          '}', U'\x2020', //†
38             U'\xf7', //÷
39             '$',  '"',
40          U'\xa7', U'\x263c', U'\x25CB', U'\xB0', // §, ☼, ○, °
41             U'\x2663', //♣
42 #if TAG_MAJOR_VERSION == 34
43          U'\xa9', //©
44 #endif
45         // transporter .. frame_top_left
46          U'\xa9', //©
47             U'\xa9', //©
48             ' ',  '#',  '*', U'\xf7', //÷
49             'X',  '`',  '#', U'\x2550', //═
50             U'\x2551', //║
51             U'\x2554', //╔
52         // frame_top_right .. draw_down
53          U'\x2557', //╗
54             U'\x255a', //╚
55             U'\x255d', //╝
56             U'\x2500', //─
57             U'\x2502', //│
58             '/', '\\', U'\x250c', //┌
59             U'\x2510', //┐
60             U'\x2514', //└
61             U'\x2518', //┘
62             'V',
63         // draw_up .. draw_left
64          U'\x39b', //Λ
65             '>',  '<',
66     },
67     // CSET_ASCII
68     {
69         // wall .. altar
70          '#',  '#',  '*',  '.',  ',', '\'',  '+',  '^',  '>',  '<',  '#',  '_',
71         // arch .. item_wand
72         '\\',  '}',  '~',  '8',  '{',  '{',  '{',  '}',  ')',  '[',  '/',
73 #if TAG_MAJOR_VERSION == 34
74         '%', // food
75 #endif
76         // item_scroll .. item_staff
77          '?',  '=',  '!',  '(',  ':',  '|',
78 #if TAG_MAJOR_VERSION == 34
79          '|', // rod
80 #endif
81         // miscellany .. amulet
82          '}',  '%',  '%',  '$',  '"',
83         // cloud .. tree
84          '0', '0', '0', '0', '7',
85 #if TAG_MAJOR_VERSION == 34
86          '^',
87 #endif
88         // transporter .. frame_top_left
89          '^',  '^',  ' ',  '#',  '*',  '+',  'X',  '`',  '#',  '-',  '|',  '+',
90         // frame_top_right .. draw_down
91          '+',  '+',  '+',  '-',  '|',  '/', '\\',  '*',  '*',  '*',  '*',  'V',
92         // draw_up .. draw_left
93          '^',  '>',  '<'
94     }
95 };
96 COMPILE_CHECK(ARRAYSZ(dchar_table) == NUM_CSET);
97 COMPILE_CHECK(ARRAYSZ(dchar_table[0]) == NUM_DCHAR_TYPES);
98 COMPILE_CHECK(ARRAYSZ(dchar_table[1]) == NUM_DCHAR_TYPES);
99 
dchar_by_name(const string & name)100 dungeon_char_type dchar_by_name(const string &name)
101 {
102     static const char *dchar_names[] =
103     {
104         "wall", "permawall", "wall_magic", "floor", "floor_magic", "door_open",
105         "door_closed", "trap", "stairs_down", "stairs_up", "grate", "altar",
106         "arch", "fountain", "wavy", "statue", "invis_exposed", "item_detected",
107         "item_orb", "item_rune", "item_weapon", "item_armour", "item_wand",
108 #if TAG_MAJOR_VERSION == 34
109         "item_food",
110 #endif
111         "item_scroll", "item_ring", "item_potion", "item_missile", "item_book",
112         "item_staff",
113 #if TAG_MAJOR_VERSION == 34
114         "item_rod",
115 #endif
116         "item_miscellany", "item_corpse", "item_skeleton", "item_gold",
117         "item_amulet", "cloud", "cloud_weak", "cloud_fading", "cloud_terminal",
118         "tree",
119 #if TAG_MAJOR_VERSION == 34
120         "teleporter",
121 #endif
122         "transporter", "transporter_landing", "space", "fired_bolt",
123         "fired_zap", "fired_burst", "fired_debug", "fired_missile",
124         "explosion", "frame_horiz", "frame_vert", "frame_top_left",
125         "frame_top_right", "frame_bottom_left", "frame_bottom_right",
126         "draw_horiz", "draw_vert", "draw_slash", "draw_backslash",
127         "draw_top_left", "draw_top_right", "draw_bottom_left",
128         "draw_bottom_right", "draw_down", "draw_up", "draw_right", "draw_left",
129     };
130     COMPILE_CHECK(ARRAYSZ(dchar_names) == NUM_DCHAR_TYPES);
131 
132     for (unsigned i = 0; i < ARRAYSZ(dchar_names); ++i)
133         if (dchar_names[i] == name)
134             return dungeon_char_type(i);
135 
136     return NUM_DCHAR_TYPES;
137 }
138 
init_char_table(char_set_type set)139 void init_char_table(char_set_type set)
140 {
141     for (int i = 0; i < NUM_DCHAR_TYPES; i++)
142     {
143         char32_t c;
144         if (Options.cset_override[i])
145             c = Options.cset_override[i];
146         else
147             c = dchar_table[set][i];
148         if (wcwidth(c) != 1)
149             c = dchar_table[CSET_ASCII][i];
150         Options.char_table[i] = c;
151     }
152 }
153 
dchar_glyph(dungeon_char_type dchar)154 char32_t dchar_glyph(dungeon_char_type dchar)
155 {
156     if (dchar >= 0 && dchar < NUM_DCHAR_TYPES)
157         return Options.char_table[dchar];
158     else
159         return 0;
160 }
161 
stringize_glyph(char32_t glyph)162 string stringize_glyph(char32_t glyph)
163 {
164     char buf[5];
165     buf[wctoutf8(buf, glyph)] = 0;
166 
167     return buf;
168 }
169 
get_feature_dchar(dungeon_feature_type feat)170 dungeon_char_type get_feature_dchar(dungeon_feature_type feat)
171 {
172     return get_feature_def(feat).dchar;
173 }
174