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.10 by elmex, Thu Dec 14 00:08:52 2006 UTC vs.
Revision 1.23 by root, Sun Jul 1 05:00:18 2007 UTC

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