|
|
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 | |
42 | static recipe * |
67 | static recipe * |
43 | get_empty_formula (void) |
68 | get_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). */ |
338 | archetype * |
363 | archetype * |
339 | find_treasure_by_name (const treasure *t, const char *name, int depth) |
364 | find_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->clone.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 |
… | |
… | |
435 | { |
448 | { |
436 | strcpy (part1, name); |
449 | strcpy (part1, name); |
437 | part1[cp - name] = '\0'; |
450 | part1[cp - name] = '\0'; |
438 | strcpy (part2, cp + 4); |
451 | strcpy (part2, cp + 4); |
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 (at = first_archetype; at; at = at->next) |
441 | if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL) |
454 | if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL) |
442 | break; |
455 | break; |
443 | if (at != NULL) |
456 | if (at != NULL) |
444 | { |
457 | { |
445 | /* find the first artifact derived from that archetype (same type) */ |
458 | /* find the first artifact derived from that archetype (same type) */ |
446 | for (al = first_artifactlist; al != NULL; al = al->next) |
459 | for (al = first_artifactlist; al; al = al->next) |
447 | if (al->type == at->clone.type) |
460 | if (al->type == at->clone.type) |
448 | { |
461 | { |
449 | for (art = al->items; art != NULL; art = art->next) |
462 | for (art = al->items; art; art = art->next) |
450 | if (!strcasecmp (art->item->name, part2)) |
463 | if (!strcasecmp (art->item->name, part2)) |
451 | return mult * at->clone.value * art->item->value; |
464 | return mult * at->clone.value * art->item->value; |
452 | } |
465 | } |
453 | } |
466 | } |
454 | } |
467 | } |
… | |
… | |
459 | { |
472 | { |
460 | strcpy (part1, name); |
473 | strcpy (part1, name); |
461 | part1[cp - name] = '\0'; |
474 | part1[cp - name] = '\0'; |
462 | strcpy (part2, cp + 3); |
475 | strcpy (part2, cp + 3); |
463 | /* examine all archetypes matching the first part of the name */ |
476 | /* examine all archetypes matching the first part of the name */ |
464 | for (at = first_archetype; at != NULL; at = at->next) |
477 | for (at = first_archetype; at; at = at->next) |
465 | if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL) |
478 | if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL) |
466 | { |
479 | { |
467 | if (at->clone.randomitems != NULL) |
480 | if (at->clone.randomitems) |
468 | { |
481 | { |
469 | at2 = find_treasure_by_name (at->clone.randomitems->items, part2, 0); |
482 | at2 = find_treasure_by_name (at->clone.randomitems->items, part2, 0); |
470 | if (at2) |
483 | if (at2) |
471 | return mult * at2->clone.value * isqrt (at->clone.level * 2); |
484 | return mult * at2->clone.value * isqrt (at->clone.level * 2); |
472 | } |
485 | } |
… | |
… | |
492 | fprintf (logfile, "\n"); |
505 | fprintf (logfile, "\n"); |
493 | while (fl) |
506 | while (fl) |
494 | { |
507 | { |
495 | fprintf (logfile, "\n Formulae with %d ingredient%s %d Formulae with total_chance=%d\n", |
508 | 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); |
509 | num_ingred, num_ingred > 1 ? "s." : ".", fl->number, fl->total_chance); |
497 | for (formula = fl->items; formula != NULL; formula = formula->next) |
510 | for (formula = fl->items; formula; formula = formula->next) |
498 | { |
511 | { |
499 | artifact *art = NULL; |
512 | artifact *art = NULL; |
500 | archetype *at = NULL; |
513 | archetype *at = NULL; |
501 | char buf[MAX_BUF]; |
514 | char buf[MAX_BUF]; |
502 | size_t i; |
515 | size_t i; |