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.22 by root, Mon Jun 4 13:04:00 2007 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game 2 * This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game.
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 it
9 * it under the terms of the GNU General Public License as published by 9 * under the terms of the GNU General Public License as published by the Free
10 * the Free Software Foundation; either version 2 of the License, or 10 * Software Foundation; either version 2 of the License, or (at your option)
11 * (at your option) any later version. 11 * 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, but
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * GNU General Public License for more details. 16 * 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 along
19 * along with this program; if not, write to the Free Software 19 * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 * 21 *
22 * The authors can be reached via e-mail at <crossfire@schmorp.de> 22 * The authors can be reached via e-mail to <crossfire@schmorp.de>
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.
375 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))
376 return at; 376 return at;
377 } 377 }
378 else 378 else
379 { 379 {
380 if (t->item && !strcasecmp (t->item->clone.name, name)) 380 if (t->item && !strcasecmp (t->item->object::name, name))
381 return t->item; 381 return t->item;
382 } 382 }
383 383
384 if (t->next_yes) 384 if (t->next_yes)
385 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))
404 * 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
405 * big_dragon_worthless). */ 405 * big_dragon_worthless). */
406long 406long
407find_ingred_cost (const char *name) 407find_ingred_cost (const char *name)
408{ 408{
409 archetype *at;
410 archetype *at2; 409 archetype *at2;
411 artifactlist *al; 410 artifactlist *al;
412 artifact *art; 411 artifact *art;
413 long mult; 412 long mult;
414 char *cp; 413 char *cp;
427 name++; 426 name++;
428 else 427 else
429 mult = 1; 428 mult = 1;
430 429
431 /* first, try to match the name of an archetype */ 430 /* first, try to match the name of an archetype */
432 for (at = first_archetype; at != NULL; at = at->next) 431 for_all_archetypes (at)
433 { 432 {
434 if (at->clone.title != NULL) 433 if (at->title != NULL)
435 { 434 {
436 /* inefficient, but who cares? */ 435 /* inefficient, but who cares? */
437 sprintf (part1, "%s %s", &at->clone.name, &at->clone.title); 436 sprintf (part1, "%s %s", &at->object::name, &at->title);
438 if (!strcasecmp (part1, name)) 437 if (!strcasecmp (part1, name))
439 return mult * at->clone.value; 438 return mult * at->value;
440 } 439 }
441 if (!strcasecmp (at->clone.name, name)) 440 if (!strcasecmp (at->object::name, name))
442 return mult * at->clone.value; 441 return mult * at->value;
443 } 442 }
444 443
445 /* second, try to match an artifact ("arch of something") */ 444 /* second, try to match an artifact ("arch of something") */
446 cp = strstr (name, " of "); 445 cp = strstr (name, " of ");
447 if (cp != NULL) 446 if (cp != NULL)
448 { 447 {
449 strcpy (part1, name); 448 strcpy (part1, name);
450 part1[cp - name] = '\0'; 449 part1[cp - name] = '\0';
451 strcpy (part2, cp + 4); 450 strcpy (part2, cp + 4);
451
452 /* find the first archetype matching the first part of the name */ 452 /* find the first archetype matching the first part of the name */
453 for (at = first_archetype; at; at = at->next) 453 for_all_archetypes (at)
454 if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL) 454 if (!strcasecmp (at->object::name, part1) && at->title == NULL)
455 break;
456 if (at != NULL)
457 { 455 {
458 /* find the first artifact derived from that archetype (same type) */ 456 /* find the first artifact derived from that archetype (same type) */
459 for (al = first_artifactlist; al; al = al->next) 457 for (al = first_artifactlist; al; al = al->next)
460 if (al->type == at->clone.type) 458 if (al->type == at->type)
461 { 459 {
462 for (art = al->items; art; art = art->next) 460 for (art = al->items; art; art = art->next)
463 if (!strcasecmp (art->item->name, part2)) 461 if (!strcasecmp (art->item->name, part2))
464 return mult * at->clone.value * art->item->value; 462 return mult * at->value * art->item->value;
465 } 463 }
466 } 464 }
467 } 465 }
468 466
469 /* third, try to match a body part ("arch's something") */ 467 /* third, try to match a body part ("arch's something") */
470 cp = strstr (name, "'s "); 468 cp = strstr (name, "'s ");
471 if (cp) 469 if (cp)
472 { 470 {
473 strcpy (part1, name); 471 strcpy (part1, name);
474 part1[cp - name] = '\0'; 472 part1[cp - name] = '\0';
475 strcpy (part2, cp + 3); 473 strcpy (part2, cp + 3);
476 /* examine all archetypes matching the first part of the name */ 474 /* examine all archetypes matching the first part of the name */
477 for (at = first_archetype; at; at = at->next) 475 for_all_archetypes (at)
478 if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL) 476 if (!strcasecmp (at->object::name, part1) && at->title == NULL)
479 { 477 {
480 if (at->clone.randomitems) 478 if (at->randomitems)
481 { 479 {
482 at2 = find_treasure_by_name (at->clone.randomitems->items, part2, 0); 480 at2 = find_treasure_by_name (at->randomitems->items, part2, 0);
483 if (at2) 481 if (at2)
484 return mult * at2->clone.value * isqrt (at->clone.level * 2); 482 return mult * at2->value * isqrt (at->level * 2);
485 } 483 }
486 } 484 }
487 } 485 }
488 486
489 /* failed to find any matching items -- formula should be checked */ 487 /* failed to find any matching items -- formula should be checked */
543 tcost = -1; 541 tcost = -1;
544 else 542 else
545 tcost += cost; 543 tcost += cost;
546 } 544 }
547 if (art != NULL && art->item != NULL) 545 if (art != NULL && art->item != NULL)
548 cost = at->clone.value * art->item->value; 546 cost = at->value * art->item->value;
549 else 547 else
550 cost = at->clone.value; 548 cost = at->value;
551 fprintf (logfile, "\t\tBuying result costs: %5ld", cost); 549 fprintf (logfile, "\t\tBuying result costs: %5ld", cost);
552 if (formula->yield > 1) 550 if (formula->yield > 1)
553 { 551 {
554 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);
555 cost = cost * (formula->yield + 1L) / 2L; 553 cost = cost * (formula->yield + 1L) / 2L;
616locate_recipe_artifact (const recipe *rp, size_t idx) 614locate_recipe_artifact (const recipe *rp, size_t idx)
617{ 615{
618 archetype *at = archetype::find (rp->arch_name [idx]); 616 archetype *at = archetype::find (rp->arch_name [idx]);
619 617
620 if (at) 618 if (at)
621 if (artifactlist *al = find_artifactlist (at->clone.type)) 619 if (artifactlist *al = find_artifactlist (at->type))
622 for (artifact *art = al->items; art; art = art->next) 620 for (artifact *art = al->items; art; art = art->next)
623 if (art->item->name == rp->title) 621 if (art->item->name == rp->title)
624 return art; 622 return art;
625 623
626 return 0; 624 return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines