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.8 by root, Thu Sep 14 22:34:03 2006 UTC vs.
Revision 1.31 by root, Mon Sep 29 10:20:48 2008 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 (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
6 7 *
7 This program is free software; you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
8 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
9 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version. 11 * (at your option) any later version.
11 12 *
12 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,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 16 * GNU General Public License for more details.
16 17 *
17 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
18 along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 *
20 21 * The authors can be reached via e-mail to <support@deliantra.net>
21 The authors can be reached via e-mail at <crossfire@schmorp.de>
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>
27#include <object.h> 27#include <object.h>
28#ifndef __CEXTRACT__
29# include <sproto.h> 28#include <sproto.h>
30#endif
31#include <skills.h> 29#include <skills.h>
32#include <spells.h> 30#include <spells.h>
33 31
34/** define this for some helpful debuging information */ 32/** define this for some helpful debuging information */
35#if 0 33#if 0
155 /* the caster gets an increase in ability based on thier skill lvl */ 153 /* the caster gets an increase in ability based on thier skill lvl */
156 if (rp->skill) 154 if (rp->skill)
157 { 155 {
158 skop = find_skill_by_name (caster, rp->skill); 156 skop = find_skill_by_name (caster, rp->skill);
159 if (!skop) 157 if (!skop)
160 {
161 new_draw_info (NDI_UNIQUE, 0, caster, "You do not have the proper skill for this recipe"); 158 new_draw_info (NDI_UNIQUE, 0, caster, "You do not have the proper skill for this recipe");
162 }
163 else 159 else
164 {
165 ability += (int) (skop->level * ((4.0 + cauldron->magic) / 4.0)); 160 ability += (int) (skop->level * ((4.0 + cauldron->magic) / 4.0));
166 }
167 } 161 }
168 else 162 else
169 { 163 {
170 LOG (llevDebug, "Recipe %s has NULL skill!\n", &rp->title); 164 LOG (llevDebug, "Recipe %s has NULL skill!\n", &rp->title);
171 return; 165 return;
172 } 166 }
173 167
174 if (rp->cauldron) 168 if (!rp->cauldron)
175 { 169 {
176 LOG (llevDebug, "Recipe %s has NULL cauldron!\n", &rp->title); 170 LOG (llevDebug, "Recipe %s has NULL cauldron!\n", &rp->title);
177 return; 171 return;
178 } 172 }
179 173
198 192
199 value_item = query_cost (item, NULL, F_TRUE | F_IDENTIFIED | F_NOT_CURSED); 193 value_item = query_cost (item, NULL, F_TRUE | F_IDENTIFIED | F_NOT_CURSED);
200 if (attempt_shadow_alchemy && value_item > value_ingredients) 194 if (attempt_shadow_alchemy && value_item > value_ingredients)
201 { 195 {
202#ifdef ALCHEMY_DEBUG 196#ifdef ALCHEMY_DEBUG
203# ifndef WIN32
204 LOG (llevDebug, 197 LOG (llevDebug,
205 "Forcing failure for shadow alchemy recipe because price of ingredients (%llu) is less than price of result (%llu).\n", 198 "Forcing failure for shadow alchemy recipe because price of ingredients (%llu) is less than price of result (%llu).\n",
206 value_ingredients, value_item); 199 value_ingredients, value_item);
207# else
208 LOG (llevDebug,
209 "Forcing failure for shadow alchemy recipe because price of ingredients (%I64d) is less than price of result (%I64d).\n",
210 value_ingredients, value_item);
211# endif
212#endif 200#endif
213 } 201 }
214 /* roll the dice */ 202 /* roll the dice */
215 else if ((float) (random_roll (0, 101, caster, PREFER_LOW)) <= 100.0 * success_chance) 203 else if ((float) (random_roll (0, 101, caster, PREFER_LOW)) <= 100.0 * success_chance)
216 { 204 {
217 change_exp (caster, rp->exp, rp->skill, SK_EXP_NONE); 205 change_exp (caster, rp->exp, rp->skill, SK_EXP_NONE);
206
207 // let alchemy consume some time, so that exploits are less easy
208 caster->speed_left -= 1.0;
209
218 return; 210 return;
219 } 211 }
220 } 212 }
221 } 213 }
222 } 214 }
215
223 /* if we get here, we failed!! */ 216 /* if we get here, we failed!! */
224 alchemy_failure_effect (caster, cauldron, rp, calc_alch_danger (caster, cauldron, rp)); 217 alchemy_failure_effect (caster, cauldron, rp, calc_alch_danger (caster, cauldron, rp));
225} 218}
226 219
227/** 220/**
238 int tval = 0, formula = 0; 231 int tval = 0, formula = 0;
239 232
240 while (tmp) 233 while (tmp)
241 { 234 {
242 tval = 0; 235 tval = 0;
243 strcpy (name, tmp->name); 236 assign (name, tmp->name);
244 if (tmp->title) 237 if (tmp->title)
245 sprintf (name, "%s %s", &tmp->name, &tmp->title); 238 sprintf (name, "%s %s", &tmp->name, &tmp->title);
246 tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1)); 239 tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1));
247#ifdef ALCHEMY_DEBUG 240#ifdef ALCHEMY_DEBUG
248 LOG (llevDebug, "Got ingredient %d %s(%d)\n", tmp->nrof ? tmp->nrof : 1, name, tval); 241 LOG (llevDebug, "Got ingredient %d %s(%d)\n", tmp->nrof ? tmp->nrof : 1, name, tval);
297 290
298 /* this should be passed to this fctn, not effiecent cpu use this way */ 291 /* this should be passed to this fctn, not effiecent cpu use this way */
299 int batches = abs (nbatches); 292 int batches = abs (nbatches);
300 293
301 294
302 LOG (llevDebug, "A %s <=> %s\n", &(rp->cauldron), &(cauldron->arch->name));
303 /* is the cauldron the right type? */ 295 /* is the cauldron the right type? */
304 if (strcmp (rp->cauldron, cauldron->arch->name) != 0) 296 if (rp->cauldron != cauldron->arch->archname)
305 { 297 {
306 new_draw_info (NDI_UNIQUE, 0, caster, "You are not using the proper" " facilities for this formula."); 298 new_draw_info (NDI_UNIQUE, 0, caster, "You are not using the proper" " facilities for this formula.");
307 return 0; 299 return 0;
308 } 300 }
309 301
315 /* code required for this recipe, search the caster */ 307 /* code required for this recipe, search the caster */
316 if (rp->keycode) 308 if (rp->keycode)
317 { 309 {
318 object *tmp; 310 object *tmp;
319 311
320 for (tmp = caster->inv; tmp != NULL; tmp = tmp->below) 312 for (tmp = caster->inv; tmp; tmp = tmp->below)
321 { 313 {
322 if (tmp->type == FORCE && tmp->slaying && !strcmp (rp->keycode, tmp->slaying)) 314 if (tmp->type == FORCE && tmp->slaying && rp->keycode == tmp->slaying)
323 break; 315 break;
324 } 316 }
317
325 if (tmp == NULL) 318 if (!tmp)
326 { /* failure--no code found */ 319 { /* failure--no code found */
327 new_draw_info (NDI_UNIQUE, 0, caster, "You know the ingredients," " but not the technique. Go learn how to do this recipe."); 320 new_draw_info (NDI_UNIQUE, 0, caster, "You know the ingredients, but not the technique. Go learn how to do this recipe.");
328 return 0; 321 return 0;
329 } 322 }
330 } 323 }
331 324
332#ifdef EXTREME_ALCHEMY_DEBUG 325#ifdef EXTREME_ALCHEMY_DEBUG
336 329
337 if ((item = make_item_from_recipe (cauldron, rp)) != NULL) 330 if ((item = make_item_from_recipe (cauldron, rp)) != NULL)
338 { 331 {
339 remove_contents (cauldron->inv, item); 332 remove_contents (cauldron->inv, item);
340 /* Recalc carrying of the cauldron, in case recipe did not conserve mass */ 333 /* Recalc carrying of the cauldron, in case recipe did not conserve mass */
341 sum_weight (cauldron); 334 cauldron->update_weight ();
342 /* adj lvl, nrof on caster level */ 335 /* adj lvl, nrof on caster level */
343 adjust_product (item, ability, rp->yield ? (rp->yield * batches) : batches); 336 adjust_product (item, ability, rp->yield ? (rp->yield * batches) : batches);
344 if (!item->env && (item = insert_ob_in_ob (item, cauldron)) == NULL) 337 if (!item->env && (item = insert_ob_in_ob (item, cauldron)) == NULL)
345 { 338 {
346 new_draw_info (NDI_UNIQUE, 0, caster, "Nothing happened."); 339 new_draw_info (NDI_UNIQUE, 0, caster, "Nothing happened.");
347 /* new_draw_info_format(NDI_UNIQUE, 0,caster, 340 /* new_draw_info_format(NDI_UNIQUE, 0,caster,
348 "Your spell causes the %s to explode!",&cauldron->name); */ 341 "Your spell causes the %s to explode!",&cauldron->name); */
349 /* kaboom_cauldron(); */ 342 /* kaboom_cauldron(); */
350 } 343 }
351 else 344 else
352 {
353 new_draw_info_format (NDI_UNIQUE, 0, caster, "The %s %s.", &cauldron->name, cauldron_sound ()); 345 new_draw_info_format (NDI_UNIQUE, 0, caster, "The %s %s.", &cauldron->name, cauldron_sound ());
354 }
355 } 346 }
347
356 return item; 348 return item;
357} 349}
358 350
359 351
360 352
361/** 353/**
362 * We adjust the nrof, exp and level of the final product, based 354 * We adjust the nrof, exp and level of the final product, based
363 * on the item's default parameters, and the relevant caster skill level. 355 * on the item's default parameters, and the relevant caster skill level.
364 */ 356 */
365 void 357void
366adjust_product (object *item, int lvl, int yield) 358adjust_product (object *item, int lvl, int yield)
367{ 359{
368 int nrof = 1; 360 int nrof = 1;
369 361
370 if (!yield) 362 if (!yield)
371 yield = 1; 363 yield = 1;
364
372 if (lvl <= 0) 365 if (lvl <= 0)
373 lvl = 1; /* lets avoid div by zero! */ 366 lvl = 1; /* lets avoid div by zero! */
367
374 if (item->nrof) 368 if (item->nrof)
375 { 369 {
376 nrof = (int) ((1.0 - 1.0 / (lvl / 10.0 + 1.0)) * (rndm (0, yield - 1) + rndm (0, yield - 1) + rndm (0, yield - 1)) + 1); 370 nrof = (int) ((1.0 - 1.0 / (lvl / 10.0 + 1.0)) * (rndm (0, yield - 1) + rndm (0, yield - 1) + rndm (0, yield - 1)) + 1);
371
377 if (nrof > yield) 372 if (nrof > yield)
378 nrof = yield; 373 nrof = yield;
374
379 item->nrof = nrof; 375 item->nrof = nrof;
380 } 376 }
381} 377}
382 378
383 379
451 { 447 {
452 size_t i; 448 size_t i;
453 449
454 for (i = 0; i < rp->arch_names; i++) 450 for (i = 0; i < rp->arch_names; i++)
455 { 451 {
456 if (strcmp (item->arch->name, rp->arch_name[i]) == 0) 452 if (item->arch->archname == rp->arch_name[i])
457 { 453 {
458 *rp_arch_index = i; 454 *rp_arch_index = i;
459 break; 455 break;
460 } 456 }
461 } 457 }
458
462 if (i < rp->arch_names) 459 if (i < rp->arch_names)
463 break; 460 break;
464 } 461 }
465 462
466 /* failed, create a fresh object. Note no nrof>1 because that would 463 /* failed, create a fresh object. Note no nrof>1 because that would
513 510
514 if (rndm (0, 2)) 511 if (rndm (0, 2))
515 { /* slag created */ 512 { /* slag created */
516 object *tmp = cauldron->inv; 513 object *tmp = cauldron->inv;
517 int weight = 0; 514 int weight = 0;
518 uint16 material = M_STONE;
519 515
520 while (tmp)
521 { /* slag has coadded ingredient properties */
522 weight += tmp->weight;
523 if (!(material & tmp->material))
524 material |= tmp->material;
525 tmp = tmp->below;
526 }
527 tmp = get_archetype ("rock"); 516 tmp = get_archetype ("rock");
528 tmp->weight = weight; 517 tmp->weight = weight;
529 tmp->value = 0; 518 tmp->value = 0;
530 tmp->material = material;
531 tmp->materialname = "stone"; 519 tmp->materialname = "stone";
532 tmp->name = "slag"; 520 tmp->name = "slag";
533 tmp->name_pl = "slags"; 521 tmp->name_pl = "slags";
534 item = insert_ob_in_ob (tmp, cauldron); 522 item = insert_ob_in_ob (tmp, cauldron);
535 CLEAR_FLAG (tmp, FLAG_CAN_ROLL); 523 CLEAR_FLAG (tmp, FLAG_CAN_ROLL);
536 CLEAR_FLAG (tmp, FLAG_NO_PICK); 524 CLEAR_FLAG (tmp, FLAG_NO_PICK);
537 tmp->move_block = 0; 525 tmp->move_block = 0;
538 } 526 }
527
539 remove_contents (cauldron->inv, item); 528 remove_contents (cauldron->inv, item);
540 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); 529 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ());
541 return; 530 return;
542 } 531 }
543 else if (level < 40) 532 else if (level < 40)
569 } 558 }
570 while (rndm (0, 2)); 559 while (rndm (0, 2));
571 } 560 }
572 return; 561 return;
573 } 562 }
563
574 if (level == 40) 564 if (level == 40)
575 { /* MAKE RANDOM RECIPE */ 565 { /* MAKE RANDOM RECIPE */
576 recipelist *fl; 566 recipelist *fl;
577 int numb = numb_ob_inside (cauldron); 567 int numb = numb_ob_inside (cauldron);
578 568
580 if (fl && (rp = get_random_recipe (fl))) 570 if (fl && (rp = get_random_recipe (fl)))
581 /* even though random, don't grant user any EXP for it */ 571 /* even though random, don't grant user any EXP for it */
582 (void) attempt_recipe (op, cauldron, 1, rp, -1); 572 (void) attempt_recipe (op, cauldron, 1, rp, -1);
583 else 573 else
584 alchemy_failure_effect (op, cauldron, rp, level - 1); 574 alchemy_failure_effect (op, cauldron, rp, level - 1);
585 return;
586
587 } 575 }
588 else if (level < 45) 576 else if (level < 45)
589 { /* INFURIATE NPC's */ 577 { /* INFURIATE NPC's */
590 /* this is kind of kludgy I know... */ 578 /* this is kind of kludgy I know... */
591 cauldron->enemy = op; 579 cauldron->enemy = op;
592 npc_call_help (cauldron); 580 npc_call_help (cauldron);
593 cauldron->enemy = NULL; 581 cauldron->enemy = NULL;
594 582
595 alchemy_failure_effect (op, cauldron, rp, level - 5); 583 alchemy_failure_effect (op, cauldron, rp, level - 5);
596 return;
597 } 584 }
598 else if (level < 50) 585 else if (level < 50)
599 { /* MINOR EXPLOSION/FIREBALL */ 586 { /* MINOR EXPLOSION/FIREBALL */
600 object *tmp; 587 object *tmp;
601 588
602 remove_contents (cauldron->inv, NULL); 589 remove_contents (cauldron->inv, NULL);
603 switch (rndm (0, 2)) 590 switch (rndm (0, 2))
604 { 591 {
605 case 0: 592 case 0:
606 tmp = get_archetype ("bomb"); 593 tmp = get_archetype ("bomb");
607 tmp->stats.dam = random_roll (1, level, op, PREFER_LOW); 594 tmp->stats.dam = random_roll (1, level, op, PREFER_LOW);
608 tmp->stats.hp = random_roll (1, level, op, PREFER_LOW); 595 tmp->stats.hp = random_roll (1, level, op, PREFER_LOW);
609 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s creates a bomb!", &cauldron->name); 596 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s creates a bomb!", &cauldron->name);
610 break; 597 break;
611 598
612 default: 599 default:
613 tmp = get_archetype ("fireball"); 600 tmp = get_archetype ("fireball");
614 tmp->stats.dam = random_roll (1, level, op, PREFER_LOW) / 5 + 1; 601 tmp->stats.dam = random_roll (1, level, op, PREFER_LOW) / 5 + 1;
615 tmp->stats.hp = random_roll (1, level, op, PREFER_LOW) / 10 + 2; 602 tmp->stats.hp = random_roll (1, level, op, PREFER_LOW) / 10 + 2;
616 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); 603 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name);
617 break; 604 break;
618 } 605 }
619 tmp->x = cauldron->x, tmp->y = cauldron->y;
620 insert_ob_in_map (tmp, op->map, NULL, 0);
621 return;
622 606
607 tmp->insert_at (cauldron);
623 } 608 }
624 else if (level < 60) 609 else if (level < 60)
625 { /* CREATE MONSTER */ 610 { /* CREATE MONSTER */
626 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); 611 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ());
627 remove_contents (cauldron->inv, NULL); 612 remove_contents (cauldron->inv, NULL);
628 return;
629 } 613 }
630 else if (level < 80) 614 else if (level < 80)
631 { /* MAJOR FIRE */ 615 { /* MAJOR FIRE */
632 object *fb = get_archetype (SP_MED_FIREBALL); 616 object *fb = get_archetype (SP_MED_FIREBALL);
633 617
634 remove_contents (cauldron->inv, NULL); 618 remove_contents (cauldron->inv, NULL);
635 fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb); 619 fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb);
636 free_object (fb); 620 fb->destroy (true);
637 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); 621 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name);
638 return;
639
640 } 622 }
641 else if (level < 100) 623 else if (level < 100)
642 { /* WHAMMY the CAULDRON */ 624 { /* WHAMMY the CAULDRON */
643 if (!QUERY_FLAG (cauldron, FLAG_CURSED)) 625 if (!QUERY_FLAG (cauldron, FLAG_CURSED))
644 SET_FLAG (cauldron, FLAG_CURSED); 626 SET_FLAG (cauldron, FLAG_CURSED);
645 else 627 else
646 cauldron->magic--; 628 cauldron->magic--;
629
647 cauldron->magic -= random_roll (0, 4, op, PREFER_LOW); 630 cauldron->magic -= random_roll (0, 4, op, PREFER_LOW);
631
648 if (rndm (0, 1)) 632 if (rndm (0, 1))
649 { 633 {
650 remove_contents (cauldron->inv, NULL); 634 remove_contents (cauldron->inv, NULL);
651 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s turns darker then makes a gulping sound!", &cauldron->name); 635 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s turns darker then makes a gulping sound!", &cauldron->name);
652 } 636 }
653 else 637 else
654 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s becomes darker.", &cauldron->name); 638 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s becomes darker.", &cauldron->name);
655 return;
656
657 } 639 }
658 else if (level < 110) 640 else if (level < 110)
659 { /* SUMMON EVIL MONSTERS */ 641 { /* SUMMON EVIL MONSTERS */
660 object *tmp = get_random_mon (level / 5); 642 object *tmp = get_random_mon (level / 5);
661 643
662 remove_contents (cauldron->inv, NULL); 644 remove_contents (cauldron->inv, NULL);
645
663 if (!tmp) 646 if (!tmp)
664 alchemy_failure_effect (op, cauldron, rp, level); 647 alchemy_failure_effect (op, cauldron, rp, level);
665 else if (summon_hostile_monsters (cauldron, random_roll (1, 10, op, PREFER_LOW), tmp->arch->name)) 648 else if (summon_hostile_monsters (cauldron, random_roll (1, 10, op, PREFER_LOW), tmp->arch->archname))
666 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s and then pours forth monsters!", &cauldron->name, cauldron_sound ()); 649 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s and then pours forth monsters!", &cauldron->name, cauldron_sound ());
667 return;
668
669 } 650 }
670 else if (level < 150) 651 else if (level < 150)
671 { /* COMBO EFFECT */ 652 { /* COMBO EFFECT */
672 int roll = rndm (1, 3); 653 int roll = rndm (1, 3);
673 654
674 while (roll) 655 while (roll)
675 { 656 {
676 alchemy_failure_effect (op, cauldron, rp, level - 39); 657 alchemy_failure_effect (op, cauldron, rp, level - 39);
677 roll--; 658 roll--;
678 } 659 }
679 return;
680 } 660 }
681 else if (level == 151) 661 else if (level == 151)
682 { /* CREATE RANDOM ARTIFACT */ 662 { /* CREATE RANDOM ARTIFACT */
683 object *tmp; 663 object *tmp;
684 664
695 { 675 {
696 remove_contents (cauldron->inv, tmp); 676 remove_contents (cauldron->inv, tmp);
697 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); 677 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ());
698 } 678 }
699 } 679 }
700 return;
701 } 680 }
702 else 681 else
703 { /* MANA STORM - watch out!! */ 682 { /* MANA STORM - watch out!! */
704 object *tmp = get_archetype (LOOSE_MANA); 683 object *tmp = get_archetype (LOOSE_MANA);
705 684
706 new_draw_info (NDI_UNIQUE, 0, op, "You unwisely release potent forces!"); 685 new_draw_info (NDI_UNIQUE, 0, op, "You unwisely release potent forces!");
707 remove_contents (cauldron->inv, NULL); 686 remove_contents (cauldron->inv, NULL);
708 cast_magic_storm (op, tmp, level); 687 cast_magic_storm (op, tmp, level);
709 return;
710 } 688 }
711} 689}
712 690
713 691/*
714/**
715 * All but object "save_item" are elimentated from 692 * All but object "save_item" are elimentated from
716 * the container list. Note we have to becareful to remove the inventories 693 * the container list. Note we have to becareful to remove the inventories
717 * of objects in the cauldron inventory (ex icecube has stuff in it). 694 * of objects in the cauldron inventory (ex icecube has stuff in it).
718 */ 695 */
719
720void 696void
721remove_contents (object *first_ob, object *save_item) 697remove_contents (object *first_ob, object *save_item)
722{ 698{
699 // this cries for a cleaner rewrite, removing save_item first possibly
723 object *next, *tmp = first_ob; 700 object *next, *tmp = first_ob;
724 701
725 while (tmp) 702 while (tmp)
726 { 703 {
727 next = tmp->below; 704 next = tmp->below;
705
728 if (tmp == save_item) 706 if (tmp == save_item)
729 { 707 {
730 if (!(tmp = next)) 708 if (!(tmp = next))
731 break; 709 break;
732 else 710 else
733 next = next->below; 711 next = next->below;
734 } 712 }
713
735 if (tmp->inv) 714 if (tmp->inv)
736 remove_contents (tmp->inv, NULL); 715 remove_contents (tmp->inv, NULL);
737 remove_ob (tmp); 716
738 free_object (tmp); 717 tmp->destroy (true);
739 tmp = next; 718 tmp = next;
740 } 719 }
741} 720}
742 721
743/** 722/**
744 *"Danger" level, will determine how bad the backfire 723 *"Danger" level, will determine how bad the backfire
745 * could be if the user fails to concoct a recipe properly. Factors include 724 * could be if the user fails to concoct a recipe properly. Factors include
746 * the number of ingredients, the length of the name of each ingredient, 725 * the number of ingredients, the length of the name of each ingredient,
747 * the user's effective level, the user's Int and the enchantment on the 726 * the user's effective level, the user's Int and the enchantment on the
748 * mixing device (aka "cauldron"). Higher values of 'danger' indicate more 727 * mixing device (aka "cauldron"). Higher values of 'danger' indicate more
749 * danger. Note that we assume that we have had the caster ready the alchemy 728 * danger. Note that we assume that we have had the caster ready the alchemy
750 * skill *before* this routine is called. (no longer auto-readies that skill) 729 * skill *before* this routine is called. (no longer auto-readies that skill)
751 * -b.t. 730 * -b.t.
752 */ 731 */
753
754int 732int
755calc_alch_danger (object *caster, object *cauldron, recipe *rp) 733calc_alch_danger (object *caster, object *cauldron, recipe *rp)
756{ 734{
757 object *item; 735 object *item;
758 char name[MAX_BUF]; 736 char name[MAX_BUF];
759 int danger = 0, nrofi = 0; 737 int danger = 0, nrofi = 0;
760 738
761 /* Knowing alchemy skill reduces yer risk */ 739 /* Knowing alchemy skill reduces yer risk */
762 danger -= caster->chosen_skill ? caster->chosen_skill->level : caster->level; 740 danger -= caster->chosen_skill ? caster->chosen_skill->level : caster->level;
741
742 if (!caster->chosen_skill)
743 LOG (llevError | logBacktrace, "calc_alch_danger called without a chosen skill, caster %s, cauldron %s\n",
744 caster->debug_desc (), cauldron->debug_desc ());
763 745
764 /* better cauldrons reduce risk */ 746 /* better cauldrons reduce risk */
765 danger -= cauldron->magic; 747 danger -= cauldron->magic;
766 748
767 /* Higher Int, lower the risk */ 749 /* Higher Int, lower the risk */
771 * Thus the backfire is worse. Also, more ingredients 753 * Thus the backfire is worse. Also, more ingredients
772 * means we are attempting a more powerfull potion, 754 * means we are attempting a more powerfull potion,
773 * and thus the backfire will be worse. */ 755 * and thus the backfire will be worse. */
774 for (item = cauldron->inv; item; item = item->below) 756 for (item = cauldron->inv; item; item = item->below)
775 { 757 {
776 strcpy (name, item->name); 758 assign (name, item->name);
777 if (item->title) 759 if (item->title)
778 sprintf (name, "%s %s", &item->name, &item->title); 760 sprintf (name, "%s %s", &item->name, &item->title);
779 danger += (strtoint (name) / 1000) + 3; 761 danger += (strtoint (name) / 1000) + 3;
780 nrofi++; 762 nrofi++;
781 } 763 }
764
782 if (rp == NULL) 765 if (rp == NULL)
783 danger += 110; 766 danger += 110;
784 else 767 else
785 danger += rp->diff * 3; 768 danger += rp->diff * 3;
786 769
795#endif 778#endif
796 779
797 return danger; 780 return danger;
798} 781}
799 782
800/** 783/**
801 * Determines if ingredients in a container match the 784 * Determines if ingredients in a container match the
802 * proper ingredients for a recipe. 785 * proper ingredients for a recipe.
803 * 786 *
804 * rp is the recipe to check 787 * rp is the recipe to check
805 * cauldron is the container that holds the ingredients 788 * cauldron is the container that holds the ingredients
909 LOG (llevDebug, "looking for formula %d:\n", formula); 892 LOG (llevDebug, "looking for formula %d:\n", formula);
910#endif 893#endif
911 result = NULL; 894 result = NULL;
912 recipes_matching = 0; 895 recipes_matching = 0;
913 transmute_found = 0; 896 transmute_found = 0;
897
914 for (rp = fl->items; rp != NULL; rp = rp->next) 898 for (rp = fl->items; rp; rp = rp->next)
915 { 899 {
916 /* check if recipe matches at all */ 900 /* check if recipe matches at all */
917 if (formula % rp->index != 0) 901 if (formula % rp->index != 0)
918 { 902 {
919#ifdef EXTREME_ALCHEMY_DEBUG 903#ifdef EXTREME_ALCHEMY_DEBUG

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines