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.5 by root, Sun Sep 10 16:00:23 2006 UTC vs.
Revision 1.24 by root, Thu Nov 8 19:43:23 2007 UTC

1 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 *
8 * Deliantra 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 <support@deliantra.net>
22 */
2 23
3/* 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
4 * 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
5 * more generally useful. 26 * more generally useful.
6 * 27 *
12 * Ingredients are just comma delimited list of archetype (or object) 33 * Ingredients are just comma delimited list of archetype (or object)
13 * names. 34 * names.
14 */ 35 */
15 36
16/* Example 'formula' entry in libdir/formulae: 37/* Example 'formula' entry in libdir/formulae:
17 * Object transparency 38 * object transparency
18 * chance 10 39 * chance 10
19 * ingred dust of beholdereye,gem 40 * ingred dust of beholdereye,gem
20 * arch potion_generic 41 * arch potion_generic
21 */ 42 */
22 43
44#include <cctype>
45
23#include <global.h> 46#include <global.h>
24#include <object.h> 47#include <object.h>
25#include <ctype.h>
26 48
27static void build_stringlist (const char *str, char ***result_list, size_t * result_size); 49static void build_stringlist (const char *str, char ***result_list, size_t * result_size);
28 50
29static recipelist *formulalist; 51static recipelist *formulalist;
30 52
33{ 55{
34 recipelist *tl = new recipelist; 56 recipelist *tl = new recipelist;
35 57
36 tl->total_chance = 0; 58 tl->total_chance = 0;
37 tl->number = 0; 59 tl->number = 0;
38 tl->items = NULL; 60 tl->items = 0;
39 tl->next = NULL; 61 tl->next = 0;
62
40 return tl; 63 return tl;
41} 64}
42 65
43static recipe * 66static recipe *
44get_empty_formula (void) 67get_empty_formula (void)
61 t->next = NULL; 84 t->next = NULL;
62 return t; 85 return t;
63} 86}
64 87
65/* get_formulalist() - returns pointer to the formula list */ 88/* get_formulalist() - returns pointer to the formula list */
66
67recipelist * 89recipelist *
68get_formulalist (int i) 90get_formulalist (int i)
69{ 91{
70 recipelist *fl = formulalist; 92 recipelist *fl = formulalist;
71 int number = i; 93 int number = i;
74 { 96 {
75 if (!(fl = fl->next)) 97 if (!(fl = fl->next))
76 break; 98 break;
77 number--; 99 number--;
78 } 100 }
101
79 return fl; 102 return fl;
80} 103}
81 104
82/* check_recipe() - makes sure we actually have the requested artifact 105/* check_recipe() - makes sure we actually have the requested artifact
83 * and archetype. */ 106 * and archetype. */
84
85static int 107static int
86check_recipe (const recipe *rp) 108check_recipe (const recipe *rp)
87{ 109{
88 size_t i; 110 size_t i;
89 int result; 111 int result = 1;
90 112
91 result = 1;
92 for (i = 0; i < rp->arch_names; i++) 113 for (i = 0; i < rp->arch_names; i++)
93 { 114 {
94 if (find_archetype (rp->arch_name[i]) != NULL) 115 if (archetype::find (rp->arch_name[i]) != NULL)
95 { 116 {
96 artifact *art = locate_recipe_artifact (rp, i); 117 artifact *art = locate_recipe_artifact (rp, i);
97 118
98 if (!art && strcmp (rp->title, "NONE") != 0) 119 if (!art && strcmp (rp->title, "NONE") != 0)
99 { 120 {
100 LOG (llevError, "\nWARNING: Formula %s of %s has no artifact.\n", rp->arch_name[i], &rp->title); 121 LOG (llevError, "WARNING: Formula %s of %s has no artifact.\n", rp->arch_name[i], &rp->title);
101 result = 0; 122 result = 0;
102 } 123 }
103 } 124 }
104 else 125 else
105 { 126 {
106 LOG (llevError, "\nWARNING: Can't find archetype %s for formula %s\n", rp->arch_name[i], &rp->title); 127 LOG (llevError, "WARNING: Can't find archetype %s for formula %s\n", rp->arch_name[i], &rp->title);
107 result = 0; 128 result = 0;
108 } 129 }
109 } 130 }
110 131
111 return result; 132 return result;
112} 133}
113
114 134
115/* 135/*
116 * init_formulae() - Builds up the lists of formula from the file in 136 * init_formulae() - Builds up the lists of formula from the file in
117 * the libdir. -b.t. 137 * the libdir. -b.t.
118 */ 138 */
119
120void 139void
121init_formulae (void) 140init_formulae (void)
122{ 141{
123 static int has_been_done = 0; 142 static int has_been_done = 0;
124 FILE *fp; 143 FILE *fp;
135 return; 154 return;
136 else 155 else
137 has_been_done = 1; 156 has_been_done = 1;
138 157
139 sprintf (filename, "%s/formulae", settings.datadir); 158 sprintf (filename, "%s/formulae", settings.datadir);
140 LOG (llevDebug, "Reading alchemical formulae from %s...", filename); 159 LOG (llevDebug, "Reading alchemical formulae from %s...\n", filename);
141 if ((fp = open_and_uncompress (filename, 0, &comp)) == NULL) 160 if ((fp = open_and_uncompress (filename, 0, &comp)) == NULL)
142 { 161 {
143 LOG (llevError, "Can't open %s.\n", filename); 162 LOG (llevError, "Can't open %s.\n", filename);
144 return; 163 return;
145 } 164 }
152 *cp = '\0'; 171 *cp = '\0';
153 cp = buf; 172 cp = buf;
154 while (*cp == ' ') /* Skip blanks */ 173 while (*cp == ' ') /* Skip blanks */
155 cp++; 174 cp++;
156 175
157 if (!strncmp (cp, "Object", 6)) 176 if (!strncmp (cp, "object", 6))
158 { 177 {
159 formula = get_empty_formula (); 178 formula = get_empty_formula ();
160 formula->title = strchr (cp, ' ') + 1; 179 formula->title = strchr (cp, ' ') + 1;
161 } 180 }
162 else if (!strncmp (cp, "keycode", 7)) 181 else if (!strncmp (cp, "keycode", 7))
163 {
164 formula->keycode = strchr (cp, ' ') + 1; 182 formula->keycode = strchr (cp, ' ') + 1;
165 }
166 else if (sscanf (cp, "trans %d", &value)) 183 else if (sscanf (cp, "trans %d", &value))
167 {
168 formula->transmute = (uint16) value; 184 formula->transmute = (uint16) value;
169 }
170 else if (sscanf (cp, "yield %d", &value)) 185 else if (sscanf (cp, "yield %d", &value))
171 {
172 formula->yield = (uint16) value; 186 formula->yield = (uint16) value;
173 }
174 else if (sscanf (cp, "chance %d", &value)) 187 else if (sscanf (cp, "chance %d", &value))
175 {
176 formula->chance = (uint16) value; 188 formula->chance = (uint16) value;
177 }
178 else if (sscanf (cp, "exp %d", &value)) 189 else if (sscanf (cp, "exp %d", &value))
179 {
180 formula->exp = (uint16) value; 190 formula->exp = (uint16) value;
181 }
182 else if (sscanf (cp, "diff %d", &value)) 191 else if (sscanf (cp, "diff %d", &value))
183 {
184 formula->diff = (uint16) value; 192 formula->diff = (uint16) value;
185 }
186 else if (!strncmp (cp, "ingred", 6)) 193 else if (!strncmp (cp, "ingred", 6))
187 { 194 {
188 int numb_ingred = 1; 195 int numb_ingred = 1;
189 196
190 cp = strchr (cp, ' ') + 1; 197 cp = strchr (cp, ' ') + 1;
193 if ((next = strchr (cp, ',')) != NULL) 200 if ((next = strchr (cp, ',')) != NULL)
194 { 201 {
195 *(next++) = '\0'; 202 *(next++) = '\0';
196 numb_ingred++; 203 numb_ingred++;
197 } 204 }
205
198 tmp = new linked_char; 206 tmp = new linked_char;
199 207
200 tmp->name = cp; 208 tmp->name = cp;
201 tmp->next = formula->ingred; 209 tmp->next = formula->ingred;
202 formula->ingred = tmp; 210 formula->ingred = tmp;
205 * quickly for the right recipe. 213 * quickly for the right recipe.
206 */ 214 */
207 formula->index += strtoint (cp); 215 formula->index += strtoint (cp);
208 } 216 }
209 while ((cp = next) != NULL); 217 while ((cp = next) != NULL);
218
210 /* now find the correct (# of ingred ordered) formulalist */ 219 /* now find the correct (# of ingred ordered) formulalist */
211 fl = formulalist; 220 fl = formulalist;
212 while (numb_ingred != 1) 221 while (numb_ingred != 1)
213 { 222 {
214 if (!fl->next) 223 if (!fl->next)
215 fl->next = init_recipelist (); 224 fl->next = init_recipelist ();
225
216 fl = fl->next; 226 fl = fl->next;
217 numb_ingred--; 227 numb_ingred--;
218 } 228 }
229
219 fl->total_chance += formula->chance; 230 fl->total_chance += formula->chance;
220 fl->number++; 231 fl->number++;
221 formula->next = fl->items; 232 formula->next = fl->items;
222 fl->items = formula; 233 fl->items = formula;
223 } 234 }
225 { 236 {
226 build_stringlist (strchr (cp, ' ') + 1, &formula->arch_name, &formula->arch_names); 237 build_stringlist (strchr (cp, ' ') + 1, &formula->arch_name, &formula->arch_names);
227 check_recipe (formula); 238 check_recipe (formula);
228 } 239 }
229 else if (!strncmp (cp, "skill", 5)) 240 else if (!strncmp (cp, "skill", 5))
230 {
231 formula->skill = strchr (cp, ' ') + 1; 241 formula->skill = strchr (cp, ' ') + 1;
232 }
233 else if (!strncmp (cp, "cauldron", 8)) 242 else if (!strncmp (cp, "cauldron", 8))
234 {
235 formula->cauldron = strchr (cp, ' ') + 1; 243 formula->cauldron = strchr (cp, ' ') + 1;
236 }
237 else 244 else
238 LOG (llevError, "Unknown input in file %s: %s\n", filename, buf); 245 LOG (llevError, "Unknown input in file %s: %s\n", filename, buf);
239 } 246 }
247
240 LOG (llevDebug, "done.\n"); 248 LOG (llevDebug, "done.\n");
241 close_and_delete (fp, comp); 249 close_and_delete (fp, comp);
242 /* Lastly, lets check for problems in formula we got */ 250 /* Lastly, lets check for problems in formula we got */
243 check_formulae (); 251 check_formulae ();
244} 252}
255{ 263{
256 recipelist *fl; 264 recipelist *fl;
257 recipe *check, *formula; 265 recipe *check, *formula;
258 int numb = 1; 266 int numb = 1;
259 267
260 LOG (llevDebug, "Checking formulae lists..."); 268 LOG (llevDebug, "Checking formulae lists...\n");
261 269
262 for (fl = formulalist; fl != NULL; fl = fl->next) 270 for (fl = formulalist; fl; fl = fl->next)
263 { 271 {
264 for (formula = fl->items; formula != NULL; formula = formula->next) 272 for (formula = fl->items; formula; formula = formula->next)
265 for (check = formula->next; check != NULL; check = check->next) 273 for (check = formula->next; check; check = check->next)
266 if (check->index == formula->index) 274 if (check->index == formula->index)
267 { 275 {
268 LOG (llevError, " ERROR: On %d ingred list: ", numb); 276 LOG (llevError, " ERROR: On %d ingred list: ", numb);
269 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",
270 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);
289 fprintf (logfile, "\n"); 297 fprintf (logfile, "\n");
290 while (fl) 298 while (fl)
291 { 299 {
292 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",
293 num_ingred, num_ingred > 1 ? "s." : ".", fl->number, fl->total_chance); 301 num_ingred, num_ingred > 1 ? "s." : ".", fl->number, fl->total_chance);
294 for (formula = fl->items; formula != NULL; formula = formula->next) 302 for (formula = fl->items; formula; formula = formula->next)
295 { 303 {
296 artifact *art = NULL; 304 artifact *art = NULL;
297 char buf[MAX_BUF]; 305 char buf[MAX_BUF];
298 size_t i; 306 size_t i;
299 307
300 for (i = 0; i < formula->arch_names; i++) 308 for (i = 0; i < formula->arch_names; i++)
301 { 309 {
302 const char *string = formula->arch_name[i]; 310 const char *string = formula->arch_name[i];
303 311
304 if (find_archetype (string) != NULL) 312 if (archetype::find (string) != NULL)
305 { 313 {
306 art = locate_recipe_artifact (formula, i); 314 art = locate_recipe_artifact (formula, i);
307 if (!art && strcmp (formula->title, "NONE")) 315 if (!art && strcmp (formula->title, "NONE"))
308 LOG (llevError, "Formula %s has no artifact\n", &formula->title); 316 LOG (llevError, "Formula %s has no artifact!\n", &formula->title);
309 else 317 else
310 { 318 {
311 if (strcmp (formula->title, "NONE")) 319 if (strcmp (formula->title, "NONE"))
312 sprintf (buf, "%s of %s", string, &formula->title); 320 sprintf (buf, "%s of %s", string, &formula->title);
313 else 321 else
352 * only there to prevent infinite loops in treasure lists (a list 360 * only there to prevent infinite loops in treasure lists (a list
353 * referencing another list pointing back to the first one). */ 361 * referencing another list pointing back to the first one). */
354archetype * 362archetype *
355find_treasure_by_name (const treasure *t, const char *name, int depth) 363find_treasure_by_name (const treasure *t, const char *name, int depth)
356{ 364{
357 treasurelist *tl;
358 archetype *at;
359
360 if (depth > 10) 365 if (depth > 10)
361 return NULL; 366 return 0;
362 while (t != NULL) 367
368 while (t)
363 { 369 {
364 if (t->name != NULL) 370 if (t->name)
365 { 371 {
366 tl = find_treasurelist (t->name); 372 if (treasurelist *tl = treasurelist::find (t->name))
373 if (tl->items)
367 at = find_treasure_by_name (tl->items, name, depth + 1); 374 if (archetype *at = find_treasure_by_name (tl->items, name, depth + 1))
368 if (at != NULL)
369 return at; 375 return at;
370 } 376 }
371 else 377 else
372 { 378 {
373 if (!strcasecmp (t->item->clone.name, name)) 379 if (t->item && !strcasecmp (t->item->object::name, name))
374 return t->item; 380 return t->item;
375 } 381 }
382
376 if (t->next_yes != NULL) 383 if (t->next_yes)
377 {
378 at = find_treasure_by_name (t->next_yes, name, depth); 384 if (archetype *at = find_treasure_by_name (t->next_yes, name, depth))
379 if (at != NULL)
380 return at; 385 return at;
381 } 386
382 if (t->next_no != NULL) 387 if (t->next_no)
383 {
384 at = find_treasure_by_name (t->next_no, name, depth); 388 if (archetype *at = find_treasure_by_name (t->next_no, name, depth))
385 if (at != NULL)
386 return at; 389 return at;
387 } 390
388 t = t->next; 391 t = t->next;
389 } 392 }
393
390 return NULL; 394 return 0;
391} 395}
392 396
393/* 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
394 * one with that name will be returned. This happens for the 398 * one with that name will be returned. This happens for the
395 * mushrooms (mushroom_1, mushroom_2 and mushroom_3). For the 399 * mushrooms (mushroom_1, mushroom_2 and mushroom_3). For the
399 * 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
400 * big_dragon_worthless). */ 404 * big_dragon_worthless). */
401long 405long
402find_ingred_cost (const char *name) 406find_ingred_cost (const char *name)
403{ 407{
404 archetype *at;
405 archetype *at2; 408 archetype *at2;
406 artifactlist *al; 409 artifactlist *al;
407 artifact *art; 410 artifact *art;
408 long mult; 411 long mult;
409 char *cp; 412 char *cp;
415 while (isdigit (*name)) 418 while (isdigit (*name))
416 { 419 {
417 mult = 10 * mult + (*name - '0'); 420 mult = 10 * mult + (*name - '0');
418 name++; 421 name++;
419 } 422 }
423
420 if (mult > 0) 424 if (mult > 0)
421 name++; 425 name++;
422 else 426 else
423 mult = 1; 427 mult = 1;
428
424 /* first, try to match the name of an archetype */ 429 /* first, try to match the name of an archetype */
425 for (at = first_archetype; at != NULL; at = at->next) 430 for_all_archetypes (at)
426 { 431 {
427 if (at->clone.title != NULL) 432 if (at->title != NULL)
428 { 433 {
429 /* inefficient, but who cares? */ 434 /* inefficient, but who cares? */
430 sprintf (part1, "%s %s", &at->clone.name, &at->clone.title); 435 sprintf (part1, "%s %s", &at->object::name, &at->title);
431 if (!strcasecmp (part1, name)) 436 if (!strcasecmp (part1, name))
432 return mult * at->clone.value; 437 return mult * at->value;
433 } 438 }
434 if (!strcasecmp (at->clone.name, name)) 439 if (!strcasecmp (at->object::name, name))
435 return mult * at->clone.value; 440 return mult * at->value;
436 } 441 }
442
437 /* second, try to match an artifact ("arch of something") */ 443 /* second, try to match an artifact ("arch of something") */
438 cp = strstr (name, " of "); 444 cp = strstr (name, " of ");
439 if (cp != NULL) 445 if (cp != NULL)
440 { 446 {
441 strcpy (part1, name); 447 strcpy (part1, name);
442 part1[cp - name] = '\0'; 448 part1[cp - name] = '\0';
443 strcpy (part2, cp + 4); 449 strcpy (part2, cp + 4);
450
444 /* find the first archetype matching the first part of the name */ 451 /* find the first archetype matching the first part of the name */
445 for (at = first_archetype; at != NULL; at = at->next) 452 for_all_archetypes (at)
446 if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL) 453 if (!strcasecmp (at->object::name, part1) && at->title == NULL)
447 break;
448 if (at != NULL)
449 { 454 {
450 /* find the first artifact derived from that archetype (same type) */ 455 /* find the first artifact derived from that archetype (same type) */
451 for (al = first_artifactlist; al != NULL; al = al->next) 456 for (al = first_artifactlist; al; al = al->next)
452 if (al->type == at->clone.type) 457 if (al->type == at->type)
453 { 458 {
454 for (art = al->items; art != NULL; art = art->next) 459 for (art = al->items; art; art = art->next)
455 if (!strcasecmp (art->item->name, part2)) 460 if (!strcasecmp (art->item->name, part2))
456 return mult * at->clone.value * art->item->value; 461 return mult * at->value * art->item->value;
457 } 462 }
458 } 463 }
459 } 464 }
465
460 /* third, try to match a body part ("arch's something") */ 466 /* third, try to match a body part ("arch's something") */
461 cp = strstr (name, "'s "); 467 cp = strstr (name, "'s ");
462 if (cp != NULL) 468 if (cp)
463 { 469 {
464 strcpy (part1, name); 470 strcpy (part1, name);
465 part1[cp - name] = '\0'; 471 part1[cp - name] = '\0';
466 strcpy (part2, cp + 3); 472 strcpy (part2, cp + 3);
467 /* examine all archetypes matching the first part of the name */ 473 /* examine all archetypes matching the first part of the name */
468 for (at = first_archetype; at != NULL; at = at->next) 474 for_all_archetypes (at)
469 if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL) 475 if (!strcasecmp (at->object::name, part1) && at->title == NULL)
470 { 476 {
471 if (at->clone.randomitems != NULL) 477 if (at->randomitems)
472 { 478 {
473 at2 = find_treasure_by_name (at->clone.randomitems->items, part2, 0); 479 at2 = find_treasure_by_name (at->randomitems->items, part2, 0);
474 if (at2 != NULL) 480 if (at2)
475 return mult * at2->clone.value * isqrt (at->clone.level * 2); 481 return mult * at2->value * isqrt (at->level * 2);
476 } 482 }
477 } 483 }
478 } 484 }
485
479 /* failed to find any matching items -- formula should be checked */ 486 /* failed to find any matching items -- formula should be checked */
480 return -1; 487 return -1;
481} 488}
482 489
483/* code copied from dump_alchemy() and modified by Raphael Quinet */ 490/* code copied from dump_alchemy() and modified by Raphael Quinet */
495 fprintf (logfile, "\n"); 502 fprintf (logfile, "\n");
496 while (fl) 503 while (fl)
497 { 504 {
498 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",
499 num_ingred, num_ingred > 1 ? "s." : ".", fl->number, fl->total_chance); 506 num_ingred, num_ingred > 1 ? "s." : ".", fl->number, fl->total_chance);
500 for (formula = fl->items; formula != NULL; formula = formula->next) 507 for (formula = fl->items; formula; formula = formula->next)
501 { 508 {
502 artifact *art = NULL; 509 artifact *art = NULL;
503 archetype *at = NULL; 510 archetype *at = NULL;
504 char buf[MAX_BUF]; 511 char buf[MAX_BUF];
505 size_t i; 512 size_t i;
506 513
507 for (i = 0; i < formula->arch_names; i++) 514 for (i = 0; i < formula->arch_names; i++)
508 { 515 {
509 const char *string = formula->arch_name[i]; 516 const char *string = formula->arch_name[i];
510 517
511 if ((at = find_archetype (string)) != NULL) 518 if ((at = archetype::find (string)) != NULL)
512 { 519 {
513 art = locate_recipe_artifact (formula, i); 520 art = locate_recipe_artifact (formula, i);
514 if (!art && strcmp (formula->title, "NONE")) 521 if (!art && strcmp (formula->title, "NONE"))
515 LOG (llevError, "Formula %s has no artifact\n", &formula->title); 522 LOG (llevError, "Formula %s has no artifact\n", &formula->title);
516 else 523 else
533 tcost = -1; 540 tcost = -1;
534 else 541 else
535 tcost += cost; 542 tcost += cost;
536 } 543 }
537 if (art != NULL && art->item != NULL) 544 if (art != NULL && art->item != NULL)
538 cost = at->clone.value * art->item->value; 545 cost = at->value * art->item->value;
539 else 546 else
540 cost = at->clone.value; 547 cost = at->value;
541 fprintf (logfile, "\t\tBuying result costs: %5ld", cost); 548 fprintf (logfile, "\t\tBuying result costs: %5ld", cost);
542 if (formula->yield > 1) 549 if (formula->yield > 1)
543 { 550 {
544 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);
545 cost = cost * (formula->yield + 1L) / 2L; 552 cost = cost * (formula->yield + 1L) / 2L;
603} 610}
604 611
605artifact * 612artifact *
606locate_recipe_artifact (const recipe *rp, size_t idx) 613locate_recipe_artifact (const recipe *rp, size_t idx)
607{ 614{
608 object *item = get_archetype (rp->arch_name[idx]); 615 archetype *at = archetype::find (rp->arch_name [idx]);
609 artifactlist *at = NULL;
610 artifact *art = NULL;
611 616
612 if (!item) 617 if (at)
613 return (artifact *) NULL;
614
615 if ((at = find_artifactlist (item->type))) 618 if (artifactlist *al = find_artifactlist (at->type))
616 for (art = at->items; art; art = art->next) 619 for (artifact *art = al->items; art; art = art->next)
617 if (!strcmp (art->item->name, rp->title)) 620 if (art->item->name == rp->title)
618 break; 621 return art;
619 622
620 free_object (item);
621
622 return art; 623 return 0;
623} 624}
624 625
625int 626int
626numb_ingred (const char *buf) 627numb_ingred (const char *buf)
627{ 628{
643 for (fl = get_formulalist (1); fl; fl = fl->next) 644 for (fl = get_formulalist (1); fl; fl = fl->next)
644 number++; 645 number++;
645 646
646 /* now, randomly choose one */ 647 /* now, randomly choose one */
647 if (number > 0) 648 if (number > 0)
648 roll = RANDOM () % number; 649 roll = rndm (number);
649 650
650 fl = get_formulalist (1); 651 fl = get_formulalist (1);
651 while (roll && fl) 652 while (roll && fl)
652 { 653 {
653 if (fl->next) 654 if (fl->next)
676 if ((fl = get_random_recipelist ()) == NULL) 677 if ((fl = get_random_recipelist ()) == NULL)
677 return rp; 678 return rp;
678 679
679 if (fl->total_chance > 0) 680 if (fl->total_chance > 0)
680 { 681 {
681 r = RANDOM () % fl->total_chance; 682 r = rndm (fl->total_chance);
682 for (rp = fl->items; rp; rp = rp->next) 683 for (rp = fl->items; rp; rp = rp->next)
683 { 684 {
684 r -= rp->chance; 685 r -= rp->chance;
685 if (r < 0) 686 if (r < 0)
686 break; 687 break;
737 char *dup; 738 char *dup;
738 char *p; 739 char *p;
739 size_t size; 740 size_t size;
740 size_t i; 741 size_t i;
741 742
742 dup = strdup_local (str); 743 dup = strdup (str);
743 if (dup == NULL) 744 if (dup == NULL)
744 fatal (OUT_OF_MEMORY); 745 fatal (OUT_OF_MEMORY);
745 746
746 size = 0; 747 size = 0;
747 for (p = strtok (dup, ","); p != NULL; p = strtok (NULL, ",")) 748 for (p = strtok (dup, ","); p != NULL; p = strtok (NULL, ","))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines