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 |
8 | 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 |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | (at your option) any later version. |
11 | * (at your 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 GNU General Public License |
18 | along with this program; if not, write to the Free Software |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * |
20 | |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
|
|
22 | */ |
22 | */ |
23 | |
23 | |
24 | /* 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 */ |
25 | |
25 | |
26 | #include <global.h> |
26 | #include <global.h> |
27 | #include <object.h> |
27 | #include <object.h> |
… | |
… | |
94 | * around. :) |
94 | * around. :) |
95 | * -b.t. |
95 | * -b.t. |
96 | */ |
96 | */ |
97 | |
97 | |
98 | void |
98 | void |
99 | attempt_do_alchemy (object *caster, object *cauldron) |
99 | attempt_do_alchemy (object *caster, object *cauldron, object *skill) |
100 | { |
100 | { |
101 | recipelist *fl; |
101 | recipelist *fl; |
102 | recipe *rp = NULL; |
102 | recipe *rp = NULL; |
103 | float success_chance; |
103 | float success_chance; |
104 | int numb, ability = 1; |
104 | int numb, ability = 1; |
… | |
… | |
140 | return; |
140 | return; |
141 | } /* End of WIZ alchemy */ |
141 | } /* End of WIZ alchemy */ |
142 | |
142 | |
143 | /* find the recipe */ |
143 | /* find the recipe */ |
144 | rp = find_recipe (fl, formula, cauldron->inv); |
144 | rp = find_recipe (fl, formula, cauldron->inv); |
145 | if (rp) |
145 | if (rp |
|
|
146 | && rp->skill == skill->skill |
|
|
147 | && (!rp->cauldron |
|
|
148 | || rp->cauldron == cauldron->arch->archname)) |
146 | { |
149 | { |
147 | uint64 value_ingredients; |
150 | uint64 value_ingredients; |
148 | uint64 value_item; |
151 | uint64 value_item; |
149 | object *tmp; |
152 | object *tmp; |
150 | int attempt_shadow_alchemy; |
153 | int attempt_shadow_alchemy; |
151 | |
154 | |
152 | ave_chance = fl->total_chance / (float) fl->number; |
155 | ave_chance = fl->total_chance / (float) fl->number; |
153 | /* the caster gets an increase in ability based on thier skill lvl */ |
156 | |
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)); |
157 | 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 | |
158 | |
174 | /* determine value of ingredients */ |
159 | /* determine value of ingredients */ |
175 | value_ingredients = 0; |
160 | value_ingredients = 0; |
176 | for (tmp = cauldron->inv; tmp != NULL; tmp = tmp->below) |
161 | for (tmp = cauldron->inv; tmp != NULL; tmp = tmp->below) |
177 | value_ingredients += query_cost (tmp, NULL, F_TRUE); |
162 | value_ingredients += query_cost (tmp, NULL, F_TRUE); |
… | |
… | |
231 | int tval = 0, formula = 0; |
216 | int tval = 0, formula = 0; |
232 | |
217 | |
233 | while (tmp) |
218 | while (tmp) |
234 | { |
219 | { |
235 | tval = 0; |
220 | tval = 0; |
236 | strcpy (name, tmp->name); |
221 | assign (name, tmp->name); |
237 | if (tmp->title) |
222 | if (tmp->title) |
238 | sprintf (name, "%s %s", &tmp->name, &tmp->title); |
223 | sprintf (name, "%s %s", &tmp->name, &tmp->title); |
239 | tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1)); |
224 | tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1)); |
240 | #ifdef ALCHEMY_DEBUG |
225 | #ifdef ALCHEMY_DEBUG |
241 | 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); |
… | |
… | |
289 | object *item = NULL, *skop; |
274 | object *item = NULL, *skop; |
290 | |
275 | |
291 | /* 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 */ |
292 | int batches = abs (nbatches); |
277 | int batches = abs (nbatches); |
293 | |
278 | |
294 | |
|
|
295 | LOG (llevDebug, "A %s <=> %s\n", &(rp->cauldron), &(cauldron->arch->name)); |
|
|
296 | /* is the cauldron the right type? */ |
279 | /* is the cauldron the right type? */ |
297 | if (strcmp (rp->cauldron, cauldron->arch->name) != 0) |
280 | 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; |
281 | return 0; |
301 | } |
|
|
302 | |
282 | |
303 | skop = find_skill_by_name (caster, rp->skill); |
283 | skop = find_skill_by_name (caster, rp->skill); |
304 | /* does the caster have the skill? */ |
284 | /* does the caster have the skill? */ |
305 | if (!skop) |
285 | if (!skop) |
306 | return 0; |
286 | return 0; |
… | |
… | |
308 | /* code required for this recipe, search the caster */ |
288 | /* code required for this recipe, search the caster */ |
309 | if (rp->keycode) |
289 | if (rp->keycode) |
310 | { |
290 | { |
311 | object *tmp; |
291 | object *tmp; |
312 | |
292 | |
313 | for (tmp = caster->inv; tmp != NULL; tmp = tmp->below) |
293 | for (tmp = caster->inv; tmp; tmp = tmp->below) |
314 | { |
294 | { |
315 | if (tmp->type == FORCE && tmp->slaying && !strcmp (rp->keycode, tmp->slaying)) |
295 | if (tmp->type == FORCE && tmp->slaying && rp->keycode == tmp->slaying) |
316 | break; |
296 | break; |
317 | } |
297 | } |
|
|
298 | |
318 | if (tmp == NULL) |
299 | if (!tmp) |
319 | { /* failure--no code found */ |
300 | { /* 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."); |
301 | 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; |
302 | return 0; |
322 | } |
303 | } |
323 | } |
304 | } |
324 | |
305 | |
325 | #ifdef EXTREME_ALCHEMY_DEBUG |
306 | #ifdef EXTREME_ALCHEMY_DEBUG |
… | |
… | |
329 | |
310 | |
330 | if ((item = make_item_from_recipe (cauldron, rp)) != NULL) |
311 | if ((item = make_item_from_recipe (cauldron, rp)) != NULL) |
331 | { |
312 | { |
332 | remove_contents (cauldron->inv, item); |
313 | remove_contents (cauldron->inv, item); |
333 | /* 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 */ |
334 | sum_weight (cauldron); |
315 | cauldron->update_weight (); |
335 | /* adj lvl, nrof on caster level */ |
316 | /* adj lvl, nrof on caster level */ |
336 | adjust_product (item, ability, rp->yield ? (rp->yield * batches) : batches); |
317 | adjust_product (item, ability, rp->yield ? (rp->yield * batches) : batches); |
337 | if (!item->env && (item = insert_ob_in_ob (item, cauldron)) == NULL) |
318 | if (!item->env && (item = insert_ob_in_ob (item, cauldron)) == NULL) |
338 | { |
319 | { |
339 | new_draw_info (NDI_UNIQUE, 0, caster, "Nothing happened."); |
320 | new_draw_info (NDI_UNIQUE, 0, caster, "Nothing happened."); |
340 | /* new_draw_info_format(NDI_UNIQUE, 0,caster, |
321 | /* new_draw_info_format(NDI_UNIQUE, 0,caster, |
341 | "Your spell causes the %s to explode!",&cauldron->name); */ |
322 | "Your spell causes the %s to explode!",&cauldron->name); */ |
342 | /* kaboom_cauldron(); */ |
323 | /* kaboom_cauldron(); */ |
343 | } |
324 | } |
344 | else |
325 | else |
345 | { |
|
|
346 | 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 ()); |
347 | } |
|
|
348 | } |
327 | } |
|
|
328 | |
349 | return item; |
329 | return item; |
350 | } |
330 | } |
351 | |
331 | |
352 | |
332 | |
353 | |
333 | |
354 | /**
|
334 | /** |
355 | * 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 |
356 | * 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.
|
357 | */ |
337 | */ |
358 |
void |
338 | void |
359 | adjust_product (object *item, int lvl, int yield) |
339 | adjust_product (object *item, int lvl, int yield) |
360 | { |
340 | { |
361 | int nrof = 1; |
341 | int nrof = 1; |
362 | |
342 | |
363 | if (!yield) |
343 | if (!yield) |
364 | yield = 1; |
344 | yield = 1; |
|
|
345 | |
365 | if (lvl <= 0) |
346 | if (lvl <= 0) |
366 | lvl = 1; /* lets avoid div by zero! */ |
347 | lvl = 1; /* lets avoid div by zero! */ |
|
|
348 | |
367 | if (item->nrof) |
349 | if (item->nrof) |
368 | { |
350 | { |
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); |
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 | |
370 | if (nrof > yield) |
353 | if (nrof > yield) |
371 | nrof = yield; |
354 | nrof = yield; |
|
|
355 | |
372 | item->nrof = nrof; |
356 | item->nrof = nrof; |
373 | } |
357 | } |
374 | } |
358 | } |
375 | |
359 | |
376 | |
360 | |
… | |
… | |
400 | LOG (llevDebug, "make_alchemy_item(): failed to create alchemical object.\n"); |
384 | LOG (llevDebug, "make_alchemy_item(): failed to create alchemical object.\n"); |
401 | return (object *) NULL; |
385 | return (object *) NULL; |
402 | } |
386 | } |
403 | |
387 | |
404 | /* Find the appropriate artifact template... */ |
388 | /* Find the appropriate artifact template... */ |
405 | if (strcmp (rp->title, "NONE")) |
389 | if (rp->title != shstr_NONE) |
406 | { |
390 | { |
407 | if ((art = locate_recipe_artifact (rp, rp_arch_index)) == NULL) |
391 | if ((art = locate_recipe_artifact (rp, rp_arch_index)) == NULL) |
408 | { |
392 | { |
409 | LOG (llevError, "make_alchemy_item(): failed to locate recipe artifact.\n"); |
393 | 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); |
394 | LOG (llevDebug, " --requested recipe: %s of %s.\n", rp->arch_name[0], &rp->title); |
411 | return (object *) NULL; |
395 | return (object *) NULL; |
412 | } |
396 | } |
|
|
397 | |
413 | transmute_materialname (item, art->item); |
398 | transmute_materialname (item, art->item); |
414 | give_artifact_abilities (item, art->item); |
399 | give_artifact_abilities (item, art->item); |
415 | } |
400 | } |
416 | |
401 | |
417 | if (QUERY_FLAG (cauldron, FLAG_CURSED)) |
402 | if (QUERY_FLAG (cauldron, FLAG_CURSED)) |
… | |
… | |
431 | * @param rp_arch_index pointer to return value; set to arch index for recipe; |
416 | * @param rp_arch_index pointer to return value; set to arch index for recipe; |
432 | * set to zero if not using a transmution formula |
417 | * set to zero if not using a transmution formula |
433 | */ |
418 | */ |
434 | |
419 | |
435 | object * |
420 | object * |
436 | find_transmution_ob (object *first_ingred, recipe *rp, size_t * rp_arch_index, int create_item) |
421 | find_transmution_ob (object *first_ingred, recipe *rp, size_t *rp_arch_index, int create_item) |
437 | { |
422 | { |
438 | object *item = NULL; |
423 | object *prod_item = 0; |
439 | |
424 | bool found = false; |
440 | *rp_arch_index = 0; |
425 | *rp_arch_index = 0; |
441 | |
426 | |
442 | if (rp->transmute) /* look for matching ingredient/prod archs */ |
427 | if (rp->transmute) /* look for matching ingredient/prod archs */ |
443 | for (item = first_ingred; item; item = item->below) |
428 | for (object *item = first_ingred; item; item = item->below) |
444 | { |
429 | { |
445 | size_t i; |
|
|
446 | |
|
|
447 | for (i = 0; i < rp->arch_names; i++) |
430 | for (int i = 0; i < rp->arch_names; i++) |
448 | { |
431 | //TODO: should be a shstr comparison |
449 | if (strcmp (item->arch->name, rp->arch_name[i]) == 0) |
432 | if (&item->arch->archname == rp->arch_name[i]) |
450 | { |
433 | { |
451 | *rp_arch_index = i; |
434 | *rp_arch_index = i; |
|
|
435 | prod_item = item; |
452 | break; |
436 | break; |
453 | } |
437 | } |
454 | } |
438 | |
455 | if (i < rp->arch_names) |
439 | if (prod_item) |
456 | break; |
440 | break; |
457 | } |
441 | } |
458 | |
442 | |
459 | /* failed, create a fresh object. Note no nrof>1 because that would |
443 | /* failed, create a fresh object. Note no nrof>1 because that would |
460 | * allow players to create massive amounts of artifacts easily */ |
444 | * allow players to create massive amounts of artifacts easily */ |
461 | if (create_item && (!item || item->nrof > 1)) |
445 | if (create_item && (!prod_item || prod_item->nrof > 1)) |
462 | { |
446 | { |
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->name, prod_item->stats.sp); |
472 | } |
457 | } |
473 | #endif |
458 | #endif |
474 | |
459 | |
475 | return item; |
460 | return prod_item; |
476 | } |
461 | } |
477 | |
462 | |
478 | |
463 | |
479 | /**
|
464 | /**
|
480 | * Ouch. We didnt get the formula we wanted. |
465 | * Ouch. We didnt get the formula we wanted. |
… | |
… | |
506 | |
491 | |
507 | if (rndm (0, 2)) |
492 | if (rndm (0, 2)) |
508 | { /* slag created */ |
493 | { /* slag created */ |
509 | object *tmp = cauldron->inv; |
494 | object *tmp = cauldron->inv; |
510 | int weight = 0; |
495 | int weight = 0; |
511 | uint16 material = M_STONE; |
|
|
512 | |
496 | |
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"); |
497 | tmp = get_archetype ("rock"); |
521 | tmp->weight = weight; |
498 | tmp->weight = weight; |
522 | tmp->value = 0; |
499 | tmp->value = 0; |
523 | tmp->material = material; |
|
|
524 | tmp->materialname = "stone"; |
500 | tmp->materialname = "stone"; |
525 | tmp->name = "slag"; |
501 | tmp->name = "slag"; |
526 | tmp->name_pl = "slags"; |
502 | tmp->name_pl = "slags"; |
527 | item = insert_ob_in_ob (tmp, cauldron); |
503 | item = insert_ob_in_ob (tmp, cauldron); |
528 | CLEAR_FLAG (tmp, FLAG_CAN_ROLL); |
504 | CLEAR_FLAG (tmp, FLAG_CAN_ROLL); |
529 | CLEAR_FLAG (tmp, FLAG_NO_PICK); |
505 | CLEAR_FLAG (tmp, FLAG_NO_PICK); |
530 | tmp->move_block = 0; |
506 | tmp->move_block = 0; |
531 | } |
507 | } |
|
|
508 | |
532 | remove_contents (cauldron->inv, item); |
509 | remove_contents (cauldron->inv, item); |
533 | 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 ()); |
534 | return; |
511 | return; |
535 | } |
512 | } |
536 | else if (level < 40) |
513 | else if (level < 40) |
… | |
… | |
562 | } |
539 | } |
563 | while (rndm (0, 2)); |
540 | while (rndm (0, 2)); |
564 | } |
541 | } |
565 | return; |
542 | return; |
566 | } |
543 | } |
|
|
544 | |
567 | if (level == 40) |
545 | if (level == 40) |
568 | { /* MAKE RANDOM RECIPE */ |
546 | { /* MAKE RANDOM RECIPE */ |
569 | recipelist *fl; |
547 | recipelist *fl; |
570 | int numb = numb_ob_inside (cauldron); |
548 | int numb = numb_ob_inside (cauldron); |
571 | |
549 | |
… | |
… | |
573 | if (fl && (rp = get_random_recipe (fl))) |
551 | if (fl && (rp = get_random_recipe (fl))) |
574 | /* even though random, don't grant user any EXP for it */ |
552 | /* even though random, don't grant user any EXP for it */ |
575 | (void) attempt_recipe (op, cauldron, 1, rp, -1); |
553 | (void) attempt_recipe (op, cauldron, 1, rp, -1); |
576 | else |
554 | else |
577 | alchemy_failure_effect (op, cauldron, rp, level - 1); |
555 | alchemy_failure_effect (op, cauldron, rp, level - 1); |
578 | return; |
|
|
579 | |
|
|
580 | } |
556 | } |
581 | else if (level < 45) |
557 | else if (level < 45) |
582 | { /* INFURIATE NPC's */ |
558 | { /* INFURIATE NPC's */ |
583 | /* this is kind of kludgy I know... */ |
559 | /* this is kind of kludgy I know... */ |
584 | cauldron->enemy = op; |
560 | cauldron->enemy = op; |
585 | npc_call_help (cauldron); |
561 | npc_call_help (cauldron); |
586 | cauldron->enemy = NULL; |
562 | cauldron->enemy = NULL; |
587 | |
563 | |
588 | alchemy_failure_effect (op, cauldron, rp, level - 5); |
564 | alchemy_failure_effect (op, cauldron, rp, level - 5); |
589 | return; |
|
|
590 | } |
565 | } |
591 | else if (level < 50) |
566 | else if (level < 50) |
592 | { /* MINOR EXPLOSION/FIREBALL */ |
567 | { /* MINOR EXPLOSION/FIREBALL */ |
593 | object *tmp; |
568 | object *tmp; |
594 | |
569 | |
… | |
… | |
608 | 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; |
609 | 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); |
610 | break; |
585 | break; |
611 | } |
586 | } |
612 | |
587 | |
613 | op->insert_at (cauldron); |
588 | tmp->insert_at (cauldron); |
614 | return; |
|
|
615 | |
|
|
616 | } |
589 | } |
617 | else if (level < 60) |
590 | else if (level < 60) |
618 | { /* CREATE MONSTER */ |
591 | { /* CREATE MONSTER */ |
619 | 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 ()); |
620 | remove_contents (cauldron->inv, NULL); |
593 | remove_contents (cauldron->inv, NULL); |
621 | return; |
|
|
622 | } |
594 | } |
623 | else if (level < 80) |
595 | else if (level < 80) |
624 | { /* MAJOR FIRE */ |
596 | { /* MAJOR FIRE */ |
625 | object *fb = get_archetype (SP_MED_FIREBALL); |
597 | object *fb = get_archetype (SP_MED_FIREBALL); |
626 | |
598 | |
627 | remove_contents (cauldron->inv, NULL); |
599 | remove_contents (cauldron->inv, NULL); |
628 | 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); |
629 | fb->destroy (); |
601 | fb->destroy (); |
630 | 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); |
631 | return; |
|
|
632 | |
|
|
633 | } |
603 | } |
634 | else if (level < 100) |
604 | else if (level < 100) |
635 | { /* WHAMMY the CAULDRON */ |
605 | { /* WHAMMY the CAULDRON */ |
636 | if (!QUERY_FLAG (cauldron, FLAG_CURSED)) |
606 | if (!QUERY_FLAG (cauldron, FLAG_CURSED)) |
637 | SET_FLAG (cauldron, FLAG_CURSED); |
607 | SET_FLAG (cauldron, FLAG_CURSED); |
638 | else |
608 | else |
639 | cauldron->magic--; |
609 | cauldron->magic--; |
|
|
610 | |
640 | cauldron->magic -= random_roll (0, 4, op, PREFER_LOW); |
611 | cauldron->magic -= random_roll (0, 4, op, PREFER_LOW); |
|
|
612 | |
641 | if (rndm (0, 1)) |
613 | if (rndm (0, 1)) |
642 | { |
614 | { |
643 | remove_contents (cauldron->inv, NULL); |
615 | 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); |
616 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s turns darker then makes a gulping sound!", &cauldron->name); |
645 | } |
617 | } |
646 | else |
618 | else |
647 | 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); |
648 | return; |
|
|
649 | |
|
|
650 | } |
620 | } |
651 | else if (level < 110) |
621 | else if (level < 110) |
652 | { /* SUMMON EVIL MONSTERS */ |
622 | { /* SUMMON EVIL MONSTERS */ |
653 | object *tmp = get_random_mon (level / 5); |
623 | object *tmp = get_random_mon (level / 5); |
654 | |
624 | |
655 | remove_contents (cauldron->inv, NULL); |
625 | remove_contents (cauldron->inv, NULL); |
|
|
626 | |
656 | if (!tmp) |
627 | if (!tmp) |
657 | alchemy_failure_effect (op, cauldron, rp, level); |
628 | alchemy_failure_effect (op, cauldron, rp, level); |
658 | 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)) |
659 | 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 ()); |
660 | return; |
|
|
661 | |
|
|
662 | } |
631 | } |
663 | else if (level < 150) |
632 | else if (level < 150) |
664 | { /* COMBO EFFECT */ |
633 | { /* COMBO EFFECT */ |
665 | int roll = rndm (1, 3); |
634 | int roll = rndm (1, 3); |
666 | |
635 | |
667 | while (roll) |
636 | while (roll) |
668 | { |
637 | { |
669 | alchemy_failure_effect (op, cauldron, rp, level - 39); |
638 | alchemy_failure_effect (op, cauldron, rp, level - 39); |
670 | roll--; |
639 | roll--; |
671 | } |
640 | } |
672 | return; |
|
|
673 | } |
641 | } |
674 | else if (level == 151) |
642 | else if (level == 151) |
675 | { /* CREATE RANDOM ARTIFACT */ |
643 | { /* CREATE RANDOM ARTIFACT */ |
676 | object *tmp; |
644 | object *tmp; |
677 | |
645 | |
… | |
… | |
679 | * in this one, we allow *any* valid alchemy artifact |
647 | * in this one, we allow *any* valid alchemy artifact |
680 | * to be made (rather than only those on the given |
648 | * to be made (rather than only those on the given |
681 | * formulalist) */ |
649 | * formulalist) */ |
682 | if (!rp) |
650 | if (!rp) |
683 | rp = get_random_recipe ((recipelist *) NULL); |
651 | rp = get_random_recipe ((recipelist *) NULL); |
|
|
652 | |
684 | 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)]))) |
685 | { |
654 | { |
686 | 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); |
687 | if ((tmp = insert_ob_in_ob (tmp, cauldron))) |
656 | if ((tmp = insert_ob_in_ob (tmp, cauldron))) |
688 | { |
657 | { |
689 | remove_contents (cauldron->inv, tmp); |
658 | remove_contents (cauldron->inv, tmp); |
690 | 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 ()); |
691 | } |
660 | } |
692 | } |
661 | } |
693 | return; |
|
|
694 | } |
662 | } |
695 | else |
663 | else |
696 | { /* MANA STORM - watch out!! */ |
664 | { /* MANA STORM - watch out!! */ |
697 | object *tmp = get_archetype (LOOSE_MANA); |
665 | object *tmp = get_archetype (LOOSE_MANA); |
698 | |
666 | |
699 | 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!"); |
700 | remove_contents (cauldron->inv, NULL); |
668 | remove_contents (cauldron->inv, NULL); |
701 | cast_magic_storm (op, tmp, level); |
669 | cast_magic_storm (op, tmp, level); |
702 | return; |
|
|
703 | } |
670 | } |
704 | } |
671 | } |
705 | |
|
|
706 | |
672 | |
707 | /* |
673 | /* |
708 | * All but object "save_item" are elimentated from |
674 | * All but object "save_item" are elimentated from |
709 | * 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 |
710 | * 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). |
711 | */ |
677 | */ |
712 | |
|
|
713 | void |
678 | void |
714 | remove_contents (object *first_ob, object *save_item) |
679 | remove_contents (object *first_ob, object *save_item) |
715 | { |
680 | { |
|
|
681 | // this cries for a cleaner rewrite, removing save_item first possibly |
716 | object *next, *tmp = first_ob; |
682 | object *next, *tmp = first_ob; |
717 | |
683 | |
718 | while (tmp) |
684 | while (tmp) |
719 | { |
685 | { |
720 | next = tmp->below; |
686 | next = tmp->below; |
… | |
… | |
733 | tmp->destroy (); |
699 | tmp->destroy (); |
734 | tmp = next; |
700 | tmp = next; |
735 | } |
701 | } |
736 | } |
702 | } |
737 | |
703 | |
738 | /**
|
704 | /** |
739 | *"Danger" level, will determine how bad the backfire |
705 | *"Danger" level, will determine how bad the backfire |
740 | * 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 |
741 | * 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, |
742 | * 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 |
743 | * mixing device (aka "cauldron"). Higher values of 'danger' indicate more |
709 | * 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 |
710 | * 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) |
711 | * skill *before* this routine is called. (no longer auto-readies that skill) |
746 | * -b.t. |
712 | * -b.t. |
747 | */ |
713 | */ |
748 | |
|
|
749 | int |
714 | int |
750 | calc_alch_danger (object *caster, object *cauldron, recipe *rp) |
715 | calc_alch_danger (object *caster, object *cauldron, recipe *rp) |
751 | { |
716 | { |
752 | object *item; |
717 | object *item; |
753 | char name[MAX_BUF]; |
718 | char name[MAX_BUF]; |
754 | int danger = 0, nrofi = 0; |
719 | int danger = 0, nrofi = 0; |
755 | |
720 | |
756 | /* Knowing alchemy skill reduces yer risk */ |
721 | /* Knowing alchemy skill reduces yer risk */ |
757 | 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 ()); |
758 | |
727 | |
759 | /* better cauldrons reduce risk */ |
728 | /* better cauldrons reduce risk */ |
760 | danger -= cauldron->magic; |
729 | danger -= cauldron->magic; |
761 | |
730 | |
762 | /* Higher Int, lower the risk */ |
731 | /* Higher Int, lower the risk */ |
… | |
… | |
766 | * Thus the backfire is worse. Also, more ingredients |
735 | * Thus the backfire is worse. Also, more ingredients |
767 | * means we are attempting a more powerfull potion, |
736 | * means we are attempting a more powerfull potion, |
768 | * and thus the backfire will be worse. */ |
737 | * and thus the backfire will be worse. */ |
769 | for (item = cauldron->inv; item; item = item->below) |
738 | for (item = cauldron->inv; item; item = item->below) |
770 | { |
739 | { |
771 | strcpy (name, item->name); |
740 | assign (name, item->name); |
772 | if (item->title) |
741 | if (item->title) |
773 | sprintf (name, "%s %s", &item->name, &item->title); |
742 | sprintf (name, "%s %s", &item->name, &item->title); |
774 | danger += (strtoint (name) / 1000) + 3; |
743 | danger += (strtoint (name) / 1000) + 3; |
775 | nrofi++; |
744 | nrofi++; |
776 | } |
745 | } |
|
|
746 | |
777 | if (rp == NULL) |
747 | if (rp == NULL) |
778 | danger += 110; |
748 | danger += 110; |
779 | else |
749 | else |
780 | danger += rp->diff * 3; |
750 | danger += rp->diff * 3; |
781 | |
751 | |
… | |
… | |
790 | #endif |
760 | #endif |
791 | |
761 | |
792 | return danger; |
762 | return danger; |
793 | } |
763 | } |
794 | |
764 | |
795 | /**
|
765 | /** |
796 | * Determines if ingredients in a container match the |
766 | * Determines if ingredients in a container match the |
797 | * proper ingredients for a recipe. |
767 | * proper ingredients for a recipe. |
798 | * |
768 | * |
799 | * rp is the recipe to check |
769 | * rp is the recipe to check |
800 | * cauldron is the container that holds the ingredients |
770 | * cauldron is the container that holds the ingredients |
… | |
… | |
849 | for (ob = cauldron->inv; ob != NULL; ob = ob->below) |
819 | for (ob = cauldron->inv; ob != NULL; ob = ob->below) |
850 | { |
820 | { |
851 | char name_ob[MAX_BUF]; |
821 | char name_ob[MAX_BUF]; |
852 | const char *name2; |
822 | const char *name2; |
853 | |
823 | |
854 | if (ob->title == NULL) |
824 | if (!ob->title) |
855 | name2 = ob->name; |
825 | name2 = ob->name; |
856 | else |
826 | else |
857 | { |
827 | { |
858 | 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); |
859 | name2 = name_ob; |
829 | name2 = name_ob; |
… | |
… | |
904 | LOG (llevDebug, "looking for formula %d:\n", formula); |
874 | LOG (llevDebug, "looking for formula %d:\n", formula); |
905 | #endif |
875 | #endif |
906 | result = NULL; |
876 | result = NULL; |
907 | recipes_matching = 0; |
877 | recipes_matching = 0; |
908 | transmute_found = 0; |
878 | transmute_found = 0; |
|
|
879 | |
909 | for (rp = fl->items; rp != NULL; rp = rp->next) |
880 | for (rp = fl->items; rp; rp = rp->next) |
910 | { |
881 | { |
911 | /* check if recipe matches at all */ |
882 | /* check if recipe matches at all */ |
912 | if (formula % rp->index != 0) |
883 | if (formula % rp->index != 0) |
913 | { |
884 | { |
914 | #ifdef EXTREME_ALCHEMY_DEBUG |
885 | #ifdef EXTREME_ALCHEMY_DEBUG |