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.18 by pippijn, Mon Jan 15 21:06:19 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);
232 int tval = 0, formula = 0; 216 int tval = 0, formula = 0;
233 217
234 while (tmp) 218 while (tmp)
235 { 219 {
236 tval = 0; 220 tval = 0;
237 strcpy (name, tmp->name); 221 assign (name, tmp->name);
238 if (tmp->title) 222 if (tmp->title)
239 sprintf (name, "%s %s", &tmp->name, &tmp->title); 223 sprintf (name, "%s %s", &tmp->name, &tmp->title);
240 tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1)); 224 tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1));
241#ifdef ALCHEMY_DEBUG 225#ifdef ALCHEMY_DEBUG
242 LOG (llevDebug, "Got ingredient %d %s(%d)\n", tmp->nrof ? tmp->nrof : 1, name, tval); 226 LOG (llevDebug, "Got ingredient %d %s(%d)\n", tmp->nrof ? tmp->nrof : 1, name, tval);
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 (strcmp (rp->cauldron, cauldron->arch->name) != 0) 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;
310 { 290 {
311 object *tmp; 291 object *tmp;
312 292
313 for (tmp = caster->inv; tmp; tmp = tmp->below) 293 for (tmp = caster->inv; tmp; tmp = tmp->below)
314 { 294 {
315 if (tmp->type == FORCE && tmp->slaying && !strcmp (rp->keycode, tmp->slaying)) 295 if (tmp->type == FORCE && tmp->slaying && rp->keycode == tmp->slaying)
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 (strcmp (item->arch->name, rp->arch_name[i]) == 0) 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 } 438
459 if (i < rp->arch_names) 439 if (prod_item)
460 break; 440 break;
461 } 441 }
462 442
463 /* 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
464 * allow players to create massive amounts of artifacts easily */ 444 * allow players to create massive amounts of artifacts easily */
465 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)
466 { 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)
467 *rp_arch_index = RANDOM () % rp->arch_names; 456 *rp_arch_index = rndm (rp->arch_names);
468 item = get_archetype (rp->arch_name[*rp_arch_index]); 457 prod_item = get_archetype (rp->arch_name[*rp_arch_index]);
469 } 458 }
470 459
471#ifdef ALCHEMY_DEBUG 460#ifdef ALCHEMY_DEBUG
472 LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no "); 461 LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no ");
473 if (item != NULL) 462 if (prod_item != NULL)
474 { 463 {
475 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);
476 } 466 }
477#endif 467#endif
478 468
479 return item; 469 return prod_item;
480} 470}
481 471
482 472
483/** 473/**
484 * Ouch. We didnt get the formula we wanted. 474 * Ouch. We didnt get the formula we wanted.
510 500
511 if (rndm (0, 2)) 501 if (rndm (0, 2))
512 { /* slag created */ 502 { /* slag created */
513 object *tmp = cauldron->inv; 503 object *tmp = cauldron->inv;
514 int weight = 0; 504 int weight = 0;
515 uint16 material = M_STONE;
516 505
517 while (tmp)
518 { /* slag has coadded ingredient properties */
519 weight += tmp->weight;
520 if (!(material & tmp->material))
521 material |= tmp->material;
522 tmp = tmp->below;
523 }
524 tmp = get_archetype ("rock"); 506 tmp = get_archetype ("rock");
525 tmp->weight = weight; 507 tmp->weight = weight;
526 tmp->value = 0; 508 tmp->value = 0;
527 tmp->material = material;
528 tmp->materialname = "stone"; 509 tmp->materialname = "stone";
529 tmp->name = "slag"; 510 tmp->name = "slag";
530 tmp->name_pl = "slags"; 511 tmp->name_pl = "slags";
531 item = insert_ob_in_ob (tmp, cauldron); 512 item = insert_ob_in_ob (tmp, cauldron);
532 CLEAR_FLAG (tmp, FLAG_CAN_ROLL); 513 CLEAR_FLAG (tmp, FLAG_CAN_ROLL);
533 CLEAR_FLAG (tmp, FLAG_NO_PICK); 514 CLEAR_FLAG (tmp, FLAG_NO_PICK);
534 tmp->move_block = 0; 515 tmp->move_block = 0;
535 } 516 }
517
536 remove_contents (cauldron->inv, item); 518 remove_contents (cauldron->inv, item);
537 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 ());
538 return; 520 return;
539 } 521 }
540 else if (level < 40) 522 else if (level < 40)
566 } 548 }
567 while (rndm (0, 2)); 549 while (rndm (0, 2));
568 } 550 }
569 return; 551 return;
570 } 552 }
553
571 if (level == 40) 554 if (level == 40)
572 { /* MAKE RANDOM RECIPE */ 555 { /* MAKE RANDOM RECIPE */
573 recipelist *fl; 556 recipelist *fl;
574 int numb = numb_ob_inside (cauldron); 557 int numb = numb_ob_inside (cauldron);
575 558
577 if (fl && (rp = get_random_recipe (fl))) 560 if (fl && (rp = get_random_recipe (fl)))
578 /* even though random, don't grant user any EXP for it */ 561 /* even though random, don't grant user any EXP for it */
579 (void) attempt_recipe (op, cauldron, 1, rp, -1); 562 (void) attempt_recipe (op, cauldron, 1, rp, -1);
580 else 563 else
581 alchemy_failure_effect (op, cauldron, rp, level - 1); 564 alchemy_failure_effect (op, cauldron, rp, level - 1);
582 return;
583
584 } 565 }
585 else if (level < 45) 566 else if (level < 45)
586 { /* INFURIATE NPC's */ 567 { /* INFURIATE NPC's */
587 /* this is kind of kludgy I know... */ 568 /* this is kind of kludgy I know... */
588 cauldron->enemy = op; 569 cauldron->enemy = op;
589 npc_call_help (cauldron); 570 npc_call_help (cauldron);
590 cauldron->enemy = NULL; 571 cauldron->enemy = NULL;
591 572
592 alchemy_failure_effect (op, cauldron, rp, level - 5); 573 alchemy_failure_effect (op, cauldron, rp, level - 5);
593 return;
594 } 574 }
595 else if (level < 50) 575 else if (level < 50)
596 { /* MINOR EXPLOSION/FIREBALL */ 576 { /* MINOR EXPLOSION/FIREBALL */
597 object *tmp; 577 object *tmp;
598 578
612 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;
613 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);
614 break; 594 break;
615 } 595 }
616 596
617 op->insert_at (cauldron); 597 tmp->insert_at (cauldron);
618 return;
619
620 } 598 }
621 else if (level < 60) 599 else if (level < 60)
622 { /* CREATE MONSTER */ 600 { /* CREATE MONSTER */
623 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 ());
624 remove_contents (cauldron->inv, NULL); 602 remove_contents (cauldron->inv, NULL);
625 return;
626 } 603 }
627 else if (level < 80) 604 else if (level < 80)
628 { /* MAJOR FIRE */ 605 { /* MAJOR FIRE */
629 object *fb = get_archetype (SP_MED_FIREBALL); 606 object *fb = get_archetype (SP_MED_FIREBALL);
630 607
631 remove_contents (cauldron->inv, NULL); 608 remove_contents (cauldron->inv, NULL);
632 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);
633 fb->destroy (); 610 fb->destroy ();
634 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);
635 return;
636
637 } 612 }
638 else if (level < 100) 613 else if (level < 100)
639 { /* WHAMMY the CAULDRON */ 614 { /* WHAMMY the CAULDRON */
640 if (!QUERY_FLAG (cauldron, FLAG_CURSED)) 615 if (!QUERY_FLAG (cauldron, FLAG_CURSED))
641 SET_FLAG (cauldron, FLAG_CURSED); 616 SET_FLAG (cauldron, FLAG_CURSED);
642 else 617 else
643 cauldron->magic--; 618 cauldron->magic--;
619
644 cauldron->magic -= random_roll (0, 4, op, PREFER_LOW); 620 cauldron->magic -= random_roll (0, 4, op, PREFER_LOW);
621
645 if (rndm (0, 1)) 622 if (rndm (0, 1))
646 { 623 {
647 remove_contents (cauldron->inv, NULL); 624 remove_contents (cauldron->inv, NULL);
648 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);
649 } 626 }
650 else 627 else
651 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);
652 return;
653
654 } 629 }
655 else if (level < 110) 630 else if (level < 110)
656 { /* SUMMON EVIL MONSTERS */ 631 { /* SUMMON EVIL MONSTERS */
657 object *tmp = get_random_mon (level / 5); 632 object *tmp = get_random_mon (level / 5);
658 633
659 remove_contents (cauldron->inv, NULL); 634 remove_contents (cauldron->inv, NULL);
635
660 if (!tmp) 636 if (!tmp)
661 alchemy_failure_effect (op, cauldron, rp, level); 637 alchemy_failure_effect (op, cauldron, rp, level);
662 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))
663 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 ());
664 return;
665
666 } 640 }
667 else if (level < 150) 641 else if (level < 150)
668 { /* COMBO EFFECT */ 642 { /* COMBO EFFECT */
669 int roll = rndm (1, 3); 643 int roll = rndm (1, 3);
670 644
671 while (roll) 645 while (roll)
672 { 646 {
673 alchemy_failure_effect (op, cauldron, rp, level - 39); 647 alchemy_failure_effect (op, cauldron, rp, level - 39);
674 roll--; 648 roll--;
675 } 649 }
676 return;
677 } 650 }
678 else if (level == 151) 651 else if (level == 151)
679 { /* CREATE RANDOM ARTIFACT */ 652 { /* CREATE RANDOM ARTIFACT */
680 object *tmp; 653 object *tmp;
681 654
683 * in this one, we allow *any* valid alchemy artifact 656 * in this one, we allow *any* valid alchemy artifact
684 * to be made (rather than only those on the given 657 * to be made (rather than only those on the given
685 * formulalist) */ 658 * formulalist) */
686 if (!rp) 659 if (!rp)
687 rp = get_random_recipe ((recipelist *) NULL); 660 rp = get_random_recipe ((recipelist *) NULL);
661
688 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)])))
689 { 663 {
690 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);
691 if ((tmp = insert_ob_in_ob (tmp, cauldron))) 665 if ((tmp = insert_ob_in_ob (tmp, cauldron)))
692 { 666 {
693 remove_contents (cauldron->inv, tmp); 667 remove_contents (cauldron->inv, tmp);
694 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 ());
695 } 669 }
696 } 670 }
697 return;
698 } 671 }
699 else 672 else
700 { /* MANA STORM - watch out!! */ 673 { /* MANA STORM - watch out!! */
701 object *tmp = get_archetype (LOOSE_MANA); 674 object *tmp = get_archetype (LOOSE_MANA);
702 675
703 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!");
704 remove_contents (cauldron->inv, NULL); 677 remove_contents (cauldron->inv, NULL);
705 cast_magic_storm (op, tmp, level); 678 cast_magic_storm (op, tmp, level);
706 return;
707 } 679 }
708} 680}
709
710 681
711/* 682/*
712 * All but object "save_item" are elimentated from 683 * All but object "save_item" are elimentated from
713 * 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
714 * 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).
715 */ 686 */
716
717void 687void
718remove_contents (object *first_ob, object *save_item) 688remove_contents (object *first_ob, object *save_item)
719{ 689{
690 // this cries for a cleaner rewrite, removing save_item first possibly
720 object *next, *tmp = first_ob; 691 object *next, *tmp = first_ob;
721 692
722 while (tmp) 693 while (tmp)
723 { 694 {
724 next = tmp->below; 695 next = tmp->below;
737 tmp->destroy (); 708 tmp->destroy ();
738 tmp = next; 709 tmp = next;
739 } 710 }
740} 711}
741 712
742/** 713/**
743 *"Danger" level, will determine how bad the backfire 714 *"Danger" level, will determine how bad the backfire
744 * 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
745 * 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,
746 * 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
747 * mixing device (aka "cauldron"). Higher values of 'danger' indicate more 718 * mixing device (aka "cauldron"). Higher values of 'danger' indicate more
748 * 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
749 * 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)
750 * -b.t. 721 * -b.t.
751 */ 722 */
752
753int 723int
754calc_alch_danger (object *caster, object *cauldron, recipe *rp) 724calc_alch_danger (object *caster, object *cauldron, recipe *rp)
755{ 725{
756 object *item; 726 object *item;
757 char name[MAX_BUF]; 727 char name[MAX_BUF];
758 int danger = 0, nrofi = 0; 728 int danger = 0, nrofi = 0;
759 729
760 /* Knowing alchemy skill reduces yer risk */ 730 /* Knowing alchemy skill reduces yer risk */
761 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 ());
762 736
763 /* better cauldrons reduce risk */ 737 /* better cauldrons reduce risk */
764 danger -= cauldron->magic; 738 danger -= cauldron->magic;
765 739
766 /* Higher Int, lower the risk */ 740 /* Higher Int, lower the risk */
770 * Thus the backfire is worse. Also, more ingredients 744 * Thus the backfire is worse. Also, more ingredients
771 * means we are attempting a more powerfull potion, 745 * means we are attempting a more powerfull potion,
772 * and thus the backfire will be worse. */ 746 * and thus the backfire will be worse. */
773 for (item = cauldron->inv; item; item = item->below) 747 for (item = cauldron->inv; item; item = item->below)
774 { 748 {
775 strcpy (name, item->name); 749 assign (name, item->name);
776 if (item->title) 750 if (item->title)
777 sprintf (name, "%s %s", &item->name, &item->title); 751 sprintf (name, "%s %s", &item->name, &item->title);
778 danger += (strtoint (name) / 1000) + 3; 752 danger += (strtoint (name) / 1000) + 3;
779 nrofi++; 753 nrofi++;
780 } 754 }
755
781 if (rp == NULL) 756 if (rp == NULL)
782 danger += 110; 757 danger += 110;
783 else 758 else
784 danger += rp->diff * 3; 759 danger += rp->diff * 3;
785 760
794#endif 769#endif
795 770
796 return danger; 771 return danger;
797} 772}
798 773
799/** 774/**
800 * Determines if ingredients in a container match the 775 * Determines if ingredients in a container match the
801 * proper ingredients for a recipe. 776 * proper ingredients for a recipe.
802 * 777 *
803 * rp is the recipe to check 778 * rp is the recipe to check
804 * cauldron is the container that holds the ingredients 779 * cauldron is the container that holds the ingredients
853 for (ob = cauldron->inv; ob != NULL; ob = ob->below) 828 for (ob = cauldron->inv; ob != NULL; ob = ob->below)
854 { 829 {
855 char name_ob[MAX_BUF]; 830 char name_ob[MAX_BUF];
856 const char *name2; 831 const char *name2;
857 832
858 if (ob->title == NULL) 833 if (!ob->title)
859 name2 = ob->name; 834 name2 = ob->name;
860 else 835 else
861 { 836 {
862 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);
863 name2 = name_ob; 838 name2 = name_ob;
908 LOG (llevDebug, "looking for formula %d:\n", formula); 883 LOG (llevDebug, "looking for formula %d:\n", formula);
909#endif 884#endif
910 result = NULL; 885 result = NULL;
911 recipes_matching = 0; 886 recipes_matching = 0;
912 transmute_found = 0; 887 transmute_found = 0;
888
913 for (rp = fl->items; rp != NULL; rp = rp->next) 889 for (rp = fl->items; rp; rp = rp->next)
914 { 890 {
915 /* check if recipe matches at all */ 891 /* check if recipe matches at all */
916 if (formula % rp->index != 0) 892 if (formula % rp->index != 0)
917 { 893 {
918#ifdef EXTREME_ALCHEMY_DEBUG 894#ifdef EXTREME_ALCHEMY_DEBUG
919 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);
920#endif 896#endif
921 continue; 897 continue;
922 } 898 }
923 899
924 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)
925 { 901 {
926#ifdef EXTREME_ALCHEMY_DEBUG 902#ifdef EXTREME_ALCHEMY_DEBUG
927 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);
928#endif 904#endif
929 /* transmution recipe with matching base ingredient */ 905 /* transmution recipe with matching base ingredient */
930 if (!transmute_found) 906 if (!transmute_found)
931 { 907 {
932 transmute_found = 1; 908 transmute_found = 1;
934 } 910 }
935 } 911 }
936 else if (transmute_found) 912 else if (transmute_found)
937 { 913 {
938#ifdef EXTREME_ALCHEMY_DEBUG 914#ifdef EXTREME_ALCHEMY_DEBUG
939 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,
940 rp->index); 916 rp->index);
941#endif 917#endif
942 /* "normal" recipe found after previous transmution recipe => ignore this recipe */ 918 /* "normal" recipe found after previous transmution recipe => ignore this recipe */
943 continue; 919 continue;
944 } 920 }
945#ifdef EXTREME_ALCHEMY_DEBUG 921#ifdef EXTREME_ALCHEMY_DEBUG
946 else 922 else
947 { 923 {
948 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);
949 } 925 }
950#endif 926#endif
951 927
952 if (rndm (0, recipes_matching) == 0) 928 if (rndm (0, recipes_matching) == 0)
953 result = rp; 929 result = rp;
963 return NULL; 939 return NULL;
964 } 940 }
965 941
966#ifdef ALCHEMY_DEBUG 942#ifdef ALCHEMY_DEBUG
967 if (strcmp (result->title, "NONE") != 0) 943 if (strcmp (result->title, "NONE") != 0)
968 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);
969 else 945 else
970 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);
971#endif 947#endif
972 return result; 948 return result;
973} 949}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines