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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines