|
|
1 | /* |
|
|
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
|
|
3 | * |
|
|
4 | * Copyright (©) 2005,2006,2007,2008 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 it under |
|
|
9 | * the terms of the Affero GNU General Public License as published by the |
|
|
10 | * Free Software Foundation, either version 3 of the License, or (at your |
|
|
11 | * 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 Affero GNU General Public License |
|
|
19 | * and the GNU General Public License along with this program. If not, see |
|
|
20 | * <http://www.gnu.org/licenses/>. |
|
|
21 | * |
|
|
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
|
|
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 |
… | |
… | |
26 | static void build_stringlist (const char *str, char ***result_list, size_t * result_size); |
50 | static void build_stringlist (const char *str, char ***result_list, size_t * result_size); |
27 | |
51 | |
28 | static recipelist *formulalist; |
52 | static recipelist *formulalist; |
29 | |
53 | |
30 | static recipelist * |
54 | static recipelist * |
31 | init_recipelist (void) |
55 | init_recipelist () |
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 () |
44 | { |
69 | { |
45 | recipe *t = new recipe; |
70 | recipe *t = new recipe; |
46 | |
71 | |
47 | t->chance = 0; |
72 | t->chance = 0; |
48 | t->index = 0; |
73 | t->index = 0; |
… | |
… | |
86 | size_t i; |
111 | size_t i; |
87 | int result = 1; |
112 | int result = 1; |
88 | |
113 | |
89 | for (i = 0; i < rp->arch_names; i++) |
114 | for (i = 0; i < rp->arch_names; i++) |
90 | { |
115 | { |
91 | if (archetype::find (rp->arch_name[i]) != NULL) |
116 | if (archetype::find (rp->arch_name[i])) |
92 | { |
117 | { |
93 | artifact *art = locate_recipe_artifact (rp, i); |
118 | artifact *art = locate_recipe_artifact (rp, i); |
94 | |
119 | |
95 | if (!art && strcmp (rp->title, "NONE") != 0) |
120 | if (!art && rp->title != shstr_NONE) |
96 | { |
121 | { |
97 | LOG (llevError, "WARNING: Formula %s of %s has no artifact.\n", rp->arch_name[i], &rp->title); |
122 | LOG (llevError, "WARNING: Formula %s of %s has no artifact.\n", rp->arch_name[i], &rp->title); |
98 | result = 0; |
123 | result = 0; |
99 | } |
124 | } |
100 | } |
125 | } |
… | |
… | |
106 | } |
131 | } |
107 | |
132 | |
108 | return result; |
133 | return result; |
109 | } |
134 | } |
110 | |
135 | |
|
|
136 | /* check_formulae()- since we are doing a squential search on the |
|
|
137 | * formulae lists now, we have to be carefull that we dont have 2 |
|
|
138 | * formula with the exact same index value. Under the new nbatches |
|
|
139 | * code, it is possible to have multiples of ingredients in a cauldron |
|
|
140 | * which could result in an index formula mismatch. We *don't* check for |
|
|
141 | * that possibility here. -b.t. |
|
|
142 | */ |
|
|
143 | static void |
|
|
144 | check_formulae () |
|
|
145 | { |
|
|
146 | recipelist *fl; |
|
|
147 | recipe *check, *formula; |
|
|
148 | int numb = 1; |
|
|
149 | |
|
|
150 | LOG (llevDebug, "Checking formulae lists...\n"); |
|
|
151 | |
|
|
152 | for (fl = formulalist; fl; fl = fl->next) |
|
|
153 | { |
|
|
154 | for (formula = fl->items; formula; formula = formula->next) |
|
|
155 | for (check = formula->next; check; check = check->next) |
|
|
156 | if (check->index == formula->index) |
|
|
157 | { |
|
|
158 | LOG (llevError, " ERROR: On %d ingred list: ", numb); |
|
|
159 | LOG (llevError, "Formulae [%s] of %s and [%s] of %s have matching index id (%d)\n", |
|
|
160 | formula->arch_name[0], &formula->title, check->arch_name[0], &check->title, formula->index); |
|
|
161 | } |
|
|
162 | numb++; |
|
|
163 | } |
|
|
164 | |
|
|
165 | LOG (llevDebug, "done.\n"); |
|
|
166 | |
|
|
167 | } |
|
|
168 | |
111 | /* |
169 | /* |
112 | * init_formulae() - Builds up the lists of formula from the file in |
170 | * init_formulae() - Builds up the lists of formula from the file in |
113 | * the libdir. -b.t. |
171 | * the libdir. -b.t. |
114 | */ |
172 | */ |
115 | void |
173 | void |
116 | init_formulae (void) |
174 | init_formulae () |
117 | { |
175 | { |
118 | static int has_been_done = 0; |
176 | static int has_been_done = 0; |
119 | FILE *fp; |
177 | FILE *fp; |
120 | char filename[MAX_BUF], buf[MAX_BUF], *cp, *next; |
178 | char filename[MAX_BUF], buf[MAX_BUF], *cp, *next; |
121 | recipe *formula = NULL; |
179 | recipe *formula = NULL; |
… | |
… | |
225 | close_and_delete (fp, comp); |
283 | close_and_delete (fp, comp); |
226 | /* Lastly, lets check for problems in formula we got */ |
284 | /* Lastly, lets check for problems in formula we got */ |
227 | check_formulae (); |
285 | check_formulae (); |
228 | } |
286 | } |
229 | |
287 | |
230 | /* check_formulae()- since we are doing a squential search on the |
|
|
231 | * formulae lists now, we have to be carefull that we dont have 2 |
|
|
232 | * formula with the exact same index value. Under the new nbatches |
|
|
233 | * code, it is possible to have multiples of ingredients in a cauldron |
|
|
234 | * which could result in an index formula mismatch. We *don't* check for |
|
|
235 | * that possibility here. -b.t. |
|
|
236 | */ |
|
|
237 | void |
|
|
238 | check_formulae (void) |
|
|
239 | { |
|
|
240 | recipelist *fl; |
|
|
241 | recipe *check, *formula; |
|
|
242 | int numb = 1; |
|
|
243 | |
|
|
244 | LOG (llevDebug, "Checking formulae lists...\n"); |
|
|
245 | |
|
|
246 | for (fl = formulalist; fl != NULL; fl = fl->next) |
|
|
247 | { |
|
|
248 | for (formula = fl->items; formula != NULL; formula = formula->next) |
|
|
249 | for (check = formula->next; check != NULL; check = check->next) |
|
|
250 | if (check->index == formula->index) |
|
|
251 | { |
|
|
252 | 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", |
|
|
254 | formula->arch_name[0], &formula->title, check->arch_name[0], &check->title, formula->index); |
|
|
255 | } |
|
|
256 | numb++; |
|
|
257 | } |
|
|
258 | |
|
|
259 | LOG (llevDebug, "done.\n"); |
|
|
260 | |
|
|
261 | } |
|
|
262 | |
|
|
263 | /* Borrowed (again) from the artifacts code for this */ |
|
|
264 | |
|
|
265 | void |
|
|
266 | dump_alchemy (void) |
|
|
267 | { |
|
|
268 | recipelist *fl = formulalist; |
|
|
269 | recipe *formula = NULL; |
|
|
270 | linked_char *next; |
|
|
271 | int num_ingred = 1; |
|
|
272 | |
|
|
273 | fprintf (logfile, "\n"); |
|
|
274 | while (fl) |
|
|
275 | { |
|
|
276 | 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); |
|
|
278 | for (formula = fl->items; formula != NULL; formula = formula->next) |
|
|
279 | { |
|
|
280 | artifact *art = NULL; |
|
|
281 | char buf[MAX_BUF]; |
|
|
282 | size_t i; |
|
|
283 | |
|
|
284 | for (i = 0; i < formula->arch_names; i++) |
|
|
285 | { |
|
|
286 | const char *string = formula->arch_name[i]; |
|
|
287 | |
|
|
288 | if (archetype::find (string) != NULL) |
|
|
289 | { |
|
|
290 | art = locate_recipe_artifact (formula, i); |
|
|
291 | if (!art && strcmp (formula->title, "NONE")) |
|
|
292 | LOG (llevError, "Formula %s has no artifact!\n", &formula->title); |
|
|
293 | else |
|
|
294 | { |
|
|
295 | if (strcmp (formula->title, "NONE")) |
|
|
296 | sprintf (buf, "%s of %s", string, &formula->title); |
|
|
297 | else |
|
|
298 | sprintf (buf, "%s", string); |
|
|
299 | fprintf (logfile, "%-30s(%d) bookchance %3d ", buf, formula->index, formula->chance); |
|
|
300 | fprintf (logfile, "skill %s", &formula->skill); |
|
|
301 | fprintf (logfile, "\n"); |
|
|
302 | if (formula->ingred != NULL) |
|
|
303 | { |
|
|
304 | int nval = 0, tval = 0; |
|
|
305 | |
|
|
306 | fprintf (logfile, "\tIngred: "); |
|
|
307 | for (next = formula->ingred; next != NULL; next = next->next) |
|
|
308 | { |
|
|
309 | if (nval != 0) |
|
|
310 | fprintf (logfile, ","); |
|
|
311 | fprintf (logfile, "%s(%d)", &next->name, (nval = strtoint (next->name))); |
|
|
312 | tval += nval; |
|
|
313 | } |
|
|
314 | fprintf (logfile, "\n"); |
|
|
315 | if (tval != formula->index) |
|
|
316 | fprintf (logfile, "WARNING:ingredient list and formula values not equal.\n"); |
|
|
317 | } |
|
|
318 | if (formula->skill != NULL) |
|
|
319 | fprintf (logfile, "\tSkill Required: %s", &formula->skill); |
|
|
320 | if (formula->cauldron != NULL) |
|
|
321 | fprintf (logfile, "\tCauldron: %s\n", &formula->cauldron); |
|
|
322 | fprintf (logfile, "\tDifficulty: %d\t Exp: %d\n", formula->diff, formula->exp); |
|
|
323 | } |
|
|
324 | } |
|
|
325 | else |
|
|
326 | LOG (llevError, "Can't find archetype:%s for formula %s\n", string, &formula->title); |
|
|
327 | } |
|
|
328 | } |
|
|
329 | fprintf (logfile, "\n"); |
|
|
330 | fl = fl->next; |
|
|
331 | num_ingred++; |
|
|
332 | } |
|
|
333 | } |
|
|
334 | |
|
|
335 | /* Find a treasure with a matching name. The 'depth' parameter is |
288 | /* Find a treasure with a matching name. The 'depth' parameter is |
336 | * only there to prevent infinite loops in treasure lists (a list |
289 | * only there to prevent infinite loops in treasure lists (a list |
337 | * referencing another list pointing back to the first one). */ |
290 | * referencing another list pointing back to the first one). */ |
338 | archetype * |
291 | static archetype * |
339 | find_treasure_by_name (const treasure *t, const char *name, int depth) |
292 | find_treasure_by_name (const treasure *t, const char *name, int depth) |
340 | { |
293 | { |
341 | treasurelist *tl; |
|
|
342 | archetype *at; |
|
|
343 | |
|
|
344 | if (depth > 10) |
294 | if (depth > 10) |
345 | return 0; |
295 | return 0; |
346 | |
296 | |
347 | while (t) |
297 | while (t) |
348 | { |
298 | { |
349 | if (t->name) |
299 | if (t->name) |
350 | { |
300 | { |
351 | tl = find_treasurelist (t->name); |
301 | if (treasurelist *tl = treasurelist::find (t->name)) |
352 | |
|
|
353 | if (tl) |
302 | if (tl->items) |
354 | { |
|
|
355 | at = find_treasure_by_name (tl->items, name, depth + 1); |
303 | if (archetype *at = find_treasure_by_name (tl->items, name, depth + 1)) |
356 | |
|
|
357 | if (at) |
|
|
358 | return at; |
304 | return at; |
359 | } |
|
|
360 | } |
305 | } |
361 | else |
306 | else |
362 | { |
307 | { |
363 | if (t->item && !strcasecmp (t->item->clone.name, name)) |
308 | if (t->item && !strcasecmp (t->item->object::name, name)) |
364 | return t->item; |
309 | return t->item; |
365 | } |
310 | } |
366 | |
311 | |
367 | if (t->next_yes) |
312 | if (t->next_yes) |
368 | { |
|
|
369 | at = find_treasure_by_name (t->next_yes, name, depth); |
313 | if (archetype *at = find_treasure_by_name (t->next_yes, name, depth)) |
370 | if (at) |
|
|
371 | return at; |
314 | return at; |
372 | } |
|
|
373 | |
315 | |
374 | if (t->next_no) |
316 | if (t->next_no) |
375 | { |
|
|
376 | at = find_treasure_by_name (t->next_no, name, depth); |
317 | if (archetype *at = find_treasure_by_name (t->next_no, name, depth)) |
377 | if (at) |
|
|
378 | return at; |
318 | return at; |
379 | } |
319 | |
380 | t = t->next; |
320 | t = t->next; |
381 | } |
321 | } |
|
|
322 | |
382 | return 0; |
323 | return 0; |
383 | } |
324 | } |
384 | |
325 | |
385 | /* If several archetypes have the same name, the value of the first |
|
|
386 | * one with that name will be returned. This happens for the |
|
|
387 | * mushrooms (mushroom_1, mushroom_2 and mushroom_3). For the |
|
|
388 | * monsters' body parts, there may be several monsters with the same |
|
|
389 | * name. This is not a problem if these monsters have the same level |
|
|
390 | * (e.g. sage & c_sage) or if only one of the monsters generates the |
|
|
391 | * body parts that we are looking for (e.g. big_dragon and |
|
|
392 | * big_dragon_worthless). */ |
|
|
393 | long |
|
|
394 | find_ingred_cost (const char *name) |
|
|
395 | { |
|
|
396 | archetype *at; |
|
|
397 | archetype *at2; |
|
|
398 | artifactlist *al; |
|
|
399 | artifact *art; |
|
|
400 | long mult; |
|
|
401 | char *cp; |
|
|
402 | char part1[100]; |
|
|
403 | char part2[100]; |
|
|
404 | |
|
|
405 | /* same as atoi(), but skip number */ |
|
|
406 | mult = 0; |
|
|
407 | while (isdigit (*name)) |
|
|
408 | { |
|
|
409 | mult = 10 * mult + (*name - '0'); |
|
|
410 | name++; |
|
|
411 | } |
|
|
412 | |
|
|
413 | if (mult > 0) |
|
|
414 | name++; |
|
|
415 | else |
|
|
416 | mult = 1; |
|
|
417 | |
|
|
418 | /* first, try to match the name of an archetype */ |
|
|
419 | for (at = first_archetype; at != NULL; at = at->next) |
|
|
420 | { |
|
|
421 | if (at->clone.title != NULL) |
|
|
422 | { |
|
|
423 | /* inefficient, but who cares? */ |
|
|
424 | sprintf (part1, "%s %s", &at->clone.name, &at->clone.title); |
|
|
425 | if (!strcasecmp (part1, name)) |
|
|
426 | return mult * at->clone.value; |
|
|
427 | } |
|
|
428 | if (!strcasecmp (at->clone.name, name)) |
|
|
429 | return mult * at->clone.value; |
|
|
430 | } |
|
|
431 | |
|
|
432 | /* second, try to match an artifact ("arch of something") */ |
|
|
433 | cp = strstr (name, " of "); |
|
|
434 | if (cp != NULL) |
|
|
435 | { |
|
|
436 | strcpy (part1, name); |
|
|
437 | part1[cp - name] = '\0'; |
|
|
438 | strcpy (part2, cp + 4); |
|
|
439 | /* find the first archetype matching the first part of the name */ |
|
|
440 | for (at = first_archetype; at != NULL; at = at->next) |
|
|
441 | if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL) |
|
|
442 | break; |
|
|
443 | if (at != NULL) |
|
|
444 | { |
|
|
445 | /* find the first artifact derived from that archetype (same type) */ |
|
|
446 | for (al = first_artifactlist; al != NULL; al = al->next) |
|
|
447 | if (al->type == at->clone.type) |
|
|
448 | { |
|
|
449 | for (art = al->items; art != NULL; art = art->next) |
|
|
450 | if (!strcasecmp (art->item->name, part2)) |
|
|
451 | return mult * at->clone.value * art->item->value; |
|
|
452 | } |
|
|
453 | } |
|
|
454 | } |
|
|
455 | |
|
|
456 | /* third, try to match a body part ("arch's something") */ |
|
|
457 | cp = strstr (name, "'s "); |
|
|
458 | if (cp) |
|
|
459 | { |
|
|
460 | strcpy (part1, name); |
|
|
461 | part1[cp - name] = '\0'; |
|
|
462 | strcpy (part2, cp + 3); |
|
|
463 | /* examine all archetypes matching the first part of the name */ |
|
|
464 | for (at = first_archetype; at != NULL; at = at->next) |
|
|
465 | if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL) |
|
|
466 | { |
|
|
467 | if (at->clone.randomitems != NULL) |
|
|
468 | { |
|
|
469 | at2 = find_treasure_by_name (at->clone.randomitems->items, part2, 0); |
|
|
470 | if (at2) |
|
|
471 | return mult * at2->clone.value * isqrt (at->clone.level * 2); |
|
|
472 | } |
|
|
473 | } |
|
|
474 | } |
|
|
475 | |
|
|
476 | /* failed to find any matching items -- formula should be checked */ |
|
|
477 | return -1; |
|
|
478 | } |
|
|
479 | |
|
|
480 | /* code copied from dump_alchemy() and modified by Raphael Quinet */ |
|
|
481 | void |
|
|
482 | dump_alchemy_costs (void) |
|
|
483 | { |
|
|
484 | recipelist *fl = formulalist; |
|
|
485 | recipe *formula = NULL; |
|
|
486 | linked_char *next; |
|
|
487 | int num_ingred = 1; |
|
|
488 | int num_errors = 0; |
|
|
489 | long cost; |
|
|
490 | long tcost; |
|
|
491 | |
|
|
492 | fprintf (logfile, "\n"); |
|
|
493 | while (fl) |
|
|
494 | { |
|
|
495 | 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); |
|
|
497 | for (formula = fl->items; formula != NULL; formula = formula->next) |
|
|
498 | { |
|
|
499 | artifact *art = NULL; |
|
|
500 | archetype *at = NULL; |
|
|
501 | char buf[MAX_BUF]; |
|
|
502 | size_t i; |
|
|
503 | |
|
|
504 | for (i = 0; i < formula->arch_names; i++) |
|
|
505 | { |
|
|
506 | const char *string = formula->arch_name[i]; |
|
|
507 | |
|
|
508 | if ((at = archetype::find (string)) != NULL) |
|
|
509 | { |
|
|
510 | art = locate_recipe_artifact (formula, i); |
|
|
511 | if (!art && strcmp (formula->title, "NONE")) |
|
|
512 | LOG (llevError, "Formula %s has no artifact\n", &formula->title); |
|
|
513 | else |
|
|
514 | { |
|
|
515 | if (!strcmp (formula->title, "NONE")) |
|
|
516 | sprintf (buf, "%s", string); |
|
|
517 | else |
|
|
518 | sprintf (buf, "%s of %s", string, &formula->title); |
|
|
519 | fprintf (logfile, "\n%-40s bookchance %3d skill %s\n", buf, formula->chance, &(formula->skill)); |
|
|
520 | if (formula->ingred != NULL) |
|
|
521 | { |
|
|
522 | tcost = 0; |
|
|
523 | for (next = formula->ingred; next != NULL; next = next->next) |
|
|
524 | { |
|
|
525 | cost = find_ingred_cost (next->name); |
|
|
526 | if (cost < 0) |
|
|
527 | num_errors++; |
|
|
528 | fprintf (logfile, "\t%-33s%5ld\n", &next->name, cost); |
|
|
529 | if (cost < 0 || tcost < 0) |
|
|
530 | tcost = -1; |
|
|
531 | else |
|
|
532 | tcost += cost; |
|
|
533 | } |
|
|
534 | if (art != NULL && art->item != NULL) |
|
|
535 | cost = at->clone.value * art->item->value; |
|
|
536 | else |
|
|
537 | cost = at->clone.value; |
|
|
538 | fprintf (logfile, "\t\tBuying result costs: %5ld", cost); |
|
|
539 | if (formula->yield > 1) |
|
|
540 | { |
|
|
541 | fprintf (logfile, " to %ld (max %d items)\n", cost * formula->yield, formula->yield); |
|
|
542 | cost = cost * (formula->yield + 1L) / 2L; |
|
|
543 | } |
|
|
544 | else |
|
|
545 | fprintf (logfile, "\n"); |
|
|
546 | fprintf (logfile, "\t\tIngredients cost: %5ld\n\t\tComment: ", tcost); |
|
|
547 | if (tcost < 0) |
|
|
548 | fprintf (logfile, "Could not find some ingredients. Check the formula!\n"); |
|
|
549 | else if (tcost > cost) |
|
|
550 | fprintf (logfile, "Ingredients are much too expensive. Useless formula.\n"); |
|
|
551 | else if (tcost * 2L > cost) |
|
|
552 | fprintf (logfile, "Ingredients are too expensive.\n"); |
|
|
553 | else if (tcost * 10L < cost) |
|
|
554 | fprintf (logfile, "Ingredients are too cheap.\n"); |
|
|
555 | else |
|
|
556 | fprintf (logfile, "OK.\n"); |
|
|
557 | } |
|
|
558 | } |
|
|
559 | } |
|
|
560 | else |
|
|
561 | LOG (llevError, "Can't find archetype:%s for formula %s\n", string, &formula->title); |
|
|
562 | } |
|
|
563 | } |
|
|
564 | fprintf (logfile, "\n"); |
|
|
565 | fl = fl->next; |
|
|
566 | num_ingred++; |
|
|
567 | } |
|
|
568 | if (num_errors > 0) |
|
|
569 | fprintf (logfile, "WARNING: %d objects required by the formulae do not exist in the game.\n", num_errors); |
|
|
570 | } |
|
|
571 | |
|
|
572 | const char * |
326 | static const char * |
573 | ingred_name (const char *name) |
327 | ingred_name (const char *name) |
574 | { |
328 | { |
575 | const char *cp = name; |
329 | const char *cp = name; |
576 | |
330 | |
577 | if (atoi (cp)) |
331 | if (atoi (cp)) |
578 | cp = strchr (cp, ' ') + 1; |
332 | cp = strchr (cp, ' ') + 1; |
|
|
333 | |
579 | return cp; |
334 | return cp; |
580 | } |
335 | } |
581 | |
336 | |
582 | /* strtoint() - we use this to convert buf into an integer |
337 | static int |
583 | * equal to the coadded sum of the (lowercase) character |
|
|
584 | * ASCII values in buf (times prepended integers). |
|
|
585 | */ |
|
|
586 | |
|
|
587 | int |
|
|
588 | strtoint (const char *buf) |
|
|
589 | { |
|
|
590 | const char *cp = ingred_name (buf); |
|
|
591 | int val = 0, len = strlen (cp), mult = numb_ingred (buf); |
|
|
592 | |
|
|
593 | while (len) |
|
|
594 | { |
|
|
595 | val += tolower (*cp); |
|
|
596 | cp++; |
|
|
597 | len--; |
|
|
598 | } |
|
|
599 | return val * mult; |
|
|
600 | } |
|
|
601 | |
|
|
602 | artifact * |
|
|
603 | locate_recipe_artifact (const recipe *rp, size_t idx) |
|
|
604 | { |
|
|
605 | archetype *at = archetype::find (rp->arch_name [idx]); |
|
|
606 | |
|
|
607 | if (at) |
|
|
608 | if (artifactlist *al = find_artifactlist (at->clone.type)) |
|
|
609 | for (artifact *art = al->items; art; art = art->next) |
|
|
610 | if (art->item->name == rp->title) |
|
|
611 | return art; |
|
|
612 | |
|
|
613 | return 0; |
|
|
614 | } |
|
|
615 | |
|
|
616 | int |
|
|
617 | numb_ingred (const char *buf) |
338 | numb_ingred (const char *buf) |
618 | { |
339 | { |
619 | int numb; |
340 | int numb; |
620 | |
341 | |
621 | if ((numb = atoi (buf))) |
342 | if ((numb = atoi (buf))) |
622 | return numb; |
343 | return numb; |
623 | else |
344 | else |
624 | return 1; |
345 | return 1; |
625 | } |
346 | } |
626 | |
347 | |
|
|
348 | /* strtoint() - we use this to convert buf into an integer |
|
|
349 | * equal to the coadded sum of the (lowercase) character |
|
|
350 | * ASCII values in buf (times prepended integers). |
|
|
351 | * Some kind of hashing. |
|
|
352 | */ |
|
|
353 | int |
|
|
354 | strtoint (const char *buf) |
|
|
355 | { |
|
|
356 | const char *cp = ingred_name (buf); |
|
|
357 | int val = 0, len = strlen (cp), mult = numb_ingred (buf); |
|
|
358 | |
|
|
359 | while (len) |
|
|
360 | { |
|
|
361 | val += tolower (*cp); |
|
|
362 | cp++; |
|
|
363 | len--; |
|
|
364 | } |
|
|
365 | |
|
|
366 | return val * mult; |
|
|
367 | } |
|
|
368 | |
|
|
369 | artifact * |
|
|
370 | locate_recipe_artifact (const recipe *rp, size_t idx) |
|
|
371 | { |
|
|
372 | archetype *at = archetype::find (rp->arch_name [idx]); |
|
|
373 | |
|
|
374 | if (at) |
|
|
375 | if (artifactlist *al = find_artifactlist (at->type)) |
|
|
376 | for (artifact *art = al->items; art; art = art->next) |
|
|
377 | if (art->item->name == rp->title) |
|
|
378 | return art; |
|
|
379 | |
|
|
380 | return 0; |
|
|
381 | } |
|
|
382 | |
627 | recipelist * |
383 | static recipelist * |
628 | get_random_recipelist (void) |
384 | get_random_recipelist () |
629 | { |
385 | { |
630 | recipelist *fl = NULL; |
386 | recipelist *fl = NULL; |
631 | int number = 0, roll = 0; |
387 | int number = 0, roll = 0; |
632 | |
388 | |
633 | /* first, determine # of recipelist we have */ |
389 | /* first, determine # of recipelist we have */ |
… | |
… | |
676 | if (r < 0) |
432 | if (r < 0) |
677 | break; |
433 | break; |
678 | } |
434 | } |
679 | } |
435 | } |
680 | return rp; |
436 | return rp; |
681 | } |
|
|
682 | |
|
|
683 | void |
|
|
684 | free_all_recipes (void) |
|
|
685 | { |
|
|
686 | recipelist *fl = formulalist, *flnext; |
|
|
687 | recipe *formula = NULL, *next; |
|
|
688 | linked_char *lchar, *charnext; |
|
|
689 | |
|
|
690 | LOG (llevDebug, "Freeing all the recipes\n"); |
|
|
691 | for (fl = formulalist; fl != NULL; fl = flnext) |
|
|
692 | { |
|
|
693 | flnext = fl->next; |
|
|
694 | |
|
|
695 | for (formula = fl->items; formula != NULL; formula = next) |
|
|
696 | { |
|
|
697 | next = formula->next; |
|
|
698 | |
|
|
699 | free (formula->arch_name[0]); |
|
|
700 | free (formula->arch_name); |
|
|
701 | |
|
|
702 | for (lchar = formula->ingred; lchar; lchar = charnext) |
|
|
703 | { |
|
|
704 | charnext = lchar->next; |
|
|
705 | delete lchar; |
|
|
706 | } |
|
|
707 | delete formula; |
|
|
708 | } |
|
|
709 | |
|
|
710 | delete fl; |
|
|
711 | } |
|
|
712 | } |
437 | } |
713 | |
438 | |
714 | /** |
439 | /** |
715 | * Split a comma separated string list into words. |
440 | * Split a comma separated string list into words. |
716 | * |
441 | * |