ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/alchemy.C
(Generate patch)

Comparing deliantra/server/server/alchemy.C (file contents):
Revision 1.31 by root, Mon Sep 29 10:20:48 2008 UTC vs.
Revision 1.38 by sf-marcmagus, Fri Oct 9 22:46:39 2009 UTC

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
94 * around. :) 94 * around. :)
95 * -b.t. 95 * -b.t.
96 */ 96 */
97 97
98void 98void
99attempt_do_alchemy (object *caster, object *cauldron) 99attempt_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;
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 }
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);
267 number++; 252 number++;
268 o_number++; 253 o_number++;
269 tmp = tmp->below; 254 tmp = tmp->below;
270 } 255 }
271#ifdef ALCHEMY_DEBUG 256#ifdef ALCHEMY_DEBUG
272 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);
273#endif 258#endif
274 return o_number; 259 return o_number;
275} 260}
276 261
277/** 262/**
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 /* is the cauldron the right type? */ 279 /* is the cauldron the right type? */
296 if (rp->cauldron != cauldron->arch->archname) 280 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; 281 return 0;
300 }
301 282
302 skop = find_skill_by_name (caster, rp->skill); 283 skop = find_skill_by_name (caster, rp->skill);
303 /* does the caster have the skill? */ 284 /* does the caster have the skill? */
304 if (!skop) 285 if (!skop)
305 return 0; 286 return 0;
322 } 303 }
323 } 304 }
324 305
325#ifdef EXTREME_ALCHEMY_DEBUG 306#ifdef EXTREME_ALCHEMY_DEBUG
326 LOG (llevDebug, "attempt_recipe(): got %d nbatches\n", nbatches); 307 LOG (llevDebug, "attempt_recipe(): got %d nbatches\n", nbatches);
327 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");
328#endif 309#endif
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);
403 LOG (llevDebug, "make_alchemy_item(): failed to create alchemical object.\n"); 384 LOG (llevDebug, "make_alchemy_item(): failed to create alchemical object.\n");
404 return (object *) NULL; 385 return (object *) NULL;
405 } 386 }
406 387
407 /* Find the appropriate artifact template... */ 388 /* Find the appropriate artifact template... */
408 if (strcmp (rp->title, "NONE")) 389 if (rp->title != shstr_NONE)
409 { 390 {
410 if ((art = locate_recipe_artifact (rp, rp_arch_index)) == NULL) 391 if ((art = locate_recipe_artifact (rp, rp_arch_index)) == NULL)
411 { 392 {
412 LOG (llevError, "make_alchemy_item(): failed to locate recipe artifact.\n"); 393 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); 394 LOG (llevDebug, " --requested recipe: %s of %s.\n", rp->arch_name[0], &rp->title);
414 return (object *) NULL; 395 return (object *) NULL;
415 } 396 }
397
416 transmute_materialname (item, art->item); 398 transmute_materialname (item, art->item);
417 give_artifact_abilities (item, art->item); 399 give_artifact_abilities (item, art->item);
418 } 400 }
419 401
420 if (QUERY_FLAG (cauldron, FLAG_CURSED)) 402 if (QUERY_FLAG (cauldron, FLAG_CURSED))
434 * @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;
435 * set to zero if not using a transmution formula 417 * set to zero if not using a transmution formula
436 */ 418 */
437 419
438object * 420object *
439find_transmution_ob (object *first_ingred, recipe *rp, size_t * rp_arch_index, int create_item) 421find_transmution_ob (object *first_ingred, recipe *rp, size_t *rp_arch_index, int create_item)
440{ 422{
441 object *item = NULL; 423 object *prod_item = 0;
442 424 bool found = false;
443 *rp_arch_index = 0; 425 *rp_arch_index = 0;
444 426
445 if (rp->transmute) /* look for matching ingredient/prod archs */ 427 if (rp->transmute) /* look for matching ingredient/prod archs */
446 for (item = first_ingred; item; item = item->below) 428 for (object *item = first_ingred; item; item = item->below)
447 { 429 {
448 size_t i;
449
450 for (i = 0; i < rp->arch_names; i++) 430 for (int i = 0; i < rp->arch_names; i++)
451 { 431 //TODO: should be a shstr comparison
452 if (item->arch->archname == rp->arch_name[i]) 432 if (&item->arch->archname == rp->arch_name[i])
453 { 433 {
454 *rp_arch_index = i; 434 *rp_arch_index = i;
435 prod_item = item;
455 break; 436 break;
456 } 437 }
457 }
458 438
459 if (i < rp->arch_names) 439 if (prod_item)
460 break; 440 break;
461 } 441 }
462 442
463 /* 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
464 * allow players to create massive amounts of artifacts easily */ 444 * allow players to create massive amounts of artifacts easily */
465 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)
466 { 450 {
451 LOG (llevDebug, " had item: arch %s(nrof:%d)\n",
452 &prod_item->arch->archname, prod_item->nrof);
453 }
454#endif
467 *rp_arch_index = RANDOM () % rp->arch_names; 455 *rp_arch_index = rndm (rp->arch_names);
468 item = get_archetype (rp->arch_name[*rp_arch_index]); 456 prod_item = get_archetype (rp->arch_name[*rp_arch_index]);
469 } 457 }
470 458
471#ifdef ALCHEMY_DEBUG 459#ifdef ALCHEMY_DEBUG
472 LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no "); 460 LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no ");
473 if (item != NULL) 461 if (prod_item != NULL)
474 { 462 {
475 LOG (llevDebug, " find_transmutable_ob(): returns arch %s(sp:%d)\n", item->arch->name, item->stats.sp); 463 LOG (llevDebug, " find_transmutable_ob(): returns arch %s(sp:%d)\n",
464 &prod_item->arch->archname, prod_item->stats.sp);
476 } 465 }
477#endif 466#endif
478 467
479 return item; 468 return prod_item;
480} 469}
481 470
482 471
483/** 472/**
484 * Ouch. We didnt get the formula we wanted. 473 * Ouch. We didnt get the formula we wanted.
615 { /* MAJOR FIRE */ 604 { /* MAJOR FIRE */
616 object *fb = get_archetype (SP_MED_FIREBALL); 605 object *fb = get_archetype (SP_MED_FIREBALL);
617 606
618 remove_contents (cauldron->inv, NULL); 607 remove_contents (cauldron->inv, NULL);
619 fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb); 608 fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb);
620 fb->destroy (true); 609 fb->destroy ();
621 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); 610 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name);
622 } 611 }
623 else if (level < 100) 612 else if (level < 100)
624 { /* WHAMMY the CAULDRON */ 613 { /* WHAMMY the CAULDRON */
625 if (!QUERY_FLAG (cauldron, FLAG_CURSED)) 614 if (!QUERY_FLAG (cauldron, FLAG_CURSED))
666 * in this one, we allow *any* valid alchemy artifact 655 * in this one, we allow *any* valid alchemy artifact
667 * to be made (rather than only those on the given 656 * to be made (rather than only those on the given
668 * formulalist) */ 657 * formulalist) */
669 if (!rp) 658 if (!rp)
670 rp = get_random_recipe ((recipelist *) NULL); 659 rp = get_random_recipe ((recipelist *) NULL);
660
671 if (rp && (tmp = get_archetype (rp->arch_name[RANDOM () % rp->arch_names]))) 661 if (rp && (tmp = get_archetype (rp->arch_name [rndm (rp->arch_names)])))
672 { 662 {
673 generate_artifact (tmp, random_roll (1, op->level / 2 + 1, op, PREFER_HIGH) + 1); 663 generate_artifact (tmp, random_roll (1, op->level / 2 + 1, op, PREFER_HIGH) + 1);
674 if ((tmp = insert_ob_in_ob (tmp, cauldron))) 664 if ((tmp = insert_ob_in_ob (tmp, cauldron)))
675 { 665 {
676 remove_contents (cauldron->inv, tmp); 666 remove_contents (cauldron->inv, tmp);
712 } 702 }
713 703
714 if (tmp->inv) 704 if (tmp->inv)
715 remove_contents (tmp->inv, NULL); 705 remove_contents (tmp->inv, NULL);
716 706
717 tmp->destroy (true); 707 tmp->destroy ();
718 tmp = next; 708 tmp = next;
719 } 709 }
720} 710}
721 711
722/** 712/**
837 for (ob = cauldron->inv; ob != NULL; ob = ob->below) 827 for (ob = cauldron->inv; ob != NULL; ob = ob->below)
838 { 828 {
839 char name_ob[MAX_BUF]; 829 char name_ob[MAX_BUF];
840 const char *name2; 830 const char *name2;
841 831
842 if (ob->title == NULL) 832 if (!ob->title)
843 name2 = ob->name; 833 name2 = ob->name;
844 else 834 else
845 { 835 {
846 snprintf (name_ob, sizeof (name_ob), "%s %s", &ob->name, &ob->title); 836 snprintf (name_ob, sizeof (name_ob), "%s %s", &ob->name, &ob->title);
847 name2 = name_ob; 837 name2 = name_ob;
899 { 889 {
900 /* check if recipe matches at all */ 890 /* check if recipe matches at all */
901 if (formula % rp->index != 0) 891 if (formula % rp->index != 0)
902 { 892 {
903#ifdef EXTREME_ALCHEMY_DEBUG 893#ifdef EXTREME_ALCHEMY_DEBUG
904 LOG (llevDebug, " formula %s of %s (%d) does not match\n", rp->arch_name[0], rp->title, rp->index); 894 LOG (llevDebug, " formula %s of %s (%d) does not match\n", rp->arch_name[0], &rp->title, rp->index);
905#endif 895#endif
906 continue; 896 continue;
907 } 897 }
908 898
909 if (rp->transmute && find_transmution_ob (ingredients, rp, &rp_arch_index, 0) != NULL) 899 if (rp->transmute && find_transmution_ob (ingredients, rp, &rp_arch_index, 0) != NULL)
910 { 900 {
911#ifdef EXTREME_ALCHEMY_DEBUG 901#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); 902 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 903#endif
914 /* transmution recipe with matching base ingredient */ 904 /* transmution recipe with matching base ingredient */
915 if (!transmute_found) 905 if (!transmute_found)
916 { 906 {
917 transmute_found = 1; 907 transmute_found = 1;
919 } 909 }
920 } 910 }
921 else if (transmute_found) 911 else if (transmute_found)
922 { 912 {
923#ifdef EXTREME_ALCHEMY_DEBUG 913#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, 914 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); 915 rp->index);
926#endif 916#endif
927 /* "normal" recipe found after previous transmution recipe => ignore this recipe */ 917 /* "normal" recipe found after previous transmution recipe => ignore this recipe */
928 continue; 918 continue;
929 } 919 }
930#ifdef EXTREME_ALCHEMY_DEBUG 920#ifdef EXTREME_ALCHEMY_DEBUG
931 else 921 else
932 { 922 {
933 LOG (llevDebug, " formula %s of %s (%d) matches\n", rp->arch_name[0], rp->title, rp->index); 923 LOG (llevDebug, " formula %s of %s (%d) matches\n", rp->arch_name[0], &rp->title, rp->index);
934 } 924 }
935#endif 925#endif
936 926
937 if (rndm (0, recipes_matching) == 0) 927 if (rndm (0, recipes_matching) == 0)
938 result = rp; 928 result = rp;
948 return NULL; 938 return NULL;
949 } 939 }
950 940
951#ifdef ALCHEMY_DEBUG 941#ifdef ALCHEMY_DEBUG
952 if (strcmp (result->title, "NONE") != 0) 942 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); 943 LOG (llevDebug, "got formula: %s of %s (nbatches:%d)\n", result->arch_name[0], &result->title, formula / result->index);
954 else 944 else
955 LOG (llevDebug, "got formula: %s (nbatches:%d)\n", result->arch_name[0], formula / result->index); 945 LOG (llevDebug, "got formula: %s (nbatches:%d)\n", result->arch_name[0], formula / result->index);
956#endif 946#endif
957 return result; 947 return result;
958} 948}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines