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.7 by root, Sun Sep 10 15:59:57 2006 UTC vs.
Revision 1.31 by root, Mon Sep 29 10:20:48 2008 UTC

1
2/* 1/*
3 * static char *rcsid_alchemy_c = 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
4 * "$Id: alchemy.C,v 1.7 2006/09/10 15:59:57 root Exp $"; 3 *
5 */ 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
6
7/*
8 CrossFire, A Multiplayer game for X-windows
9
10 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
12 7 *
13 This program is free software; you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
14 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
15 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version. 11 * (at your option) any later version.
17 12 *
18 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,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details. 16 * GNU General Public License for more details.
22 17 *
23 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
24 along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 *
26 21 * The authors can be reached via e-mail to <support@deliantra.net>
27 The authors can be reached via e-mail at crossfire-devel@real-time.com
28*/ 22 */
29 23
30/* 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 */
31 25
32#include <global.h> 26#include <global.h>
33#include <object.h> 27#include <object.h>
34#ifndef __CEXTRACT__
35# include <sproto.h> 28#include <sproto.h>
36#endif
37#include <skills.h> 29#include <skills.h>
38#include <spells.h> 30#include <spells.h>
39 31
40/** define this for some helpful debuging information */ 32/** define this for some helpful debuging information */
41#if 0 33#if 0
161 /* 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 */
162 if (rp->skill) 154 if (rp->skill)
163 { 155 {
164 skop = find_skill_by_name (caster, rp->skill); 156 skop = find_skill_by_name (caster, rp->skill);
165 if (!skop) 157 if (!skop)
166 {
167 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");
168 }
169 else 159 else
170 {
171 ability += (int) (skop->level * ((4.0 + cauldron->magic) / 4.0)); 160 ability += (int) (skop->level * ((4.0 + cauldron->magic) / 4.0));
172 }
173 } 161 }
174 else 162 else
175 { 163 {
176 LOG (llevDebug, "Recipe %s has NULL skill!\n", &rp->title); 164 LOG (llevDebug, "Recipe %s has NULL skill!\n", &rp->title);
177 return; 165 return;
178 } 166 }
179 167
180 if (rp->cauldron) 168 if (!rp->cauldron)
181 { 169 {
182 LOG (llevDebug, "Recipe %s has NULL cauldron!\n", &rp->title); 170 LOG (llevDebug, "Recipe %s has NULL cauldron!\n", &rp->title);
183 return; 171 return;
184 } 172 }
185 173
204 192
205 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);
206 if (attempt_shadow_alchemy && value_item > value_ingredients) 194 if (attempt_shadow_alchemy && value_item > value_ingredients)
207 { 195 {
208#ifdef ALCHEMY_DEBUG 196#ifdef ALCHEMY_DEBUG
209# ifndef WIN32
210 LOG (llevDebug, 197 LOG (llevDebug,
211 "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",
212 value_ingredients, value_item); 199 value_ingredients, value_item);
213# else
214 LOG (llevDebug,
215 "Forcing failure for shadow alchemy recipe because price of ingredients (%I64d) is less than price of result (%I64d).\n",
216 value_ingredients, value_item);
217# endif
218#endif 200#endif
219 } 201 }
220 /* roll the dice */ 202 /* roll the dice */
221 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)
222 { 204 {
223 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
224 return; 210 return;
225 } 211 }
226 } 212 }
227 } 213 }
228 } 214 }
215
229 /* if we get here, we failed!! */ 216 /* if we get here, we failed!! */
230 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));
231} 218}
232 219
233/** 220/**
244 int tval = 0, formula = 0; 231 int tval = 0, formula = 0;
245 232
246 while (tmp) 233 while (tmp)
247 { 234 {
248 tval = 0; 235 tval = 0;
249 strcpy (name, tmp->name); 236 assign (name, tmp->name);
250 if (tmp->title) 237 if (tmp->title)
251 sprintf (name, "%s %s", &tmp->name, &tmp->title); 238 sprintf (name, "%s %s", &tmp->name, &tmp->title);
252 tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1)); 239 tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1));
253#ifdef ALCHEMY_DEBUG 240#ifdef ALCHEMY_DEBUG
254 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);
303 290
304 /* 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 */
305 int batches = abs (nbatches); 292 int batches = abs (nbatches);
306 293
307 294
308 LOG (llevDebug, "A %s <=> %s\n", &(rp->cauldron), &(cauldron->arch->name));
309 /* is the cauldron the right type? */ 295 /* is the cauldron the right type? */
310 if (strcmp (rp->cauldron, cauldron->arch->name) != 0) 296 if (rp->cauldron != cauldron->arch->archname)
311 { 297 {
312 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.");
313 return 0; 299 return 0;
314 } 300 }
315 301
321 /* code required for this recipe, search the caster */ 307 /* code required for this recipe, search the caster */
322 if (rp->keycode) 308 if (rp->keycode)
323 { 309 {
324 object *tmp; 310 object *tmp;
325 311
326 for (tmp = caster->inv; tmp != NULL; tmp = tmp->below) 312 for (tmp = caster->inv; tmp; tmp = tmp->below)
327 { 313 {
328 if (tmp->type == FORCE && tmp->slaying && !strcmp (rp->keycode, tmp->slaying)) 314 if (tmp->type == FORCE && tmp->slaying && rp->keycode == tmp->slaying)
329 break; 315 break;
330 } 316 }
317
331 if (tmp == NULL) 318 if (!tmp)
332 { /* failure--no code found */ 319 { /* failure--no code found */
333 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.");
334 return 0; 321 return 0;
335 } 322 }
336 } 323 }
337 324
338#ifdef EXTREME_ALCHEMY_DEBUG 325#ifdef EXTREME_ALCHEMY_DEBUG
342 329
343 if ((item = make_item_from_recipe (cauldron, rp)) != NULL) 330 if ((item = make_item_from_recipe (cauldron, rp)) != NULL)
344 { 331 {
345 remove_contents (cauldron->inv, item); 332 remove_contents (cauldron->inv, item);
346 /* 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 */
347 sum_weight (cauldron); 334 cauldron->update_weight ();
348 /* adj lvl, nrof on caster level */ 335 /* adj lvl, nrof on caster level */
349 adjust_product (item, ability, rp->yield ? (rp->yield * batches) : batches); 336 adjust_product (item, ability, rp->yield ? (rp->yield * batches) : batches);
350 if (!item->env && (item = insert_ob_in_ob (item, cauldron)) == NULL) 337 if (!item->env && (item = insert_ob_in_ob (item, cauldron)) == NULL)
351 { 338 {
352 new_draw_info (NDI_UNIQUE, 0, caster, "Nothing happened."); 339 new_draw_info (NDI_UNIQUE, 0, caster, "Nothing happened.");
353 /* new_draw_info_format(NDI_UNIQUE, 0,caster, 340 /* new_draw_info_format(NDI_UNIQUE, 0,caster,
354 "Your spell causes the %s to explode!",&cauldron->name); */ 341 "Your spell causes the %s to explode!",&cauldron->name); */
355 /* kaboom_cauldron(); */ 342 /* kaboom_cauldron(); */
356 } 343 }
357 else 344 else
358 {
359 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 ());
360 }
361 } 346 }
347
362 return item; 348 return item;
363} 349}
364 350
365 351
366 352
367/** 353/**
368 * 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
369 * 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.
370 */ 356 */
371 void 357void
372adjust_product (object *item, int lvl, int yield) 358adjust_product (object *item, int lvl, int yield)
373{ 359{
374 int nrof = 1; 360 int nrof = 1;
375 361
376 if (!yield) 362 if (!yield)
377 yield = 1; 363 yield = 1;
364
378 if (lvl <= 0) 365 if (lvl <= 0)
379 lvl = 1; /* lets avoid div by zero! */ 366 lvl = 1; /* lets avoid div by zero! */
367
380 if (item->nrof) 368 if (item->nrof)
381 { 369 {
382 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
383 if (nrof > yield) 372 if (nrof > yield)
384 nrof = yield; 373 nrof = yield;
374
385 item->nrof = nrof; 375 item->nrof = nrof;
386 } 376 }
387} 377}
388 378
389 379
457 { 447 {
458 size_t i; 448 size_t i;
459 449
460 for (i = 0; i < rp->arch_names; i++) 450 for (i = 0; i < rp->arch_names; i++)
461 { 451 {
462 if (strcmp (item->arch->name, rp->arch_name[i]) == 0) 452 if (item->arch->archname == rp->arch_name[i])
463 { 453 {
464 *rp_arch_index = i; 454 *rp_arch_index = i;
465 break; 455 break;
466 } 456 }
467 } 457 }
458
468 if (i < rp->arch_names) 459 if (i < rp->arch_names)
469 break; 460 break;
470 } 461 }
471 462
472 /* 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
519 510
520 if (rndm (0, 2)) 511 if (rndm (0, 2))
521 { /* slag created */ 512 { /* slag created */
522 object *tmp = cauldron->inv; 513 object *tmp = cauldron->inv;
523 int weight = 0; 514 int weight = 0;
524 uint16 material = M_STONE;
525 515
526 while (tmp)
527 { /* slag has coadded ingredient properties */
528 weight += tmp->weight;
529 if (!(material & tmp->material))
530 material |= tmp->material;
531 tmp = tmp->below;
532 }
533 tmp = get_archetype ("rock"); 516 tmp = get_archetype ("rock");
534 tmp->weight = weight; 517 tmp->weight = weight;
535 tmp->value = 0; 518 tmp->value = 0;
536 tmp->material = material;
537 tmp->materialname = "stone"; 519 tmp->materialname = "stone";
538 tmp->name = "slag"; 520 tmp->name = "slag";
539 tmp->name_pl = "slags"; 521 tmp->name_pl = "slags";
540 item = insert_ob_in_ob (tmp, cauldron); 522 item = insert_ob_in_ob (tmp, cauldron);
541 CLEAR_FLAG (tmp, FLAG_CAN_ROLL); 523 CLEAR_FLAG (tmp, FLAG_CAN_ROLL);
542 CLEAR_FLAG (tmp, FLAG_NO_PICK); 524 CLEAR_FLAG (tmp, FLAG_NO_PICK);
543 tmp->move_block = 0; 525 tmp->move_block = 0;
544 } 526 }
527
545 remove_contents (cauldron->inv, item); 528 remove_contents (cauldron->inv, item);
546 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 ());
547 return; 530 return;
548 } 531 }
549 else if (level < 40) 532 else if (level < 40)
575 } 558 }
576 while (rndm (0, 2)); 559 while (rndm (0, 2));
577 } 560 }
578 return; 561 return;
579 } 562 }
563
580 if (level == 40) 564 if (level == 40)
581 { /* MAKE RANDOM RECIPE */ 565 { /* MAKE RANDOM RECIPE */
582 recipelist *fl; 566 recipelist *fl;
583 int numb = numb_ob_inside (cauldron); 567 int numb = numb_ob_inside (cauldron);
584 568
586 if (fl && (rp = get_random_recipe (fl))) 570 if (fl && (rp = get_random_recipe (fl)))
587 /* even though random, don't grant user any EXP for it */ 571 /* even though random, don't grant user any EXP for it */
588 (void) attempt_recipe (op, cauldron, 1, rp, -1); 572 (void) attempt_recipe (op, cauldron, 1, rp, -1);
589 else 573 else
590 alchemy_failure_effect (op, cauldron, rp, level - 1); 574 alchemy_failure_effect (op, cauldron, rp, level - 1);
591 return;
592
593 } 575 }
594 else if (level < 45) 576 else if (level < 45)
595 { /* INFURIATE NPC's */ 577 { /* INFURIATE NPC's */
596 /* this is kind of kludgy I know... */ 578 /* this is kind of kludgy I know... */
597 cauldron->enemy = op; 579 cauldron->enemy = op;
598 npc_call_help (cauldron); 580 npc_call_help (cauldron);
599 cauldron->enemy = NULL; 581 cauldron->enemy = NULL;
600 582
601 alchemy_failure_effect (op, cauldron, rp, level - 5); 583 alchemy_failure_effect (op, cauldron, rp, level - 5);
602 return;
603 } 584 }
604 else if (level < 50) 585 else if (level < 50)
605 { /* MINOR EXPLOSION/FIREBALL */ 586 { /* MINOR EXPLOSION/FIREBALL */
606 object *tmp; 587 object *tmp;
607 588
608 remove_contents (cauldron->inv, NULL); 589 remove_contents (cauldron->inv, NULL);
609 switch (rndm (0, 2)) 590 switch (rndm (0, 2))
610 { 591 {
611 case 0: 592 case 0:
612 tmp = get_archetype ("bomb"); 593 tmp = get_archetype ("bomb");
613 tmp->stats.dam = random_roll (1, level, op, PREFER_LOW); 594 tmp->stats.dam = random_roll (1, level, op, PREFER_LOW);
614 tmp->stats.hp = random_roll (1, level, op, PREFER_LOW); 595 tmp->stats.hp = random_roll (1, level, op, PREFER_LOW);
615 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);
616 break; 597 break;
617 598
618 default: 599 default:
619 tmp = get_archetype ("fireball"); 600 tmp = get_archetype ("fireball");
620 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;
621 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;
622 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);
623 break; 604 break;
624 } 605 }
625 tmp->x = cauldron->x, tmp->y = cauldron->y;
626 insert_ob_in_map (tmp, op->map, NULL, 0);
627 return;
628 606
607 tmp->insert_at (cauldron);
629 } 608 }
630 else if (level < 60) 609 else if (level < 60)
631 { /* CREATE MONSTER */ 610 { /* CREATE MONSTER */
632 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 ());
633 remove_contents (cauldron->inv, NULL); 612 remove_contents (cauldron->inv, NULL);
634 return;
635 } 613 }
636 else if (level < 80) 614 else if (level < 80)
637 { /* MAJOR FIRE */ 615 { /* MAJOR FIRE */
638 object *fb = get_archetype (SP_MED_FIREBALL); 616 object *fb = get_archetype (SP_MED_FIREBALL);
639 617
640 remove_contents (cauldron->inv, NULL); 618 remove_contents (cauldron->inv, NULL);
641 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);
642 free_object (fb); 620 fb->destroy (true);
643 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);
644 return;
645
646 } 622 }
647 else if (level < 100) 623 else if (level < 100)
648 { /* WHAMMY the CAULDRON */ 624 { /* WHAMMY the CAULDRON */
649 if (!QUERY_FLAG (cauldron, FLAG_CURSED)) 625 if (!QUERY_FLAG (cauldron, FLAG_CURSED))
650 SET_FLAG (cauldron, FLAG_CURSED); 626 SET_FLAG (cauldron, FLAG_CURSED);
651 else 627 else
652 cauldron->magic--; 628 cauldron->magic--;
629
653 cauldron->magic -= random_roll (0, 4, op, PREFER_LOW); 630 cauldron->magic -= random_roll (0, 4, op, PREFER_LOW);
631
654 if (rndm (0, 1)) 632 if (rndm (0, 1))
655 { 633 {
656 remove_contents (cauldron->inv, NULL); 634 remove_contents (cauldron->inv, NULL);
657 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);
658 } 636 }
659 else 637 else
660 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);
661 return;
662
663 } 639 }
664 else if (level < 110) 640 else if (level < 110)
665 { /* SUMMON EVIL MONSTERS */ 641 { /* SUMMON EVIL MONSTERS */
666 object *tmp = get_random_mon (level / 5); 642 object *tmp = get_random_mon (level / 5);
667 643
668 remove_contents (cauldron->inv, NULL); 644 remove_contents (cauldron->inv, NULL);
645
669 if (!tmp) 646 if (!tmp)
670 alchemy_failure_effect (op, cauldron, rp, level); 647 alchemy_failure_effect (op, cauldron, rp, level);
671 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))
672 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 ());
673 return;
674
675 } 650 }
676 else if (level < 150) 651 else if (level < 150)
677 { /* COMBO EFFECT */ 652 { /* COMBO EFFECT */
678 int roll = rndm (1, 3); 653 int roll = rndm (1, 3);
679 654
680 while (roll) 655 while (roll)
681 { 656 {
682 alchemy_failure_effect (op, cauldron, rp, level - 39); 657 alchemy_failure_effect (op, cauldron, rp, level - 39);
683 roll--; 658 roll--;
684 } 659 }
685 return;
686 } 660 }
687 else if (level == 151) 661 else if (level == 151)
688 { /* CREATE RANDOM ARTIFACT */ 662 { /* CREATE RANDOM ARTIFACT */
689 object *tmp; 663 object *tmp;
690 664
701 { 675 {
702 remove_contents (cauldron->inv, tmp); 676 remove_contents (cauldron->inv, tmp);
703 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 ());
704 } 678 }
705 } 679 }
706 return;
707 } 680 }
708 else 681 else
709 { /* MANA STORM - watch out!! */ 682 { /* MANA STORM - watch out!! */
710 object *tmp = get_archetype (LOOSE_MANA); 683 object *tmp = get_archetype (LOOSE_MANA);
711 684
712 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!");
713 remove_contents (cauldron->inv, NULL); 686 remove_contents (cauldron->inv, NULL);
714 cast_magic_storm (op, tmp, level); 687 cast_magic_storm (op, tmp, level);
715 return;
716 } 688 }
717} 689}
718 690
719 691/*
720/**
721 * All but object "save_item" are elimentated from 692 * All but object "save_item" are elimentated from
722 * 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
723 * 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).
724 */ 695 */
725
726void 696void
727remove_contents (object *first_ob, object *save_item) 697remove_contents (object *first_ob, object *save_item)
728{ 698{
699 // this cries for a cleaner rewrite, removing save_item first possibly
729 object *next, *tmp = first_ob; 700 object *next, *tmp = first_ob;
730 701
731 while (tmp) 702 while (tmp)
732 { 703 {
733 next = tmp->below; 704 next = tmp->below;
705
734 if (tmp == save_item) 706 if (tmp == save_item)
735 { 707 {
736 if (!(tmp = next)) 708 if (!(tmp = next))
737 break; 709 break;
738 else 710 else
739 next = next->below; 711 next = next->below;
740 } 712 }
713
741 if (tmp->inv) 714 if (tmp->inv)
742 remove_contents (tmp->inv, NULL); 715 remove_contents (tmp->inv, NULL);
743 remove_ob (tmp); 716
744 free_object (tmp); 717 tmp->destroy (true);
745 tmp = next; 718 tmp = next;
746 } 719 }
747} 720}
748 721
749/** 722/**
750 *"Danger" level, will determine how bad the backfire 723 *"Danger" level, will determine how bad the backfire
751 * 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
752 * 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,
753 * 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
754 * mixing device (aka "cauldron"). Higher values of 'danger' indicate more 727 * mixing device (aka "cauldron"). Higher values of 'danger' indicate more
755 * 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
756 * 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)
757 * -b.t. 730 * -b.t.
758 */ 731 */
759
760int 732int
761calc_alch_danger (object *caster, object *cauldron, recipe *rp) 733calc_alch_danger (object *caster, object *cauldron, recipe *rp)
762{ 734{
763 object *item; 735 object *item;
764 char name[MAX_BUF]; 736 char name[MAX_BUF];
765 int danger = 0, nrofi = 0; 737 int danger = 0, nrofi = 0;
766 738
767 /* Knowing alchemy skill reduces yer risk */ 739 /* Knowing alchemy skill reduces yer risk */
768 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 ());
769 745
770 /* better cauldrons reduce risk */ 746 /* better cauldrons reduce risk */
771 danger -= cauldron->magic; 747 danger -= cauldron->magic;
772 748
773 /* Higher Int, lower the risk */ 749 /* Higher Int, lower the risk */
777 * Thus the backfire is worse. Also, more ingredients 753 * Thus the backfire is worse. Also, more ingredients
778 * means we are attempting a more powerfull potion, 754 * means we are attempting a more powerfull potion,
779 * and thus the backfire will be worse. */ 755 * and thus the backfire will be worse. */
780 for (item = cauldron->inv; item; item = item->below) 756 for (item = cauldron->inv; item; item = item->below)
781 { 757 {
782 strcpy (name, item->name); 758 assign (name, item->name);
783 if (item->title) 759 if (item->title)
784 sprintf (name, "%s %s", &item->name, &item->title); 760 sprintf (name, "%s %s", &item->name, &item->title);
785 danger += (strtoint (name) / 1000) + 3; 761 danger += (strtoint (name) / 1000) + 3;
786 nrofi++; 762 nrofi++;
787 } 763 }
764
788 if (rp == NULL) 765 if (rp == NULL)
789 danger += 110; 766 danger += 110;
790 else 767 else
791 danger += rp->diff * 3; 768 danger += rp->diff * 3;
792 769
801#endif 778#endif
802 779
803 return danger; 780 return danger;
804} 781}
805 782
806/** 783/**
807 * Determines if ingredients in a container match the 784 * Determines if ingredients in a container match the
808 * proper ingredients for a recipe. 785 * proper ingredients for a recipe.
809 * 786 *
810 * rp is the recipe to check 787 * rp is the recipe to check
811 * cauldron is the container that holds the ingredients 788 * cauldron is the container that holds the ingredients
915 LOG (llevDebug, "looking for formula %d:\n", formula); 892 LOG (llevDebug, "looking for formula %d:\n", formula);
916#endif 893#endif
917 result = NULL; 894 result = NULL;
918 recipes_matching = 0; 895 recipes_matching = 0;
919 transmute_found = 0; 896 transmute_found = 0;
897
920 for (rp = fl->items; rp != NULL; rp = rp->next) 898 for (rp = fl->items; rp; rp = rp->next)
921 { 899 {
922 /* check if recipe matches at all */ 900 /* check if recipe matches at all */
923 if (formula % rp->index != 0) 901 if (formula % rp->index != 0)
924 { 902 {
925#ifdef EXTREME_ALCHEMY_DEBUG 903#ifdef EXTREME_ALCHEMY_DEBUG

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines