--- deliantra/server/common/arch.C 2006/09/12 20:55:40 1.18 +++ deliantra/server/common/arch.C 2006/09/14 21:16:11 1.20 @@ -77,8 +77,7 @@ archetype * find_archetype_by_object_name (const char *name) { - archetype * - at; + archetype *at; if (name == NULL) return (archetype *) NULL; @@ -99,8 +98,7 @@ archetype * find_archetype_by_object_type_name (int type, const char *name) { - archetype * - at; + archetype *at; if (name == NULL) return NULL; @@ -184,9 +182,7 @@ at = find_archetype_by_object_name (tmpname); if (at != NULL) - { - return arch_to_object (at); - } + return arch_to_object (at); } return create_singularity (name); @@ -329,10 +325,11 @@ { /* called from add_player() and edit() */ if (first_archetype != NULL) /* Only do this once */ return; + arch_init = 1; load_archetypes (); arch_init = 0; - empty_archetype = find_archetype ("empty_archetype"); + empty_archetype = archetype::find ("empty_archetype"); /* init_blocksview();*/ } @@ -551,14 +548,14 @@ } if (!strcmp ("Object", variable)) { - if ((at = find_archetype (argument)) == NULL) + if ((at = archetype::find (argument)) == NULL) LOG (llevError, "Warning: failed to find arch %s\n", argument); } else if (!strcmp ("other_arch", variable)) { if (at != NULL && at->clone.other_arch == NULL) { - if ((other = find_archetype (argument)) == NULL) + if ((other = archetype::find (argument)) == NULL) LOG (llevError, "Warning: failed to find other_arch %s\n", argument); else if (at != NULL) at->clone.other_arch = other; @@ -680,10 +677,8 @@ object * create_singularity (const char *name) { - object * - op; - char - buf[MAX_BUF]; + object * op; + char buf[MAX_BUF]; sprintf (buf, "%s (%s)", ARCH_SINGULARITY, name); op = get_object (); @@ -700,11 +695,9 @@ object * get_archetype (const char *name) { - archetype * - at; + archetype *at = archetype::find (name); - at = find_archetype (name); - if (at == NULL) + if (!at) return create_singularity (name); return arch_to_object (at); @@ -717,12 +710,9 @@ unsigned long hasharch (const char *str, int tablesize) { - unsigned long - hash = 0; - unsigned int - i = 0; - const char * - p; + unsigned long hash = 0; + unsigned int i = 0; + const char *p; /* use the one-at-a-time hash function, which supposedly is * better than the djb2-like one used by perl5.005, but @@ -749,15 +739,13 @@ */ archetype * -find_archetype (const char *name) +archetype::find (const char *name) { -#if USE_UNORDERED_MAP - name = shstr::find (name); - if (!name) return 0; - HT::const_iterator i = ht.find ((size_t) name); +#if USE_UNORDERED_MAP + AUTODECL (i, ht.find ((size_t) name)); if (i == ht.end ()) return 0; @@ -765,28 +753,28 @@ return i->second; #endif - archetype * - at; - unsigned long - index; - - if (name == NULL) - return (archetype *) NULL; + archetype *at; + unsigned long index; index = hasharch (name, ARCHTABLE); arch_search++; for (;;) { at = arch_table[index]; + if (at == NULL) { if (warn_archetypes) LOG (llevError, "Couldn't find archetype %s\n", name); + return NULL; } + arch_cmp++; + if (!strcmp ((const char *) at->name, name)) return at; + if (++index >= ARCHTABLE) index = 0; } @@ -803,8 +791,7 @@ ht.insert (std::make_pair ((size_t) (const char *) at->name, at)); #endif - int - index = hasharch ((const char *) at->name, ARCHTABLE), org_index = index; + int index = hasharch ((const char *) at->name, ARCHTABLE), org_index = index; for (;;) { @@ -830,13 +817,13 @@ archetype * type_to_archetype (int type) { - archetype * - at; + archetype *at; - for (at = first_archetype; at != NULL; at = (at->more == NULL) ? at->next : at->more) + for (at = first_archetype; at; at = at->more == 0 ? at->next : at->more) if (at->clone.type == type) return at; - return NULL; + + return 0; } /* @@ -848,10 +835,8 @@ object * clone_arch (int type) { - archetype * - at; - object * - op = get_object (); + archetype *at; + object *op = get_object (); if ((at = type_to_archetype (type)) == NULL) { @@ -859,6 +844,7 @@ free_object (op); return NULL; } + copy_object (&at->clone, op); op->instantiate (); return op; @@ -871,23 +857,24 @@ object * object_create_arch (archetype *at) { - object * - op, * - prev = NULL, *head = NULL; + object *op, *prev = 0, *head = 0; while (at) { op = arch_to_object (at); op->x = at->clone.x; op->y = at->clone.y; + if (head) op->head = head, prev->more = op; + if (!head) head = op; + prev = op; at = at->more; } + return (head); } -/*** end of arch.c ***/