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.32 by root, Mon Sep 29 10:32:50 2008 UTC vs.
Revision 1.35 by elmex, Sun Jan 4 16:30:39 2009 UTC

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;
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);
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;
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))
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 (item = first_ingred; item; item = item->below)
447 { 429 {
448 size_t i; 430 int i;
449 431
450 for (i = 0; i < rp->arch_names; i++) 432 for (int i = 0; i < rp->arch_names; i++)
451 { 433 //TODO: should be a shstr comparison
452 if (item->arch->archname == rp->arch_name[i]) 434 if (&item->arch->archname == rp->arch_name[i])
453 { 435 {
454 *rp_arch_index = i; 436 *rp_arch_index = i;
455 break; 437 break;
456 } 438 }
457 }
458 439
459 if (i < rp->arch_names) 440 if (i < rp->arch_names)
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 && (!item || item->nrof > 1))
466 { 447 {
467 *rp_arch_index = RANDOM () % rp->arch_names; 448 *rp_arch_index = rndm (rp->arch_names);
468 item = get_archetype (rp->arch_name[*rp_arch_index]); 449 item = get_archetype (rp->arch_name[*rp_arch_index]);
469 } 450 }
470 451
471#ifdef ALCHEMY_DEBUG 452#ifdef ALCHEMY_DEBUG
472 LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no "); 453 LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no ");
666 * in this one, we allow *any* valid alchemy artifact 647 * in this one, we allow *any* valid alchemy artifact
667 * to be made (rather than only those on the given 648 * to be made (rather than only those on the given
668 * formulalist) */ 649 * formulalist) */
669 if (!rp) 650 if (!rp)
670 rp = get_random_recipe ((recipelist *) NULL); 651 rp = get_random_recipe ((recipelist *) NULL);
652
671 if (rp && (tmp = get_archetype (rp->arch_name[RANDOM () % rp->arch_names]))) 653 if (rp && (tmp = get_archetype (rp->arch_name [rndm (rp->arch_names)])))
672 { 654 {
673 generate_artifact (tmp, random_roll (1, op->level / 2 + 1, op, PREFER_HIGH) + 1); 655 generate_artifact (tmp, random_roll (1, op->level / 2 + 1, op, PREFER_HIGH) + 1);
674 if ((tmp = insert_ob_in_ob (tmp, cauldron))) 656 if ((tmp = insert_ob_in_ob (tmp, cauldron)))
675 { 657 {
676 remove_contents (cauldron->inv, tmp); 658 remove_contents (cauldron->inv, tmp);
837 for (ob = cauldron->inv; ob != NULL; ob = ob->below) 819 for (ob = cauldron->inv; ob != NULL; ob = ob->below)
838 { 820 {
839 char name_ob[MAX_BUF]; 821 char name_ob[MAX_BUF];
840 const char *name2; 822 const char *name2;
841 823
842 if (ob->title == NULL) 824 if (!ob->title)
843 name2 = ob->name; 825 name2 = ob->name;
844 else 826 else
845 { 827 {
846 snprintf (name_ob, sizeof (name_ob), "%s %s", &ob->name, &ob->title); 828 snprintf (name_ob, sizeof (name_ob), "%s %s", &ob->name, &ob->title);
847 name2 = name_ob; 829 name2 = name_ob;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines