--- deliantra/server/common/arch.C 2006/08/30 11:02:15 1.9 +++ deliantra/server/common/arch.C 2006/09/03 00:18:39 1.10 @@ -1,6 +1,6 @@ /* * static char *rcsid_arch_c = - * "$Id: arch.C,v 1.9 2006/08/30 11:02:15 root Exp $"; + * "$Id: arch.C,v 1.10 2006/09/03 00:18:39 root Exp $"; */ /* @@ -337,14 +337,8 @@ for (at=first_archetype; at!=NULL; at=next) { if (at->more) next=at->more; else next=at->next; - if (at->name) free_string(at->name); - if (at->clone.name) free_string(at->clone.name); - if (at->clone.name_pl) free_string(at->clone.name_pl); - if (at->clone.title) free_string(at->clone.title); - if (at->clone.race) free_string(at->clone.race); - if (at->clone.slaying) free_string(at->clone.slaying); - if (at->clone.msg) free_string(at->clone.msg); - free(at); + + delete at; i++; } LOG(llevDebug,"Freed %d archetypes, %d faces\n", i, f); @@ -353,27 +347,16 @@ /* * Allocates, initialises and returns the pointer to an archetype structure. */ - +// TODO: should become constructor archetype *get_archetype_struct(void) { archetype *arch; - arch=(archetype *)CALLOC(1,sizeof(archetype)); - if(arch==NULL) - fatal(OUT_OF_MEMORY); - arch->next=NULL; - arch->name=NULL; - arch->clone.other_arch=NULL; - arch->clone.name=NULL; - arch->clone.name_pl=NULL; - arch->clone.title=NULL; - arch->clone.race=NULL; - arch->clone.slaying=NULL; - arch->clone.msg=NULL; - clear_object(&arch->clone); /* to initial state other also */ - CLEAR_FLAG((&arch->clone),FLAG_FREED); /* This shouldn't matter, since copy_object() */ - SET_FLAG((&arch->clone), FLAG_REMOVED); /* doesn't copy these flags... */ - arch->head=NULL; - arch->more=NULL; + arch = new archetype; + + clear_object (&arch->clone); /* to initial state other also */ + CLEAR_FLAG (&arch->clone, FLAG_FREED); /* This shouldn't matter, since copy_object() */ + SET_FLAG (&arch->clone, FLAG_REMOVED); /* doesn't copy these flags... */ + return arch; } @@ -446,7 +429,8 @@ clear_object(op); op->arch=at; } - free(at); + + delete at; free_object(op); } @@ -484,7 +468,7 @@ if(at!=NULL) { treasurelist *tl=find_treasurelist(argument); if(tl==NULL) - LOG(llevError,"Failed to link treasure to arch (%s): %s\n",at->name, argument); + LOG(llevError,"Failed to link treasure to arch (%s): %s\n", &at->name, argument); else at->clone.randomitems=tl; } @@ -497,8 +481,7 @@ archetype *at; for(at=first_archetype;at!=NULL;at=at->next) if(QUERY_FLAG(&at->clone,FLAG_GENERATOR)&&at->clone.other_arch==NULL) - LOG(llevError,"Warning: %s is generator but lacks other_arch.\n", - at->name); + LOG(llevError,"Warning: %s is generator but lacks other_arch.\n", &at->name); } #endif @@ -579,8 +562,7 @@ char buf[MAX_BUF]; sprintf(buf,"%s (%s)",ARCH_SINGULARITY,name); op = get_object(); - op->name = add_string(buf); - op->name_pl = add_string(buf); + op->name = op->name_pl = buf; SET_FLAG(op,FLAG_NO_PICK); return op; } @@ -603,25 +585,29 @@ */ unsigned long -hasharch(const char *str, int tablesize) { - unsigned long hash = 0; - 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 - * certainly is better then the bug used here before. - * see http://burtleburtle.net/bob/hash/doobs.html - */ - for (p = str; i < MAXSTRING && *p; p++, i++) { - hash += *p; - hash += hash << 10; - hash ^= hash >> 6; - } - hash += hash << 3; - hash ^= hash >> 11; - hash += hash << 15; - return hash % tablesize; +hasharch(const char *str, int tablesize) +{ + 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 + * certainly is better then the bug used here before. + * see http://burtleburtle.net/bob/hash/doobs.html + */ + for (p = str; i < MAXSTRING && *p; p++, i++) + { + hash += *p; + hash += hash << 10; + hash ^= hash >> 6; + } + + hash += hash << 3; + hash ^= hash >> 11; + hash += hash << 15; + + return hash % tablesize; } /* @@ -646,7 +632,7 @@ return NULL; } arch_cmp++; - if (!strcmp(at->name,name)) + if (!strcmp((const char *)at->name,name)) return at; if(++index>=ARCHTABLE) index=0; @@ -658,7 +644,7 @@ */ static void add_arch(archetype *at) { - int index=hasharch(at->name, ARCHTABLE),org_index=index; + int index=hasharch((const char *)at->name, ARCHTABLE),org_index=index; for(;;) { if(arch_table[index]==NULL) { arch_table[index]=at;