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.55 by root, Thu May 6 22:08:07 2010 UTC vs.
Revision 1.67 by root, Tue May 10 11:02:56 2022 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 (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 5 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team 6 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992 Frank Tore Johansen 7 * Copyright (©) 1992 Frank Tore Johansen
7 * 8 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 9 * 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 10 * the terms of the Affero GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your 11 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 12 * option) any later version.
12 * 13 *
13 * This program is distributed in the hope that it will be useful, 14 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 17 * GNU General Public License for more details.
17 * 18 *
18 * You should have received a copy of the Affero GNU General Public License 19 * You should have received a copy of the Affero GNU General Public License
19 * and the GNU General Public License along with this program. If not, see 20 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>. 21 * <http://www.gnu.org/licenses/>.
21 * 22 *
22 * The authors can be reached via e-mail to <support@deliantra.net> 23 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 24 */
24 25
25/* March 96 - Laid down original code. -b.t. thomas@astro.psu.edu */ 26/* March 96 - Laid down original code. -b.t. thomas@astro.psu.edu */
26 27
63 64
64/** Returns a random selection from cauldron_effect[] */ 65/** Returns a random selection from cauldron_effect[] */
65static const char * 66static const char *
66cauldron_sound () 67cauldron_sound ()
67{ 68{
68 return cauldron_effect [rndm (array_length (cauldron_effect))]; 69 return cauldron_effect [rndm (ecb_array_length (cauldron_effect))];
69} 70}
70 71
71/** 72/**
72 * Recipe value of the entire contents of a container. 73 * Recipe value of the entire contents of a container.
73 * This appears to just generate a hash value, which I guess for now works 74 * This appears to just generate a hash value, which I guess for now works
133 */ 134 */
134static object * 135static object *
135find_transmution_ob (object *first_ingred, recipe *rp, size_t *rp_arch_index, int create_item) 136find_transmution_ob (object *first_ingred, recipe *rp, size_t *rp_arch_index, int create_item)
136{ 137{
137 object *prod_item = 0; 138 object *prod_item = 0;
138 bool found = false;
139 *rp_arch_index = 0; 139 *rp_arch_index = 0;
140 140
141 if (rp->transmute) /* look for matching ingredient/prod archs */ 141 if (rp->transmute) /* look for matching ingredient/prod archs */
142 for (object *item = first_ingred; item; item = item->below) 142 for (object *item = first_ingred; item; item = item->below)
143 { 143 {
166 &prod_item->arch->archname, prod_item->nrof); 166 &prod_item->arch->archname, prod_item->nrof);
167 } 167 }
168#endif 168#endif
169 if (!prod_item) 169 if (!prod_item)
170 *rp_arch_index = rndm (rp->arch_names); 170 *rp_arch_index = rndm (rp->arch_names);
171 prod_item = get_archetype (rp->arch_name[*rp_arch_index]); 171 prod_item = archetype::get (rp->arch_name[*rp_arch_index]);
172 } 172 }
173 173
174#ifdef ALCHEMY_DEBUG 174#ifdef ALCHEMY_DEBUG
175 LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no "); 175 LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no ");
176 if (prod_item != NULL) 176 if (prod_item != NULL)
232} 232}
233 233
234/* 234/*
235 * All but object "save_item" are elimentated from 235 * All but object "save_item" are elimentated from
236 * the container list. Note we have to becareful to remove the inventories 236 * the container list. Note we have to becareful to remove the inventories
237 * of objects in the cauldron inventory (ex icecube has stuff in it). 237 * of objects in the cauldron inventory (ex icecube has stuff in it).
238 */ 238 */
239static void 239static void
240remove_contents (object *first_ob, object *save_item) 240remove_contents (object *first_ob, object *save_item)
241{ 241{
242 // this cries for a cleaner rewrite, removing save_item first possibly 242 // this cries for a cleaner rewrite, removing save_item first possibly
287 item->nrof = nrof; 287 item->nrof = nrof;
288 } 288 }
289} 289}
290 290
291/** 291/**
292 * Essentially a wrapper for make_item_from_recipe() and 292 * Essentially a wrapper for make_item_from_recipe() and
293 * insert_ob_in_ob. If the caster has some alchemy skill, then they might 293 * insert_ob_in_ob. If the caster has some alchemy skill, then they might
294 * gain some exp from (successfull) fabrication of the product. 294 * gain some exp from (successfull) fabrication of the product.
295 * If nbatches==-1, don't give exp for this creation (random generation/ 295 * If nbatches==-1, don't give exp for this creation (random generation/
296 * failed recipe) 296 * failed recipe)
297 */ 297 */
298static object * 298static object *
299attempt_recipe (object *caster, object *cauldron, int ability, recipe *rp, int nbatches) 299attempt_recipe (object *caster, object *cauldron, int ability, recipe *rp, int nbatches)
340 { 340 {
341 remove_contents (cauldron->inv, item); 341 remove_contents (cauldron->inv, item);
342 /* 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 */
343 cauldron->update_weight (); 343 cauldron->update_weight ();
344 /* adj lvl, nrof on caster level */ 344 /* adj lvl, nrof on caster level */
345 adjust_product (item, ability, rp->yield ? (rp->yield * batches) : batches); 345 adjust_product (item, ability, rp->yield ? rp->yield * batches : batches);
346
346 if (!item->env && (item = insert_ob_in_ob (item, cauldron)) == NULL) 347 if (!item->env && (item = insert_ob_in_ob (item, cauldron)) == NULL)
347 { 348 {
348 new_draw_info (NDI_UNIQUE, 0, caster, "Nothing happened."); 349 new_draw_info (NDI_UNIQUE, 0, caster, "Nothing happened.");
349 /* new_draw_info_format(NDI_UNIQUE, 0,caster, 350 /* new_draw_info_format(NDI_UNIQUE, 0,caster,
350 "Your spell causes the %s to explode!",&cauldron->name); */ 351 "Your spell causes the %s to explode!",&cauldron->name); */
387 if (rndm (0, 2)) 388 if (rndm (0, 2))
388 { /* slag created */ 389 { /* slag created */
389 object *tmp = cauldron->inv; 390 object *tmp = cauldron->inv;
390 int weight = 0; 391 int weight = 0;
391 392
392 tmp = get_archetype (shstr_rock); 393 tmp = archetype::get (shstr_rock);
393 tmp->weight = weight; 394 tmp->weight = weight;
394 tmp->value = 0; 395 tmp->value = 0;
395 tmp->material = name_to_material (shstr_stone); 396 tmp->material = name_to_material (shstr_stone);
396 tmp->name = shstr_slag; 397 tmp->name = shstr_slag;
397 tmp->name_pl = shstr_slags; 398 tmp->name_pl = shstr_slags;
464 465
465 remove_contents (cauldron->inv, NULL); 466 remove_contents (cauldron->inv, NULL);
466 switch (rndm (0, 2)) 467 switch (rndm (0, 2))
467 { 468 {
468 case 0: 469 case 0:
469 tmp = get_archetype (shstr_bomb); 470 tmp = archetype::get (shstr_bomb);
470 tmp->stats.dam = random_roll (1, level, op, PREFER_LOW); 471 tmp->stats.dam = random_roll (1, level, op, PREFER_LOW);
471 tmp->stats.hp = random_roll (1, level, op, PREFER_LOW); 472 tmp->stats.hp = random_roll (1, level, op, PREFER_LOW);
472 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);
473 break; 474 break;
474 475
475 default: 476 default:
476 tmp = get_archetype (shstr_fireball); 477 tmp = archetype::get (shstr_fireball);
477 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;
478 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;
479 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);
480 break; 481 break;
481 } 482 }
487 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 ());
488 remove_contents (cauldron->inv, NULL); 489 remove_contents (cauldron->inv, NULL);
489 } 490 }
490 else if (level < 80) 491 else if (level < 80)
491 { /* MAJOR FIRE */ 492 { /* MAJOR FIRE */
492 object *fb = get_archetype (SP_MED_FIREBALL); 493 object *fb = archetype::get (SP_MED_FIREBALL);
493 494
494 remove_contents (cauldron->inv, NULL); 495 remove_contents (cauldron->inv, NULL);
495 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);
496 fb->destroy (); 497 fb->destroy ();
497 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);
536 } 537 }
537 else if (level == 151) 538 else if (level == 151)
538 { /* CREATE RANDOM ARTIFACT */ 539 { /* CREATE RANDOM ARTIFACT */
539 object *tmp; 540 object *tmp;
540 541
541 /* this is meant to be better than prior possiblity, 542 /* this is meant to be better than prior possiblity,
542 * in this one, we allow *any* valid alchemy artifact 543 * in this one, we allow *any* valid alchemy artifact
543 * to be made (rather than only those on the given 544 * to be made (rather than only those on the given
544 * formulalist) */ 545 * formulalist) */
545 if (!rp) 546 if (!rp)
546 rp = get_random_recipe ((recipelist *) NULL); 547 rp = get_random_recipe ((recipelist *) NULL);
547 548
548 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)])))
549 { 550 {
550 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);
551 if ((tmp = insert_ob_in_ob (tmp, cauldron))) 552 if ((tmp = insert_ob_in_ob (tmp, cauldron)))
552 { 553 {
553 remove_contents (cauldron->inv, tmp); 554 remove_contents (cauldron->inv, tmp);
555 } 556 }
556 } 557 }
557 } 558 }
558 else 559 else
559 { /* MANA STORM - watch out!! */ 560 { /* MANA STORM - watch out!! */
560 object *tmp = get_archetype (LOOSE_MANA); 561 object *tmp = archetype::get (LOOSE_MANA);
561 562
562 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!");
563 remove_contents (cauldron->inv, NULL); 564 remove_contents (cauldron->inv, NULL);
564 cast_magic_storm (op, tmp, level); 565 cast_magic_storm (op, tmp, level);
565 } 566 }
570 * could be if the user fails to concoct a recipe properly. Factors include 571 * could be if the user fails to concoct a recipe properly. Factors include
571 * the number of ingredients, the length of the name of each ingredient, 572 * the number of ingredients, the length of the name of each ingredient,
572 * the user's effective level, the user's Int and the enchantment on the 573 * the user's effective level, the user's Int and the enchantment on the
573 * mixing device (aka "cauldron"). Higher values of 'danger' indicate more 574 * mixing device (aka "cauldron"). Higher values of 'danger' indicate more
574 * 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
575 * 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)
576 * -b.t. 577 * -b.t.
577 */ 578 */
578static int 579static int
579calc_alch_danger (object *caster, object *cauldron, object *skill, recipe *rp) 580calc_alch_danger (object *caster, object *cauldron, object *skill, recipe *rp)
580{ 581{
581 int danger = 0; 582 int danger = 0;
795 return result; 796 return result;
796} 797}
797 798
798/** 799/**
799 * Main part of the ALCHEMY code. From this we call fctns 800 * Main part of the ALCHEMY code. From this we call fctns
800 * that take a look at the contents of the 'cauldron' and, using these ingredients, 801 * that take a look at the contents of the 'cauldron' and, using these ingredients,
801 * we construct an integer formula value which is referenced (randomly) against a 802 * we construct an integer formula value which is referenced (randomly) against a
802 * formula list (the formula list chosen is based on the # contents of the cauldron). 803 * formula list (the formula list chosen is based on the # contents of the cauldron).
803 * 804 *
804 * If we get a match between the recipe indicated in cauldron contents and a 805 * If we get a match between the recipe indicated in cauldron contents and a
805 * randomly chosen one, an item is created and experience awarded. Otherwise 806 * randomly chosen one, an item is created and experience awarded. Otherwise
806 * various failure effects are possible (getting worse and worse w/ # cauldron 807 * various failure effects are possible (getting worse and worse w/ # cauldron
807 * ingredients). Note that the 'item' to be made can be *anything* listed on 808 * ingredients). Note that the 'item' to be made can be *anything* listed on
808 * the artifacts list in lib/artifacts which has a recipe listed in lib/formulae. 809 * the artifacts list in lib/artifacts which has a recipe listed in lib/formulae.
809 * 810 *
810 * To those wondering why I am using the funky formula index method: 811 * To those wondering why I am using the funky formula index method:
811 * 1) I want to match recipe to ingredients regardless of ordering. 812 * 1) I want to match recipe to ingredients regardless of ordering.
812 * 2) I want a fast search for the 'right' recipe. 813 * 2) I want a fast search for the 'right' recipe.
813 * 814 *
814 * Note: it is just possible that a totally different combination of 815 * Note: it is just possible that a totally different combination of
815 * ingredients will result in a match with a given recipe. This is not a bug! 816 * ingredients will result in a match with a given recipe. This is not a bug!
816 * There is no good reason (in my mind) why alchemical processes have to be 817 * There is no good reason (in my mind) why alchemical processes have to be
817 * unique -- such a 'feature' is one reason why players might want to experiment 818 * unique -- such a 'feature' is one reason why players might want to experiment
818 * around. :) 819 * around. :)
824 recipelist *fl; 825 recipelist *fl;
825 recipe *rp = NULL; 826 recipe *rp = NULL;
826 float success_chance; 827 float success_chance;
827 int numb, ability = 1; 828 int numb, ability = 1;
828 int formula = 0; 829 int formula = 0;
829 float ave_chance;
830 object *item, *skop; 830 object *item;
831 831
832 if (caster->type != PLAYER) 832 if (caster->type != PLAYER)
833 return; /* only players for now */ 833 return; /* only players for now */
834 834
835 if (get_map_flags (caster->map, NULL, caster->x, caster->y, NULL, NULL) & P_SAFE) 835 if (get_map_flags (caster->map, NULL, caster->x, caster->y, NULL, NULL) & P_SAFE)
873 uint64 value_ingredients; 873 uint64 value_ingredients;
874 uint64 value_item; 874 uint64 value_item;
875 object *tmp; 875 object *tmp;
876 int attempt_shadow_alchemy; 876 int attempt_shadow_alchemy;
877 877
878 ave_chance = fl->total_chance / (float)fl->number; 878 //ave_chance = fl->total_chance / (float)fl->number;
879 879
880 ability += skill->level * ((4.0 + cauldron->magic) / 4.0); 880 ability += skill->level * ((4.0 + cauldron->magic) / 4.0);
881 881
882 /* determine value of ingredients */ 882 /* determine value of ingredients */
883 value_ingredients = 0; 883 value_ingredients = 0;
888 888
889 /* create the object **FIRST**, then decide whether to keep it. */ 889 /* create the object **FIRST**, then decide whether to keep it. */
890 if ((item = attempt_recipe (caster, cauldron, ability, rp, formula / rp->index)) != NULL) 890 if ((item = attempt_recipe (caster, cauldron, ability, rp, formula / rp->index)) != NULL)
891 { 891 {
892 /* compute base chance of recipe success */ 892 /* compute base chance of recipe success */
893 //TODO: (marc) diff is documenmted as percentage difficulty, not as divisor.
893 success_chance = ((float) ability / (float) (rp->diff * (item->level + 2))); 894 success_chance = ((float)ability / (float)(rp->diff * (item->level + 2)));
894 if (ave_chance == 0)
895 ave_chance = 1;
896 895
897#ifdef ALCHEMY_DEBUG 896#ifdef ALCHEMY_DEBUG
898 LOG (llevDebug, "percent success chance = %f ab%d / diff%d*lev%d\n", success_chance, ability, rp->diff, item->level); 897 LOG (llevDebug, "percent success chance = %f ab%d / diff%d*lev%d\n", success_chance, ability, rp->diff, item->level);
899#endif 898#endif
900 899

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines