|
|
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 |
… | |
… | |
10 | * Ingredients are just comma delimited list of archetype (or object) |
34 | * Ingredients are just comma delimited list of archetype (or object) |
11 | * names. |
35 | * names. |
12 | */ |
36 | */ |
13 | |
37 | |
14 | /* Example 'formula' entry in libdir/formulae: |
38 | /* Example 'formula' entry in libdir/formulae: |
15 | * Object transparency |
39 | * object transparency |
16 | * chance 10 |
40 | * chance 10 |
17 | * ingred dust of beholdereye,gem |
41 | * ingred dust of beholdereye,gem |
18 | * arch potion_generic |
42 | * arch potion_generic |
19 | */ |
43 | */ |
20 | |
44 | |
… | |
… | |
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) |
… | |
… | |
60 | t->next = NULL; |
85 | t->next = NULL; |
61 | return t; |
86 | return t; |
62 | } |
87 | } |
63 | |
88 | |
64 | /* get_formulalist() - returns pointer to the formula list */ |
89 | /* get_formulalist() - returns pointer to the formula list */ |
65 | |
|
|
66 | recipelist * |
90 | recipelist * |
67 | get_formulalist (int i) |
91 | get_formulalist (int i) |
68 | { |
92 | { |
69 | recipelist *fl = formulalist; |
93 | recipelist *fl = formulalist; |
70 | int number = i; |
94 | int number = i; |
… | |
… | |
73 | { |
97 | { |
74 | if (!(fl = fl->next)) |
98 | if (!(fl = fl->next)) |
75 | break; |
99 | break; |
76 | number--; |
100 | number--; |
77 | } |
101 | } |
|
|
102 | |
78 | return fl; |
103 | return fl; |
79 | } |
104 | } |
80 | |
105 | |
81 | /* check_recipe() - makes sure we actually have the requested artifact |
106 | /* check_recipe() - makes sure we actually have the requested artifact |
82 | * and archetype. */ |
107 | * and archetype. */ |
83 | |
|
|
84 | static int |
108 | static int |
85 | check_recipe (const recipe *rp) |
109 | check_recipe (const recipe *rp) |
86 | { |
110 | { |
87 | size_t i; |
111 | size_t i; |
88 | int result; |
112 | int result = 1; |
89 | |
113 | |
90 | result = 1; |
|
|
91 | for (i = 0; i < rp->arch_names; i++) |
114 | for (i = 0; i < rp->arch_names; i++) |
92 | { |
115 | { |
93 | if (archetype::find (rp->arch_name[i]) != NULL) |
116 | if (archetype::find (rp->arch_name[i])) |
94 | { |
117 | { |
95 | artifact *art = locate_recipe_artifact (rp, i); |
118 | artifact *art = locate_recipe_artifact (rp, i); |
96 | |
119 | |
97 | if (!art && strcmp (rp->title, "NONE") != 0) |
120 | if (!art && rp->title != shstr_NONE) |
98 | { |
121 | { |
99 | 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); |
100 | result = 0; |
123 | result = 0; |
101 | } |
124 | } |
102 | } |
125 | } |
… | |
… | |
108 | } |
131 | } |
109 | |
132 | |
110 | return result; |
133 | return result; |
111 | } |
134 | } |
112 | |
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 | |
|
|
167 | } |
113 | |
168 | |
114 | /* |
169 | /* |
115 | * 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 |
116 | * the libdir. -b.t. |
171 | * the libdir. -b.t. |
117 | */ |
172 | */ |
118 | |
|
|
119 | void |
173 | void |
120 | init_formulae (void) |
174 | init_formulae (void) |
121 | { |
175 | { |
122 | static int has_been_done = 0; |
176 | static int has_been_done = 0; |
123 | FILE *fp; |
177 | FILE *fp; |
… | |
… | |
151 | *cp = '\0'; |
205 | *cp = '\0'; |
152 | cp = buf; |
206 | cp = buf; |
153 | while (*cp == ' ') /* Skip blanks */ |
207 | while (*cp == ' ') /* Skip blanks */ |
154 | cp++; |
208 | cp++; |
155 | |
209 | |
156 | if (!strncmp (cp, "Object", 6)) |
210 | if (!strncmp (cp, "object", 6)) |
157 | { |
211 | { |
158 | formula = get_empty_formula (); |
212 | formula = get_empty_formula (); |
159 | formula->title = strchr (cp, ' ') + 1; |
213 | formula->title = strchr (cp, ' ') + 1; |
160 | } |
214 | } |
161 | else if (!strncmp (cp, "keycode", 7)) |
215 | else if (!strncmp (cp, "keycode", 7)) |
162 | { |
|
|
163 | formula->keycode = strchr (cp, ' ') + 1; |
216 | formula->keycode = strchr (cp, ' ') + 1; |
164 | } |
|
|
165 | else if (sscanf (cp, "trans %d", &value)) |
217 | else if (sscanf (cp, "trans %d", &value)) |
166 | { |
|
|
167 | formula->transmute = (uint16) value; |
218 | formula->transmute = (uint16) value; |
168 | } |
|
|
169 | else if (sscanf (cp, "yield %d", &value)) |
219 | else if (sscanf (cp, "yield %d", &value)) |
170 | { |
|
|
171 | formula->yield = (uint16) value; |
220 | formula->yield = (uint16) value; |
172 | } |
|
|
173 | else if (sscanf (cp, "chance %d", &value)) |
221 | else if (sscanf (cp, "chance %d", &value)) |
174 | { |
|
|
175 | formula->chance = (uint16) value; |
222 | formula->chance = (uint16) value; |
176 | } |
|
|
177 | else if (sscanf (cp, "exp %d", &value)) |
223 | else if (sscanf (cp, "exp %d", &value)) |
178 | { |
|
|
179 | formula->exp = (uint16) value; |
224 | formula->exp = (uint16) value; |
180 | } |
|
|
181 | else if (sscanf (cp, "diff %d", &value)) |
225 | else if (sscanf (cp, "diff %d", &value)) |
182 | { |
|
|
183 | formula->diff = (uint16) value; |
226 | formula->diff = (uint16) value; |
184 | } |
|
|
185 | else if (!strncmp (cp, "ingred", 6)) |
227 | else if (!strncmp (cp, "ingred", 6)) |
186 | { |
228 | { |
187 | int numb_ingred = 1; |
229 | int numb_ingred = 1; |
188 | |
230 | |
189 | cp = strchr (cp, ' ') + 1; |
231 | cp = strchr (cp, ' ') + 1; |
… | |
… | |
192 | if ((next = strchr (cp, ',')) != NULL) |
234 | if ((next = strchr (cp, ',')) != NULL) |
193 | { |
235 | { |
194 | *(next++) = '\0'; |
236 | *(next++) = '\0'; |
195 | numb_ingred++; |
237 | numb_ingred++; |
196 | } |
238 | } |
|
|
239 | |
197 | tmp = new linked_char; |
240 | tmp = new linked_char; |
198 | |
241 | |
199 | tmp->name = cp; |
242 | tmp->name = cp; |
200 | tmp->next = formula->ingred; |
243 | tmp->next = formula->ingred; |
201 | formula->ingred = tmp; |
244 | formula->ingred = tmp; |
… | |
… | |
204 | * quickly for the right recipe. |
247 | * quickly for the right recipe. |
205 | */ |
248 | */ |
206 | formula->index += strtoint (cp); |
249 | formula->index += strtoint (cp); |
207 | } |
250 | } |
208 | while ((cp = next) != NULL); |
251 | while ((cp = next) != NULL); |
|
|
252 | |
209 | /* now find the correct (# of ingred ordered) formulalist */ |
253 | /* now find the correct (# of ingred ordered) formulalist */ |
210 | fl = formulalist; |
254 | fl = formulalist; |
211 | while (numb_ingred != 1) |
255 | while (numb_ingred != 1) |
212 | { |
256 | { |
213 | if (!fl->next) |
257 | if (!fl->next) |
214 | fl->next = init_recipelist (); |
258 | fl->next = init_recipelist (); |
|
|
259 | |
215 | fl = fl->next; |
260 | fl = fl->next; |
216 | numb_ingred--; |
261 | numb_ingred--; |
217 | } |
262 | } |
|
|
263 | |
218 | fl->total_chance += formula->chance; |
264 | fl->total_chance += formula->chance; |
219 | fl->number++; |
265 | fl->number++; |
220 | formula->next = fl->items; |
266 | formula->next = fl->items; |
221 | fl->items = formula; |
267 | fl->items = formula; |
222 | } |
268 | } |
… | |
… | |
224 | { |
270 | { |
225 | build_stringlist (strchr (cp, ' ') + 1, &formula->arch_name, &formula->arch_names); |
271 | build_stringlist (strchr (cp, ' ') + 1, &formula->arch_name, &formula->arch_names); |
226 | check_recipe (formula); |
272 | check_recipe (formula); |
227 | } |
273 | } |
228 | else if (!strncmp (cp, "skill", 5)) |
274 | else if (!strncmp (cp, "skill", 5)) |
229 | { |
|
|
230 | formula->skill = strchr (cp, ' ') + 1; |
275 | formula->skill = strchr (cp, ' ') + 1; |
231 | } |
|
|
232 | else if (!strncmp (cp, "cauldron", 8)) |
276 | else if (!strncmp (cp, "cauldron", 8)) |
233 | { |
|
|
234 | formula->cauldron = strchr (cp, ' ') + 1; |
277 | formula->cauldron = strchr (cp, ' ') + 1; |
235 | } |
|
|
236 | else |
278 | else |
237 | LOG (llevError, "Unknown input in file %s: %s\n", filename, buf); |
279 | LOG (llevError, "Unknown input in file %s: %s\n", filename, buf); |
238 | } |
280 | } |
|
|
281 | |
239 | LOG (llevDebug, "done.\n"); |
282 | LOG (llevDebug, "done.\n"); |
240 | close_and_delete (fp, comp); |
283 | close_and_delete (fp, comp); |
241 | /* Lastly, lets check for problems in formula we got */ |
284 | /* Lastly, lets check for problems in formula we got */ |
242 | check_formulae (); |
285 | check_formulae (); |
243 | } |
|
|
244 | |
|
|
245 | /* check_formulae()- since we are doing a squential search on the |
|
|
246 | * formulae lists now, we have to be carefull that we dont have 2 |
|
|
247 | * formula with the exact same index value. Under the new nbatches |
|
|
248 | * code, it is possible to have multiples of ingredients in a cauldron |
|
|
249 | * which could result in an index formula mismatch. We *don't* check for |
|
|
250 | * that possibility here. -b.t. |
|
|
251 | */ |
|
|
252 | void |
|
|
253 | check_formulae (void) |
|
|
254 | { |
|
|
255 | recipelist *fl; |
|
|
256 | recipe *check, *formula; |
|
|
257 | int numb = 1; |
|
|
258 | |
|
|
259 | LOG (llevDebug, "Checking formulae lists...\n"); |
|
|
260 | |
|
|
261 | for (fl = formulalist; fl != NULL; fl = fl->next) |
|
|
262 | { |
|
|
263 | for (formula = fl->items; formula != NULL; formula = formula->next) |
|
|
264 | for (check = formula->next; check != NULL; check = check->next) |
|
|
265 | if (check->index == formula->index) |
|
|
266 | { |
|
|
267 | 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", |
|
|
269 | formula->arch_name[0], &formula->title, check->arch_name[0], &check->title, formula->index); |
|
|
270 | } |
|
|
271 | numb++; |
|
|
272 | } |
|
|
273 | |
|
|
274 | LOG (llevDebug, "done.\n"); |
|
|
275 | |
|
|
276 | } |
|
|
277 | |
|
|
278 | /* Borrowed (again) from the artifacts code for this */ |
|
|
279 | |
|
|
280 | void |
|
|
281 | dump_alchemy (void) |
|
|
282 | { |
|
|
283 | recipelist *fl = formulalist; |
|
|
284 | recipe *formula = NULL; |
|
|
285 | linked_char *next; |
|
|
286 | int num_ingred = 1; |
|
|
287 | |
|
|
288 | fprintf (logfile, "\n"); |
|
|
289 | while (fl) |
|
|
290 | { |
|
|
291 | 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); |
|
|
293 | for (formula = fl->items; formula != NULL; formula = formula->next) |
|
|
294 | { |
|
|
295 | artifact *art = NULL; |
|
|
296 | char buf[MAX_BUF]; |
|
|
297 | size_t i; |
|
|
298 | |
|
|
299 | for (i = 0; i < formula->arch_names; i++) |
|
|
300 | { |
|
|
301 | const char *string = formula->arch_name[i]; |
|
|
302 | |
|
|
303 | if (archetype::find (string) != NULL) |
|
|
304 | { |
|
|
305 | art = locate_recipe_artifact (formula, i); |
|
|
306 | if (!art && strcmp (formula->title, "NONE")) |
|
|
307 | LOG (llevError, "Formula %s has no artifact\n", &formula->title); |
|
|
308 | else |
|
|
309 | { |
|
|
310 | if (strcmp (formula->title, "NONE")) |
|
|
311 | sprintf (buf, "%s of %s", string, &formula->title); |
|
|
312 | else |
|
|
313 | sprintf (buf, "%s", string); |
|
|
314 | fprintf (logfile, "%-30s(%d) bookchance %3d ", buf, formula->index, formula->chance); |
|
|
315 | fprintf (logfile, "skill %s", &formula->skill); |
|
|
316 | fprintf (logfile, "\n"); |
|
|
317 | if (formula->ingred != NULL) |
|
|
318 | { |
|
|
319 | int nval = 0, tval = 0; |
|
|
320 | |
|
|
321 | fprintf (logfile, "\tIngred: "); |
|
|
322 | for (next = formula->ingred; next != NULL; next = next->next) |
|
|
323 | { |
|
|
324 | if (nval != 0) |
|
|
325 | fprintf (logfile, ","); |
|
|
326 | fprintf (logfile, "%s(%d)", &next->name, (nval = strtoint (next->name))); |
|
|
327 | tval += nval; |
|
|
328 | } |
|
|
329 | fprintf (logfile, "\n"); |
|
|
330 | if (tval != formula->index) |
|
|
331 | fprintf (logfile, "WARNING:ingredient list and formula values not equal.\n"); |
|
|
332 | } |
|
|
333 | if (formula->skill != NULL) |
|
|
334 | fprintf (logfile, "\tSkill Required: %s", &formula->skill); |
|
|
335 | if (formula->cauldron != NULL) |
|
|
336 | fprintf (logfile, "\tCauldron: %s\n", &formula->cauldron); |
|
|
337 | fprintf (logfile, "\tDifficulty: %d\t Exp: %d\n", formula->diff, formula->exp); |
|
|
338 | } |
|
|
339 | } |
|
|
340 | else |
|
|
341 | LOG (llevError, "Can't find archetype:%s for formula %s\n", string, &formula->title); |
|
|
342 | } |
|
|
343 | } |
|
|
344 | fprintf (logfile, "\n"); |
|
|
345 | fl = fl->next; |
|
|
346 | num_ingred++; |
|
|
347 | } |
|
|
348 | } |
286 | } |
349 | |
287 | |
350 | /* Find a treasure with a matching name. The 'depth' parameter is |
288 | /* Find a treasure with a matching name. The 'depth' parameter is |
351 | * only there to prevent infinite loops in treasure lists (a list |
289 | * only there to prevent infinite loops in treasure lists (a list |
352 | * referencing another list pointing back to the first one). */ |
290 | * referencing another list pointing back to the first one). */ |
353 | archetype * |
291 | archetype * |
354 | 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) |
355 | { |
293 | { |
356 | treasurelist *tl; |
|
|
357 | archetype *at; |
|
|
358 | |
|
|
359 | if (depth > 10) |
294 | if (depth > 10) |
360 | return 0; |
295 | return 0; |
361 | |
296 | |
362 | while (t) |
297 | while (t) |
363 | { |
298 | { |
364 | if (t->name) |
299 | if (t->name) |
365 | { |
300 | { |
366 | tl = find_treasurelist (t->name); |
301 | if (treasurelist *tl = treasurelist::find (t->name)) |
367 | |
|
|
368 | if (tl) |
302 | if (tl->items) |
369 | { |
|
|
370 | at = find_treasure_by_name (tl->items, name, depth + 1); |
303 | if (archetype *at = find_treasure_by_name (tl->items, name, depth + 1)) |
371 | |
|
|
372 | if (at) |
|
|
373 | return at; |
304 | return at; |
374 | } |
|
|
375 | } |
305 | } |
376 | else |
306 | else |
377 | { |
307 | { |
378 | if (!strcasecmp (t->item->clone.name, name)) |
308 | if (t->item && !strcasecmp (t->item->object::name, name)) |
379 | return t->item; |
309 | return t->item; |
380 | } |
310 | } |
381 | |
311 | |
382 | if (t->next_yes) |
312 | if (t->next_yes) |
383 | { |
|
|
384 | at = find_treasure_by_name (t->next_yes, name, depth); |
313 | if (archetype *at = find_treasure_by_name (t->next_yes, name, depth)) |
385 | if (at) |
|
|
386 | return at; |
314 | return at; |
387 | } |
|
|
388 | |
315 | |
389 | if (t->next_no) |
316 | if (t->next_no) |
390 | { |
|
|
391 | at = find_treasure_by_name (t->next_no, name, depth); |
317 | if (archetype *at = find_treasure_by_name (t->next_no, name, depth)) |
392 | if (at) |
|
|
393 | return at; |
318 | return at; |
394 | } |
319 | |
395 | t = t->next; |
320 | t = t->next; |
396 | } |
321 | } |
|
|
322 | |
397 | return 0; |
323 | return 0; |
398 | } |
324 | } |
399 | |
325 | |
400 | /* 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 |
401 | * one with that name will be returned. This happens for the |
327 | * one with that name will be returned. This happens for the |
… | |
… | |
406 | * 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 |
407 | * big_dragon_worthless). */ |
333 | * big_dragon_worthless). */ |
408 | long |
334 | long |
409 | find_ingred_cost (const char *name) |
335 | find_ingred_cost (const char *name) |
410 | { |
336 | { |
411 | archetype *at; |
|
|
412 | archetype *at2; |
337 | archetype *at2; |
413 | artifactlist *al; |
338 | artifactlist *al; |
414 | artifact *art; |
339 | artifact *art; |
415 | long mult; |
340 | long mult; |
416 | char *cp; |
341 | char *cp; |
… | |
… | |
422 | while (isdigit (*name)) |
347 | while (isdigit (*name)) |
423 | { |
348 | { |
424 | mult = 10 * mult + (*name - '0'); |
349 | mult = 10 * mult + (*name - '0'); |
425 | name++; |
350 | name++; |
426 | } |
351 | } |
|
|
352 | |
427 | if (mult > 0) |
353 | if (mult > 0) |
428 | name++; |
354 | name++; |
429 | else |
355 | else |
430 | mult = 1; |
356 | mult = 1; |
|
|
357 | |
431 | /* first, try to match the name of an archetype */ |
358 | /* first, try to match the name of an archetype */ |
432 | for (at = first_archetype; at != NULL; at = at->next) |
359 | for_all_archetypes (at) |
433 | { |
360 | { |
434 | if (at->clone.title != NULL) |
361 | if (at->title != NULL) |
435 | { |
362 | { |
436 | /* inefficient, but who cares? */ |
363 | /* inefficient, but who cares? */ |
437 | sprintf (part1, "%s %s", &at->clone.name, &at->clone.title); |
364 | sprintf (part1, "%s %s", &at->object::name, &at->title); |
438 | if (!strcasecmp (part1, name)) |
365 | if (!strcasecmp (part1, name)) |
439 | return mult * at->clone.value; |
366 | return mult * at->value; |
440 | } |
367 | } |
441 | if (!strcasecmp (at->clone.name, name)) |
368 | if (!strcasecmp (at->object::name, name)) |
442 | return mult * at->clone.value; |
369 | return mult * at->value; |
443 | } |
370 | } |
|
|
371 | |
444 | /* second, try to match an artifact ("arch of something") */ |
372 | /* second, try to match an artifact ("arch of something") */ |
445 | cp = strstr (name, " of "); |
373 | cp = strstr (name, " of "); |
446 | if (cp != NULL) |
374 | if (cp != NULL) |
447 | { |
375 | { |
448 | strcpy (part1, name); |
376 | strcpy (part1, name); |
449 | part1[cp - name] = '\0'; |
377 | part1[cp - name] = '\0'; |
450 | strcpy (part2, cp + 4); |
378 | strcpy (part2, cp + 4); |
|
|
379 | |
451 | /* find the first archetype matching the first part of the name */ |
380 | /* find the first archetype matching the first part of the name */ |
452 | for (at = first_archetype; at != NULL; at = at->next) |
381 | for_all_archetypes (at) |
453 | if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL) |
382 | if (at->object::name.eq_nc (part1) && !at->title) |
454 | break; |
|
|
455 | if (at != NULL) |
|
|
456 | { |
383 | { |
457 | /* find the first artifact derived from that archetype (same type) */ |
384 | /* find the first artifact derived from that archetype (same type) */ |
458 | for (al = first_artifactlist; al != NULL; al = al->next) |
385 | for (al = first_artifactlist; al; al = al->next) |
459 | if (al->type == at->clone.type) |
386 | if (al->type == at->type) |
460 | { |
387 | { |
461 | for (art = al->items; art != NULL; art = art->next) |
388 | for (art = al->items; art; art = art->next) |
462 | if (!strcasecmp (art->item->name, part2)) |
389 | if (!strcasecmp (art->item->name, part2)) |
463 | return mult * at->clone.value * art->item->value; |
390 | return mult * at->value * art->item->value; |
464 | } |
391 | } |
465 | } |
392 | } |
466 | } |
393 | } |
|
|
394 | |
467 | /* third, try to match a body part ("arch's something") */ |
395 | /* third, try to match a body part ("arch's something") */ |
468 | cp = strstr (name, "'s "); |
396 | cp = strstr (name, "'s "); |
469 | if (cp != NULL) |
397 | if (cp) |
470 | { |
398 | { |
471 | strcpy (part1, name); |
399 | strcpy (part1, name); |
472 | part1[cp - name] = '\0'; |
400 | part1[cp - name] = '\0'; |
473 | strcpy (part2, cp + 3); |
401 | strcpy (part2, cp + 3); |
474 | /* examine all archetypes matching the first part of the name */ |
402 | /* examine all archetypes matching the first part of the name */ |
475 | for (at = first_archetype; at != NULL; at = at->next) |
403 | for_all_archetypes (at) |
476 | if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL) |
404 | if (at->object::name.eq_nc (part1) && !at->title) |
477 | { |
405 | { |
478 | if (at->clone.randomitems != NULL) |
406 | if (at->randomitems) |
479 | { |
407 | { |
480 | at2 = find_treasure_by_name (at->clone.randomitems->items, part2, 0); |
408 | at2 = find_treasure_by_name (at->randomitems->items, part2, 0); |
481 | if (at2) |
409 | if (at2) |
482 | return mult * at2->clone.value * isqrt (at->clone.level * 2); |
410 | return mult * at2->value * isqrt (at->level * 2); |
483 | } |
411 | } |
484 | } |
412 | } |
485 | } |
413 | } |
|
|
414 | |
486 | /* failed to find any matching items -- formula should be checked */ |
415 | /* failed to find any matching items -- formula should be checked */ |
487 | return -1; |
416 | return -1; |
488 | } |
417 | } |
489 | |
418 | |
490 | /* code copied from dump_alchemy() and modified by Raphael Quinet */ |
|
|
491 | void |
|
|
492 | dump_alchemy_costs (void) |
|
|
493 | { |
|
|
494 | recipelist *fl = formulalist; |
|
|
495 | recipe *formula = NULL; |
|
|
496 | linked_char *next; |
|
|
497 | int num_ingred = 1; |
|
|
498 | int num_errors = 0; |
|
|
499 | long cost; |
|
|
500 | long tcost; |
|
|
501 | |
|
|
502 | fprintf (logfile, "\n"); |
|
|
503 | while (fl) |
|
|
504 | { |
|
|
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); |
|
|
507 | for (formula = fl->items; formula != NULL; formula = formula->next) |
|
|
508 | { |
|
|
509 | artifact *art = NULL; |
|
|
510 | archetype *at = NULL; |
|
|
511 | char buf[MAX_BUF]; |
|
|
512 | size_t i; |
|
|
513 | |
|
|
514 | for (i = 0; i < formula->arch_names; i++) |
|
|
515 | { |
|
|
516 | const char *string = formula->arch_name[i]; |
|
|
517 | |
|
|
518 | if ((at = archetype::find (string)) != NULL) |
|
|
519 | { |
|
|
520 | art = locate_recipe_artifact (formula, i); |
|
|
521 | if (!art && strcmp (formula->title, "NONE")) |
|
|
522 | LOG (llevError, "Formula %s has no artifact\n", &formula->title); |
|
|
523 | else |
|
|
524 | { |
|
|
525 | if (!strcmp (formula->title, "NONE")) |
|
|
526 | sprintf (buf, "%s", string); |
|
|
527 | else |
|
|
528 | sprintf (buf, "%s of %s", string, &formula->title); |
|
|
529 | fprintf (logfile, "\n%-40s bookchance %3d skill %s\n", buf, formula->chance, &(formula->skill)); |
|
|
530 | if (formula->ingred != NULL) |
|
|
531 | { |
|
|
532 | tcost = 0; |
|
|
533 | for (next = formula->ingred; next != NULL; next = next->next) |
|
|
534 | { |
|
|
535 | cost = find_ingred_cost (next->name); |
|
|
536 | if (cost < 0) |
|
|
537 | num_errors++; |
|
|
538 | fprintf (logfile, "\t%-33s%5ld\n", &next->name, cost); |
|
|
539 | if (cost < 0 || tcost < 0) |
|
|
540 | tcost = -1; |
|
|
541 | else |
|
|
542 | tcost += cost; |
|
|
543 | } |
|
|
544 | if (art != NULL && art->item != NULL) |
|
|
545 | cost = at->clone.value * art->item->value; |
|
|
546 | else |
|
|
547 | cost = at->clone.value; |
|
|
548 | fprintf (logfile, "\t\tBuying result costs: %5ld", cost); |
|
|
549 | if (formula->yield > 1) |
|
|
550 | { |
|
|
551 | fprintf (logfile, " to %ld (max %d items)\n", cost * formula->yield, formula->yield); |
|
|
552 | cost = cost * (formula->yield + 1L) / 2L; |
|
|
553 | } |
|
|
554 | else |
|
|
555 | fprintf (logfile, "\n"); |
|
|
556 | fprintf (logfile, "\t\tIngredients cost: %5ld\n\t\tComment: ", tcost); |
|
|
557 | if (tcost < 0) |
|
|
558 | fprintf (logfile, "Could not find some ingredients. Check the formula!\n"); |
|
|
559 | else if (tcost > cost) |
|
|
560 | fprintf (logfile, "Ingredients are much too expensive. Useless formula.\n"); |
|
|
561 | else if (tcost * 2L > cost) |
|
|
562 | fprintf (logfile, "Ingredients are too expensive.\n"); |
|
|
563 | else if (tcost * 10L < cost) |
|
|
564 | fprintf (logfile, "Ingredients are too cheap.\n"); |
|
|
565 | else |
|
|
566 | fprintf (logfile, "OK.\n"); |
|
|
567 | } |
|
|
568 | } |
|
|
569 | } |
|
|
570 | else |
|
|
571 | LOG (llevError, "Can't find archetype:%s for formula %s\n", string, &formula->title); |
|
|
572 | } |
|
|
573 | } |
|
|
574 | fprintf (logfile, "\n"); |
|
|
575 | fl = fl->next; |
|
|
576 | num_ingred++; |
|
|
577 | } |
|
|
578 | if (num_errors > 0) |
|
|
579 | fprintf (logfile, "WARNING: %d objects required by the formulae do not exist in the game.\n", num_errors); |
|
|
580 | } |
|
|
581 | |
|
|
582 | const char * |
419 | const char * |
583 | ingred_name (const char *name) |
420 | ingred_name (const char *name) |
584 | { |
421 | { |
585 | const char *cp = name; |
422 | const char *cp = name; |
586 | |
423 | |
587 | if (atoi (cp)) |
424 | if (atoi (cp)) |
588 | cp = strchr (cp, ' ') + 1; |
425 | cp = strchr (cp, ' ') + 1; |
|
|
426 | |
589 | return cp; |
427 | return cp; |
590 | } |
|
|
591 | |
|
|
592 | /* strtoint() - we use this to convert buf into an integer |
|
|
593 | * equal to the coadded sum of the (lowercase) character |
|
|
594 | * ASCII values in buf (times prepended integers). |
|
|
595 | */ |
|
|
596 | |
|
|
597 | int |
|
|
598 | strtoint (const char *buf) |
|
|
599 | { |
|
|
600 | const char *cp = ingred_name (buf); |
|
|
601 | int val = 0, len = strlen (cp), mult = numb_ingred (buf); |
|
|
602 | |
|
|
603 | while (len) |
|
|
604 | { |
|
|
605 | val += tolower (*cp); |
|
|
606 | cp++; |
|
|
607 | len--; |
|
|
608 | } |
|
|
609 | return val * mult; |
|
|
610 | } |
|
|
611 | |
|
|
612 | artifact * |
|
|
613 | locate_recipe_artifact (const recipe *rp, size_t idx) |
|
|
614 | { |
|
|
615 | object *item = get_archetype (rp->arch_name[idx]); |
|
|
616 | artifactlist *at = NULL; |
|
|
617 | artifact *art = NULL; |
|
|
618 | |
|
|
619 | if (!item) |
|
|
620 | return (artifact *) NULL; |
|
|
621 | |
|
|
622 | if ((at = find_artifactlist (item->type))) |
|
|
623 | for (art = at->items; art; art = art->next) |
|
|
624 | if (!strcmp (art->item->name, rp->title)) |
|
|
625 | break; |
|
|
626 | |
|
|
627 | item->destroy (); |
|
|
628 | |
|
|
629 | return art; |
|
|
630 | } |
428 | } |
631 | |
429 | |
632 | int |
430 | int |
633 | numb_ingred (const char *buf) |
431 | numb_ingred (const char *buf) |
634 | { |
432 | { |
… | |
… | |
638 | return numb; |
436 | return numb; |
639 | else |
437 | else |
640 | return 1; |
438 | return 1; |
641 | } |
439 | } |
642 | |
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; |
|
|
474 | } |
|
|
475 | |
643 | recipelist * |
476 | recipelist * |
644 | get_random_recipelist (void) |
477 | get_random_recipelist (void) |
645 | { |
478 | { |
646 | recipelist *fl = NULL; |
479 | recipelist *fl = NULL; |
647 | int number = 0, roll = 0; |
480 | int number = 0, roll = 0; |
… | |
… | |
650 | for (fl = get_formulalist (1); fl; fl = fl->next) |
483 | for (fl = get_formulalist (1); fl; fl = fl->next) |
651 | number++; |
484 | number++; |
652 | |
485 | |
653 | /* now, randomly choose one */ |
486 | /* now, randomly choose one */ |
654 | if (number > 0) |
487 | if (number > 0) |
655 | roll = RANDOM () % number; |
488 | roll = rndm (number); |
656 | |
489 | |
657 | fl = get_formulalist (1); |
490 | fl = get_formulalist (1); |
658 | while (roll && fl) |
491 | while (roll && fl) |
659 | { |
492 | { |
660 | if (fl->next) |
493 | if (fl->next) |
… | |
… | |
683 | if ((fl = get_random_recipelist ()) == NULL) |
516 | if ((fl = get_random_recipelist ()) == NULL) |
684 | return rp; |
517 | return rp; |
685 | |
518 | |
686 | if (fl->total_chance > 0) |
519 | if (fl->total_chance > 0) |
687 | { |
520 | { |
688 | r = RANDOM () % fl->total_chance; |
521 | r = rndm (fl->total_chance); |
689 | for (rp = fl->items; rp; rp = rp->next) |
522 | for (rp = fl->items; rp; rp = rp->next) |
690 | { |
523 | { |
691 | r -= rp->chance; |
524 | r -= rp->chance; |
692 | if (r < 0) |
525 | if (r < 0) |
693 | break; |
526 | break; |