1 | |
|
|
2 | /* |
1 | /* |
3 | * static char *rcsid_alchemy_c = |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
4 | * "$Id: alchemy.C,v 1.7 2006/09/10 15:59:57 root Exp $"; |
3 | * |
5 | */ |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
6 | |
|
|
7 | /* |
|
|
8 | CrossFire, A Multiplayer game for X-windows |
|
|
9 | |
|
|
10 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
11 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
12 | |
7 | * |
13 | This program is free software; you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify |
14 | it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
15 | the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation, either version 3 of the License, or |
16 | (at your option) any later version. |
11 | * (at your option) any later version. |
17 | |
12 | * |
18 | 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, |
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
21 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
22 | |
17 | * |
23 | You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
24 | along with this program; if not, write to the Free Software |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
25 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * |
26 | |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
27 | The authors can be reached via e-mail at crossfire-devel@real-time.com |
|
|
28 | */ |
22 | */ |
29 | |
23 | |
30 | /* March 96 - Laid down original code. -b.t. thomas@astro.psu.edu */ |
24 | /* March 96 - Laid down original code. -b.t. thomas@astro.psu.edu */ |
31 | |
25 | |
32 | #include <global.h> |
26 | #include <global.h> |
33 | #include <object.h> |
27 | #include <object.h> |
34 | #ifndef __CEXTRACT__ |
|
|
35 | # include <sproto.h> |
28 | #include <sproto.h> |
36 | #endif |
|
|
37 | #include <skills.h> |
29 | #include <skills.h> |
38 | #include <spells.h> |
30 | #include <spells.h> |
39 | |
31 | |
40 | /** define this for some helpful debuging information */ |
32 | /** define this for some helpful debuging information */ |
41 | #if 0 |
33 | #if 0 |
… | |
… | |
102 | * around. :) |
94 | * around. :) |
103 | * -b.t. |
95 | * -b.t. |
104 | */ |
96 | */ |
105 | |
97 | |
106 | void |
98 | void |
107 | attempt_do_alchemy (object *caster, object *cauldron) |
99 | attempt_do_alchemy (object *caster, object *cauldron, object *skill) |
108 | { |
100 | { |
109 | recipelist *fl; |
101 | recipelist *fl; |
110 | recipe *rp = NULL; |
102 | recipe *rp = NULL; |
111 | float success_chance; |
103 | float success_chance; |
112 | int numb, ability = 1; |
104 | int numb, ability = 1; |
… | |
… | |
148 | return; |
140 | return; |
149 | } /* End of WIZ alchemy */ |
141 | } /* End of WIZ alchemy */ |
150 | |
142 | |
151 | /* find the recipe */ |
143 | /* find the recipe */ |
152 | rp = find_recipe (fl, formula, cauldron->inv); |
144 | rp = find_recipe (fl, formula, cauldron->inv); |
153 | if (rp) |
145 | if (rp |
|
|
146 | && rp->skill == skill->skill |
|
|
147 | && (!rp->cauldron |
|
|
148 | || rp->cauldron == cauldron->arch->archname)) |
154 | { |
149 | { |
155 | uint64 value_ingredients; |
150 | uint64 value_ingredients; |
156 | uint64 value_item; |
151 | uint64 value_item; |
157 | object *tmp; |
152 | object *tmp; |
158 | int attempt_shadow_alchemy; |
153 | int attempt_shadow_alchemy; |
159 | |
154 | |
160 | ave_chance = fl->total_chance / (float) fl->number; |
155 | ave_chance = fl->total_chance / (float) fl->number; |
161 | /* the caster gets an increase in ability based on thier skill lvl */ |
156 | |
162 | if (rp->skill) |
|
|
163 | { |
|
|
164 | skop = find_skill_by_name (caster, rp->skill); |
|
|
165 | if (!skop) |
|
|
166 | { |
|
|
167 | new_draw_info (NDI_UNIQUE, 0, caster, "You do not have the proper skill for this recipe"); |
|
|
168 | } |
|
|
169 | else |
|
|
170 | { |
|
|
171 | ability += (int) (skop->level * ((4.0 + cauldron->magic) / 4.0)); |
157 | ability += (int) (skill->level * ((4.0 + cauldron->magic) / 4.0)); |
172 | } |
|
|
173 | } |
|
|
174 | else |
|
|
175 | { |
|
|
176 | LOG (llevDebug, "Recipe %s has NULL skill!\n", &rp->title); |
|
|
177 | return; |
|
|
178 | } |
|
|
179 | |
|
|
180 | if (rp->cauldron) |
|
|
181 | { |
|
|
182 | LOG (llevDebug, "Recipe %s has NULL cauldron!\n", &rp->title); |
|
|
183 | return; |
|
|
184 | } |
|
|
185 | |
158 | |
186 | /* determine value of ingredients */ |
159 | /* determine value of ingredients */ |
187 | value_ingredients = 0; |
160 | value_ingredients = 0; |
188 | for (tmp = cauldron->inv; tmp != NULL; tmp = tmp->below) |
161 | for (tmp = cauldron->inv; tmp != NULL; tmp = tmp->below) |
189 | value_ingredients += query_cost (tmp, NULL, F_TRUE); |
162 | value_ingredients += query_cost (tmp, NULL, F_TRUE); |
… | |
… | |
204 | |
177 | |
205 | value_item = query_cost (item, NULL, F_TRUE | F_IDENTIFIED | F_NOT_CURSED); |
178 | value_item = query_cost (item, NULL, F_TRUE | F_IDENTIFIED | F_NOT_CURSED); |
206 | if (attempt_shadow_alchemy && value_item > value_ingredients) |
179 | if (attempt_shadow_alchemy && value_item > value_ingredients) |
207 | { |
180 | { |
208 | #ifdef ALCHEMY_DEBUG |
181 | #ifdef ALCHEMY_DEBUG |
209 | # ifndef WIN32 |
|
|
210 | LOG (llevDebug, |
182 | LOG (llevDebug, |
211 | "Forcing failure for shadow alchemy recipe because price of ingredients (%llu) is less than price of result (%llu).\n", |
183 | "Forcing failure for shadow alchemy recipe because price of ingredients (%llu) is less than price of result (%llu).\n", |
212 | value_ingredients, value_item); |
184 | value_ingredients, value_item); |
213 | # else |
|
|
214 | LOG (llevDebug, |
|
|
215 | "Forcing failure for shadow alchemy recipe because price of ingredients (%I64d) is less than price of result (%I64d).\n", |
|
|
216 | value_ingredients, value_item); |
|
|
217 | # endif |
|
|
218 | #endif |
185 | #endif |
219 | } |
186 | } |
220 | /* roll the dice */ |
187 | /* roll the dice */ |
221 | else if ((float) (random_roll (0, 101, caster, PREFER_LOW)) <= 100.0 * success_chance) |
188 | else if ((float) (random_roll (0, 101, caster, PREFER_LOW)) <= 100.0 * success_chance) |
222 | { |
189 | { |
223 | change_exp (caster, rp->exp, rp->skill, SK_EXP_NONE); |
190 | change_exp (caster, rp->exp, rp->skill, SK_EXP_NONE); |
|
|
191 | |
|
|
192 | // let alchemy consume some time, so that exploits are less easy |
|
|
193 | caster->speed_left -= 1.0; |
|
|
194 | |
224 | return; |
195 | return; |
225 | } |
196 | } |
226 | } |
197 | } |
227 | } |
198 | } |
228 | } |
199 | } |
|
|
200 | |
229 | /* if we get here, we failed!! */ |
201 | /* if we get here, we failed!! */ |
230 | alchemy_failure_effect (caster, cauldron, rp, calc_alch_danger (caster, cauldron, rp)); |
202 | alchemy_failure_effect (caster, cauldron, rp, calc_alch_danger (caster, cauldron, rp)); |
231 | } |
203 | } |
232 | |
204 | |
233 | /**
|
205 | /**
|
… | |
… | |
244 | int tval = 0, formula = 0; |
216 | int tval = 0, formula = 0; |
245 | |
217 | |
246 | while (tmp) |
218 | while (tmp) |
247 | { |
219 | { |
248 | tval = 0; |
220 | tval = 0; |
249 | strcpy (name, tmp->name); |
221 | assign (name, tmp->name); |
250 | if (tmp->title) |
222 | if (tmp->title) |
251 | sprintf (name, "%s %s", &tmp->name, &tmp->title); |
223 | sprintf (name, "%s %s", &tmp->name, &tmp->title); |
252 | tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1)); |
224 | tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1)); |
253 | #ifdef ALCHEMY_DEBUG |
225 | #ifdef ALCHEMY_DEBUG |
254 | LOG (llevDebug, "Got ingredient %d %s(%d)\n", tmp->nrof ? tmp->nrof : 1, name, tval); |
226 | LOG (llevDebug, "Got ingredient %d %s(%d)\n", tmp->nrof ? tmp->nrof : 1, name, tval); |
… | |
… | |
302 | object *item = NULL, *skop; |
274 | object *item = NULL, *skop; |
303 | |
275 | |
304 | /* this should be passed to this fctn, not effiecent cpu use this way */ |
276 | /* this should be passed to this fctn, not effiecent cpu use this way */ |
305 | int batches = abs (nbatches); |
277 | int batches = abs (nbatches); |
306 | |
278 | |
307 | |
|
|
308 | LOG (llevDebug, "A %s <=> %s\n", &(rp->cauldron), &(cauldron->arch->name)); |
|
|
309 | /* is the cauldron the right type? */ |
279 | /* is the cauldron the right type? */ |
310 | if (strcmp (rp->cauldron, cauldron->arch->name) != 0) |
280 | if (rp->cauldron && rp->cauldron != cauldron->arch->archname) |
311 | { |
|
|
312 | new_draw_info (NDI_UNIQUE, 0, caster, "You are not using the proper" " facilities for this formula."); |
|
|
313 | return 0; |
281 | return 0; |
314 | } |
|
|
315 | |
282 | |
316 | skop = find_skill_by_name (caster, rp->skill); |
283 | skop = find_skill_by_name (caster, rp->skill); |
317 | /* does the caster have the skill? */ |
284 | /* does the caster have the skill? */ |
318 | if (!skop) |
285 | if (!skop) |
319 | return 0; |
286 | return 0; |
… | |
… | |
321 | /* code required for this recipe, search the caster */ |
288 | /* code required for this recipe, search the caster */ |
322 | if (rp->keycode) |
289 | if (rp->keycode) |
323 | { |
290 | { |
324 | object *tmp; |
291 | object *tmp; |
325 | |
292 | |
326 | for (tmp = caster->inv; tmp != NULL; tmp = tmp->below) |
293 | for (tmp = caster->inv; tmp; tmp = tmp->below) |
327 | { |
294 | { |
328 | if (tmp->type == FORCE && tmp->slaying && !strcmp (rp->keycode, tmp->slaying)) |
295 | if (tmp->type == FORCE && tmp->slaying && rp->keycode == tmp->slaying) |
329 | break; |
296 | break; |
330 | } |
297 | } |
|
|
298 | |
331 | if (tmp == NULL) |
299 | if (!tmp) |
332 | { /* failure--no code found */ |
300 | { /* failure--no code found */ |
333 | new_draw_info (NDI_UNIQUE, 0, caster, "You know the ingredients," " but not the technique. Go learn how to do this recipe."); |
301 | new_draw_info (NDI_UNIQUE, 0, caster, "You know the ingredients, but not the technique. Go learn how to do this recipe."); |
334 | return 0; |
302 | return 0; |
335 | } |
303 | } |
336 | } |
304 | } |
337 | |
305 | |
338 | #ifdef EXTREME_ALCHEMY_DEBUG |
306 | #ifdef EXTREME_ALCHEMY_DEBUG |
… | |
… | |
342 | |
310 | |
343 | if ((item = make_item_from_recipe (cauldron, rp)) != NULL) |
311 | if ((item = make_item_from_recipe (cauldron, rp)) != NULL) |
344 | { |
312 | { |
345 | remove_contents (cauldron->inv, item); |
313 | remove_contents (cauldron->inv, item); |
346 | /* Recalc carrying of the cauldron, in case recipe did not conserve mass */ |
314 | /* Recalc carrying of the cauldron, in case recipe did not conserve mass */ |
347 | sum_weight (cauldron); |
315 | cauldron->update_weight (); |
348 | /* adj lvl, nrof on caster level */ |
316 | /* adj lvl, nrof on caster level */ |
349 | adjust_product (item, ability, rp->yield ? (rp->yield * batches) : batches); |
317 | adjust_product (item, ability, rp->yield ? (rp->yield * batches) : batches); |
350 | if (!item->env && (item = insert_ob_in_ob (item, cauldron)) == NULL) |
318 | if (!item->env && (item = insert_ob_in_ob (item, cauldron)) == NULL) |
351 | { |
319 | { |
352 | new_draw_info (NDI_UNIQUE, 0, caster, "Nothing happened."); |
320 | new_draw_info (NDI_UNIQUE, 0, caster, "Nothing happened."); |
353 | /* new_draw_info_format(NDI_UNIQUE, 0,caster, |
321 | /* new_draw_info_format(NDI_UNIQUE, 0,caster, |
354 | "Your spell causes the %s to explode!",&cauldron->name); */ |
322 | "Your spell causes the %s to explode!",&cauldron->name); */ |
355 | /* kaboom_cauldron(); */ |
323 | /* kaboom_cauldron(); */ |
356 | } |
324 | } |
357 | else |
325 | else |
358 | { |
|
|
359 | new_draw_info_format (NDI_UNIQUE, 0, caster, "The %s %s.", &cauldron->name, cauldron_sound ()); |
326 | new_draw_info_format (NDI_UNIQUE, 0, caster, "The %s %s.", &cauldron->name, cauldron_sound ()); |
360 | } |
|
|
361 | } |
327 | } |
|
|
328 | |
362 | return item; |
329 | return item; |
363 | } |
330 | } |
364 | |
331 | |
365 | |
332 | |
366 | |
333 | |
367 | /**
|
334 | /** |
368 | * We adjust the nrof, exp and level of the final product, based |
335 | * We adjust the nrof, exp and level of the final product, based |
369 | * on the item's default parameters, and the relevant caster skill level.
|
336 | * on the item's default parameters, and the relevant caster skill level.
|
370 | */ |
337 | */ |
371 |
void |
338 | void |
372 | adjust_product (object *item, int lvl, int yield) |
339 | adjust_product (object *item, int lvl, int yield) |
373 | { |
340 | { |
374 | int nrof = 1; |
341 | int nrof = 1; |
375 | |
342 | |
376 | if (!yield) |
343 | if (!yield) |
377 | yield = 1; |
344 | yield = 1; |
|
|
345 | |
378 | if (lvl <= 0) |
346 | if (lvl <= 0) |
379 | lvl = 1; /* lets avoid div by zero! */ |
347 | lvl = 1; /* lets avoid div by zero! */ |
|
|
348 | |
380 | if (item->nrof) |
349 | if (item->nrof) |
381 | { |
350 | { |
382 | nrof = (int) ((1.0 - 1.0 / (lvl / 10.0 + 1.0)) * (rndm (0, yield - 1) + rndm (0, yield - 1) + rndm (0, yield - 1)) + 1); |
351 | nrof = (int) ((1.0 - 1.0 / (lvl / 10.0 + 1.0)) * (rndm (0, yield - 1) + rndm (0, yield - 1) + rndm (0, yield - 1)) + 1); |
|
|
352 | |
383 | if (nrof > yield) |
353 | if (nrof > yield) |
384 | nrof = yield; |
354 | nrof = yield; |
|
|
355 | |
385 | item->nrof = nrof; |
356 | item->nrof = nrof; |
386 | } |
357 | } |
387 | } |
358 | } |
388 | |
359 | |
389 | |
360 | |
… | |
… | |
413 | LOG (llevDebug, "make_alchemy_item(): failed to create alchemical object.\n"); |
384 | LOG (llevDebug, "make_alchemy_item(): failed to create alchemical object.\n"); |
414 | return (object *) NULL; |
385 | return (object *) NULL; |
415 | } |
386 | } |
416 | |
387 | |
417 | /* Find the appropriate artifact template... */ |
388 | /* Find the appropriate artifact template... */ |
418 | if (strcmp (rp->title, "NONE")) |
389 | if (rp->title != shstr_NONE) |
419 | { |
390 | { |
420 | if ((art = locate_recipe_artifact (rp, rp_arch_index)) == NULL) |
391 | if ((art = locate_recipe_artifact (rp, rp_arch_index)) == NULL) |
421 | { |
392 | { |
422 | LOG (llevError, "make_alchemy_item(): failed to locate recipe artifact.\n"); |
393 | LOG (llevError, "make_alchemy_item(): failed to locate recipe artifact.\n"); |
423 | LOG (llevDebug, " --requested recipe: %s of %s.\n", rp->arch_name[0], &rp->title); |
394 | LOG (llevDebug, " --requested recipe: %s of %s.\n", rp->arch_name[0], &rp->title); |
424 | return (object *) NULL; |
395 | return (object *) NULL; |
425 | } |
396 | } |
|
|
397 | |
426 | transmute_materialname (item, art->item); |
398 | transmute_materialname (item, art->item); |
427 | give_artifact_abilities (item, art->item); |
399 | give_artifact_abilities (item, art->item); |
428 | } |
400 | } |
429 | |
401 | |
430 | if (QUERY_FLAG (cauldron, FLAG_CURSED)) |
402 | if (QUERY_FLAG (cauldron, FLAG_CURSED)) |
… | |
… | |
453 | *rp_arch_index = 0; |
425 | *rp_arch_index = 0; |
454 | |
426 | |
455 | if (rp->transmute) /* look for matching ingredient/prod archs */ |
427 | if (rp->transmute) /* look for matching ingredient/prod archs */ |
456 | for (item = first_ingred; item; item = item->below) |
428 | for (item = first_ingred; item; item = item->below) |
457 | { |
429 | { |
458 | size_t i; |
430 | int i; |
459 | |
431 | |
460 | for (i = 0; i < rp->arch_names; i++) |
432 | for (int i = 0; i < rp->arch_names; i++) |
461 | { |
433 | //TODO: should be a shstr comparison |
462 | if (strcmp (item->arch->name, rp->arch_name[i]) == 0) |
434 | if (&item->arch->archname == rp->arch_name[i]) |
463 | { |
435 | { |
464 | *rp_arch_index = i; |
436 | *rp_arch_index = i; |
465 | break; |
437 | break; |
466 | } |
438 | } |
467 | } |
439 | |
468 | if (i < rp->arch_names) |
440 | if (i < rp->arch_names) |
469 | break; |
441 | break; |
470 | } |
442 | } |
471 | |
443 | |
472 | /* failed, create a fresh object. Note no nrof>1 because that would |
444 | /* failed, create a fresh object. Note no nrof>1 because that would |
473 | * allow players to create massive amounts of artifacts easily */ |
445 | * allow players to create massive amounts of artifacts easily */ |
474 | if (create_item && (!item || item->nrof > 1)) |
446 | if (create_item && (!item || item->nrof > 1)) |
475 | { |
447 | { |
476 | *rp_arch_index = RANDOM () % rp->arch_names; |
448 | *rp_arch_index = rndm (rp->arch_names); |
477 | item = get_archetype (rp->arch_name[*rp_arch_index]); |
449 | item = get_archetype (rp->arch_name[*rp_arch_index]); |
478 | } |
450 | } |
479 | |
451 | |
480 | #ifdef ALCHEMY_DEBUG |
452 | #ifdef ALCHEMY_DEBUG |
481 | LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no "); |
453 | LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no "); |
… | |
… | |
519 | |
491 | |
520 | if (rndm (0, 2)) |
492 | if (rndm (0, 2)) |
521 | { /* slag created */ |
493 | { /* slag created */ |
522 | object *tmp = cauldron->inv; |
494 | object *tmp = cauldron->inv; |
523 | int weight = 0; |
495 | int weight = 0; |
524 | uint16 material = M_STONE; |
|
|
525 | |
496 | |
526 | while (tmp) |
|
|
527 | { /* slag has coadded ingredient properties */ |
|
|
528 | weight += tmp->weight; |
|
|
529 | if (!(material & tmp->material)) |
|
|
530 | material |= tmp->material; |
|
|
531 | tmp = tmp->below; |
|
|
532 | } |
|
|
533 | tmp = get_archetype ("rock"); |
497 | tmp = get_archetype ("rock"); |
534 | tmp->weight = weight; |
498 | tmp->weight = weight; |
535 | tmp->value = 0; |
499 | tmp->value = 0; |
536 | tmp->material = material; |
|
|
537 | tmp->materialname = "stone"; |
500 | tmp->materialname = "stone"; |
538 | tmp->name = "slag"; |
501 | tmp->name = "slag"; |
539 | tmp->name_pl = "slags"; |
502 | tmp->name_pl = "slags"; |
540 | item = insert_ob_in_ob (tmp, cauldron); |
503 | item = insert_ob_in_ob (tmp, cauldron); |
541 | CLEAR_FLAG (tmp, FLAG_CAN_ROLL); |
504 | CLEAR_FLAG (tmp, FLAG_CAN_ROLL); |
542 | CLEAR_FLAG (tmp, FLAG_NO_PICK); |
505 | CLEAR_FLAG (tmp, FLAG_NO_PICK); |
543 | tmp->move_block = 0; |
506 | tmp->move_block = 0; |
544 | } |
507 | } |
|
|
508 | |
545 | remove_contents (cauldron->inv, item); |
509 | remove_contents (cauldron->inv, item); |
546 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); |
510 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); |
547 | return; |
511 | return; |
548 | } |
512 | } |
549 | else if (level < 40) |
513 | else if (level < 40) |
… | |
… | |
575 | } |
539 | } |
576 | while (rndm (0, 2)); |
540 | while (rndm (0, 2)); |
577 | } |
541 | } |
578 | return; |
542 | return; |
579 | } |
543 | } |
|
|
544 | |
580 | if (level == 40) |
545 | if (level == 40) |
581 | { /* MAKE RANDOM RECIPE */ |
546 | { /* MAKE RANDOM RECIPE */ |
582 | recipelist *fl; |
547 | recipelist *fl; |
583 | int numb = numb_ob_inside (cauldron); |
548 | int numb = numb_ob_inside (cauldron); |
584 | |
549 | |
… | |
… | |
586 | if (fl && (rp = get_random_recipe (fl))) |
551 | if (fl && (rp = get_random_recipe (fl))) |
587 | /* even though random, don't grant user any EXP for it */ |
552 | /* even though random, don't grant user any EXP for it */ |
588 | (void) attempt_recipe (op, cauldron, 1, rp, -1); |
553 | (void) attempt_recipe (op, cauldron, 1, rp, -1); |
589 | else |
554 | else |
590 | alchemy_failure_effect (op, cauldron, rp, level - 1); |
555 | alchemy_failure_effect (op, cauldron, rp, level - 1); |
591 | return; |
|
|
592 | |
|
|
593 | } |
556 | } |
594 | else if (level < 45) |
557 | else if (level < 45) |
595 | { /* INFURIATE NPC's */ |
558 | { /* INFURIATE NPC's */ |
596 | /* this is kind of kludgy I know... */ |
559 | /* this is kind of kludgy I know... */ |
597 | cauldron->enemy = op; |
560 | cauldron->enemy = op; |
598 | npc_call_help (cauldron); |
561 | npc_call_help (cauldron); |
599 | cauldron->enemy = NULL; |
562 | cauldron->enemy = NULL; |
600 | |
563 | |
601 | alchemy_failure_effect (op, cauldron, rp, level - 5); |
564 | alchemy_failure_effect (op, cauldron, rp, level - 5); |
602 | return; |
|
|
603 | } |
565 | } |
604 | else if (level < 50) |
566 | else if (level < 50) |
605 | { /* MINOR EXPLOSION/FIREBALL */ |
567 | { /* MINOR EXPLOSION/FIREBALL */ |
606 | object *tmp; |
568 | object *tmp; |
607 | |
569 | |
608 | remove_contents (cauldron->inv, NULL); |
570 | remove_contents (cauldron->inv, NULL); |
609 | switch (rndm (0, 2)) |
571 | switch (rndm (0, 2)) |
610 | { |
572 | { |
611 | case 0: |
573 | case 0: |
612 | tmp = get_archetype ("bomb"); |
574 | tmp = get_archetype ("bomb"); |
613 | tmp->stats.dam = random_roll (1, level, op, PREFER_LOW); |
575 | tmp->stats.dam = random_roll (1, level, op, PREFER_LOW); |
614 | tmp->stats.hp = random_roll (1, level, op, PREFER_LOW); |
576 | tmp->stats.hp = random_roll (1, level, op, PREFER_LOW); |
615 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s creates a bomb!", &cauldron->name); |
577 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s creates a bomb!", &cauldron->name); |
616 | break; |
578 | break; |
617 | |
579 | |
618 | default: |
580 | default: |
619 | tmp = get_archetype ("fireball"); |
581 | tmp = get_archetype ("fireball"); |
620 | tmp->stats.dam = random_roll (1, level, op, PREFER_LOW) / 5 + 1; |
582 | tmp->stats.dam = random_roll (1, level, op, PREFER_LOW) / 5 + 1; |
621 | tmp->stats.hp = random_roll (1, level, op, PREFER_LOW) / 10 + 2; |
583 | tmp->stats.hp = random_roll (1, level, op, PREFER_LOW) / 10 + 2; |
622 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); |
584 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); |
623 | break; |
585 | break; |
624 | } |
586 | } |
625 | tmp->x = cauldron->x, tmp->y = cauldron->y; |
|
|
626 | insert_ob_in_map (tmp, op->map, NULL, 0); |
|
|
627 | return; |
|
|
628 | |
587 | |
|
|
588 | tmp->insert_at (cauldron); |
629 | } |
589 | } |
630 | else if (level < 60) |
590 | else if (level < 60) |
631 | { /* CREATE MONSTER */ |
591 | { /* CREATE MONSTER */ |
632 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); |
592 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); |
633 | remove_contents (cauldron->inv, NULL); |
593 | remove_contents (cauldron->inv, NULL); |
634 | return; |
|
|
635 | } |
594 | } |
636 | else if (level < 80) |
595 | else if (level < 80) |
637 | { /* MAJOR FIRE */ |
596 | { /* MAJOR FIRE */ |
638 | object *fb = get_archetype (SP_MED_FIREBALL); |
597 | object *fb = get_archetype (SP_MED_FIREBALL); |
639 | |
598 | |
640 | remove_contents (cauldron->inv, NULL); |
599 | remove_contents (cauldron->inv, NULL); |
641 | fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb); |
600 | fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb); |
642 | free_object (fb); |
601 | fb->destroy (); |
643 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); |
602 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); |
644 | return; |
|
|
645 | |
|
|
646 | } |
603 | } |
647 | else if (level < 100) |
604 | else if (level < 100) |
648 | { /* WHAMMY the CAULDRON */ |
605 | { /* WHAMMY the CAULDRON */ |
649 | if (!QUERY_FLAG (cauldron, FLAG_CURSED)) |
606 | if (!QUERY_FLAG (cauldron, FLAG_CURSED)) |
650 | SET_FLAG (cauldron, FLAG_CURSED); |
607 | SET_FLAG (cauldron, FLAG_CURSED); |
651 | else |
608 | else |
652 | cauldron->magic--; |
609 | cauldron->magic--; |
|
|
610 | |
653 | cauldron->magic -= random_roll (0, 4, op, PREFER_LOW); |
611 | cauldron->magic -= random_roll (0, 4, op, PREFER_LOW); |
|
|
612 | |
654 | if (rndm (0, 1)) |
613 | if (rndm (0, 1)) |
655 | { |
614 | { |
656 | remove_contents (cauldron->inv, NULL); |
615 | remove_contents (cauldron->inv, NULL); |
657 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s turns darker then makes a gulping sound!", &cauldron->name); |
616 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s turns darker then makes a gulping sound!", &cauldron->name); |
658 | } |
617 | } |
659 | else |
618 | else |
660 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s becomes darker.", &cauldron->name); |
619 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s becomes darker.", &cauldron->name); |
661 | return; |
|
|
662 | |
|
|
663 | } |
620 | } |
664 | else if (level < 110) |
621 | else if (level < 110) |
665 | { /* SUMMON EVIL MONSTERS */ |
622 | { /* SUMMON EVIL MONSTERS */ |
666 | object *tmp = get_random_mon (level / 5); |
623 | object *tmp = get_random_mon (level / 5); |
667 | |
624 | |
668 | remove_contents (cauldron->inv, NULL); |
625 | remove_contents (cauldron->inv, NULL); |
|
|
626 | |
669 | if (!tmp) |
627 | if (!tmp) |
670 | alchemy_failure_effect (op, cauldron, rp, level); |
628 | alchemy_failure_effect (op, cauldron, rp, level); |
671 | else if (summon_hostile_monsters (cauldron, random_roll (1, 10, op, PREFER_LOW), tmp->arch->name)) |
629 | else if (summon_hostile_monsters (cauldron, random_roll (1, 10, op, PREFER_LOW), tmp->arch->archname)) |
672 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s and then pours forth monsters!", &cauldron->name, cauldron_sound ()); |
630 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s and then pours forth monsters!", &cauldron->name, cauldron_sound ()); |
673 | return; |
|
|
674 | |
|
|
675 | } |
631 | } |
676 | else if (level < 150) |
632 | else if (level < 150) |
677 | { /* COMBO EFFECT */ |
633 | { /* COMBO EFFECT */ |
678 | int roll = rndm (1, 3); |
634 | int roll = rndm (1, 3); |
679 | |
635 | |
680 | while (roll) |
636 | while (roll) |
681 | { |
637 | { |
682 | alchemy_failure_effect (op, cauldron, rp, level - 39); |
638 | alchemy_failure_effect (op, cauldron, rp, level - 39); |
683 | roll--; |
639 | roll--; |
684 | } |
640 | } |
685 | return; |
|
|
686 | } |
641 | } |
687 | else if (level == 151) |
642 | else if (level == 151) |
688 | { /* CREATE RANDOM ARTIFACT */ |
643 | { /* CREATE RANDOM ARTIFACT */ |
689 | object *tmp; |
644 | object *tmp; |
690 | |
645 | |
… | |
… | |
692 | * in this one, we allow *any* valid alchemy artifact |
647 | * in this one, we allow *any* valid alchemy artifact |
693 | * to be made (rather than only those on the given |
648 | * to be made (rather than only those on the given |
694 | * formulalist) */ |
649 | * formulalist) */ |
695 | if (!rp) |
650 | if (!rp) |
696 | rp = get_random_recipe ((recipelist *) NULL); |
651 | rp = get_random_recipe ((recipelist *) NULL); |
|
|
652 | |
697 | if (rp && (tmp = get_archetype (rp->arch_name[RANDOM () % rp->arch_names]))) |
653 | if (rp && (tmp = get_archetype (rp->arch_name [rndm (rp->arch_names)]))) |
698 | { |
654 | { |
699 | generate_artifact (tmp, random_roll (1, op->level / 2 + 1, op, PREFER_HIGH) + 1); |
655 | generate_artifact (tmp, random_roll (1, op->level / 2 + 1, op, PREFER_HIGH) + 1); |
700 | if ((tmp = insert_ob_in_ob (tmp, cauldron))) |
656 | if ((tmp = insert_ob_in_ob (tmp, cauldron))) |
701 | { |
657 | { |
702 | remove_contents (cauldron->inv, tmp); |
658 | remove_contents (cauldron->inv, tmp); |
703 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); |
659 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); |
704 | } |
660 | } |
705 | } |
661 | } |
706 | return; |
|
|
707 | } |
662 | } |
708 | else |
663 | else |
709 | { /* MANA STORM - watch out!! */ |
664 | { /* MANA STORM - watch out!! */ |
710 | object *tmp = get_archetype (LOOSE_MANA); |
665 | object *tmp = get_archetype (LOOSE_MANA); |
711 | |
666 | |
712 | new_draw_info (NDI_UNIQUE, 0, op, "You unwisely release potent forces!"); |
667 | new_draw_info (NDI_UNIQUE, 0, op, "You unwisely release potent forces!"); |
713 | remove_contents (cauldron->inv, NULL); |
668 | remove_contents (cauldron->inv, NULL); |
714 | cast_magic_storm (op, tmp, level); |
669 | cast_magic_storm (op, tmp, level); |
715 | return; |
|
|
716 | } |
670 | } |
717 | } |
671 | } |
718 | |
672 | |
719 | |
673 | /* |
720 | /**
|
|
|
721 | * All but object "save_item" are elimentated from |
674 | * All but object "save_item" are elimentated from |
722 | * the container list. Note we have to becareful to remove the inventories |
675 | * the container list. Note we have to becareful to remove the inventories |
723 | * of objects in the cauldron inventory (ex icecube has stuff in it). |
676 | * of objects in the cauldron inventory (ex icecube has stuff in it). |
724 | */ |
677 | */ |
725 | |
|
|
726 | void |
678 | void |
727 | remove_contents (object *first_ob, object *save_item) |
679 | remove_contents (object *first_ob, object *save_item) |
728 | { |
680 | { |
|
|
681 | // this cries for a cleaner rewrite, removing save_item first possibly |
729 | object *next, *tmp = first_ob; |
682 | object *next, *tmp = first_ob; |
730 | |
683 | |
731 | while (tmp) |
684 | while (tmp) |
732 | { |
685 | { |
733 | next = tmp->below; |
686 | next = tmp->below; |
|
|
687 | |
734 | if (tmp == save_item) |
688 | if (tmp == save_item) |
735 | { |
689 | { |
736 | if (!(tmp = next)) |
690 | if (!(tmp = next)) |
737 | break; |
691 | break; |
738 | else |
692 | else |
739 | next = next->below; |
693 | next = next->below; |
740 | } |
694 | } |
|
|
695 | |
741 | if (tmp->inv) |
696 | if (tmp->inv) |
742 | remove_contents (tmp->inv, NULL); |
697 | remove_contents (tmp->inv, NULL); |
743 | remove_ob (tmp); |
698 | |
744 | free_object (tmp); |
699 | tmp->destroy (); |
745 | tmp = next; |
700 | tmp = next; |
746 | } |
701 | } |
747 | } |
702 | } |
748 | |
703 | |
749 | /**
|
704 | /** |
750 | *"Danger" level, will determine how bad the backfire |
705 | *"Danger" level, will determine how bad the backfire |
751 | * could be if the user fails to concoct a recipe properly. Factors include |
706 | * could be if the user fails to concoct a recipe properly. Factors include |
752 | * the number of ingredients, the length of the name of each ingredient, |
707 | * the number of ingredients, the length of the name of each ingredient, |
753 | * the user's effective level, the user's Int and the enchantment on the |
708 | * the user's effective level, the user's Int and the enchantment on the |
754 | * mixing device (aka "cauldron"). Higher values of 'danger' indicate more |
709 | * mixing device (aka "cauldron"). Higher values of 'danger' indicate more |
755 | * danger. Note that we assume that we have had the caster ready the alchemy |
710 | * danger. Note that we assume that we have had the caster ready the alchemy |
756 | * skill *before* this routine is called. (no longer auto-readies that skill) |
711 | * skill *before* this routine is called. (no longer auto-readies that skill) |
757 | * -b.t. |
712 | * -b.t. |
758 | */ |
713 | */ |
759 | |
|
|
760 | int |
714 | int |
761 | calc_alch_danger (object *caster, object *cauldron, recipe *rp) |
715 | calc_alch_danger (object *caster, object *cauldron, recipe *rp) |
762 | { |
716 | { |
763 | object *item; |
717 | object *item; |
764 | char name[MAX_BUF]; |
718 | char name[MAX_BUF]; |
765 | int danger = 0, nrofi = 0; |
719 | int danger = 0, nrofi = 0; |
766 | |
720 | |
767 | /* Knowing alchemy skill reduces yer risk */ |
721 | /* Knowing alchemy skill reduces yer risk */ |
768 | danger -= caster->chosen_skill ? caster->chosen_skill->level : caster->level; |
722 | danger -= caster->chosen_skill ? caster->chosen_skill->level : caster->level; |
|
|
723 | |
|
|
724 | if (!caster->chosen_skill) |
|
|
725 | LOG (llevError | logBacktrace, "calc_alch_danger called without a chosen skill, caster %s, cauldron %s\n", |
|
|
726 | caster->debug_desc (), cauldron->debug_desc ()); |
769 | |
727 | |
770 | /* better cauldrons reduce risk */ |
728 | /* better cauldrons reduce risk */ |
771 | danger -= cauldron->magic; |
729 | danger -= cauldron->magic; |
772 | |
730 | |
773 | /* Higher Int, lower the risk */ |
731 | /* Higher Int, lower the risk */ |
… | |
… | |
777 | * Thus the backfire is worse. Also, more ingredients |
735 | * Thus the backfire is worse. Also, more ingredients |
778 | * means we are attempting a more powerfull potion, |
736 | * means we are attempting a more powerfull potion, |
779 | * and thus the backfire will be worse. */ |
737 | * and thus the backfire will be worse. */ |
780 | for (item = cauldron->inv; item; item = item->below) |
738 | for (item = cauldron->inv; item; item = item->below) |
781 | { |
739 | { |
782 | strcpy (name, item->name); |
740 | assign (name, item->name); |
783 | if (item->title) |
741 | if (item->title) |
784 | sprintf (name, "%s %s", &item->name, &item->title); |
742 | sprintf (name, "%s %s", &item->name, &item->title); |
785 | danger += (strtoint (name) / 1000) + 3; |
743 | danger += (strtoint (name) / 1000) + 3; |
786 | nrofi++; |
744 | nrofi++; |
787 | } |
745 | } |
|
|
746 | |
788 | if (rp == NULL) |
747 | if (rp == NULL) |
789 | danger += 110; |
748 | danger += 110; |
790 | else |
749 | else |
791 | danger += rp->diff * 3; |
750 | danger += rp->diff * 3; |
792 | |
751 | |
… | |
… | |
801 | #endif |
760 | #endif |
802 | |
761 | |
803 | return danger; |
762 | return danger; |
804 | } |
763 | } |
805 | |
764 | |
806 | /**
|
765 | /** |
807 | * Determines if ingredients in a container match the |
766 | * Determines if ingredients in a container match the |
808 | * proper ingredients for a recipe. |
767 | * proper ingredients for a recipe. |
809 | * |
768 | * |
810 | * rp is the recipe to check |
769 | * rp is the recipe to check |
811 | * cauldron is the container that holds the ingredients |
770 | * cauldron is the container that holds the ingredients |
… | |
… | |
860 | for (ob = cauldron->inv; ob != NULL; ob = ob->below) |
819 | for (ob = cauldron->inv; ob != NULL; ob = ob->below) |
861 | { |
820 | { |
862 | char name_ob[MAX_BUF]; |
821 | char name_ob[MAX_BUF]; |
863 | const char *name2; |
822 | const char *name2; |
864 | |
823 | |
865 | if (ob->title == NULL) |
824 | if (!ob->title) |
866 | name2 = ob->name; |
825 | name2 = ob->name; |
867 | else |
826 | else |
868 | { |
827 | { |
869 | snprintf (name_ob, sizeof (name_ob), "%s %s", &ob->name, &ob->title); |
828 | snprintf (name_ob, sizeof (name_ob), "%s %s", &ob->name, &ob->title); |
870 | name2 = name_ob; |
829 | name2 = name_ob; |
… | |
… | |
915 | LOG (llevDebug, "looking for formula %d:\n", formula); |
874 | LOG (llevDebug, "looking for formula %d:\n", formula); |
916 | #endif |
875 | #endif |
917 | result = NULL; |
876 | result = NULL; |
918 | recipes_matching = 0; |
877 | recipes_matching = 0; |
919 | transmute_found = 0; |
878 | transmute_found = 0; |
|
|
879 | |
920 | for (rp = fl->items; rp != NULL; rp = rp->next) |
880 | for (rp = fl->items; rp; rp = rp->next) |
921 | { |
881 | { |
922 | /* check if recipe matches at all */ |
882 | /* check if recipe matches at all */ |
923 | if (formula % rp->index != 0) |
883 | if (formula % rp->index != 0) |
924 | { |
884 | { |
925 | #ifdef EXTREME_ALCHEMY_DEBUG |
885 | #ifdef EXTREME_ALCHEMY_DEBUG |