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