|
|
1 | /* |
|
|
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
|
|
3 | * |
|
|
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
|
|
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
|
|
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
|
|
7 | * |
|
|
8 | * Deliantra is free software: you can redistribute it and/or modify |
|
|
9 | * it under the terms of the GNU General Public License as published by |
|
|
10 | * the Free Software Foundation, either version 3 of the License, or |
|
|
11 | * (at your option) any later version. |
|
|
12 | * |
|
|
13 | * This program is distributed in the hope that it will be useful, |
|
|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
16 | * GNU General Public License for more details. |
|
|
17 | * |
|
|
18 | * You should have received a copy of the GNU General Public License |
|
|
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
|
20 | * |
|
|
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
|
|
22 | */ |
|
|
23 | |
1 | /* Basic stuff for use with the alchemy code. Clearly some of this stuff |
24 | /* Basic stuff for use with the alchemy code. Clearly some of this stuff |
2 | * could go into server/alchemy, but I left it here just in case it proves |
25 | * could go into server/alchemy, but I left it here just in case it proves |
3 | * more generally useful. |
26 | * more generally useful. |
4 | * |
27 | * |
5 | * Nov 1995 - file created by b.t. thomas@astro.psu.edu |
28 | * Nov 1995 - file created by b.t. thomas@astro.psu.edu |
… | |
… | |
32 | { |
55 | { |
33 | recipelist *tl = new recipelist; |
56 | recipelist *tl = new recipelist; |
34 | |
57 | |
35 | tl->total_chance = 0; |
58 | tl->total_chance = 0; |
36 | tl->number = 0; |
59 | tl->number = 0; |
37 | tl->items = NULL; |
60 | tl->items = 0; |
38 | tl->next = NULL; |
61 | tl->next = 0; |
|
|
62 | |
39 | return tl; |
63 | return tl; |
40 | } |
64 | } |
41 | |
65 | |
42 | static recipe * |
66 | static recipe * |
43 | get_empty_formula (void) |
67 | get_empty_formula (void) |
… | |
… | |
86 | size_t i; |
110 | size_t i; |
87 | int result = 1; |
111 | int result = 1; |
88 | |
112 | |
89 | for (i = 0; i < rp->arch_names; i++) |
113 | for (i = 0; i < rp->arch_names; i++) |
90 | { |
114 | { |
91 | if (archetype::find (rp->arch_name[i]) != NULL) |
115 | if (archetype::find (rp->arch_name[i])) |
92 | { |
116 | { |
93 | artifact *art = locate_recipe_artifact (rp, i); |
117 | artifact *art = locate_recipe_artifact (rp, i); |
94 | |
118 | |
95 | if (!art && strcmp (rp->title, "NONE") != 0) |
119 | if (!art && rp->title != shstr_NONE) |
96 | { |
120 | { |
97 | LOG (llevError, "WARNING: Formula %s of %s has no artifact.\n", rp->arch_name[i], &rp->title); |
121 | LOG (llevError, "WARNING: Formula %s of %s has no artifact.\n", rp->arch_name[i], &rp->title); |
98 | result = 0; |
122 | result = 0; |
99 | } |
123 | } |
100 | } |
124 | } |
… | |
… | |
241 | recipe *check, *formula; |
265 | recipe *check, *formula; |
242 | int numb = 1; |
266 | int numb = 1; |
243 | |
267 | |
244 | LOG (llevDebug, "Checking formulae lists...\n"); |
268 | LOG (llevDebug, "Checking formulae lists...\n"); |
245 | |
269 | |
246 | for (fl = formulalist; fl != NULL; fl = fl->next) |
270 | for (fl = formulalist; fl; fl = fl->next) |
247 | { |
271 | { |
248 | for (formula = fl->items; formula != NULL; formula = formula->next) |
272 | for (formula = fl->items; formula; formula = formula->next) |
249 | for (check = formula->next; check != NULL; check = check->next) |
273 | for (check = formula->next; check; check = check->next) |
250 | if (check->index == formula->index) |
274 | if (check->index == formula->index) |
251 | { |
275 | { |
252 | LOG (llevError, " ERROR: On %d ingred list: ", numb); |
276 | LOG (llevError, " ERROR: On %d ingred list: ", numb); |
253 | LOG (llevError, "Formulae [%s] of %s and [%s] of %s have matching index id (%d)\n", |
277 | LOG (llevError, "Formulae [%s] of %s and [%s] of %s have matching index id (%d)\n", |
254 | formula->arch_name[0], &formula->title, check->arch_name[0], &check->title, formula->index); |
278 | formula->arch_name[0], &formula->title, check->arch_name[0], &check->title, formula->index); |
… | |
… | |
258 | |
282 | |
259 | LOG (llevDebug, "done.\n"); |
283 | LOG (llevDebug, "done.\n"); |
260 | |
284 | |
261 | } |
285 | } |
262 | |
286 | |
263 | /* Borrowed (again) from the artifacts code for this */ |
|
|
264 | |
|
|
265 | void |
|
|
266 | dump_alchemy (void) |
|
|
267 | { |
|
|
268 | recipelist *fl = formulalist; |
|
|
269 | recipe *formula = NULL; |
|
|
270 | linked_char *next; |
|
|
271 | int num_ingred = 1; |
|
|
272 | |
|
|
273 | fprintf (logfile, "\n"); |
|
|
274 | while (fl) |
|
|
275 | { |
|
|
276 | fprintf (logfile, "\n Formulae with %d ingredient%s %d Formulae with total_chance=%d\n", |
|
|
277 | num_ingred, num_ingred > 1 ? "s." : ".", fl->number, fl->total_chance); |
|
|
278 | for (formula = fl->items; formula != NULL; formula = formula->next) |
|
|
279 | { |
|
|
280 | artifact *art = NULL; |
|
|
281 | char buf[MAX_BUF]; |
|
|
282 | size_t i; |
|
|
283 | |
|
|
284 | for (i = 0; i < formula->arch_names; i++) |
|
|
285 | { |
|
|
286 | const char *string = formula->arch_name[i]; |
|
|
287 | |
|
|
288 | if (archetype::find (string) != NULL) |
|
|
289 | { |
|
|
290 | art = locate_recipe_artifact (formula, i); |
|
|
291 | if (!art && strcmp (formula->title, "NONE")) |
|
|
292 | LOG (llevError, "Formula %s has no artifact!\n", &formula->title); |
|
|
293 | else |
|
|
294 | { |
|
|
295 | if (strcmp (formula->title, "NONE")) |
|
|
296 | sprintf (buf, "%s of %s", string, &formula->title); |
|
|
297 | else |
|
|
298 | sprintf (buf, "%s", string); |
|
|
299 | fprintf (logfile, "%-30s(%d) bookchance %3d ", buf, formula->index, formula->chance); |
|
|
300 | fprintf (logfile, "skill %s", &formula->skill); |
|
|
301 | fprintf (logfile, "\n"); |
|
|
302 | if (formula->ingred != NULL) |
|
|
303 | { |
|
|
304 | int nval = 0, tval = 0; |
|
|
305 | |
|
|
306 | fprintf (logfile, "\tIngred: "); |
|
|
307 | for (next = formula->ingred; next != NULL; next = next->next) |
|
|
308 | { |
|
|
309 | if (nval != 0) |
|
|
310 | fprintf (logfile, ","); |
|
|
311 | fprintf (logfile, "%s(%d)", &next->name, (nval = strtoint (next->name))); |
|
|
312 | tval += nval; |
|
|
313 | } |
|
|
314 | fprintf (logfile, "\n"); |
|
|
315 | if (tval != formula->index) |
|
|
316 | fprintf (logfile, "WARNING:ingredient list and formula values not equal.\n"); |
|
|
317 | } |
|
|
318 | if (formula->skill != NULL) |
|
|
319 | fprintf (logfile, "\tSkill Required: %s", &formula->skill); |
|
|
320 | if (formula->cauldron != NULL) |
|
|
321 | fprintf (logfile, "\tCauldron: %s\n", &formula->cauldron); |
|
|
322 | fprintf (logfile, "\tDifficulty: %d\t Exp: %d\n", formula->diff, formula->exp); |
|
|
323 | } |
|
|
324 | } |
|
|
325 | else |
|
|
326 | LOG (llevError, "Can't find archetype:%s for formula %s\n", string, &formula->title); |
|
|
327 | } |
|
|
328 | } |
|
|
329 | fprintf (logfile, "\n"); |
|
|
330 | fl = fl->next; |
|
|
331 | num_ingred++; |
|
|
332 | } |
|
|
333 | } |
|
|
334 | |
|
|
335 | /* Find a treasure with a matching name. The 'depth' parameter is |
287 | /* Find a treasure with a matching name. The 'depth' parameter is |
336 | * only there to prevent infinite loops in treasure lists (a list |
288 | * only there to prevent infinite loops in treasure lists (a list |
337 | * referencing another list pointing back to the first one). */ |
289 | * referencing another list pointing back to the first one). */ |
338 | archetype * |
290 | archetype * |
339 | find_treasure_by_name (const treasure *t, const char *name, int depth) |
291 | find_treasure_by_name (const treasure *t, const char *name, int depth) |
340 | { |
292 | { |
341 | treasurelist *tl; |
|
|
342 | archetype *at; |
|
|
343 | |
|
|
344 | if (depth > 10) |
293 | if (depth > 10) |
345 | return 0; |
294 | return 0; |
346 | |
295 | |
347 | while (t) |
296 | while (t) |
348 | { |
297 | { |
349 | if (t->name) |
298 | if (t->name) |
350 | { |
299 | { |
351 | tl = find_treasurelist (t->name); |
300 | if (treasurelist *tl = treasurelist::find (t->name)) |
352 | |
|
|
353 | if (tl) |
301 | if (tl->items) |
354 | { |
|
|
355 | at = find_treasure_by_name (tl->items, name, depth + 1); |
302 | if (archetype *at = find_treasure_by_name (tl->items, name, depth + 1)) |
356 | |
|
|
357 | if (at) |
|
|
358 | return at; |
303 | return at; |
359 | } |
|
|
360 | } |
304 | } |
361 | else |
305 | else |
362 | { |
306 | { |
363 | if (t->item && !strcasecmp (t->item->clone.name, name)) |
307 | if (t->item && !strcasecmp (t->item->object::name, name)) |
364 | return t->item; |
308 | return t->item; |
365 | } |
309 | } |
366 | |
310 | |
367 | if (t->next_yes) |
311 | if (t->next_yes) |
368 | { |
|
|
369 | at = find_treasure_by_name (t->next_yes, name, depth); |
312 | if (archetype *at = find_treasure_by_name (t->next_yes, name, depth)) |
370 | if (at) |
|
|
371 | return at; |
313 | return at; |
372 | } |
|
|
373 | |
314 | |
374 | if (t->next_no) |
315 | if (t->next_no) |
375 | { |
|
|
376 | at = find_treasure_by_name (t->next_no, name, depth); |
316 | if (archetype *at = find_treasure_by_name (t->next_no, name, depth)) |
377 | if (at) |
|
|
378 | return at; |
317 | return at; |
379 | } |
318 | |
380 | t = t->next; |
319 | t = t->next; |
381 | } |
320 | } |
|
|
321 | |
382 | return 0; |
322 | return 0; |
383 | } |
323 | } |
384 | |
324 | |
385 | /* If several archetypes have the same name, the value of the first |
325 | /* If several archetypes have the same name, the value of the first |
386 | * one with that name will be returned. This happens for the |
326 | * one with that name will be returned. This happens for the |
… | |
… | |
391 | * body parts that we are looking for (e.g. big_dragon and |
331 | * body parts that we are looking for (e.g. big_dragon and |
392 | * big_dragon_worthless). */ |
332 | * big_dragon_worthless). */ |
393 | long |
333 | long |
394 | find_ingred_cost (const char *name) |
334 | find_ingred_cost (const char *name) |
395 | { |
335 | { |
396 | archetype *at; |
|
|
397 | archetype *at2; |
336 | archetype *at2; |
398 | artifactlist *al; |
337 | artifactlist *al; |
399 | artifact *art; |
338 | artifact *art; |
400 | long mult; |
339 | long mult; |
401 | char *cp; |
340 | char *cp; |
… | |
… | |
414 | name++; |
353 | name++; |
415 | else |
354 | else |
416 | mult = 1; |
355 | mult = 1; |
417 | |
356 | |
418 | /* first, try to match the name of an archetype */ |
357 | /* first, try to match the name of an archetype */ |
419 | for (at = first_archetype; at != NULL; at = at->next) |
358 | for_all_archetypes (at) |
420 | { |
359 | { |
421 | if (at->clone.title != NULL) |
360 | if (at->title != NULL) |
422 | { |
361 | { |
423 | /* inefficient, but who cares? */ |
362 | /* inefficient, but who cares? */ |
424 | sprintf (part1, "%s %s", &at->clone.name, &at->clone.title); |
363 | sprintf (part1, "%s %s", &at->object::name, &at->title); |
425 | if (!strcasecmp (part1, name)) |
364 | if (!strcasecmp (part1, name)) |
426 | return mult * at->clone.value; |
365 | return mult * at->value; |
427 | } |
366 | } |
428 | if (!strcasecmp (at->clone.name, name)) |
367 | if (!strcasecmp (at->object::name, name)) |
429 | return mult * at->clone.value; |
368 | return mult * at->value; |
430 | } |
369 | } |
431 | |
370 | |
432 | /* second, try to match an artifact ("arch of something") */ |
371 | /* second, try to match an artifact ("arch of something") */ |
433 | cp = strstr (name, " of "); |
372 | cp = strstr (name, " of "); |
434 | if (cp != NULL) |
373 | if (cp != NULL) |
435 | { |
374 | { |
436 | strcpy (part1, name); |
375 | strcpy (part1, name); |
437 | part1[cp - name] = '\0'; |
376 | part1[cp - name] = '\0'; |
438 | strcpy (part2, cp + 4); |
377 | strcpy (part2, cp + 4); |
|
|
378 | |
439 | /* find the first archetype matching the first part of the name */ |
379 | /* find the first archetype matching the first part of the name */ |
440 | for (at = first_archetype; at != NULL; at = at->next) |
380 | for_all_archetypes (at) |
441 | if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL) |
381 | if (at->object::name.eq_nc (part1) && !at->title) |
442 | break; |
|
|
443 | if (at != NULL) |
|
|
444 | { |
382 | { |
445 | /* find the first artifact derived from that archetype (same type) */ |
383 | /* find the first artifact derived from that archetype (same type) */ |
446 | for (al = first_artifactlist; al != NULL; al = al->next) |
384 | for (al = first_artifactlist; al; al = al->next) |
447 | if (al->type == at->clone.type) |
385 | if (al->type == at->type) |
448 | { |
386 | { |
449 | for (art = al->items; art != NULL; art = art->next) |
387 | for (art = al->items; art; art = art->next) |
450 | if (!strcasecmp (art->item->name, part2)) |
388 | if (!strcasecmp (art->item->name, part2)) |
451 | return mult * at->clone.value * art->item->value; |
389 | return mult * at->value * art->item->value; |
452 | } |
390 | } |
453 | } |
391 | } |
454 | } |
392 | } |
455 | |
393 | |
456 | /* third, try to match a body part ("arch's something") */ |
394 | /* third, try to match a body part ("arch's something") */ |
457 | cp = strstr (name, "'s "); |
395 | cp = strstr (name, "'s "); |
458 | if (cp) |
396 | if (cp) |
459 | { |
397 | { |
460 | strcpy (part1, name); |
398 | strcpy (part1, name); |
461 | part1[cp - name] = '\0'; |
399 | part1[cp - name] = '\0'; |
462 | strcpy (part2, cp + 3); |
400 | strcpy (part2, cp + 3); |
463 | /* examine all archetypes matching the first part of the name */ |
401 | /* examine all archetypes matching the first part of the name */ |
464 | for (at = first_archetype; at != NULL; at = at->next) |
402 | for_all_archetypes (at) |
465 | if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL) |
403 | if (at->object::name.eq_nc (part1) && !at->title) |
466 | { |
404 | { |
467 | if (at->clone.randomitems != NULL) |
405 | if (at->randomitems) |
468 | { |
406 | { |
469 | at2 = find_treasure_by_name (at->clone.randomitems->items, part2, 0); |
407 | at2 = find_treasure_by_name (at->randomitems->items, part2, 0); |
470 | if (at2) |
408 | if (at2) |
471 | return mult * at2->clone.value * isqrt (at->clone.level * 2); |
409 | return mult * at2->value * isqrt (at->level * 2); |
472 | } |
410 | } |
473 | } |
411 | } |
474 | } |
412 | } |
475 | |
413 | |
476 | /* failed to find any matching items -- formula should be checked */ |
414 | /* failed to find any matching items -- formula should be checked */ |
477 | return -1; |
415 | return -1; |
478 | } |
416 | } |
479 | |
417 | |
480 | /* code copied from dump_alchemy() and modified by Raphael Quinet */ |
|
|
481 | void |
|
|
482 | dump_alchemy_costs (void) |
|
|
483 | { |
|
|
484 | recipelist *fl = formulalist; |
|
|
485 | recipe *formula = NULL; |
|
|
486 | linked_char *next; |
|
|
487 | int num_ingred = 1; |
|
|
488 | int num_errors = 0; |
|
|
489 | long cost; |
|
|
490 | long tcost; |
|
|
491 | |
|
|
492 | fprintf (logfile, "\n"); |
|
|
493 | while (fl) |
|
|
494 | { |
|
|
495 | fprintf (logfile, "\n Formulae with %d ingredient%s %d Formulae with total_chance=%d\n", |
|
|
496 | num_ingred, num_ingred > 1 ? "s." : ".", fl->number, fl->total_chance); |
|
|
497 | for (formula = fl->items; formula != NULL; formula = formula->next) |
|
|
498 | { |
|
|
499 | artifact *art = NULL; |
|
|
500 | archetype *at = NULL; |
|
|
501 | char buf[MAX_BUF]; |
|
|
502 | size_t i; |
|
|
503 | |
|
|
504 | for (i = 0; i < formula->arch_names; i++) |
|
|
505 | { |
|
|
506 | const char *string = formula->arch_name[i]; |
|
|
507 | |
|
|
508 | if ((at = archetype::find (string)) != NULL) |
|
|
509 | { |
|
|
510 | art = locate_recipe_artifact (formula, i); |
|
|
511 | if (!art && strcmp (formula->title, "NONE")) |
|
|
512 | LOG (llevError, "Formula %s has no artifact\n", &formula->title); |
|
|
513 | else |
|
|
514 | { |
|
|
515 | if (!strcmp (formula->title, "NONE")) |
|
|
516 | sprintf (buf, "%s", string); |
|
|
517 | else |
|
|
518 | sprintf (buf, "%s of %s", string, &formula->title); |
|
|
519 | fprintf (logfile, "\n%-40s bookchance %3d skill %s\n", buf, formula->chance, &(formula->skill)); |
|
|
520 | if (formula->ingred != NULL) |
|
|
521 | { |
|
|
522 | tcost = 0; |
|
|
523 | for (next = formula->ingred; next != NULL; next = next->next) |
|
|
524 | { |
|
|
525 | cost = find_ingred_cost (next->name); |
|
|
526 | if (cost < 0) |
|
|
527 | num_errors++; |
|
|
528 | fprintf (logfile, "\t%-33s%5ld\n", &next->name, cost); |
|
|
529 | if (cost < 0 || tcost < 0) |
|
|
530 | tcost = -1; |
|
|
531 | else |
|
|
532 | tcost += cost; |
|
|
533 | } |
|
|
534 | if (art != NULL && art->item != NULL) |
|
|
535 | cost = at->clone.value * art->item->value; |
|
|
536 | else |
|
|
537 | cost = at->clone.value; |
|
|
538 | fprintf (logfile, "\t\tBuying result costs: %5ld", cost); |
|
|
539 | if (formula->yield > 1) |
|
|
540 | { |
|
|
541 | fprintf (logfile, " to %ld (max %d items)\n", cost * formula->yield, formula->yield); |
|
|
542 | cost = cost * (formula->yield + 1L) / 2L; |
|
|
543 | } |
|
|
544 | else |
|
|
545 | fprintf (logfile, "\n"); |
|
|
546 | fprintf (logfile, "\t\tIngredients cost: %5ld\n\t\tComment: ", tcost); |
|
|
547 | if (tcost < 0) |
|
|
548 | fprintf (logfile, "Could not find some ingredients. Check the formula!\n"); |
|
|
549 | else if (tcost > cost) |
|
|
550 | fprintf (logfile, "Ingredients are much too expensive. Useless formula.\n"); |
|
|
551 | else if (tcost * 2L > cost) |
|
|
552 | fprintf (logfile, "Ingredients are too expensive.\n"); |
|
|
553 | else if (tcost * 10L < cost) |
|
|
554 | fprintf (logfile, "Ingredients are too cheap.\n"); |
|
|
555 | else |
|
|
556 | fprintf (logfile, "OK.\n"); |
|
|
557 | } |
|
|
558 | } |
|
|
559 | } |
|
|
560 | else |
|
|
561 | LOG (llevError, "Can't find archetype:%s for formula %s\n", string, &formula->title); |
|
|
562 | } |
|
|
563 | } |
|
|
564 | fprintf (logfile, "\n"); |
|
|
565 | fl = fl->next; |
|
|
566 | num_ingred++; |
|
|
567 | } |
|
|
568 | if (num_errors > 0) |
|
|
569 | fprintf (logfile, "WARNING: %d objects required by the formulae do not exist in the game.\n", num_errors); |
|
|
570 | } |
|
|
571 | |
|
|
572 | const char * |
418 | const char * |
573 | ingred_name (const char *name) |
419 | ingred_name (const char *name) |
574 | { |
420 | { |
575 | const char *cp = name; |
421 | const char *cp = name; |
576 | |
422 | |
577 | if (atoi (cp)) |
423 | if (atoi (cp)) |
578 | cp = strchr (cp, ' ') + 1; |
424 | cp = strchr (cp, ' ') + 1; |
|
|
425 | |
579 | return cp; |
426 | return cp; |
580 | } |
427 | } |
581 | |
428 | |
582 | /* strtoint() - we use this to convert buf into an integer |
429 | /* strtoint() - we use this to convert buf into an integer |
583 | * equal to the coadded sum of the (lowercase) character |
430 | * equal to the coadded sum of the (lowercase) character |
… | |
… | |
603 | locate_recipe_artifact (const recipe *rp, size_t idx) |
450 | locate_recipe_artifact (const recipe *rp, size_t idx) |
604 | { |
451 | { |
605 | archetype *at = archetype::find (rp->arch_name [idx]); |
452 | archetype *at = archetype::find (rp->arch_name [idx]); |
606 | |
453 | |
607 | if (at) |
454 | if (at) |
608 | if (artifactlist *al = find_artifactlist (at->clone.type)) |
455 | if (artifactlist *al = find_artifactlist (at->type)) |
609 | for (artifact *art = al->items; art; art = art->next) |
456 | for (artifact *art = al->items; art; art = art->next) |
610 | if (art->item->name == rp->title) |
457 | if (art->item->name == rp->title) |
611 | return art; |
458 | return art; |
612 | |
459 | |
613 | return 0; |
460 | return 0; |