1 | |
|
|
2 | /* |
|
|
3 | * static char *rcsid_arch_c = |
|
|
4 | * "$Id: arch.C,v 1.15 2006/09/10 13:20:12 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 HT |
63 | static HT ht; |
65 | ht; |
|
|
66 | #endif |
64 | #endif |
67 | |
65 | |
68 | /** |
66 | /** |
69 | * GROS - This function retrieves an archetype given the name that appears |
67 | * GROS - This function retrieves an archetype given the name that appears |
70 | * during the game (for example, "writing pen" instead of "stylus"). |
68 | * during the game (for example, "writing pen" instead of "stylus"). |
… | |
… | |
172 | * but it otherwise had a big memory leak. |
170 | * but it otherwise had a big memory leak. |
173 | */ |
171 | */ |
174 | object * |
172 | object * |
175 | get_archetype_by_object_name (const char *name) |
173 | get_archetype_by_object_name (const char *name) |
176 | { |
174 | { |
177 | archetype * |
175 | archetype *at; |
178 | at; |
|
|
179 | char |
|
|
180 | tmpname[MAX_BUF]; |
176 | char tmpname[MAX_BUF]; |
181 | int |
177 | int i; |
182 | i; |
|
|
183 | |
178 | |
184 | strncpy (tmpname, name, MAX_BUF - 1); |
179 | assign (tmpname, name); |
185 | tmpname[MAX_BUF - 1] = 0; |
180 | |
186 | for (i = strlen (tmpname); i > 0; i--) |
181 | for (i = strlen (tmpname); i > 0; i--) |
187 | { |
182 | { |
188 | tmpname[i] = 0; |
183 | tmpname[i] = 0; |
189 | at = find_archetype_by_object_name (tmpname); |
184 | at = find_archetype_by_object_name (tmpname); |
|
|
185 | |
190 | if (at != NULL) |
186 | if (at != NULL) |
191 | { |
187 | { |
192 | return arch_to_object (at); |
188 | return arch_to_object (at); |
193 | } |
189 | } |
194 | } |
190 | } |
|
|
191 | |
195 | return create_singularity (name); |
192 | return create_singularity (name); |
196 | } |
193 | } |
197 | |
194 | |
198 | /* 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 |
199 | * a string seperated lists of things to match, with certain keywords. |
196 | * a string seperated lists of things to match, with certain keywords. |
… | |
… | |
423 | if (at->more) |
420 | if (at->more) |
424 | next = at->more; |
421 | next = at->more; |
425 | else |
422 | else |
426 | next = at->next; |
423 | next = at->next; |
427 | |
424 | |
428 | delete at; |
425 | delete |
|
|
426 | at; |
|
|
427 | |
429 | i++; |
428 | i++; |
430 | } |
429 | } |
431 | LOG (llevDebug, "Freed %d archetypes, %d faces\n", i, f); |
430 | LOG (llevDebug, "Freed %d archetypes, %d faces\n", i, f); |
432 | } |
431 | } |
433 | |
432 | |
… | |
… | |
517 | at = new archetype; |
516 | at = new archetype; |
518 | |
517 | |
519 | at->clone.arch = at; |
518 | at->clone.arch = at; |
520 | } |
519 | } |
521 | |
520 | |
522 | delete |
521 | delete at; |
523 | at; |
|
|
524 | } |
522 | } |
525 | |
523 | |
526 | /* |
524 | /* |
527 | * Reads the archetype file once more, and links all pointers between |
525 | * Reads the archetype file once more, and links all pointers between |
528 | * archetypes. |
526 | * archetypes. |
… | |
… | |
616 | |
614 | |
617 | sprintf (filename, "%s/%s", settings.datadir, settings.archetypes); |
615 | sprintf (filename, "%s/%s", settings.datadir, settings.archetypes); |
618 | LOG (llevDebug, "Reading archetypes from %s:\n", filename); |
616 | LOG (llevDebug, "Reading archetypes from %s:\n", filename); |
619 | |
617 | |
620 | { |
618 | { |
|
|
619 | object_thawer |
621 | object_thawer thawer (filename); |
620 | thawer (filename); |
622 | |
621 | |
623 | clear_archetable (); |
622 | clear_archetable (); |
624 | LOG (llevDebug, " arch-pass 1...\n"); |
623 | LOG (llevDebug, " arch-pass 1...\n"); |
625 | first_arch_pass (thawer); |
624 | first_arch_pass (thawer); |
626 | LOG (llevDebug, " done\n"); |
625 | LOG (llevDebug, " done\n"); |
… | |
… | |
628 | |
627 | |
629 | init_archetable (); |
628 | init_archetable (); |
630 | warn_archetypes = 1; |
629 | warn_archetypes = 1; |
631 | |
630 | |
632 | { |
631 | { |
|
|
632 | object_thawer |
633 | object_thawer thawer (filename); |
633 | thawer (filename); |
634 | |
634 | |
635 | LOG (llevDebug, " loading treasure...\n"); |
635 | LOG (llevDebug, " loading treasure...\n"); |
636 | load_treasures (); |
636 | load_treasures (); |
637 | LOG (llevDebug, " done\n arch-pass 2...\n"); |
637 | LOG (llevDebug, " done\n arch-pass 2...\n"); |
638 | second_arch_pass (thawer); |
638 | second_arch_pass (thawer); |