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.40 by root, Mon Oct 12 14:00:58 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 it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation; either version 2 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * 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 Affero GNU General Public License
19 * along with this program; if not, write to the Free Software 19 * and the GNU General Public License along with this program. If not, see
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * <http://www.gnu.org/licenses/>.
21 * 21 *
22 * The authors can be reached via e-mail at <crossfire@schmorp.de> 22 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 23 */
24 24
25/* March 96 - Laid down original code. -b.t. thomas@astro.psu.edu */ 25/* March 96 - Laid down original code. -b.t. thomas@astro.psu.edu */
26 26
27#include <global.h> 27#include <global.h>
95 * around. :) 95 * around. :)
96 * -b.t. 96 * -b.t.
97 */ 97 */
98 98
99void 99void
100attempt_do_alchemy (object *caster, object *cauldron) 100attempt_do_alchemy (object *caster, object *cauldron, object *skill)
101{ 101{
102 recipelist *fl; 102 recipelist *fl;
103 recipe *rp = NULL; 103 recipe *rp = NULL;
104 float success_chance; 104 float success_chance;
105 int numb, ability = 1; 105 int numb, ability = 1;
128 rp = find_recipe (fl, formula, cauldron->inv); 128 rp = find_recipe (fl, formula, cauldron->inv);
129 if (rp != NULL) 129 if (rp != NULL)
130 { 130 {
131#ifdef ALCHEMY_DEBUG 131#ifdef ALCHEMY_DEBUG
132 if (strcmp (rp->title, "NONE")) 132 if (strcmp (rp->title, "NONE"))
133 LOG (llevDebug, "WIZ got formula: %s of %s\n", rp->arch_name[0], rp->title); 133 LOG (llevDebug, "WIZ got formula: %s of %s\n", rp->arch_name[0], &rp->title);
134 else 134 else
135 LOG (llevDebug, "WIZ got formula: %s (nbatches:%d)\n", rp->arch_name[0], formula / rp->index); 135 LOG (llevDebug, "WIZ got formula: %s (nbatches:%d)\n", rp->arch_name[0], formula / rp->index);
136#endif 136#endif
137 attempt_recipe (caster, cauldron, ability, rp, formula / rp->index); 137 attempt_recipe (caster, cauldron, ability, rp, formula / rp->index);
138 } 138 }
141 return; 141 return;
142 } /* End of WIZ alchemy */ 142 } /* End of WIZ alchemy */
143 143
144 /* find the recipe */ 144 /* find the recipe */
145 rp = find_recipe (fl, formula, cauldron->inv); 145 rp = find_recipe (fl, formula, cauldron->inv);
146 if (rp) 146 if (rp
147 && rp->skill == skill->skill
148 && (!rp->cauldron
149 || rp->cauldron == cauldron->arch->archname))
147 { 150 {
148 uint64 value_ingredients; 151 uint64 value_ingredients;
149 uint64 value_item; 152 uint64 value_item;
150 object *tmp; 153 object *tmp;
151 int attempt_shadow_alchemy; 154 int attempt_shadow_alchemy;
152 155
153 ave_chance = fl->total_chance / (float) fl->number; 156 ave_chance = fl->total_chance / (float) fl->number;
154 /* the caster gets an increase in ability based on thier skill lvl */ 157
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)); 158 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 159
175 /* determine value of ingredients */ 160 /* determine value of ingredients */
176 value_ingredients = 0; 161 value_ingredients = 0;
177 for (tmp = cauldron->inv; tmp != NULL; tmp = tmp->below) 162 for (tmp = cauldron->inv; tmp != NULL; tmp = tmp->below)
178 value_ingredients += query_cost (tmp, NULL, F_TRUE); 163 value_ingredients += query_cost (tmp, NULL, F_TRUE);
232 int tval = 0, formula = 0; 217 int tval = 0, formula = 0;
233 218
234 while (tmp) 219 while (tmp)
235 { 220 {
236 tval = 0; 221 tval = 0;
237 strcpy (name, tmp->name); 222 assign (name, tmp->name);
238 if (tmp->title) 223 if (tmp->title)
239 sprintf (name, "%s %s", &tmp->name, &tmp->title); 224 sprintf (name, "%s %s", &tmp->name, &tmp->title);
240 tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1)); 225 tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1));
241#ifdef ALCHEMY_DEBUG 226#ifdef ALCHEMY_DEBUG
242 LOG (llevDebug, "Got ingredient %d %s(%d)\n", tmp->nrof ? tmp->nrof : 1, name, tval); 227 LOG (llevDebug, "Got ingredient %d %s(%d)\n", tmp->nrof ? tmp->nrof : 1, name, tval);
268 number++; 253 number++;
269 o_number++; 254 o_number++;
270 tmp = tmp->below; 255 tmp = tmp->below;
271 } 256 }
272#ifdef ALCHEMY_DEBUG 257#ifdef ALCHEMY_DEBUG
273 LOG (llevDebug, "numb_ob_inside(%s): found %d ingredients\n", op->name, o_number); 258 LOG (llevDebug, "numb_ob_inside(%s): found %d ingredients\n", &op->name, o_number);
274#endif 259#endif
275 return o_number; 260 return o_number;
276} 261}
277 262
278/** 263/**
290 object *item = NULL, *skop; 275 object *item = NULL, *skop;
291 276
292 /* this should be passed to this fctn, not effiecent cpu use this way */ 277 /* this should be passed to this fctn, not effiecent cpu use this way */
293 int batches = abs (nbatches); 278 int batches = abs (nbatches);
294 279
295
296 /* is the cauldron the right type? */ 280 /* is the cauldron the right type? */
297 if (strcmp (rp->cauldron, cauldron->arch->name) != 0) 281 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; 282 return 0;
301 }
302 283
303 skop = find_skill_by_name (caster, rp->skill); 284 skop = find_skill_by_name (caster, rp->skill);
304 /* does the caster have the skill? */ 285 /* does the caster have the skill? */
305 if (!skop) 286 if (!skop)
306 return 0; 287 return 0;
310 { 291 {
311 object *tmp; 292 object *tmp;
312 293
313 for (tmp = caster->inv; tmp; tmp = tmp->below) 294 for (tmp = caster->inv; tmp; tmp = tmp->below)
314 { 295 {
315 if (tmp->type == FORCE && tmp->slaying && !strcmp (rp->keycode, tmp->slaying)) 296 if (tmp->type == FORCE && tmp->slaying && rp->keycode == tmp->slaying)
316 break; 297 break;
317 } 298 }
318 299
319 if (!tmp) 300 if (!tmp)
320 { /* failure--no code found */ 301 { /* 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."); 302 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; 303 return 0;
323 } 304 }
324 } 305 }
325 306
326#ifdef EXTREME_ALCHEMY_DEBUG 307#ifdef EXTREME_ALCHEMY_DEBUG
327 LOG (llevDebug, "attempt_recipe(): got %d nbatches\n", nbatches); 308 LOG (llevDebug, "attempt_recipe(): got %d nbatches\n", nbatches);
328 LOG (llevDebug, "attempt_recipe(): using recipe %s\n", rp->title ? rp->title : "unknown"); 309 LOG (llevDebug, "attempt_recipe(): using recipe %s\n", *rp->title ? &rp->title : "unknown");
329#endif 310#endif
330 311
331 if ((item = make_item_from_recipe (cauldron, rp)) != NULL) 312 if ((item = make_item_from_recipe (cauldron, rp)) != NULL)
332 { 313 {
333 remove_contents (cauldron->inv, item); 314 remove_contents (cauldron->inv, item);
334 /* Recalc carrying of the cauldron, in case recipe did not conserve mass */ 315 /* Recalc carrying of the cauldron, in case recipe did not conserve mass */
335 sum_weight (cauldron); 316 cauldron->update_weight ();
336 /* adj lvl, nrof on caster level */ 317 /* adj lvl, nrof on caster level */
337 adjust_product (item, ability, rp->yield ? (rp->yield * batches) : batches); 318 adjust_product (item, ability, rp->yield ? (rp->yield * batches) : batches);
338 if (!item->env && (item = insert_ob_in_ob (item, cauldron)) == NULL) 319 if (!item->env && (item = insert_ob_in_ob (item, cauldron)) == NULL)
339 { 320 {
340 new_draw_info (NDI_UNIQUE, 0, caster, "Nothing happened."); 321 new_draw_info (NDI_UNIQUE, 0, caster, "Nothing happened.");
404 LOG (llevDebug, "make_alchemy_item(): failed to create alchemical object.\n"); 385 LOG (llevDebug, "make_alchemy_item(): failed to create alchemical object.\n");
405 return (object *) NULL; 386 return (object *) NULL;
406 } 387 }
407 388
408 /* Find the appropriate artifact template... */ 389 /* Find the appropriate artifact template... */
409 if (strcmp (rp->title, "NONE")) 390 if (rp->title != shstr_NONE)
410 { 391 {
411 if ((art = locate_recipe_artifact (rp, rp_arch_index)) == NULL) 392 if ((art = locate_recipe_artifact (rp, rp_arch_index)) == NULL)
412 { 393 {
413 LOG (llevError, "make_alchemy_item(): failed to locate recipe artifact.\n"); 394 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); 395 LOG (llevDebug, " --requested recipe: %s of %s.\n", rp->arch_name[0], &rp->title);
415 return (object *) NULL; 396 return (object *) NULL;
416 } 397 }
398
417 transmute_materialname (item, art->item); 399 transmute_materialname (item, art->item);
418 give_artifact_abilities (item, art->item); 400 give_artifact_abilities (item, art->item);
419 } 401 }
420 402
421 if (QUERY_FLAG (cauldron, FLAG_CURSED)) 403 if (QUERY_FLAG (cauldron, FLAG_CURSED))
435 * @param rp_arch_index pointer to return value; set to arch index for recipe; 417 * @param rp_arch_index pointer to return value; set to arch index for recipe;
436 * set to zero if not using a transmution formula 418 * set to zero if not using a transmution formula
437 */ 419 */
438 420
439object * 421object *
440find_transmution_ob (object *first_ingred, recipe *rp, size_t * rp_arch_index, int create_item) 422find_transmution_ob (object *first_ingred, recipe *rp, size_t *rp_arch_index, int create_item)
441{ 423{
442 object *item = NULL; 424 object *prod_item = 0;
443 425 bool found = false;
444 *rp_arch_index = 0; 426 *rp_arch_index = 0;
445 427
446 if (rp->transmute) /* look for matching ingredient/prod archs */ 428 if (rp->transmute) /* look for matching ingredient/prod archs */
447 for (item = first_ingred; item; item = item->below) 429 for (object *item = first_ingred; item; item = item->below)
448 { 430 {
449 size_t i;
450
451 for (i = 0; i < rp->arch_names; i++) 431 for (int i = 0; i < rp->arch_names; i++)
452 { 432 //TODO: should be a shstr comparison
453 if (strcmp (item->arch->name, rp->arch_name[i]) == 0) 433 if (!strcmp(&item->arch->archname,rp->arch_name[i]))
454 { 434 {
455 *rp_arch_index = i; 435 *rp_arch_index = i;
436 prod_item = item;
456 break; 437 break;
457 } 438 }
458 } 439
459 if (i < rp->arch_names) 440 if (prod_item)
460 break; 441 break;
461 } 442 }
462 443
463 /* failed, create a fresh object. Note no nrof>1 because that would 444 /* failed, create a fresh object. Note no nrof>1 because that would
464 * allow players to create massive amounts of artifacts easily */ 445 * allow players to create massive amounts of artifacts easily */
465 if (create_item && (!item || item->nrof > 1)) 446 if (create_item && (!prod_item || prod_item->nrof > 1))
447 {
448#ifdef ALCHEMY_DEBUG
449 LOG (llevDebug, "creating a new item.\n");
450 if (prod_item != NULL)
466 { 451 {
452 LOG (llevDebug, " had item: arch %s(nrof:%d)\n",
453 &prod_item->arch->archname, prod_item->nrof);
454 }
455#endif
456 if (!prod_item)
467 *rp_arch_index = RANDOM () % rp->arch_names; 457 *rp_arch_index = rndm (rp->arch_names);
468 item = get_archetype (rp->arch_name[*rp_arch_index]); 458 prod_item = get_archetype (rp->arch_name[*rp_arch_index]);
469 } 459 }
470 460
471#ifdef ALCHEMY_DEBUG 461#ifdef ALCHEMY_DEBUG
472 LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no "); 462 LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no ");
473 if (item != NULL) 463 if (prod_item != NULL)
474 { 464 {
475 LOG (llevDebug, " find_transmutable_ob(): returns arch %s(sp:%d)\n", item->arch->name, item->stats.sp); 465 LOG (llevDebug, " find_transmutable_ob(): returns arch %s(sp:%d)\n",
466 &prod_item->arch->archname, prod_item->stats.sp);
476 } 467 }
477#endif 468#endif
478 469
479 return item; 470 return prod_item;
480} 471}
481 472
482 473
483/** 474/**
484 * Ouch. We didnt get the formula we wanted. 475 * Ouch. We didnt get the formula we wanted.
510 501
511 if (rndm (0, 2)) 502 if (rndm (0, 2))
512 { /* slag created */ 503 { /* slag created */
513 object *tmp = cauldron->inv; 504 object *tmp = cauldron->inv;
514 int weight = 0; 505 int weight = 0;
515 uint16 material = M_STONE;
516 506
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"); 507 tmp = get_archetype ("rock");
525 tmp->weight = weight; 508 tmp->weight = weight;
526 tmp->value = 0; 509 tmp->value = 0;
527 tmp->material = material;
528 tmp->materialname = "stone"; 510 tmp->materialname = "stone";
529 tmp->name = "slag"; 511 tmp->name = "slag";
530 tmp->name_pl = "slags"; 512 tmp->name_pl = "slags";
531 item = insert_ob_in_ob (tmp, cauldron); 513 item = insert_ob_in_ob (tmp, cauldron);
532 CLEAR_FLAG (tmp, FLAG_CAN_ROLL); 514 CLEAR_FLAG (tmp, FLAG_CAN_ROLL);
533 CLEAR_FLAG (tmp, FLAG_NO_PICK); 515 CLEAR_FLAG (tmp, FLAG_NO_PICK);
534 tmp->move_block = 0; 516 tmp->move_block = 0;
535 } 517 }
518
536 remove_contents (cauldron->inv, item); 519 remove_contents (cauldron->inv, item);
537 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); 520 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ());
538 return; 521 return;
539 } 522 }
540 else if (level < 40) 523 else if (level < 40)
566 } 549 }
567 while (rndm (0, 2)); 550 while (rndm (0, 2));
568 } 551 }
569 return; 552 return;
570 } 553 }
554
571 if (level == 40) 555 if (level == 40)
572 { /* MAKE RANDOM RECIPE */ 556 { /* MAKE RANDOM RECIPE */
573 recipelist *fl; 557 recipelist *fl;
574 int numb = numb_ob_inside (cauldron); 558 int numb = numb_ob_inside (cauldron);
575 559
577 if (fl && (rp = get_random_recipe (fl))) 561 if (fl && (rp = get_random_recipe (fl)))
578 /* even though random, don't grant user any EXP for it */ 562 /* even though random, don't grant user any EXP for it */
579 (void) attempt_recipe (op, cauldron, 1, rp, -1); 563 (void) attempt_recipe (op, cauldron, 1, rp, -1);
580 else 564 else
581 alchemy_failure_effect (op, cauldron, rp, level - 1); 565 alchemy_failure_effect (op, cauldron, rp, level - 1);
582 return;
583
584 } 566 }
585 else if (level < 45) 567 else if (level < 45)
586 { /* INFURIATE NPC's */ 568 { /* INFURIATE NPC's */
587 /* this is kind of kludgy I know... */ 569 /* this is kind of kludgy I know... */
588 cauldron->enemy = op; 570 cauldron->enemy = op;
589 npc_call_help (cauldron); 571 npc_call_help (cauldron);
590 cauldron->enemy = NULL; 572 cauldron->enemy = NULL;
591 573
592 alchemy_failure_effect (op, cauldron, rp, level - 5); 574 alchemy_failure_effect (op, cauldron, rp, level - 5);
593 return;
594 } 575 }
595 else if (level < 50) 576 else if (level < 50)
596 { /* MINOR EXPLOSION/FIREBALL */ 577 { /* MINOR EXPLOSION/FIREBALL */
597 object *tmp; 578 object *tmp;
598 579
612 tmp->stats.hp = random_roll (1, level, op, PREFER_LOW) / 10 + 2; 593 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); 594 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name);
614 break; 595 break;
615 } 596 }
616 597
617 op->insert_at (cauldron); 598 tmp->insert_at (cauldron);
618 return;
619
620 } 599 }
621 else if (level < 60) 600 else if (level < 60)
622 { /* CREATE MONSTER */ 601 { /* CREATE MONSTER */
623 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); 602 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ());
624 remove_contents (cauldron->inv, NULL); 603 remove_contents (cauldron->inv, NULL);
625 return;
626 } 604 }
627 else if (level < 80) 605 else if (level < 80)
628 { /* MAJOR FIRE */ 606 { /* MAJOR FIRE */
629 object *fb = get_archetype (SP_MED_FIREBALL); 607 object *fb = get_archetype (SP_MED_FIREBALL);
630 608
631 remove_contents (cauldron->inv, NULL); 609 remove_contents (cauldron->inv, NULL);
632 fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb); 610 fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb);
633 fb->destroy (); 611 fb->destroy ();
634 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); 612 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name);
635 return;
636
637 } 613 }
638 else if (level < 100) 614 else if (level < 100)
639 { /* WHAMMY the CAULDRON */ 615 { /* WHAMMY the CAULDRON */
640 if (!QUERY_FLAG (cauldron, FLAG_CURSED)) 616 if (!QUERY_FLAG (cauldron, FLAG_CURSED))
641 SET_FLAG (cauldron, FLAG_CURSED); 617 SET_FLAG (cauldron, FLAG_CURSED);
642 else 618 else
643 cauldron->magic--; 619 cauldron->magic--;
620
644 cauldron->magic -= random_roll (0, 4, op, PREFER_LOW); 621 cauldron->magic -= random_roll (0, 4, op, PREFER_LOW);
622
645 if (rndm (0, 1)) 623 if (rndm (0, 1))
646 { 624 {
647 remove_contents (cauldron->inv, NULL); 625 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); 626 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s turns darker then makes a gulping sound!", &cauldron->name);
649 } 627 }
650 else 628 else
651 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s becomes darker.", &cauldron->name); 629 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s becomes darker.", &cauldron->name);
652 return;
653
654 } 630 }
655 else if (level < 110) 631 else if (level < 110)
656 { /* SUMMON EVIL MONSTERS */ 632 { /* SUMMON EVIL MONSTERS */
657 object *tmp = get_random_mon (level / 5); 633 object *tmp = get_random_mon (level / 5);
658 634
659 remove_contents (cauldron->inv, NULL); 635 remove_contents (cauldron->inv, NULL);
636
660 if (!tmp) 637 if (!tmp)
661 alchemy_failure_effect (op, cauldron, rp, level); 638 alchemy_failure_effect (op, cauldron, rp, level);
662 else if (summon_hostile_monsters (cauldron, random_roll (1, 10, op, PREFER_LOW), tmp->arch->name)) 639 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 ()); 640 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s and then pours forth monsters!", &cauldron->name, cauldron_sound ());
664 return;
665
666 } 641 }
667 else if (level < 150) 642 else if (level < 150)
668 { /* COMBO EFFECT */ 643 { /* COMBO EFFECT */
669 int roll = rndm (1, 3); 644 int roll = rndm (1, 3);
670 645
671 while (roll) 646 while (roll)
672 { 647 {
673 alchemy_failure_effect (op, cauldron, rp, level - 39); 648 alchemy_failure_effect (op, cauldron, rp, level - 39);
674 roll--; 649 roll--;
675 } 650 }
676 return;
677 } 651 }
678 else if (level == 151) 652 else if (level == 151)
679 { /* CREATE RANDOM ARTIFACT */ 653 { /* CREATE RANDOM ARTIFACT */
680 object *tmp; 654 object *tmp;
681 655
683 * in this one, we allow *any* valid alchemy artifact 657 * in this one, we allow *any* valid alchemy artifact
684 * to be made (rather than only those on the given 658 * to be made (rather than only those on the given
685 * formulalist) */ 659 * formulalist) */
686 if (!rp) 660 if (!rp)
687 rp = get_random_recipe ((recipelist *) NULL); 661 rp = get_random_recipe ((recipelist *) NULL);
662
688 if (rp && (tmp = get_archetype (rp->arch_name[RANDOM () % rp->arch_names]))) 663 if (rp && (tmp = get_archetype (rp->arch_name [rndm (rp->arch_names)])))
689 { 664 {
690 generate_artifact (tmp, random_roll (1, op->level / 2 + 1, op, PREFER_HIGH) + 1); 665 generate_artifact (tmp, random_roll (1, op->level / 2 + 1, op, PREFER_HIGH) + 1);
691 if ((tmp = insert_ob_in_ob (tmp, cauldron))) 666 if ((tmp = insert_ob_in_ob (tmp, cauldron)))
692 { 667 {
693 remove_contents (cauldron->inv, tmp); 668 remove_contents (cauldron->inv, tmp);
694 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); 669 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ());
695 } 670 }
696 } 671 }
697 return;
698 } 672 }
699 else 673 else
700 { /* MANA STORM - watch out!! */ 674 { /* MANA STORM - watch out!! */
701 object *tmp = get_archetype (LOOSE_MANA); 675 object *tmp = get_archetype (LOOSE_MANA);
702 676
703 new_draw_info (NDI_UNIQUE, 0, op, "You unwisely release potent forces!"); 677 new_draw_info (NDI_UNIQUE, 0, op, "You unwisely release potent forces!");
704 remove_contents (cauldron->inv, NULL); 678 remove_contents (cauldron->inv, NULL);
705 cast_magic_storm (op, tmp, level); 679 cast_magic_storm (op, tmp, level);
706 return;
707 } 680 }
708} 681}
709
710 682
711/* 683/*
712 * All but object "save_item" are elimentated from 684 * All but object "save_item" are elimentated from
713 * the container list. Note we have to becareful to remove the inventories 685 * 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). 686 * of objects in the cauldron inventory (ex icecube has stuff in it).
715 */ 687 */
716
717void 688void
718remove_contents (object *first_ob, object *save_item) 689remove_contents (object *first_ob, object *save_item)
719{ 690{
691 // this cries for a cleaner rewrite, removing save_item first possibly
720 object *next, *tmp = first_ob; 692 object *next, *tmp = first_ob;
721 693
722 while (tmp) 694 while (tmp)
723 { 695 {
724 next = tmp->below; 696 next = tmp->below;
737 tmp->destroy (); 709 tmp->destroy ();
738 tmp = next; 710 tmp = next;
739 } 711 }
740} 712}
741 713
742/** 714/**
743 *"Danger" level, will determine how bad the backfire 715 *"Danger" level, will determine how bad the backfire
744 * could be if the user fails to concoct a recipe properly. Factors include 716 * 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, 717 * 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 718 * 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 719 * 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 720 * 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) 721 * skill *before* this routine is called. (no longer auto-readies that skill)
750 * -b.t. 722 * -b.t.
751 */ 723 */
752
753int 724int
754calc_alch_danger (object *caster, object *cauldron, recipe *rp) 725calc_alch_danger (object *caster, object *cauldron, recipe *rp)
755{ 726{
756 object *item; 727 object *item;
757 char name[MAX_BUF]; 728 char name[MAX_BUF];
758 int danger = 0, nrofi = 0; 729 int danger = 0, nrofi = 0;
759 730
760 /* Knowing alchemy skill reduces yer risk */ 731 /* Knowing alchemy skill reduces yer risk */
761 danger -= caster->chosen_skill ? caster->chosen_skill->level : caster->level; 732 danger -= caster->chosen_skill ? caster->chosen_skill->level : caster->level;
733
734 if (!caster->chosen_skill)
735 LOG (llevError | logBacktrace, "calc_alch_danger called without a chosen skill, caster %s, cauldron %s\n",
736 caster->debug_desc (), cauldron->debug_desc ());
762 737
763 /* better cauldrons reduce risk */ 738 /* better cauldrons reduce risk */
764 danger -= cauldron->magic; 739 danger -= cauldron->magic;
765 740
766 /* Higher Int, lower the risk */ 741 /* Higher Int, lower the risk */
770 * Thus the backfire is worse. Also, more ingredients 745 * Thus the backfire is worse. Also, more ingredients
771 * means we are attempting a more powerfull potion, 746 * means we are attempting a more powerfull potion,
772 * and thus the backfire will be worse. */ 747 * and thus the backfire will be worse. */
773 for (item = cauldron->inv; item; item = item->below) 748 for (item = cauldron->inv; item; item = item->below)
774 { 749 {
775 strcpy (name, item->name); 750 assign (name, item->name);
776 if (item->title) 751 if (item->title)
777 sprintf (name, "%s %s", &item->name, &item->title); 752 sprintf (name, "%s %s", &item->name, &item->title);
778 danger += (strtoint (name) / 1000) + 3; 753 danger += (strtoint (name) / 1000) + 3;
779 nrofi++; 754 nrofi++;
780 } 755 }
756
781 if (rp == NULL) 757 if (rp == NULL)
782 danger += 110; 758 danger += 110;
783 else 759 else
784 danger += rp->diff * 3; 760 danger += rp->diff * 3;
785 761
794#endif 770#endif
795 771
796 return danger; 772 return danger;
797} 773}
798 774
799/** 775/**
800 * Determines if ingredients in a container match the 776 * Determines if ingredients in a container match the
801 * proper ingredients for a recipe. 777 * proper ingredients for a recipe.
802 * 778 *
803 * rp is the recipe to check 779 * rp is the recipe to check
804 * cauldron is the container that holds the ingredients 780 * cauldron is the container that holds the ingredients
853 for (ob = cauldron->inv; ob != NULL; ob = ob->below) 829 for (ob = cauldron->inv; ob != NULL; ob = ob->below)
854 { 830 {
855 char name_ob[MAX_BUF]; 831 char name_ob[MAX_BUF];
856 const char *name2; 832 const char *name2;
857 833
858 if (ob->title == NULL) 834 if (!ob->title)
859 name2 = ob->name; 835 name2 = ob->name;
860 else 836 else
861 { 837 {
862 snprintf (name_ob, sizeof (name_ob), "%s %s", &ob->name, &ob->title); 838 snprintf (name_ob, sizeof (name_ob), "%s %s", &ob->name, &ob->title);
863 name2 = name_ob; 839 name2 = name_ob;
908 LOG (llevDebug, "looking for formula %d:\n", formula); 884 LOG (llevDebug, "looking for formula %d:\n", formula);
909#endif 885#endif
910 result = NULL; 886 result = NULL;
911 recipes_matching = 0; 887 recipes_matching = 0;
912 transmute_found = 0; 888 transmute_found = 0;
889
913 for (rp = fl->items; rp != NULL; rp = rp->next) 890 for (rp = fl->items; rp; rp = rp->next)
914 { 891 {
915 /* check if recipe matches at all */ 892 /* check if recipe matches at all */
916 if (formula % rp->index != 0) 893 if (formula % rp->index != 0)
917 { 894 {
918#ifdef EXTREME_ALCHEMY_DEBUG 895#ifdef EXTREME_ALCHEMY_DEBUG
919 LOG (llevDebug, " formula %s of %s (%d) does not match\n", rp->arch_name[0], rp->title, rp->index); 896 LOG (llevDebug, " formula %s of %s (%d) does not match\n", rp->arch_name[0], &rp->title, rp->index);
920#endif 897#endif
921 continue; 898 continue;
922 } 899 }
923 900
924 if (rp->transmute && find_transmution_ob (ingredients, rp, &rp_arch_index, 0) != NULL) 901 if (rp->transmute && find_transmution_ob (ingredients, rp, &rp_arch_index, 0) != NULL)
925 { 902 {
926#ifdef EXTREME_ALCHEMY_DEBUG 903#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); 904 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 905#endif
929 /* transmution recipe with matching base ingredient */ 906 /* transmution recipe with matching base ingredient */
930 if (!transmute_found) 907 if (!transmute_found)
931 { 908 {
932 transmute_found = 1; 909 transmute_found = 1;
934 } 911 }
935 } 912 }
936 else if (transmute_found) 913 else if (transmute_found)
937 { 914 {
938#ifdef EXTREME_ALCHEMY_DEBUG 915#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, 916 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); 917 rp->index);
941#endif 918#endif
942 /* "normal" recipe found after previous transmution recipe => ignore this recipe */ 919 /* "normal" recipe found after previous transmution recipe => ignore this recipe */
943 continue; 920 continue;
944 } 921 }
945#ifdef EXTREME_ALCHEMY_DEBUG 922#ifdef EXTREME_ALCHEMY_DEBUG
946 else 923 else
947 { 924 {
948 LOG (llevDebug, " formula %s of %s (%d) matches\n", rp->arch_name[0], rp->title, rp->index); 925 LOG (llevDebug, " formula %s of %s (%d) matches\n", rp->arch_name[0], &rp->title, rp->index);
949 } 926 }
950#endif 927#endif
951 928
952 if (rndm (0, recipes_matching) == 0) 929 if (rndm (0, recipes_matching) == 0)
953 result = rp; 930 result = rp;
963 return NULL; 940 return NULL;
964 } 941 }
965 942
966#ifdef ALCHEMY_DEBUG 943#ifdef ALCHEMY_DEBUG
967 if (strcmp (result->title, "NONE") != 0) 944 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); 945 LOG (llevDebug, "got formula: %s of %s (nbatches:%d)\n", result->arch_name[0], &result->title, formula / result->index);
969 else 946 else
970 LOG (llevDebug, "got formula: %s (nbatches:%d)\n", result->arch_name[0], formula / result->index); 947 LOG (llevDebug, "got formula: %s (nbatches:%d)\n", result->arch_name[0], formula / result->index);
971#endif 948#endif
972 return result; 949 return result;
973} 950}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines