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 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 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. |
… | |
… | |
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 | |
63 | |
64 | /** Returns a random selection from cauldron_effect[] */ |
64 | /** Returns a random selection from cauldron_effect[] */ |
65 | static const char * |
65 | static const char * |
66 | cauldron_sound (void) |
66 | cauldron_sound () |
67 | { |
67 | { |
68 | int size = sizeof (cauldron_effect) / sizeof (char *); |
68 | return cauldron_effect [rndm (array_length (cauldron_effect))]; |
69 | |
|
|
70 | return cauldron_effect[rndm (0, size - 1)]; |
|
|
71 | } |
69 | } |
72 | |
70 | |
73 | /** |
71 | /** |
74 | * Recipe value of the entire contents of a container. |
72 | * Recipe value of the entire contents of a container. |
75 | * This appears to just generate a hash value, which I guess for now works |
73 | * This appears to just generate a hash value, which I guess for now works |
76 | * ok, but the possibility of duplicate hashes is certainly possible - msw |
74 | * ok, but the possibility of duplicate hashes is certainly possible - msw |
77 | */ |
75 | */ |
78 | static int |
76 | static int |
79 | content_recipe_value (object *op) |
77 | content_recipe_value (object *op) |
80 | { |
78 | { |
81 | char name[MAX_BUF]; |
|
|
82 | object *tmp = op->inv; |
79 | object *tmp = op->inv; |
83 | int tval = 0, formula = 0; |
80 | int formula = 0; |
84 | |
81 | |
85 | while (tmp) |
82 | while (tmp) |
86 | { |
83 | { |
87 | tval = 0; |
84 | const char *name = tmp->title |
88 | assign (name, tmp->name); |
|
|
89 | if (tmp->title) |
|
|
90 | sprintf (name, "%s %s", &tmp->name, &tmp->title); |
85 | ? (const char *)format ("%s %s", &tmp->name, &tmp->title) |
|
|
86 | : tmp->name; |
|
|
87 | |
91 | tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1)); |
88 | int tval = strtoint (name) * tmp->number_of (); |
92 | #ifdef ALCHEMY_DEBUG |
89 | #ifdef ALCHEMY_DEBUG |
93 | LOG (llevDebug, "Got ingredient %d %s(%d)\n", tmp->nrof ? tmp->nrof : 1, name, tval); |
90 | LOG (llevDebug, "Got ingredient %d %s(%d)\n", tmp->nrof ? tmp->nrof : 1, name, tval); |
94 | #endif |
91 | #endif |
95 | formula += tval; |
92 | formula += tval; |
96 | tmp = tmp->below; |
93 | tmp = tmp->below; |
97 | } |
94 | } |
98 | #ifdef ALCHEMY_DEBUG |
95 | #ifdef ALCHEMY_DEBUG |
99 | LOG (llevDebug, " Formula value=%d\n", formula); |
96 | LOG (llevDebug, " Formula value=%d\n", formula); |
100 | #endif |
97 | #endif |
|
|
98 | |
101 | return formula; |
99 | return formula; |
102 | } |
100 | } |
103 | |
101 | |
104 | /** |
102 | /** |
105 | * Returns total number of items in op |
103 | * Returns total number of items in op |
… | |
… | |
223 | |
221 | |
224 | transmute_materialname (item, art->item); |
222 | transmute_materialname (item, art->item); |
225 | give_artifact_abilities (item, art->item); |
223 | give_artifact_abilities (item, art->item); |
226 | } |
224 | } |
227 | |
225 | |
228 | if (QUERY_FLAG (cauldron, FLAG_CURSED)) |
226 | if (cauldron->flag [FLAG_CURSED]) |
229 | SET_FLAG (item, FLAG_CURSED); |
227 | item->set_flag (FLAG_CURSED); |
230 | if (QUERY_FLAG (cauldron, FLAG_DAMNED)) |
228 | if (cauldron->flag [FLAG_DAMNED]) |
231 | SET_FLAG (item, FLAG_DAMNED); |
229 | item->set_flag (FLAG_DAMNED); |
232 | |
230 | |
233 | return item; |
231 | return item; |
234 | } |
232 | } |
235 | |
233 | |
236 | /* |
234 | /* |
… | |
… | |
392 | int weight = 0; |
390 | int weight = 0; |
393 | |
391 | |
394 | tmp = get_archetype (shstr_rock); |
392 | tmp = get_archetype (shstr_rock); |
395 | tmp->weight = weight; |
393 | tmp->weight = weight; |
396 | tmp->value = 0; |
394 | tmp->value = 0; |
397 | tmp->materialname = shstr_stone; |
395 | tmp->material = name_to_material (shstr_stone); |
398 | tmp->name = shstr_slag; |
396 | tmp->name = shstr_slag; |
399 | tmp->name_pl = shstr_slags; |
397 | tmp->name_pl = shstr_slags; |
400 | item = insert_ob_in_ob (tmp, cauldron); |
398 | item = insert_ob_in_ob (tmp, cauldron); |
401 | CLEAR_FLAG (tmp, FLAG_CAN_ROLL); |
399 | tmp->clr_flag (FLAG_CAN_ROLL); |
402 | SET_FLAG (tmp, FLAG_NO_DROP); |
400 | tmp->set_flag (FLAG_NO_DROP); |
403 | tmp->move_block = 0; |
401 | tmp->move_block = 0; |
404 | } |
402 | } |
405 | |
403 | |
406 | remove_contents (cauldron->inv, item); |
404 | remove_contents (cauldron->inv, item); |
407 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); |
405 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); |
… | |
… | |
415 | if ((rp = get_random_recipe ((recipelist *) NULL)) == NULL) |
413 | if ((rp = get_random_recipe ((recipelist *) NULL)) == NULL) |
416 | return; |
414 | return; |
417 | |
415 | |
418 | if ((tmp = attempt_recipe (op, cauldron, 1, rp, -1))) |
416 | if ((tmp = attempt_recipe (op, cauldron, 1, rp, -1))) |
419 | { |
417 | { |
420 | if (!QUERY_FLAG (tmp, FLAG_CURSED)) /* curse it */ |
418 | if (!tmp->flag [FLAG_CURSED]) /* curse it */ |
421 | SET_FLAG (tmp, FLAG_CURSED); |
419 | tmp->set_flag (FLAG_CURSED); |
422 | |
420 | |
423 | /* the apply code for potions already deals with cursed |
421 | /* the apply code for potions already deals with cursed |
424 | * potions, so any code here is basically ignored. |
422 | * potions, so any code here is basically ignored. |
425 | */ |
423 | */ |
426 | if (tmp->type == FOOD) |
424 | if (tmp->type == FOOD) |
… | |
… | |
445 | int numb = numb_ob_inside (cauldron); |
443 | int numb = numb_ob_inside (cauldron); |
446 | |
444 | |
447 | fl = get_formulalist (numb - 1); /* take a lower recipe list */ |
445 | fl = get_formulalist (numb - 1); /* take a lower recipe list */ |
448 | if (fl && (rp = get_random_recipe (fl))) |
446 | if (fl && (rp = get_random_recipe (fl))) |
449 | /* even though random, don't grant user any EXP for it */ |
447 | /* even though random, don't grant user any EXP for it */ |
450 | (void) attempt_recipe (op, cauldron, 1, rp, -1); |
448 | attempt_recipe (op, cauldron, 1, rp, -1); |
451 | else |
449 | else |
452 | alchemy_failure_effect (op, cauldron, rp, level - 1); |
450 | alchemy_failure_effect (op, cauldron, rp, level - 1); |
453 | } |
451 | } |
454 | else if (level < 45) |
452 | else if (level < 45) |
455 | { /* INFURIATE NPC's */ |
453 | { /* INFURIATE NPC's */ |
… | |
… | |
498 | fb->destroy (); |
496 | fb->destroy (); |
499 | 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); |
500 | } |
498 | } |
501 | else if (level < 100) |
499 | else if (level < 100) |
502 | { /* WHAMMY the CAULDRON */ |
500 | { /* WHAMMY the CAULDRON */ |
503 | if (!QUERY_FLAG (cauldron, FLAG_CURSED)) |
501 | if (!cauldron->flag [FLAG_CURSED]) |
504 | SET_FLAG (cauldron, FLAG_CURSED); |
502 | cauldron->set_flag (FLAG_CURSED); |
505 | else |
503 | else |
506 | cauldron->magic--; |
504 | cauldron->magic--; |
507 | |
505 | |
508 | cauldron->magic -= random_roll (0, 4, op, PREFER_LOW); |
506 | cauldron->magic -= random_roll (0, 4, op, PREFER_LOW); |
509 | |
507 | |
… | |
… | |
576 | * 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 |
577 | * 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) |
578 | * -b.t. |
576 | * -b.t. |
579 | */ |
577 | */ |
580 | static int |
578 | static int |
581 | calc_alch_danger (object *caster, object *cauldron, recipe *rp) |
579 | calc_alch_danger (object *caster, object *cauldron, object *skill, recipe *rp) |
582 | { |
580 | { |
583 | object *item; |
|
|
584 | char name[MAX_BUF]; |
|
|
585 | int danger = 0, nrofi = 0; |
581 | int danger = 0; |
586 | |
582 | |
587 | /* Knowing alchemy skill reduces yer risk */ |
583 | /* Knowing alchemy skill reduces yer risk */ |
588 | danger -= caster->chosen_skill ? caster->chosen_skill->level : caster->level; |
584 | danger -= skill->level; |
589 | |
|
|
590 | if (!caster->chosen_skill) |
|
|
591 | LOG (llevError | logBacktrace, "calc_alch_danger called without a chosen skill, caster %s, cauldron %s\n", |
|
|
592 | caster->debug_desc (), cauldron->debug_desc ()); |
|
|
593 | |
585 | |
594 | /* better cauldrons reduce risk */ |
586 | /* better cauldrons reduce risk */ |
595 | danger -= cauldron->magic; |
587 | danger -= cauldron->magic; |
596 | |
588 | |
597 | /* Higher Int, lower the risk */ |
589 | /* Higher Int, lower the risk */ |
… | |
… | |
599 | |
591 | |
600 | /* Ingredients. Longer names usually mean rarer stuff. |
592 | /* Ingredients. Longer names usually mean rarer stuff. |
601 | * Thus the backfire is worse. Also, more ingredients |
593 | * Thus the backfire is worse. Also, more ingredients |
602 | * means we are attempting a more powerfull potion, |
594 | * means we are attempting a more powerfull potion, |
603 | * and thus the backfire will be worse. */ |
595 | * and thus the backfire will be worse. */ |
604 | for (item = cauldron->inv; item; item = item->below) |
596 | for (object *item = cauldron->inv; item; item = item->below) |
605 | { |
597 | { |
606 | assign (name, item->name); |
598 | const char *name = item->title |
607 | if (item->title) |
|
|
608 | sprintf (name, "%s %s", &item->name, &item->title); |
599 | ? format ("%s %s", &item->name, &item->title) |
|
|
600 | : &item->name; |
|
|
601 | |
609 | danger += (strtoint (name) / 1000) + 3; |
602 | danger += strtoint (name) / 1000 + 3; |
610 | nrofi++; |
|
|
611 | } |
603 | } |
612 | |
604 | |
613 | if (rp == NULL) |
605 | if (!rp) |
614 | danger += 110; |
606 | danger += 110; |
615 | else |
607 | else |
616 | danger += rp->diff * 3; |
608 | danger += rp->diff * 3; |
617 | |
609 | |
618 | /* Using a bad device is *majorly* stupid */ |
610 | /* Using a bad device is *majorly* stupid */ |
619 | if (QUERY_FLAG (cauldron, FLAG_CURSED)) |
611 | if (cauldron->flag [FLAG_CURSED]) danger += 80; |
620 | danger += 80; |
612 | if (cauldron->flag [FLAG_DAMNED]) danger += 200; |
621 | if (QUERY_FLAG (cauldron, FLAG_DAMNED)) |
|
|
622 | danger += 200; |
|
|
623 | |
613 | |
624 | #ifdef ALCHEMY_DEBUG |
614 | #ifdef ALCHEMY_DEBUG |
625 | LOG (llevDebug, "calc_alch_danger() returned danger=%d\n", danger); |
615 | LOG (llevDebug, "calc_alch_danger() returned danger=%d\n", danger); |
626 | #endif |
616 | #endif |
627 | |
617 | |
… | |
… | |
853 | return; |
843 | return; |
854 | |
844 | |
855 | numb = numb_ob_inside (cauldron); |
845 | numb = numb_ob_inside (cauldron); |
856 | if ((fl = get_formulalist (numb))) |
846 | if ((fl = get_formulalist (numb))) |
857 | { |
847 | { |
858 | if (QUERY_FLAG (caster, FLAG_WIZ)) |
848 | if (caster->flag [FLAG_WIZ]) |
859 | { |
849 | { |
860 | rp = find_recipe (fl, formula, cauldron->inv); |
850 | rp = find_recipe (fl, formula, cauldron->inv); |
861 | if (rp != NULL) |
851 | if (rp != NULL) |
862 | { |
852 | { |
863 | #ifdef ALCHEMY_DEBUG |
853 | #ifdef ALCHEMY_DEBUG |
… | |
… | |
885 | object *tmp; |
875 | object *tmp; |
886 | int attempt_shadow_alchemy; |
876 | int attempt_shadow_alchemy; |
887 | |
877 | |
888 | ave_chance = fl->total_chance / (float)fl->number; |
878 | ave_chance = fl->total_chance / (float)fl->number; |
889 | |
879 | |
890 | ability += (int) (skill->level * ((4.0 + cauldron->magic) / 4.0)); |
880 | ability += skill->level * ((4.0 + cauldron->magic) / 4.0); |
891 | |
881 | |
892 | /* determine value of ingredients */ |
882 | /* determine value of ingredients */ |
893 | value_ingredients = 0; |
883 | value_ingredients = 0; |
894 | for (tmp = cauldron->inv; tmp; tmp = tmp->below) |
884 | for (tmp = cauldron->inv; tmp; tmp = tmp->below) |
895 | value_ingredients += query_cost (tmp, NULL, F_TRUE); |
885 | value_ingredients += query_cost (tmp, NULL, F_TRUE); |
… | |
… | |
916 | "Forcing failure for shadow alchemy recipe because price of ingredients (%llu) is less than price of result (%llu).\n", |
906 | "Forcing failure for shadow alchemy recipe because price of ingredients (%llu) is less than price of result (%llu).\n", |
917 | value_ingredients, value_item); |
907 | value_ingredients, value_item); |
918 | #endif |
908 | #endif |
919 | } |
909 | } |
920 | /* roll the dice */ |
910 | /* roll the dice */ |
921 | else if ((float) (random_roll (0, 101, caster, PREFER_LOW)) <= 100.0 * success_chance) |
911 | else if (random_roll (0, 101, caster, PREFER_LOW) <= 100.0 * success_chance) |
922 | { |
912 | { |
923 | change_exp (caster, rp->exp, rp->skill, SK_EXP_NONE); |
913 | change_exp (caster, rp->exp, rp->skill, SK_EXP_NONE); |
924 | |
914 | |
925 | // let alchemy consume some time, so that exploits are less easy |
915 | // let alchemy consume some time, so that exploits are less easy |
926 | caster->speed_left -= 1.0; |
916 | caster->speed_left -= 1.0; |
… | |
… | |
930 | } |
920 | } |
931 | } |
921 | } |
932 | } |
922 | } |
933 | |
923 | |
934 | /* if we get here, we failed!! */ |
924 | /* if we get here, we failed!! */ |
935 | 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)); |
936 | } |
926 | } |
937 | |
927 | |