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.39 by sf-marcmagus, Fri Oct 9 23:00: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,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;
128 rp = find_recipe (fl, formula, cauldron->inv); 127 rp = find_recipe (fl, formula, cauldron->inv);
129 if (rp != NULL) 128 if (rp != NULL)
130 { 129 {
131#ifdef ALCHEMY_DEBUG 130#ifdef ALCHEMY_DEBUG
132 if (strcmp (rp->title, "NONE")) 131 if (strcmp (rp->title, "NONE"))
133 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);
134 else 133 else
135 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);
136#endif 135#endif
137 attempt_recipe (caster, cauldron, ability, rp, formula / rp->index); 136 attempt_recipe (caster, cauldron, ability, rp, formula / rp->index);
138 } 137 }
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);
268 number++; 252 number++;
269 o_number++; 253 o_number++;
270 tmp = tmp->below; 254 tmp = tmp->below;
271 } 255 }
272#ifdef ALCHEMY_DEBUG 256#ifdef ALCHEMY_DEBUG
273 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);
274#endif 258#endif
275 return o_number; 259 return o_number;
276} 260}
277 261
278/** 262/**
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
327 LOG (llevDebug, "attempt_recipe(): got %d nbatches\n", nbatches); 307 LOG (llevDebug, "attempt_recipe(): got %d nbatches\n", nbatches);
328 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");
329#endif 309#endif
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))
435 * @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;
436 * set to zero if not using a transmution formula 417 * set to zero if not using a transmution formula
437 */ 418 */
438 419
439object * 420object *
440find_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)
441{ 422{
442 object *item = NULL; 423 object *prod_item = 0;
443 424 bool found = false;
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 (object *item = first_ingred; item; item = item->below)
448 { 429 {
449 size_t i;
450
451 for (i = 0; i < rp->arch_names; i++) 430 for (int i = 0; i < rp->arch_names; i++)
452 { 431 //TODO: should be a shstr comparison
453 if (item->arch->name == rp->arch_name[i]) 432 if (!strcmp(&item->arch->archname,rp->arch_name[i]))
454 { 433 {
455 *rp_arch_index = i; 434 *rp_arch_index = i;
435 prod_item = item;
456 break; 436 break;
457 } 437 }
458 }
459 438
460 if (i < rp->arch_names) 439 if (prod_item)
461 break; 440 break;
462 } 441 }
463 442
464 /* 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
465 * allow players to create massive amounts of artifacts easily */ 444 * allow players to create massive amounts of artifacts easily */
466 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)
467 { 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)
468 *rp_arch_index = RANDOM () % rp->arch_names; 456 *rp_arch_index = rndm (rp->arch_names);
469 item = get_archetype (rp->arch_name[*rp_arch_index]); 457 prod_item = get_archetype (rp->arch_name[*rp_arch_index]);
470 } 458 }
471 459
472#ifdef ALCHEMY_DEBUG 460#ifdef ALCHEMY_DEBUG
473 LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no "); 461 LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no ");
474 if (item != NULL) 462 if (prod_item != NULL)
475 { 463 {
476 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);
477 } 466 }
478#endif 467#endif
479 468
480 return item; 469 return prod_item;
481} 470}
482 471
483 472
484/** 473/**
485 * Ouch. We didnt get the formula we wanted. 474 * Ouch. We didnt get the formula we wanted.
511 500
512 if (rndm (0, 2)) 501 if (rndm (0, 2))
513 { /* slag created */ 502 { /* slag created */
514 object *tmp = cauldron->inv; 503 object *tmp = cauldron->inv;
515 int weight = 0; 504 int weight = 0;
516 uint16 material = M_STONE;
517 505
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"); 506 tmp = get_archetype ("rock");
526 tmp->weight = weight; 507 tmp->weight = weight;
527 tmp->value = 0; 508 tmp->value = 0;
528 tmp->material = material;
529 tmp->materialname = "stone"; 509 tmp->materialname = "stone";
530 tmp->name = "slag"; 510 tmp->name = "slag";
531 tmp->name_pl = "slags"; 511 tmp->name_pl = "slags";
532 item = insert_ob_in_ob (tmp, cauldron); 512 item = insert_ob_in_ob (tmp, cauldron);
533 CLEAR_FLAG (tmp, FLAG_CAN_ROLL); 513 CLEAR_FLAG (tmp, FLAG_CAN_ROLL);
534 CLEAR_FLAG (tmp, FLAG_NO_PICK); 514 CLEAR_FLAG (tmp, FLAG_NO_PICK);
535 tmp->move_block = 0; 515 tmp->move_block = 0;
536 } 516 }
517
537 remove_contents (cauldron->inv, item); 518 remove_contents (cauldron->inv, item);
538 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); 519 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ());
539 return; 520 return;
540 } 521 }
541 else if (level < 40) 522 else if (level < 40)
567 } 548 }
568 while (rndm (0, 2)); 549 while (rndm (0, 2));
569 } 550 }
570 return; 551 return;
571 } 552 }
553
572 if (level == 40) 554 if (level == 40)
573 { /* MAKE RANDOM RECIPE */ 555 { /* MAKE RANDOM RECIPE */
574 recipelist *fl; 556 recipelist *fl;
575 int numb = numb_ob_inside (cauldron); 557 int numb = numb_ob_inside (cauldron);
576 558
578 if (fl && (rp = get_random_recipe (fl))) 560 if (fl && (rp = get_random_recipe (fl)))
579 /* even though random, don't grant user any EXP for it */ 561 /* even though random, don't grant user any EXP for it */
580 (void) attempt_recipe (op, cauldron, 1, rp, -1); 562 (void) attempt_recipe (op, cauldron, 1, rp, -1);
581 else 563 else
582 alchemy_failure_effect (op, cauldron, rp, level - 1); 564 alchemy_failure_effect (op, cauldron, rp, level - 1);
583 return;
584
585 } 565 }
586 else if (level < 45) 566 else if (level < 45)
587 { /* INFURIATE NPC's */ 567 { /* INFURIATE NPC's */
588 /* this is kind of kludgy I know... */ 568 /* this is kind of kludgy I know... */
589 cauldron->enemy = op; 569 cauldron->enemy = op;
590 npc_call_help (cauldron); 570 npc_call_help (cauldron);
591 cauldron->enemy = NULL; 571 cauldron->enemy = NULL;
592 572
593 alchemy_failure_effect (op, cauldron, rp, level - 5); 573 alchemy_failure_effect (op, cauldron, rp, level - 5);
594 return;
595 } 574 }
596 else if (level < 50) 575 else if (level < 50)
597 { /* MINOR EXPLOSION/FIREBALL */ 576 { /* MINOR EXPLOSION/FIREBALL */
598 object *tmp; 577 object *tmp;
599 578
613 tmp->stats.hp = random_roll (1, level, op, PREFER_LOW) / 10 + 2; 592 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); 593 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name);
615 break; 594 break;
616 } 595 }
617 596
618 op->insert_at (cauldron); 597 tmp->insert_at (cauldron);
619 return;
620
621 } 598 }
622 else if (level < 60) 599 else if (level < 60)
623 { /* CREATE MONSTER */ 600 { /* CREATE MONSTER */
624 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); 601 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ());
625 remove_contents (cauldron->inv, NULL); 602 remove_contents (cauldron->inv, NULL);
626 return;
627 } 603 }
628 else if (level < 80) 604 else if (level < 80)
629 { /* MAJOR FIRE */ 605 { /* MAJOR FIRE */
630 object *fb = get_archetype (SP_MED_FIREBALL); 606 object *fb = get_archetype (SP_MED_FIREBALL);
631 607
632 remove_contents (cauldron->inv, NULL); 608 remove_contents (cauldron->inv, NULL);
633 fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb); 609 fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb);
634 fb->destroy (); 610 fb->destroy ();
635 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); 611 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name);
636 return;
637
638 } 612 }
639 else if (level < 100) 613 else if (level < 100)
640 { /* WHAMMY the CAULDRON */ 614 { /* WHAMMY the CAULDRON */
641 if (!QUERY_FLAG (cauldron, FLAG_CURSED)) 615 if (!QUERY_FLAG (cauldron, FLAG_CURSED))
642 SET_FLAG (cauldron, FLAG_CURSED); 616 SET_FLAG (cauldron, FLAG_CURSED);
643 else 617 else
644 cauldron->magic--; 618 cauldron->magic--;
619
645 cauldron->magic -= random_roll (0, 4, op, PREFER_LOW); 620 cauldron->magic -= random_roll (0, 4, op, PREFER_LOW);
621
646 if (rndm (0, 1)) 622 if (rndm (0, 1))
647 { 623 {
648 remove_contents (cauldron->inv, NULL); 624 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); 625 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s turns darker then makes a gulping sound!", &cauldron->name);
650 } 626 }
651 else 627 else
652 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s becomes darker.", &cauldron->name); 628 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s becomes darker.", &cauldron->name);
653 return;
654
655 } 629 }
656 else if (level < 110) 630 else if (level < 110)
657 { /* SUMMON EVIL MONSTERS */ 631 { /* SUMMON EVIL MONSTERS */
658 object *tmp = get_random_mon (level / 5); 632 object *tmp = get_random_mon (level / 5);
659 633
660 remove_contents (cauldron->inv, NULL); 634 remove_contents (cauldron->inv, NULL);
635
661 if (!tmp) 636 if (!tmp)
662 alchemy_failure_effect (op, cauldron, rp, level); 637 alchemy_failure_effect (op, cauldron, rp, level);
663 else if (summon_hostile_monsters (cauldron, random_roll (1, 10, op, PREFER_LOW), tmp->arch->name)) 638 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 ()); 639 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s and then pours forth monsters!", &cauldron->name, cauldron_sound ());
665 return;
666
667 } 640 }
668 else if (level < 150) 641 else if (level < 150)
669 { /* COMBO EFFECT */ 642 { /* COMBO EFFECT */
670 int roll = rndm (1, 3); 643 int roll = rndm (1, 3);
671 644
672 while (roll) 645 while (roll)
673 { 646 {
674 alchemy_failure_effect (op, cauldron, rp, level - 39); 647 alchemy_failure_effect (op, cauldron, rp, level - 39);
675 roll--; 648 roll--;
676 } 649 }
677 return;
678 } 650 }
679 else if (level == 151) 651 else if (level == 151)
680 { /* CREATE RANDOM ARTIFACT */ 652 { /* CREATE RANDOM ARTIFACT */
681 object *tmp; 653 object *tmp;
682 654
684 * in this one, we allow *any* valid alchemy artifact 656 * in this one, we allow *any* valid alchemy artifact
685 * to be made (rather than only those on the given 657 * to be made (rather than only those on the given
686 * formulalist) */ 658 * formulalist) */
687 if (!rp) 659 if (!rp)
688 rp = get_random_recipe ((recipelist *) NULL); 660 rp = get_random_recipe ((recipelist *) NULL);
661
689 if (rp && (tmp = get_archetype (rp->arch_name[RANDOM () % rp->arch_names]))) 662 if (rp && (tmp = get_archetype (rp->arch_name [rndm (rp->arch_names)])))
690 { 663 {
691 generate_artifact (tmp, random_roll (1, op->level / 2 + 1, op, PREFER_HIGH) + 1); 664 generate_artifact (tmp, random_roll (1, op->level / 2 + 1, op, PREFER_HIGH) + 1);
692 if ((tmp = insert_ob_in_ob (tmp, cauldron))) 665 if ((tmp = insert_ob_in_ob (tmp, cauldron)))
693 { 666 {
694 remove_contents (cauldron->inv, tmp); 667 remove_contents (cauldron->inv, tmp);
695 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); 668 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ());
696 } 669 }
697 } 670 }
698 return;
699 } 671 }
700 else 672 else
701 { /* MANA STORM - watch out!! */ 673 { /* MANA STORM - watch out!! */
702 object *tmp = get_archetype (LOOSE_MANA); 674 object *tmp = get_archetype (LOOSE_MANA);
703 675
704 new_draw_info (NDI_UNIQUE, 0, op, "You unwisely release potent forces!"); 676 new_draw_info (NDI_UNIQUE, 0, op, "You unwisely release potent forces!");
705 remove_contents (cauldron->inv, NULL); 677 remove_contents (cauldron->inv, NULL);
706 cast_magic_storm (op, tmp, level); 678 cast_magic_storm (op, tmp, level);
707 return;
708 } 679 }
709} 680}
710
711 681
712/* 682/*
713 * All but object "save_item" are elimentated from 683 * All but object "save_item" are elimentated from
714 * the container list. Note we have to becareful to remove the inventories 684 * 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). 685 * of objects in the cauldron inventory (ex icecube has stuff in it).
716 */ 686 */
717
718void 687void
719remove_contents (object *first_ob, object *save_item) 688remove_contents (object *first_ob, object *save_item)
720{ 689{
690 // this cries for a cleaner rewrite, removing save_item first possibly
721 object *next, *tmp = first_ob; 691 object *next, *tmp = first_ob;
722 692
723 while (tmp) 693 while (tmp)
724 { 694 {
725 next = tmp->below; 695 next = tmp->below;
738 tmp->destroy (); 708 tmp->destroy ();
739 tmp = next; 709 tmp = next;
740 } 710 }
741} 711}
742 712
743/** 713/**
744 *"Danger" level, will determine how bad the backfire 714 *"Danger" level, will determine how bad the backfire
745 * could be if the user fails to concoct a recipe properly. Factors include 715 * 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, 716 * 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 717 * 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 718 * 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 719 * 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) 720 * skill *before* this routine is called. (no longer auto-readies that skill)
751 * -b.t. 721 * -b.t.
752 */ 722 */
753
754int 723int
755calc_alch_danger (object *caster, object *cauldron, recipe *rp) 724calc_alch_danger (object *caster, object *cauldron, recipe *rp)
756{ 725{
757 object *item; 726 object *item;
758 char name[MAX_BUF]; 727 char name[MAX_BUF];
759 int danger = 0, nrofi = 0; 728 int danger = 0, nrofi = 0;
760 729
761 /* Knowing alchemy skill reduces yer risk */ 730 /* Knowing alchemy skill reduces yer risk */
762 danger -= caster->chosen_skill ? caster->chosen_skill->level : caster->level; 731 danger -= caster->chosen_skill ? caster->chosen_skill->level : caster->level;
732
733 if (!caster->chosen_skill)
734 LOG (llevError | logBacktrace, "calc_alch_danger called without a chosen skill, caster %s, cauldron %s\n",
735 caster->debug_desc (), cauldron->debug_desc ());
763 736
764 /* better cauldrons reduce risk */ 737 /* better cauldrons reduce risk */
765 danger -= cauldron->magic; 738 danger -= cauldron->magic;
766 739
767 /* Higher Int, lower the risk */ 740 /* Higher Int, lower the risk */
777 if (item->title) 750 if (item->title)
778 sprintf (name, "%s %s", &item->name, &item->title); 751 sprintf (name, "%s %s", &item->name, &item->title);
779 danger += (strtoint (name) / 1000) + 3; 752 danger += (strtoint (name) / 1000) + 3;
780 nrofi++; 753 nrofi++;
781 } 754 }
755
782 if (rp == NULL) 756 if (rp == NULL)
783 danger += 110; 757 danger += 110;
784 else 758 else
785 danger += rp->diff * 3; 759 danger += rp->diff * 3;
786 760
795#endif 769#endif
796 770
797 return danger; 771 return danger;
798} 772}
799 773
800/** 774/**
801 * Determines if ingredients in a container match the 775 * Determines if ingredients in a container match the
802 * proper ingredients for a recipe. 776 * proper ingredients for a recipe.
803 * 777 *
804 * rp is the recipe to check 778 * rp is the recipe to check
805 * cauldron is the container that holds the ingredients 779 * cauldron is the container that holds the ingredients
854 for (ob = cauldron->inv; ob != NULL; ob = ob->below) 828 for (ob = cauldron->inv; ob != NULL; ob = ob->below)
855 { 829 {
856 char name_ob[MAX_BUF]; 830 char name_ob[MAX_BUF];
857 const char *name2; 831 const char *name2;
858 832
859 if (ob->title == NULL) 833 if (!ob->title)
860 name2 = ob->name; 834 name2 = ob->name;
861 else 835 else
862 { 836 {
863 snprintf (name_ob, sizeof (name_ob), "%s %s", &ob->name, &ob->title); 837 snprintf (name_ob, sizeof (name_ob), "%s %s", &ob->name, &ob->title);
864 name2 = name_ob; 838 name2 = name_ob;
909 LOG (llevDebug, "looking for formula %d:\n", formula); 883 LOG (llevDebug, "looking for formula %d:\n", formula);
910#endif 884#endif
911 result = NULL; 885 result = NULL;
912 recipes_matching = 0; 886 recipes_matching = 0;
913 transmute_found = 0; 887 transmute_found = 0;
888
914 for (rp = fl->items; rp != NULL; rp = rp->next) 889 for (rp = fl->items; rp; rp = rp->next)
915 { 890 {
916 /* check if recipe matches at all */ 891 /* check if recipe matches at all */
917 if (formula % rp->index != 0) 892 if (formula % rp->index != 0)
918 { 893 {
919#ifdef EXTREME_ALCHEMY_DEBUG 894#ifdef EXTREME_ALCHEMY_DEBUG
920 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);
921#endif 896#endif
922 continue; 897 continue;
923 } 898 }
924 899
925 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)
926 { 901 {
927#ifdef EXTREME_ALCHEMY_DEBUG 902#ifdef EXTREME_ALCHEMY_DEBUG
928 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);
929#endif 904#endif
930 /* transmution recipe with matching base ingredient */ 905 /* transmution recipe with matching base ingredient */
931 if (!transmute_found) 906 if (!transmute_found)
932 { 907 {
933 transmute_found = 1; 908 transmute_found = 1;
935 } 910 }
936 } 911 }
937 else if (transmute_found) 912 else if (transmute_found)
938 { 913 {
939#ifdef EXTREME_ALCHEMY_DEBUG 914#ifdef EXTREME_ALCHEMY_DEBUG
940 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,
941 rp->index); 916 rp->index);
942#endif 917#endif
943 /* "normal" recipe found after previous transmution recipe => ignore this recipe */ 918 /* "normal" recipe found after previous transmution recipe => ignore this recipe */
944 continue; 919 continue;
945 } 920 }
946#ifdef EXTREME_ALCHEMY_DEBUG 921#ifdef EXTREME_ALCHEMY_DEBUG
947 else 922 else
948 { 923 {
949 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);
950 } 925 }
951#endif 926#endif
952 927
953 if (rndm (0, recipes_matching) == 0) 928 if (rndm (0, recipes_matching) == 0)
954 result = rp; 929 result = rp;
964 return NULL; 939 return NULL;
965 } 940 }
966 941
967#ifdef ALCHEMY_DEBUG 942#ifdef ALCHEMY_DEBUG
968 if (strcmp (result->title, "NONE") != 0) 943 if (strcmp (result->title, "NONE") != 0)
969 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);
970 else 945 else
971 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);
972#endif 947#endif
973 return result; 948 return result;
974} 949}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines