… | |
… | |
94 | { |
94 | { |
95 | artifact *art = locate_recipe_artifact (rp, i); |
95 | artifact *art = locate_recipe_artifact (rp, i); |
96 | |
96 | |
97 | if (!art && strcmp (rp->title, "NONE") != 0) |
97 | if (!art && strcmp (rp->title, "NONE") != 0) |
98 | { |
98 | { |
99 | LOG (llevError, "\nWARNING: Formula %s of %s has no artifact.\n", rp->arch_name[i], &rp->title); |
99 | LOG (llevError, "WARNING: Formula %s of %s has no artifact.\n", rp->arch_name[i], &rp->title); |
100 | result = 0; |
100 | result = 0; |
101 | } |
101 | } |
102 | } |
102 | } |
103 | else |
103 | else |
104 | { |
104 | { |
105 | LOG (llevError, "\nWARNING: Can't find archetype %s for formula %s\n", rp->arch_name[i], &rp->title); |
105 | LOG (llevError, "WARNING: Can't find archetype %s for formula %s\n", rp->arch_name[i], &rp->title); |
106 | result = 0; |
106 | result = 0; |
107 | } |
107 | } |
108 | } |
108 | } |
109 | |
109 | |
110 | return result; |
110 | return result; |
… | |
… | |
134 | return; |
134 | return; |
135 | else |
135 | else |
136 | has_been_done = 1; |
136 | has_been_done = 1; |
137 | |
137 | |
138 | sprintf (filename, "%s/formulae", settings.datadir); |
138 | sprintf (filename, "%s/formulae", settings.datadir); |
139 | LOG (llevDebug, "Reading alchemical formulae from %s...", filename); |
139 | LOG (llevDebug, "Reading alchemical formulae from %s...\n", filename); |
140 | if ((fp = open_and_uncompress (filename, 0, &comp)) == NULL) |
140 | if ((fp = open_and_uncompress (filename, 0, &comp)) == NULL) |
141 | { |
141 | { |
142 | LOG (llevError, "Can't open %s.\n", filename); |
142 | LOG (llevError, "Can't open %s.\n", filename); |
143 | return; |
143 | return; |
144 | } |
144 | } |
… | |
… | |
151 | *cp = '\0'; |
151 | *cp = '\0'; |
152 | cp = buf; |
152 | cp = buf; |
153 | while (*cp == ' ') /* Skip blanks */ |
153 | while (*cp == ' ') /* Skip blanks */ |
154 | cp++; |
154 | cp++; |
155 | |
155 | |
156 | if (!strncmp (cp, "Object", 6)) |
156 | if (!strncmp (cp, "Object", 6) || !strncmp (cp, "object", 6)) |
157 | { |
157 | { |
158 | formula = get_empty_formula (); |
158 | formula = get_empty_formula (); |
159 | formula->title = strchr (cp, ' ') + 1; |
159 | formula->title = strchr (cp, ' ') + 1; |
160 | } |
160 | } |
161 | else if (!strncmp (cp, "keycode", 7)) |
161 | else if (!strncmp (cp, "keycode", 7)) |
… | |
… | |
254 | { |
254 | { |
255 | recipelist *fl; |
255 | recipelist *fl; |
256 | recipe *check, *formula; |
256 | recipe *check, *formula; |
257 | int numb = 1; |
257 | int numb = 1; |
258 | |
258 | |
259 | LOG (llevDebug, "Checking formulae lists..."); |
259 | LOG (llevDebug, "Checking formulae lists...\n"); |
260 | |
260 | |
261 | for (fl = formulalist; fl != NULL; fl = fl->next) |
261 | for (fl = formulalist; fl != NULL; fl = fl->next) |
262 | { |
262 | { |
263 | for (formula = fl->items; formula != NULL; formula = formula->next) |
263 | for (formula = fl->items; formula != NULL; formula = formula->next) |
264 | for (check = formula->next; check != NULL; check = check->next) |
264 | for (check = formula->next; check != NULL; check = check->next) |
… | |
… | |
373 | return at; |
373 | return at; |
374 | } |
374 | } |
375 | } |
375 | } |
376 | else |
376 | else |
377 | { |
377 | { |
378 | if (!strcasecmp (t->item->clone.name, name)) |
378 | if (t->item && !strcasecmp (t->item->clone.name, name)) |
379 | return t->item; |
379 | return t->item; |
380 | } |
380 | } |
381 | |
381 | |
382 | if (t->next_yes) |
382 | if (t->next_yes) |
383 | { |
383 | { |
… | |
… | |
422 | while (isdigit (*name)) |
422 | while (isdigit (*name)) |
423 | { |
423 | { |
424 | mult = 10 * mult + (*name - '0'); |
424 | mult = 10 * mult + (*name - '0'); |
425 | name++; |
425 | name++; |
426 | } |
426 | } |
|
|
427 | |
427 | if (mult > 0) |
428 | if (mult > 0) |
428 | name++; |
429 | name++; |
429 | else |
430 | else |
430 | mult = 1; |
431 | mult = 1; |
|
|
432 | |
431 | /* first, try to match the name of an archetype */ |
433 | /* first, try to match the name of an archetype */ |
432 | for (at = first_archetype; at != NULL; at = at->next) |
434 | for (at = first_archetype; at != NULL; at = at->next) |
433 | { |
435 | { |
434 | if (at->clone.title != NULL) |
436 | if (at->clone.title != NULL) |
435 | { |
437 | { |
… | |
… | |
439 | return mult * at->clone.value; |
441 | return mult * at->clone.value; |
440 | } |
442 | } |
441 | if (!strcasecmp (at->clone.name, name)) |
443 | if (!strcasecmp (at->clone.name, name)) |
442 | return mult * at->clone.value; |
444 | return mult * at->clone.value; |
443 | } |
445 | } |
|
|
446 | |
444 | /* second, try to match an artifact ("arch of something") */ |
447 | /* second, try to match an artifact ("arch of something") */ |
445 | cp = strstr (name, " of "); |
448 | cp = strstr (name, " of "); |
446 | if (cp != NULL) |
449 | if (cp != NULL) |
447 | { |
450 | { |
448 | strcpy (part1, name); |
451 | strcpy (part1, name); |
… | |
… | |
462 | if (!strcasecmp (art->item->name, part2)) |
465 | if (!strcasecmp (art->item->name, part2)) |
463 | return mult * at->clone.value * art->item->value; |
466 | return mult * at->clone.value * art->item->value; |
464 | } |
467 | } |
465 | } |
468 | } |
466 | } |
469 | } |
|
|
470 | |
467 | /* third, try to match a body part ("arch's something") */ |
471 | /* third, try to match a body part ("arch's something") */ |
468 | cp = strstr (name, "'s "); |
472 | cp = strstr (name, "'s "); |
469 | if (cp != NULL) |
473 | if (cp) |
470 | { |
474 | { |
471 | strcpy (part1, name); |
475 | strcpy (part1, name); |
472 | part1[cp - name] = '\0'; |
476 | part1[cp - name] = '\0'; |
473 | strcpy (part2, cp + 3); |
477 | strcpy (part2, cp + 3); |
474 | /* examine all archetypes matching the first part of the name */ |
478 | /* examine all archetypes matching the first part of the name */ |
… | |
… | |
481 | if (at2) |
485 | if (at2) |
482 | return mult * at2->clone.value * isqrt (at->clone.level * 2); |
486 | return mult * at2->clone.value * isqrt (at->clone.level * 2); |
483 | } |
487 | } |
484 | } |
488 | } |
485 | } |
489 | } |
|
|
490 | |
486 | /* failed to find any matching items -- formula should be checked */ |
491 | /* failed to find any matching items -- formula should be checked */ |
487 | return -1; |
492 | return -1; |
488 | } |
493 | } |
489 | |
494 | |
490 | /* code copied from dump_alchemy() and modified by Raphael Quinet */ |
495 | /* code copied from dump_alchemy() and modified by Raphael Quinet */ |
… | |
… | |
650 | for (fl = get_formulalist (1); fl; fl = fl->next) |
655 | for (fl = get_formulalist (1); fl; fl = fl->next) |
651 | number++; |
656 | number++; |
652 | |
657 | |
653 | /* now, randomly choose one */ |
658 | /* now, randomly choose one */ |
654 | if (number > 0) |
659 | if (number > 0) |
655 | roll = RANDOM () % number; |
660 | roll = rndm (number); |
656 | |
661 | |
657 | fl = get_formulalist (1); |
662 | fl = get_formulalist (1); |
658 | while (roll && fl) |
663 | while (roll && fl) |
659 | { |
664 | { |
660 | if (fl->next) |
665 | if (fl->next) |
… | |
… | |
683 | if ((fl = get_random_recipelist ()) == NULL) |
688 | if ((fl = get_random_recipelist ()) == NULL) |
684 | return rp; |
689 | return rp; |
685 | |
690 | |
686 | if (fl->total_chance > 0) |
691 | if (fl->total_chance > 0) |
687 | { |
692 | { |
688 | r = RANDOM () % fl->total_chance; |
693 | r = rndm (fl->total_chance); |
689 | for (rp = fl->items; rp; rp = rp->next) |
694 | for (rp = fl->items; rp; rp = rp->next) |
690 | { |
695 | { |
691 | r -= rp->chance; |
696 | r -= rp->chance; |
692 | if (r < 0) |
697 | if (r < 0) |
693 | break; |
698 | break; |