--- deliantra/server/common/recipe.C 2006/08/29 08:01:36 1.2 +++ deliantra/server/common/recipe.C 2006/09/03 00:18:40 1.3 @@ -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; @@ -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); } @@ -257,7 +255,7 @@ 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"); @@ -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; } @@ -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 @@ -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; } } +