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.20 by root, Thu May 17 21:32:08 2007 UTC vs.
Revision 1.23 by root, Sun Jul 1 05:00:18 2007 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game 2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
5 * Copyright (C) Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (C) Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 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 9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version. 11 * (at your 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 GNU General Public License
19 * along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * 20 *
22 * The authors can be reached via e-mail at <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <crossfire@schmorp.de>
23 */ 22 */
24 23
25/* 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
26 * 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
27 * more generally useful. 26 * more generally useful.
375 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))
376 return at; 375 return at;
377 } 376 }
378 else 377 else
379 { 378 {
380 if (t->item && !strcasecmp (t->item->clone.name, name)) 379 if (t->item && !strcasecmp (t->item->object::name, name))
381 return t->item; 380 return t->item;
382 } 381 }
383 382
384 if (t->next_yes) 383 if (t->next_yes)
385 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))
404 * 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
405 * big_dragon_worthless). */ 404 * big_dragon_worthless). */
406long 405long
407find_ingred_cost (const char *name) 406find_ingred_cost (const char *name)
408{ 407{
409 archetype *at;
410 archetype *at2; 408 archetype *at2;
411 artifactlist *al; 409 artifactlist *al;
412 artifact *art; 410 artifact *art;
413 long mult; 411 long mult;
414 char *cp; 412 char *cp;
427 name++; 425 name++;
428 else 426 else
429 mult = 1; 427 mult = 1;
430 428
431 /* first, try to match the name of an archetype */ 429 /* first, try to match the name of an archetype */
432 for (at = first_archetype; at != NULL; at = at->next) 430 for_all_archetypes (at)
433 { 431 {
434 if (at->clone.title != NULL) 432 if (at->title != NULL)
435 { 433 {
436 /* inefficient, but who cares? */ 434 /* inefficient, but who cares? */
437 sprintf (part1, "%s %s", &at->clone.name, &at->clone.title); 435 sprintf (part1, "%s %s", &at->object::name, &at->title);
438 if (!strcasecmp (part1, name)) 436 if (!strcasecmp (part1, name))
439 return mult * at->clone.value; 437 return mult * at->value;
440 } 438 }
441 if (!strcasecmp (at->clone.name, name)) 439 if (!strcasecmp (at->object::name, name))
442 return mult * at->clone.value; 440 return mult * at->value;
443 } 441 }
444 442
445 /* second, try to match an artifact ("arch of something") */ 443 /* second, try to match an artifact ("arch of something") */
446 cp = strstr (name, " of "); 444 cp = strstr (name, " of ");
447 if (cp != NULL) 445 if (cp != NULL)
448 { 446 {
449 strcpy (part1, name); 447 strcpy (part1, name);
450 part1[cp - name] = '\0'; 448 part1[cp - name] = '\0';
451 strcpy (part2, cp + 4); 449 strcpy (part2, cp + 4);
450
452 /* find the first archetype matching the first part of the name */ 451 /* find the first archetype matching the first part of the name */
453 for (at = first_archetype; at; at = at->next) 452 for_all_archetypes (at)
454 if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL) 453 if (!strcasecmp (at->object::name, part1) && at->title == NULL)
455 break;
456 if (at != NULL)
457 { 454 {
458 /* find the first artifact derived from that archetype (same type) */ 455 /* find the first artifact derived from that archetype (same type) */
459 for (al = first_artifactlist; al; al = al->next) 456 for (al = first_artifactlist; al; al = al->next)
460 if (al->type == at->clone.type) 457 if (al->type == at->type)
461 { 458 {
462 for (art = al->items; art; art = art->next) 459 for (art = al->items; art; art = art->next)
463 if (!strcasecmp (art->item->name, part2)) 460 if (!strcasecmp (art->item->name, part2))
464 return mult * at->clone.value * art->item->value; 461 return mult * at->value * art->item->value;
465 } 462 }
466 } 463 }
467 } 464 }
468 465
469 /* third, try to match a body part ("arch's something") */ 466 /* third, try to match a body part ("arch's something") */
470 cp = strstr (name, "'s "); 467 cp = strstr (name, "'s ");
471 if (cp) 468 if (cp)
472 { 469 {
473 strcpy (part1, name); 470 strcpy (part1, name);
474 part1[cp - name] = '\0'; 471 part1[cp - name] = '\0';
475 strcpy (part2, cp + 3); 472 strcpy (part2, cp + 3);
476 /* examine all archetypes matching the first part of the name */ 473 /* examine all archetypes matching the first part of the name */
477 for (at = first_archetype; at; at = at->next) 474 for_all_archetypes (at)
478 if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL) 475 if (!strcasecmp (at->object::name, part1) && at->title == NULL)
479 { 476 {
480 if (at->clone.randomitems) 477 if (at->randomitems)
481 { 478 {
482 at2 = find_treasure_by_name (at->clone.randomitems->items, part2, 0); 479 at2 = find_treasure_by_name (at->randomitems->items, part2, 0);
483 if (at2) 480 if (at2)
484 return mult * at2->clone.value * isqrt (at->clone.level * 2); 481 return mult * at2->value * isqrt (at->level * 2);
485 } 482 }
486 } 483 }
487 } 484 }
488 485
489 /* failed to find any matching items -- formula should be checked */ 486 /* failed to find any matching items -- formula should be checked */
543 tcost = -1; 540 tcost = -1;
544 else 541 else
545 tcost += cost; 542 tcost += cost;
546 } 543 }
547 if (art != NULL && art->item != NULL) 544 if (art != NULL && art->item != NULL)
548 cost = at->clone.value * art->item->value; 545 cost = at->value * art->item->value;
549 else 546 else
550 cost = at->clone.value; 547 cost = at->value;
551 fprintf (logfile, "\t\tBuying result costs: %5ld", cost); 548 fprintf (logfile, "\t\tBuying result costs: %5ld", cost);
552 if (formula->yield > 1) 549 if (formula->yield > 1)
553 { 550 {
554 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);
555 cost = cost * (formula->yield + 1L) / 2L; 552 cost = cost * (formula->yield + 1L) / 2L;
616locate_recipe_artifact (const recipe *rp, size_t idx) 613locate_recipe_artifact (const recipe *rp, size_t idx)
617{ 614{
618 archetype *at = archetype::find (rp->arch_name [idx]); 615 archetype *at = archetype::find (rp->arch_name [idx]);
619 616
620 if (at) 617 if (at)
621 if (artifactlist *al = find_artifactlist (at->clone.type)) 618 if (artifactlist *al = find_artifactlist (at->type))
622 for (artifact *art = al->items; art; art = art->next) 619 for (artifact *art = al->items; art; art = art->next)
623 if (art->item->name == rp->title) 620 if (art->item->name == rp->title)
624 return art; 621 return art;
625 622
626 return 0; 623 return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines