1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * it under the terms of the GNU General Public License as published by |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your option) any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * and the GNU General Public License along with this program. If not, see |
|
|
20 | * <http://www.gnu.org/licenses/>. |
20 | * |
21 | * |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | /* Basic stuff for use with the alchemy code. Clearly some of this stuff |
25 | /* Basic stuff for use with the alchemy code. Clearly some of this stuff |
… | |
… | |
110 | size_t i; |
111 | size_t i; |
111 | int result = 1; |
112 | int result = 1; |
112 | |
113 | |
113 | for (i = 0; i < rp->arch_names; i++) |
114 | for (i = 0; i < rp->arch_names; i++) |
114 | { |
115 | { |
115 | if (archetype::find (rp->arch_name[i]) != NULL) |
116 | if (archetype::find (rp->arch_name[i])) |
116 | { |
117 | { |
117 | artifact *art = locate_recipe_artifact (rp, i); |
118 | artifact *art = locate_recipe_artifact (rp, i); |
118 | |
119 | |
119 | if (!art && strcmp (rp->title, "NONE") != 0) |
120 | if (!art && rp->title != shstr_NONE) |
120 | { |
121 | { |
121 | LOG (llevError, "WARNING: Formula %s of %s has no artifact.\n", rp->arch_name[i], &rp->title); |
122 | LOG (llevError, "WARNING: Formula %s of %s has no artifact.\n", rp->arch_name[i], &rp->title); |
122 | result = 0; |
123 | result = 0; |
123 | } |
124 | } |
124 | } |
125 | } |
… | |
… | |
128 | result = 0; |
129 | result = 0; |
129 | } |
130 | } |
130 | } |
131 | } |
131 | |
132 | |
132 | return result; |
133 | return result; |
|
|
134 | } |
|
|
135 | |
|
|
136 | /* check_formulae()- since we are doing a squential search on the |
|
|
137 | * formulae lists now, we have to be carefull that we dont have 2 |
|
|
138 | * formula with the exact same index value. Under the new nbatches |
|
|
139 | * code, it is possible to have multiples of ingredients in a cauldron |
|
|
140 | * which could result in an index formula mismatch. We *don't* check for |
|
|
141 | * that possibility here. -b.t. |
|
|
142 | */ |
|
|
143 | static void |
|
|
144 | check_formulae (void) |
|
|
145 | { |
|
|
146 | recipelist *fl; |
|
|
147 | recipe *check, *formula; |
|
|
148 | int numb = 1; |
|
|
149 | |
|
|
150 | LOG (llevDebug, "Checking formulae lists...\n"); |
|
|
151 | |
|
|
152 | for (fl = formulalist; fl; fl = fl->next) |
|
|
153 | { |
|
|
154 | for (formula = fl->items; formula; formula = formula->next) |
|
|
155 | for (check = formula->next; check; check = check->next) |
|
|
156 | if (check->index == formula->index) |
|
|
157 | { |
|
|
158 | LOG (llevError, " ERROR: On %d ingred list: ", numb); |
|
|
159 | LOG (llevError, "Formulae [%s] of %s and [%s] of %s have matching index id (%d)\n", |
|
|
160 | formula->arch_name[0], &formula->title, check->arch_name[0], &check->title, formula->index); |
|
|
161 | } |
|
|
162 | numb++; |
|
|
163 | } |
|
|
164 | |
|
|
165 | LOG (llevDebug, "done.\n"); |
|
|
166 | |
133 | } |
167 | } |
134 | |
168 | |
135 | /* |
169 | /* |
136 | * init_formulae() - Builds up the lists of formula from the file in |
170 | * init_formulae() - Builds up the lists of formula from the file in |
137 | * the libdir. -b.t. |
171 | * the libdir. -b.t. |
… | |
… | |
249 | close_and_delete (fp, comp); |
283 | close_and_delete (fp, comp); |
250 | /* Lastly, lets check for problems in formula we got */ |
284 | /* Lastly, lets check for problems in formula we got */ |
251 | check_formulae (); |
285 | check_formulae (); |
252 | } |
286 | } |
253 | |
287 | |
254 | /* check_formulae()- since we are doing a squential search on the |
|
|
255 | * formulae lists now, we have to be carefull that we dont have 2 |
|
|
256 | * formula with the exact same index value. Under the new nbatches |
|
|
257 | * code, it is possible to have multiples of ingredients in a cauldron |
|
|
258 | * which could result in an index formula mismatch. We *don't* check for |
|
|
259 | * that possibility here. -b.t. |
|
|
260 | */ |
|
|
261 | void |
|
|
262 | check_formulae (void) |
|
|
263 | { |
|
|
264 | recipelist *fl; |
|
|
265 | recipe *check, *formula; |
|
|
266 | int numb = 1; |
|
|
267 | |
|
|
268 | LOG (llevDebug, "Checking formulae lists...\n"); |
|
|
269 | |
|
|
270 | for (fl = formulalist; fl; fl = fl->next) |
|
|
271 | { |
|
|
272 | for (formula = fl->items; formula; formula = formula->next) |
|
|
273 | for (check = formula->next; check; check = check->next) |
|
|
274 | if (check->index == formula->index) |
|
|
275 | { |
|
|
276 | LOG (llevError, " ERROR: On %d ingred list: ", numb); |
|
|
277 | LOG (llevError, "Formulae [%s] of %s and [%s] of %s have matching index id (%d)\n", |
|
|
278 | formula->arch_name[0], &formula->title, check->arch_name[0], &check->title, formula->index); |
|
|
279 | } |
|
|
280 | numb++; |
|
|
281 | } |
|
|
282 | |
|
|
283 | LOG (llevDebug, "done.\n"); |
|
|
284 | |
|
|
285 | } |
|
|
286 | |
|
|
287 | /* Borrowed (again) from the artifacts code for this */ |
|
|
288 | |
|
|
289 | void |
|
|
290 | dump_alchemy (void) |
|
|
291 | { |
|
|
292 | recipelist *fl = formulalist; |
|
|
293 | recipe *formula = NULL; |
|
|
294 | linked_char *next; |
|
|
295 | int num_ingred = 1; |
|
|
296 | |
|
|
297 | fprintf (logfile, "\n"); |
|
|
298 | while (fl) |
|
|
299 | { |
|
|
300 | fprintf (logfile, "\n Formulae with %d ingredient%s %d Formulae with total_chance=%d\n", |
|
|
301 | num_ingred, num_ingred > 1 ? "s." : ".", fl->number, fl->total_chance); |
|
|
302 | for (formula = fl->items; formula; formula = formula->next) |
|
|
303 | { |
|
|
304 | artifact *art = NULL; |
|
|
305 | char buf[MAX_BUF]; |
|
|
306 | size_t i; |
|
|
307 | |
|
|
308 | for (i = 0; i < formula->arch_names; i++) |
|
|
309 | { |
|
|
310 | const char *string = formula->arch_name[i]; |
|
|
311 | |
|
|
312 | if (archetype::find (string) != NULL) |
|
|
313 | { |
|
|
314 | art = locate_recipe_artifact (formula, i); |
|
|
315 | if (!art && strcmp (formula->title, "NONE")) |
|
|
316 | LOG (llevError, "Formula %s has no artifact!\n", &formula->title); |
|
|
317 | else |
|
|
318 | { |
|
|
319 | if (strcmp (formula->title, "NONE")) |
|
|
320 | sprintf (buf, "%s of %s", string, &formula->title); |
|
|
321 | else |
|
|
322 | sprintf (buf, "%s", string); |
|
|
323 | fprintf (logfile, "%-30s(%d) bookchance %3d ", buf, formula->index, formula->chance); |
|
|
324 | fprintf (logfile, "skill %s", &formula->skill); |
|
|
325 | fprintf (logfile, "\n"); |
|
|
326 | if (formula->ingred != NULL) |
|
|
327 | { |
|
|
328 | int nval = 0, tval = 0; |
|
|
329 | |
|
|
330 | fprintf (logfile, "\tIngred: "); |
|
|
331 | for (next = formula->ingred; next != NULL; next = next->next) |
|
|
332 | { |
|
|
333 | if (nval != 0) |
|
|
334 | fprintf (logfile, ","); |
|
|
335 | fprintf (logfile, "%s(%d)", &next->name, (nval = strtoint (next->name))); |
|
|
336 | tval += nval; |
|
|
337 | } |
|
|
338 | fprintf (logfile, "\n"); |
|
|
339 | if (tval != formula->index) |
|
|
340 | fprintf (logfile, "WARNING:ingredient list and formula values not equal.\n"); |
|
|
341 | } |
|
|
342 | if (formula->skill != NULL) |
|
|
343 | fprintf (logfile, "\tSkill Required: %s", &formula->skill); |
|
|
344 | if (formula->cauldron != NULL) |
|
|
345 | fprintf (logfile, "\tCauldron: %s\n", &formula->cauldron); |
|
|
346 | fprintf (logfile, "\tDifficulty: %d\t Exp: %d\n", formula->diff, formula->exp); |
|
|
347 | } |
|
|
348 | } |
|
|
349 | else |
|
|
350 | LOG (llevError, "Can't find archetype:%s for formula %s\n", string, &formula->title); |
|
|
351 | } |
|
|
352 | } |
|
|
353 | fprintf (logfile, "\n"); |
|
|
354 | fl = fl->next; |
|
|
355 | num_ingred++; |
|
|
356 | } |
|
|
357 | } |
|
|
358 | |
|
|
359 | /* Find a treasure with a matching name. The 'depth' parameter is |
288 | /* Find a treasure with a matching name. The 'depth' parameter is |
360 | * only there to prevent infinite loops in treasure lists (a list |
289 | * only there to prevent infinite loops in treasure lists (a list |
361 | * referencing another list pointing back to the first one). */ |
290 | * referencing another list pointing back to the first one). */ |
362 | archetype * |
291 | archetype * |
363 | find_treasure_by_name (const treasure *t, const char *name, int depth) |
292 | find_treasure_by_name (const treasure *t, const char *name, int depth) |
… | |
… | |
448 | part1[cp - name] = '\0'; |
377 | part1[cp - name] = '\0'; |
449 | strcpy (part2, cp + 4); |
378 | strcpy (part2, cp + 4); |
450 | |
379 | |
451 | /* find the first archetype matching the first part of the name */ |
380 | /* find the first archetype matching the first part of the name */ |
452 | for_all_archetypes (at) |
381 | for_all_archetypes (at) |
453 | if (!strcasecmp (at->object::name, part1) && at->title == NULL) |
382 | if (at->object::name.eq_nc (part1) && !at->title) |
454 | { |
383 | { |
455 | /* find the first artifact derived from that archetype (same type) */ |
384 | /* find the first artifact derived from that archetype (same type) */ |
456 | for (al = first_artifactlist; al; al = al->next) |
385 | for (al = first_artifactlist; al; al = al->next) |
457 | if (al->type == at->type) |
386 | if (al->type == at->type) |
458 | { |
387 | { |
… | |
… | |
470 | strcpy (part1, name); |
399 | strcpy (part1, name); |
471 | part1[cp - name] = '\0'; |
400 | part1[cp - name] = '\0'; |
472 | strcpy (part2, cp + 3); |
401 | strcpy (part2, cp + 3); |
473 | /* examine all archetypes matching the first part of the name */ |
402 | /* examine all archetypes matching the first part of the name */ |
474 | for_all_archetypes (at) |
403 | for_all_archetypes (at) |
475 | if (!strcasecmp (at->object::name, part1) && at->title == NULL) |
404 | if (at->object::name.eq_nc (part1) && !at->title) |
476 | { |
405 | { |
477 | if (at->randomitems) |
406 | if (at->randomitems) |
478 | { |
407 | { |
479 | at2 = find_treasure_by_name (at->randomitems->items, part2, 0); |
408 | at2 = find_treasure_by_name (at->randomitems->items, part2, 0); |
480 | if (at2) |
409 | if (at2) |
… | |
… | |
485 | |
414 | |
486 | /* failed to find any matching items -- formula should be checked */ |
415 | /* failed to find any matching items -- formula should be checked */ |
487 | return -1; |
416 | return -1; |
488 | } |
417 | } |
489 | |
418 | |
490 | /* code copied from dump_alchemy() and modified by Raphael Quinet */ |
|
|
491 | void |
|
|
492 | dump_alchemy_costs (void) |
|
|
493 | { |
|
|
494 | recipelist *fl = formulalist; |
|
|
495 | recipe *formula = NULL; |
|
|
496 | linked_char *next; |
|
|
497 | int num_ingred = 1; |
|
|
498 | int num_errors = 0; |
|
|
499 | long cost; |
|
|
500 | long tcost; |
|
|
501 | |
|
|
502 | fprintf (logfile, "\n"); |
|
|
503 | while (fl) |
|
|
504 | { |
|
|
505 | fprintf (logfile, "\n Formulae with %d ingredient%s %d Formulae with total_chance=%d\n", |
|
|
506 | num_ingred, num_ingred > 1 ? "s." : ".", fl->number, fl->total_chance); |
|
|
507 | for (formula = fl->items; formula; formula = formula->next) |
|
|
508 | { |
|
|
509 | artifact *art = NULL; |
|
|
510 | archetype *at = NULL; |
|
|
511 | char buf[MAX_BUF]; |
|
|
512 | size_t i; |
|
|
513 | |
|
|
514 | for (i = 0; i < formula->arch_names; i++) |
|
|
515 | { |
|
|
516 | const char *string = formula->arch_name[i]; |
|
|
517 | |
|
|
518 | if ((at = archetype::find (string)) != NULL) |
|
|
519 | { |
|
|
520 | art = locate_recipe_artifact (formula, i); |
|
|
521 | if (!art && strcmp (formula->title, "NONE")) |
|
|
522 | LOG (llevError, "Formula %s has no artifact\n", &formula->title); |
|
|
523 | else |
|
|
524 | { |
|
|
525 | if (!strcmp (formula->title, "NONE")) |
|
|
526 | sprintf (buf, "%s", string); |
|
|
527 | else |
|
|
528 | sprintf (buf, "%s of %s", string, &formula->title); |
|
|
529 | fprintf (logfile, "\n%-40s bookchance %3d skill %s\n", buf, formula->chance, &(formula->skill)); |
|
|
530 | if (formula->ingred != NULL) |
|
|
531 | { |
|
|
532 | tcost = 0; |
|
|
533 | for (next = formula->ingred; next != NULL; next = next->next) |
|
|
534 | { |
|
|
535 | cost = find_ingred_cost (next->name); |
|
|
536 | if (cost < 0) |
|
|
537 | num_errors++; |
|
|
538 | fprintf (logfile, "\t%-33s%5ld\n", &next->name, cost); |
|
|
539 | if (cost < 0 || tcost < 0) |
|
|
540 | tcost = -1; |
|
|
541 | else |
|
|
542 | tcost += cost; |
|
|
543 | } |
|
|
544 | if (art != NULL && art->item != NULL) |
|
|
545 | cost = at->value * art->item->value; |
|
|
546 | else |
|
|
547 | cost = at->value; |
|
|
548 | fprintf (logfile, "\t\tBuying result costs: %5ld", cost); |
|
|
549 | if (formula->yield > 1) |
|
|
550 | { |
|
|
551 | fprintf (logfile, " to %ld (max %d items)\n", cost * formula->yield, formula->yield); |
|
|
552 | cost = cost * (formula->yield + 1L) / 2L; |
|
|
553 | } |
|
|
554 | else |
|
|
555 | fprintf (logfile, "\n"); |
|
|
556 | fprintf (logfile, "\t\tIngredients cost: %5ld\n\t\tComment: ", tcost); |
|
|
557 | if (tcost < 0) |
|
|
558 | fprintf (logfile, "Could not find some ingredients. Check the formula!\n"); |
|
|
559 | else if (tcost > cost) |
|
|
560 | fprintf (logfile, "Ingredients are much too expensive. Useless formula.\n"); |
|
|
561 | else if (tcost * 2L > cost) |
|
|
562 | fprintf (logfile, "Ingredients are too expensive.\n"); |
|
|
563 | else if (tcost * 10L < cost) |
|
|
564 | fprintf (logfile, "Ingredients are too cheap.\n"); |
|
|
565 | else |
|
|
566 | fprintf (logfile, "OK.\n"); |
|
|
567 | } |
|
|
568 | } |
|
|
569 | } |
|
|
570 | else |
|
|
571 | LOG (llevError, "Can't find archetype:%s for formula %s\n", string, &formula->title); |
|
|
572 | } |
|
|
573 | } |
|
|
574 | fprintf (logfile, "\n"); |
|
|
575 | fl = fl->next; |
|
|
576 | num_ingred++; |
|
|
577 | } |
|
|
578 | if (num_errors > 0) |
|
|
579 | fprintf (logfile, "WARNING: %d objects required by the formulae do not exist in the game.\n", num_errors); |
|
|
580 | } |
|
|
581 | |
|
|
582 | const char * |
419 | const char * |
583 | ingred_name (const char *name) |
420 | ingred_name (const char *name) |
584 | { |
421 | { |
585 | const char *cp = name; |
422 | const char *cp = name; |
586 | |
423 | |
587 | if (atoi (cp)) |
424 | if (atoi (cp)) |
588 | cp = strchr (cp, ' ') + 1; |
425 | cp = strchr (cp, ' ') + 1; |
|
|
426 | |
589 | return cp; |
427 | return cp; |
|
|
428 | } |
|
|
429 | |
|
|
430 | int |
|
|
431 | numb_ingred (const char *buf) |
|
|
432 | { |
|
|
433 | int numb; |
|
|
434 | |
|
|
435 | if ((numb = atoi (buf))) |
|
|
436 | return numb; |
|
|
437 | else |
|
|
438 | return 1; |
590 | } |
439 | } |
591 | |
440 | |
592 | /* strtoint() - we use this to convert buf into an integer |
441 | /* strtoint() - we use this to convert buf into an integer |
593 | * equal to the coadded sum of the (lowercase) character |
442 | * equal to the coadded sum of the (lowercase) character |
594 | * ASCII values in buf (times prepended integers). |
443 | * ASCII values in buf (times prepended integers). |
|
|
444 | * Some kind of hashing. |
595 | */ |
445 | */ |
596 | |
|
|
597 | int |
446 | int |
598 | strtoint (const char *buf) |
447 | strtoint (const char *buf) |
599 | { |
448 | { |
600 | const char *cp = ingred_name (buf); |
449 | const char *cp = ingred_name (buf); |
601 | int val = 0, len = strlen (cp), mult = numb_ingred (buf); |
450 | int val = 0, len = strlen (cp), mult = numb_ingred (buf); |
… | |
… | |
604 | { |
453 | { |
605 | val += tolower (*cp); |
454 | val += tolower (*cp); |
606 | cp++; |
455 | cp++; |
607 | len--; |
456 | len--; |
608 | } |
457 | } |
|
|
458 | |
609 | return val * mult; |
459 | return val * mult; |
610 | } |
460 | } |
611 | |
461 | |
612 | artifact * |
462 | artifact * |
613 | locate_recipe_artifact (const recipe *rp, size_t idx) |
463 | locate_recipe_artifact (const recipe *rp, size_t idx) |
… | |
… | |
619 | for (artifact *art = al->items; art; art = art->next) |
469 | for (artifact *art = al->items; art; art = art->next) |
620 | if (art->item->name == rp->title) |
470 | if (art->item->name == rp->title) |
621 | return art; |
471 | return art; |
622 | |
472 | |
623 | return 0; |
473 | return 0; |
624 | } |
|
|
625 | |
|
|
626 | int |
|
|
627 | numb_ingred (const char *buf) |
|
|
628 | { |
|
|
629 | int numb; |
|
|
630 | |
|
|
631 | if ((numb = atoi (buf))) |
|
|
632 | return numb; |
|
|
633 | else |
|
|
634 | return 1; |
|
|
635 | } |
474 | } |
636 | |
475 | |
637 | recipelist * |
476 | recipelist * |
638 | get_random_recipelist (void) |
477 | get_random_recipelist (void) |
639 | { |
478 | { |