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.18 by root, Fri Feb 16 19:43:41 2007 UTC vs.
Revision 1.22 by root, Mon Jun 4 13:04:00 2007 UTC

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
32{ 56{
33 recipelist *tl = new recipelist; 57 recipelist *tl = new recipelist;
34 58
35 tl->total_chance = 0; 59 tl->total_chance = 0;
36 tl->number = 0; 60 tl->number = 0;
37 tl->items = NULL; 61 tl->items = 0;
38 tl->next = NULL; 62 tl->next = 0;
63
39 return tl; 64 return tl;
40} 65}
41 66
42static recipe * 67static recipe *
43get_empty_formula (void) 68get_empty_formula (void)
241 recipe *check, *formula; 266 recipe *check, *formula;
242 int numb = 1; 267 int numb = 1;
243 268
244 LOG (llevDebug, "Checking formulae lists...\n"); 269 LOG (llevDebug, "Checking formulae lists...\n");
245 270
246 for (fl = formulalist; fl != NULL; fl = fl->next) 271 for (fl = formulalist; fl; fl = fl->next)
247 { 272 {
248 for (formula = fl->items; formula != NULL; formula = formula->next) 273 for (formula = fl->items; formula; formula = formula->next)
249 for (check = formula->next; check != NULL; check = check->next) 274 for (check = formula->next; check; check = check->next)
250 if (check->index == formula->index) 275 if (check->index == formula->index)
251 { 276 {
252 LOG (llevError, " ERROR: On %d ingred list: ", numb); 277 LOG (llevError, " ERROR: On %d ingred list: ", numb);
253 LOG (llevError, "Formulae [%s] of %s and [%s] of %s have matching index id (%d)\n", 278 LOG (llevError, "Formulae [%s] of %s and [%s] of %s have matching index id (%d)\n",
254 formula->arch_name[0], &formula->title, check->arch_name[0], &check->title, formula->index); 279 formula->arch_name[0], &formula->title, check->arch_name[0], &check->title, formula->index);
273 fprintf (logfile, "\n"); 298 fprintf (logfile, "\n");
274 while (fl) 299 while (fl)
275 { 300 {
276 fprintf (logfile, "\n Formulae with %d ingredient%s %d Formulae with total_chance=%d\n", 301 fprintf (logfile, "\n Formulae with %d ingredient%s %d Formulae with total_chance=%d\n",
277 num_ingred, num_ingred > 1 ? "s." : ".", fl->number, fl->total_chance); 302 num_ingred, num_ingred > 1 ? "s." : ".", fl->number, fl->total_chance);
278 for (formula = fl->items; formula != NULL; formula = formula->next) 303 for (formula = fl->items; formula; formula = formula->next)
279 { 304 {
280 artifact *art = NULL; 305 artifact *art = NULL;
281 char buf[MAX_BUF]; 306 char buf[MAX_BUF];
282 size_t i; 307 size_t i;
283 308
336 * only there to prevent infinite loops in treasure lists (a list 361 * only there to prevent infinite loops in treasure lists (a list
337 * referencing another list pointing back to the first one). */ 362 * referencing another list pointing back to the first one). */
338archetype * 363archetype *
339find_treasure_by_name (const treasure *t, const char *name, int depth) 364find_treasure_by_name (const treasure *t, const char *name, int depth)
340{ 365{
341 treasurelist *tl;
342 archetype *at;
343
344 if (depth > 10) 366 if (depth > 10)
345 return 0; 367 return 0;
346 368
347 while (t) 369 while (t)
348 { 370 {
349 if (t->name) 371 if (t->name)
350 { 372 {
351 tl = find_treasurelist (t->name); 373 if (treasurelist *tl = treasurelist::find (t->name))
352
353 if (tl) 374 if (tl->items)
354 {
355 at = find_treasure_by_name (tl->items, name, depth + 1); 375 if (archetype *at = find_treasure_by_name (tl->items, name, depth + 1))
356
357 if (at)
358 return at; 376 return at;
359 }
360 } 377 }
361 else 378 else
362 { 379 {
363 if (t->item && !strcasecmp (t->item->clone.name, name)) 380 if (t->item && !strcasecmp (t->item->object::name, name))
364 return t->item; 381 return t->item;
365 } 382 }
366 383
367 if (t->next_yes) 384 if (t->next_yes)
368 {
369 at = find_treasure_by_name (t->next_yes, name, depth); 385 if (archetype *at = find_treasure_by_name (t->next_yes, name, depth))
370 if (at)
371 return at; 386 return at;
372 }
373 387
374 if (t->next_no) 388 if (t->next_no)
375 {
376 at = find_treasure_by_name (t->next_no, name, depth); 389 if (archetype *at = find_treasure_by_name (t->next_no, name, depth))
377 if (at)
378 return at; 390 return at;
379 } 391
380 t = t->next; 392 t = t->next;
381 } 393 }
394
382 return 0; 395 return 0;
383} 396}
384 397
385/* If several archetypes have the same name, the value of the first 398/* If several archetypes have the same name, the value of the first
386 * one with that name will be returned. This happens for the 399 * one with that name will be returned. This happens for the
391 * 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
392 * big_dragon_worthless). */ 405 * big_dragon_worthless). */
393long 406long
394find_ingred_cost (const char *name) 407find_ingred_cost (const char *name)
395{ 408{
396 archetype *at;
397 archetype *at2; 409 archetype *at2;
398 artifactlist *al; 410 artifactlist *al;
399 artifact *art; 411 artifact *art;
400 long mult; 412 long mult;
401 char *cp; 413 char *cp;
414 name++; 426 name++;
415 else 427 else
416 mult = 1; 428 mult = 1;
417 429
418 /* first, try to match the name of an archetype */ 430 /* first, try to match the name of an archetype */
419 for (at = first_archetype; at != NULL; at = at->next) 431 for_all_archetypes (at)
420 { 432 {
421 if (at->clone.title != NULL) 433 if (at->title != NULL)
422 { 434 {
423 /* inefficient, but who cares? */ 435 /* inefficient, but who cares? */
424 sprintf (part1, "%s %s", &at->clone.name, &at->clone.title); 436 sprintf (part1, "%s %s", &at->object::name, &at->title);
425 if (!strcasecmp (part1, name)) 437 if (!strcasecmp (part1, name))
426 return mult * at->clone.value; 438 return mult * at->value;
427 } 439 }
428 if (!strcasecmp (at->clone.name, name)) 440 if (!strcasecmp (at->object::name, name))
429 return mult * at->clone.value; 441 return mult * at->value;
430 } 442 }
431 443
432 /* second, try to match an artifact ("arch of something") */ 444 /* second, try to match an artifact ("arch of something") */
433 cp = strstr (name, " of "); 445 cp = strstr (name, " of ");
434 if (cp != NULL) 446 if (cp != NULL)
435 { 447 {
436 strcpy (part1, name); 448 strcpy (part1, name);
437 part1[cp - name] = '\0'; 449 part1[cp - name] = '\0';
438 strcpy (part2, cp + 4); 450 strcpy (part2, cp + 4);
451
439 /* find the first archetype matching the first part of the name */ 452 /* find the first archetype matching the first part of the name */
440 for (at = first_archetype; at != NULL; at = at->next) 453 for_all_archetypes (at)
441 if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL) 454 if (!strcasecmp (at->object::name, part1) && at->title == NULL)
442 break;
443 if (at != NULL)
444 { 455 {
445 /* find the first artifact derived from that archetype (same type) */ 456 /* find the first artifact derived from that archetype (same type) */
446 for (al = first_artifactlist; al != NULL; al = al->next) 457 for (al = first_artifactlist; al; al = al->next)
447 if (al->type == at->clone.type) 458 if (al->type == at->type)
448 { 459 {
449 for (art = al->items; art != NULL; art = art->next) 460 for (art = al->items; art; art = art->next)
450 if (!strcasecmp (art->item->name, part2)) 461 if (!strcasecmp (art->item->name, part2))
451 return mult * at->clone.value * art->item->value; 462 return mult * at->value * art->item->value;
452 } 463 }
453 } 464 }
454 } 465 }
455 466
456 /* third, try to match a body part ("arch's something") */ 467 /* third, try to match a body part ("arch's something") */
457 cp = strstr (name, "'s "); 468 cp = strstr (name, "'s ");
458 if (cp) 469 if (cp)
459 { 470 {
460 strcpy (part1, name); 471 strcpy (part1, name);
461 part1[cp - name] = '\0'; 472 part1[cp - name] = '\0';
462 strcpy (part2, cp + 3); 473 strcpy (part2, cp + 3);
463 /* examine all archetypes matching the first part of the name */ 474 /* examine all archetypes matching the first part of the name */
464 for (at = first_archetype; at != NULL; at = at->next) 475 for_all_archetypes (at)
465 if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL) 476 if (!strcasecmp (at->object::name, part1) && at->title == NULL)
466 { 477 {
467 if (at->clone.randomitems != NULL) 478 if (at->randomitems)
468 { 479 {
469 at2 = find_treasure_by_name (at->clone.randomitems->items, part2, 0); 480 at2 = find_treasure_by_name (at->randomitems->items, part2, 0);
470 if (at2) 481 if (at2)
471 return mult * at2->clone.value * isqrt (at->clone.level * 2); 482 return mult * at2->value * isqrt (at->level * 2);
472 } 483 }
473 } 484 }
474 } 485 }
475 486
476 /* failed to find any matching items -- formula should be checked */ 487 /* failed to find any matching items -- formula should be checked */
492 fprintf (logfile, "\n"); 503 fprintf (logfile, "\n");
493 while (fl) 504 while (fl)
494 { 505 {
495 fprintf (logfile, "\n Formulae with %d ingredient%s %d Formulae with total_chance=%d\n", 506 fprintf (logfile, "\n Formulae with %d ingredient%s %d Formulae with total_chance=%d\n",
496 num_ingred, num_ingred > 1 ? "s." : ".", fl->number, fl->total_chance); 507 num_ingred, num_ingred > 1 ? "s." : ".", fl->number, fl->total_chance);
497 for (formula = fl->items; formula != NULL; formula = formula->next) 508 for (formula = fl->items; formula; formula = formula->next)
498 { 509 {
499 artifact *art = NULL; 510 artifact *art = NULL;
500 archetype *at = NULL; 511 archetype *at = NULL;
501 char buf[MAX_BUF]; 512 char buf[MAX_BUF];
502 size_t i; 513 size_t i;
530 tcost = -1; 541 tcost = -1;
531 else 542 else
532 tcost += cost; 543 tcost += cost;
533 } 544 }
534 if (art != NULL && art->item != NULL) 545 if (art != NULL && art->item != NULL)
535 cost = at->clone.value * art->item->value; 546 cost = at->value * art->item->value;
536 else 547 else
537 cost = at->clone.value; 548 cost = at->value;
538 fprintf (logfile, "\t\tBuying result costs: %5ld", cost); 549 fprintf (logfile, "\t\tBuying result costs: %5ld", cost);
539 if (formula->yield > 1) 550 if (formula->yield > 1)
540 { 551 {
541 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);
542 cost = cost * (formula->yield + 1L) / 2L; 553 cost = cost * (formula->yield + 1L) / 2L;
603locate_recipe_artifact (const recipe *rp, size_t idx) 614locate_recipe_artifact (const recipe *rp, size_t idx)
604{ 615{
605 archetype *at = archetype::find (rp->arch_name [idx]); 616 archetype *at = archetype::find (rp->arch_name [idx]);
606 617
607 if (at) 618 if (at)
608 if (artifactlist *al = find_artifactlist (at->clone.type)) 619 if (artifactlist *al = find_artifactlist (at->type))
609 for (artifact *art = al->items; art; art = art->next) 620 for (artifact *art = al->items; art; art = art->next)
610 if (art->item->name == rp->title) 621 if (art->item->name == rp->title)
611 return art; 622 return art;
612 623
613 return 0; 624 return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines