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.15 by root, Tue Dec 26 20:04:09 2006 UTC vs.
Revision 1.38 by sf-marcmagus, Fri Oct 9 22:46: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 (©) 2005,2006,2007,2008,2009 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>
94 * around. :) 94 * around. :)
95 * -b.t. 95 * -b.t.
96 */ 96 */
97 97
98void 98void
99attempt_do_alchemy (object *caster, object *cauldron) 99attempt_do_alchemy (object *caster, object *cauldron, object *skill)
100{ 100{
101 recipelist *fl; 101 recipelist *fl;
102 recipe *rp = NULL; 102 recipe *rp = NULL;
103 float success_chance; 103 float success_chance;
104 int numb, ability = 1; 104 int numb, ability = 1;
127 rp = find_recipe (fl, formula, cauldron->inv); 127 rp = find_recipe (fl, formula, cauldron->inv);
128 if (rp != NULL) 128 if (rp != NULL)
129 { 129 {
130#ifdef ALCHEMY_DEBUG 130#ifdef ALCHEMY_DEBUG
131 if (strcmp (rp->title, "NONE")) 131 if (strcmp (rp->title, "NONE"))
132 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);
133 else 133 else
134 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);
135#endif 135#endif
136 attempt_recipe (caster, cauldron, ability, rp, formula / rp->index); 136 attempt_recipe (caster, cauldron, ability, rp, formula / rp->index);
137 } 137 }
140 return; 140 return;
141 } /* End of WIZ alchemy */ 141 } /* End of WIZ alchemy */
142 142
143 /* find the recipe */ 143 /* find the recipe */
144 rp = find_recipe (fl, formula, cauldron->inv); 144 rp = find_recipe (fl, formula, cauldron->inv);
145 if (rp) 145 if (rp
146 && rp->skill == skill->skill
147 && (!rp->cauldron
148 || rp->cauldron == cauldron->arch->archname))
146 { 149 {
147 uint64 value_ingredients; 150 uint64 value_ingredients;
148 uint64 value_item; 151 uint64 value_item;
149 object *tmp; 152 object *tmp;
150 int attempt_shadow_alchemy; 153 int attempt_shadow_alchemy;
151 154
152 ave_chance = fl->total_chance / (float) fl->number; 155 ave_chance = fl->total_chance / (float) fl->number;
153 /* the caster gets an increase in ability based on thier skill lvl */ 156
154 if (rp->skill)
155 {
156 skop = find_skill_by_name (caster, rp->skill);
157 if (!skop)
158 new_draw_info (NDI_UNIQUE, 0, caster, "You do not have the proper skill for this recipe");
159 else
160 ability += (int) (skop->level * ((4.0 + cauldron->magic) / 4.0)); 157 ability += (int) (skill->level * ((4.0 + cauldron->magic) / 4.0));
161 }
162 else
163 {
164 LOG (llevDebug, "Recipe %s has NULL skill!\n", &rp->title);
165 return;
166 }
167
168 if (!rp->cauldron)
169 {
170 LOG (llevDebug, "Recipe %s has NULL cauldron!\n", &rp->title);
171 return;
172 }
173 158
174 /* determine value of ingredients */ 159 /* determine value of ingredients */
175 value_ingredients = 0; 160 value_ingredients = 0;
176 for (tmp = cauldron->inv; tmp != NULL; tmp = tmp->below) 161 for (tmp = cauldron->inv; tmp != NULL; tmp = tmp->below)
177 value_ingredients += query_cost (tmp, NULL, F_TRUE); 162 value_ingredients += query_cost (tmp, NULL, F_TRUE);
231 int tval = 0, formula = 0; 216 int tval = 0, formula = 0;
232 217
233 while (tmp) 218 while (tmp)
234 { 219 {
235 tval = 0; 220 tval = 0;
236 strcpy (name, tmp->name); 221 assign (name, tmp->name);
237 if (tmp->title) 222 if (tmp->title)
238 sprintf (name, "%s %s", &tmp->name, &tmp->title); 223 sprintf (name, "%s %s", &tmp->name, &tmp->title);
239 tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1)); 224 tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1));
240#ifdef ALCHEMY_DEBUG 225#ifdef ALCHEMY_DEBUG
241 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);
267 number++; 252 number++;
268 o_number++; 253 o_number++;
269 tmp = tmp->below; 254 tmp = tmp->below;
270 } 255 }
271#ifdef ALCHEMY_DEBUG 256#ifdef ALCHEMY_DEBUG
272 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);
273#endif 258#endif
274 return o_number; 259 return o_number;
275} 260}
276 261
277/** 262/**
289 object *item = NULL, *skop; 274 object *item = NULL, *skop;
290 275
291 /* 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 */
292 int batches = abs (nbatches); 277 int batches = abs (nbatches);
293 278
294
295 LOG (llevDebug, "A %s <=> %s\n", &(rp->cauldron), &(cauldron->arch->name));
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;
308 /* code required for this recipe, search the caster */ 288 /* code required for this recipe, search the caster */
309 if (rp->keycode) 289 if (rp->keycode)
310 { 290 {
311 object *tmp; 291 object *tmp;
312 292
313 for (tmp = caster->inv; tmp != NULL; 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 }
298
318 if (tmp == NULL) 299 if (!tmp)
319 { /* failure--no code found */ 300 { /* failure--no code found */
320 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.");
321 return 0; 302 return 0;
322 } 303 }
323 } 304 }
324 305
325#ifdef EXTREME_ALCHEMY_DEBUG 306#ifdef EXTREME_ALCHEMY_DEBUG
326 LOG (llevDebug, "attempt_recipe(): got %d nbatches\n", nbatches); 307 LOG (llevDebug, "attempt_recipe(): got %d nbatches\n", nbatches);
327 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");
328#endif 309#endif
329 310
330 if ((item = make_item_from_recipe (cauldron, rp)) != NULL) 311 if ((item = make_item_from_recipe (cauldron, rp)) != NULL)
331 { 312 {
332 remove_contents (cauldron->inv, item); 313 remove_contents (cauldron->inv, item);
333 /* 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 */
334 sum_weight (cauldron); 315 cauldron->update_weight ();
335 /* adj lvl, nrof on caster level */ 316 /* adj lvl, nrof on caster level */
336 adjust_product (item, ability, rp->yield ? (rp->yield * batches) : batches); 317 adjust_product (item, ability, rp->yield ? (rp->yield * batches) : batches);
337 if (!item->env && (item = insert_ob_in_ob (item, cauldron)) == NULL) 318 if (!item->env && (item = insert_ob_in_ob (item, cauldron)) == NULL)
338 { 319 {
339 new_draw_info (NDI_UNIQUE, 0, caster, "Nothing happened."); 320 new_draw_info (NDI_UNIQUE, 0, caster, "Nothing happened.");
340 /* new_draw_info_format(NDI_UNIQUE, 0,caster, 321 /* new_draw_info_format(NDI_UNIQUE, 0,caster,
341 "Your spell causes the %s to explode!",&cauldron->name); */ 322 "Your spell causes the %s to explode!",&cauldron->name); */
342 /* kaboom_cauldron(); */ 323 /* kaboom_cauldron(); */
343 } 324 }
344 else 325 else
345 {
346 new_draw_info_format (NDI_UNIQUE, 0, caster, "The %s %s.", &cauldron->name, cauldron_sound ()); 326 new_draw_info_format (NDI_UNIQUE, 0, caster, "The %s %s.", &cauldron->name, cauldron_sound ());
347 }
348 } 327 }
328
349 return item; 329 return item;
350} 330}
351 331
352 332
353 333
354/** 334/**
355 * We adjust the nrof, exp and level of the final product, based 335 * We adjust the nrof, exp and level of the final product, based
356 * on the item's default parameters, and the relevant caster skill level. 336 * on the item's default parameters, and the relevant caster skill level.
357 */ 337 */
358 void 338void
359adjust_product (object *item, int lvl, int yield) 339adjust_product (object *item, int lvl, int yield)
360{ 340{
361 int nrof = 1; 341 int nrof = 1;
362 342
363 if (!yield) 343 if (!yield)
364 yield = 1; 344 yield = 1;
345
365 if (lvl <= 0) 346 if (lvl <= 0)
366 lvl = 1; /* lets avoid div by zero! */ 347 lvl = 1; /* lets avoid div by zero! */
348
367 if (item->nrof) 349 if (item->nrof)
368 { 350 {
369 nrof = (int) ((1.0 - 1.0 / (lvl / 10.0 + 1.0)) * (rndm (0, yield - 1) + rndm (0, yield - 1) + rndm (0, yield - 1)) + 1); 351 nrof = (int) ((1.0 - 1.0 / (lvl / 10.0 + 1.0)) * (rndm (0, yield - 1) + rndm (0, yield - 1) + rndm (0, yield - 1)) + 1);
352
370 if (nrof > yield) 353 if (nrof > yield)
371 nrof = yield; 354 nrof = yield;
355
372 item->nrof = nrof; 356 item->nrof = nrof;
373 } 357 }
374} 358}
375 359
376 360
400 LOG (llevDebug, "make_alchemy_item(): failed to create alchemical object.\n"); 384 LOG (llevDebug, "make_alchemy_item(): failed to create alchemical object.\n");
401 return (object *) NULL; 385 return (object *) NULL;
402 } 386 }
403 387
404 /* Find the appropriate artifact template... */ 388 /* Find the appropriate artifact template... */
405 if (strcmp (rp->title, "NONE")) 389 if (rp->title != shstr_NONE)
406 { 390 {
407 if ((art = locate_recipe_artifact (rp, rp_arch_index)) == NULL) 391 if ((art = locate_recipe_artifact (rp, rp_arch_index)) == NULL)
408 { 392 {
409 LOG (llevError, "make_alchemy_item(): failed to locate recipe artifact.\n"); 393 LOG (llevError, "make_alchemy_item(): failed to locate recipe artifact.\n");
410 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);
411 return (object *) NULL; 395 return (object *) NULL;
412 } 396 }
397
413 transmute_materialname (item, art->item); 398 transmute_materialname (item, art->item);
414 give_artifact_abilities (item, art->item); 399 give_artifact_abilities (item, art->item);
415 } 400 }
416 401
417 if (QUERY_FLAG (cauldron, FLAG_CURSED)) 402 if (QUERY_FLAG (cauldron, FLAG_CURSED))
431 * @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;
432 * set to zero if not using a transmution formula 417 * set to zero if not using a transmution formula
433 */ 418 */
434 419
435object * 420object *
436find_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)
437{ 422{
438 object *item = NULL; 423 object *prod_item = 0;
439 424 bool found = false;
440 *rp_arch_index = 0; 425 *rp_arch_index = 0;
441 426
442 if (rp->transmute) /* look for matching ingredient/prod archs */ 427 if (rp->transmute) /* look for matching ingredient/prod archs */
443 for (item = first_ingred; item; item = item->below) 428 for (object *item = first_ingred; item; item = item->below)
444 { 429 {
445 size_t i;
446
447 for (i = 0; i < rp->arch_names; i++) 430 for (int i = 0; i < rp->arch_names; i++)
448 { 431 //TODO: should be a shstr comparison
449 if (strcmp (item->arch->name, rp->arch_name[i]) == 0) 432 if (&item->arch->archname == rp->arch_name[i])
450 { 433 {
451 *rp_arch_index = i; 434 *rp_arch_index = i;
435 prod_item = item;
452 break; 436 break;
453 } 437 }
454 } 438
455 if (i < rp->arch_names) 439 if (prod_item)
456 break; 440 break;
457 } 441 }
458 442
459 /* 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
460 * allow players to create massive amounts of artifacts easily */ 444 * allow players to create massive amounts of artifacts easily */
461 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)
462 { 450 {
451 LOG (llevDebug, " had item: arch %s(nrof:%d)\n",
452 &prod_item->arch->archname, prod_item->nrof);
453 }
454#endif
463 *rp_arch_index = RANDOM () % rp->arch_names; 455 *rp_arch_index = rndm (rp->arch_names);
464 item = get_archetype (rp->arch_name[*rp_arch_index]); 456 prod_item = get_archetype (rp->arch_name[*rp_arch_index]);
465 } 457 }
466 458
467#ifdef ALCHEMY_DEBUG 459#ifdef ALCHEMY_DEBUG
468 LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no "); 460 LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no ");
469 if (item != NULL) 461 if (prod_item != NULL)
470 { 462 {
471 LOG (llevDebug, " find_transmutable_ob(): returns arch %s(sp:%d)\n", item->arch->name, item->stats.sp); 463 LOG (llevDebug, " find_transmutable_ob(): returns arch %s(sp:%d)\n",
464 &prod_item->arch->archname, prod_item->stats.sp);
472 } 465 }
473#endif 466#endif
474 467
475 return item; 468 return prod_item;
476} 469}
477 470
478 471
479/** 472/**
480 * Ouch. We didnt get the formula we wanted. 473 * Ouch. We didnt get the formula we wanted.
506 499
507 if (rndm (0, 2)) 500 if (rndm (0, 2))
508 { /* slag created */ 501 { /* slag created */
509 object *tmp = cauldron->inv; 502 object *tmp = cauldron->inv;
510 int weight = 0; 503 int weight = 0;
511 uint16 material = M_STONE;
512 504
513 while (tmp)
514 { /* slag has coadded ingredient properties */
515 weight += tmp->weight;
516 if (!(material & tmp->material))
517 material |= tmp->material;
518 tmp = tmp->below;
519 }
520 tmp = get_archetype ("rock"); 505 tmp = get_archetype ("rock");
521 tmp->weight = weight; 506 tmp->weight = weight;
522 tmp->value = 0; 507 tmp->value = 0;
523 tmp->material = material;
524 tmp->materialname = "stone"; 508 tmp->materialname = "stone";
525 tmp->name = "slag"; 509 tmp->name = "slag";
526 tmp->name_pl = "slags"; 510 tmp->name_pl = "slags";
527 item = insert_ob_in_ob (tmp, cauldron); 511 item = insert_ob_in_ob (tmp, cauldron);
528 CLEAR_FLAG (tmp, FLAG_CAN_ROLL); 512 CLEAR_FLAG (tmp, FLAG_CAN_ROLL);
529 CLEAR_FLAG (tmp, FLAG_NO_PICK); 513 CLEAR_FLAG (tmp, FLAG_NO_PICK);
530 tmp->move_block = 0; 514 tmp->move_block = 0;
531 } 515 }
516
532 remove_contents (cauldron->inv, item); 517 remove_contents (cauldron->inv, item);
533 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); 518 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ());
534 return; 519 return;
535 } 520 }
536 else if (level < 40) 521 else if (level < 40)
562 } 547 }
563 while (rndm (0, 2)); 548 while (rndm (0, 2));
564 } 549 }
565 return; 550 return;
566 } 551 }
552
567 if (level == 40) 553 if (level == 40)
568 { /* MAKE RANDOM RECIPE */ 554 { /* MAKE RANDOM RECIPE */
569 recipelist *fl; 555 recipelist *fl;
570 int numb = numb_ob_inside (cauldron); 556 int numb = numb_ob_inside (cauldron);
571 557
573 if (fl && (rp = get_random_recipe (fl))) 559 if (fl && (rp = get_random_recipe (fl)))
574 /* even though random, don't grant user any EXP for it */ 560 /* even though random, don't grant user any EXP for it */
575 (void) attempt_recipe (op, cauldron, 1, rp, -1); 561 (void) attempt_recipe (op, cauldron, 1, rp, -1);
576 else 562 else
577 alchemy_failure_effect (op, cauldron, rp, level - 1); 563 alchemy_failure_effect (op, cauldron, rp, level - 1);
578 return;
579
580 } 564 }
581 else if (level < 45) 565 else if (level < 45)
582 { /* INFURIATE NPC's */ 566 { /* INFURIATE NPC's */
583 /* this is kind of kludgy I know... */ 567 /* this is kind of kludgy I know... */
584 cauldron->enemy = op; 568 cauldron->enemy = op;
585 npc_call_help (cauldron); 569 npc_call_help (cauldron);
586 cauldron->enemy = NULL; 570 cauldron->enemy = NULL;
587 571
588 alchemy_failure_effect (op, cauldron, rp, level - 5); 572 alchemy_failure_effect (op, cauldron, rp, level - 5);
589 return;
590 } 573 }
591 else if (level < 50) 574 else if (level < 50)
592 { /* MINOR EXPLOSION/FIREBALL */ 575 { /* MINOR EXPLOSION/FIREBALL */
593 object *tmp; 576 object *tmp;
594 577
608 tmp->stats.hp = random_roll (1, level, op, PREFER_LOW) / 10 + 2; 591 tmp->stats.hp = random_roll (1, level, op, PREFER_LOW) / 10 + 2;
609 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); 592 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name);
610 break; 593 break;
611 } 594 }
612 595
613 op->insert_at (cauldron); 596 tmp->insert_at (cauldron);
614 return;
615
616 } 597 }
617 else if (level < 60) 598 else if (level < 60)
618 { /* CREATE MONSTER */ 599 { /* CREATE MONSTER */
619 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); 600 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ());
620 remove_contents (cauldron->inv, NULL); 601 remove_contents (cauldron->inv, NULL);
621 return;
622 } 602 }
623 else if (level < 80) 603 else if (level < 80)
624 { /* MAJOR FIRE */ 604 { /* MAJOR FIRE */
625 object *fb = get_archetype (SP_MED_FIREBALL); 605 object *fb = get_archetype (SP_MED_FIREBALL);
626 606
627 remove_contents (cauldron->inv, NULL); 607 remove_contents (cauldron->inv, NULL);
628 fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb); 608 fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb);
629 fb->destroy (); 609 fb->destroy ();
630 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); 610 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name);
631 return;
632
633 } 611 }
634 else if (level < 100) 612 else if (level < 100)
635 { /* WHAMMY the CAULDRON */ 613 { /* WHAMMY the CAULDRON */
636 if (!QUERY_FLAG (cauldron, FLAG_CURSED)) 614 if (!QUERY_FLAG (cauldron, FLAG_CURSED))
637 SET_FLAG (cauldron, FLAG_CURSED); 615 SET_FLAG (cauldron, FLAG_CURSED);
638 else 616 else
639 cauldron->magic--; 617 cauldron->magic--;
618
640 cauldron->magic -= random_roll (0, 4, op, PREFER_LOW); 619 cauldron->magic -= random_roll (0, 4, op, PREFER_LOW);
620
641 if (rndm (0, 1)) 621 if (rndm (0, 1))
642 { 622 {
643 remove_contents (cauldron->inv, NULL); 623 remove_contents (cauldron->inv, NULL);
644 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s turns darker then makes a gulping sound!", &cauldron->name); 624 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s turns darker then makes a gulping sound!", &cauldron->name);
645 } 625 }
646 else 626 else
647 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s becomes darker.", &cauldron->name); 627 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s becomes darker.", &cauldron->name);
648 return;
649
650 } 628 }
651 else if (level < 110) 629 else if (level < 110)
652 { /* SUMMON EVIL MONSTERS */ 630 { /* SUMMON EVIL MONSTERS */
653 object *tmp = get_random_mon (level / 5); 631 object *tmp = get_random_mon (level / 5);
654 632
655 remove_contents (cauldron->inv, NULL); 633 remove_contents (cauldron->inv, NULL);
634
656 if (!tmp) 635 if (!tmp)
657 alchemy_failure_effect (op, cauldron, rp, level); 636 alchemy_failure_effect (op, cauldron, rp, level);
658 else if (summon_hostile_monsters (cauldron, random_roll (1, 10, op, PREFER_LOW), tmp->arch->name)) 637 else if (summon_hostile_monsters (cauldron, random_roll (1, 10, op, PREFER_LOW), tmp->arch->archname))
659 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s and then pours forth monsters!", &cauldron->name, cauldron_sound ()); 638 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s and then pours forth monsters!", &cauldron->name, cauldron_sound ());
660 return;
661
662 } 639 }
663 else if (level < 150) 640 else if (level < 150)
664 { /* COMBO EFFECT */ 641 { /* COMBO EFFECT */
665 int roll = rndm (1, 3); 642 int roll = rndm (1, 3);
666 643
667 while (roll) 644 while (roll)
668 { 645 {
669 alchemy_failure_effect (op, cauldron, rp, level - 39); 646 alchemy_failure_effect (op, cauldron, rp, level - 39);
670 roll--; 647 roll--;
671 } 648 }
672 return;
673 } 649 }
674 else if (level == 151) 650 else if (level == 151)
675 { /* CREATE RANDOM ARTIFACT */ 651 { /* CREATE RANDOM ARTIFACT */
676 object *tmp; 652 object *tmp;
677 653
679 * in this one, we allow *any* valid alchemy artifact 655 * in this one, we allow *any* valid alchemy artifact
680 * to be made (rather than only those on the given 656 * to be made (rather than only those on the given
681 * formulalist) */ 657 * formulalist) */
682 if (!rp) 658 if (!rp)
683 rp = get_random_recipe ((recipelist *) NULL); 659 rp = get_random_recipe ((recipelist *) NULL);
660
684 if (rp && (tmp = get_archetype (rp->arch_name[RANDOM () % rp->arch_names]))) 661 if (rp && (tmp = get_archetype (rp->arch_name [rndm (rp->arch_names)])))
685 { 662 {
686 generate_artifact (tmp, random_roll (1, op->level / 2 + 1, op, PREFER_HIGH) + 1); 663 generate_artifact (tmp, random_roll (1, op->level / 2 + 1, op, PREFER_HIGH) + 1);
687 if ((tmp = insert_ob_in_ob (tmp, cauldron))) 664 if ((tmp = insert_ob_in_ob (tmp, cauldron)))
688 { 665 {
689 remove_contents (cauldron->inv, tmp); 666 remove_contents (cauldron->inv, tmp);
690 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); 667 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ());
691 } 668 }
692 } 669 }
693 return;
694 } 670 }
695 else 671 else
696 { /* MANA STORM - watch out!! */ 672 { /* MANA STORM - watch out!! */
697 object *tmp = get_archetype (LOOSE_MANA); 673 object *tmp = get_archetype (LOOSE_MANA);
698 674
699 new_draw_info (NDI_UNIQUE, 0, op, "You unwisely release potent forces!"); 675 new_draw_info (NDI_UNIQUE, 0, op, "You unwisely release potent forces!");
700 remove_contents (cauldron->inv, NULL); 676 remove_contents (cauldron->inv, NULL);
701 cast_magic_storm (op, tmp, level); 677 cast_magic_storm (op, tmp, level);
702 return;
703 } 678 }
704} 679}
705
706 680
707/* 681/*
708 * All but object "save_item" are elimentated from 682 * All but object "save_item" are elimentated from
709 * the container list. Note we have to becareful to remove the inventories 683 * the container list. Note we have to becareful to remove the inventories
710 * of objects in the cauldron inventory (ex icecube has stuff in it). 684 * of objects in the cauldron inventory (ex icecube has stuff in it).
711 */ 685 */
712
713void 686void
714remove_contents (object *first_ob, object *save_item) 687remove_contents (object *first_ob, object *save_item)
715{ 688{
689 // this cries for a cleaner rewrite, removing save_item first possibly
716 object *next, *tmp = first_ob; 690 object *next, *tmp = first_ob;
717 691
718 while (tmp) 692 while (tmp)
719 { 693 {
720 next = tmp->below; 694 next = tmp->below;
733 tmp->destroy (); 707 tmp->destroy ();
734 tmp = next; 708 tmp = next;
735 } 709 }
736} 710}
737 711
738/** 712/**
739 *"Danger" level, will determine how bad the backfire 713 *"Danger" level, will determine how bad the backfire
740 * could be if the user fails to concoct a recipe properly. Factors include 714 * could be if the user fails to concoct a recipe properly. Factors include
741 * the number of ingredients, the length of the name of each ingredient, 715 * the number of ingredients, the length of the name of each ingredient,
742 * the user's effective level, the user's Int and the enchantment on the 716 * the user's effective level, the user's Int and the enchantment on the
743 * mixing device (aka "cauldron"). Higher values of 'danger' indicate more 717 * mixing device (aka "cauldron"). Higher values of 'danger' indicate more
744 * danger. Note that we assume that we have had the caster ready the alchemy 718 * danger. Note that we assume that we have had the caster ready the alchemy
745 * skill *before* this routine is called. (no longer auto-readies that skill) 719 * skill *before* this routine is called. (no longer auto-readies that skill)
746 * -b.t. 720 * -b.t.
747 */ 721 */
748
749int 722int
750calc_alch_danger (object *caster, object *cauldron, recipe *rp) 723calc_alch_danger (object *caster, object *cauldron, recipe *rp)
751{ 724{
752 object *item; 725 object *item;
753 char name[MAX_BUF]; 726 char name[MAX_BUF];
754 int danger = 0, nrofi = 0; 727 int danger = 0, nrofi = 0;
755 728
756 /* Knowing alchemy skill reduces yer risk */ 729 /* Knowing alchemy skill reduces yer risk */
757 danger -= caster->chosen_skill ? caster->chosen_skill->level : caster->level; 730 danger -= caster->chosen_skill ? caster->chosen_skill->level : caster->level;
731
732 if (!caster->chosen_skill)
733 LOG (llevError | logBacktrace, "calc_alch_danger called without a chosen skill, caster %s, cauldron %s\n",
734 caster->debug_desc (), cauldron->debug_desc ());
758 735
759 /* better cauldrons reduce risk */ 736 /* better cauldrons reduce risk */
760 danger -= cauldron->magic; 737 danger -= cauldron->magic;
761 738
762 /* Higher Int, lower the risk */ 739 /* Higher Int, lower the risk */
766 * Thus the backfire is worse. Also, more ingredients 743 * Thus the backfire is worse. Also, more ingredients
767 * means we are attempting a more powerfull potion, 744 * means we are attempting a more powerfull potion,
768 * and thus the backfire will be worse. */ 745 * and thus the backfire will be worse. */
769 for (item = cauldron->inv; item; item = item->below) 746 for (item = cauldron->inv; item; item = item->below)
770 { 747 {
771 strcpy (name, item->name); 748 assign (name, item->name);
772 if (item->title) 749 if (item->title)
773 sprintf (name, "%s %s", &item->name, &item->title); 750 sprintf (name, "%s %s", &item->name, &item->title);
774 danger += (strtoint (name) / 1000) + 3; 751 danger += (strtoint (name) / 1000) + 3;
775 nrofi++; 752 nrofi++;
776 } 753 }
754
777 if (rp == NULL) 755 if (rp == NULL)
778 danger += 110; 756 danger += 110;
779 else 757 else
780 danger += rp->diff * 3; 758 danger += rp->diff * 3;
781 759
790#endif 768#endif
791 769
792 return danger; 770 return danger;
793} 771}
794 772
795/** 773/**
796 * Determines if ingredients in a container match the 774 * Determines if ingredients in a container match the
797 * proper ingredients for a recipe. 775 * proper ingredients for a recipe.
798 * 776 *
799 * rp is the recipe to check 777 * rp is the recipe to check
800 * cauldron is the container that holds the ingredients 778 * cauldron is the container that holds the ingredients
849 for (ob = cauldron->inv; ob != NULL; ob = ob->below) 827 for (ob = cauldron->inv; ob != NULL; ob = ob->below)
850 { 828 {
851 char name_ob[MAX_BUF]; 829 char name_ob[MAX_BUF];
852 const char *name2; 830 const char *name2;
853 831
854 if (ob->title == NULL) 832 if (!ob->title)
855 name2 = ob->name; 833 name2 = ob->name;
856 else 834 else
857 { 835 {
858 snprintf (name_ob, sizeof (name_ob), "%s %s", &ob->name, &ob->title); 836 snprintf (name_ob, sizeof (name_ob), "%s %s", &ob->name, &ob->title);
859 name2 = name_ob; 837 name2 = name_ob;
904 LOG (llevDebug, "looking for formula %d:\n", formula); 882 LOG (llevDebug, "looking for formula %d:\n", formula);
905#endif 883#endif
906 result = NULL; 884 result = NULL;
907 recipes_matching = 0; 885 recipes_matching = 0;
908 transmute_found = 0; 886 transmute_found = 0;
887
909 for (rp = fl->items; rp != NULL; rp = rp->next) 888 for (rp = fl->items; rp; rp = rp->next)
910 { 889 {
911 /* check if recipe matches at all */ 890 /* check if recipe matches at all */
912 if (formula % rp->index != 0) 891 if (formula % rp->index != 0)
913 { 892 {
914#ifdef EXTREME_ALCHEMY_DEBUG 893#ifdef EXTREME_ALCHEMY_DEBUG
915 LOG (llevDebug, " formula %s of %s (%d) does not match\n", rp->arch_name[0], rp->title, rp->index); 894 LOG (llevDebug, " formula %s of %s (%d) does not match\n", rp->arch_name[0], &rp->title, rp->index);
916#endif 895#endif
917 continue; 896 continue;
918 } 897 }
919 898
920 if (rp->transmute && find_transmution_ob (ingredients, rp, &rp_arch_index, 0) != NULL) 899 if (rp->transmute && find_transmution_ob (ingredients, rp, &rp_arch_index, 0) != NULL)
921 { 900 {
922#ifdef EXTREME_ALCHEMY_DEBUG 901#ifdef EXTREME_ALCHEMY_DEBUG
923 LOG (llevDebug, " formula %s of %s (%d) is a matching transmuting formula\n", rp->arch_name[rp_arch_index], rp->title, rp->index); 902 LOG (llevDebug, " formula %s of %s (%d) is a matching transmuting formula\n", rp->arch_name[rp_arch_index], &rp->title, rp->index);
924#endif 903#endif
925 /* transmution recipe with matching base ingredient */ 904 /* transmution recipe with matching base ingredient */
926 if (!transmute_found) 905 if (!transmute_found)
927 { 906 {
928 transmute_found = 1; 907 transmute_found = 1;
930 } 909 }
931 } 910 }
932 else if (transmute_found) 911 else if (transmute_found)
933 { 912 {
934#ifdef EXTREME_ALCHEMY_DEBUG 913#ifdef EXTREME_ALCHEMY_DEBUG
935 LOG (llevDebug, " formula %s of %s (%d) matches but is not a matching transmuting formula\n", rp->arch_name[0], rp->title, 914 LOG (llevDebug, " formula %s of %s (%d) matches but is not a matching transmuting formula\n", rp->arch_name[0], &rp->title,
936 rp->index); 915 rp->index);
937#endif 916#endif
938 /* "normal" recipe found after previous transmution recipe => ignore this recipe */ 917 /* "normal" recipe found after previous transmution recipe => ignore this recipe */
939 continue; 918 continue;
940 } 919 }
941#ifdef EXTREME_ALCHEMY_DEBUG 920#ifdef EXTREME_ALCHEMY_DEBUG
942 else 921 else
943 { 922 {
944 LOG (llevDebug, " formula %s of %s (%d) matches\n", rp->arch_name[0], rp->title, rp->index); 923 LOG (llevDebug, " formula %s of %s (%d) matches\n", rp->arch_name[0], &rp->title, rp->index);
945 } 924 }
946#endif 925#endif
947 926
948 if (rndm (0, recipes_matching) == 0) 927 if (rndm (0, recipes_matching) == 0)
949 result = rp; 928 result = rp;
959 return NULL; 938 return NULL;
960 } 939 }
961 940
962#ifdef ALCHEMY_DEBUG 941#ifdef ALCHEMY_DEBUG
963 if (strcmp (result->title, "NONE") != 0) 942 if (strcmp (result->title, "NONE") != 0)
964 LOG (llevDebug, "got formula: %s of %s (nbatches:%d)\n", result->arch_name[0], result->title, formula / result->index); 943 LOG (llevDebug, "got formula: %s of %s (nbatches:%d)\n", result->arch_name[0], &result->title, formula / result->index);
965 else 944 else
966 LOG (llevDebug, "got formula: %s (nbatches:%d)\n", result->arch_name[0], formula / result->index); 945 LOG (llevDebug, "got formula: %s (nbatches:%d)\n", result->arch_name[0], formula / result->index);
967#endif 946#endif
968 return result; 947 return result;
969} 948}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines