--- deliantra/server/common/recipe.C 2006/08/13 17:16:00 1.1 +++ deliantra/server/common/recipe.C 2006/08/29 08:01:36 1.2 @@ -140,13 +140,13 @@ } else if (sscanf(cp, "trans %d", &value)) { formula->transmute = (uint16)value; } else if (sscanf(cp, "yield %d", &value)) { - formula->yield = (uint16)value; + formula->yield = (uint16)value; } else if (sscanf(cp, "chance %d", &value)) { formula->chance = (uint16)value; } else if (sscanf(cp, "exp %d", &value)) { - formula->exp = (uint16)value; + formula->exp = (uint16)value; } else if (sscanf(cp, "diff %d", &value)) { - formula->diff = (uint16)value; + formula->diff = (uint16)value; } else if (!strncmp(cp, "ingred",6)) { int numb_ingred = 1; cp = strchr(cp,' ') + 1; @@ -157,18 +157,18 @@ tmp->name = add_string(cp); tmp->next = formula->ingred; formula->ingred = tmp; - /* each ingredient's ASCII value is coadded. Later on this + /* each ingredient's ASCII value is coadded. Later on this * value will be used allow us to search the formula lists - * quickly for the right recipe. - */ - formula->index += strtoint(cp); + * quickly for the right recipe. + */ + formula->index += strtoint(cp); } while ((cp=next)!=NULL); /* now find the correct (# of ingred ordered) formulalist */ fl=formulalist; while(numb_ingred!=1) { - if(!fl->next) - fl->next = init_recipelist(); - fl = fl->next; + if(!fl->next) + fl->next = init_recipelist(); + fl = fl->next; numb_ingred--; } fl->total_chance += formula->chance; @@ -179,9 +179,9 @@ build_stringlist(strchr(cp, ' ')+1, &formula->arch_name, &formula->arch_names); (void) check_recipe(formula); } else if (!strncmp(cp, "skill", 5)) { - formula->skill = add_string(strchr(cp, ' ')+1); + formula->skill = add_string(strchr(cp, ' ')+1); } else if (!strncmp(cp, "cauldron", 8)) { - formula->cauldron = add_string(strchr(cp, ' ')+1); + formula->cauldron = add_string(strchr(cp, ' ')+1); } else LOG(llevError,"Unknown input in file %s: %s\n", filename, buf); } @@ -231,7 +231,7 @@ fprintf(logfile, "\n"); while(fl) { fprintf(logfile, "\n Formulae with %d ingredient%s %d Formulae with total_chance=%d\n", - num_ingred, num_ingred>1?"s.":".",fl->number,fl->total_chance); + num_ingred, num_ingred>1?"s.":".",fl->number,fl->total_chance); for (formula=fl->items; formula!=NULL; formula=formula->next) { artifact *art=NULL; char buf[MAX_BUF]; @@ -239,40 +239,40 @@ for (i = 0; i < formula->arch_names; i++) { const char *string = formula->arch_name[i]; - if(find_archetype(string)!=NULL) { + 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); - else { - if(strcmp(formula->title,"NONE")) + LOG(llevError,"Formula %s has no artifact\n",formula->title); + else { + if(strcmp(formula->title,"NONE")) sprintf(buf,"%s of %s",string,formula->title); - else + else sprintf(buf,"%s",string); fprintf(logfile,"%-30s(%d) bookchance %3d ",buf,formula->index, - formula->chance); + formula->chance); fprintf(logfile,"skill %s",formula->skill); fprintf(logfile,"\n"); if (formula->ingred !=NULL) { - int nval=0,tval=0; + int nval=0,tval=0; fprintf(logfile,"\tIngred: "); for (next=formula->ingred; next!=NULL; next=next->next) { - if(nval!=0) fprintf(logfile,","); + if(nval!=0) fprintf(logfile,","); fprintf(logfile,"%s(%d)",next->name,(nval=strtoint(next->name))); - tval += nval; - } + tval += nval; + } fprintf(logfile,"\n"); - if(tval!=formula->index) fprintf(logfile, "WARNING:ingredient list and formula values not equal.\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); - if (formula->cauldron != NULL) - 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); + if (formula->skill != NULL) + fprintf(logfile, "\tSkill Required: %s", formula->skill); + if (formula->cauldron != NULL) + 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); } } fprintf(logfile,"\n"); @@ -294,29 +294,29 @@ while (t != NULL) { if (t->name != NULL) - { - tl = find_treasurelist (t->name); - at = find_treasure_by_name (tl->items, name, depth + 1); - if (at != NULL) - return at; - } + { + tl = find_treasurelist (t->name); + at = find_treasure_by_name (tl->items, name, depth + 1); + if (at != NULL) + return at; + } else - { - if (! strcasecmp (t->item->clone.name, name)) - return t->item; - } + { + if (! strcasecmp (t->item->clone.name, name)) + return t->item; + } if (t->next_yes != NULL) - { - at = find_treasure_by_name (t->next_yes, name, depth); - if (at != NULL) - return at; - } + { + at = find_treasure_by_name (t->next_yes, name, depth); + if (at != NULL) + return at; + } if (t->next_no != NULL) - { - at = find_treasure_by_name (t->next_no, name, depth); - if (at != NULL) - return at; - } + { + at = find_treasure_by_name (t->next_no, name, depth); + if (at != NULL) + return at; + } t = t->next; } return NULL; @@ -356,14 +356,14 @@ for (at = first_archetype; at != NULL; at = at->next) { if (at->clone.title != NULL) - { - /* inefficient, but who cares? */ - sprintf (part1, "%s %s", at->clone.name, at->clone.title); - if (! strcasecmp (part1, name)) - return mult * at->clone.value; - } + { + /* inefficient, but who cares? */ + sprintf (part1, "%s %s", at->clone.name, at->clone.title); + if (! strcasecmp (part1, name)) + return mult * at->clone.value; + } if (! strcasecmp (at->clone.name, name)) - return mult * at->clone.value; + return mult * at->clone.value; } /* second, try to match an artifact ("arch of something") */ cp = strstr (name, " of "); @@ -374,19 +374,19 @@ strcpy (part2, cp + 4); /* find the first archetype matching the first part of the name */ for (at = first_archetype; at != NULL; at = at->next) - if (! strcasecmp (at->clone.name, part1) && at->clone.title == NULL) - break; + if (! strcasecmp (at->clone.name, part1) && at->clone.title == NULL) + break; if (at != NULL) - { - /* find the first artifact derived from that archetype (same type) */ - for (al = first_artifactlist; al != NULL; al = al->next) - if (al->type == at->clone.type) - { - for (art = al->items; art != NULL; art = art->next) - if (! strcasecmp (art->item->name, part2)) - return mult * at->clone.value * art->item->value; - } - } + { + /* find the first artifact derived from that archetype (same type) */ + for (al = first_artifactlist; al != NULL; al = al->next) + if (al->type == at->clone.type) + { + for (art = al->items; art != NULL; art = art->next) + if (! strcasecmp (art->item->name, part2)) + return mult * at->clone.value * art->item->value; + } + } } /* third, try to match a body part ("arch's something") */ cp = strstr (name, "'s "); @@ -397,16 +397,16 @@ strcpy (part2, cp + 3); /* examine all archetypes matching the first part of the name */ for (at = first_archetype; at != NULL; at = at->next) - if (! strcasecmp (at->clone.name, part1) && at->clone.title == NULL) - { - if (at->clone.randomitems != NULL) - { - at2 = find_treasure_by_name (at->clone.randomitems->items, - part2, 0); - if (at2 != NULL) - return mult * at2->clone.value * isqrt (at->clone.level * 2); - } - } + if (! strcasecmp (at->clone.name, part1) && at->clone.title == NULL) + { + if (at->clone.randomitems != NULL) + { + at2 = find_treasure_by_name (at->clone.randomitems->items, + part2, 0); + if (at2 != NULL) + return mult * at2->clone.value * isqrt (at->clone.level * 2); + } + } } /* failed to find any matching items -- formula should be checked */ return -1; @@ -426,7 +426,7 @@ fprintf (logfile, "\n"); while (fl) { fprintf(logfile, "\n Formulae with %d ingredient%s %d Formulae with total_chance=%d\n", - num_ingred, num_ingred>1?"s.":".",fl->number,fl->total_chance); + num_ingred, num_ingred>1?"s.":".",fl->number,fl->total_chance); for (formula = fl->items; formula != NULL; formula = formula->next) { artifact *art=NULL; archetype *at=NULL; @@ -435,62 +435,62 @@ for (i = 0; i < formula->arch_names; i++) { const char *string = formula->arch_name[i]; - if ((at = find_archetype (string)) != NULL) { + 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); - else - { - if (! strcmp (formula->title, "NONE")) - sprintf (buf, "%s", string); - else - sprintf (buf, "%s of %s", string, formula->title); - fprintf (logfile, "\n%-40s bookchance %3d skill %s\n", - buf, formula->chance, formula->skill); - if (formula->ingred !=NULL) - { - tcost = 0; - for (next = formula->ingred; next != NULL; next = next->next) - { - cost = find_ingred_cost (next->name); - if (cost < 0) - num_errors++; - fprintf (logfile,"\t%-33s%5ld\n", next->name, cost); - if (cost < 0 || tcost < 0) - tcost = -1; - else - tcost += cost; - } - if (art != NULL && art->item != NULL) - cost = at->clone.value * art->item->value; - else - cost = at->clone.value; - fprintf (logfile, "\t\tBuying result costs: %5ld", cost); - if (formula->yield > 1) - { - fprintf (logfile, " to %ld (max %d items)\n", - cost * formula->yield, formula->yield); - cost = cost * (formula->yield + 1L) / 2L; - } - else - fprintf (logfile, "\n"); - fprintf (logfile, "\t\tIngredients cost: %5ld\n\t\tComment: ", tcost); - if (tcost < 0) - fprintf (logfile, "Could not find some ingredients. Check the formula!\n"); - else if (tcost > cost) - fprintf (logfile, "Ingredients are much too expensive. Useless formula.\n"); - else if (tcost * 2L > cost) - fprintf (logfile, "Ingredients are too expensive.\n"); - else if (tcost * 10L < cost) - fprintf (logfile, "Ingredients are too cheap.\n"); - else - fprintf (logfile, "OK.\n"); - } - } - } - else - LOG(llevError, "Can't find archetype:%s for formula %s\n", string, - 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); + fprintf (logfile, "\n%-40s bookchance %3d skill %s\n", + buf, formula->chance, formula->skill); + if (formula->ingred !=NULL) + { + tcost = 0; + for (next = formula->ingred; next != NULL; next = next->next) + { + cost = find_ingred_cost (next->name); + if (cost < 0) + num_errors++; + fprintf (logfile,"\t%-33s%5ld\n", next->name, cost); + if (cost < 0 || tcost < 0) + tcost = -1; + else + tcost += cost; + } + if (art != NULL && art->item != NULL) + cost = at->clone.value * art->item->value; + else + cost = at->clone.value; + fprintf (logfile, "\t\tBuying result costs: %5ld", cost); + if (formula->yield > 1) + { + fprintf (logfile, " to %ld (max %d items)\n", + cost * formula->yield, formula->yield); + cost = cost * (formula->yield + 1L) / 2L; + } + else + fprintf (logfile, "\n"); + fprintf (logfile, "\t\tIngredients cost: %5ld\n\t\tComment: ", tcost); + if (tcost < 0) + fprintf (logfile, "Could not find some ingredients. Check the formula!\n"); + else if (tcost > cost) + fprintf (logfile, "Ingredients are much too expensive. Useless formula.\n"); + else if (tcost * 2L > cost) + fprintf (logfile, "Ingredients are too expensive.\n"); + else if (tcost * 10L < cost) + fprintf (logfile, "Ingredients are too cheap.\n"); + else + fprintf (logfile, "OK.\n"); + } + } + } + else + LOG(llevError, "Can't find archetype:%s for formula %s\n", string, + formula->title); } } fprintf (logfile,"\n"); @@ -499,7 +499,7 @@ } if (num_errors > 0) fprintf (logfile, "WARNING: %d objects required by the formulae do not exist in the game.\n", - num_errors); + num_errors); } const char * ingred_name (const char *name) { @@ -597,27 +597,27 @@ LOG(llevDebug,"Freeing all the recipes\n"); for (fl=formulalist; fl!=NULL; fl=flnext) { - flnext=fl->next; + flnext=fl->next; - for (formula=fl->items; formula!=NULL; formula=next) { - next=formula->next; + 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); - for (lchar=formula->ingred; lchar; lchar=charnext) { - charnext=lchar->next; - free_string(lchar->name); - free(lchar); - } - free(formula); - } - free(fl); + 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); + for (lchar=formula->ingred; lchar; lchar=charnext) { + charnext=lchar->next; + free_string(lchar->name); + free(lchar); + } + free(formula); + } + free(fl); } }