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 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * it under the terms of the GNU General Public License as published by |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your 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 GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * and the GNU General Public License along with this program. If not, see |
|
|
20 | * <http://www.gnu.org/licenses/>. |
20 | * |
21 | * |
21 | * 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> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | /* March 96 - Laid down original code. -b.t. thomas@astro.psu.edu */ |
25 | /* March 96 - Laid down original code. -b.t. thomas@astro.psu.edu */ |
… | |
… | |
94 | * around. :) |
95 | * around. :) |
95 | * -b.t. |
96 | * -b.t. |
96 | */ |
97 | */ |
97 | |
98 | |
98 | void |
99 | void |
99 | attempt_do_alchemy (object *caster, object *cauldron) |
100 | attempt_do_alchemy (object *caster, object *cauldron, object *skill) |
100 | { |
101 | { |
101 | recipelist *fl; |
102 | recipelist *fl; |
102 | recipe *rp = NULL; |
103 | recipe *rp = NULL; |
103 | float success_chance; |
104 | float success_chance; |
104 | int numb, ability = 1; |
105 | int numb, ability = 1; |
… | |
… | |
127 | rp = find_recipe (fl, formula, cauldron->inv); |
128 | rp = find_recipe (fl, formula, cauldron->inv); |
128 | if (rp != NULL) |
129 | if (rp != NULL) |
129 | { |
130 | { |
130 | #ifdef ALCHEMY_DEBUG |
131 | #ifdef ALCHEMY_DEBUG |
131 | if (strcmp (rp->title, "NONE")) |
132 | if (strcmp (rp->title, "NONE")) |
132 | LOG (llevDebug, "WIZ got formula: %s of %s\n", rp->arch_name[0], rp->title); |
133 | LOG (llevDebug, "WIZ got formula: %s of %s\n", rp->arch_name[0], &rp->title); |
133 | else |
134 | else |
134 | LOG (llevDebug, "WIZ got formula: %s (nbatches:%d)\n", rp->arch_name[0], formula / rp->index); |
135 | LOG (llevDebug, "WIZ got formula: %s (nbatches:%d)\n", rp->arch_name[0], formula / rp->index); |
135 | #endif |
136 | #endif |
136 | attempt_recipe (caster, cauldron, ability, rp, formula / rp->index); |
137 | attempt_recipe (caster, cauldron, ability, rp, formula / rp->index); |
137 | } |
138 | } |
… | |
… | |
140 | return; |
141 | return; |
141 | } /* End of WIZ alchemy */ |
142 | } /* End of WIZ alchemy */ |
142 | |
143 | |
143 | /* find the recipe */ |
144 | /* find the recipe */ |
144 | rp = find_recipe (fl, formula, cauldron->inv); |
145 | rp = find_recipe (fl, formula, cauldron->inv); |
145 | if (rp) |
146 | if (rp |
|
|
147 | && rp->skill == skill->skill |
|
|
148 | && (!rp->cauldron |
|
|
149 | || rp->cauldron == cauldron->arch->archname)) |
146 | { |
150 | { |
147 | uint64 value_ingredients; |
151 | uint64 value_ingredients; |
148 | uint64 value_item; |
152 | uint64 value_item; |
149 | object *tmp; |
153 | object *tmp; |
150 | int attempt_shadow_alchemy; |
154 | int attempt_shadow_alchemy; |
151 | |
155 | |
152 | ave_chance = fl->total_chance / (float) fl->number; |
156 | ave_chance = fl->total_chance / (float) fl->number; |
153 | /* the caster gets an increase in ability based on thier skill lvl */ |
157 | |
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)); |
158 | 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 | |
159 | |
174 | /* determine value of ingredients */ |
160 | /* determine value of ingredients */ |
175 | value_ingredients = 0; |
161 | value_ingredients = 0; |
176 | for (tmp = cauldron->inv; tmp != NULL; tmp = tmp->below) |
162 | for (tmp = cauldron->inv; tmp != NULL; tmp = tmp->below) |
177 | value_ingredients += query_cost (tmp, NULL, F_TRUE); |
163 | value_ingredients += query_cost (tmp, NULL, F_TRUE); |
… | |
… | |
267 | number++; |
253 | number++; |
268 | o_number++; |
254 | o_number++; |
269 | tmp = tmp->below; |
255 | tmp = tmp->below; |
270 | } |
256 | } |
271 | #ifdef ALCHEMY_DEBUG |
257 | #ifdef ALCHEMY_DEBUG |
272 | LOG (llevDebug, "numb_ob_inside(%s): found %d ingredients\n", op->name, o_number); |
258 | LOG (llevDebug, "numb_ob_inside(%s): found %d ingredients\n", &op->name, o_number); |
273 | #endif |
259 | #endif |
274 | return o_number; |
260 | return o_number; |
275 | } |
261 | } |
276 | |
262 | |
277 | /** |
263 | /** |
… | |
… | |
289 | object *item = NULL, *skop; |
275 | object *item = NULL, *skop; |
290 | |
276 | |
291 | /* this should be passed to this fctn, not effiecent cpu use this way */ |
277 | /* this should be passed to this fctn, not effiecent cpu use this way */ |
292 | int batches = abs (nbatches); |
278 | int batches = abs (nbatches); |
293 | |
279 | |
294 | |
|
|
295 | /* is the cauldron the right type? */ |
280 | /* is the cauldron the right type? */ |
296 | if (rp->cauldron != cauldron->arch->archname) |
281 | if (rp->cauldron && rp->cauldron != cauldron->arch->archname) |
297 | { |
|
|
298 | new_draw_info (NDI_UNIQUE, 0, caster, "You are not using the proper" " facilities for this formula."); |
|
|
299 | return 0; |
282 | return 0; |
300 | } |
|
|
301 | |
283 | |
302 | skop = find_skill_by_name (caster, rp->skill); |
284 | skop = find_skill_by_name (caster, rp->skill); |
303 | /* does the caster have the skill? */ |
285 | /* does the caster have the skill? */ |
304 | if (!skop) |
286 | if (!skop) |
305 | return 0; |
287 | return 0; |
… | |
… | |
322 | } |
304 | } |
323 | } |
305 | } |
324 | |
306 | |
325 | #ifdef EXTREME_ALCHEMY_DEBUG |
307 | #ifdef EXTREME_ALCHEMY_DEBUG |
326 | LOG (llevDebug, "attempt_recipe(): got %d nbatches\n", nbatches); |
308 | LOG (llevDebug, "attempt_recipe(): got %d nbatches\n", nbatches); |
327 | LOG (llevDebug, "attempt_recipe(): using recipe %s\n", rp->title ? rp->title : "unknown"); |
309 | LOG (llevDebug, "attempt_recipe(): using recipe %s\n", *rp->title ? &rp->title : "unknown"); |
328 | #endif |
310 | #endif |
329 | |
311 | |
330 | if ((item = make_item_from_recipe (cauldron, rp)) != NULL) |
312 | if ((item = make_item_from_recipe (cauldron, rp)) != NULL) |
331 | { |
313 | { |
332 | remove_contents (cauldron->inv, item); |
314 | remove_contents (cauldron->inv, item); |
… | |
… | |
403 | LOG (llevDebug, "make_alchemy_item(): failed to create alchemical object.\n"); |
385 | LOG (llevDebug, "make_alchemy_item(): failed to create alchemical object.\n"); |
404 | return (object *) NULL; |
386 | return (object *) NULL; |
405 | } |
387 | } |
406 | |
388 | |
407 | /* Find the appropriate artifact template... */ |
389 | /* Find the appropriate artifact template... */ |
408 | if (strcmp (rp->title, "NONE")) |
390 | if (rp->title != shstr_NONE) |
409 | { |
391 | { |
410 | if ((art = locate_recipe_artifact (rp, rp_arch_index)) == NULL) |
392 | if ((art = locate_recipe_artifact (rp, rp_arch_index)) == NULL) |
411 | { |
393 | { |
412 | LOG (llevError, "make_alchemy_item(): failed to locate recipe artifact.\n"); |
394 | LOG (llevError, "make_alchemy_item(): failed to locate recipe artifact.\n"); |
413 | LOG (llevDebug, " --requested recipe: %s of %s.\n", rp->arch_name[0], &rp->title); |
395 | LOG (llevDebug, " --requested recipe: %s of %s.\n", rp->arch_name[0], &rp->title); |
414 | return (object *) NULL; |
396 | return (object *) NULL; |
415 | } |
397 | } |
|
|
398 | |
416 | transmute_materialname (item, art->item); |
399 | transmute_materialname (item, art->item); |
417 | give_artifact_abilities (item, art->item); |
400 | give_artifact_abilities (item, art->item); |
418 | } |
401 | } |
419 | |
402 | |
420 | if (QUERY_FLAG (cauldron, FLAG_CURSED)) |
403 | if (QUERY_FLAG (cauldron, FLAG_CURSED)) |
… | |
… | |
434 | * @param rp_arch_index pointer to return value; set to arch index for recipe; |
417 | * @param rp_arch_index pointer to return value; set to arch index for recipe; |
435 | * set to zero if not using a transmution formula |
418 | * set to zero if not using a transmution formula |
436 | */ |
419 | */ |
437 | |
420 | |
438 | object * |
421 | object * |
439 | find_transmution_ob (object *first_ingred, recipe *rp, size_t * rp_arch_index, int create_item) |
422 | find_transmution_ob (object *first_ingred, recipe *rp, size_t *rp_arch_index, int create_item) |
440 | { |
423 | { |
441 | object *item = NULL; |
424 | object *prod_item = 0; |
442 | |
425 | bool found = false; |
443 | *rp_arch_index = 0; |
426 | *rp_arch_index = 0; |
444 | |
427 | |
445 | if (rp->transmute) /* look for matching ingredient/prod archs */ |
428 | if (rp->transmute) /* look for matching ingredient/prod archs */ |
446 | for (item = first_ingred; item; item = item->below) |
429 | for (object *item = first_ingred; item; item = item->below) |
447 | { |
430 | { |
448 | size_t i; |
|
|
449 | |
|
|
450 | for (i = 0; i < rp->arch_names; i++) |
431 | for (int i = 0; i < rp->arch_names; i++) |
451 | { |
432 | //TODO: should be a shstr comparison |
452 | if (item->arch->archname == rp->arch_name[i]) |
433 | if (!strcmp(&item->arch->archname,rp->arch_name[i])) |
453 | { |
434 | { |
454 | *rp_arch_index = i; |
435 | *rp_arch_index = i; |
|
|
436 | prod_item = item; |
455 | break; |
437 | break; |
456 | } |
438 | } |
457 | } |
|
|
458 | |
439 | |
459 | if (i < rp->arch_names) |
440 | if (prod_item) |
460 | break; |
441 | break; |
461 | } |
442 | } |
462 | |
443 | |
463 | /* 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 |
464 | * allow players to create massive amounts of artifacts easily */ |
445 | * allow players to create massive amounts of artifacts easily */ |
465 | if (create_item && (!item || item->nrof > 1)) |
446 | if (create_item && (!prod_item || prod_item->nrof > 1)) |
|
|
447 | { |
|
|
448 | #ifdef ALCHEMY_DEBUG |
|
|
449 | LOG (llevDebug, "creating a new item.\n"); |
|
|
450 | if (prod_item != NULL) |
466 | { |
451 | { |
|
|
452 | LOG (llevDebug, " had item: arch %s(nrof:%d)\n", |
|
|
453 | &prod_item->arch->archname, prod_item->nrof); |
|
|
454 | } |
|
|
455 | #endif |
|
|
456 | if (!prod_item) |
467 | *rp_arch_index = RANDOM () % rp->arch_names; |
457 | *rp_arch_index = rndm (rp->arch_names); |
468 | item = get_archetype (rp->arch_name[*rp_arch_index]); |
458 | prod_item = get_archetype (rp->arch_name[*rp_arch_index]); |
469 | } |
459 | } |
470 | |
460 | |
471 | #ifdef ALCHEMY_DEBUG |
461 | #ifdef ALCHEMY_DEBUG |
472 | LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no "); |
462 | LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no "); |
473 | if (item != NULL) |
463 | if (prod_item != NULL) |
474 | { |
464 | { |
475 | LOG (llevDebug, " find_transmutable_ob(): returns arch %s(sp:%d)\n", item->arch->name, item->stats.sp); |
465 | LOG (llevDebug, " find_transmutable_ob(): returns arch %s(sp:%d)\n", |
|
|
466 | &prod_item->arch->archname, prod_item->stats.sp); |
476 | } |
467 | } |
477 | #endif |
468 | #endif |
478 | |
469 | |
479 | return item; |
470 | return prod_item; |
480 | } |
471 | } |
481 | |
472 | |
482 | |
473 | |
483 | /**
|
474 | /**
|
484 | * Ouch. We didnt get the formula we wanted. |
475 | * Ouch. We didnt get the formula we wanted. |
… | |
… | |
615 | { /* MAJOR FIRE */ |
606 | { /* MAJOR FIRE */ |
616 | object *fb = get_archetype (SP_MED_FIREBALL); |
607 | object *fb = get_archetype (SP_MED_FIREBALL); |
617 | |
608 | |
618 | remove_contents (cauldron->inv, NULL); |
609 | remove_contents (cauldron->inv, NULL); |
619 | fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb); |
610 | fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb); |
620 | fb->destroy (true); |
611 | fb->destroy (); |
621 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); |
612 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); |
622 | } |
613 | } |
623 | else if (level < 100) |
614 | else if (level < 100) |
624 | { /* WHAMMY the CAULDRON */ |
615 | { /* WHAMMY the CAULDRON */ |
625 | if (!QUERY_FLAG (cauldron, FLAG_CURSED)) |
616 | if (!QUERY_FLAG (cauldron, FLAG_CURSED)) |
… | |
… | |
666 | * in this one, we allow *any* valid alchemy artifact |
657 | * in this one, we allow *any* valid alchemy artifact |
667 | * to be made (rather than only those on the given |
658 | * to be made (rather than only those on the given |
668 | * formulalist) */ |
659 | * formulalist) */ |
669 | if (!rp) |
660 | if (!rp) |
670 | rp = get_random_recipe ((recipelist *) NULL); |
661 | rp = get_random_recipe ((recipelist *) NULL); |
|
|
662 | |
671 | if (rp && (tmp = get_archetype (rp->arch_name[RANDOM () % rp->arch_names]))) |
663 | if (rp && (tmp = get_archetype (rp->arch_name [rndm (rp->arch_names)]))) |
672 | { |
664 | { |
673 | generate_artifact (tmp, random_roll (1, op->level / 2 + 1, op, PREFER_HIGH) + 1); |
665 | generate_artifact (tmp, random_roll (1, op->level / 2 + 1, op, PREFER_HIGH) + 1); |
674 | if ((tmp = insert_ob_in_ob (tmp, cauldron))) |
666 | if ((tmp = insert_ob_in_ob (tmp, cauldron))) |
675 | { |
667 | { |
676 | remove_contents (cauldron->inv, tmp); |
668 | remove_contents (cauldron->inv, tmp); |
… | |
… | |
712 | } |
704 | } |
713 | |
705 | |
714 | if (tmp->inv) |
706 | if (tmp->inv) |
715 | remove_contents (tmp->inv, NULL); |
707 | remove_contents (tmp->inv, NULL); |
716 | |
708 | |
717 | tmp->destroy (true); |
709 | tmp->destroy (); |
718 | tmp = next; |
710 | tmp = next; |
719 | } |
711 | } |
720 | } |
712 | } |
721 | |
713 | |
722 | /** |
714 | /** |
… | |
… | |
837 | for (ob = cauldron->inv; ob != NULL; ob = ob->below) |
829 | for (ob = cauldron->inv; ob != NULL; ob = ob->below) |
838 | { |
830 | { |
839 | char name_ob[MAX_BUF]; |
831 | char name_ob[MAX_BUF]; |
840 | const char *name2; |
832 | const char *name2; |
841 | |
833 | |
842 | if (ob->title == NULL) |
834 | if (!ob->title) |
843 | name2 = ob->name; |
835 | name2 = ob->name; |
844 | else |
836 | else |
845 | { |
837 | { |
846 | snprintf (name_ob, sizeof (name_ob), "%s %s", &ob->name, &ob->title); |
838 | snprintf (name_ob, sizeof (name_ob), "%s %s", &ob->name, &ob->title); |
847 | name2 = name_ob; |
839 | name2 = name_ob; |
… | |
… | |
899 | { |
891 | { |
900 | /* check if recipe matches at all */ |
892 | /* check if recipe matches at all */ |
901 | if (formula % rp->index != 0) |
893 | if (formula % rp->index != 0) |
902 | { |
894 | { |
903 | #ifdef EXTREME_ALCHEMY_DEBUG |
895 | #ifdef EXTREME_ALCHEMY_DEBUG |
904 | LOG (llevDebug, " formula %s of %s (%d) does not match\n", rp->arch_name[0], rp->title, rp->index); |
896 | LOG (llevDebug, " formula %s of %s (%d) does not match\n", rp->arch_name[0], &rp->title, rp->index); |
905 | #endif |
897 | #endif |
906 | continue; |
898 | continue; |
907 | } |
899 | } |
908 | |
900 | |
909 | if (rp->transmute && find_transmution_ob (ingredients, rp, &rp_arch_index, 0) != NULL) |
901 | if (rp->transmute && find_transmution_ob (ingredients, rp, &rp_arch_index, 0) != NULL) |
910 | { |
902 | { |
911 | #ifdef EXTREME_ALCHEMY_DEBUG |
903 | #ifdef EXTREME_ALCHEMY_DEBUG |
912 | LOG (llevDebug, " formula %s of %s (%d) is a matching transmuting formula\n", rp->arch_name[rp_arch_index], rp->title, rp->index); |
904 | LOG (llevDebug, " formula %s of %s (%d) is a matching transmuting formula\n", rp->arch_name[rp_arch_index], &rp->title, rp->index); |
913 | #endif |
905 | #endif |
914 | /* transmution recipe with matching base ingredient */ |
906 | /* transmution recipe with matching base ingredient */ |
915 | if (!transmute_found) |
907 | if (!transmute_found) |
916 | { |
908 | { |
917 | transmute_found = 1; |
909 | transmute_found = 1; |
… | |
… | |
919 | } |
911 | } |
920 | } |
912 | } |
921 | else if (transmute_found) |
913 | else if (transmute_found) |
922 | { |
914 | { |
923 | #ifdef EXTREME_ALCHEMY_DEBUG |
915 | #ifdef EXTREME_ALCHEMY_DEBUG |
924 | LOG (llevDebug, " formula %s of %s (%d) matches but is not a matching transmuting formula\n", rp->arch_name[0], rp->title, |
916 | LOG (llevDebug, " formula %s of %s (%d) matches but is not a matching transmuting formula\n", rp->arch_name[0], &rp->title, |
925 | rp->index); |
917 | rp->index); |
926 | #endif |
918 | #endif |
927 | /* "normal" recipe found after previous transmution recipe => ignore this recipe */ |
919 | /* "normal" recipe found after previous transmution recipe => ignore this recipe */ |
928 | continue; |
920 | continue; |
929 | } |
921 | } |
930 | #ifdef EXTREME_ALCHEMY_DEBUG |
922 | #ifdef EXTREME_ALCHEMY_DEBUG |
931 | else |
923 | else |
932 | { |
924 | { |
933 | LOG (llevDebug, " formula %s of %s (%d) matches\n", rp->arch_name[0], rp->title, rp->index); |
925 | LOG (llevDebug, " formula %s of %s (%d) matches\n", rp->arch_name[0], &rp->title, rp->index); |
934 | } |
926 | } |
935 | #endif |
927 | #endif |
936 | |
928 | |
937 | if (rndm (0, recipes_matching) == 0) |
929 | if (rndm (0, recipes_matching) == 0) |
938 | result = rp; |
930 | result = rp; |
… | |
… | |
948 | return NULL; |
940 | return NULL; |
949 | } |
941 | } |
950 | |
942 | |
951 | #ifdef ALCHEMY_DEBUG |
943 | #ifdef ALCHEMY_DEBUG |
952 | if (strcmp (result->title, "NONE") != 0) |
944 | if (strcmp (result->title, "NONE") != 0) |
953 | LOG (llevDebug, "got formula: %s of %s (nbatches:%d)\n", result->arch_name[0], result->title, formula / result->index); |
945 | LOG (llevDebug, "got formula: %s of %s (nbatches:%d)\n", result->arch_name[0], &result->title, formula / result->index); |
954 | else |
946 | else |
955 | LOG (llevDebug, "got formula: %s (nbatches:%d)\n", result->arch_name[0], formula / result->index); |
947 | LOG (llevDebug, "got formula: %s (nbatches:%d)\n", result->arch_name[0], formula / result->index); |
956 | #endif |
948 | #endif |
957 | return result; |
949 | return result; |
958 | } |
950 | } |