ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/recipe.C
(Generate patch)

Comparing deliantra/server/common/recipe.C (file contents):
Revision 1.19 by root, Mon Apr 16 06:23:40 2007 UTC vs.
Revision 1.23 by root, Sun Jul 1 05:00:18 2007 UTC

1/*
2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
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
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 <crossfire@schmorp.de>
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
351 if (archetype *at = find_treasure_by_name (tl->items, name, depth + 1)) 374 if (archetype *at = find_treasure_by_name (tl->items, name, depth + 1))
352 return at; 375 return at;
353 } 376 }
354 else 377 else
355 { 378 {
356 if (t->item && !strcasecmp (t->item->clone.name, name)) 379 if (t->item && !strcasecmp (t->item->object::name, name))
357 return t->item; 380 return t->item;
358 } 381 }
359 382
360 if (t->next_yes) 383 if (t->next_yes)
361 if (archetype *at = find_treasure_by_name (t->next_yes, name, depth)) 384 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 403 * body parts that we are looking for (e.g. big_dragon and
381 * big_dragon_worthless). */ 404 * big_dragon_worthless). */
382long 405long
383find_ingred_cost (const char *name) 406find_ingred_cost (const char *name)
384{ 407{
385 archetype *at;
386 archetype *at2; 408 archetype *at2;
387 artifactlist *al; 409 artifactlist *al;
388 artifact *art; 410 artifact *art;
389 long mult; 411 long mult;
390 char *cp; 412 char *cp;
403 name++; 425 name++;
404 else 426 else
405 mult = 1; 427 mult = 1;
406 428
407 /* first, try to match the name of an archetype */ 429 /* first, try to match the name of an archetype */
408 for (at = first_archetype; at != NULL; at = at->next) 430 for_all_archetypes (at)
409 { 431 {
410 if (at->clone.title != NULL) 432 if (at->title != NULL)
411 { 433 {
412 /* inefficient, but who cares? */ 434 /* inefficient, but who cares? */
413 sprintf (part1, "%s %s", &at->clone.name, &at->clone.title); 435 sprintf (part1, "%s %s", &at->object::name, &at->title);
414 if (!strcasecmp (part1, name)) 436 if (!strcasecmp (part1, name))
415 return mult * at->clone.value; 437 return mult * at->value;
416 } 438 }
417 if (!strcasecmp (at->clone.name, name)) 439 if (!strcasecmp (at->object::name, name))
418 return mult * at->clone.value; 440 return mult * at->value;
419 } 441 }
420 442
421 /* second, try to match an artifact ("arch of something") */ 443 /* second, try to match an artifact ("arch of something") */
422 cp = strstr (name, " of "); 444 cp = strstr (name, " of ");
423 if (cp != NULL) 445 if (cp != NULL)
424 { 446 {
425 strcpy (part1, name); 447 strcpy (part1, name);
426 part1[cp - name] = '\0'; 448 part1[cp - name] = '\0';
427 strcpy (part2, cp + 4); 449 strcpy (part2, cp + 4);
450
428 /* find the first archetype matching the first part of the name */ 451 /* find the first archetype matching the first part of the name */
429 for (at = first_archetype; at; at = at->next) 452 for_all_archetypes (at)
430 if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL) 453 if (!strcasecmp (at->object::name, part1) && at->title == NULL)
431 break;
432 if (at != NULL)
433 { 454 {
434 /* find the first artifact derived from that archetype (same type) */ 455 /* find the first artifact derived from that archetype (same type) */
435 for (al = first_artifactlist; al; al = al->next) 456 for (al = first_artifactlist; al; al = al->next)
436 if (al->type == at->clone.type) 457 if (al->type == at->type)
437 { 458 {
438 for (art = al->items; art; art = art->next) 459 for (art = al->items; art; art = art->next)
439 if (!strcasecmp (art->item->name, part2)) 460 if (!strcasecmp (art->item->name, part2))
440 return mult * at->clone.value * art->item->value; 461 return mult * at->value * art->item->value;
441 } 462 }
442 } 463 }
443 } 464 }
444 465
445 /* third, try to match a body part ("arch's something") */ 466 /* third, try to match a body part ("arch's something") */
446 cp = strstr (name, "'s "); 467 cp = strstr (name, "'s ");
447 if (cp) 468 if (cp)
448 { 469 {
449 strcpy (part1, name); 470 strcpy (part1, name);
450 part1[cp - name] = '\0'; 471 part1[cp - name] = '\0';
451 strcpy (part2, cp + 3); 472 strcpy (part2, cp + 3);
452 /* examine all archetypes matching the first part of the name */ 473 /* examine all archetypes matching the first part of the name */
453 for (at = first_archetype; at; at = at->next) 474 for_all_archetypes (at)
454 if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL) 475 if (!strcasecmp (at->object::name, part1) && at->title == NULL)
455 { 476 {
456 if (at->clone.randomitems) 477 if (at->randomitems)
457 { 478 {
458 at2 = find_treasure_by_name (at->clone.randomitems->items, part2, 0); 479 at2 = find_treasure_by_name (at->randomitems->items, part2, 0);
459 if (at2) 480 if (at2)
460 return mult * at2->clone.value * isqrt (at->clone.level * 2); 481 return mult * at2->value * isqrt (at->level * 2);
461 } 482 }
462 } 483 }
463 } 484 }
464 485
465 /* failed to find any matching items -- formula should be checked */ 486 /* failed to find any matching items -- formula should be checked */
519 tcost = -1; 540 tcost = -1;
520 else 541 else
521 tcost += cost; 542 tcost += cost;
522 } 543 }
523 if (art != NULL && art->item != NULL) 544 if (art != NULL && art->item != NULL)
524 cost = at->clone.value * art->item->value; 545 cost = at->value * art->item->value;
525 else 546 else
526 cost = at->clone.value; 547 cost = at->value;
527 fprintf (logfile, "\t\tBuying result costs: %5ld", cost); 548 fprintf (logfile, "\t\tBuying result costs: %5ld", cost);
528 if (formula->yield > 1) 549 if (formula->yield > 1)
529 { 550 {
530 fprintf (logfile, " to %ld (max %d items)\n", cost * formula->yield, formula->yield); 551 fprintf (logfile, " to %ld (max %d items)\n", cost * formula->yield, formula->yield);
531 cost = cost * (formula->yield + 1L) / 2L; 552 cost = cost * (formula->yield + 1L) / 2L;
592locate_recipe_artifact (const recipe *rp, size_t idx) 613locate_recipe_artifact (const recipe *rp, size_t idx)
593{ 614{
594 archetype *at = archetype::find (rp->arch_name [idx]); 615 archetype *at = archetype::find (rp->arch_name [idx]);
595 616
596 if (at) 617 if (at)
597 if (artifactlist *al = find_artifactlist (at->clone.type)) 618 if (artifactlist *al = find_artifactlist (at->type))
598 for (artifact *art = al->items; art; art = art->next) 619 for (artifact *art = al->items; art; art = art->next)
599 if (art->item->name == rp->title) 620 if (art->item->name == rp->title)
600 return art; 621 return art;
601 622
602 return 0; 623 return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines