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.20 by root, Mon Feb 5 02:07:40 2007 UTC vs.
Revision 1.36 by elmex, Sun Jan 4 20:23:07 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,2009 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);
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 (rp->cauldron != cauldron->arch->name) 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;
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 (item->arch->name == rp->arch_name[i]) 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 }
459 439
460 if (i < rp->arch_names) 440 if (i < rp->arch_names)
461 break; 441 break;
462 } 442 }
463 443
464 /* 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
465 * allow players to create massive amounts of artifacts easily */ 445 * allow players to create massive amounts of artifacts easily */
466 if (create_item && (!item || item->nrof > 1)) 446 if (create_item && (!item || item->nrof > 1))
467 { 447 {
468 *rp_arch_index = RANDOM () % rp->arch_names; 448 *rp_arch_index = rndm (rp->arch_names);
469 item = get_archetype (rp->arch_name[*rp_arch_index]); 449 item = get_archetype (rp->arch_name[*rp_arch_index]);
470 } 450 }
471 451
472#ifdef ALCHEMY_DEBUG 452#ifdef ALCHEMY_DEBUG
473 LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no "); 453 LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no ");
511 491
512 if (rndm (0, 2)) 492 if (rndm (0, 2))
513 { /* slag created */ 493 { /* slag created */
514 object *tmp = cauldron->inv; 494 object *tmp = cauldron->inv;
515 int weight = 0; 495 int weight = 0;
516 uint16 material = M_STONE;
517 496
518 while (tmp)
519 { /* slag has coadded ingredient properties */
520 weight += tmp->weight;
521 if (!(material & tmp->material))
522 material |= tmp->material;
523 tmp = tmp->below;
524 }
525 tmp = get_archetype ("rock"); 497 tmp = get_archetype ("rock");
526 tmp->weight = weight; 498 tmp->weight = weight;
527 tmp->value = 0; 499 tmp->value = 0;
528 tmp->material = material;
529 tmp->materialname = "stone"; 500 tmp->materialname = "stone";
530 tmp->name = "slag"; 501 tmp->name = "slag";
531 tmp->name_pl = "slags"; 502 tmp->name_pl = "slags";
532 item = insert_ob_in_ob (tmp, cauldron); 503 item = insert_ob_in_ob (tmp, cauldron);
533 CLEAR_FLAG (tmp, FLAG_CAN_ROLL); 504 CLEAR_FLAG (tmp, FLAG_CAN_ROLL);
534 CLEAR_FLAG (tmp, FLAG_NO_PICK); 505 CLEAR_FLAG (tmp, FLAG_NO_PICK);
535 tmp->move_block = 0; 506 tmp->move_block = 0;
536 } 507 }
508
537 remove_contents (cauldron->inv, item); 509 remove_contents (cauldron->inv, item);
538 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 ());
539 return; 511 return;
540 } 512 }
541 else if (level < 40) 513 else if (level < 40)
567 } 539 }
568 while (rndm (0, 2)); 540 while (rndm (0, 2));
569 } 541 }
570 return; 542 return;
571 } 543 }
544
572 if (level == 40) 545 if (level == 40)
573 { /* MAKE RANDOM RECIPE */ 546 { /* MAKE RANDOM RECIPE */
574 recipelist *fl; 547 recipelist *fl;
575 int numb = numb_ob_inside (cauldron); 548 int numb = numb_ob_inside (cauldron);
576 549
578 if (fl && (rp = get_random_recipe (fl))) 551 if (fl && (rp = get_random_recipe (fl)))
579 /* even though random, don't grant user any EXP for it */ 552 /* even though random, don't grant user any EXP for it */
580 (void) attempt_recipe (op, cauldron, 1, rp, -1); 553 (void) attempt_recipe (op, cauldron, 1, rp, -1);
581 else 554 else
582 alchemy_failure_effect (op, cauldron, rp, level - 1); 555 alchemy_failure_effect (op, cauldron, rp, level - 1);
583 return;
584
585 } 556 }
586 else if (level < 45) 557 else if (level < 45)
587 { /* INFURIATE NPC's */ 558 { /* INFURIATE NPC's */
588 /* this is kind of kludgy I know... */ 559 /* this is kind of kludgy I know... */
589 cauldron->enemy = op; 560 cauldron->enemy = op;
590 npc_call_help (cauldron); 561 npc_call_help (cauldron);
591 cauldron->enemy = NULL; 562 cauldron->enemy = NULL;
592 563
593 alchemy_failure_effect (op, cauldron, rp, level - 5); 564 alchemy_failure_effect (op, cauldron, rp, level - 5);
594 return;
595 } 565 }
596 else if (level < 50) 566 else if (level < 50)
597 { /* MINOR EXPLOSION/FIREBALL */ 567 { /* MINOR EXPLOSION/FIREBALL */
598 object *tmp; 568 object *tmp;
599 569
613 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;
614 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);
615 break; 585 break;
616 } 586 }
617 587
618 op->insert_at (cauldron); 588 tmp->insert_at (cauldron);
619 return;
620
621 } 589 }
622 else if (level < 60) 590 else if (level < 60)
623 { /* CREATE MONSTER */ 591 { /* CREATE MONSTER */
624 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 ());
625 remove_contents (cauldron->inv, NULL); 593 remove_contents (cauldron->inv, NULL);
626 return;
627 } 594 }
628 else if (level < 80) 595 else if (level < 80)
629 { /* MAJOR FIRE */ 596 { /* MAJOR FIRE */
630 object *fb = get_archetype (SP_MED_FIREBALL); 597 object *fb = get_archetype (SP_MED_FIREBALL);
631 598
632 remove_contents (cauldron->inv, NULL); 599 remove_contents (cauldron->inv, NULL);
633 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);
634 fb->destroy (); 601 fb->destroy ();
635 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);
636 return;
637
638 } 603 }
639 else if (level < 100) 604 else if (level < 100)
640 { /* WHAMMY the CAULDRON */ 605 { /* WHAMMY the CAULDRON */
641 if (!QUERY_FLAG (cauldron, FLAG_CURSED)) 606 if (!QUERY_FLAG (cauldron, FLAG_CURSED))
642 SET_FLAG (cauldron, FLAG_CURSED); 607 SET_FLAG (cauldron, FLAG_CURSED);
643 else 608 else
644 cauldron->magic--; 609 cauldron->magic--;
610
645 cauldron->magic -= random_roll (0, 4, op, PREFER_LOW); 611 cauldron->magic -= random_roll (0, 4, op, PREFER_LOW);
612
646 if (rndm (0, 1)) 613 if (rndm (0, 1))
647 { 614 {
648 remove_contents (cauldron->inv, NULL); 615 remove_contents (cauldron->inv, NULL);
649 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);
650 } 617 }
651 else 618 else
652 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);
653 return;
654
655 } 620 }
656 else if (level < 110) 621 else if (level < 110)
657 { /* SUMMON EVIL MONSTERS */ 622 { /* SUMMON EVIL MONSTERS */
658 object *tmp = get_random_mon (level / 5); 623 object *tmp = get_random_mon (level / 5);
659 624
660 remove_contents (cauldron->inv, NULL); 625 remove_contents (cauldron->inv, NULL);
626
661 if (!tmp) 627 if (!tmp)
662 alchemy_failure_effect (op, cauldron, rp, level); 628 alchemy_failure_effect (op, cauldron, rp, level);
663 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))
664 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 ());
665 return;
666
667 } 631 }
668 else if (level < 150) 632 else if (level < 150)
669 { /* COMBO EFFECT */ 633 { /* COMBO EFFECT */
670 int roll = rndm (1, 3); 634 int roll = rndm (1, 3);
671 635
672 while (roll) 636 while (roll)
673 { 637 {
674 alchemy_failure_effect (op, cauldron, rp, level - 39); 638 alchemy_failure_effect (op, cauldron, rp, level - 39);
675 roll--; 639 roll--;
676 } 640 }
677 return;
678 } 641 }
679 else if (level == 151) 642 else if (level == 151)
680 { /* CREATE RANDOM ARTIFACT */ 643 { /* CREATE RANDOM ARTIFACT */
681 object *tmp; 644 object *tmp;
682 645
684 * in this one, we allow *any* valid alchemy artifact 647 * in this one, we allow *any* valid alchemy artifact
685 * to be made (rather than only those on the given 648 * to be made (rather than only those on the given
686 * formulalist) */ 649 * formulalist) */
687 if (!rp) 650 if (!rp)
688 rp = get_random_recipe ((recipelist *) NULL); 651 rp = get_random_recipe ((recipelist *) NULL);
652
689 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)])))
690 { 654 {
691 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);
692 if ((tmp = insert_ob_in_ob (tmp, cauldron))) 656 if ((tmp = insert_ob_in_ob (tmp, cauldron)))
693 { 657 {
694 remove_contents (cauldron->inv, tmp); 658 remove_contents (cauldron->inv, tmp);
695 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 ());
696 } 660 }
697 } 661 }
698 return;
699 } 662 }
700 else 663 else
701 { /* MANA STORM - watch out!! */ 664 { /* MANA STORM - watch out!! */
702 object *tmp = get_archetype (LOOSE_MANA); 665 object *tmp = get_archetype (LOOSE_MANA);
703 666
704 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!");
705 remove_contents (cauldron->inv, NULL); 668 remove_contents (cauldron->inv, NULL);
706 cast_magic_storm (op, tmp, level); 669 cast_magic_storm (op, tmp, level);
707 return;
708 } 670 }
709} 671}
710
711 672
712/* 673/*
713 * All but object "save_item" are elimentated from 674 * All but object "save_item" are elimentated from
714 * 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
715 * 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).
716 */ 677 */
717
718void 678void
719remove_contents (object *first_ob, object *save_item) 679remove_contents (object *first_ob, object *save_item)
720{ 680{
681 // this cries for a cleaner rewrite, removing save_item first possibly
721 object *next, *tmp = first_ob; 682 object *next, *tmp = first_ob;
722 683
723 while (tmp) 684 while (tmp)
724 { 685 {
725 next = tmp->below; 686 next = tmp->below;
738 tmp->destroy (); 699 tmp->destroy ();
739 tmp = next; 700 tmp = next;
740 } 701 }
741} 702}
742 703
743/** 704/**
744 *"Danger" level, will determine how bad the backfire 705 *"Danger" level, will determine how bad the backfire
745 * 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
746 * 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,
747 * 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
748 * mixing device (aka "cauldron"). Higher values of 'danger' indicate more 709 * mixing device (aka "cauldron"). Higher values of 'danger' indicate more
749 * 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
750 * 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)
751 * -b.t. 712 * -b.t.
752 */ 713 */
753
754int 714int
755calc_alch_danger (object *caster, object *cauldron, recipe *rp) 715calc_alch_danger (object *caster, object *cauldron, recipe *rp)
756{ 716{
757 object *item; 717 object *item;
758 char name[MAX_BUF]; 718 char name[MAX_BUF];
759 int danger = 0, nrofi = 0; 719 int danger = 0, nrofi = 0;
760 720
761 /* Knowing alchemy skill reduces yer risk */ 721 /* Knowing alchemy skill reduces yer risk */
762 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 ());
763 727
764 /* better cauldrons reduce risk */ 728 /* better cauldrons reduce risk */
765 danger -= cauldron->magic; 729 danger -= cauldron->magic;
766 730
767 /* Higher Int, lower the risk */ 731 /* Higher Int, lower the risk */
777 if (item->title) 741 if (item->title)
778 sprintf (name, "%s %s", &item->name, &item->title); 742 sprintf (name, "%s %s", &item->name, &item->title);
779 danger += (strtoint (name) / 1000) + 3; 743 danger += (strtoint (name) / 1000) + 3;
780 nrofi++; 744 nrofi++;
781 } 745 }
746
782 if (rp == NULL) 747 if (rp == NULL)
783 danger += 110; 748 danger += 110;
784 else 749 else
785 danger += rp->diff * 3; 750 danger += rp->diff * 3;
786 751
795#endif 760#endif
796 761
797 return danger; 762 return danger;
798} 763}
799 764
800/** 765/**
801 * Determines if ingredients in a container match the 766 * Determines if ingredients in a container match the
802 * proper ingredients for a recipe. 767 * proper ingredients for a recipe.
803 * 768 *
804 * rp is the recipe to check 769 * rp is the recipe to check
805 * cauldron is the container that holds the ingredients 770 * cauldron is the container that holds the ingredients
854 for (ob = cauldron->inv; ob != NULL; ob = ob->below) 819 for (ob = cauldron->inv; ob != NULL; ob = ob->below)
855 { 820 {
856 char name_ob[MAX_BUF]; 821 char name_ob[MAX_BUF];
857 const char *name2; 822 const char *name2;
858 823
859 if (ob->title == NULL) 824 if (!ob->title)
860 name2 = ob->name; 825 name2 = ob->name;
861 else 826 else
862 { 827 {
863 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);
864 name2 = name_ob; 829 name2 = name_ob;
909 LOG (llevDebug, "looking for formula %d:\n", formula); 874 LOG (llevDebug, "looking for formula %d:\n", formula);
910#endif 875#endif
911 result = NULL; 876 result = NULL;
912 recipes_matching = 0; 877 recipes_matching = 0;
913 transmute_found = 0; 878 transmute_found = 0;
879
914 for (rp = fl->items; rp != NULL; rp = rp->next) 880 for (rp = fl->items; rp; rp = rp->next)
915 { 881 {
916 /* check if recipe matches at all */ 882 /* check if recipe matches at all */
917 if (formula % rp->index != 0) 883 if (formula % rp->index != 0)
918 { 884 {
919#ifdef EXTREME_ALCHEMY_DEBUG 885#ifdef EXTREME_ALCHEMY_DEBUG

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines