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.23 by root, Tue May 1 05:48:20 2007 UTC vs.
Revision 1.35 by elmex, Sun Jan 4 16:30:39 2009 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game 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);
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 ");
559 } 539 }
560 while (rndm (0, 2)); 540 while (rndm (0, 2));
561 } 541 }
562 return; 542 return;
563 } 543 }
544
564 if (level == 40) 545 if (level == 40)
565 { /* MAKE RANDOM RECIPE */ 546 { /* MAKE RANDOM RECIPE */
566 recipelist *fl; 547 recipelist *fl;
567 int numb = numb_ob_inside (cauldron); 548 int numb = numb_ob_inside (cauldron);
568 549
570 if (fl && (rp = get_random_recipe (fl))) 551 if (fl && (rp = get_random_recipe (fl)))
571 /* even though random, don't grant user any EXP for it */ 552 /* even though random, don't grant user any EXP for it */
572 (void) attempt_recipe (op, cauldron, 1, rp, -1); 553 (void) attempt_recipe (op, cauldron, 1, rp, -1);
573 else 554 else
574 alchemy_failure_effect (op, cauldron, rp, level - 1); 555 alchemy_failure_effect (op, cauldron, rp, level - 1);
575 return;
576
577 } 556 }
578 else if (level < 45) 557 else if (level < 45)
579 { /* INFURIATE NPC's */ 558 { /* INFURIATE NPC's */
580 /* this is kind of kludgy I know... */ 559 /* this is kind of kludgy I know... */
581 cauldron->enemy = op; 560 cauldron->enemy = op;
582 npc_call_help (cauldron); 561 npc_call_help (cauldron);
583 cauldron->enemy = NULL; 562 cauldron->enemy = NULL;
584 563
585 alchemy_failure_effect (op, cauldron, rp, level - 5); 564 alchemy_failure_effect (op, cauldron, rp, level - 5);
586 return;
587 } 565 }
588 else if (level < 50) 566 else if (level < 50)
589 { /* MINOR EXPLOSION/FIREBALL */ 567 { /* MINOR EXPLOSION/FIREBALL */
590 object *tmp; 568 object *tmp;
591 569
605 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;
606 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);
607 break; 585 break;
608 } 586 }
609 587
610 op->insert_at (cauldron); 588 tmp->insert_at (cauldron);
611 return;
612
613 } 589 }
614 else if (level < 60) 590 else if (level < 60)
615 { /* CREATE MONSTER */ 591 { /* CREATE MONSTER */
616 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 ());
617 remove_contents (cauldron->inv, NULL); 593 remove_contents (cauldron->inv, NULL);
618 return;
619 } 594 }
620 else if (level < 80) 595 else if (level < 80)
621 { /* MAJOR FIRE */ 596 { /* MAJOR FIRE */
622 object *fb = get_archetype (SP_MED_FIREBALL); 597 object *fb = get_archetype (SP_MED_FIREBALL);
623 598
624 remove_contents (cauldron->inv, NULL); 599 remove_contents (cauldron->inv, NULL);
625 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);
626 fb->destroy (); 601 fb->destroy ();
627 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);
628 return;
629
630 } 603 }
631 else if (level < 100) 604 else if (level < 100)
632 { /* WHAMMY the CAULDRON */ 605 { /* WHAMMY the CAULDRON */
633 if (!QUERY_FLAG (cauldron, FLAG_CURSED)) 606 if (!QUERY_FLAG (cauldron, FLAG_CURSED))
634 SET_FLAG (cauldron, FLAG_CURSED); 607 SET_FLAG (cauldron, FLAG_CURSED);
635 else 608 else
636 cauldron->magic--; 609 cauldron->magic--;
610
637 cauldron->magic -= random_roll (0, 4, op, PREFER_LOW); 611 cauldron->magic -= random_roll (0, 4, op, PREFER_LOW);
612
638 if (rndm (0, 1)) 613 if (rndm (0, 1))
639 { 614 {
640 remove_contents (cauldron->inv, NULL); 615 remove_contents (cauldron->inv, NULL);
641 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);
642 } 617 }
643 else 618 else
644 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);
645 return;
646
647 } 620 }
648 else if (level < 110) 621 else if (level < 110)
649 { /* SUMMON EVIL MONSTERS */ 622 { /* SUMMON EVIL MONSTERS */
650 object *tmp = get_random_mon (level / 5); 623 object *tmp = get_random_mon (level / 5);
651 624
652 remove_contents (cauldron->inv, NULL); 625 remove_contents (cauldron->inv, NULL);
626
653 if (!tmp) 627 if (!tmp)
654 alchemy_failure_effect (op, cauldron, rp, level); 628 alchemy_failure_effect (op, cauldron, rp, level);
655 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))
656 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 ());
657 return;
658
659 } 631 }
660 else if (level < 150) 632 else if (level < 150)
661 { /* COMBO EFFECT */ 633 { /* COMBO EFFECT */
662 int roll = rndm (1, 3); 634 int roll = rndm (1, 3);
663 635
664 while (roll) 636 while (roll)
665 { 637 {
666 alchemy_failure_effect (op, cauldron, rp, level - 39); 638 alchemy_failure_effect (op, cauldron, rp, level - 39);
667 roll--; 639 roll--;
668 } 640 }
669 return;
670 } 641 }
671 else if (level == 151) 642 else if (level == 151)
672 { /* CREATE RANDOM ARTIFACT */ 643 { /* CREATE RANDOM ARTIFACT */
673 object *tmp; 644 object *tmp;
674 645
676 * in this one, we allow *any* valid alchemy artifact 647 * in this one, we allow *any* valid alchemy artifact
677 * to be made (rather than only those on the given 648 * to be made (rather than only those on the given
678 * formulalist) */ 649 * formulalist) */
679 if (!rp) 650 if (!rp)
680 rp = get_random_recipe ((recipelist *) NULL); 651 rp = get_random_recipe ((recipelist *) NULL);
652
681 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)])))
682 { 654 {
683 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);
684 if ((tmp = insert_ob_in_ob (tmp, cauldron))) 656 if ((tmp = insert_ob_in_ob (tmp, cauldron)))
685 { 657 {
686 remove_contents (cauldron->inv, tmp); 658 remove_contents (cauldron->inv, tmp);
687 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 ());
688 } 660 }
689 } 661 }
690 return;
691 } 662 }
692 else 663 else
693 { /* MANA STORM - watch out!! */ 664 { /* MANA STORM - watch out!! */
694 object *tmp = get_archetype (LOOSE_MANA); 665 object *tmp = get_archetype (LOOSE_MANA);
695 666
696 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!");
697 remove_contents (cauldron->inv, NULL); 668 remove_contents (cauldron->inv, NULL);
698 cast_magic_storm (op, tmp, level); 669 cast_magic_storm (op, tmp, level);
699 return;
700 } 670 }
701} 671}
702
703 672
704/* 673/*
705 * All but object "save_item" are elimentated from 674 * All but object "save_item" are elimentated from
706 * 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
707 * 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).
708 */ 677 */
709
710void 678void
711remove_contents (object *first_ob, object *save_item) 679remove_contents (object *first_ob, object *save_item)
712{ 680{
681 // this cries for a cleaner rewrite, removing save_item first possibly
713 object *next, *tmp = first_ob; 682 object *next, *tmp = first_ob;
714 683
715 while (tmp) 684 while (tmp)
716 { 685 {
717 next = tmp->below; 686 next = tmp->below;
850 for (ob = cauldron->inv; ob != NULL; ob = ob->below) 819 for (ob = cauldron->inv; ob != NULL; ob = ob->below)
851 { 820 {
852 char name_ob[MAX_BUF]; 821 char name_ob[MAX_BUF];
853 const char *name2; 822 const char *name2;
854 823
855 if (ob->title == NULL) 824 if (!ob->title)
856 name2 = ob->name; 825 name2 = ob->name;
857 else 826 else
858 { 827 {
859 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);
860 name2 = name_ob; 829 name2 = name_ob;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines