1 | |
|
|
2 | /* |
|
|
3 | * static char *rcsid_arch_c = |
|
|
4 | * "$Id: arch.C,v 1.16 2006/09/10 16:00:23 root Exp $"; |
|
|
5 | */ |
|
|
6 | |
|
|
7 | /* |
1 | /* |
8 | CrossFire, A Multiplayer game for X-windows |
2 | CrossFire, A Multiplayer game for X-windows |
9 | |
3 | |
10 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
11 | Copyright (C) 1992 Frank Tore Johansen |
5 | Copyright (C) 1992 Frank Tore Johansen |
… | |
… | |
54 | * MSW 2003-04-29 |
48 | * MSW 2003-04-29 |
55 | */ |
49 | */ |
56 | |
50 | |
57 | #if USE_UNORDERED_MAP |
51 | #if USE_UNORDERED_MAP |
58 | // the hashtable |
52 | // the hashtable |
59 | typedef |
|
|
60 | std::tr1::unordered_map < |
53 | typedef std::tr1::unordered_map |
61 | size_t, archetype *> |
54 | < |
|
|
55 | std::size_t, |
|
|
56 | archetype *, |
|
|
57 | std::hash<size_t>, |
|
|
58 | std::equal_to<size_t>, |
|
|
59 | slice_allocator< std::pair<const std::size_t, archetype *> > |
|
|
60 | true, |
62 | HT; |
61 | > HT; |
63 | |
62 | |
64 | static |
63 | static HT ht; |
65 | HT |
|
|
66 | ht; |
|
|
67 | #endif |
64 | #endif |
68 | |
65 | |
69 | /** |
66 | /** |
70 | * GROS - This function retrieves an archetype given the name that appears |
67 | * GROS - This function retrieves an archetype given the name that appears |
71 | * during the game (for example, "writing pen" instead of "stylus"). |
68 | * during the game (for example, "writing pen" instead of "stylus"). |
… | |
… | |
173 | * but it otherwise had a big memory leak. |
170 | * but it otherwise had a big memory leak. |
174 | */ |
171 | */ |
175 | object * |
172 | object * |
176 | get_archetype_by_object_name (const char *name) |
173 | get_archetype_by_object_name (const char *name) |
177 | { |
174 | { |
178 | archetype * |
175 | archetype *at; |
179 | at; |
|
|
180 | char |
|
|
181 | tmpname[MAX_BUF]; |
176 | char tmpname[MAX_BUF]; |
182 | int |
177 | int i; |
183 | i; |
|
|
184 | |
178 | |
185 | strncpy (tmpname, name, MAX_BUF - 1); |
179 | assign (tmpname, name); |
186 | tmpname[MAX_BUF - 1] = 0; |
180 | |
187 | for (i = strlen (tmpname); i > 0; i--) |
181 | for (i = strlen (tmpname); i > 0; i--) |
188 | { |
182 | { |
189 | tmpname[i] = 0; |
183 | tmpname[i] = 0; |
190 | at = find_archetype_by_object_name (tmpname); |
184 | at = find_archetype_by_object_name (tmpname); |
|
|
185 | |
191 | if (at != NULL) |
186 | if (at != NULL) |
192 | { |
187 | { |
193 | return arch_to_object (at); |
188 | return arch_to_object (at); |
194 | } |
189 | } |
195 | } |
190 | } |
|
|
191 | |
196 | return create_singularity (name); |
192 | return create_singularity (name); |
197 | } |
193 | } |
198 | |
194 | |
199 | /* This is a subset of the parse_id command. Basically, name can be |
195 | /* This is a subset of the parse_id command. Basically, name can be |
200 | * a string seperated lists of things to match, with certain keywords. |
196 | * a string seperated lists of things to match, with certain keywords. |