1 |
elmex |
1.1 |
/* |
2 |
root |
1.29 |
* This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 |
pippijn |
1.12 |
* |
4 |
root |
1.32 |
* Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 |
pippijn |
1.12 |
* |
6 |
root |
1.31 |
* Deliantra is free software: you can redistribute it and/or modify it under |
7 |
|
|
* the terms of the Affero GNU General Public License as published by the |
8 |
|
|
* Free Software Foundation, either version 3 of the License, or (at your |
9 |
|
|
* option) any later version. |
10 |
pippijn |
1.12 |
* |
11 |
root |
1.26 |
* This program is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
pippijn |
1.12 |
* |
16 |
root |
1.31 |
* You should have received a copy of the Affero GNU General Public License |
17 |
|
|
* and the GNU General Public License along with this program. If not, see |
18 |
|
|
* <http://www.gnu.org/licenses/>. |
19 |
root |
1.24 |
* |
20 |
root |
1.29 |
* The authors can be reached via e-mail to <support@deliantra.net> |
21 |
pippijn |
1.12 |
*/ |
22 |
elmex |
1.1 |
|
23 |
|
|
#include <global.h> |
24 |
|
|
#include <stdio.h> |
25 |
|
|
|
26 |
root |
1.19 |
#include "face.h" |
27 |
root |
1.17 |
#include "crc.h" |
28 |
|
|
|
29 |
root |
1.19 |
faceidx blank_face, empty_face; |
30 |
elmex |
1.1 |
|
31 |
root |
1.19 |
facehash_t facehash; |
32 |
|
|
std::vector<faceinfo> faces; |
33 |
elmex |
1.1 |
|
34 |
|
|
/* the only thing this table is used for now is to |
35 |
|
|
* translate the colorname in the magicmap field of the |
36 |
|
|
* face into a numeric index that is then sent to the |
37 |
|
|
* client for magic map commands. The order of this table |
38 |
|
|
* must match that of the NDI colors in include/newclient.h. |
39 |
|
|
*/ |
40 |
|
|
static const char *const colorname[] = { |
41 |
root |
1.6 |
"black", /* 0 */ |
42 |
|
|
"white", /* 1 */ |
43 |
|
|
"blue", /* 2 */ |
44 |
|
|
"red", /* 3 */ |
45 |
|
|
"orange", /* 4 */ |
46 |
|
|
"light_blue", /* 5 */ |
47 |
|
|
"dark_orange", /* 6 */ |
48 |
|
|
"green", /* 7 */ |
49 |
|
|
"light_green", /* 8 */ |
50 |
|
|
"grey", /* 9 */ |
51 |
|
|
"brown", /* 10 */ |
52 |
|
|
"yellow", /* 11 */ |
53 |
|
|
"khaki" /* 12 */ |
54 |
elmex |
1.1 |
}; |
55 |
|
|
|
56 |
|
|
/* |
57 |
|
|
* Returns the matching color in the coloralias if found, |
58 |
|
|
* 0 otherwise. Note that 0 will actually be black, so there is no |
59 |
|
|
* way the calling function can tell if an error occurred or not |
60 |
|
|
*/ |
61 |
root |
1.6 |
static uint8 |
62 |
|
|
find_color (const char *name) |
63 |
|
|
{ |
64 |
elmex |
1.1 |
uint8 i; |
65 |
root |
1.6 |
|
66 |
|
|
for (i = 0; i < sizeof (colorname) / sizeof (*colorname); i++) |
67 |
|
|
if (!strcmp (name, colorname[i])) |
68 |
elmex |
1.1 |
return i; |
69 |
root |
1.19 |
|
70 |
root |
1.6 |
LOG (llevError, "Unknown color: %s\n", name); |
71 |
elmex |
1.1 |
return 0; |
72 |
|
|
} |
73 |
|
|
|
74 |
root |
1.20 |
faceidx |
75 |
|
|
face_find (const char *name, faceidx defidx) |
76 |
elmex |
1.1 |
{ |
77 |
root |
1.22 |
if (!name) |
78 |
|
|
return defidx; |
79 |
|
|
|
80 |
root |
1.19 |
facehash_t::iterator i = facehash.find (name); |
81 |
root |
1.6 |
|
82 |
root |
1.19 |
return i == facehash.end () |
83 |
|
|
? defidx : i->second; |
84 |
elmex |
1.1 |
} |
85 |
|
|
|
86 |
root |
1.20 |
faceinfo * |
87 |
|
|
face_info (faceidx idx) |
88 |
root |
1.6 |
{ |
89 |
root |
1.21 |
assert (0 < (faceidx)-1); // faceidx must be unsigned |
90 |
|
|
|
91 |
root |
1.20 |
if (idx >= faces.size ()) |
92 |
|
|
return 0; |
93 |
elmex |
1.1 |
|
94 |
root |
1.20 |
return &faces [idx]; |
95 |
elmex |
1.1 |
} |
96 |
|
|
|
97 |
root |
1.20 |
facedata * |
98 |
root |
1.28 |
faceinfo::data (int faceset) const |
99 |
|
|
{ |
100 |
|
|
return (facedata *)&(faceset && !type && data64.data.size () ? data64 : data32); |
101 |
|
|
} |
102 |
|
|
|
103 |
|
|
facedata * |
104 |
root |
1.20 |
face_data (faceidx idx, int faceset) |
105 |
root |
1.6 |
{ |
106 |
root |
1.20 |
if (faceinfo *f = face_info (idx)) |
107 |
root |
1.28 |
return f->data (faceset); |
108 |
elmex |
1.1 |
|
109 |
root |
1.20 |
return 0; |
110 |
elmex |
1.1 |
} |
111 |
|
|
|