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.53 by root, Wed Apr 28 19:59:06 2010 UTC vs.
Revision 1.59 by root, Tue Jan 3 11:25:35 2012 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the 9 * the terms of the Affero GNU General Public License as published by the
63 63
64/** Returns a random selection from cauldron_effect[] */ 64/** Returns a random selection from cauldron_effect[] */
65static const char * 65static const char *
66cauldron_sound () 66cauldron_sound ()
67{ 67{
68 int size = sizeof (cauldron_effect) / sizeof (char *); 68 return cauldron_effect [rndm (array_length (cauldron_effect))];
69
70 return cauldron_effect[rndm (0, size - 1)];
71} 69}
72 70
73/** 71/**
74 * Recipe value of the entire contents of a container. 72 * Recipe value of the entire contents of a container.
75 * This appears to just generate a hash value, which I guess for now works 73 * This appears to just generate a hash value, which I guess for now works
168 &prod_item->arch->archname, prod_item->nrof); 166 &prod_item->arch->archname, prod_item->nrof);
169 } 167 }
170#endif 168#endif
171 if (!prod_item) 169 if (!prod_item)
172 *rp_arch_index = rndm (rp->arch_names); 170 *rp_arch_index = rndm (rp->arch_names);
173 prod_item = get_archetype (rp->arch_name[*rp_arch_index]); 171 prod_item = archetype::get (rp->arch_name[*rp_arch_index]);
174 } 172 }
175 173
176#ifdef ALCHEMY_DEBUG 174#ifdef ALCHEMY_DEBUG
177 LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no "); 175 LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no ");
178 if (prod_item != NULL) 176 if (prod_item != NULL)
342 { 340 {
343 remove_contents (cauldron->inv, item); 341 remove_contents (cauldron->inv, item);
344 /* Recalc carrying of the cauldron, in case recipe did not conserve mass */ 342 /* Recalc carrying of the cauldron, in case recipe did not conserve mass */
345 cauldron->update_weight (); 343 cauldron->update_weight ();
346 /* adj lvl, nrof on caster level */ 344 /* adj lvl, nrof on caster level */
347 adjust_product (item, ability, rp->yield ? (rp->yield * batches) : batches); 345 adjust_product (item, ability, rp->yield ? rp->yield * batches : batches);
346
348 if (!item->env && (item = insert_ob_in_ob (item, cauldron)) == NULL) 347 if (!item->env && (item = insert_ob_in_ob (item, cauldron)) == NULL)
349 { 348 {
350 new_draw_info (NDI_UNIQUE, 0, caster, "Nothing happened."); 349 new_draw_info (NDI_UNIQUE, 0, caster, "Nothing happened.");
351 /* new_draw_info_format(NDI_UNIQUE, 0,caster, 350 /* new_draw_info_format(NDI_UNIQUE, 0,caster,
352 "Your spell causes the %s to explode!",&cauldron->name); */ 351 "Your spell causes the %s to explode!",&cauldron->name); */
389 if (rndm (0, 2)) 388 if (rndm (0, 2))
390 { /* slag created */ 389 { /* slag created */
391 object *tmp = cauldron->inv; 390 object *tmp = cauldron->inv;
392 int weight = 0; 391 int weight = 0;
393 392
394 tmp = get_archetype (shstr_rock); 393 tmp = archetype::get (shstr_rock);
395 tmp->weight = weight; 394 tmp->weight = weight;
396 tmp->value = 0; 395 tmp->value = 0;
397 tmp->material = name_to_material (shstr_stone); 396 tmp->material = name_to_material (shstr_stone);
398 tmp->name = shstr_slag; 397 tmp->name = shstr_slag;
399 tmp->name_pl = shstr_slags; 398 tmp->name_pl = shstr_slags;
466 465
467 remove_contents (cauldron->inv, NULL); 466 remove_contents (cauldron->inv, NULL);
468 switch (rndm (0, 2)) 467 switch (rndm (0, 2))
469 { 468 {
470 case 0: 469 case 0:
471 tmp = get_archetype (shstr_bomb); 470 tmp = archetype::get (shstr_bomb);
472 tmp->stats.dam = random_roll (1, level, op, PREFER_LOW); 471 tmp->stats.dam = random_roll (1, level, op, PREFER_LOW);
473 tmp->stats.hp = random_roll (1, level, op, PREFER_LOW); 472 tmp->stats.hp = random_roll (1, level, op, PREFER_LOW);
474 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s creates a bomb!", &cauldron->name); 473 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s creates a bomb!", &cauldron->name);
475 break; 474 break;
476 475
477 default: 476 default:
478 tmp = get_archetype (shstr_fireball); 477 tmp = archetype::get (shstr_fireball);
479 tmp->stats.dam = random_roll (1, level, op, PREFER_LOW) / 5 + 1; 478 tmp->stats.dam = random_roll (1, level, op, PREFER_LOW) / 5 + 1;
480 tmp->stats.hp = random_roll (1, level, op, PREFER_LOW) / 10 + 2; 479 tmp->stats.hp = random_roll (1, level, op, PREFER_LOW) / 10 + 2;
481 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); 480 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name);
482 break; 481 break;
483 } 482 }
489 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); 488 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ());
490 remove_contents (cauldron->inv, NULL); 489 remove_contents (cauldron->inv, NULL);
491 } 490 }
492 else if (level < 80) 491 else if (level < 80)
493 { /* MAJOR FIRE */ 492 { /* MAJOR FIRE */
494 object *fb = get_archetype (SP_MED_FIREBALL); 493 object *fb = archetype::get (SP_MED_FIREBALL);
495 494
496 remove_contents (cauldron->inv, NULL); 495 remove_contents (cauldron->inv, NULL);
497 fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb); 496 fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb);
498 fb->destroy (); 497 fb->destroy ();
499 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); 498 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name);
545 * to be made (rather than only those on the given 544 * to be made (rather than only those on the given
546 * formulalist) */ 545 * formulalist) */
547 if (!rp) 546 if (!rp)
548 rp = get_random_recipe ((recipelist *) NULL); 547 rp = get_random_recipe ((recipelist *) NULL);
549 548
550 if (rp && (tmp = get_archetype (rp->arch_name [rndm (rp->arch_names)]))) 549 if (rp && (tmp = archetype::get (rp->arch_name [rndm (rp->arch_names)])))
551 { 550 {
552 generate_artifact (tmp, random_roll (1, op->level / 2 + 1, op, PREFER_HIGH) + 1); 551 generate_artifact (tmp, random_roll (1, op->level / 2 + 1, op, PREFER_HIGH) + 1);
553 if ((tmp = insert_ob_in_ob (tmp, cauldron))) 552 if ((tmp = insert_ob_in_ob (tmp, cauldron)))
554 { 553 {
555 remove_contents (cauldron->inv, tmp); 554 remove_contents (cauldron->inv, tmp);
557 } 556 }
558 } 557 }
559 } 558 }
560 else 559 else
561 { /* MANA STORM - watch out!! */ 560 { /* MANA STORM - watch out!! */
562 object *tmp = get_archetype (LOOSE_MANA); 561 object *tmp = archetype::get (LOOSE_MANA);
563 562
564 new_draw_info (NDI_UNIQUE, 0, op, "You unwisely release potent forces!"); 563 new_draw_info (NDI_UNIQUE, 0, op, "You unwisely release potent forces!");
565 remove_contents (cauldron->inv, NULL); 564 remove_contents (cauldron->inv, NULL);
566 cast_magic_storm (op, tmp, level); 565 cast_magic_storm (op, tmp, level);
567 } 566 }
576 * danger. Note that we assume that we have had the caster ready the alchemy 575 * danger. Note that we assume that we have had the caster ready the alchemy
577 * skill *before* this routine is called. (no longer auto-readies that skill) 576 * skill *before* this routine is called. (no longer auto-readies that skill)
578 * -b.t. 577 * -b.t.
579 */ 578 */
580static int 579static int
581calc_alch_danger (object *caster, object *cauldron, recipe *rp) 580calc_alch_danger (object *caster, object *cauldron, object *skill, recipe *rp)
582{ 581{
583 object *item;
584 char name[MAX_BUF];
585 int danger = 0, nrofi = 0; 582 int danger = 0;
586 583
587 /* Knowing alchemy skill reduces yer risk */ 584 /* Knowing alchemy skill reduces yer risk */
588 danger -= caster->chosen_skill ? caster->chosen_skill->level : caster->level; 585 danger -= skill->level;
589
590 if (!caster->chosen_skill)
591 LOG (llevError | logBacktrace, "calc_alch_danger called without a chosen skill, caster %s, cauldron %s\n",
592 caster->debug_desc (), cauldron->debug_desc ());
593 586
594 /* better cauldrons reduce risk */ 587 /* better cauldrons reduce risk */
595 danger -= cauldron->magic; 588 danger -= cauldron->magic;
596 589
597 /* Higher Int, lower the risk */ 590 /* Higher Int, lower the risk */
599 592
600 /* Ingredients. Longer names usually mean rarer stuff. 593 /* Ingredients. Longer names usually mean rarer stuff.
601 * Thus the backfire is worse. Also, more ingredients 594 * Thus the backfire is worse. Also, more ingredients
602 * means we are attempting a more powerfull potion, 595 * means we are attempting a more powerfull potion,
603 * and thus the backfire will be worse. */ 596 * and thus the backfire will be worse. */
604 for (item = cauldron->inv; item; item = item->below) 597 for (object *item = cauldron->inv; item; item = item->below)
605 { 598 {
606 assign (name, item->name); 599 const char *name = item->title
607 if (item->title)
608 sprintf (name, "%s %s", &item->name, &item->title); 600 ? format ("%s %s", &item->name, &item->title)
601 : &item->name;
602
609 danger += (strtoint (name) / 1000) + 3; 603 danger += strtoint (name) / 1000 + 3;
610 nrofi++;
611 } 604 }
612 605
613 if (rp == NULL) 606 if (!rp)
614 danger += 110; 607 danger += 110;
615 else 608 else
616 danger += rp->diff * 3; 609 danger += rp->diff * 3;
617 610
618 /* Using a bad device is *majorly* stupid */ 611 /* Using a bad device is *majorly* stupid */
619 if (cauldron->flag [FLAG_CURSED]) 612 if (cauldron->flag [FLAG_CURSED]) danger += 80;
620 danger += 80;
621 if (cauldron->flag [FLAG_DAMNED]) 613 if (cauldron->flag [FLAG_DAMNED]) danger += 200;
622 danger += 200;
623 614
624#ifdef ALCHEMY_DEBUG 615#ifdef ALCHEMY_DEBUG
625 LOG (llevDebug, "calc_alch_danger() returned danger=%d\n", danger); 616 LOG (llevDebug, "calc_alch_danger() returned danger=%d\n", danger);
626#endif 617#endif
627 618
898 889
899 /* create the object **FIRST**, then decide whether to keep it. */ 890 /* create the object **FIRST**, then decide whether to keep it. */
900 if ((item = attempt_recipe (caster, cauldron, ability, rp, formula / rp->index)) != NULL) 891 if ((item = attempt_recipe (caster, cauldron, ability, rp, formula / rp->index)) != NULL)
901 { 892 {
902 /* compute base chance of recipe success */ 893 /* compute base chance of recipe success */
903 success_chance = ((float) ability / (float) (rp->diff * (item->level + 2))); 894 success_chance = ((float)ability / (float)(rp->diff * (item->level + 2)));
904 if (ave_chance == 0) 895 if (ave_chance == 0)
905 ave_chance = 1; 896 ave_chance = 1;
906 897
907#ifdef ALCHEMY_DEBUG 898#ifdef ALCHEMY_DEBUG
908 LOG (llevDebug, "percent success chance = %f ab%d / diff%d*lev%d\n", success_chance, ability, rp->diff, item->level); 899 LOG (llevDebug, "percent success chance = %f ab%d / diff%d*lev%d\n", success_chance, ability, rp->diff, item->level);
930 } 921 }
931 } 922 }
932 } 923 }
933 924
934 /* if we get here, we failed!! */ 925 /* if we get here, we failed!! */
935 alchemy_failure_effect (caster, cauldron, rp, calc_alch_danger (caster, cauldron, rp)); 926 alchemy_failure_effect (caster, cauldron, rp, calc_alch_danger (caster, cauldron, skill, rp));
936} 927}
937 928

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines