|
|
1 | /* |
|
|
2 | * This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game. |
|
|
3 | * |
|
|
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
|
|
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
|
|
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
|
|
7 | * |
|
|
8 | * Crossfire TRT is free software; you can redistribute it and/or modify it |
|
|
9 | * under the terms of the GNU General Public License as published by the Free |
|
|
10 | * Software Foundation; either version 2 of the License, or (at your option) |
|
|
11 | * any later version. |
|
|
12 | * |
|
|
13 | * This program is distributed in the hope that it will be useful, but |
|
|
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
|
|
15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
|
16 | * for more details. |
|
|
17 | * |
|
|
18 | * You should have received a copy of the GNU General Public License along |
|
|
19 | * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 |
|
|
20 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
|
21 | * |
|
|
22 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
|
|
23 | */ |
|
|
24 | |
1 | /* 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 |
2 | * 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 |
3 | * more generally useful. |
27 | * more generally useful. |
4 | * |
28 | * |
5 | * Nov 1995 - file created by b.t. thomas@astro.psu.edu |
29 | * Nov 1995 - file created by b.t. thomas@astro.psu.edu |
… | |
… | |
351 | if (archetype *at = find_treasure_by_name (tl->items, name, depth + 1)) |
375 | if (archetype *at = find_treasure_by_name (tl->items, name, depth + 1)) |
352 | return at; |
376 | return at; |
353 | } |
377 | } |
354 | else |
378 | else |
355 | { |
379 | { |
356 | if (t->item && !strcasecmp (t->item->clone.name, name)) |
380 | if (t->item && !strcasecmp (t->item->object::name, name)) |
357 | return t->item; |
381 | return t->item; |
358 | } |
382 | } |
359 | |
383 | |
360 | if (t->next_yes) |
384 | if (t->next_yes) |
361 | if (archetype *at = find_treasure_by_name (t->next_yes, name, depth)) |
385 | if (archetype *at = find_treasure_by_name (t->next_yes, name, depth)) |
… | |
… | |
380 | * body parts that we are looking for (e.g. big_dragon and |
404 | * body parts that we are looking for (e.g. big_dragon and |
381 | * big_dragon_worthless). */ |
405 | * big_dragon_worthless). */ |
382 | long |
406 | long |
383 | find_ingred_cost (const char *name) |
407 | find_ingred_cost (const char *name) |
384 | { |
408 | { |
385 | archetype *at; |
|
|
386 | archetype *at2; |
409 | archetype *at2; |
387 | artifactlist *al; |
410 | artifactlist *al; |
388 | artifact *art; |
411 | artifact *art; |
389 | long mult; |
412 | long mult; |
390 | char *cp; |
413 | char *cp; |
… | |
… | |
403 | name++; |
426 | name++; |
404 | else |
427 | else |
405 | mult = 1; |
428 | mult = 1; |
406 | |
429 | |
407 | /* first, try to match the name of an archetype */ |
430 | /* first, try to match the name of an archetype */ |
408 | for (at = first_archetype; at != NULL; at = at->next) |
431 | for_all_archetypes (at) |
409 | { |
432 | { |
410 | if (at->clone.title != NULL) |
433 | if (at->title != NULL) |
411 | { |
434 | { |
412 | /* inefficient, but who cares? */ |
435 | /* inefficient, but who cares? */ |
413 | sprintf (part1, "%s %s", &at->clone.name, &at->clone.title); |
436 | sprintf (part1, "%s %s", &at->object::name, &at->title); |
414 | if (!strcasecmp (part1, name)) |
437 | if (!strcasecmp (part1, name)) |
415 | return mult * at->clone.value; |
438 | return mult * at->value; |
416 | } |
439 | } |
417 | if (!strcasecmp (at->clone.name, name)) |
440 | if (!strcasecmp (at->object::name, name)) |
418 | return mult * at->clone.value; |
441 | return mult * at->value; |
419 | } |
442 | } |
420 | |
443 | |
421 | /* second, try to match an artifact ("arch of something") */ |
444 | /* second, try to match an artifact ("arch of something") */ |
422 | cp = strstr (name, " of "); |
445 | cp = strstr (name, " of "); |
423 | if (cp != NULL) |
446 | if (cp != NULL) |
424 | { |
447 | { |
425 | strcpy (part1, name); |
448 | strcpy (part1, name); |
426 | part1[cp - name] = '\0'; |
449 | part1[cp - name] = '\0'; |
427 | strcpy (part2, cp + 4); |
450 | strcpy (part2, cp + 4); |
|
|
451 | |
428 | /* find the first archetype matching the first part of the name */ |
452 | /* find the first archetype matching the first part of the name */ |
429 | for (at = first_archetype; at; at = at->next) |
453 | for_all_archetypes (at) |
430 | if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL) |
454 | if (!strcasecmp (at->object::name, part1) && at->title == NULL) |
431 | break; |
|
|
432 | if (at != NULL) |
|
|
433 | { |
455 | { |
434 | /* find the first artifact derived from that archetype (same type) */ |
456 | /* find the first artifact derived from that archetype (same type) */ |
435 | for (al = first_artifactlist; al; al = al->next) |
457 | for (al = first_artifactlist; al; al = al->next) |
436 | if (al->type == at->clone.type) |
458 | if (al->type == at->type) |
437 | { |
459 | { |
438 | for (art = al->items; art; art = art->next) |
460 | for (art = al->items; art; art = art->next) |
439 | if (!strcasecmp (art->item->name, part2)) |
461 | if (!strcasecmp (art->item->name, part2)) |
440 | return mult * at->clone.value * art->item->value; |
462 | return mult * at->value * art->item->value; |
441 | } |
463 | } |
442 | } |
464 | } |
443 | } |
465 | } |
444 | |
466 | |
445 | /* third, try to match a body part ("arch's something") */ |
467 | /* third, try to match a body part ("arch's something") */ |
446 | cp = strstr (name, "'s "); |
468 | cp = strstr (name, "'s "); |
447 | if (cp) |
469 | if (cp) |
448 | { |
470 | { |
449 | strcpy (part1, name); |
471 | strcpy (part1, name); |
450 | part1[cp - name] = '\0'; |
472 | part1[cp - name] = '\0'; |
451 | strcpy (part2, cp + 3); |
473 | strcpy (part2, cp + 3); |
452 | /* examine all archetypes matching the first part of the name */ |
474 | /* examine all archetypes matching the first part of the name */ |
453 | for (at = first_archetype; at; at = at->next) |
475 | for_all_archetypes (at) |
454 | if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL) |
476 | if (!strcasecmp (at->object::name, part1) && at->title == NULL) |
455 | { |
477 | { |
456 | if (at->clone.randomitems) |
478 | if (at->randomitems) |
457 | { |
479 | { |
458 | at2 = find_treasure_by_name (at->clone.randomitems->items, part2, 0); |
480 | at2 = find_treasure_by_name (at->randomitems->items, part2, 0); |
459 | if (at2) |
481 | if (at2) |
460 | return mult * at2->clone.value * isqrt (at->clone.level * 2); |
482 | return mult * at2->value * isqrt (at->level * 2); |
461 | } |
483 | } |
462 | } |
484 | } |
463 | } |
485 | } |
464 | |
486 | |
465 | /* failed to find any matching items -- formula should be checked */ |
487 | /* failed to find any matching items -- formula should be checked */ |
… | |
… | |
519 | tcost = -1; |
541 | tcost = -1; |
520 | else |
542 | else |
521 | tcost += cost; |
543 | tcost += cost; |
522 | } |
544 | } |
523 | if (art != NULL && art->item != NULL) |
545 | if (art != NULL && art->item != NULL) |
524 | cost = at->clone.value * art->item->value; |
546 | cost = at->value * art->item->value; |
525 | else |
547 | else |
526 | cost = at->clone.value; |
548 | cost = at->value; |
527 | fprintf (logfile, "\t\tBuying result costs: %5ld", cost); |
549 | fprintf (logfile, "\t\tBuying result costs: %5ld", cost); |
528 | if (formula->yield > 1) |
550 | if (formula->yield > 1) |
529 | { |
551 | { |
530 | fprintf (logfile, " to %ld (max %d items)\n", cost * formula->yield, formula->yield); |
552 | fprintf (logfile, " to %ld (max %d items)\n", cost * formula->yield, formula->yield); |
531 | cost = cost * (formula->yield + 1L) / 2L; |
553 | cost = cost * (formula->yield + 1L) / 2L; |
… | |
… | |
592 | locate_recipe_artifact (const recipe *rp, size_t idx) |
614 | locate_recipe_artifact (const recipe *rp, size_t idx) |
593 | { |
615 | { |
594 | archetype *at = archetype::find (rp->arch_name [idx]); |
616 | archetype *at = archetype::find (rp->arch_name [idx]); |
595 | |
617 | |
596 | if (at) |
618 | if (at) |
597 | if (artifactlist *al = find_artifactlist (at->clone.type)) |
619 | if (artifactlist *al = find_artifactlist (at->type)) |
598 | for (artifact *art = al->items; art; art = art->next) |
620 | for (artifact *art = al->items; art; art = art->next) |
599 | if (art->item->name == rp->title) |
621 | if (art->item->name == rp->title) |
600 | return art; |
622 | return art; |
601 | |
623 | |
602 | return 0; |
624 | return 0; |