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.6 by root, Thu Sep 14 21:16:11 2006 UTC vs.
Revision 1.13 by pippijn, Wed Jan 3 00:08:17 2007 UTC

1
2
3/* Basic stuff for use with the alchemy code. Clearly some of this stuff 1/* Basic stuff for use with the alchemy code. Clearly some of this stuff
4 * could go into server/alchemy, but I left it here just in case it proves 2 * could go into server/alchemy, but I left it here just in case it proves
5 * more generally useful. 3 * more generally useful.
6 * 4 *
7 * Nov 1995 - file created by b.t. thomas@astro.psu.edu 5 * Nov 1995 - file created by b.t. thomas@astro.psu.edu
18 * chance 10 16 * chance 10
19 * ingred dust of beholdereye,gem 17 * ingred dust of beholdereye,gem
20 * arch potion_generic 18 * arch potion_generic
21 */ 19 */
22 20
21#include <cctype>
22
23#include <global.h> 23#include <global.h>
24#include <object.h> 24#include <object.h>
25#include <ctype.h>
26 25
27static void build_stringlist (const char *str, char ***result_list, size_t * result_size); 26static void build_stringlist (const char *str, char ***result_list, size_t * result_size);
28 27
29static recipelist *formulalist; 28static recipelist *formulalist;
30 29
95 { 94 {
96 artifact *art = locate_recipe_artifact (rp, i); 95 artifact *art = locate_recipe_artifact (rp, i);
97 96
98 if (!art && strcmp (rp->title, "NONE") != 0) 97 if (!art && strcmp (rp->title, "NONE") != 0)
99 { 98 {
100 LOG (llevError, "\nWARNING: Formula %s of %s has no artifact.\n", rp->arch_name[i], &rp->title); 99 LOG (llevError, "WARNING: Formula %s of %s has no artifact.\n", rp->arch_name[i], &rp->title);
101 result = 0; 100 result = 0;
102 } 101 }
103 } 102 }
104 else 103 else
105 { 104 {
106 LOG (llevError, "\nWARNING: Can't find archetype %s for formula %s\n", rp->arch_name[i], &rp->title); 105 LOG (llevError, "WARNING: Can't find archetype %s for formula %s\n", rp->arch_name[i], &rp->title);
107 result = 0; 106 result = 0;
108 } 107 }
109 } 108 }
110 109
111 return result; 110 return result;
135 return; 134 return;
136 else 135 else
137 has_been_done = 1; 136 has_been_done = 1;
138 137
139 sprintf (filename, "%s/formulae", settings.datadir); 138 sprintf (filename, "%s/formulae", settings.datadir);
140 LOG (llevDebug, "Reading alchemical formulae from %s...", filename); 139 LOG (llevDebug, "Reading alchemical formulae from %s...\n", filename);
141 if ((fp = open_and_uncompress (filename, 0, &comp)) == NULL) 140 if ((fp = open_and_uncompress (filename, 0, &comp)) == NULL)
142 { 141 {
143 LOG (llevError, "Can't open %s.\n", filename); 142 LOG (llevError, "Can't open %s.\n", filename);
144 return; 143 return;
145 } 144 }
255{ 254{
256 recipelist *fl; 255 recipelist *fl;
257 recipe *check, *formula; 256 recipe *check, *formula;
258 int numb = 1; 257 int numb = 1;
259 258
260 LOG (llevDebug, "Checking formulae lists..."); 259 LOG (llevDebug, "Checking formulae lists...\n");
261 260
262 for (fl = formulalist; fl != NULL; fl = fl->next) 261 for (fl = formulalist; fl != NULL; fl = fl->next)
263 { 262 {
264 for (formula = fl->items; formula != NULL; formula = formula->next) 263 for (formula = fl->items; formula != NULL; formula = formula->next)
265 for (check = formula->next; check != NULL; check = check->next) 264 for (check = formula->next; check != NULL; check = check->next)
356{ 355{
357 treasurelist *tl; 356 treasurelist *tl;
358 archetype *at; 357 archetype *at;
359 358
360 if (depth > 10) 359 if (depth > 10)
361 return NULL; 360 return 0;
362 while (t != NULL) 361
362 while (t)
363 { 363 {
364 if (t->name != NULL) 364 if (t->name)
365 { 365 {
366 tl = find_treasurelist (t->name); 366 tl = find_treasurelist (t->name);
367
368 if (tl)
369 {
367 at = find_treasure_by_name (tl->items, name, depth + 1); 370 at = find_treasure_by_name (tl->items, name, depth + 1);
368 if (at != NULL) 371
372 if (at)
369 return at; 373 return at;
374 }
370 } 375 }
371 else 376 else
372 { 377 {
373 if (!strcasecmp (t->item->clone.name, name)) 378 if (!strcasecmp (t->item->clone.name, name))
374 return t->item; 379 return t->item;
375 } 380 }
381
376 if (t->next_yes != NULL) 382 if (t->next_yes)
377 { 383 {
378 at = find_treasure_by_name (t->next_yes, name, depth); 384 at = find_treasure_by_name (t->next_yes, name, depth);
379 if (at != NULL) 385 if (at)
380 return at; 386 return at;
381 } 387 }
388
382 if (t->next_no != NULL) 389 if (t->next_no)
383 { 390 {
384 at = find_treasure_by_name (t->next_no, name, depth); 391 at = find_treasure_by_name (t->next_no, name, depth);
385 if (at != NULL) 392 if (at)
386 return at; 393 return at;
387 } 394 }
388 t = t->next; 395 t = t->next;
389 } 396 }
390 return NULL; 397 return 0;
391} 398}
392 399
393/* If several archetypes have the same name, the value of the first 400/* If several archetypes have the same name, the value of the first
394 * one with that name will be returned. This happens for the 401 * one with that name will be returned. This happens for the
395 * mushrooms (mushroom_1, mushroom_2 and mushroom_3). For the 402 * mushrooms (mushroom_1, mushroom_2 and mushroom_3). For the
469 if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL) 476 if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL)
470 { 477 {
471 if (at->clone.randomitems != NULL) 478 if (at->clone.randomitems != NULL)
472 { 479 {
473 at2 = find_treasure_by_name (at->clone.randomitems->items, part2, 0); 480 at2 = find_treasure_by_name (at->clone.randomitems->items, part2, 0);
474 if (at2 != NULL) 481 if (at2)
475 return mult * at2->clone.value * isqrt (at->clone.level * 2); 482 return mult * at2->clone.value * isqrt (at->clone.level * 2);
476 } 483 }
477 } 484 }
478 } 485 }
479 /* failed to find any matching items -- formula should be checked */ 486 /* failed to find any matching items -- formula should be checked */
615 if ((at = find_artifactlist (item->type))) 622 if ((at = find_artifactlist (item->type)))
616 for (art = at->items; art; art = art->next) 623 for (art = at->items; art; art = art->next)
617 if (!strcmp (art->item->name, rp->title)) 624 if (!strcmp (art->item->name, rp->title))
618 break; 625 break;
619 626
620 free_object (item); 627 item->destroy ();
621 628
622 return art; 629 return art;
623} 630}
624 631
625int 632int
737 char *dup; 744 char *dup;
738 char *p; 745 char *p;
739 size_t size; 746 size_t size;
740 size_t i; 747 size_t i;
741 748
742 dup = strdup_local (str); 749 dup = strdup (str);
743 if (dup == NULL) 750 if (dup == NULL)
744 fatal (OUT_OF_MEMORY); 751 fatal (OUT_OF_MEMORY);
745 752
746 size = 0; 753 size = 0;
747 for (p = strtok (dup, ","); p != NULL; p = strtok (NULL, ",")) 754 for (p = strtok (dup, ","); p != NULL; p = strtok (NULL, ","))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines