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.18 by pippijn, Mon Jan 15 21:06:19 2007 UTC vs.
Revision 1.35 by elmex, Sun Jan 4 16:30:39 2009 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game for X-windows 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * This program 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
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version. 11 * (at your 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 GNU General Public License
19 * along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * 20 *
22 * The authors can be reached via e-mail at <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 22 */
24 23
25/* March 96 - Laid down original code. -b.t. thomas@astro.psu.edu */ 24/* March 96 - Laid down original code. -b.t. thomas@astro.psu.edu */
26 25
27#include <global.h> 26#include <global.h>
95 * around. :) 94 * around. :)
96 * -b.t. 95 * -b.t.
97 */ 96 */
98 97
99void 98void
100attempt_do_alchemy (object *caster, object *cauldron) 99attempt_do_alchemy (object *caster, object *cauldron, object *skill)
101{ 100{
102 recipelist *fl; 101 recipelist *fl;
103 recipe *rp = NULL; 102 recipe *rp = NULL;
104 float success_chance; 103 float success_chance;
105 int numb, ability = 1; 104 int numb, ability = 1;
141 return; 140 return;
142 } /* End of WIZ alchemy */ 141 } /* End of WIZ alchemy */
143 142
144 /* find the recipe */ 143 /* find the recipe */
145 rp = find_recipe (fl, formula, cauldron->inv); 144 rp = find_recipe (fl, formula, cauldron->inv);
146 if (rp) 145 if (rp
146 && rp->skill == skill->skill
147 && (!rp->cauldron
148 || rp->cauldron == cauldron->arch->archname))
147 { 149 {
148 uint64 value_ingredients; 150 uint64 value_ingredients;
149 uint64 value_item; 151 uint64 value_item;
150 object *tmp; 152 object *tmp;
151 int attempt_shadow_alchemy; 153 int attempt_shadow_alchemy;
152 154
153 ave_chance = fl->total_chance / (float) fl->number; 155 ave_chance = fl->total_chance / (float) fl->number;
154 /* the caster gets an increase in ability based on thier skill lvl */ 156
155 if (rp->skill)
156 {
157 skop = find_skill_by_name (caster, rp->skill);
158 if (!skop)
159 new_draw_info (NDI_UNIQUE, 0, caster, "You do not have the proper skill for this recipe");
160 else
161 ability += (int) (skop->level * ((4.0 + cauldron->magic) / 4.0)); 157 ability += (int) (skill->level * ((4.0 + cauldron->magic) / 4.0));
162 }
163 else
164 {
165 LOG (llevDebug, "Recipe %s has NULL skill!\n", &rp->title);
166 return;
167 }
168
169 if (!rp->cauldron)
170 {
171 LOG (llevDebug, "Recipe %s has NULL cauldron!\n", &rp->title);
172 return;
173 }
174 158
175 /* determine value of ingredients */ 159 /* determine value of ingredients */
176 value_ingredients = 0; 160 value_ingredients = 0;
177 for (tmp = cauldron->inv; tmp != NULL; tmp = tmp->below) 161 for (tmp = cauldron->inv; tmp != NULL; tmp = tmp->below)
178 value_ingredients += query_cost (tmp, NULL, F_TRUE); 162 value_ingredients += query_cost (tmp, NULL, F_TRUE);
232 int tval = 0, formula = 0; 216 int tval = 0, formula = 0;
233 217
234 while (tmp) 218 while (tmp)
235 { 219 {
236 tval = 0; 220 tval = 0;
237 strcpy (name, tmp->name); 221 assign (name, tmp->name);
238 if (tmp->title) 222 if (tmp->title)
239 sprintf (name, "%s %s", &tmp->name, &tmp->title); 223 sprintf (name, "%s %s", &tmp->name, &tmp->title);
240 tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1)); 224 tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1));
241#ifdef ALCHEMY_DEBUG 225#ifdef ALCHEMY_DEBUG
242 LOG (llevDebug, "Got ingredient %d %s(%d)\n", tmp->nrof ? tmp->nrof : 1, name, tval); 226 LOG (llevDebug, "Got ingredient %d %s(%d)\n", tmp->nrof ? tmp->nrof : 1, name, tval);
290 object *item = NULL, *skop; 274 object *item = NULL, *skop;
291 275
292 /* 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 */
293 int batches = abs (nbatches); 277 int batches = abs (nbatches);
294 278
295
296 /* is the cauldron the right type? */ 279 /* is the cauldron the right type? */
297 if (strcmp (rp->cauldron, cauldron->arch->name) != 0) 280 if (rp->cauldron && rp->cauldron != cauldron->arch->archname)
298 {
299 new_draw_info (NDI_UNIQUE, 0, caster, "You are not using the proper" " facilities for this formula.");
300 return 0; 281 return 0;
301 }
302 282
303 skop = find_skill_by_name (caster, rp->skill); 283 skop = find_skill_by_name (caster, rp->skill);
304 /* does the caster have the skill? */ 284 /* does the caster have the skill? */
305 if (!skop) 285 if (!skop)
306 return 0; 286 return 0;
310 { 290 {
311 object *tmp; 291 object *tmp;
312 292
313 for (tmp = caster->inv; tmp; tmp = tmp->below) 293 for (tmp = caster->inv; tmp; tmp = tmp->below)
314 { 294 {
315 if (tmp->type == FORCE && tmp->slaying && !strcmp (rp->keycode, tmp->slaying)) 295 if (tmp->type == FORCE && tmp->slaying && rp->keycode == tmp->slaying)
316 break; 296 break;
317 } 297 }
318 298
319 if (!tmp) 299 if (!tmp)
320 { /* failure--no code found */ 300 { /* failure--no code found */
321 new_draw_info (NDI_UNIQUE, 0, caster, "You know the ingredients," " but not the technique. Go learn how to do this recipe."); 301 new_draw_info (NDI_UNIQUE, 0, caster, "You know the ingredients, but not the technique. Go learn how to do this recipe.");
322 return 0; 302 return 0;
323 } 303 }
324 } 304 }
325 305
326#ifdef EXTREME_ALCHEMY_DEBUG 306#ifdef EXTREME_ALCHEMY_DEBUG
330 310
331 if ((item = make_item_from_recipe (cauldron, rp)) != NULL) 311 if ((item = make_item_from_recipe (cauldron, rp)) != NULL)
332 { 312 {
333 remove_contents (cauldron->inv, item); 313 remove_contents (cauldron->inv, item);
334 /* Recalc carrying of the cauldron, in case recipe did not conserve mass */ 314 /* Recalc carrying of the cauldron, in case recipe did not conserve mass */
335 sum_weight (cauldron); 315 cauldron->update_weight ();
336 /* adj lvl, nrof on caster level */ 316 /* adj lvl, nrof on caster level */
337 adjust_product (item, ability, rp->yield ? (rp->yield * batches) : batches); 317 adjust_product (item, ability, rp->yield ? (rp->yield * batches) : batches);
338 if (!item->env && (item = insert_ob_in_ob (item, cauldron)) == NULL) 318 if (!item->env && (item = insert_ob_in_ob (item, cauldron)) == NULL)
339 { 319 {
340 new_draw_info (NDI_UNIQUE, 0, caster, "Nothing happened."); 320 new_draw_info (NDI_UNIQUE, 0, caster, "Nothing happened.");
404 LOG (llevDebug, "make_alchemy_item(): failed to create alchemical object.\n"); 384 LOG (llevDebug, "make_alchemy_item(): failed to create alchemical object.\n");
405 return (object *) NULL; 385 return (object *) NULL;
406 } 386 }
407 387
408 /* Find the appropriate artifact template... */ 388 /* Find the appropriate artifact template... */
409 if (strcmp (rp->title, "NONE")) 389 if (rp->title != shstr_NONE)
410 { 390 {
411 if ((art = locate_recipe_artifact (rp, rp_arch_index)) == NULL) 391 if ((art = locate_recipe_artifact (rp, rp_arch_index)) == NULL)
412 { 392 {
413 LOG (llevError, "make_alchemy_item(): failed to locate recipe artifact.\n"); 393 LOG (llevError, "make_alchemy_item(): failed to locate recipe artifact.\n");
414 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);
415 return (object *) NULL; 395 return (object *) NULL;
416 } 396 }
397
417 transmute_materialname (item, art->item); 398 transmute_materialname (item, art->item);
418 give_artifact_abilities (item, art->item); 399 give_artifact_abilities (item, art->item);
419 } 400 }
420 401
421 if (QUERY_FLAG (cauldron, FLAG_CURSED)) 402 if (QUERY_FLAG (cauldron, FLAG_CURSED))
444 *rp_arch_index = 0; 425 *rp_arch_index = 0;
445 426
446 if (rp->transmute) /* look for matching ingredient/prod archs */ 427 if (rp->transmute) /* look for matching ingredient/prod archs */
447 for (item = first_ingred; item; item = item->below) 428 for (item = first_ingred; item; item = item->below)
448 { 429 {
449 size_t i; 430 int i;
450 431
451 for (i = 0; i < rp->arch_names; i++) 432 for (int i = 0; i < rp->arch_names; i++)
452 { 433 //TODO: should be a shstr comparison
453 if (strcmp (item->arch->name, rp->arch_name[i]) == 0) 434 if (&item->arch->archname == rp->arch_name[i])
454 { 435 {
455 *rp_arch_index = i; 436 *rp_arch_index = i;
456 break; 437 break;
457 } 438 }
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 ");
510 491
511 if (rndm (0, 2)) 492 if (rndm (0, 2))
512 { /* slag created */ 493 { /* slag created */
513 object *tmp = cauldron->inv; 494 object *tmp = cauldron->inv;
514 int weight = 0; 495 int weight = 0;
515 uint16 material = M_STONE;
516 496
517 while (tmp)
518 { /* slag has coadded ingredient properties */
519 weight += tmp->weight;
520 if (!(material & tmp->material))
521 material |= tmp->material;
522 tmp = tmp->below;
523 }
524 tmp = get_archetype ("rock"); 497 tmp = get_archetype ("rock");
525 tmp->weight = weight; 498 tmp->weight = weight;
526 tmp->value = 0; 499 tmp->value = 0;
527 tmp->material = material;
528 tmp->materialname = "stone"; 500 tmp->materialname = "stone";
529 tmp->name = "slag"; 501 tmp->name = "slag";
530 tmp->name_pl = "slags"; 502 tmp->name_pl = "slags";
531 item = insert_ob_in_ob (tmp, cauldron); 503 item = insert_ob_in_ob (tmp, cauldron);
532 CLEAR_FLAG (tmp, FLAG_CAN_ROLL); 504 CLEAR_FLAG (tmp, FLAG_CAN_ROLL);
533 CLEAR_FLAG (tmp, FLAG_NO_PICK); 505 CLEAR_FLAG (tmp, FLAG_NO_PICK);
534 tmp->move_block = 0; 506 tmp->move_block = 0;
535 } 507 }
508
536 remove_contents (cauldron->inv, item); 509 remove_contents (cauldron->inv, item);
537 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); 510 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ());
538 return; 511 return;
539 } 512 }
540 else if (level < 40) 513 else if (level < 40)
566 } 539 }
567 while (rndm (0, 2)); 540 while (rndm (0, 2));
568 } 541 }
569 return; 542 return;
570 } 543 }
544
571 if (level == 40) 545 if (level == 40)
572 { /* MAKE RANDOM RECIPE */ 546 { /* MAKE RANDOM RECIPE */
573 recipelist *fl; 547 recipelist *fl;
574 int numb = numb_ob_inside (cauldron); 548 int numb = numb_ob_inside (cauldron);
575 549
577 if (fl && (rp = get_random_recipe (fl))) 551 if (fl && (rp = get_random_recipe (fl)))
578 /* even though random, don't grant user any EXP for it */ 552 /* even though random, don't grant user any EXP for it */
579 (void) attempt_recipe (op, cauldron, 1, rp, -1); 553 (void) attempt_recipe (op, cauldron, 1, rp, -1);
580 else 554 else
581 alchemy_failure_effect (op, cauldron, rp, level - 1); 555 alchemy_failure_effect (op, cauldron, rp, level - 1);
582 return;
583
584 } 556 }
585 else if (level < 45) 557 else if (level < 45)
586 { /* INFURIATE NPC's */ 558 { /* INFURIATE NPC's */
587 /* this is kind of kludgy I know... */ 559 /* this is kind of kludgy I know... */
588 cauldron->enemy = op; 560 cauldron->enemy = op;
589 npc_call_help (cauldron); 561 npc_call_help (cauldron);
590 cauldron->enemy = NULL; 562 cauldron->enemy = NULL;
591 563
592 alchemy_failure_effect (op, cauldron, rp, level - 5); 564 alchemy_failure_effect (op, cauldron, rp, level - 5);
593 return;
594 } 565 }
595 else if (level < 50) 566 else if (level < 50)
596 { /* MINOR EXPLOSION/FIREBALL */ 567 { /* MINOR EXPLOSION/FIREBALL */
597 object *tmp; 568 object *tmp;
598 569
612 tmp->stats.hp = random_roll (1, level, op, PREFER_LOW) / 10 + 2; 583 tmp->stats.hp = random_roll (1, level, op, PREFER_LOW) / 10 + 2;
613 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); 584 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name);
614 break; 585 break;
615 } 586 }
616 587
617 op->insert_at (cauldron); 588 tmp->insert_at (cauldron);
618 return;
619
620 } 589 }
621 else if (level < 60) 590 else if (level < 60)
622 { /* CREATE MONSTER */ 591 { /* CREATE MONSTER */
623 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); 592 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ());
624 remove_contents (cauldron->inv, NULL); 593 remove_contents (cauldron->inv, NULL);
625 return;
626 } 594 }
627 else if (level < 80) 595 else if (level < 80)
628 { /* MAJOR FIRE */ 596 { /* MAJOR FIRE */
629 object *fb = get_archetype (SP_MED_FIREBALL); 597 object *fb = get_archetype (SP_MED_FIREBALL);
630 598
631 remove_contents (cauldron->inv, NULL); 599 remove_contents (cauldron->inv, NULL);
632 fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb); 600 fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb);
633 fb->destroy (); 601 fb->destroy ();
634 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); 602 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name);
635 return;
636
637 } 603 }
638 else if (level < 100) 604 else if (level < 100)
639 { /* WHAMMY the CAULDRON */ 605 { /* WHAMMY the CAULDRON */
640 if (!QUERY_FLAG (cauldron, FLAG_CURSED)) 606 if (!QUERY_FLAG (cauldron, FLAG_CURSED))
641 SET_FLAG (cauldron, FLAG_CURSED); 607 SET_FLAG (cauldron, FLAG_CURSED);
642 else 608 else
643 cauldron->magic--; 609 cauldron->magic--;
610
644 cauldron->magic -= random_roll (0, 4, op, PREFER_LOW); 611 cauldron->magic -= random_roll (0, 4, op, PREFER_LOW);
612
645 if (rndm (0, 1)) 613 if (rndm (0, 1))
646 { 614 {
647 remove_contents (cauldron->inv, NULL); 615 remove_contents (cauldron->inv, NULL);
648 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s turns darker then makes a gulping sound!", &cauldron->name); 616 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s turns darker then makes a gulping sound!", &cauldron->name);
649 } 617 }
650 else 618 else
651 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s becomes darker.", &cauldron->name); 619 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s becomes darker.", &cauldron->name);
652 return;
653
654 } 620 }
655 else if (level < 110) 621 else if (level < 110)
656 { /* SUMMON EVIL MONSTERS */ 622 { /* SUMMON EVIL MONSTERS */
657 object *tmp = get_random_mon (level / 5); 623 object *tmp = get_random_mon (level / 5);
658 624
659 remove_contents (cauldron->inv, NULL); 625 remove_contents (cauldron->inv, NULL);
626
660 if (!tmp) 627 if (!tmp)
661 alchemy_failure_effect (op, cauldron, rp, level); 628 alchemy_failure_effect (op, cauldron, rp, level);
662 else if (summon_hostile_monsters (cauldron, random_roll (1, 10, op, PREFER_LOW), tmp->arch->name)) 629 else if (summon_hostile_monsters (cauldron, random_roll (1, 10, op, PREFER_LOW), tmp->arch->archname))
663 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s and then pours forth monsters!", &cauldron->name, cauldron_sound ()); 630 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s and then pours forth monsters!", &cauldron->name, cauldron_sound ());
664 return;
665
666 } 631 }
667 else if (level < 150) 632 else if (level < 150)
668 { /* COMBO EFFECT */ 633 { /* COMBO EFFECT */
669 int roll = rndm (1, 3); 634 int roll = rndm (1, 3);
670 635
671 while (roll) 636 while (roll)
672 { 637 {
673 alchemy_failure_effect (op, cauldron, rp, level - 39); 638 alchemy_failure_effect (op, cauldron, rp, level - 39);
674 roll--; 639 roll--;
675 } 640 }
676 return;
677 } 641 }
678 else if (level == 151) 642 else if (level == 151)
679 { /* CREATE RANDOM ARTIFACT */ 643 { /* CREATE RANDOM ARTIFACT */
680 object *tmp; 644 object *tmp;
681 645
683 * in this one, we allow *any* valid alchemy artifact 647 * in this one, we allow *any* valid alchemy artifact
684 * to be made (rather than only those on the given 648 * to be made (rather than only those on the given
685 * formulalist) */ 649 * formulalist) */
686 if (!rp) 650 if (!rp)
687 rp = get_random_recipe ((recipelist *) NULL); 651 rp = get_random_recipe ((recipelist *) NULL);
652
688 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)])))
689 { 654 {
690 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);
691 if ((tmp = insert_ob_in_ob (tmp, cauldron))) 656 if ((tmp = insert_ob_in_ob (tmp, cauldron)))
692 { 657 {
693 remove_contents (cauldron->inv, tmp); 658 remove_contents (cauldron->inv, tmp);
694 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); 659 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ());
695 } 660 }
696 } 661 }
697 return;
698 } 662 }
699 else 663 else
700 { /* MANA STORM - watch out!! */ 664 { /* MANA STORM - watch out!! */
701 object *tmp = get_archetype (LOOSE_MANA); 665 object *tmp = get_archetype (LOOSE_MANA);
702 666
703 new_draw_info (NDI_UNIQUE, 0, op, "You unwisely release potent forces!"); 667 new_draw_info (NDI_UNIQUE, 0, op, "You unwisely release potent forces!");
704 remove_contents (cauldron->inv, NULL); 668 remove_contents (cauldron->inv, NULL);
705 cast_magic_storm (op, tmp, level); 669 cast_magic_storm (op, tmp, level);
706 return;
707 } 670 }
708} 671}
709
710 672
711/* 673/*
712 * All but object "save_item" are elimentated from 674 * All but object "save_item" are elimentated from
713 * the container list. Note we have to becareful to remove the inventories 675 * the container list. Note we have to becareful to remove the inventories
714 * of objects in the cauldron inventory (ex icecube has stuff in it). 676 * of objects in the cauldron inventory (ex icecube has stuff in it).
715 */ 677 */
716
717void 678void
718remove_contents (object *first_ob, object *save_item) 679remove_contents (object *first_ob, object *save_item)
719{ 680{
681 // this cries for a cleaner rewrite, removing save_item first possibly
720 object *next, *tmp = first_ob; 682 object *next, *tmp = first_ob;
721 683
722 while (tmp) 684 while (tmp)
723 { 685 {
724 next = tmp->below; 686 next = tmp->below;
737 tmp->destroy (); 699 tmp->destroy ();
738 tmp = next; 700 tmp = next;
739 } 701 }
740} 702}
741 703
742/** 704/**
743 *"Danger" level, will determine how bad the backfire 705 *"Danger" level, will determine how bad the backfire
744 * could be if the user fails to concoct a recipe properly. Factors include 706 * could be if the user fails to concoct a recipe properly. Factors include
745 * the number of ingredients, the length of the name of each ingredient, 707 * the number of ingredients, the length of the name of each ingredient,
746 * the user's effective level, the user's Int and the enchantment on the 708 * the user's effective level, the user's Int and the enchantment on the
747 * mixing device (aka "cauldron"). Higher values of 'danger' indicate more 709 * mixing device (aka "cauldron"). Higher values of 'danger' indicate more
748 * danger. Note that we assume that we have had the caster ready the alchemy 710 * danger. Note that we assume that we have had the caster ready the alchemy
749 * skill *before* this routine is called. (no longer auto-readies that skill) 711 * skill *before* this routine is called. (no longer auto-readies that skill)
750 * -b.t. 712 * -b.t.
751 */ 713 */
752
753int 714int
754calc_alch_danger (object *caster, object *cauldron, recipe *rp) 715calc_alch_danger (object *caster, object *cauldron, recipe *rp)
755{ 716{
756 object *item; 717 object *item;
757 char name[MAX_BUF]; 718 char name[MAX_BUF];
758 int danger = 0, nrofi = 0; 719 int danger = 0, nrofi = 0;
759 720
760 /* Knowing alchemy skill reduces yer risk */ 721 /* Knowing alchemy skill reduces yer risk */
761 danger -= caster->chosen_skill ? caster->chosen_skill->level : caster->level; 722 danger -= caster->chosen_skill ? caster->chosen_skill->level : caster->level;
723
724 if (!caster->chosen_skill)
725 LOG (llevError | logBacktrace, "calc_alch_danger called without a chosen skill, caster %s, cauldron %s\n",
726 caster->debug_desc (), cauldron->debug_desc ());
762 727
763 /* better cauldrons reduce risk */ 728 /* better cauldrons reduce risk */
764 danger -= cauldron->magic; 729 danger -= cauldron->magic;
765 730
766 /* Higher Int, lower the risk */ 731 /* Higher Int, lower the risk */
770 * Thus the backfire is worse. Also, more ingredients 735 * Thus the backfire is worse. Also, more ingredients
771 * means we are attempting a more powerfull potion, 736 * means we are attempting a more powerfull potion,
772 * and thus the backfire will be worse. */ 737 * and thus the backfire will be worse. */
773 for (item = cauldron->inv; item; item = item->below) 738 for (item = cauldron->inv; item; item = item->below)
774 { 739 {
775 strcpy (name, item->name); 740 assign (name, item->name);
776 if (item->title) 741 if (item->title)
777 sprintf (name, "%s %s", &item->name, &item->title); 742 sprintf (name, "%s %s", &item->name, &item->title);
778 danger += (strtoint (name) / 1000) + 3; 743 danger += (strtoint (name) / 1000) + 3;
779 nrofi++; 744 nrofi++;
780 } 745 }
746
781 if (rp == NULL) 747 if (rp == NULL)
782 danger += 110; 748 danger += 110;
783 else 749 else
784 danger += rp->diff * 3; 750 danger += rp->diff * 3;
785 751
794#endif 760#endif
795 761
796 return danger; 762 return danger;
797} 763}
798 764
799/** 765/**
800 * Determines if ingredients in a container match the 766 * Determines if ingredients in a container match the
801 * proper ingredients for a recipe. 767 * proper ingredients for a recipe.
802 * 768 *
803 * rp is the recipe to check 769 * rp is the recipe to check
804 * cauldron is the container that holds the ingredients 770 * cauldron is the container that holds the ingredients
853 for (ob = cauldron->inv; ob != NULL; ob = ob->below) 819 for (ob = cauldron->inv; ob != NULL; ob = ob->below)
854 { 820 {
855 char name_ob[MAX_BUF]; 821 char name_ob[MAX_BUF];
856 const char *name2; 822 const char *name2;
857 823
858 if (ob->title == NULL) 824 if (!ob->title)
859 name2 = ob->name; 825 name2 = ob->name;
860 else 826 else
861 { 827 {
862 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);
863 name2 = name_ob; 829 name2 = name_ob;
908 LOG (llevDebug, "looking for formula %d:\n", formula); 874 LOG (llevDebug, "looking for formula %d:\n", formula);
909#endif 875#endif
910 result = NULL; 876 result = NULL;
911 recipes_matching = 0; 877 recipes_matching = 0;
912 transmute_found = 0; 878 transmute_found = 0;
879
913 for (rp = fl->items; rp != NULL; rp = rp->next) 880 for (rp = fl->items; rp; rp = rp->next)
914 { 881 {
915 /* check if recipe matches at all */ 882 /* check if recipe matches at all */
916 if (formula % rp->index != 0) 883 if (formula % rp->index != 0)
917 { 884 {
918#ifdef EXTREME_ALCHEMY_DEBUG 885#ifdef EXTREME_ALCHEMY_DEBUG

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines