1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | |
3 | * |
|
|
4 | * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | |
7 | * |
7 | This program is free software; you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | it under the terms of the GNU General Public License as published by |
9 | * the terms of the Affero GNU General Public License as published by the |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | (at your option) any later version. |
11 | * option) any later version. |
11 | |
12 | * |
12 | This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
16 | |
17 | * |
17 | You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
18 | along with this program; if not, write to the Free Software |
19 | * and the GNU General Public License along with this program. If not, see |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * <http://www.gnu.org/licenses/>. |
20 | |
21 | * |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | /* March 96 - Laid down original code. -b.t. thomas@astro.psu.edu */ |
25 | /* March 96 - Laid down original code. -b.t. thomas@astro.psu.edu */ |
25 | |
26 | |
26 | #include <global.h> |
27 | #include <global.h> |
27 | #include <object.h> |
28 | #include <object.h> |
… | |
… | |
55 | "rattles", |
56 | "rattles", |
56 | "makes chugging sounds", |
57 | "makes chugging sounds", |
57 | "smokes heavily for a while" |
58 | "smokes heavily for a while" |
58 | }; |
59 | }; |
59 | |
60 | |
60 | |
|
|
61 | static int is_defined_recipe (const recipe *rp, const object *cauldron, object *caster); |
61 | static int is_defined_recipe (const recipe *rp, const object *cauldron, object *caster); |
62 | static recipe *find_recipe (recipelist * fl, int formula, object *ingredients); |
62 | static recipe *find_recipe (recipelist * fl, int formula, object *ingredients); |
63 | |
|
|
64 | |
63 | |
65 | /** Returns a random selection from cauldron_effect[] */ |
64 | /** Returns a random selection from cauldron_effect[] */ |
66 | static const char * |
65 | static const char * |
67 | cauldron_sound (void) |
66 | cauldron_sound (void) |
68 | { |
67 | { |
69 | int size = sizeof (cauldron_effect) / sizeof (char *); |
68 | int size = sizeof (cauldron_effect) / sizeof (char *); |
70 | |
69 | |
71 | return cauldron_effect[rndm (0, size - 1)]; |
70 | return cauldron_effect[rndm (0, size - 1)]; |
72 | } |
71 | } |
73 | |
72 | |
74 | /**
|
73 | /** |
75 | * Main part of the ALCHEMY code. From this we call fctns |
74 | * Main part of the ALCHEMY code. From this we call fctns |
76 | * that take a look at the contents of the 'cauldron' and, using these ingredients, |
75 | * that take a look at the contents of the 'cauldron' and, using these ingredients, |
77 | * we construct an integer formula value which is referenced (randomly) against a |
76 | * we construct an integer formula value which is referenced (randomly) against a |
78 | * formula list (the formula list chosen is based on the # contents of the cauldron). |
77 | * formula list (the formula list chosen is based on the # contents of the cauldron). |
79 | * |
78 | * |
… | |
… | |
94 | * around. :) |
93 | * around. :) |
95 | * -b.t. |
94 | * -b.t. |
96 | */ |
95 | */ |
97 | |
96 | |
98 | void |
97 | void |
99 | attempt_do_alchemy (object *caster, object *cauldron) |
98 | attempt_do_alchemy (object *caster, object *cauldron, object *skill) |
100 | { |
99 | { |
101 | recipelist *fl; |
100 | recipelist *fl; |
102 | recipe *rp = NULL; |
101 | recipe *rp = NULL; |
103 | float success_chance; |
102 | float success_chance; |
104 | int numb, ability = 1; |
103 | int numb, ability = 1; |
… | |
… | |
127 | rp = find_recipe (fl, formula, cauldron->inv); |
126 | rp = find_recipe (fl, formula, cauldron->inv); |
128 | if (rp != NULL) |
127 | if (rp != NULL) |
129 | { |
128 | { |
130 | #ifdef ALCHEMY_DEBUG |
129 | #ifdef ALCHEMY_DEBUG |
131 | if (strcmp (rp->title, "NONE")) |
130 | if (strcmp (rp->title, "NONE")) |
132 | LOG (llevDebug, "WIZ got formula: %s of %s\n", rp->arch_name[0], rp->title); |
131 | LOG (llevDebug, "WIZ got formula: %s of %s\n", rp->arch_name[0], &rp->title); |
133 | else |
132 | else |
134 | LOG (llevDebug, "WIZ got formula: %s (nbatches:%d)\n", rp->arch_name[0], formula / rp->index); |
133 | LOG (llevDebug, "WIZ got formula: %s (nbatches:%d)\n", rp->arch_name[0], formula / rp->index); |
135 | #endif |
134 | #endif |
136 | attempt_recipe (caster, cauldron, ability, rp, formula / rp->index); |
135 | attempt_recipe (caster, cauldron, ability, rp, formula / rp->index); |
137 | } |
136 | } |
… | |
… | |
140 | return; |
139 | return; |
141 | } /* End of WIZ alchemy */ |
140 | } /* End of WIZ alchemy */ |
142 | |
141 | |
143 | /* find the recipe */ |
142 | /* find the recipe */ |
144 | rp = find_recipe (fl, formula, cauldron->inv); |
143 | rp = find_recipe (fl, formula, cauldron->inv); |
145 | if (rp) |
144 | if (rp |
|
|
145 | && rp->skill == skill->skill |
|
|
146 | && (!rp->cauldron |
|
|
147 | || rp->cauldron == cauldron->arch->archname)) |
146 | { |
148 | { |
147 | uint64 value_ingredients; |
149 | uint64 value_ingredients; |
148 | uint64 value_item; |
150 | uint64 value_item; |
149 | object *tmp; |
151 | object *tmp; |
150 | int attempt_shadow_alchemy; |
152 | int attempt_shadow_alchemy; |
151 | |
153 | |
152 | ave_chance = fl->total_chance / (float) fl->number; |
154 | ave_chance = fl->total_chance / (float) fl->number; |
153 | /* the caster gets an increase in ability based on thier skill lvl */ |
155 | |
154 | if (rp->skill) |
|
|
155 | { |
|
|
156 | skop = find_skill_by_name (caster, rp->skill); |
|
|
157 | if (!skop) |
|
|
158 | new_draw_info (NDI_UNIQUE, 0, caster, "You do not have the proper skill for this recipe"); |
|
|
159 | else |
|
|
160 | ability += (int) (skop->level * ((4.0 + cauldron->magic) / 4.0)); |
156 | ability += (int) (skill->level * ((4.0 + cauldron->magic) / 4.0)); |
161 | } |
|
|
162 | else |
|
|
163 | { |
|
|
164 | LOG (llevDebug, "Recipe %s has NULL skill!\n", &rp->title); |
|
|
165 | return; |
|
|
166 | } |
|
|
167 | |
|
|
168 | if (!rp->cauldron) |
|
|
169 | { |
|
|
170 | LOG (llevDebug, "Recipe %s has NULL cauldron!\n", &rp->title); |
|
|
171 | return; |
|
|
172 | } |
|
|
173 | |
157 | |
174 | /* determine value of ingredients */ |
158 | /* determine value of ingredients */ |
175 | value_ingredients = 0; |
159 | value_ingredients = 0; |
176 | for (tmp = cauldron->inv; tmp != NULL; tmp = tmp->below) |
160 | for (tmp = cauldron->inv; tmp != NULL; tmp = tmp->below) |
177 | value_ingredients += query_cost (tmp, NULL, F_TRUE); |
161 | value_ingredients += query_cost (tmp, NULL, F_TRUE); |
… | |
… | |
215 | |
199 | |
216 | /* if we get here, we failed!! */ |
200 | /* if we get here, we failed!! */ |
217 | alchemy_failure_effect (caster, cauldron, rp, calc_alch_danger (caster, cauldron, rp)); |
201 | alchemy_failure_effect (caster, cauldron, rp, calc_alch_danger (caster, cauldron, rp)); |
218 | } |
202 | } |
219 | |
203 | |
220 | /**
|
204 | /** |
221 | * Recipe value of the entire contents of a container. |
205 | * Recipe value of the entire contents of a container. |
222 | * This appears to just generate a hash value, which I guess for now works |
206 | * This appears to just generate a hash value, which I guess for now works |
223 | * ok, but the possibility of duplicate hashes is certainly possible - msw |
207 | * ok, but the possibility of duplicate hashes is certainly possible - msw |
224 | */ |
208 | */ |
225 | |
|
|
226 | int |
209 | int |
227 | content_recipe_value (object *op) |
210 | content_recipe_value (object *op) |
228 | { |
211 | { |
229 | char name[MAX_BUF]; |
212 | char name[MAX_BUF]; |
230 | object *tmp = op->inv; |
213 | object *tmp = op->inv; |
231 | int tval = 0, formula = 0; |
214 | int tval = 0, formula = 0; |
232 | |
215 | |
233 | while (tmp) |
216 | while (tmp) |
234 | { |
217 | { |
235 | tval = 0; |
218 | tval = 0; |
236 | strcpy (name, tmp->name); |
219 | assign (name, tmp->name); |
237 | if (tmp->title) |
220 | if (tmp->title) |
238 | sprintf (name, "%s %s", &tmp->name, &tmp->title); |
221 | sprintf (name, "%s %s", &tmp->name, &tmp->title); |
239 | tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1)); |
222 | tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1)); |
240 | #ifdef ALCHEMY_DEBUG |
223 | #ifdef ALCHEMY_DEBUG |
241 | LOG (llevDebug, "Got ingredient %d %s(%d)\n", tmp->nrof ? tmp->nrof : 1, name, tval); |
224 | LOG (llevDebug, "Got ingredient %d %s(%d)\n", tmp->nrof ? tmp->nrof : 1, name, tval); |
… | |
… | |
247 | LOG (llevDebug, " Formula value=%d\n", formula); |
230 | LOG (llevDebug, " Formula value=%d\n", formula); |
248 | #endif |
231 | #endif |
249 | return formula; |
232 | return formula; |
250 | } |
233 | } |
251 | |
234 | |
252 | /**
|
235 | /** |
253 | * Returns total number of items in op
|
236 | * Returns total number of items in op |
254 | */ |
237 | */ |
255 | |
238 | |
256 | int |
239 | int |
257 | numb_ob_inside (object *op) |
240 | numb_ob_inside (object *op) |
258 | { |
241 | { |
… | |
… | |
267 | number++; |
250 | number++; |
268 | o_number++; |
251 | o_number++; |
269 | tmp = tmp->below; |
252 | tmp = tmp->below; |
270 | } |
253 | } |
271 | #ifdef ALCHEMY_DEBUG |
254 | #ifdef ALCHEMY_DEBUG |
272 | LOG (llevDebug, "numb_ob_inside(%s): found %d ingredients\n", op->name, o_number); |
255 | LOG (llevDebug, "numb_ob_inside(%s): found %d ingredients\n", &op->name, o_number); |
273 | #endif |
256 | #endif |
274 | return o_number; |
257 | return o_number; |
275 | } |
258 | } |
276 | |
259 | |
277 | /** |
260 | /** |
… | |
… | |
279 | * insert_ob_in_ob. If the caster has some alchemy skill, then they might |
262 | * insert_ob_in_ob. If the caster has some alchemy skill, then they might |
280 | * gain some exp from (successfull) fabrication of the product. |
263 | * gain some exp from (successfull) fabrication of the product. |
281 | * If nbatches==-1, don't give exp for this creation (random generation/ |
264 | * If nbatches==-1, don't give exp for this creation (random generation/ |
282 | * failed recipe) |
265 | * failed recipe) |
283 | */ |
266 | */ |
284 | |
|
|
285 | object * |
267 | object * |
286 | attempt_recipe (object *caster, object *cauldron, int ability, recipe *rp, int nbatches) |
268 | attempt_recipe (object *caster, object *cauldron, int ability, recipe *rp, int nbatches) |
287 | { |
269 | { |
288 | |
270 | |
289 | object *item = NULL, *skop; |
271 | object *item = NULL, *skop; |
290 | |
272 | |
291 | /* this should be passed to this fctn, not effiecent cpu use this way */ |
273 | /* this should be passed to this fctn, not effiecent cpu use this way */ |
292 | int batches = abs (nbatches); |
274 | int batches = abs (nbatches); |
293 | |
275 | |
294 | |
|
|
295 | LOG (llevDebug, "A %s <=> %s\n", &(rp->cauldron), &(cauldron->arch->name)); |
|
|
296 | /* is the cauldron the right type? */ |
276 | /* is the cauldron the right type? */ |
297 | if (strcmp (rp->cauldron, cauldron->arch->name) != 0) |
277 | if (rp->cauldron && rp->cauldron != cauldron->arch->archname) |
298 | { |
|
|
299 | new_draw_info (NDI_UNIQUE, 0, caster, "You are not using the proper" " facilities for this formula."); |
|
|
300 | return 0; |
278 | return 0; |
301 | } |
|
|
302 | |
279 | |
303 | skop = find_skill_by_name (caster, rp->skill); |
280 | skop = find_skill_by_name (caster, rp->skill); |
304 | /* does the caster have the skill? */ |
281 | /* does the caster have the skill? */ |
305 | if (!skop) |
282 | if (!skop) |
306 | return 0; |
283 | return 0; |
… | |
… | |
308 | /* code required for this recipe, search the caster */ |
285 | /* code required for this recipe, search the caster */ |
309 | if (rp->keycode) |
286 | if (rp->keycode) |
310 | { |
287 | { |
311 | object *tmp; |
288 | object *tmp; |
312 | |
289 | |
313 | for (tmp = caster->inv; tmp != NULL; tmp = tmp->below) |
290 | for (tmp = caster->inv; tmp; tmp = tmp->below) |
314 | { |
291 | { |
315 | if (tmp->type == FORCE && tmp->slaying && !strcmp (rp->keycode, tmp->slaying)) |
292 | if (tmp->type == FORCE && tmp->slaying && rp->keycode == tmp->slaying) |
316 | break; |
293 | break; |
317 | } |
294 | } |
|
|
295 | |
318 | if (tmp == NULL) |
296 | if (!tmp) |
319 | { /* failure--no code found */ |
297 | { /* failure--no code found */ |
320 | new_draw_info (NDI_UNIQUE, 0, caster, "You know the ingredients," " but not the technique. Go learn how to do this recipe."); |
298 | new_draw_info (NDI_UNIQUE, 0, caster, "You know the ingredients, but not the technique. Go learn how to do this recipe."); |
321 | return 0; |
299 | return 0; |
322 | } |
300 | } |
323 | } |
301 | } |
324 | |
302 | |
325 | #ifdef EXTREME_ALCHEMY_DEBUG |
303 | #ifdef EXTREME_ALCHEMY_DEBUG |
326 | LOG (llevDebug, "attempt_recipe(): got %d nbatches\n", nbatches); |
304 | LOG (llevDebug, "attempt_recipe(): got %d nbatches\n", nbatches); |
327 | LOG (llevDebug, "attempt_recipe(): using recipe %s\n", rp->title ? rp->title : "unknown"); |
305 | LOG (llevDebug, "attempt_recipe(): using recipe %s\n", *rp->title ? &rp->title : "unknown"); |
328 | #endif |
306 | #endif |
329 | |
307 | |
330 | if ((item = make_item_from_recipe (cauldron, rp)) != NULL) |
308 | if ((item = make_item_from_recipe (cauldron, rp)) != NULL) |
331 | { |
309 | { |
332 | remove_contents (cauldron->inv, item); |
310 | remove_contents (cauldron->inv, item); |
333 | /* Recalc carrying of the cauldron, in case recipe did not conserve mass */ |
311 | /* Recalc carrying of the cauldron, in case recipe did not conserve mass */ |
334 | sum_weight (cauldron); |
312 | cauldron->update_weight (); |
335 | /* adj lvl, nrof on caster level */ |
313 | /* adj lvl, nrof on caster level */ |
336 | adjust_product (item, ability, rp->yield ? (rp->yield * batches) : batches); |
314 | adjust_product (item, ability, rp->yield ? (rp->yield * batches) : batches); |
337 | if (!item->env && (item = insert_ob_in_ob (item, cauldron)) == NULL) |
315 | if (!item->env && (item = insert_ob_in_ob (item, cauldron)) == NULL) |
338 | { |
316 | { |
339 | new_draw_info (NDI_UNIQUE, 0, caster, "Nothing happened."); |
317 | new_draw_info (NDI_UNIQUE, 0, caster, "Nothing happened."); |
340 | /* new_draw_info_format(NDI_UNIQUE, 0,caster, |
318 | /* new_draw_info_format(NDI_UNIQUE, 0,caster, |
341 | "Your spell causes the %s to explode!",&cauldron->name); */ |
319 | "Your spell causes the %s to explode!",&cauldron->name); */ |
342 | /* kaboom_cauldron(); */ |
320 | /* kaboom_cauldron(); */ |
343 | } |
321 | } |
344 | else |
322 | else |
345 | { |
|
|
346 | new_draw_info_format (NDI_UNIQUE, 0, caster, "The %s %s.", &cauldron->name, cauldron_sound ()); |
323 | new_draw_info_format (NDI_UNIQUE, 0, caster, "The %s %s.", &cauldron->name, cauldron_sound ()); |
347 | } |
|
|
348 | } |
324 | } |
|
|
325 | |
349 | return item; |
326 | return item; |
350 | } |
327 | } |
351 | |
328 | |
352 | |
|
|
353 | |
|
|
354 | /**
|
329 | /** |
355 | * We adjust the nrof, exp and level of the final product, based |
330 | * We adjust the nrof, exp and level of the final product, based |
356 | * on the item's default parameters, and the relevant caster skill level.
|
331 | * on the item's default parameters, and the relevant caster skill level. |
357 | */ |
332 | */ |
358 |
void |
333 | void |
359 | adjust_product (object *item, int lvl, int yield) |
334 | adjust_product (object *item, int lvl, int yield) |
360 | { |
335 | { |
361 | int nrof = 1; |
336 | int nrof = 1; |
362 | |
337 | |
363 | if (!yield) |
338 | if (!yield) |
364 | yield = 1; |
339 | yield = 1; |
|
|
340 | |
365 | if (lvl <= 0) |
341 | if (lvl <= 0) |
366 | lvl = 1; /* lets avoid div by zero! */ |
342 | lvl = 1; /* lets avoid div by zero! */ |
|
|
343 | |
367 | if (item->nrof) |
344 | if (item->nrof) |
368 | { |
345 | { |
369 | nrof = (int) ((1.0 - 1.0 / (lvl / 10.0 + 1.0)) * (rndm (0, yield - 1) + rndm (0, yield - 1) + rndm (0, yield - 1)) + 1); |
346 | nrof = (int) ((1.0 - 1.0 / (lvl / 10.0 + 1.0)) * (rndm (0, yield - 1) + rndm (0, yield - 1) + rndm (0, yield - 1)) + 1); |
|
|
347 | |
370 | if (nrof > yield) |
348 | if (nrof > yield) |
371 | nrof = yield; |
349 | nrof = yield; |
|
|
350 | |
372 | item->nrof = nrof; |
351 | item->nrof = nrof; |
373 | } |
352 | } |
374 | } |
353 | } |
375 | |
|
|
376 | |
354 | |
377 | /** |
355 | /** |
378 | * Using a list of items and a recipe to make an artifact. |
356 | * Using a list of items and a recipe to make an artifact. |
379 | * |
357 | * |
380 | * @param cauldron the cauldron (including the ingredients) used to make the item |
358 | * @param cauldron the cauldron (including the ingredients) used to make the item |
381 | * |
359 | * |
382 | * @param rp the recipe to make the artifact from |
360 | * @param rp the recipe to make the artifact from |
383 | * |
361 | * |
384 | * @return the newly created object, NULL if something failed |
362 | * @return the newly created object, NULL if something failed |
385 | */ |
363 | */ |
386 | |
|
|
387 | object * |
364 | object * |
388 | make_item_from_recipe (object *cauldron, recipe *rp) |
365 | make_item_from_recipe (object *cauldron, recipe *rp) |
389 | { |
366 | { |
390 | artifact *art = NULL; |
367 | artifact *art = NULL; |
391 | object *item = NULL; |
368 | object *item = NULL; |
… | |
… | |
400 | LOG (llevDebug, "make_alchemy_item(): failed to create alchemical object.\n"); |
377 | LOG (llevDebug, "make_alchemy_item(): failed to create alchemical object.\n"); |
401 | return (object *) NULL; |
378 | return (object *) NULL; |
402 | } |
379 | } |
403 | |
380 | |
404 | /* Find the appropriate artifact template... */ |
381 | /* Find the appropriate artifact template... */ |
405 | if (strcmp (rp->title, "NONE")) |
382 | if (rp->title != shstr_NONE) |
406 | { |
383 | { |
407 | if ((art = locate_recipe_artifact (rp, rp_arch_index)) == NULL) |
384 | if ((art = locate_recipe_artifact (rp, rp_arch_index)) == NULL) |
408 | { |
385 | { |
409 | LOG (llevError, "make_alchemy_item(): failed to locate recipe artifact.\n"); |
386 | LOG (llevError, "make_alchemy_item(): failed to locate recipe artifact.\n"); |
410 | LOG (llevDebug, " --requested recipe: %s of %s.\n", rp->arch_name[0], &rp->title); |
387 | LOG (llevDebug, " --requested recipe: %s of %s.\n", rp->arch_name[0], &rp->title); |
411 | return (object *) NULL; |
388 | return (object *) NULL; |
412 | } |
389 | } |
|
|
390 | |
413 | transmute_materialname (item, art->item); |
391 | transmute_materialname (item, art->item); |
414 | give_artifact_abilities (item, art->item); |
392 | give_artifact_abilities (item, art->item); |
415 | } |
393 | } |
416 | |
394 | |
417 | if (QUERY_FLAG (cauldron, FLAG_CURSED)) |
395 | if (QUERY_FLAG (cauldron, FLAG_CURSED)) |
… | |
… | |
420 | SET_FLAG (item, FLAG_DAMNED); |
398 | SET_FLAG (item, FLAG_DAMNED); |
421 | |
399 | |
422 | return item; |
400 | return item; |
423 | } |
401 | } |
424 | |
402 | |
425 | |
|
|
426 | /**
|
403 | /** |
427 | * Looks through the ingredient list. If we find a |
404 | * Looks through the ingredient list. If we find a |
428 | * suitable object in it - we will use that to make the requested artifact. |
405 | * suitable object in it - we will use that to make the requested artifact. |
429 | * Otherwise the code returns a 'generic' item if create_item is set. -b.t. |
406 | * Otherwise the code returns a 'generic' item if create_item is set. -b.t. |
430 | * |
407 | * |
431 | * @param rp_arch_index pointer to return value; set to arch index for recipe; |
408 | * @param rp_arch_index pointer to return value; set to arch index for recipe; |
432 | * set to zero if not using a transmution formula |
409 | * set to zero if not using a transmution formula |
433 | */ |
410 | */ |
434 | |
|
|
435 | object * |
411 | object * |
436 | find_transmution_ob (object *first_ingred, recipe *rp, size_t * rp_arch_index, int create_item) |
412 | find_transmution_ob (object *first_ingred, recipe *rp, size_t *rp_arch_index, int create_item) |
437 | { |
413 | { |
438 | object *item = NULL; |
414 | object *prod_item = 0; |
439 | |
415 | bool found = false; |
440 | *rp_arch_index = 0; |
416 | *rp_arch_index = 0; |
441 | |
417 | |
442 | if (rp->transmute) /* look for matching ingredient/prod archs */ |
418 | if (rp->transmute) /* look for matching ingredient/prod archs */ |
443 | for (item = first_ingred; item; item = item->below) |
419 | for (object *item = first_ingred; item; item = item->below) |
444 | { |
420 | { |
445 | size_t i; |
|
|
446 | |
|
|
447 | for (i = 0; i < rp->arch_names; i++) |
421 | for (int i = 0; i < rp->arch_names; i++) |
448 | { |
422 | //TODO: should be a shstr comparison |
449 | if (strcmp (item->arch->name, rp->arch_name[i]) == 0) |
423 | if (!strcmp(&item->arch->archname,rp->arch_name[i])) |
450 | { |
424 | { |
451 | *rp_arch_index = i; |
425 | *rp_arch_index = i; |
|
|
426 | prod_item = item; |
452 | break; |
427 | break; |
453 | } |
428 | } |
454 | } |
429 | |
455 | if (i < rp->arch_names) |
430 | if (prod_item) |
456 | break; |
431 | break; |
457 | } |
432 | } |
458 | |
433 | |
459 | /* failed, create a fresh object. Note no nrof>1 because that would |
434 | /* failed, create a fresh object. Note no nrof>1 because that would |
460 | * allow players to create massive amounts of artifacts easily */ |
435 | * allow players to create massive amounts of artifacts easily */ |
461 | if (create_item && (!item || item->nrof > 1)) |
436 | if (create_item && (!prod_item || prod_item->nrof > 1)) |
|
|
437 | { |
|
|
438 | #ifdef ALCHEMY_DEBUG |
|
|
439 | LOG (llevDebug, "creating a new item.\n"); |
|
|
440 | if (prod_item != NULL) |
462 | { |
441 | { |
|
|
442 | LOG (llevDebug, " had item: arch %s(nrof:%d)\n", |
|
|
443 | &prod_item->arch->archname, prod_item->nrof); |
|
|
444 | } |
|
|
445 | #endif |
|
|
446 | if (!prod_item) |
463 | *rp_arch_index = RANDOM () % rp->arch_names; |
447 | *rp_arch_index = rndm (rp->arch_names); |
464 | item = get_archetype (rp->arch_name[*rp_arch_index]); |
448 | prod_item = get_archetype (rp->arch_name[*rp_arch_index]); |
465 | } |
449 | } |
466 | |
450 | |
467 | #ifdef ALCHEMY_DEBUG |
451 | #ifdef ALCHEMY_DEBUG |
468 | LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no "); |
452 | LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no "); |
469 | if (item != NULL) |
453 | if (prod_item != NULL) |
470 | { |
454 | { |
471 | LOG (llevDebug, " find_transmutable_ob(): returns arch %s(sp:%d)\n", item->arch->name, item->stats.sp); |
455 | LOG (llevDebug, " find_transmutable_ob(): returns arch %s(sp:%d)\n", |
|
|
456 | &prod_item->arch->archname, prod_item->stats.sp); |
472 | } |
457 | } |
473 | #endif |
458 | #endif |
474 | |
459 | |
475 | return item; |
460 | return prod_item; |
476 | } |
461 | } |
477 | |
462 | |
478 | |
|
|
479 | /**
|
463 | /** |
480 | * Ouch. We didnt get the formula we wanted. |
464 | * Ouch. We didnt get the formula we wanted. |
481 | * This fctn simulates the backfire effects--worse effects as the level |
465 | * This fctn simulates the backfire effects--worse effects as the level |
482 | * increases. If SPELL_FAILURE_EFFECTS is defined some really evil things |
466 | * increases. If SPELL_FAILURE_EFFECTS is defined some really evil things |
483 | * can happen to the would be alchemist. This table probably needs some |
467 | * can happen to the would be alchemist. This table probably needs some |
484 | * adjustment for playbalance. -b.t. |
468 | * adjustment for playbalance. -b.t. |
485 | */ |
469 | */ |
486 | |
|
|
487 | void |
470 | void |
488 | alchemy_failure_effect (object *op, object *cauldron, recipe *rp, int danger) |
471 | alchemy_failure_effect (object *op, object *cauldron, recipe *rp, int danger) |
489 | { |
472 | { |
490 | int level = 0; |
473 | int level = 0; |
491 | |
474 | |
… | |
… | |
506 | |
489 | |
507 | if (rndm (0, 2)) |
490 | if (rndm (0, 2)) |
508 | { /* slag created */ |
491 | { /* slag created */ |
509 | object *tmp = cauldron->inv; |
492 | object *tmp = cauldron->inv; |
510 | int weight = 0; |
493 | int weight = 0; |
511 | uint16 material = M_STONE; |
|
|
512 | |
494 | |
513 | while (tmp) |
|
|
514 | { /* slag has coadded ingredient properties */ |
|
|
515 | weight += tmp->weight; |
|
|
516 | if (!(material & tmp->material)) |
|
|
517 | material |= tmp->material; |
|
|
518 | tmp = tmp->below; |
|
|
519 | } |
|
|
520 | tmp = get_archetype ("rock"); |
495 | tmp = get_archetype ("rock"); |
521 | tmp->weight = weight; |
496 | tmp->weight = weight; |
522 | tmp->value = 0; |
497 | tmp->value = 0; |
523 | tmp->material = material; |
|
|
524 | tmp->materialname = "stone"; |
498 | tmp->materialname = "stone"; |
525 | tmp->name = "slag"; |
499 | tmp->name = "slag"; |
526 | tmp->name_pl = "slags"; |
500 | tmp->name_pl = "slags"; |
527 | item = insert_ob_in_ob (tmp, cauldron); |
501 | item = insert_ob_in_ob (tmp, cauldron); |
528 | CLEAR_FLAG (tmp, FLAG_CAN_ROLL); |
502 | CLEAR_FLAG (tmp, FLAG_CAN_ROLL); |
529 | CLEAR_FLAG (tmp, FLAG_NO_PICK); |
503 | SET_FLAG (tmp, FLAG_NO_DROP); |
530 | tmp->move_block = 0; |
504 | tmp->move_block = 0; |
531 | } |
505 | } |
|
|
506 | |
532 | remove_contents (cauldron->inv, item); |
507 | remove_contents (cauldron->inv, item); |
533 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); |
508 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); |
534 | return; |
509 | return; |
535 | } |
510 | } |
536 | else if (level < 40) |
511 | else if (level < 40) |
… | |
… | |
562 | } |
537 | } |
563 | while (rndm (0, 2)); |
538 | while (rndm (0, 2)); |
564 | } |
539 | } |
565 | return; |
540 | return; |
566 | } |
541 | } |
|
|
542 | |
567 | if (level == 40) |
543 | if (level == 40) |
568 | { /* MAKE RANDOM RECIPE */ |
544 | { /* MAKE RANDOM RECIPE */ |
569 | recipelist *fl; |
545 | recipelist *fl; |
570 | int numb = numb_ob_inside (cauldron); |
546 | int numb = numb_ob_inside (cauldron); |
571 | |
547 | |
… | |
… | |
573 | if (fl && (rp = get_random_recipe (fl))) |
549 | if (fl && (rp = get_random_recipe (fl))) |
574 | /* even though random, don't grant user any EXP for it */ |
550 | /* even though random, don't grant user any EXP for it */ |
575 | (void) attempt_recipe (op, cauldron, 1, rp, -1); |
551 | (void) attempt_recipe (op, cauldron, 1, rp, -1); |
576 | else |
552 | else |
577 | alchemy_failure_effect (op, cauldron, rp, level - 1); |
553 | alchemy_failure_effect (op, cauldron, rp, level - 1); |
578 | return; |
|
|
579 | |
|
|
580 | } |
554 | } |
581 | else if (level < 45) |
555 | else if (level < 45) |
582 | { /* INFURIATE NPC's */ |
556 | { /* INFURIATE NPC's */ |
583 | /* this is kind of kludgy I know... */ |
557 | /* this is kind of kludgy I know... */ |
584 | cauldron->enemy = op; |
558 | cauldron->enemy = op; |
585 | npc_call_help (cauldron); |
559 | npc_call_help (cauldron); |
586 | cauldron->enemy = NULL; |
560 | cauldron->enemy = NULL; |
587 | |
561 | |
588 | alchemy_failure_effect (op, cauldron, rp, level - 5); |
562 | alchemy_failure_effect (op, cauldron, rp, level - 5); |
589 | return; |
|
|
590 | } |
563 | } |
591 | else if (level < 50) |
564 | else if (level < 50) |
592 | { /* MINOR EXPLOSION/FIREBALL */ |
565 | { /* MINOR EXPLOSION/FIREBALL */ |
593 | object *tmp; |
566 | object *tmp; |
594 | |
567 | |
… | |
… | |
608 | tmp->stats.hp = random_roll (1, level, op, PREFER_LOW) / 10 + 2; |
581 | tmp->stats.hp = random_roll (1, level, op, PREFER_LOW) / 10 + 2; |
609 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); |
582 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); |
610 | break; |
583 | break; |
611 | } |
584 | } |
612 | |
585 | |
613 | op->insert_at (cauldron); |
586 | tmp->insert_at (cauldron); |
614 | return; |
|
|
615 | |
|
|
616 | } |
587 | } |
617 | else if (level < 60) |
588 | else if (level < 60) |
618 | { /* CREATE MONSTER */ |
589 | { /* CREATE MONSTER */ |
619 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); |
590 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); |
620 | remove_contents (cauldron->inv, NULL); |
591 | remove_contents (cauldron->inv, NULL); |
621 | return; |
|
|
622 | } |
592 | } |
623 | else if (level < 80) |
593 | else if (level < 80) |
624 | { /* MAJOR FIRE */ |
594 | { /* MAJOR FIRE */ |
625 | object *fb = get_archetype (SP_MED_FIREBALL); |
595 | object *fb = get_archetype (SP_MED_FIREBALL); |
626 | |
596 | |
627 | remove_contents (cauldron->inv, NULL); |
597 | remove_contents (cauldron->inv, NULL); |
628 | fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb); |
598 | fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb); |
629 | fb->destroy (); |
599 | fb->destroy (); |
630 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); |
600 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); |
631 | return; |
|
|
632 | |
|
|
633 | } |
601 | } |
634 | else if (level < 100) |
602 | else if (level < 100) |
635 | { /* WHAMMY the CAULDRON */ |
603 | { /* WHAMMY the CAULDRON */ |
636 | if (!QUERY_FLAG (cauldron, FLAG_CURSED)) |
604 | if (!QUERY_FLAG (cauldron, FLAG_CURSED)) |
637 | SET_FLAG (cauldron, FLAG_CURSED); |
605 | SET_FLAG (cauldron, FLAG_CURSED); |
638 | else |
606 | else |
639 | cauldron->magic--; |
607 | cauldron->magic--; |
|
|
608 | |
640 | cauldron->magic -= random_roll (0, 4, op, PREFER_LOW); |
609 | cauldron->magic -= random_roll (0, 4, op, PREFER_LOW); |
|
|
610 | |
641 | if (rndm (0, 1)) |
611 | if (rndm (0, 1)) |
642 | { |
612 | { |
643 | remove_contents (cauldron->inv, NULL); |
613 | remove_contents (cauldron->inv, NULL); |
644 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s turns darker then makes a gulping sound!", &cauldron->name); |
614 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s turns darker then makes a gulping sound!", &cauldron->name); |
645 | } |
615 | } |
646 | else |
616 | else |
647 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s becomes darker.", &cauldron->name); |
617 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s becomes darker.", &cauldron->name); |
648 | return; |
|
|
649 | |
|
|
650 | } |
618 | } |
651 | else if (level < 110) |
619 | else if (level < 110) |
652 | { /* SUMMON EVIL MONSTERS */ |
620 | { /* SUMMON EVIL MONSTERS */ |
653 | object *tmp = get_random_mon (level / 5); |
621 | object *tmp = get_random_mon (level / 5); |
654 | |
622 | |
655 | remove_contents (cauldron->inv, NULL); |
623 | remove_contents (cauldron->inv, NULL); |
|
|
624 | |
656 | if (!tmp) |
625 | if (!tmp) |
657 | alchemy_failure_effect (op, cauldron, rp, level); |
626 | alchemy_failure_effect (op, cauldron, rp, level); |
658 | else if (summon_hostile_monsters (cauldron, random_roll (1, 10, op, PREFER_LOW), tmp->arch->name)) |
627 | else if (summon_hostile_monsters (cauldron, random_roll (1, 10, op, PREFER_LOW), tmp->arch->archname)) |
659 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s and then pours forth monsters!", &cauldron->name, cauldron_sound ()); |
628 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s and then pours forth monsters!", &cauldron->name, cauldron_sound ()); |
660 | return; |
|
|
661 | |
|
|
662 | } |
629 | } |
663 | else if (level < 150) |
630 | else if (level < 150) |
664 | { /* COMBO EFFECT */ |
631 | { /* COMBO EFFECT */ |
665 | int roll = rndm (1, 3); |
632 | int roll = rndm (1, 3); |
666 | |
633 | |
667 | while (roll) |
634 | while (roll) |
668 | { |
635 | { |
669 | alchemy_failure_effect (op, cauldron, rp, level - 39); |
636 | alchemy_failure_effect (op, cauldron, rp, level - 39); |
670 | roll--; |
637 | roll--; |
671 | } |
638 | } |
672 | return; |
|
|
673 | } |
639 | } |
674 | else if (level == 151) |
640 | else if (level == 151) |
675 | { /* CREATE RANDOM ARTIFACT */ |
641 | { /* CREATE RANDOM ARTIFACT */ |
676 | object *tmp; |
642 | object *tmp; |
677 | |
643 | |
… | |
… | |
679 | * in this one, we allow *any* valid alchemy artifact |
645 | * in this one, we allow *any* valid alchemy artifact |
680 | * to be made (rather than only those on the given |
646 | * to be made (rather than only those on the given |
681 | * formulalist) */ |
647 | * formulalist) */ |
682 | if (!rp) |
648 | if (!rp) |
683 | rp = get_random_recipe ((recipelist *) NULL); |
649 | rp = get_random_recipe ((recipelist *) NULL); |
|
|
650 | |
684 | if (rp && (tmp = get_archetype (rp->arch_name[RANDOM () % rp->arch_names]))) |
651 | if (rp && (tmp = get_archetype (rp->arch_name [rndm (rp->arch_names)]))) |
685 | { |
652 | { |
686 | generate_artifact (tmp, random_roll (1, op->level / 2 + 1, op, PREFER_HIGH) + 1); |
653 | generate_artifact (tmp, random_roll (1, op->level / 2 + 1, op, PREFER_HIGH) + 1); |
687 | if ((tmp = insert_ob_in_ob (tmp, cauldron))) |
654 | if ((tmp = insert_ob_in_ob (tmp, cauldron))) |
688 | { |
655 | { |
689 | remove_contents (cauldron->inv, tmp); |
656 | remove_contents (cauldron->inv, tmp); |
690 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); |
657 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); |
691 | } |
658 | } |
692 | } |
659 | } |
693 | return; |
|
|
694 | } |
660 | } |
695 | else |
661 | else |
696 | { /* MANA STORM - watch out!! */ |
662 | { /* MANA STORM - watch out!! */ |
697 | object *tmp = get_archetype (LOOSE_MANA); |
663 | object *tmp = get_archetype (LOOSE_MANA); |
698 | |
664 | |
699 | new_draw_info (NDI_UNIQUE, 0, op, "You unwisely release potent forces!"); |
665 | new_draw_info (NDI_UNIQUE, 0, op, "You unwisely release potent forces!"); |
700 | remove_contents (cauldron->inv, NULL); |
666 | remove_contents (cauldron->inv, NULL); |
701 | cast_magic_storm (op, tmp, level); |
667 | cast_magic_storm (op, tmp, level); |
702 | return; |
|
|
703 | } |
668 | } |
704 | } |
669 | } |
705 | |
|
|
706 | |
670 | |
707 | /* |
671 | /* |
708 | * All but object "save_item" are elimentated from |
672 | * All but object "save_item" are elimentated from |
709 | * the container list. Note we have to becareful to remove the inventories |
673 | * the container list. Note we have to becareful to remove the inventories |
710 | * of objects in the cauldron inventory (ex icecube has stuff in it). |
674 | * of objects in the cauldron inventory (ex icecube has stuff in it). |
711 | */ |
675 | */ |
712 | |
|
|
713 | void |
676 | void |
714 | remove_contents (object *first_ob, object *save_item) |
677 | remove_contents (object *first_ob, object *save_item) |
715 | { |
678 | { |
|
|
679 | // this cries for a cleaner rewrite, removing save_item first possibly |
716 | object *next, *tmp = first_ob; |
680 | object *next, *tmp = first_ob; |
717 | |
681 | |
718 | while (tmp) |
682 | while (tmp) |
719 | { |
683 | { |
720 | next = tmp->below; |
684 | next = tmp->below; |
… | |
… | |
733 | tmp->destroy (); |
697 | tmp->destroy (); |
734 | tmp = next; |
698 | tmp = next; |
735 | } |
699 | } |
736 | } |
700 | } |
737 | |
701 | |
738 | /**
|
702 | /** |
739 | *"Danger" level, will determine how bad the backfire |
703 | *"Danger" level, will determine how bad the backfire |
740 | * could be if the user fails to concoct a recipe properly. Factors include |
704 | * could be if the user fails to concoct a recipe properly. Factors include |
741 | * the number of ingredients, the length of the name of each ingredient, |
705 | * the number of ingredients, the length of the name of each ingredient, |
742 | * the user's effective level, the user's Int and the enchantment on the |
706 | * the user's effective level, the user's Int and the enchantment on the |
743 | * mixing device (aka "cauldron"). Higher values of 'danger' indicate more |
707 | * mixing device (aka "cauldron"). Higher values of 'danger' indicate more |
744 | * danger. Note that we assume that we have had the caster ready the alchemy |
708 | * danger. Note that we assume that we have had the caster ready the alchemy |
745 | * skill *before* this routine is called. (no longer auto-readies that skill) |
709 | * skill *before* this routine is called. (no longer auto-readies that skill) |
746 | * -b.t. |
710 | * -b.t. |
747 | */ |
711 | */ |
748 | |
|
|
749 | int |
712 | int |
750 | calc_alch_danger (object *caster, object *cauldron, recipe *rp) |
713 | calc_alch_danger (object *caster, object *cauldron, recipe *rp) |
751 | { |
714 | { |
752 | object *item; |
715 | object *item; |
753 | char name[MAX_BUF]; |
716 | char name[MAX_BUF]; |
754 | int danger = 0, nrofi = 0; |
717 | int danger = 0, nrofi = 0; |
755 | |
718 | |
756 | /* Knowing alchemy skill reduces yer risk */ |
719 | /* Knowing alchemy skill reduces yer risk */ |
757 | danger -= caster->chosen_skill ? caster->chosen_skill->level : caster->level; |
720 | danger -= caster->chosen_skill ? caster->chosen_skill->level : caster->level; |
|
|
721 | |
|
|
722 | if (!caster->chosen_skill) |
|
|
723 | LOG (llevError | logBacktrace, "calc_alch_danger called without a chosen skill, caster %s, cauldron %s\n", |
|
|
724 | caster->debug_desc (), cauldron->debug_desc ()); |
758 | |
725 | |
759 | /* better cauldrons reduce risk */ |
726 | /* better cauldrons reduce risk */ |
760 | danger -= cauldron->magic; |
727 | danger -= cauldron->magic; |
761 | |
728 | |
762 | /* Higher Int, lower the risk */ |
729 | /* Higher Int, lower the risk */ |
… | |
… | |
766 | * Thus the backfire is worse. Also, more ingredients |
733 | * Thus the backfire is worse. Also, more ingredients |
767 | * means we are attempting a more powerfull potion, |
734 | * means we are attempting a more powerfull potion, |
768 | * and thus the backfire will be worse. */ |
735 | * and thus the backfire will be worse. */ |
769 | for (item = cauldron->inv; item; item = item->below) |
736 | for (item = cauldron->inv; item; item = item->below) |
770 | { |
737 | { |
771 | strcpy (name, item->name); |
738 | assign (name, item->name); |
772 | if (item->title) |
739 | if (item->title) |
773 | sprintf (name, "%s %s", &item->name, &item->title); |
740 | sprintf (name, "%s %s", &item->name, &item->title); |
774 | danger += (strtoint (name) / 1000) + 3; |
741 | danger += (strtoint (name) / 1000) + 3; |
775 | nrofi++; |
742 | nrofi++; |
776 | } |
743 | } |
|
|
744 | |
777 | if (rp == NULL) |
745 | if (rp == NULL) |
778 | danger += 110; |
746 | danger += 110; |
779 | else |
747 | else |
780 | danger += rp->diff * 3; |
748 | danger += rp->diff * 3; |
781 | |
749 | |
… | |
… | |
790 | #endif |
758 | #endif |
791 | |
759 | |
792 | return danger; |
760 | return danger; |
793 | } |
761 | } |
794 | |
762 | |
795 | /**
|
763 | /** |
796 | * Determines if ingredients in a container match the |
764 | * Determines if ingredients in a container match the |
797 | * proper ingredients for a recipe. |
765 | * proper ingredients for a recipe. |
798 | * |
766 | * |
799 | * rp is the recipe to check |
767 | * rp is the recipe to check |
800 | * cauldron is the container that holds the ingredients |
768 | * cauldron is the container that holds the ingredients |
… | |
… | |
849 | for (ob = cauldron->inv; ob != NULL; ob = ob->below) |
817 | for (ob = cauldron->inv; ob != NULL; ob = ob->below) |
850 | { |
818 | { |
851 | char name_ob[MAX_BUF]; |
819 | char name_ob[MAX_BUF]; |
852 | const char *name2; |
820 | const char *name2; |
853 | |
821 | |
854 | if (ob->title == NULL) |
822 | if (!ob->title) |
855 | name2 = ob->name; |
823 | name2 = ob->name; |
856 | else |
824 | else |
857 | { |
825 | { |
858 | snprintf (name_ob, sizeof (name_ob), "%s %s", &ob->name, &ob->title); |
826 | snprintf (name_ob, sizeof (name_ob), "%s %s", &ob->name, &ob->title); |
859 | name2 = name_ob; |
827 | name2 = name_ob; |
… | |
… | |
904 | LOG (llevDebug, "looking for formula %d:\n", formula); |
872 | LOG (llevDebug, "looking for formula %d:\n", formula); |
905 | #endif |
873 | #endif |
906 | result = NULL; |
874 | result = NULL; |
907 | recipes_matching = 0; |
875 | recipes_matching = 0; |
908 | transmute_found = 0; |
876 | transmute_found = 0; |
|
|
877 | |
909 | for (rp = fl->items; rp != NULL; rp = rp->next) |
878 | for (rp = fl->items; rp; rp = rp->next) |
910 | { |
879 | { |
911 | /* check if recipe matches at all */ |
880 | /* check if recipe matches at all */ |
912 | if (formula % rp->index != 0) |
881 | if (formula % rp->index != 0) |
913 | { |
882 | { |
914 | #ifdef EXTREME_ALCHEMY_DEBUG |
883 | #ifdef EXTREME_ALCHEMY_DEBUG |
915 | LOG (llevDebug, " formula %s of %s (%d) does not match\n", rp->arch_name[0], rp->title, rp->index); |
884 | LOG (llevDebug, " formula %s of %s (%d) does not match\n", rp->arch_name[0], &rp->title, rp->index); |
916 | #endif |
885 | #endif |
917 | continue; |
886 | continue; |
918 | } |
887 | } |
919 | |
888 | |
920 | if (rp->transmute && find_transmution_ob (ingredients, rp, &rp_arch_index, 0) != NULL) |
889 | if (rp->transmute && find_transmution_ob (ingredients, rp, &rp_arch_index, 0) != NULL) |
921 | { |
890 | { |
922 | #ifdef EXTREME_ALCHEMY_DEBUG |
891 | #ifdef EXTREME_ALCHEMY_DEBUG |
923 | LOG (llevDebug, " formula %s of %s (%d) is a matching transmuting formula\n", rp->arch_name[rp_arch_index], rp->title, rp->index); |
892 | LOG (llevDebug, " formula %s of %s (%d) is a matching transmuting formula\n", rp->arch_name[rp_arch_index], &rp->title, rp->index); |
924 | #endif |
893 | #endif |
925 | /* transmution recipe with matching base ingredient */ |
894 | /* transmution recipe with matching base ingredient */ |
926 | if (!transmute_found) |
895 | if (!transmute_found) |
927 | { |
896 | { |
928 | transmute_found = 1; |
897 | transmute_found = 1; |
… | |
… | |
930 | } |
899 | } |
931 | } |
900 | } |
932 | else if (transmute_found) |
901 | else if (transmute_found) |
933 | { |
902 | { |
934 | #ifdef EXTREME_ALCHEMY_DEBUG |
903 | #ifdef EXTREME_ALCHEMY_DEBUG |
935 | LOG (llevDebug, " formula %s of %s (%d) matches but is not a matching transmuting formula\n", rp->arch_name[0], rp->title, |
904 | LOG (llevDebug, " formula %s of %s (%d) matches but is not a matching transmuting formula\n", rp->arch_name[0], &rp->title, |
936 | rp->index); |
905 | rp->index); |
937 | #endif |
906 | #endif |
938 | /* "normal" recipe found after previous transmution recipe => ignore this recipe */ |
907 | /* "normal" recipe found after previous transmution recipe => ignore this recipe */ |
939 | continue; |
908 | continue; |
940 | } |
909 | } |
941 | #ifdef EXTREME_ALCHEMY_DEBUG |
910 | #ifdef EXTREME_ALCHEMY_DEBUG |
942 | else |
911 | else |
943 | { |
912 | { |
944 | LOG (llevDebug, " formula %s of %s (%d) matches\n", rp->arch_name[0], rp->title, rp->index); |
913 | LOG (llevDebug, " formula %s of %s (%d) matches\n", rp->arch_name[0], &rp->title, rp->index); |
945 | } |
914 | } |
946 | #endif |
915 | #endif |
947 | |
916 | |
948 | if (rndm (0, recipes_matching) == 0) |
917 | if (rndm (0, recipes_matching) == 0) |
949 | result = rp; |
918 | result = rp; |
… | |
… | |
959 | return NULL; |
928 | return NULL; |
960 | } |
929 | } |
961 | |
930 | |
962 | #ifdef ALCHEMY_DEBUG |
931 | #ifdef ALCHEMY_DEBUG |
963 | if (strcmp (result->title, "NONE") != 0) |
932 | if (strcmp (result->title, "NONE") != 0) |
964 | LOG (llevDebug, "got formula: %s of %s (nbatches:%d)\n", result->arch_name[0], result->title, formula / result->index); |
933 | LOG (llevDebug, "got formula: %s of %s (nbatches:%d)\n", result->arch_name[0], &result->title, formula / result->index); |
965 | else |
934 | else |
966 | LOG (llevDebug, "got formula: %s (nbatches:%d)\n", result->arch_name[0], formula / result->index); |
935 | LOG (llevDebug, "got formula: %s (nbatches:%d)\n", result->arch_name[0], formula / result->index); |
967 | #endif |
936 | #endif |
968 | return result; |
937 | return result; |
969 | } |
938 | } |