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 |
9 | * 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 |
… | |
… | |
127 | rp = find_recipe (fl, formula, cauldron->inv); |
127 | rp = find_recipe (fl, formula, cauldron->inv); |
128 | if (rp != NULL) |
128 | if (rp != NULL) |
129 | { |
129 | { |
130 | #ifdef ALCHEMY_DEBUG |
130 | #ifdef ALCHEMY_DEBUG |
131 | if (strcmp (rp->title, "NONE")) |
131 | if (strcmp (rp->title, "NONE")) |
132 | LOG (llevDebug, "WIZ got formula: %s of %s\n", rp->arch_name[0], rp->title); |
132 | LOG (llevDebug, "WIZ got formula: %s of %s\n", rp->arch_name[0], &rp->title); |
133 | else |
133 | else |
134 | LOG (llevDebug, "WIZ got formula: %s (nbatches:%d)\n", rp->arch_name[0], formula / rp->index); |
134 | LOG (llevDebug, "WIZ got formula: %s (nbatches:%d)\n", rp->arch_name[0], formula / rp->index); |
135 | #endif |
135 | #endif |
136 | attempt_recipe (caster, cauldron, ability, rp, formula / rp->index); |
136 | attempt_recipe (caster, cauldron, ability, rp, formula / rp->index); |
137 | } |
137 | } |
… | |
… | |
252 | number++; |
252 | number++; |
253 | o_number++; |
253 | o_number++; |
254 | tmp = tmp->below; |
254 | tmp = tmp->below; |
255 | } |
255 | } |
256 | #ifdef ALCHEMY_DEBUG |
256 | #ifdef ALCHEMY_DEBUG |
257 | LOG (llevDebug, "numb_ob_inside(%s): found %d ingredients\n", op->name, o_number); |
257 | LOG (llevDebug, "numb_ob_inside(%s): found %d ingredients\n", &op->name, o_number); |
258 | #endif |
258 | #endif |
259 | return o_number; |
259 | return o_number; |
260 | } |
260 | } |
261 | |
261 | |
262 | /** |
262 | /** |
… | |
… | |
303 | } |
303 | } |
304 | } |
304 | } |
305 | |
305 | |
306 | #ifdef EXTREME_ALCHEMY_DEBUG |
306 | #ifdef EXTREME_ALCHEMY_DEBUG |
307 | LOG (llevDebug, "attempt_recipe(): got %d nbatches\n", nbatches); |
307 | LOG (llevDebug, "attempt_recipe(): got %d nbatches\n", nbatches); |
308 | LOG (llevDebug, "attempt_recipe(): using recipe %s\n", rp->title ? rp->title : "unknown"); |
308 | LOG (llevDebug, "attempt_recipe(): using recipe %s\n", *rp->title ? &rp->title : "unknown"); |
309 | #endif |
309 | #endif |
310 | |
310 | |
311 | if ((item = make_item_from_recipe (cauldron, rp)) != NULL) |
311 | if ((item = make_item_from_recipe (cauldron, rp)) != NULL) |
312 | { |
312 | { |
313 | remove_contents (cauldron->inv, item); |
313 | remove_contents (cauldron->inv, item); |
… | |
… | |
416 | * @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; |
417 | * set to zero if not using a transmution formula |
417 | * set to zero if not using a transmution formula |
418 | */ |
418 | */ |
419 | |
419 | |
420 | object * |
420 | object * |
421 | 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) |
422 | { |
422 | { |
423 | object *item = NULL; |
423 | object *prod_item = 0; |
424 | |
424 | bool found = false; |
425 | *rp_arch_index = 0; |
425 | *rp_arch_index = 0; |
426 | |
426 | |
427 | if (rp->transmute) /* look for matching ingredient/prod archs */ |
427 | if (rp->transmute) /* look for matching ingredient/prod archs */ |
428 | for (item = first_ingred; item; item = item->below) |
428 | for (object *item = first_ingred; item; item = item->below) |
429 | { |
429 | { |
430 | int i; |
|
|
431 | |
|
|
432 | for (int i = 0; i < rp->arch_names; i++) |
430 | for (int i = 0; i < rp->arch_names; i++) |
433 | //TODO: should be a shstr comparison |
431 | //TODO: should be a shstr comparison |
434 | if (&item->arch->archname == rp->arch_name[i]) |
432 | if (!strcmp(&item->arch->archname,rp->arch_name[i])) |
435 | { |
433 | { |
436 | *rp_arch_index = i; |
434 | *rp_arch_index = i; |
|
|
435 | prod_item = item; |
437 | break; |
436 | break; |
438 | } |
437 | } |
439 | |
438 | |
440 | if (i < rp->arch_names) |
439 | if (prod_item) |
441 | break; |
440 | break; |
442 | } |
441 | } |
443 | |
442 | |
444 | /* 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 |
445 | * allow players to create massive amounts of artifacts easily */ |
444 | * allow players to create massive amounts of artifacts easily */ |
446 | if (create_item && (!item || item->nrof > 1)) |
445 | if (create_item && (!prod_item || prod_item->nrof > 1)) |
|
|
446 | { |
|
|
447 | #ifdef ALCHEMY_DEBUG |
|
|
448 | LOG (llevDebug, "creating a new item.\n"); |
|
|
449 | if (prod_item != NULL) |
447 | { |
450 | { |
|
|
451 | LOG (llevDebug, " had item: arch %s(nrof:%d)\n", |
|
|
452 | &prod_item->arch->archname, prod_item->nrof); |
|
|
453 | } |
|
|
454 | #endif |
|
|
455 | if (!prod_item) |
448 | *rp_arch_index = rndm (rp->arch_names); |
456 | *rp_arch_index = rndm (rp->arch_names); |
449 | item = get_archetype (rp->arch_name[*rp_arch_index]); |
457 | prod_item = get_archetype (rp->arch_name[*rp_arch_index]); |
450 | } |
458 | } |
451 | |
459 | |
452 | #ifdef ALCHEMY_DEBUG |
460 | #ifdef ALCHEMY_DEBUG |
453 | LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no "); |
461 | LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no "); |
454 | if (item != NULL) |
462 | if (prod_item != NULL) |
455 | { |
463 | { |
456 | LOG (llevDebug, " find_transmutable_ob(): returns arch %s(sp:%d)\n", item->arch->name, item->stats.sp); |
464 | LOG (llevDebug, " find_transmutable_ob(): returns arch %s(sp:%d)\n", |
|
|
465 | &prod_item->arch->archname, prod_item->stats.sp); |
457 | } |
466 | } |
458 | #endif |
467 | #endif |
459 | |
468 | |
460 | return item; |
469 | return prod_item; |
461 | } |
470 | } |
462 | |
471 | |
463 | |
472 | |
464 | /**
|
473 | /**
|
465 | * Ouch. We didnt get the formula we wanted. |
474 | * Ouch. We didnt get the formula we wanted. |
… | |
… | |
881 | { |
890 | { |
882 | /* check if recipe matches at all */ |
891 | /* check if recipe matches at all */ |
883 | if (formula % rp->index != 0) |
892 | if (formula % rp->index != 0) |
884 | { |
893 | { |
885 | #ifdef EXTREME_ALCHEMY_DEBUG |
894 | #ifdef EXTREME_ALCHEMY_DEBUG |
886 | LOG (llevDebug, " formula %s of %s (%d) does not match\n", rp->arch_name[0], rp->title, rp->index); |
895 | LOG (llevDebug, " formula %s of %s (%d) does not match\n", rp->arch_name[0], &rp->title, rp->index); |
887 | #endif |
896 | #endif |
888 | continue; |
897 | continue; |
889 | } |
898 | } |
890 | |
899 | |
891 | if (rp->transmute && find_transmution_ob (ingredients, rp, &rp_arch_index, 0) != NULL) |
900 | if (rp->transmute && find_transmution_ob (ingredients, rp, &rp_arch_index, 0) != NULL) |
892 | { |
901 | { |
893 | #ifdef EXTREME_ALCHEMY_DEBUG |
902 | #ifdef EXTREME_ALCHEMY_DEBUG |
894 | LOG (llevDebug, " formula %s of %s (%d) is a matching transmuting formula\n", rp->arch_name[rp_arch_index], rp->title, rp->index); |
903 | LOG (llevDebug, " formula %s of %s (%d) is a matching transmuting formula\n", rp->arch_name[rp_arch_index], &rp->title, rp->index); |
895 | #endif |
904 | #endif |
896 | /* transmution recipe with matching base ingredient */ |
905 | /* transmution recipe with matching base ingredient */ |
897 | if (!transmute_found) |
906 | if (!transmute_found) |
898 | { |
907 | { |
899 | transmute_found = 1; |
908 | transmute_found = 1; |
… | |
… | |
901 | } |
910 | } |
902 | } |
911 | } |
903 | else if (transmute_found) |
912 | else if (transmute_found) |
904 | { |
913 | { |
905 | #ifdef EXTREME_ALCHEMY_DEBUG |
914 | #ifdef EXTREME_ALCHEMY_DEBUG |
906 | LOG (llevDebug, " formula %s of %s (%d) matches but is not a matching transmuting formula\n", rp->arch_name[0], rp->title, |
915 | LOG (llevDebug, " formula %s of %s (%d) matches but is not a matching transmuting formula\n", rp->arch_name[0], &rp->title, |
907 | rp->index); |
916 | rp->index); |
908 | #endif |
917 | #endif |
909 | /* "normal" recipe found after previous transmution recipe => ignore this recipe */ |
918 | /* "normal" recipe found after previous transmution recipe => ignore this recipe */ |
910 | continue; |
919 | continue; |
911 | } |
920 | } |
912 | #ifdef EXTREME_ALCHEMY_DEBUG |
921 | #ifdef EXTREME_ALCHEMY_DEBUG |
913 | else |
922 | else |
914 | { |
923 | { |
915 | LOG (llevDebug, " formula %s of %s (%d) matches\n", rp->arch_name[0], rp->title, rp->index); |
924 | LOG (llevDebug, " formula %s of %s (%d) matches\n", rp->arch_name[0], &rp->title, rp->index); |
916 | } |
925 | } |
917 | #endif |
926 | #endif |
918 | |
927 | |
919 | if (rndm (0, recipes_matching) == 0) |
928 | if (rndm (0, recipes_matching) == 0) |
920 | result = rp; |
929 | result = rp; |
… | |
… | |
930 | return NULL; |
939 | return NULL; |
931 | } |
940 | } |
932 | |
941 | |
933 | #ifdef ALCHEMY_DEBUG |
942 | #ifdef ALCHEMY_DEBUG |
934 | if (strcmp (result->title, "NONE") != 0) |
943 | if (strcmp (result->title, "NONE") != 0) |
935 | LOG (llevDebug, "got formula: %s of %s (nbatches:%d)\n", result->arch_name[0], result->title, formula / result->index); |
944 | LOG (llevDebug, "got formula: %s of %s (nbatches:%d)\n", result->arch_name[0], &result->title, formula / result->index); |
936 | else |
945 | else |
937 | LOG (llevDebug, "got formula: %s (nbatches:%d)\n", result->arch_name[0], formula / result->index); |
946 | LOG (llevDebug, "got formula: %s (nbatches:%d)\n", result->arch_name[0], formula / result->index); |
938 | #endif |
947 | #endif |
939 | return result; |
948 | return result; |
940 | } |
949 | } |