--- deliantra/server/common/recipe.C 2006/08/29 08:01:36 1.2 +++ deliantra/server/common/recipe.C 2006/09/03 14:33:48 1.4 @@ -29,9 +29,8 @@ static recipelist *formulalist; static recipelist *init_recipelist(void) { - recipelist *tl = (recipelist *) malloc(sizeof(recipelist)); - if(tl==NULL) - fatal(OUT_OF_MEMORY); + recipelist *tl = new recipelist; + tl->total_chance=0; tl->number=0; tl->items=NULL; @@ -40,9 +39,8 @@ } static recipe *get_empty_formula(void) { - recipe *t = (recipe *) malloc(sizeof(recipe)); - if(t==NULL) - fatal(OUT_OF_MEMORY); + recipe *t = new recipe; + t->chance = 0; t->index = 0; t->transmute = 0; @@ -85,11 +83,11 @@ if (find_archetype(rp->arch_name[i]) != NULL) { artifact *art = locate_recipe_artifact(rp, i); if (!art && strcmp(rp->title, "NONE") != 0) { - LOG(llevError,"\nWARNING: Formula %s of %s has no artifact.\n", rp->arch_name[i], rp->title); + LOG(llevError,"\nWARNING: Formula %s of %s has no artifact.\n", rp->arch_name[i], &rp->title); result = 0; } } else { - LOG(llevError,"\nWARNING: Can't find archetype %s for formula %s\n", rp->arch_name[i], rp->title); + LOG(llevError,"\nWARNING: Can't find archetype %s for formula %s\n", rp->arch_name[i], &rp->title); result = 0; } } @@ -134,9 +132,9 @@ if (!strncmp(cp, "Object", 6)) { formula=get_empty_formula(); - formula->title = add_string(strchr(cp,' ') + 1); + formula->title = strchr(cp,' ') + 1; } else if (!strncmp(cp, "keycode", 7)) { - formula->keycode = add_string(strchr(cp,' ') + 1); + formula->keycode = strchr (cp,' ') + 1; } else if (sscanf(cp, "trans %d", &value)) { formula->transmute = (uint16)value; } else if (sscanf(cp, "yield %d", &value)) { @@ -153,8 +151,8 @@ do { if ((next=strchr(cp,','))!=NULL) {*(next++) = '\0'; numb_ingred++;} - tmp = (linked_char*) malloc(sizeof(linked_char)); - tmp->name = add_string(cp); + tmp = new linked_char; + tmp->name = cp; tmp->next = formula->ingred; formula->ingred = tmp; /* each ingredient's ASCII value is coadded. Later on this @@ -177,11 +175,11 @@ fl->items = formula; } else if (!strncmp(cp, "arch",4)) { build_stringlist(strchr(cp, ' ')+1, &formula->arch_name, &formula->arch_names); - (void) check_recipe(formula); + check_recipe(formula); } else if (!strncmp(cp, "skill", 5)) { - formula->skill = add_string(strchr(cp, ' ')+1); + formula->skill = strchr(cp, ' ') + 1; } else if (!strncmp(cp, "cauldron", 8)) { - formula->cauldron = add_string(strchr(cp, ' ')+1); + formula->cauldron = strchr(cp, ' ') + 1; } else LOG(llevError,"Unknown input in file %s: %s\n", filename, buf); } @@ -211,7 +209,7 @@ if(check->index==formula->index) { LOG(llevError," ERROR: On %d ingred list: ", numb); LOG(llevError, "Formulae [%s] of %s and [%s] of %s have matching index id (%d)\n", - formula->arch_name[0],formula->title,check->arch_name[0],check->title,formula->index); + formula->arch_name[0],&formula->title,check->arch_name[0],&check->title,formula->index); } numb++; } @@ -242,37 +240,37 @@ if(find_archetype(string)!=NULL) { art = locate_recipe_artifact(formula, i); if (!art && strcmp(formula->title,"NONE")) - LOG(llevError,"Formula %s has no artifact\n",formula->title); + LOG(llevError,"Formula %s has no artifact\n",&formula->title); else { if(strcmp(formula->title,"NONE")) - sprintf(buf,"%s of %s",string,formula->title); + sprintf(buf,"%s of %s",string,&formula->title); else sprintf(buf,"%s",string); fprintf(logfile,"%-30s(%d) bookchance %3d ",buf,formula->index, formula->chance); - fprintf(logfile,"skill %s",formula->skill); + fprintf(logfile,"skill %s",&formula->skill); fprintf(logfile,"\n"); if (formula->ingred !=NULL) { int nval=0,tval=0; fprintf(logfile,"\tIngred: "); for (next=formula->ingred; next!=NULL; next=next->next) { if(nval!=0) fprintf(logfile,","); - fprintf(logfile,"%s(%d)",next->name,(nval=strtoint(next->name))); + fprintf(logfile,"%s(%d)",&next->name,(nval=strtoint(next->name))); tval += nval; } fprintf(logfile,"\n"); if(tval!=formula->index) fprintf(logfile, "WARNING:ingredient list and formula values not equal.\n"); } if (formula->skill != NULL) - fprintf(logfile, "\tSkill Required: %s", formula->skill); + fprintf(logfile, "\tSkill Required: %s", &formula->skill); if (formula->cauldron != NULL) - fprintf(logfile, "\tCauldron: %s\n", formula->cauldron); + fprintf(logfile, "\tCauldron: %s\n", &formula->cauldron); fprintf(logfile, "\tDifficulty: %d\t Exp: %d\n", formula->diff, formula->exp); } } else LOG(llevError,"Can't find archetype:%s for formula %s\n", string, - formula->title); + &formula->title); } } fprintf(logfile,"\n"); @@ -358,7 +356,7 @@ if (at->clone.title != NULL) { /* inefficient, but who cares? */ - sprintf (part1, "%s %s", at->clone.name, at->clone.title); + sprintf (part1, "%s %s", &at->clone.name, &at->clone.title); if (! strcasecmp (part1, name)) return mult * at->clone.value; } @@ -438,15 +436,15 @@ if ((at = find_archetype (string)) != NULL) { art = locate_recipe_artifact (formula, i); if (!art && strcmp (formula->title,"NONE")) - LOG (llevError, "Formula %s has no artifact\n", formula->title); + LOG (llevError, "Formula %s has no artifact\n", &formula->title); else { if (! strcmp (formula->title, "NONE")) sprintf (buf, "%s", string); else - sprintf (buf, "%s of %s", string, formula->title); + sprintf (buf, "%s of %s", string, &formula->title); fprintf (logfile, "\n%-40s bookchance %3d skill %s\n", - buf, formula->chance, formula->skill); + buf, formula->chance, &(formula->skill)); if (formula->ingred !=NULL) { tcost = 0; @@ -455,7 +453,7 @@ cost = find_ingred_cost (next->name); if (cost < 0) num_errors++; - fprintf (logfile,"\t%-33s%5ld\n", next->name, cost); + fprintf (logfile,"\t%-33s%5ld\n", &next->name, cost); if (cost < 0 || tcost < 0) tcost = -1; else @@ -490,7 +488,7 @@ } else LOG(llevError, "Can't find archetype:%s for formula %s\n", string, - formula->title); + &formula->title); } } fprintf (logfile,"\n"); @@ -602,22 +600,17 @@ for (formula=fl->items; formula!=NULL; formula=next) { next=formula->next; - free(formula->arch_name[0]); - free(formula->arch_name); - if (formula->title) - free_string(formula->title); - if (formula->skill) - free_string(formula->skill); - if (formula->cauldron) - free_string(formula->cauldron); + free (formula->arch_name [0]); + free (formula->arch_name); + for (lchar=formula->ingred; lchar; lchar=charnext) { charnext=lchar->next; - free_string(lchar->name); - free(lchar); + delete lchar; } - free(formula); + delete formula; } - free(fl); + + delete fl; } } @@ -648,8 +641,7 @@ size++; *result_list = (char **) malloc(size*sizeof(*result_list)); - if (*result_list == NULL) - fatal(OUT_OF_MEMORY); + *result_size = size; for (i = 0; i < size; i++) { @@ -657,3 +649,4 @@ dup = dup+strlen(dup)+1; } } +