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