1 | /* |
1 | /* |
2 | * This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT 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 | * Crossfire TRT is free software; you can redistribute it and/or modify it |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * under the terms of the GNU General Public License as published by the Free |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * Software Foundation; either version 2 of the License, or (at your option) |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, but |
13 | * This program is distributed in the hope that it will be useful, |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * 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 along |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 |
19 | * and the GNU General Public License along with this program. If not, see |
20 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 | * <http://www.gnu.org/licenses/>. |
21 | * |
21 | * |
22 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | /* 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 |
26 | * could go into server/alchemy, but I left it here just in case it proves |
26 | * could go into server/alchemy, but I left it here just in case it proves |
27 | * more generally useful. |
27 | * more generally useful. |
… | |
… | |
111 | size_t i; |
111 | size_t i; |
112 | int result = 1; |
112 | int result = 1; |
113 | |
113 | |
114 | for (i = 0; i < rp->arch_names; i++) |
114 | for (i = 0; i < rp->arch_names; i++) |
115 | { |
115 | { |
116 | if (archetype::find (rp->arch_name[i]) != NULL) |
116 | if (archetype::find (rp->arch_name[i])) |
117 | { |
117 | { |
118 | artifact *art = locate_recipe_artifact (rp, i); |
118 | artifact *art = locate_recipe_artifact (rp, i); |
119 | |
119 | |
120 | if (!art && strcmp (rp->title, "NONE") != 0) |
120 | if (!art && rp->title != shstr_NONE) |
121 | { |
121 | { |
122 | 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); |
123 | result = 0; |
123 | result = 0; |
124 | } |
124 | } |
125 | } |
125 | } |
… | |
… | |
283 | |
283 | |
284 | LOG (llevDebug, "done.\n"); |
284 | LOG (llevDebug, "done.\n"); |
285 | |
285 | |
286 | } |
286 | } |
287 | |
287 | |
288 | /* Borrowed (again) from the artifacts code for this */ |
|
|
289 | |
|
|
290 | void |
|
|
291 | dump_alchemy (void) |
|
|
292 | { |
|
|
293 | recipelist *fl = formulalist; |
|
|
294 | recipe *formula = NULL; |
|
|
295 | linked_char *next; |
|
|
296 | int num_ingred = 1; |
|
|
297 | |
|
|
298 | fprintf (logfile, "\n"); |
|
|
299 | while (fl) |
|
|
300 | { |
|
|
301 | fprintf (logfile, "\n Formulae with %d ingredient%s %d Formulae with total_chance=%d\n", |
|
|
302 | num_ingred, num_ingred > 1 ? "s." : ".", fl->number, fl->total_chance); |
|
|
303 | for (formula = fl->items; formula; formula = formula->next) |
|
|
304 | { |
|
|
305 | artifact *art = NULL; |
|
|
306 | char buf[MAX_BUF]; |
|
|
307 | size_t i; |
|
|
308 | |
|
|
309 | for (i = 0; i < formula->arch_names; i++) |
|
|
310 | { |
|
|
311 | const char *string = formula->arch_name[i]; |
|
|
312 | |
|
|
313 | if (archetype::find (string) != NULL) |
|
|
314 | { |
|
|
315 | art = locate_recipe_artifact (formula, i); |
|
|
316 | if (!art && strcmp (formula->title, "NONE")) |
|
|
317 | LOG (llevError, "Formula %s has no artifact!\n", &formula->title); |
|
|
318 | else |
|
|
319 | { |
|
|
320 | if (strcmp (formula->title, "NONE")) |
|
|
321 | sprintf (buf, "%s of %s", string, &formula->title); |
|
|
322 | else |
|
|
323 | sprintf (buf, "%s", string); |
|
|
324 | fprintf (logfile, "%-30s(%d) bookchance %3d ", buf, formula->index, formula->chance); |
|
|
325 | fprintf (logfile, "skill %s", &formula->skill); |
|
|
326 | fprintf (logfile, "\n"); |
|
|
327 | if (formula->ingred != NULL) |
|
|
328 | { |
|
|
329 | int nval = 0, tval = 0; |
|
|
330 | |
|
|
331 | fprintf (logfile, "\tIngred: "); |
|
|
332 | for (next = formula->ingred; next != NULL; next = next->next) |
|
|
333 | { |
|
|
334 | if (nval != 0) |
|
|
335 | fprintf (logfile, ","); |
|
|
336 | fprintf (logfile, "%s(%d)", &next->name, (nval = strtoint (next->name))); |
|
|
337 | tval += nval; |
|
|
338 | } |
|
|
339 | fprintf (logfile, "\n"); |
|
|
340 | if (tval != formula->index) |
|
|
341 | fprintf (logfile, "WARNING:ingredient list and formula values not equal.\n"); |
|
|
342 | } |
|
|
343 | if (formula->skill != NULL) |
|
|
344 | fprintf (logfile, "\tSkill Required: %s", &formula->skill); |
|
|
345 | if (formula->cauldron != NULL) |
|
|
346 | fprintf (logfile, "\tCauldron: %s\n", &formula->cauldron); |
|
|
347 | fprintf (logfile, "\tDifficulty: %d\t Exp: %d\n", formula->diff, formula->exp); |
|
|
348 | } |
|
|
349 | } |
|
|
350 | else |
|
|
351 | LOG (llevError, "Can't find archetype:%s for formula %s\n", string, &formula->title); |
|
|
352 | } |
|
|
353 | } |
|
|
354 | fprintf (logfile, "\n"); |
|
|
355 | fl = fl->next; |
|
|
356 | num_ingred++; |
|
|
357 | } |
|
|
358 | } |
|
|
359 | |
|
|
360 | /* Find a treasure with a matching name. The 'depth' parameter is |
288 | /* Find a treasure with a matching name. The 'depth' parameter is |
361 | * only there to prevent infinite loops in treasure lists (a list |
289 | * only there to prevent infinite loops in treasure lists (a list |
362 | * referencing another list pointing back to the first one). */ |
290 | * referencing another list pointing back to the first one). */ |
363 | archetype * |
291 | archetype * |
364 | 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) |
… | |
… | |
375 | if (archetype *at = find_treasure_by_name (tl->items, name, depth + 1)) |
303 | if (archetype *at = find_treasure_by_name (tl->items, name, depth + 1)) |
376 | return at; |
304 | return at; |
377 | } |
305 | } |
378 | else |
306 | else |
379 | { |
307 | { |
380 | if (t->item && !strcasecmp (t->item->clone.name, name)) |
308 | if (t->item && !strcasecmp (t->item->object::name, name)) |
381 | return t->item; |
309 | return t->item; |
382 | } |
310 | } |
383 | |
311 | |
384 | if (t->next_yes) |
312 | if (t->next_yes) |
385 | if (archetype *at = find_treasure_by_name (t->next_yes, name, depth)) |
313 | if (archetype *at = find_treasure_by_name (t->next_yes, name, depth)) |
… | |
… | |
404 | * body parts that we are looking for (e.g. big_dragon and |
332 | * body parts that we are looking for (e.g. big_dragon and |
405 | * big_dragon_worthless). */ |
333 | * big_dragon_worthless). */ |
406 | long |
334 | long |
407 | find_ingred_cost (const char *name) |
335 | find_ingred_cost (const char *name) |
408 | { |
336 | { |
409 | archetype *at; |
|
|
410 | archetype *at2; |
337 | archetype *at2; |
411 | artifactlist *al; |
338 | artifactlist *al; |
412 | artifact *art; |
339 | artifact *art; |
413 | long mult; |
340 | long mult; |
414 | char *cp; |
341 | char *cp; |
… | |
… | |
427 | name++; |
354 | name++; |
428 | else |
355 | else |
429 | mult = 1; |
356 | mult = 1; |
430 | |
357 | |
431 | /* first, try to match the name of an archetype */ |
358 | /* first, try to match the name of an archetype */ |
432 | for (at = first_archetype; at != NULL; at = at->next) |
359 | for_all_archetypes (at) |
433 | { |
360 | { |
434 | if (at->clone.title != NULL) |
361 | if (at->title != NULL) |
435 | { |
362 | { |
436 | /* inefficient, but who cares? */ |
363 | /* inefficient, but who cares? */ |
437 | sprintf (part1, "%s %s", &at->clone.name, &at->clone.title); |
364 | sprintf (part1, "%s %s", &at->object::name, &at->title); |
438 | if (!strcasecmp (part1, name)) |
365 | if (!strcasecmp (part1, name)) |
439 | return mult * at->clone.value; |
366 | return mult * at->value; |
440 | } |
367 | } |
441 | if (!strcasecmp (at->clone.name, name)) |
368 | if (!strcasecmp (at->object::name, name)) |
442 | return mult * at->clone.value; |
369 | return mult * at->value; |
443 | } |
370 | } |
444 | |
371 | |
445 | /* second, try to match an artifact ("arch of something") */ |
372 | /* second, try to match an artifact ("arch of something") */ |
446 | cp = strstr (name, " of "); |
373 | cp = strstr (name, " of "); |
447 | if (cp != NULL) |
374 | if (cp != NULL) |
448 | { |
375 | { |
449 | strcpy (part1, name); |
376 | strcpy (part1, name); |
450 | part1[cp - name] = '\0'; |
377 | part1[cp - name] = '\0'; |
451 | strcpy (part2, cp + 4); |
378 | strcpy (part2, cp + 4); |
|
|
379 | |
452 | /* find the first archetype matching the first part of the name */ |
380 | /* find the first archetype matching the first part of the name */ |
453 | for (at = first_archetype; at; at = at->next) |
381 | for_all_archetypes (at) |
454 | if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL) |
382 | if (at->object::name.eq_nc (part1) && !at->title) |
455 | break; |
|
|
456 | if (at != NULL) |
|
|
457 | { |
383 | { |
458 | /* find the first artifact derived from that archetype (same type) */ |
384 | /* find the first artifact derived from that archetype (same type) */ |
459 | for (al = first_artifactlist; al; al = al->next) |
385 | for (al = first_artifactlist; al; al = al->next) |
460 | if (al->type == at->clone.type) |
386 | if (al->type == at->type) |
461 | { |
387 | { |
462 | for (art = al->items; art; art = art->next) |
388 | for (art = al->items; art; art = art->next) |
463 | if (!strcasecmp (art->item->name, part2)) |
389 | if (!strcasecmp (art->item->name, part2)) |
464 | return mult * at->clone.value * art->item->value; |
390 | return mult * at->value * art->item->value; |
465 | } |
391 | } |
466 | } |
392 | } |
467 | } |
393 | } |
468 | |
394 | |
469 | /* third, try to match a body part ("arch's something") */ |
395 | /* third, try to match a body part ("arch's something") */ |
470 | cp = strstr (name, "'s "); |
396 | cp = strstr (name, "'s "); |
471 | if (cp) |
397 | if (cp) |
472 | { |
398 | { |
473 | strcpy (part1, name); |
399 | strcpy (part1, name); |
474 | part1[cp - name] = '\0'; |
400 | part1[cp - name] = '\0'; |
475 | strcpy (part2, cp + 3); |
401 | strcpy (part2, cp + 3); |
476 | /* examine all archetypes matching the first part of the name */ |
402 | /* examine all archetypes matching the first part of the name */ |
477 | for (at = first_archetype; at; at = at->next) |
403 | for_all_archetypes (at) |
478 | if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL) |
404 | if (at->object::name.eq_nc (part1) && !at->title) |
479 | { |
405 | { |
480 | if (at->clone.randomitems) |
406 | if (at->randomitems) |
481 | { |
407 | { |
482 | at2 = find_treasure_by_name (at->clone.randomitems->items, part2, 0); |
408 | at2 = find_treasure_by_name (at->randomitems->items, part2, 0); |
483 | if (at2) |
409 | if (at2) |
484 | return mult * at2->clone.value * isqrt (at->clone.level * 2); |
410 | return mult * at2->value * isqrt (at->level * 2); |
485 | } |
411 | } |
486 | } |
412 | } |
487 | } |
413 | } |
488 | |
414 | |
489 | /* failed to find any matching items -- formula should be checked */ |
415 | /* failed to find any matching items -- formula should be checked */ |
490 | return -1; |
416 | return -1; |
491 | } |
417 | } |
492 | |
418 | |
493 | /* code copied from dump_alchemy() and modified by Raphael Quinet */ |
|
|
494 | void |
|
|
495 | dump_alchemy_costs (void) |
|
|
496 | { |
|
|
497 | recipelist *fl = formulalist; |
|
|
498 | recipe *formula = NULL; |
|
|
499 | linked_char *next; |
|
|
500 | int num_ingred = 1; |
|
|
501 | int num_errors = 0; |
|
|
502 | long cost; |
|
|
503 | long tcost; |
|
|
504 | |
|
|
505 | fprintf (logfile, "\n"); |
|
|
506 | while (fl) |
|
|
507 | { |
|
|
508 | fprintf (logfile, "\n Formulae with %d ingredient%s %d Formulae with total_chance=%d\n", |
|
|
509 | num_ingred, num_ingred > 1 ? "s." : ".", fl->number, fl->total_chance); |
|
|
510 | for (formula = fl->items; formula; formula = formula->next) |
|
|
511 | { |
|
|
512 | artifact *art = NULL; |
|
|
513 | archetype *at = NULL; |
|
|
514 | char buf[MAX_BUF]; |
|
|
515 | size_t i; |
|
|
516 | |
|
|
517 | for (i = 0; i < formula->arch_names; i++) |
|
|
518 | { |
|
|
519 | const char *string = formula->arch_name[i]; |
|
|
520 | |
|
|
521 | if ((at = archetype::find (string)) != NULL) |
|
|
522 | { |
|
|
523 | art = locate_recipe_artifact (formula, i); |
|
|
524 | if (!art && strcmp (formula->title, "NONE")) |
|
|
525 | LOG (llevError, "Formula %s has no artifact\n", &formula->title); |
|
|
526 | else |
|
|
527 | { |
|
|
528 | if (!strcmp (formula->title, "NONE")) |
|
|
529 | sprintf (buf, "%s", string); |
|
|
530 | else |
|
|
531 | sprintf (buf, "%s of %s", string, &formula->title); |
|
|
532 | fprintf (logfile, "\n%-40s bookchance %3d skill %s\n", buf, formula->chance, &(formula->skill)); |
|
|
533 | if (formula->ingred != NULL) |
|
|
534 | { |
|
|
535 | tcost = 0; |
|
|
536 | for (next = formula->ingred; next != NULL; next = next->next) |
|
|
537 | { |
|
|
538 | cost = find_ingred_cost (next->name); |
|
|
539 | if (cost < 0) |
|
|
540 | num_errors++; |
|
|
541 | fprintf (logfile, "\t%-33s%5ld\n", &next->name, cost); |
|
|
542 | if (cost < 0 || tcost < 0) |
|
|
543 | tcost = -1; |
|
|
544 | else |
|
|
545 | tcost += cost; |
|
|
546 | } |
|
|
547 | if (art != NULL && art->item != NULL) |
|
|
548 | cost = at->clone.value * art->item->value; |
|
|
549 | else |
|
|
550 | cost = at->clone.value; |
|
|
551 | fprintf (logfile, "\t\tBuying result costs: %5ld", cost); |
|
|
552 | if (formula->yield > 1) |
|
|
553 | { |
|
|
554 | fprintf (logfile, " to %ld (max %d items)\n", cost * formula->yield, formula->yield); |
|
|
555 | cost = cost * (formula->yield + 1L) / 2L; |
|
|
556 | } |
|
|
557 | else |
|
|
558 | fprintf (logfile, "\n"); |
|
|
559 | fprintf (logfile, "\t\tIngredients cost: %5ld\n\t\tComment: ", tcost); |
|
|
560 | if (tcost < 0) |
|
|
561 | fprintf (logfile, "Could not find some ingredients. Check the formula!\n"); |
|
|
562 | else if (tcost > cost) |
|
|
563 | fprintf (logfile, "Ingredients are much too expensive. Useless formula.\n"); |
|
|
564 | else if (tcost * 2L > cost) |
|
|
565 | fprintf (logfile, "Ingredients are too expensive.\n"); |
|
|
566 | else if (tcost * 10L < cost) |
|
|
567 | fprintf (logfile, "Ingredients are too cheap.\n"); |
|
|
568 | else |
|
|
569 | fprintf (logfile, "OK.\n"); |
|
|
570 | } |
|
|
571 | } |
|
|
572 | } |
|
|
573 | else |
|
|
574 | LOG (llevError, "Can't find archetype:%s for formula %s\n", string, &formula->title); |
|
|
575 | } |
|
|
576 | } |
|
|
577 | fprintf (logfile, "\n"); |
|
|
578 | fl = fl->next; |
|
|
579 | num_ingred++; |
|
|
580 | } |
|
|
581 | if (num_errors > 0) |
|
|
582 | fprintf (logfile, "WARNING: %d objects required by the formulae do not exist in the game.\n", num_errors); |
|
|
583 | } |
|
|
584 | |
|
|
585 | const char * |
419 | const char * |
586 | ingred_name (const char *name) |
420 | ingred_name (const char *name) |
587 | { |
421 | { |
588 | const char *cp = name; |
422 | const char *cp = name; |
589 | |
423 | |
590 | if (atoi (cp)) |
424 | if (atoi (cp)) |
591 | cp = strchr (cp, ' ') + 1; |
425 | cp = strchr (cp, ' ') + 1; |
|
|
426 | |
592 | return cp; |
427 | return cp; |
593 | } |
428 | } |
594 | |
429 | |
595 | /* strtoint() - we use this to convert buf into an integer |
430 | /* strtoint() - we use this to convert buf into an integer |
596 | * equal to the coadded sum of the (lowercase) character |
431 | * equal to the coadded sum of the (lowercase) character |
… | |
… | |
616 | locate_recipe_artifact (const recipe *rp, size_t idx) |
451 | locate_recipe_artifact (const recipe *rp, size_t idx) |
617 | { |
452 | { |
618 | archetype *at = archetype::find (rp->arch_name [idx]); |
453 | archetype *at = archetype::find (rp->arch_name [idx]); |
619 | |
454 | |
620 | if (at) |
455 | if (at) |
621 | if (artifactlist *al = find_artifactlist (at->clone.type)) |
456 | if (artifactlist *al = find_artifactlist (at->type)) |
622 | for (artifact *art = al->items; art; art = art->next) |
457 | for (artifact *art = al->items; art; art = art->next) |
623 | if (art->item->name == rp->title) |
458 | if (art->item->name == rp->title) |
624 | return art; |
459 | return art; |
625 | |
460 | |
626 | return 0; |
461 | return 0; |