|
|
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 |
… | |
… | |
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 (void) |
… | |
… | |
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 | } |
… | |
… | |
104 | result = 0; |
129 | result = 0; |
105 | } |
130 | } |
106 | } |
131 | } |
107 | |
132 | |
108 | return result; |
133 | return result; |
|
|
134 | } |
|
|
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 (void) |
|
|
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 | |
109 | } |
167 | } |
110 | |
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. |
… | |
… | |
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 | 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 |
326 | /* If several archetypes have the same name, the value of the first |
386 | * one with that name will be returned. This happens for the |
327 | * one with that name will be returned. This happens for the |
… | |
… | |
391 | * body parts that we are looking for (e.g. big_dragon and |
332 | * body parts that we are looking for (e.g. big_dragon and |
392 | * big_dragon_worthless). */ |
333 | * big_dragon_worthless). */ |
393 | long |
334 | long |
394 | find_ingred_cost (const char *name) |
335 | find_ingred_cost (const char *name) |
395 | { |
336 | { |
396 | archetype *at; |
|
|
397 | archetype *at2; |
337 | archetype *at2; |
398 | artifactlist *al; |
338 | artifactlist *al; |
399 | artifact *art; |
339 | artifact *art; |
400 | long mult; |
340 | long mult; |
401 | char *cp; |
341 | char *cp; |
… | |
… | |
414 | name++; |
354 | name++; |
415 | else |
355 | else |
416 | mult = 1; |
356 | mult = 1; |
417 | |
357 | |
418 | /* first, try to match the name of an archetype */ |
358 | /* first, try to match the name of an archetype */ |
419 | for (at = first_archetype; at != NULL; at = at->next) |
359 | for_all_archetypes (at) |
420 | { |
360 | { |
421 | if (at->clone.title != NULL) |
361 | if (at->title != NULL) |
422 | { |
362 | { |
423 | /* inefficient, but who cares? */ |
363 | /* inefficient, but who cares? */ |
424 | sprintf (part1, "%s %s", &at->clone.name, &at->clone.title); |
364 | sprintf (part1, "%s %s", &at->object::name, &at->title); |
425 | if (!strcasecmp (part1, name)) |
365 | if (!strcasecmp (part1, name)) |
426 | return mult * at->clone.value; |
366 | return mult * at->value; |
427 | } |
367 | } |
428 | if (!strcasecmp (at->clone.name, name)) |
368 | if (!strcasecmp (at->object::name, name)) |
429 | return mult * at->clone.value; |
369 | return mult * at->value; |
430 | } |
370 | } |
431 | |
371 | |
432 | /* second, try to match an artifact ("arch of something") */ |
372 | /* second, try to match an artifact ("arch of something") */ |
433 | cp = strstr (name, " of "); |
373 | cp = strstr (name, " of "); |
434 | if (cp != NULL) |
374 | if (cp != NULL) |
435 | { |
375 | { |
436 | strcpy (part1, name); |
376 | strcpy (part1, name); |
437 | part1[cp - name] = '\0'; |
377 | part1[cp - name] = '\0'; |
438 | strcpy (part2, cp + 4); |
378 | strcpy (part2, cp + 4); |
|
|
379 | |
439 | /* find the first archetype matching the first part of the name */ |
380 | /* find the first archetype matching the first part of the name */ |
440 | for (at = first_archetype; at != NULL; at = at->next) |
381 | for_all_archetypes (at) |
441 | if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL) |
382 | if (at->object::name.eq_nc (part1) && !at->title) |
442 | break; |
|
|
443 | if (at != NULL) |
|
|
444 | { |
383 | { |
445 | /* find the first artifact derived from that archetype (same type) */ |
384 | /* find the first artifact derived from that archetype (same type) */ |
446 | for (al = first_artifactlist; al != NULL; al = al->next) |
385 | for (al = first_artifactlist; al; al = al->next) |
447 | if (al->type == at->clone.type) |
386 | if (al->type == at->type) |
448 | { |
387 | { |
449 | for (art = al->items; art != NULL; art = art->next) |
388 | for (art = al->items; art; art = art->next) |
450 | if (!strcasecmp (art->item->name, part2)) |
389 | if (!strcasecmp (art->item->name, part2)) |
451 | return mult * at->clone.value * art->item->value; |
390 | return mult * at->value * art->item->value; |
452 | } |
391 | } |
453 | } |
392 | } |
454 | } |
393 | } |
455 | |
394 | |
456 | /* third, try to match a body part ("arch's something") */ |
395 | /* third, try to match a body part ("arch's something") */ |
457 | cp = strstr (name, "'s "); |
396 | cp = strstr (name, "'s "); |
458 | if (cp) |
397 | if (cp) |
459 | { |
398 | { |
460 | strcpy (part1, name); |
399 | strcpy (part1, name); |
461 | part1[cp - name] = '\0'; |
400 | part1[cp - name] = '\0'; |
462 | strcpy (part2, cp + 3); |
401 | strcpy (part2, cp + 3); |
463 | /* examine all archetypes matching the first part of the name */ |
402 | /* examine all archetypes matching the first part of the name */ |
464 | for (at = first_archetype; at != NULL; at = at->next) |
403 | for_all_archetypes (at) |
465 | if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL) |
404 | if (at->object::name.eq_nc (part1) && !at->title) |
466 | { |
405 | { |
467 | if (at->clone.randomitems != NULL) |
406 | if (at->randomitems) |
468 | { |
407 | { |
469 | at2 = find_treasure_by_name (at->clone.randomitems->items, part2, 0); |
408 | at2 = find_treasure_by_name (at->randomitems->items, part2, 0); |
470 | if (at2) |
409 | if (at2) |
471 | return mult * at2->clone.value * isqrt (at->clone.level * 2); |
410 | return mult * at2->value * isqrt (at->level * 2); |
472 | } |
411 | } |
473 | } |
412 | } |
474 | } |
413 | } |
475 | |
414 | |
476 | /* failed to find any matching items -- formula should be checked */ |
415 | /* failed to find any matching items -- formula should be checked */ |
477 | return -1; |
416 | return -1; |
478 | } |
417 | } |
479 | |
418 | |
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 * |
419 | const char * |
573 | ingred_name (const char *name) |
420 | ingred_name (const char *name) |
574 | { |
421 | { |
575 | const char *cp = name; |
422 | const char *cp = name; |
576 | |
423 | |
577 | if (atoi (cp)) |
424 | if (atoi (cp)) |
578 | cp = strchr (cp, ' ') + 1; |
425 | cp = strchr (cp, ' ') + 1; |
|
|
426 | |
579 | return cp; |
427 | return cp; |
580 | } |
|
|
581 | |
|
|
582 | /* strtoint() - we use this to convert buf into an integer |
|
|
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 | } |
428 | } |
615 | |
429 | |
616 | int |
430 | int |
617 | numb_ingred (const char *buf) |
431 | numb_ingred (const char *buf) |
618 | { |
432 | { |
… | |
… | |
620 | |
434 | |
621 | if ((numb = atoi (buf))) |
435 | if ((numb = atoi (buf))) |
622 | return numb; |
436 | return numb; |
623 | else |
437 | else |
624 | return 1; |
438 | return 1; |
|
|
439 | } |
|
|
440 | |
|
|
441 | /* strtoint() - we use this to convert buf into an integer |
|
|
442 | * equal to the coadded sum of the (lowercase) character |
|
|
443 | * ASCII values in buf (times prepended integers). |
|
|
444 | * Some kind of hashing. |
|
|
445 | */ |
|
|
446 | int |
|
|
447 | strtoint (const char *buf) |
|
|
448 | { |
|
|
449 | const char *cp = ingred_name (buf); |
|
|
450 | int val = 0, len = strlen (cp), mult = numb_ingred (buf); |
|
|
451 | |
|
|
452 | while (len) |
|
|
453 | { |
|
|
454 | val += tolower (*cp); |
|
|
455 | cp++; |
|
|
456 | len--; |
|
|
457 | } |
|
|
458 | |
|
|
459 | return val * mult; |
|
|
460 | } |
|
|
461 | |
|
|
462 | artifact * |
|
|
463 | locate_recipe_artifact (const recipe *rp, size_t idx) |
|
|
464 | { |
|
|
465 | archetype *at = archetype::find (rp->arch_name [idx]); |
|
|
466 | |
|
|
467 | if (at) |
|
|
468 | if (artifactlist *al = find_artifactlist (at->type)) |
|
|
469 | for (artifact *art = al->items; art; art = art->next) |
|
|
470 | if (art->item->name == rp->title) |
|
|
471 | return art; |
|
|
472 | |
|
|
473 | return 0; |
625 | } |
474 | } |
626 | |
475 | |
627 | recipelist * |
476 | recipelist * |
628 | get_random_recipelist (void) |
477 | get_random_recipelist (void) |
629 | { |
478 | { |