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.26 by root, Sun Jul 1 05:00:19 2007 UTC vs.
Revision 1.35 by elmex, Sun Jan 4 16:30:39 2009 UTC

1/* 1/*
2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Crossfire TRT 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 3 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,
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, see <http://www.gnu.org/licenses/>. 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * 20 *
21 * The authors can be reached via e-mail to <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 22 */
23 23
24/* 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 */
25 25
26#include <global.h> 26#include <global.h>
94 * around. :) 94 * around. :)
95 * -b.t. 95 * -b.t.
96 */ 96 */
97 97
98void 98void
99attempt_do_alchemy (object *caster, object *cauldron) 99attempt_do_alchemy (object *caster, object *cauldron, object *skill)
100{ 100{
101 recipelist *fl; 101 recipelist *fl;
102 recipe *rp = NULL; 102 recipe *rp = NULL;
103 float success_chance; 103 float success_chance;
104 int numb, ability = 1; 104 int numb, ability = 1;
140 return; 140 return;
141 } /* End of WIZ alchemy */ 141 } /* End of WIZ alchemy */
142 142
143 /* find the recipe */ 143 /* find the recipe */
144 rp = find_recipe (fl, formula, cauldron->inv); 144 rp = find_recipe (fl, formula, cauldron->inv);
145 if (rp) 145 if (rp
146 && rp->skill == skill->skill
147 && (!rp->cauldron
148 || rp->cauldron == cauldron->arch->archname))
146 { 149 {
147 uint64 value_ingredients; 150 uint64 value_ingredients;
148 uint64 value_item; 151 uint64 value_item;
149 object *tmp; 152 object *tmp;
150 int attempt_shadow_alchemy; 153 int attempt_shadow_alchemy;
151 154
152 ave_chance = fl->total_chance / (float) fl->number; 155 ave_chance = fl->total_chance / (float) fl->number;
153 /* the caster gets an increase in ability based on thier skill lvl */ 156
154 if (rp->skill)
155 {
156 skop = find_skill_by_name (caster, rp->skill);
157 if (!skop)
158 new_draw_info (NDI_UNIQUE, 0, caster, "You do not have the proper skill for this recipe");
159 else
160 ability += (int) (skop->level * ((4.0 + cauldron->magic) / 4.0)); 157 ability += (int) (skill->level * ((4.0 + cauldron->magic) / 4.0));
161 }
162 else
163 {
164 LOG (llevDebug, "Recipe %s has NULL skill!\n", &rp->title);
165 return;
166 }
167
168 if (!rp->cauldron)
169 {
170 LOG (llevDebug, "Recipe %s has NULL cauldron!\n", &rp->title);
171 return;
172 }
173 158
174 /* determine value of ingredients */ 159 /* determine value of ingredients */
175 value_ingredients = 0; 160 value_ingredients = 0;
176 for (tmp = cauldron->inv; tmp != NULL; tmp = tmp->below) 161 for (tmp = cauldron->inv; tmp != NULL; tmp = tmp->below)
177 value_ingredients += query_cost (tmp, NULL, F_TRUE); 162 value_ingredients += query_cost (tmp, NULL, F_TRUE);
289 object *item = NULL, *skop; 274 object *item = NULL, *skop;
290 275
291 /* this should be passed to this fctn, not effiecent cpu use this way */ 276 /* this should be passed to this fctn, not effiecent cpu use this way */
292 int batches = abs (nbatches); 277 int batches = abs (nbatches);
293 278
294
295 /* is the cauldron the right type? */ 279 /* is the cauldron the right type? */
296 if (rp->cauldron != cauldron->arch->archname) 280 if (rp->cauldron && rp->cauldron != cauldron->arch->archname)
297 {
298 new_draw_info (NDI_UNIQUE, 0, caster, "You are not using the proper" " facilities for this formula.");
299 return 0; 281 return 0;
300 }
301 282
302 skop = find_skill_by_name (caster, rp->skill); 283 skop = find_skill_by_name (caster, rp->skill);
303 /* does the caster have the skill? */ 284 /* does the caster have the skill? */
304 if (!skop) 285 if (!skop)
305 return 0; 286 return 0;
315 break; 296 break;
316 } 297 }
317 298
318 if (!tmp) 299 if (!tmp)
319 { /* failure--no code found */ 300 { /* failure--no code found */
320 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.");
321 return 0; 302 return 0;
322 } 303 }
323 } 304 }
324 305
325#ifdef EXTREME_ALCHEMY_DEBUG 306#ifdef EXTREME_ALCHEMY_DEBUG
329 310
330 if ((item = make_item_from_recipe (cauldron, rp)) != NULL) 311 if ((item = make_item_from_recipe (cauldron, rp)) != NULL)
331 { 312 {
332 remove_contents (cauldron->inv, item); 313 remove_contents (cauldron->inv, item);
333 /* 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 */
334 sum_weight (cauldron); 315 cauldron->update_weight ();
335 /* adj lvl, nrof on caster level */ 316 /* adj lvl, nrof on caster level */
336 adjust_product (item, ability, rp->yield ? (rp->yield * batches) : batches); 317 adjust_product (item, ability, rp->yield ? (rp->yield * batches) : batches);
337 if (!item->env && (item = insert_ob_in_ob (item, cauldron)) == NULL) 318 if (!item->env && (item = insert_ob_in_ob (item, cauldron)) == NULL)
338 { 319 {
339 new_draw_info (NDI_UNIQUE, 0, caster, "Nothing happened."); 320 new_draw_info (NDI_UNIQUE, 0, caster, "Nothing happened.");
403 LOG (llevDebug, "make_alchemy_item(): failed to create alchemical object.\n"); 384 LOG (llevDebug, "make_alchemy_item(): failed to create alchemical object.\n");
404 return (object *) NULL; 385 return (object *) NULL;
405 } 386 }
406 387
407 /* Find the appropriate artifact template... */ 388 /* Find the appropriate artifact template... */
408 if (strcmp (rp->title, "NONE")) 389 if (rp->title != shstr_NONE)
409 { 390 {
410 if ((art = locate_recipe_artifact (rp, rp_arch_index)) == NULL) 391 if ((art = locate_recipe_artifact (rp, rp_arch_index)) == NULL)
411 { 392 {
412 LOG (llevError, "make_alchemy_item(): failed to locate recipe artifact.\n"); 393 LOG (llevError, "make_alchemy_item(): failed to locate recipe artifact.\n");
413 LOG (llevDebug, " --requested recipe: %s of %s.\n", rp->arch_name[0], &rp->title); 394 LOG (llevDebug, " --requested recipe: %s of %s.\n", rp->arch_name[0], &rp->title);
414 return (object *) NULL; 395 return (object *) NULL;
415 } 396 }
397
416 transmute_materialname (item, art->item); 398 transmute_materialname (item, art->item);
417 give_artifact_abilities (item, art->item); 399 give_artifact_abilities (item, art->item);
418 } 400 }
419 401
420 if (QUERY_FLAG (cauldron, FLAG_CURSED)) 402 if (QUERY_FLAG (cauldron, FLAG_CURSED))
443 *rp_arch_index = 0; 425 *rp_arch_index = 0;
444 426
445 if (rp->transmute) /* look for matching ingredient/prod archs */ 427 if (rp->transmute) /* look for matching ingredient/prod archs */
446 for (item = first_ingred; item; item = item->below) 428 for (item = first_ingred; item; item = item->below)
447 { 429 {
448 size_t i; 430 int i;
449 431
450 for (i = 0; i < rp->arch_names; i++) 432 for (int i = 0; i < rp->arch_names; i++)
451 { 433 //TODO: should be a shstr comparison
452 if (item->arch->archname == rp->arch_name[i]) 434 if (&item->arch->archname == rp->arch_name[i])
453 { 435 {
454 *rp_arch_index = i; 436 *rp_arch_index = i;
455 break; 437 break;
456 } 438 }
457 }
458 439
459 if (i < rp->arch_names) 440 if (i < rp->arch_names)
460 break; 441 break;
461 } 442 }
462 443
463 /* failed, create a fresh object. Note no nrof>1 because that would 444 /* failed, create a fresh object. Note no nrof>1 because that would
464 * allow players to create massive amounts of artifacts easily */ 445 * allow players to create massive amounts of artifacts easily */
465 if (create_item && (!item || item->nrof > 1)) 446 if (create_item && (!item || item->nrof > 1))
466 { 447 {
467 *rp_arch_index = RANDOM () % rp->arch_names; 448 *rp_arch_index = rndm (rp->arch_names);
468 item = get_archetype (rp->arch_name[*rp_arch_index]); 449 item = get_archetype (rp->arch_name[*rp_arch_index]);
469 } 450 }
470 451
471#ifdef ALCHEMY_DEBUG 452#ifdef ALCHEMY_DEBUG
472 LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no "); 453 LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no ");
558 } 539 }
559 while (rndm (0, 2)); 540 while (rndm (0, 2));
560 } 541 }
561 return; 542 return;
562 } 543 }
544
563 if (level == 40) 545 if (level == 40)
564 { /* MAKE RANDOM RECIPE */ 546 { /* MAKE RANDOM RECIPE */
565 recipelist *fl; 547 recipelist *fl;
566 int numb = numb_ob_inside (cauldron); 548 int numb = numb_ob_inside (cauldron);
567 549
569 if (fl && (rp = get_random_recipe (fl))) 551 if (fl && (rp = get_random_recipe (fl)))
570 /* even though random, don't grant user any EXP for it */ 552 /* even though random, don't grant user any EXP for it */
571 (void) attempt_recipe (op, cauldron, 1, rp, -1); 553 (void) attempt_recipe (op, cauldron, 1, rp, -1);
572 else 554 else
573 alchemy_failure_effect (op, cauldron, rp, level - 1); 555 alchemy_failure_effect (op, cauldron, rp, level - 1);
574 return;
575
576 } 556 }
577 else if (level < 45) 557 else if (level < 45)
578 { /* INFURIATE NPC's */ 558 { /* INFURIATE NPC's */
579 /* this is kind of kludgy I know... */ 559 /* this is kind of kludgy I know... */
580 cauldron->enemy = op; 560 cauldron->enemy = op;
581 npc_call_help (cauldron); 561 npc_call_help (cauldron);
582 cauldron->enemy = NULL; 562 cauldron->enemy = NULL;
583 563
584 alchemy_failure_effect (op, cauldron, rp, level - 5); 564 alchemy_failure_effect (op, cauldron, rp, level - 5);
585 return;
586 } 565 }
587 else if (level < 50) 566 else if (level < 50)
588 { /* MINOR EXPLOSION/FIREBALL */ 567 { /* MINOR EXPLOSION/FIREBALL */
589 object *tmp; 568 object *tmp;
590 569
604 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;
605 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);
606 break; 585 break;
607 } 586 }
608 587
609 op->insert_at (cauldron); 588 tmp->insert_at (cauldron);
610 return;
611
612 } 589 }
613 else if (level < 60) 590 else if (level < 60)
614 { /* CREATE MONSTER */ 591 { /* CREATE MONSTER */
615 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 ());
616 remove_contents (cauldron->inv, NULL); 593 remove_contents (cauldron->inv, NULL);
617 return;
618 } 594 }
619 else if (level < 80) 595 else if (level < 80)
620 { /* MAJOR FIRE */ 596 { /* MAJOR FIRE */
621 object *fb = get_archetype (SP_MED_FIREBALL); 597 object *fb = get_archetype (SP_MED_FIREBALL);
622 598
623 remove_contents (cauldron->inv, NULL); 599 remove_contents (cauldron->inv, NULL);
624 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);
625 fb->destroy (); 601 fb->destroy ();
626 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);
627 return;
628
629 } 603 }
630 else if (level < 100) 604 else if (level < 100)
631 { /* WHAMMY the CAULDRON */ 605 { /* WHAMMY the CAULDRON */
632 if (!QUERY_FLAG (cauldron, FLAG_CURSED)) 606 if (!QUERY_FLAG (cauldron, FLAG_CURSED))
633 SET_FLAG (cauldron, FLAG_CURSED); 607 SET_FLAG (cauldron, FLAG_CURSED);
634 else 608 else
635 cauldron->magic--; 609 cauldron->magic--;
610
636 cauldron->magic -= random_roll (0, 4, op, PREFER_LOW); 611 cauldron->magic -= random_roll (0, 4, op, PREFER_LOW);
612
637 if (rndm (0, 1)) 613 if (rndm (0, 1))
638 { 614 {
639 remove_contents (cauldron->inv, NULL); 615 remove_contents (cauldron->inv, NULL);
640 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);
641 } 617 }
642 else 618 else
643 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);
644 return;
645
646 } 620 }
647 else if (level < 110) 621 else if (level < 110)
648 { /* SUMMON EVIL MONSTERS */ 622 { /* SUMMON EVIL MONSTERS */
649 object *tmp = get_random_mon (level / 5); 623 object *tmp = get_random_mon (level / 5);
650 624
651 remove_contents (cauldron->inv, NULL); 625 remove_contents (cauldron->inv, NULL);
626
652 if (!tmp) 627 if (!tmp)
653 alchemy_failure_effect (op, cauldron, rp, level); 628 alchemy_failure_effect (op, cauldron, rp, level);
654 else if (summon_hostile_monsters (cauldron, random_roll (1, 10, op, PREFER_LOW), tmp->arch->archname)) 629 else if (summon_hostile_monsters (cauldron, random_roll (1, 10, op, PREFER_LOW), tmp->arch->archname))
655 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 ());
656 return;
657
658 } 631 }
659 else if (level < 150) 632 else if (level < 150)
660 { /* COMBO EFFECT */ 633 { /* COMBO EFFECT */
661 int roll = rndm (1, 3); 634 int roll = rndm (1, 3);
662 635
663 while (roll) 636 while (roll)
664 { 637 {
665 alchemy_failure_effect (op, cauldron, rp, level - 39); 638 alchemy_failure_effect (op, cauldron, rp, level - 39);
666 roll--; 639 roll--;
667 } 640 }
668 return;
669 } 641 }
670 else if (level == 151) 642 else if (level == 151)
671 { /* CREATE RANDOM ARTIFACT */ 643 { /* CREATE RANDOM ARTIFACT */
672 object *tmp; 644 object *tmp;
673 645
675 * in this one, we allow *any* valid alchemy artifact 647 * in this one, we allow *any* valid alchemy artifact
676 * to be made (rather than only those on the given 648 * to be made (rather than only those on the given
677 * formulalist) */ 649 * formulalist) */
678 if (!rp) 650 if (!rp)
679 rp = get_random_recipe ((recipelist *) NULL); 651 rp = get_random_recipe ((recipelist *) NULL);
652
680 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)])))
681 { 654 {
682 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);
683 if ((tmp = insert_ob_in_ob (tmp, cauldron))) 656 if ((tmp = insert_ob_in_ob (tmp, cauldron)))
684 { 657 {
685 remove_contents (cauldron->inv, tmp); 658 remove_contents (cauldron->inv, tmp);
686 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 ());
687 } 660 }
688 } 661 }
689 return;
690 } 662 }
691 else 663 else
692 { /* MANA STORM - watch out!! */ 664 { /* MANA STORM - watch out!! */
693 object *tmp = get_archetype (LOOSE_MANA); 665 object *tmp = get_archetype (LOOSE_MANA);
694 666
695 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!");
696 remove_contents (cauldron->inv, NULL); 668 remove_contents (cauldron->inv, NULL);
697 cast_magic_storm (op, tmp, level); 669 cast_magic_storm (op, tmp, level);
698 return;
699 } 670 }
700} 671}
701
702 672
703/* 673/*
704 * All but object "save_item" are elimentated from 674 * All but object "save_item" are elimentated from
705 * 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
706 * 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).
707 */ 677 */
708
709void 678void
710remove_contents (object *first_ob, object *save_item) 679remove_contents (object *first_ob, object *save_item)
711{ 680{
681 // this cries for a cleaner rewrite, removing save_item first possibly
712 object *next, *tmp = first_ob; 682 object *next, *tmp = first_ob;
713 683
714 while (tmp) 684 while (tmp)
715 { 685 {
716 next = tmp->below; 686 next = tmp->below;
849 for (ob = cauldron->inv; ob != NULL; ob = ob->below) 819 for (ob = cauldron->inv; ob != NULL; ob = ob->below)
850 { 820 {
851 char name_ob[MAX_BUF]; 821 char name_ob[MAX_BUF];
852 const char *name2; 822 const char *name2;
853 823
854 if (ob->title == NULL) 824 if (!ob->title)
855 name2 = ob->name; 825 name2 = ob->name;
856 else 826 else
857 { 827 {
858 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);
859 name2 = name_ob; 829 name2 = name_ob;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines