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 |
… | |
… | |
59 | typedef |
53 | typedef |
60 | std::tr1::unordered_map < |
54 | std::tr1::unordered_map < |
61 | size_t, archetype *> |
55 | size_t, archetype *> |
62 | HT; |
56 | HT; |
63 | |
57 | |
64 | static HT |
58 | static |
|
|
59 | HT |
65 | ht; |
60 | ht; |
66 | #endif |
61 | #endif |
67 | |
62 | |
68 | /** |
63 | /** |
69 | * GROS - This function retrieves an archetype given the name that appears |
64 | * GROS - This function retrieves an archetype given the name that appears |
… | |
… | |
172 | * but it otherwise had a big memory leak. |
167 | * but it otherwise had a big memory leak. |
173 | */ |
168 | */ |
174 | object * |
169 | object * |
175 | get_archetype_by_object_name (const char *name) |
170 | get_archetype_by_object_name (const char *name) |
176 | { |
171 | { |
177 | archetype * |
172 | archetype *at; |
178 | at; |
|
|
179 | char |
|
|
180 | tmpname[MAX_BUF]; |
173 | char tmpname[MAX_BUF]; |
181 | int |
174 | int i; |
182 | i; |
|
|
183 | |
175 | |
184 | strncpy (tmpname, name, MAX_BUF - 1); |
176 | assign (tmpname, name); |
185 | tmpname[MAX_BUF - 1] = 0; |
177 | |
186 | for (i = strlen (tmpname); i > 0; i--) |
178 | for (i = strlen (tmpname); i > 0; i--) |
187 | { |
179 | { |
188 | tmpname[i] = 0; |
180 | tmpname[i] = 0; |
189 | at = find_archetype_by_object_name (tmpname); |
181 | at = find_archetype_by_object_name (tmpname); |
|
|
182 | |
190 | if (at != NULL) |
183 | if (at != NULL) |
191 | { |
184 | { |
192 | return arch_to_object (at); |
185 | return arch_to_object (at); |
193 | } |
186 | } |
194 | } |
187 | } |
|
|
188 | |
195 | return create_singularity (name); |
189 | return create_singularity (name); |
196 | } |
190 | } |
197 | |
191 | |
198 | /* This is a subset of the parse_id command. Basically, name can be |
192 | /* 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. |
193 | * a string seperated lists of things to match, with certain keywords. |
… | |
… | |
423 | if (at->more) |
417 | if (at->more) |
424 | next = at->more; |
418 | next = at->more; |
425 | else |
419 | else |
426 | next = at->next; |
420 | next = at->next; |
427 | |
421 | |
428 | delete at; |
422 | delete |
|
|
423 | at; |
|
|
424 | |
429 | i++; |
425 | i++; |
430 | } |
426 | } |
431 | LOG (llevDebug, "Freed %d archetypes, %d faces\n", i, f); |
427 | LOG (llevDebug, "Freed %d archetypes, %d faces\n", i, f); |
432 | } |
428 | } |
433 | |
429 | |
… | |
… | |
517 | at = new archetype; |
513 | at = new archetype; |
518 | |
514 | |
519 | at->clone.arch = at; |
515 | at->clone.arch = at; |
520 | } |
516 | } |
521 | |
517 | |
522 | delete |
518 | delete at; |
523 | at; |
|
|
524 | } |
519 | } |
525 | |
520 | |
526 | /* |
521 | /* |
527 | * Reads the archetype file once more, and links all pointers between |
522 | * Reads the archetype file once more, and links all pointers between |
528 | * archetypes. |
523 | * archetypes. |
… | |
… | |
616 | |
611 | |
617 | sprintf (filename, "%s/%s", settings.datadir, settings.archetypes); |
612 | sprintf (filename, "%s/%s", settings.datadir, settings.archetypes); |
618 | LOG (llevDebug, "Reading archetypes from %s:\n", filename); |
613 | LOG (llevDebug, "Reading archetypes from %s:\n", filename); |
619 | |
614 | |
620 | { |
615 | { |
|
|
616 | object_thawer |
621 | object_thawer thawer (filename); |
617 | thawer (filename); |
622 | |
618 | |
623 | clear_archetable (); |
619 | clear_archetable (); |
624 | LOG (llevDebug, " arch-pass 1...\n"); |
620 | LOG (llevDebug, " arch-pass 1...\n"); |
625 | first_arch_pass (thawer); |
621 | first_arch_pass (thawer); |
626 | LOG (llevDebug, " done\n"); |
622 | LOG (llevDebug, " done\n"); |
… | |
… | |
628 | |
624 | |
629 | init_archetable (); |
625 | init_archetable (); |
630 | warn_archetypes = 1; |
626 | warn_archetypes = 1; |
631 | |
627 | |
632 | { |
628 | { |
|
|
629 | object_thawer |
633 | object_thawer thawer (filename); |
630 | thawer (filename); |
634 | |
631 | |
635 | LOG (llevDebug, " loading treasure...\n"); |
632 | LOG (llevDebug, " loading treasure...\n"); |
636 | load_treasures (); |
633 | load_treasures (); |
637 | LOG (llevDebug, " done\n arch-pass 2...\n"); |
634 | LOG (llevDebug, " done\n arch-pass 2...\n"); |
638 | second_arch_pass (thawer); |
635 | second_arch_pass (thawer); |