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