1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * 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, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the Affero GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * and the GNU General Public License along with this program. If not, see |
19 | * and the GNU General Public License along with this program. If not, see |
20 | * <http://www.gnu.org/licenses/>. |
20 | * <http://www.gnu.org/licenses/>. |
21 | * |
21 | * |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | /* 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 */ |
26 | |
26 | |
… | |
… | |
133 | */ |
133 | */ |
134 | static object * |
134 | static object * |
135 | find_transmution_ob (object *first_ingred, recipe *rp, size_t *rp_arch_index, int create_item) |
135 | find_transmution_ob (object *first_ingred, recipe *rp, size_t *rp_arch_index, int create_item) |
136 | { |
136 | { |
137 | object *prod_item = 0; |
137 | object *prod_item = 0; |
138 | bool found = false; |
|
|
139 | *rp_arch_index = 0; |
138 | *rp_arch_index = 0; |
140 | |
139 | |
141 | if (rp->transmute) /* look for matching ingredient/prod archs */ |
140 | if (rp->transmute) /* look for matching ingredient/prod archs */ |
142 | for (object *item = first_ingred; item; item = item->below) |
141 | for (object *item = first_ingred; item; item = item->below) |
143 | { |
142 | { |
… | |
… | |
166 | &prod_item->arch->archname, prod_item->nrof); |
165 | &prod_item->arch->archname, prod_item->nrof); |
167 | } |
166 | } |
168 | #endif |
167 | #endif |
169 | if (!prod_item) |
168 | if (!prod_item) |
170 | *rp_arch_index = rndm (rp->arch_names); |
169 | *rp_arch_index = rndm (rp->arch_names); |
171 | prod_item = get_archetype (rp->arch_name[*rp_arch_index]); |
170 | prod_item = archetype::get (rp->arch_name[*rp_arch_index]); |
172 | } |
171 | } |
173 | |
172 | |
174 | #ifdef ALCHEMY_DEBUG |
173 | #ifdef ALCHEMY_DEBUG |
175 | LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no "); |
174 | LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no "); |
176 | if (prod_item != NULL) |
175 | if (prod_item != NULL) |
… | |
… | |
232 | } |
231 | } |
233 | |
232 | |
234 | /* |
233 | /* |
235 | * All but object "save_item" are elimentated from |
234 | * All but object "save_item" are elimentated from |
236 | * the container list. Note we have to becareful to remove the inventories |
235 | * the container list. Note we have to becareful to remove the inventories |
237 | * of objects in the cauldron inventory (ex icecube has stuff in it). |
236 | * of objects in the cauldron inventory (ex icecube has stuff in it). |
238 | */ |
237 | */ |
239 | static void |
238 | static void |
240 | remove_contents (object *first_ob, object *save_item) |
239 | remove_contents (object *first_ob, object *save_item) |
241 | { |
240 | { |
242 | // this cries for a cleaner rewrite, removing save_item first possibly |
241 | // this cries for a cleaner rewrite, removing save_item first possibly |
… | |
… | |
287 | item->nrof = nrof; |
286 | item->nrof = nrof; |
288 | } |
287 | } |
289 | } |
288 | } |
290 | |
289 | |
291 | /** |
290 | /** |
292 | * Essentially a wrapper for make_item_from_recipe() and |
291 | * Essentially a wrapper for make_item_from_recipe() and |
293 | * insert_ob_in_ob. If the caster has some alchemy skill, then they might |
292 | * insert_ob_in_ob. If the caster has some alchemy skill, then they might |
294 | * gain some exp from (successfull) fabrication of the product. |
293 | * gain some exp from (successfull) fabrication of the product. |
295 | * If nbatches==-1, don't give exp for this creation (random generation/ |
294 | * If nbatches==-1, don't give exp for this creation (random generation/ |
296 | * failed recipe) |
295 | * failed recipe) |
297 | */ |
296 | */ |
298 | static object * |
297 | static object * |
299 | attempt_recipe (object *caster, object *cauldron, int ability, recipe *rp, int nbatches) |
298 | attempt_recipe (object *caster, object *cauldron, int ability, recipe *rp, int nbatches) |
… | |
… | |
340 | { |
339 | { |
341 | remove_contents (cauldron->inv, item); |
340 | remove_contents (cauldron->inv, item); |
342 | /* Recalc carrying of the cauldron, in case recipe did not conserve mass */ |
341 | /* Recalc carrying of the cauldron, in case recipe did not conserve mass */ |
343 | cauldron->update_weight (); |
342 | cauldron->update_weight (); |
344 | /* adj lvl, nrof on caster level */ |
343 | /* adj lvl, nrof on caster level */ |
345 | adjust_product (item, ability, rp->yield ? (rp->yield * batches) : batches); |
344 | adjust_product (item, ability, rp->yield ? rp->yield * batches : batches); |
|
|
345 | |
346 | if (!item->env && (item = insert_ob_in_ob (item, cauldron)) == NULL) |
346 | if (!item->env && (item = insert_ob_in_ob (item, cauldron)) == NULL) |
347 | { |
347 | { |
348 | new_draw_info (NDI_UNIQUE, 0, caster, "Nothing happened."); |
348 | new_draw_info (NDI_UNIQUE, 0, caster, "Nothing happened."); |
349 | /* new_draw_info_format(NDI_UNIQUE, 0,caster, |
349 | /* new_draw_info_format(NDI_UNIQUE, 0,caster, |
350 | "Your spell causes the %s to explode!",&cauldron->name); */ |
350 | "Your spell causes the %s to explode!",&cauldron->name); */ |
… | |
… | |
387 | if (rndm (0, 2)) |
387 | if (rndm (0, 2)) |
388 | { /* slag created */ |
388 | { /* slag created */ |
389 | object *tmp = cauldron->inv; |
389 | object *tmp = cauldron->inv; |
390 | int weight = 0; |
390 | int weight = 0; |
391 | |
391 | |
392 | tmp = get_archetype (shstr_rock); |
392 | tmp = archetype::get (shstr_rock); |
393 | tmp->weight = weight; |
393 | tmp->weight = weight; |
394 | tmp->value = 0; |
394 | tmp->value = 0; |
395 | tmp->material = name_to_material (shstr_stone); |
395 | tmp->material = name_to_material (shstr_stone); |
396 | tmp->name = shstr_slag; |
396 | tmp->name = shstr_slag; |
397 | tmp->name_pl = shstr_slags; |
397 | tmp->name_pl = shstr_slags; |
… | |
… | |
464 | |
464 | |
465 | remove_contents (cauldron->inv, NULL); |
465 | remove_contents (cauldron->inv, NULL); |
466 | switch (rndm (0, 2)) |
466 | switch (rndm (0, 2)) |
467 | { |
467 | { |
468 | case 0: |
468 | case 0: |
469 | tmp = get_archetype (shstr_bomb); |
469 | tmp = archetype::get (shstr_bomb); |
470 | tmp->stats.dam = random_roll (1, level, op, PREFER_LOW); |
470 | tmp->stats.dam = random_roll (1, level, op, PREFER_LOW); |
471 | tmp->stats.hp = random_roll (1, level, op, PREFER_LOW); |
471 | tmp->stats.hp = random_roll (1, level, op, PREFER_LOW); |
472 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s creates a bomb!", &cauldron->name); |
472 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s creates a bomb!", &cauldron->name); |
473 | break; |
473 | break; |
474 | |
474 | |
475 | default: |
475 | default: |
476 | tmp = get_archetype (shstr_fireball); |
476 | tmp = archetype::get (shstr_fireball); |
477 | tmp->stats.dam = random_roll (1, level, op, PREFER_LOW) / 5 + 1; |
477 | tmp->stats.dam = random_roll (1, level, op, PREFER_LOW) / 5 + 1; |
478 | tmp->stats.hp = random_roll (1, level, op, PREFER_LOW) / 10 + 2; |
478 | tmp->stats.hp = random_roll (1, level, op, PREFER_LOW) / 10 + 2; |
479 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); |
479 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); |
480 | break; |
480 | break; |
481 | } |
481 | } |
… | |
… | |
487 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); |
487 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); |
488 | remove_contents (cauldron->inv, NULL); |
488 | remove_contents (cauldron->inv, NULL); |
489 | } |
489 | } |
490 | else if (level < 80) |
490 | else if (level < 80) |
491 | { /* MAJOR FIRE */ |
491 | { /* MAJOR FIRE */ |
492 | object *fb = get_archetype (SP_MED_FIREBALL); |
492 | object *fb = archetype::get (SP_MED_FIREBALL); |
493 | |
493 | |
494 | remove_contents (cauldron->inv, NULL); |
494 | remove_contents (cauldron->inv, NULL); |
495 | fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb); |
495 | fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb); |
496 | fb->destroy (); |
496 | fb->destroy (); |
497 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); |
497 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); |
… | |
… | |
536 | } |
536 | } |
537 | else if (level == 151) |
537 | else if (level == 151) |
538 | { /* CREATE RANDOM ARTIFACT */ |
538 | { /* CREATE RANDOM ARTIFACT */ |
539 | object *tmp; |
539 | object *tmp; |
540 | |
540 | |
541 | /* this is meant to be better than prior possiblity, |
541 | /* this is meant to be better than prior possiblity, |
542 | * in this one, we allow *any* valid alchemy artifact |
542 | * in this one, we allow *any* valid alchemy artifact |
543 | * to be made (rather than only those on the given |
543 | * to be made (rather than only those on the given |
544 | * formulalist) */ |
544 | * formulalist) */ |
545 | if (!rp) |
545 | if (!rp) |
546 | rp = get_random_recipe ((recipelist *) NULL); |
546 | rp = get_random_recipe ((recipelist *) NULL); |
547 | |
547 | |
548 | if (rp && (tmp = get_archetype (rp->arch_name [rndm (rp->arch_names)]))) |
548 | if (rp && (tmp = archetype::get (rp->arch_name [rndm (rp->arch_names)]))) |
549 | { |
549 | { |
550 | generate_artifact (tmp, random_roll (1, op->level / 2 + 1, op, PREFER_HIGH) + 1); |
550 | generate_artifact (tmp, random_roll (1, op->level / 2 + 1, op, PREFER_HIGH) + 1); |
551 | if ((tmp = insert_ob_in_ob (tmp, cauldron))) |
551 | if ((tmp = insert_ob_in_ob (tmp, cauldron))) |
552 | { |
552 | { |
553 | remove_contents (cauldron->inv, tmp); |
553 | remove_contents (cauldron->inv, tmp); |
… | |
… | |
555 | } |
555 | } |
556 | } |
556 | } |
557 | } |
557 | } |
558 | else |
558 | else |
559 | { /* MANA STORM - watch out!! */ |
559 | { /* MANA STORM - watch out!! */ |
560 | object *tmp = get_archetype (LOOSE_MANA); |
560 | object *tmp = archetype::get (LOOSE_MANA); |
561 | |
561 | |
562 | new_draw_info (NDI_UNIQUE, 0, op, "You unwisely release potent forces!"); |
562 | new_draw_info (NDI_UNIQUE, 0, op, "You unwisely release potent forces!"); |
563 | remove_contents (cauldron->inv, NULL); |
563 | remove_contents (cauldron->inv, NULL); |
564 | cast_magic_storm (op, tmp, level); |
564 | cast_magic_storm (op, tmp, level); |
565 | } |
565 | } |
… | |
… | |
570 | * could be if the user fails to concoct a recipe properly. Factors include |
570 | * could be if the user fails to concoct a recipe properly. Factors include |
571 | * the number of ingredients, the length of the name of each ingredient, |
571 | * the number of ingredients, the length of the name of each ingredient, |
572 | * the user's effective level, the user's Int and the enchantment on the |
572 | * the user's effective level, the user's Int and the enchantment on the |
573 | * mixing device (aka "cauldron"). Higher values of 'danger' indicate more |
573 | * mixing device (aka "cauldron"). Higher values of 'danger' indicate more |
574 | * danger. Note that we assume that we have had the caster ready the alchemy |
574 | * danger. Note that we assume that we have had the caster ready the alchemy |
575 | * skill *before* this routine is called. (no longer auto-readies that skill) |
575 | * skill *before* this routine is called. (no longer auto-readies that skill) |
576 | * -b.t. |
576 | * -b.t. |
577 | */ |
577 | */ |
578 | static int |
578 | static int |
579 | calc_alch_danger (object *caster, object *cauldron, recipe *rp) |
579 | calc_alch_danger (object *caster, object *cauldron, object *skill, recipe *rp) |
580 | { |
580 | { |
581 | object *item; |
|
|
582 | char name[MAX_BUF]; |
|
|
583 | int danger = 0, nrofi = 0; |
581 | int danger = 0; |
584 | |
582 | |
585 | /* Knowing alchemy skill reduces yer risk */ |
583 | /* Knowing alchemy skill reduces yer risk */ |
586 | danger -= caster->chosen_skill ? caster->chosen_skill->level : caster->level; |
584 | danger -= skill->level; |
587 | |
|
|
588 | if (!caster->chosen_skill) |
|
|
589 | LOG (llevError | logBacktrace, "calc_alch_danger called without a chosen skill, caster %s, cauldron %s\n", |
|
|
590 | caster->debug_desc (), cauldron->debug_desc ()); |
|
|
591 | |
585 | |
592 | /* better cauldrons reduce risk */ |
586 | /* better cauldrons reduce risk */ |
593 | danger -= cauldron->magic; |
587 | danger -= cauldron->magic; |
594 | |
588 | |
595 | /* Higher Int, lower the risk */ |
589 | /* Higher Int, lower the risk */ |
… | |
… | |
597 | |
591 | |
598 | /* Ingredients. Longer names usually mean rarer stuff. |
592 | /* Ingredients. Longer names usually mean rarer stuff. |
599 | * Thus the backfire is worse. Also, more ingredients |
593 | * Thus the backfire is worse. Also, more ingredients |
600 | * means we are attempting a more powerfull potion, |
594 | * means we are attempting a more powerfull potion, |
601 | * and thus the backfire will be worse. */ |
595 | * and thus the backfire will be worse. */ |
602 | for (item = cauldron->inv; item; item = item->below) |
596 | for (object *item = cauldron->inv; item; item = item->below) |
603 | { |
597 | { |
604 | assign (name, item->name); |
598 | const char *name = item->title |
605 | if (item->title) |
|
|
606 | sprintf (name, "%s %s", &item->name, &item->title); |
599 | ? format ("%s %s", &item->name, &item->title) |
|
|
600 | : &item->name; |
|
|
601 | |
607 | danger += (strtoint (name) / 1000) + 3; |
602 | danger += strtoint (name) / 1000 + 3; |
608 | nrofi++; |
|
|
609 | } |
603 | } |
610 | |
604 | |
611 | if (rp == NULL) |
605 | if (!rp) |
612 | danger += 110; |
606 | danger += 110; |
613 | else |
607 | else |
614 | danger += rp->diff * 3; |
608 | danger += rp->diff * 3; |
615 | |
609 | |
616 | /* Using a bad device is *majorly* stupid */ |
610 | /* Using a bad device is *majorly* stupid */ |
617 | if (cauldron->flag [FLAG_CURSED]) |
611 | if (cauldron->flag [FLAG_CURSED]) danger += 80; |
618 | danger += 80; |
|
|
619 | if (cauldron->flag [FLAG_DAMNED]) |
612 | if (cauldron->flag [FLAG_DAMNED]) danger += 200; |
620 | danger += 200; |
|
|
621 | |
613 | |
622 | #ifdef ALCHEMY_DEBUG |
614 | #ifdef ALCHEMY_DEBUG |
623 | LOG (llevDebug, "calc_alch_danger() returned danger=%d\n", danger); |
615 | LOG (llevDebug, "calc_alch_danger() returned danger=%d\n", danger); |
624 | #endif |
616 | #endif |
625 | |
617 | |
… | |
… | |
803 | return result; |
795 | return result; |
804 | } |
796 | } |
805 | |
797 | |
806 | /** |
798 | /** |
807 | * Main part of the ALCHEMY code. From this we call fctns |
799 | * Main part of the ALCHEMY code. From this we call fctns |
808 | * that take a look at the contents of the 'cauldron' and, using these ingredients, |
800 | * that take a look at the contents of the 'cauldron' and, using these ingredients, |
809 | * we construct an integer formula value which is referenced (randomly) against a |
801 | * we construct an integer formula value which is referenced (randomly) against a |
810 | * formula list (the formula list chosen is based on the # contents of the cauldron). |
802 | * formula list (the formula list chosen is based on the # contents of the cauldron). |
811 | * |
803 | * |
812 | * If we get a match between the recipe indicated in cauldron contents and a |
804 | * If we get a match between the recipe indicated in cauldron contents and a |
813 | * randomly chosen one, an item is created and experience awarded. Otherwise |
805 | * randomly chosen one, an item is created and experience awarded. Otherwise |
814 | * various failure effects are possible (getting worse and worse w/ # cauldron |
806 | * various failure effects are possible (getting worse and worse w/ # cauldron |
815 | * ingredients). Note that the 'item' to be made can be *anything* listed on |
807 | * ingredients). Note that the 'item' to be made can be *anything* listed on |
816 | * the artifacts list in lib/artifacts which has a recipe listed in lib/formulae. |
808 | * the artifacts list in lib/artifacts which has a recipe listed in lib/formulae. |
817 | * |
809 | * |
818 | * To those wondering why I am using the funky formula index method: |
810 | * To those wondering why I am using the funky formula index method: |
819 | * 1) I want to match recipe to ingredients regardless of ordering. |
811 | * 1) I want to match recipe to ingredients regardless of ordering. |
820 | * 2) I want a fast search for the 'right' recipe. |
812 | * 2) I want a fast search for the 'right' recipe. |
821 | * |
813 | * |
822 | * Note: it is just possible that a totally different combination of |
814 | * Note: it is just possible that a totally different combination of |
823 | * ingredients will result in a match with a given recipe. This is not a bug! |
815 | * ingredients will result in a match with a given recipe. This is not a bug! |
824 | * There is no good reason (in my mind) why alchemical processes have to be |
816 | * There is no good reason (in my mind) why alchemical processes have to be |
825 | * unique -- such a 'feature' is one reason why players might want to experiment |
817 | * unique -- such a 'feature' is one reason why players might want to experiment |
826 | * around. :) |
818 | * around. :) |
… | |
… | |
833 | recipe *rp = NULL; |
825 | recipe *rp = NULL; |
834 | float success_chance; |
826 | float success_chance; |
835 | int numb, ability = 1; |
827 | int numb, ability = 1; |
836 | int formula = 0; |
828 | int formula = 0; |
837 | float ave_chance; |
829 | float ave_chance; |
838 | object *item, *skop; |
830 | object *item; |
839 | |
831 | |
840 | if (caster->type != PLAYER) |
832 | if (caster->type != PLAYER) |
841 | return; /* only players for now */ |
833 | return; /* only players for now */ |
842 | |
834 | |
843 | if (get_map_flags (caster->map, NULL, caster->x, caster->y, NULL, NULL) & P_SAFE) |
835 | if (get_map_flags (caster->map, NULL, caster->x, caster->y, NULL, NULL) & P_SAFE) |
… | |
… | |
896 | |
888 | |
897 | /* create the object **FIRST**, then decide whether to keep it. */ |
889 | /* create the object **FIRST**, then decide whether to keep it. */ |
898 | if ((item = attempt_recipe (caster, cauldron, ability, rp, formula / rp->index)) != NULL) |
890 | if ((item = attempt_recipe (caster, cauldron, ability, rp, formula / rp->index)) != NULL) |
899 | { |
891 | { |
900 | /* compute base chance of recipe success */ |
892 | /* compute base chance of recipe success */ |
901 | success_chance = ((float) ability / (float) (rp->diff * (item->level + 2))); |
893 | success_chance = ((float)ability / (float)(rp->diff * (item->level + 2))); |
902 | if (ave_chance == 0) |
894 | if (ave_chance == 0) |
903 | ave_chance = 1; |
895 | ave_chance = 1; |
904 | |
896 | |
905 | #ifdef ALCHEMY_DEBUG |
897 | #ifdef ALCHEMY_DEBUG |
906 | LOG (llevDebug, "percent success chance = %f ab%d / diff%d*lev%d\n", success_chance, ability, rp->diff, item->level); |
898 | LOG (llevDebug, "percent success chance = %f ab%d / diff%d*lev%d\n", success_chance, ability, rp->diff, item->level); |
… | |
… | |
928 | } |
920 | } |
929 | } |
921 | } |
930 | } |
922 | } |
931 | |
923 | |
932 | /* if we get here, we failed!! */ |
924 | /* if we get here, we failed!! */ |
933 | alchemy_failure_effect (caster, cauldron, rp, calc_alch_danger (caster, cauldron, rp)); |
925 | alchemy_failure_effect (caster, cauldron, rp, calc_alch_danger (caster, cauldron, skill, rp)); |
934 | } |
926 | } |
935 | |
927 | |