--- deliantra/server/common/recipe.C 2010/04/04 04:58:46 1.36 +++ deliantra/server/common/recipe.C 2010/04/15 03:34:30 1.37 @@ -69,20 +69,21 @@ { recipe *t = new recipe; - t->chance = 0; - t->index = 0; - t->transmute = 0; - t->yield = 0; - t->diff = 0; - t->exp = 0; - t->keycode = 0; - t->title = NULL; + t->chance = 0; + t->index = 0; + t->transmute = 0; + t->yield = 0; + t->diff = 0; + t->exp = 0; + t->keycode = 0; + t->title = 0; t->arch_names = 0; - t->arch_name = NULL; - t->skill = NULL; - t->cauldron = NULL; - t->ingred = NULL; - t->next = NULL; + t->arch_name = 0; + t->skill = 0; + t->cauldron = 0; + t->ingred = 0; + t->next = 0; + return t; } @@ -176,7 +177,6 @@ static int has_been_done = 0; FILE *fp; char filename[MAX_BUF], buf[MAX_BUF], *cp, *next; - recipe *formula = NULL; recipelist *fl = init_recipelist (); linked_char *tmp; int value, comp; @@ -191,96 +191,100 @@ sprintf (filename, "%s/formulae", settings.datadir); LOG (llevDebug, "Reading alchemical formulae from %s...\n", filename); - if ((fp = open_and_uncompress (filename, 0, &comp)) == NULL) + + object_thawer thawer (filename); + + if (!thawer) { LOG (llevError, "Can't open %s.\n", filename); return; } - while (fgets (buf, MAX_BUF, fp) != NULL) + while (thawer.kw) { - if (*buf == '#') - continue; - if ((cp = strchr (buf, '\n')) != NULL) - *cp = '\0'; - cp = buf; - while (*cp == ' ') /* Skip blanks */ - cp++; + if (thawer.kw != KW_object) + if (!thawer.parse_error ("formulae file", "formulae")) + break; - if (!strncmp (cp, "object", 6)) - { - formula = get_empty_formula (); - formula->title = strchr (cp, ' ') + 1; - } - else if (!strncmp (cp, "keycode", 7)) - formula->keycode = strchr (cp, ' ') + 1; - else if (sscanf (cp, "trans %d", &value)) - formula->transmute = (uint16) value; - else if (sscanf (cp, "yield %d", &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; - else if (sscanf (cp, "diff %d", &value)) - formula->diff = (uint16) value; - else if (!strncmp (cp, "ingred", 6)) + recipe *formula = get_empty_formula (); + thawer.get (formula->title); + + for (;;) { - int numb_ingred = 1; + thawer.next (); - cp = strchr (cp, ' ') + 1; - do + switch (thawer.kw) { - if ((next = strchr (cp, ',')) != NULL) + case KW_keycode: thawer.get (formula->keycode ); break; + case KW_trans: thawer.get (formula->transmute); break; + case KW_yield: thawer.get (formula->yield ); break; + case KW_chance: thawer.get (formula->chance ); break; + case KW_exp: thawer.get (formula->exp ); break; + case KW_diff: thawer.get (formula->diff ); break; + case KW_skill: thawer.get (formula->skill ); break; + case KW_cauldron: thawer.get (formula->cauldron ); break; + + case KW_arch: { - *(next++) = '\0'; - numb_ingred++; + build_stringlist (thawer.value_nn, &formula->arch_name, &formula->arch_names); + check_recipe (formula); } + break; - tmp = new linked_char; - - tmp->name = cp; - tmp->next = formula->ingred; - formula->ingred = tmp; - /* 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); - } - 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 (); + case KW_ingred: + if (thawer.value) + { + int numb_ingred = 1; + char *cp = thawer.value; + + do + { + if ((next = strchr (cp, ','))) + { + *next++ = '\0'; + ++numb_ingred; + } + + tmp = new linked_char; + + tmp->name = cp; + tmp->next = formula->ingred; + formula->ingred = tmp; + /* 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); + } + while ((cp = next)); + + /* now find the correct (# of ingred ordered) formulalist */ + fl = formulalist; + while (numb_ingred != 1) + { + if (!fl->next) + fl->next = init_recipelist (); + + fl = fl->next; + numb_ingred--; + } + + fl->total_chance += formula->chance; + fl->number++; + formula->next = fl->items; + fl->items = formula; + } + break; - fl = fl->next; - numb_ingred--; + default: + goto next_object; } - - fl->total_chance += formula->chance; - fl->number++; - formula->next = fl->items; - fl->items = formula; } - else if (!strncmp (cp, "arch", 4)) - { - build_stringlist (strchr (cp, ' ') + 1, &formula->arch_name, &formula->arch_names); - check_recipe (formula); - } - else if (!strncmp (cp, "skill", 5)) - formula->skill = strchr (cp, ' ') + 1; - else if (!strncmp (cp, "cauldron", 8)) - formula->cauldron = strchr (cp, ' ') + 1; - else - LOG (llevError, "Unknown input in file %s: %s\n", filename, buf); + +next_object: ; } LOG (llevDebug, "done.\n"); - close_and_delete (fp, comp); /* Lastly, lets check for problems in formula we got */ check_formulae (); }