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.41 by root, Thu Oct 15 23:02:28 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>
56 "rattles", 56 "rattles",
57 "makes chugging sounds", 57 "makes chugging sounds",
58 "smokes heavily for a while" 58 "smokes heavily for a while"
59}; 59};
60 60
61
62static int is_defined_recipe (const recipe *rp, const object *cauldron, object *caster); 61static int is_defined_recipe (const recipe *rp, const object *cauldron, object *caster);
63static recipe *find_recipe (recipelist * fl, int formula, object *ingredients); 62static recipe *find_recipe (recipelist * fl, int formula, object *ingredients);
64
65 63
66/** Returns a random selection from cauldron_effect[] */ 64/** Returns a random selection from cauldron_effect[] */
67static const char * 65static const char *
68cauldron_sound (void) 66cauldron_sound (void)
69{ 67{
70 int size = sizeof (cauldron_effect) / sizeof (char *); 68 int size = sizeof (cauldron_effect) / sizeof (char *);
71 69
72 return cauldron_effect[rndm (0, size - 1)]; 70 return cauldron_effect[rndm (0, size - 1)];
73} 71}
74 72
75/** 73/**
76 * Main part of the ALCHEMY code. From this we call fctns 74 * Main part of the ALCHEMY code. From this we call fctns
77 * that take a look at the contents of the 'cauldron' and, using these ingredients, 75 * that take a look at the contents of the 'cauldron' and, using these ingredients,
78 * we construct an integer formula value which is referenced (randomly) against a 76 * we construct an integer formula value which is referenced (randomly) against a
79 * formula list (the formula list chosen is based on the # contents of the cauldron). 77 * formula list (the formula list chosen is based on the # contents of the cauldron).
80 * 78 *
95 * around. :) 93 * around. :)
96 * -b.t. 94 * -b.t.
97 */ 95 */
98 96
99void 97void
100attempt_do_alchemy (object *caster, object *cauldron) 98attempt_do_alchemy (object *caster, object *cauldron, object *skill)
101{ 99{
102 recipelist *fl; 100 recipelist *fl;
103 recipe *rp = NULL; 101 recipe *rp = NULL;
104 float success_chance; 102 float success_chance;
105 int numb, ability = 1; 103 int numb, ability = 1;
128 rp = find_recipe (fl, formula, cauldron->inv); 126 rp = find_recipe (fl, formula, cauldron->inv);
129 if (rp != NULL) 127 if (rp != NULL)
130 { 128 {
131#ifdef ALCHEMY_DEBUG 129#ifdef ALCHEMY_DEBUG
132 if (strcmp (rp->title, "NONE")) 130 if (strcmp (rp->title, "NONE"))
133 LOG (llevDebug, "WIZ got formula: %s of %s\n", rp->arch_name[0], rp->title); 131 LOG (llevDebug, "WIZ got formula: %s of %s\n", rp->arch_name[0], &rp->title);
134 else 132 else
135 LOG (llevDebug, "WIZ got formula: %s (nbatches:%d)\n", rp->arch_name[0], formula / rp->index); 133 LOG (llevDebug, "WIZ got formula: %s (nbatches:%d)\n", rp->arch_name[0], formula / rp->index);
136#endif 134#endif
137 attempt_recipe (caster, cauldron, ability, rp, formula / rp->index); 135 attempt_recipe (caster, cauldron, ability, rp, formula / rp->index);
138 } 136 }
141 return; 139 return;
142 } /* End of WIZ alchemy */ 140 } /* End of WIZ alchemy */
143 141
144 /* find the recipe */ 142 /* find the recipe */
145 rp = find_recipe (fl, formula, cauldron->inv); 143 rp = find_recipe (fl, formula, cauldron->inv);
146 if (rp) 144 if (rp
145 && rp->skill == skill->skill
146 && (!rp->cauldron
147 || rp->cauldron == cauldron->arch->archname))
147 { 148 {
148 uint64 value_ingredients; 149 uint64 value_ingredients;
149 uint64 value_item; 150 uint64 value_item;
150 object *tmp; 151 object *tmp;
151 int attempt_shadow_alchemy; 152 int attempt_shadow_alchemy;
152 153
153 ave_chance = fl->total_chance / (float) fl->number; 154 ave_chance = fl->total_chance / (float) fl->number;
154 /* the caster gets an increase in ability based on thier skill lvl */ 155
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)); 156 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 157
175 /* determine value of ingredients */ 158 /* determine value of ingredients */
176 value_ingredients = 0; 159 value_ingredients = 0;
177 for (tmp = cauldron->inv; tmp != NULL; tmp = tmp->below) 160 for (tmp = cauldron->inv; tmp != NULL; tmp = tmp->below)
178 value_ingredients += query_cost (tmp, NULL, F_TRUE); 161 value_ingredients += query_cost (tmp, NULL, F_TRUE);
216 199
217 /* if we get here, we failed!! */ 200 /* if we get here, we failed!! */
218 alchemy_failure_effect (caster, cauldron, rp, calc_alch_danger (caster, cauldron, rp)); 201 alchemy_failure_effect (caster, cauldron, rp, calc_alch_danger (caster, cauldron, rp));
219} 202}
220 203
221/** 204/**
222 * Recipe value of the entire contents of a container. 205 * Recipe value of the entire contents of a container.
223 * This appears to just generate a hash value, which I guess for now works 206 * This appears to just generate a hash value, which I guess for now works
224 * ok, but the possibility of duplicate hashes is certainly possible - msw 207 * ok, but the possibility of duplicate hashes is certainly possible - msw
225 */ 208 */
226
227int 209int
228content_recipe_value (object *op) 210content_recipe_value (object *op)
229{ 211{
230 char name[MAX_BUF]; 212 char name[MAX_BUF];
231 object *tmp = op->inv; 213 object *tmp = op->inv;
232 int tval = 0, formula = 0; 214 int tval = 0, formula = 0;
233 215
234 while (tmp) 216 while (tmp)
235 { 217 {
236 tval = 0; 218 tval = 0;
237 strcpy (name, tmp->name); 219 assign (name, tmp->name);
238 if (tmp->title) 220 if (tmp->title)
239 sprintf (name, "%s %s", &tmp->name, &tmp->title); 221 sprintf (name, "%s %s", &tmp->name, &tmp->title);
240 tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1)); 222 tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1));
241#ifdef ALCHEMY_DEBUG 223#ifdef ALCHEMY_DEBUG
242 LOG (llevDebug, "Got ingredient %d %s(%d)\n", tmp->nrof ? tmp->nrof : 1, name, tval); 224 LOG (llevDebug, "Got ingredient %d %s(%d)\n", tmp->nrof ? tmp->nrof : 1, name, tval);
248 LOG (llevDebug, " Formula value=%d\n", formula); 230 LOG (llevDebug, " Formula value=%d\n", formula);
249#endif 231#endif
250 return formula; 232 return formula;
251} 233}
252 234
253/** 235/**
254 * Returns total number of items in op 236 * Returns total number of items in op
255 */ 237 */
256 238
257int 239int
258numb_ob_inside (object *op) 240numb_ob_inside (object *op)
259{ 241{
268 number++; 250 number++;
269 o_number++; 251 o_number++;
270 tmp = tmp->below; 252 tmp = tmp->below;
271 } 253 }
272#ifdef ALCHEMY_DEBUG 254#ifdef ALCHEMY_DEBUG
273 LOG (llevDebug, "numb_ob_inside(%s): found %d ingredients\n", op->name, o_number); 255 LOG (llevDebug, "numb_ob_inside(%s): found %d ingredients\n", &op->name, o_number);
274#endif 256#endif
275 return o_number; 257 return o_number;
276} 258}
277 259
278/** 260/**
280 * insert_ob_in_ob. If the caster has some alchemy skill, then they might 262 * insert_ob_in_ob. If the caster has some alchemy skill, then they might
281 * gain some exp from (successfull) fabrication of the product. 263 * gain some exp from (successfull) fabrication of the product.
282 * If nbatches==-1, don't give exp for this creation (random generation/ 264 * If nbatches==-1, don't give exp for this creation (random generation/
283 * failed recipe) 265 * failed recipe)
284 */ 266 */
285
286object * 267object *
287attempt_recipe (object *caster, object *cauldron, int ability, recipe *rp, int nbatches) 268attempt_recipe (object *caster, object *cauldron, int ability, recipe *rp, int nbatches)
288{ 269{
289 270
290 object *item = NULL, *skop; 271 object *item = NULL, *skop;
291 272
292 /* this should be passed to this fctn, not effiecent cpu use this way */ 273 /* this should be passed to this fctn, not effiecent cpu use this way */
293 int batches = abs (nbatches); 274 int batches = abs (nbatches);
294 275
295
296 /* is the cauldron the right type? */ 276 /* is the cauldron the right type? */
297 if (strcmp (rp->cauldron, cauldron->arch->name) != 0) 277 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; 278 return 0;
301 }
302 279
303 skop = find_skill_by_name (caster, rp->skill); 280 skop = find_skill_by_name (caster, rp->skill);
304 /* does the caster have the skill? */ 281 /* does the caster have the skill? */
305 if (!skop) 282 if (!skop)
306 return 0; 283 return 0;
310 { 287 {
311 object *tmp; 288 object *tmp;
312 289
313 for (tmp = caster->inv; tmp; tmp = tmp->below) 290 for (tmp = caster->inv; tmp; tmp = tmp->below)
314 { 291 {
315 if (tmp->type == FORCE && tmp->slaying && !strcmp (rp->keycode, tmp->slaying)) 292 if (tmp->type == FORCE && tmp->slaying && rp->keycode == tmp->slaying)
316 break; 293 break;
317 } 294 }
318 295
319 if (!tmp) 296 if (!tmp)
320 { /* failure--no code found */ 297 { /* 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."); 298 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; 299 return 0;
323 } 300 }
324 } 301 }
325 302
326#ifdef EXTREME_ALCHEMY_DEBUG 303#ifdef EXTREME_ALCHEMY_DEBUG
327 LOG (llevDebug, "attempt_recipe(): got %d nbatches\n", nbatches); 304 LOG (llevDebug, "attempt_recipe(): got %d nbatches\n", nbatches);
328 LOG (llevDebug, "attempt_recipe(): using recipe %s\n", rp->title ? rp->title : "unknown"); 305 LOG (llevDebug, "attempt_recipe(): using recipe %s\n", *rp->title ? &rp->title : "unknown");
329#endif 306#endif
330 307
331 if ((item = make_item_from_recipe (cauldron, rp)) != NULL) 308 if ((item = make_item_from_recipe (cauldron, rp)) != NULL)
332 { 309 {
333 remove_contents (cauldron->inv, item); 310 remove_contents (cauldron->inv, item);
334 /* Recalc carrying of the cauldron, in case recipe did not conserve mass */ 311 /* Recalc carrying of the cauldron, in case recipe did not conserve mass */
335 sum_weight (cauldron); 312 cauldron->update_weight ();
336 /* adj lvl, nrof on caster level */ 313 /* adj lvl, nrof on caster level */
337 adjust_product (item, ability, rp->yield ? (rp->yield * batches) : batches); 314 adjust_product (item, ability, rp->yield ? (rp->yield * batches) : batches);
338 if (!item->env && (item = insert_ob_in_ob (item, cauldron)) == NULL) 315 if (!item->env && (item = insert_ob_in_ob (item, cauldron)) == NULL)
339 { 316 {
340 new_draw_info (NDI_UNIQUE, 0, caster, "Nothing happened."); 317 new_draw_info (NDI_UNIQUE, 0, caster, "Nothing happened.");
347 } 324 }
348 325
349 return item; 326 return item;
350} 327}
351 328
352
353
354/** 329/**
355 * We adjust the nrof, exp and level of the final product, based 330 * 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. 331 * on the item's default parameters, and the relevant caster skill level.
357 */ 332 */
358void 333void
359adjust_product (object *item, int lvl, int yield) 334adjust_product (object *item, int lvl, int yield)
360{ 335{
361 int nrof = 1; 336 int nrof = 1;
374 nrof = yield; 349 nrof = yield;
375 350
376 item->nrof = nrof; 351 item->nrof = nrof;
377 } 352 }
378} 353}
379
380 354
381/** 355/**
382 * Using a list of items and a recipe to make an artifact. 356 * Using a list of items and a recipe to make an artifact.
383 * 357 *
384 * @param cauldron the cauldron (including the ingredients) used to make the item 358 * @param cauldron the cauldron (including the ingredients) used to make the item
385 * 359 *
386 * @param rp the recipe to make the artifact from 360 * @param rp the recipe to make the artifact from
387 * 361 *
388 * @return the newly created object, NULL if something failed 362 * @return the newly created object, NULL if something failed
389 */ 363 */
390
391object * 364object *
392make_item_from_recipe (object *cauldron, recipe *rp) 365make_item_from_recipe (object *cauldron, recipe *rp)
393{ 366{
394 artifact *art = NULL; 367 artifact *art = NULL;
395 object *item = NULL; 368 object *item = NULL;
404 LOG (llevDebug, "make_alchemy_item(): failed to create alchemical object.\n"); 377 LOG (llevDebug, "make_alchemy_item(): failed to create alchemical object.\n");
405 return (object *) NULL; 378 return (object *) NULL;
406 } 379 }
407 380
408 /* Find the appropriate artifact template... */ 381 /* Find the appropriate artifact template... */
409 if (strcmp (rp->title, "NONE")) 382 if (rp->title != shstr_NONE)
410 { 383 {
411 if ((art = locate_recipe_artifact (rp, rp_arch_index)) == NULL) 384 if ((art = locate_recipe_artifact (rp, rp_arch_index)) == NULL)
412 { 385 {
413 LOG (llevError, "make_alchemy_item(): failed to locate recipe artifact.\n"); 386 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); 387 LOG (llevDebug, " --requested recipe: %s of %s.\n", rp->arch_name[0], &rp->title);
415 return (object *) NULL; 388 return (object *) NULL;
416 } 389 }
390
417 transmute_materialname (item, art->item); 391 transmute_materialname (item, art->item);
418 give_artifact_abilities (item, art->item); 392 give_artifact_abilities (item, art->item);
419 } 393 }
420 394
421 if (QUERY_FLAG (cauldron, FLAG_CURSED)) 395 if (QUERY_FLAG (cauldron, FLAG_CURSED))
424 SET_FLAG (item, FLAG_DAMNED); 398 SET_FLAG (item, FLAG_DAMNED);
425 399
426 return item; 400 return item;
427} 401}
428 402
429
430/** 403/**
431 * Looks through the ingredient list. If we find a 404 * Looks through the ingredient list. If we find a
432 * suitable object in it - we will use that to make the requested artifact. 405 * suitable object in it - we will use that to make the requested artifact.
433 * Otherwise the code returns a 'generic' item if create_item is set. -b.t. 406 * Otherwise the code returns a 'generic' item if create_item is set. -b.t.
434 * 407 *
435 * @param rp_arch_index pointer to return value; set to arch index for recipe; 408 * @param rp_arch_index pointer to return value; set to arch index for recipe;
436 * set to zero if not using a transmution formula 409 * set to zero if not using a transmution formula
437 */ 410 */
438
439object * 411object *
440find_transmution_ob (object *first_ingred, recipe *rp, size_t * rp_arch_index, int create_item) 412find_transmution_ob (object *first_ingred, recipe *rp, size_t *rp_arch_index, int create_item)
441{ 413{
442 object *item = NULL; 414 object *prod_item = 0;
443 415 bool found = false;
444 *rp_arch_index = 0; 416 *rp_arch_index = 0;
445 417
446 if (rp->transmute) /* look for matching ingredient/prod archs */ 418 if (rp->transmute) /* look for matching ingredient/prod archs */
447 for (item = first_ingred; item; item = item->below) 419 for (object *item = first_ingred; item; item = item->below)
448 { 420 {
449 size_t i;
450
451 for (i = 0; i < rp->arch_names; i++) 421 for (int i = 0; i < rp->arch_names; i++)
452 { 422 //TODO: should be a shstr comparison
453 if (strcmp (item->arch->name, rp->arch_name[i]) == 0) 423 if (!strcmp(&item->arch->archname,rp->arch_name[i]))
454 { 424 {
455 *rp_arch_index = i; 425 *rp_arch_index = i;
426 prod_item = item;
456 break; 427 break;
457 } 428 }
458 } 429
459 if (i < rp->arch_names) 430 if (prod_item)
460 break; 431 break;
461 } 432 }
462 433
463 /* failed, create a fresh object. Note no nrof>1 because that would 434 /* failed, create a fresh object. Note no nrof>1 because that would
464 * allow players to create massive amounts of artifacts easily */ 435 * allow players to create massive amounts of artifacts easily */
465 if (create_item && (!item || item->nrof > 1)) 436 if (create_item && (!prod_item || prod_item->nrof > 1))
437 {
438#ifdef ALCHEMY_DEBUG
439 LOG (llevDebug, "creating a new item.\n");
440 if (prod_item != NULL)
466 { 441 {
442 LOG (llevDebug, " had item: arch %s(nrof:%d)\n",
443 &prod_item->arch->archname, prod_item->nrof);
444 }
445#endif
446 if (!prod_item)
467 *rp_arch_index = RANDOM () % rp->arch_names; 447 *rp_arch_index = rndm (rp->arch_names);
468 item = get_archetype (rp->arch_name[*rp_arch_index]); 448 prod_item = get_archetype (rp->arch_name[*rp_arch_index]);
469 } 449 }
470 450
471#ifdef ALCHEMY_DEBUG 451#ifdef ALCHEMY_DEBUG
472 LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no "); 452 LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no ");
473 if (item != NULL) 453 if (prod_item != NULL)
474 { 454 {
475 LOG (llevDebug, " find_transmutable_ob(): returns arch %s(sp:%d)\n", item->arch->name, item->stats.sp); 455 LOG (llevDebug, " find_transmutable_ob(): returns arch %s(sp:%d)\n",
456 &prod_item->arch->archname, prod_item->stats.sp);
476 } 457 }
477#endif 458#endif
478 459
479 return item; 460 return prod_item;
480} 461}
481 462
482
483/** 463/**
484 * Ouch. We didnt get the formula we wanted. 464 * Ouch. We didnt get the formula we wanted.
485 * This fctn simulates the backfire effects--worse effects as the level 465 * This fctn simulates the backfire effects--worse effects as the level
486 * increases. If SPELL_FAILURE_EFFECTS is defined some really evil things 466 * increases. If SPELL_FAILURE_EFFECTS is defined some really evil things
487 * can happen to the would be alchemist. This table probably needs some 467 * can happen to the would be alchemist. This table probably needs some
488 * adjustment for playbalance. -b.t. 468 * adjustment for playbalance. -b.t.
489 */ 469 */
490
491void 470void
492alchemy_failure_effect (object *op, object *cauldron, recipe *rp, int danger) 471alchemy_failure_effect (object *op, object *cauldron, recipe *rp, int danger)
493{ 472{
494 int level = 0; 473 int level = 0;
495 474
510 489
511 if (rndm (0, 2)) 490 if (rndm (0, 2))
512 { /* slag created */ 491 { /* slag created */
513 object *tmp = cauldron->inv; 492 object *tmp = cauldron->inv;
514 int weight = 0; 493 int weight = 0;
515 uint16 material = M_STONE;
516 494
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"); 495 tmp = get_archetype ("rock");
525 tmp->weight = weight; 496 tmp->weight = weight;
526 tmp->value = 0; 497 tmp->value = 0;
527 tmp->material = material;
528 tmp->materialname = "stone"; 498 tmp->materialname = "stone";
529 tmp->name = "slag"; 499 tmp->name = "slag";
530 tmp->name_pl = "slags"; 500 tmp->name_pl = "slags";
531 item = insert_ob_in_ob (tmp, cauldron); 501 item = insert_ob_in_ob (tmp, cauldron);
532 CLEAR_FLAG (tmp, FLAG_CAN_ROLL); 502 CLEAR_FLAG (tmp, FLAG_CAN_ROLL);
533 CLEAR_FLAG (tmp, FLAG_NO_PICK); 503 CLEAR_FLAG (tmp, FLAG_NO_PICK);
534 tmp->move_block = 0; 504 tmp->move_block = 0;
535 } 505 }
506
536 remove_contents (cauldron->inv, item); 507 remove_contents (cauldron->inv, item);
537 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); 508 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ());
538 return; 509 return;
539 } 510 }
540 else if (level < 40) 511 else if (level < 40)
566 } 537 }
567 while (rndm (0, 2)); 538 while (rndm (0, 2));
568 } 539 }
569 return; 540 return;
570 } 541 }
542
571 if (level == 40) 543 if (level == 40)
572 { /* MAKE RANDOM RECIPE */ 544 { /* MAKE RANDOM RECIPE */
573 recipelist *fl; 545 recipelist *fl;
574 int numb = numb_ob_inside (cauldron); 546 int numb = numb_ob_inside (cauldron);
575 547
577 if (fl && (rp = get_random_recipe (fl))) 549 if (fl && (rp = get_random_recipe (fl)))
578 /* even though random, don't grant user any EXP for it */ 550 /* even though random, don't grant user any EXP for it */
579 (void) attempt_recipe (op, cauldron, 1, rp, -1); 551 (void) attempt_recipe (op, cauldron, 1, rp, -1);
580 else 552 else
581 alchemy_failure_effect (op, cauldron, rp, level - 1); 553 alchemy_failure_effect (op, cauldron, rp, level - 1);
582 return;
583
584 } 554 }
585 else if (level < 45) 555 else if (level < 45)
586 { /* INFURIATE NPC's */ 556 { /* INFURIATE NPC's */
587 /* this is kind of kludgy I know... */ 557 /* this is kind of kludgy I know... */
588 cauldron->enemy = op; 558 cauldron->enemy = op;
589 npc_call_help (cauldron); 559 npc_call_help (cauldron);
590 cauldron->enemy = NULL; 560 cauldron->enemy = NULL;
591 561
592 alchemy_failure_effect (op, cauldron, rp, level - 5); 562 alchemy_failure_effect (op, cauldron, rp, level - 5);
593 return;
594 } 563 }
595 else if (level < 50) 564 else if (level < 50)
596 { /* MINOR EXPLOSION/FIREBALL */ 565 { /* MINOR EXPLOSION/FIREBALL */
597 object *tmp; 566 object *tmp;
598 567
612 tmp->stats.hp = random_roll (1, level, op, PREFER_LOW) / 10 + 2; 581 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); 582 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name);
614 break; 583 break;
615 } 584 }
616 585
617 op->insert_at (cauldron); 586 tmp->insert_at (cauldron);
618 return;
619
620 } 587 }
621 else if (level < 60) 588 else if (level < 60)
622 { /* CREATE MONSTER */ 589 { /* CREATE MONSTER */
623 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); 590 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ());
624 remove_contents (cauldron->inv, NULL); 591 remove_contents (cauldron->inv, NULL);
625 return;
626 } 592 }
627 else if (level < 80) 593 else if (level < 80)
628 { /* MAJOR FIRE */ 594 { /* MAJOR FIRE */
629 object *fb = get_archetype (SP_MED_FIREBALL); 595 object *fb = get_archetype (SP_MED_FIREBALL);
630 596
631 remove_contents (cauldron->inv, NULL); 597 remove_contents (cauldron->inv, NULL);
632 fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb); 598 fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb);
633 fb->destroy (); 599 fb->destroy ();
634 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); 600 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name);
635 return;
636
637 } 601 }
638 else if (level < 100) 602 else if (level < 100)
639 { /* WHAMMY the CAULDRON */ 603 { /* WHAMMY the CAULDRON */
640 if (!QUERY_FLAG (cauldron, FLAG_CURSED)) 604 if (!QUERY_FLAG (cauldron, FLAG_CURSED))
641 SET_FLAG (cauldron, FLAG_CURSED); 605 SET_FLAG (cauldron, FLAG_CURSED);
642 else 606 else
643 cauldron->magic--; 607 cauldron->magic--;
608
644 cauldron->magic -= random_roll (0, 4, op, PREFER_LOW); 609 cauldron->magic -= random_roll (0, 4, op, PREFER_LOW);
610
645 if (rndm (0, 1)) 611 if (rndm (0, 1))
646 { 612 {
647 remove_contents (cauldron->inv, NULL); 613 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); 614 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s turns darker then makes a gulping sound!", &cauldron->name);
649 } 615 }
650 else 616 else
651 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s becomes darker.", &cauldron->name); 617 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s becomes darker.", &cauldron->name);
652 return;
653
654 } 618 }
655 else if (level < 110) 619 else if (level < 110)
656 { /* SUMMON EVIL MONSTERS */ 620 { /* SUMMON EVIL MONSTERS */
657 object *tmp = get_random_mon (level / 5); 621 object *tmp = get_random_mon (level / 5);
658 622
659 remove_contents (cauldron->inv, NULL); 623 remove_contents (cauldron->inv, NULL);
624
660 if (!tmp) 625 if (!tmp)
661 alchemy_failure_effect (op, cauldron, rp, level); 626 alchemy_failure_effect (op, cauldron, rp, level);
662 else if (summon_hostile_monsters (cauldron, random_roll (1, 10, op, PREFER_LOW), tmp->arch->name)) 627 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 ()); 628 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s and then pours forth monsters!", &cauldron->name, cauldron_sound ());
664 return;
665
666 } 629 }
667 else if (level < 150) 630 else if (level < 150)
668 { /* COMBO EFFECT */ 631 { /* COMBO EFFECT */
669 int roll = rndm (1, 3); 632 int roll = rndm (1, 3);
670 633
671 while (roll) 634 while (roll)
672 { 635 {
673 alchemy_failure_effect (op, cauldron, rp, level - 39); 636 alchemy_failure_effect (op, cauldron, rp, level - 39);
674 roll--; 637 roll--;
675 } 638 }
676 return;
677 } 639 }
678 else if (level == 151) 640 else if (level == 151)
679 { /* CREATE RANDOM ARTIFACT */ 641 { /* CREATE RANDOM ARTIFACT */
680 object *tmp; 642 object *tmp;
681 643
683 * in this one, we allow *any* valid alchemy artifact 645 * in this one, we allow *any* valid alchemy artifact
684 * to be made (rather than only those on the given 646 * to be made (rather than only those on the given
685 * formulalist) */ 647 * formulalist) */
686 if (!rp) 648 if (!rp)
687 rp = get_random_recipe ((recipelist *) NULL); 649 rp = get_random_recipe ((recipelist *) NULL);
650
688 if (rp && (tmp = get_archetype (rp->arch_name[RANDOM () % rp->arch_names]))) 651 if (rp && (tmp = get_archetype (rp->arch_name [rndm (rp->arch_names)])))
689 { 652 {
690 generate_artifact (tmp, random_roll (1, op->level / 2 + 1, op, PREFER_HIGH) + 1); 653 generate_artifact (tmp, random_roll (1, op->level / 2 + 1, op, PREFER_HIGH) + 1);
691 if ((tmp = insert_ob_in_ob (tmp, cauldron))) 654 if ((tmp = insert_ob_in_ob (tmp, cauldron)))
692 { 655 {
693 remove_contents (cauldron->inv, tmp); 656 remove_contents (cauldron->inv, tmp);
694 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); 657 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ());
695 } 658 }
696 } 659 }
697 return;
698 } 660 }
699 else 661 else
700 { /* MANA STORM - watch out!! */ 662 { /* MANA STORM - watch out!! */
701 object *tmp = get_archetype (LOOSE_MANA); 663 object *tmp = get_archetype (LOOSE_MANA);
702 664
703 new_draw_info (NDI_UNIQUE, 0, op, "You unwisely release potent forces!"); 665 new_draw_info (NDI_UNIQUE, 0, op, "You unwisely release potent forces!");
704 remove_contents (cauldron->inv, NULL); 666 remove_contents (cauldron->inv, NULL);
705 cast_magic_storm (op, tmp, level); 667 cast_magic_storm (op, tmp, level);
706 return;
707 } 668 }
708} 669}
709
710 670
711/* 671/*
712 * All but object "save_item" are elimentated from 672 * All but object "save_item" are elimentated from
713 * the container list. Note we have to becareful to remove the inventories 673 * 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). 674 * of objects in the cauldron inventory (ex icecube has stuff in it).
715 */ 675 */
716
717void 676void
718remove_contents (object *first_ob, object *save_item) 677remove_contents (object *first_ob, object *save_item)
719{ 678{
679 // this cries for a cleaner rewrite, removing save_item first possibly
720 object *next, *tmp = first_ob; 680 object *next, *tmp = first_ob;
721 681
722 while (tmp) 682 while (tmp)
723 { 683 {
724 next = tmp->below; 684 next = tmp->below;
737 tmp->destroy (); 697 tmp->destroy ();
738 tmp = next; 698 tmp = next;
739 } 699 }
740} 700}
741 701
742/** 702/**
743 *"Danger" level, will determine how bad the backfire 703 *"Danger" level, will determine how bad the backfire
744 * could be if the user fails to concoct a recipe properly. Factors include 704 * 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, 705 * 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 706 * 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 707 * 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 708 * 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) 709 * skill *before* this routine is called. (no longer auto-readies that skill)
750 * -b.t. 710 * -b.t.
751 */ 711 */
752
753int 712int
754calc_alch_danger (object *caster, object *cauldron, recipe *rp) 713calc_alch_danger (object *caster, object *cauldron, recipe *rp)
755{ 714{
756 object *item; 715 object *item;
757 char name[MAX_BUF]; 716 char name[MAX_BUF];
758 int danger = 0, nrofi = 0; 717 int danger = 0, nrofi = 0;
759 718
760 /* Knowing alchemy skill reduces yer risk */ 719 /* Knowing alchemy skill reduces yer risk */
761 danger -= caster->chosen_skill ? caster->chosen_skill->level : caster->level; 720 danger -= caster->chosen_skill ? caster->chosen_skill->level : caster->level;
721
722 if (!caster->chosen_skill)
723 LOG (llevError | logBacktrace, "calc_alch_danger called without a chosen skill, caster %s, cauldron %s\n",
724 caster->debug_desc (), cauldron->debug_desc ());
762 725
763 /* better cauldrons reduce risk */ 726 /* better cauldrons reduce risk */
764 danger -= cauldron->magic; 727 danger -= cauldron->magic;
765 728
766 /* Higher Int, lower the risk */ 729 /* Higher Int, lower the risk */
770 * Thus the backfire is worse. Also, more ingredients 733 * Thus the backfire is worse. Also, more ingredients
771 * means we are attempting a more powerfull potion, 734 * means we are attempting a more powerfull potion,
772 * and thus the backfire will be worse. */ 735 * and thus the backfire will be worse. */
773 for (item = cauldron->inv; item; item = item->below) 736 for (item = cauldron->inv; item; item = item->below)
774 { 737 {
775 strcpy (name, item->name); 738 assign (name, item->name);
776 if (item->title) 739 if (item->title)
777 sprintf (name, "%s %s", &item->name, &item->title); 740 sprintf (name, "%s %s", &item->name, &item->title);
778 danger += (strtoint (name) / 1000) + 3; 741 danger += (strtoint (name) / 1000) + 3;
779 nrofi++; 742 nrofi++;
780 } 743 }
744
781 if (rp == NULL) 745 if (rp == NULL)
782 danger += 110; 746 danger += 110;
783 else 747 else
784 danger += rp->diff * 3; 748 danger += rp->diff * 3;
785 749
794#endif 758#endif
795 759
796 return danger; 760 return danger;
797} 761}
798 762
799/** 763/**
800 * Determines if ingredients in a container match the 764 * Determines if ingredients in a container match the
801 * proper ingredients for a recipe. 765 * proper ingredients for a recipe.
802 * 766 *
803 * rp is the recipe to check 767 * rp is the recipe to check
804 * cauldron is the container that holds the ingredients 768 * cauldron is the container that holds the ingredients
853 for (ob = cauldron->inv; ob != NULL; ob = ob->below) 817 for (ob = cauldron->inv; ob != NULL; ob = ob->below)
854 { 818 {
855 char name_ob[MAX_BUF]; 819 char name_ob[MAX_BUF];
856 const char *name2; 820 const char *name2;
857 821
858 if (ob->title == NULL) 822 if (!ob->title)
859 name2 = ob->name; 823 name2 = ob->name;
860 else 824 else
861 { 825 {
862 snprintf (name_ob, sizeof (name_ob), "%s %s", &ob->name, &ob->title); 826 snprintf (name_ob, sizeof (name_ob), "%s %s", &ob->name, &ob->title);
863 name2 = name_ob; 827 name2 = name_ob;
908 LOG (llevDebug, "looking for formula %d:\n", formula); 872 LOG (llevDebug, "looking for formula %d:\n", formula);
909#endif 873#endif
910 result = NULL; 874 result = NULL;
911 recipes_matching = 0; 875 recipes_matching = 0;
912 transmute_found = 0; 876 transmute_found = 0;
877
913 for (rp = fl->items; rp != NULL; rp = rp->next) 878 for (rp = fl->items; rp; rp = rp->next)
914 { 879 {
915 /* check if recipe matches at all */ 880 /* check if recipe matches at all */
916 if (formula % rp->index != 0) 881 if (formula % rp->index != 0)
917 { 882 {
918#ifdef EXTREME_ALCHEMY_DEBUG 883#ifdef EXTREME_ALCHEMY_DEBUG
919 LOG (llevDebug, " formula %s of %s (%d) does not match\n", rp->arch_name[0], rp->title, rp->index); 884 LOG (llevDebug, " formula %s of %s (%d) does not match\n", rp->arch_name[0], &rp->title, rp->index);
920#endif 885#endif
921 continue; 886 continue;
922 } 887 }
923 888
924 if (rp->transmute && find_transmution_ob (ingredients, rp, &rp_arch_index, 0) != NULL) 889 if (rp->transmute && find_transmution_ob (ingredients, rp, &rp_arch_index, 0) != NULL)
925 { 890 {
926#ifdef EXTREME_ALCHEMY_DEBUG 891#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); 892 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 893#endif
929 /* transmution recipe with matching base ingredient */ 894 /* transmution recipe with matching base ingredient */
930 if (!transmute_found) 895 if (!transmute_found)
931 { 896 {
932 transmute_found = 1; 897 transmute_found = 1;
934 } 899 }
935 } 900 }
936 else if (transmute_found) 901 else if (transmute_found)
937 { 902 {
938#ifdef EXTREME_ALCHEMY_DEBUG 903#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, 904 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); 905 rp->index);
941#endif 906#endif
942 /* "normal" recipe found after previous transmution recipe => ignore this recipe */ 907 /* "normal" recipe found after previous transmution recipe => ignore this recipe */
943 continue; 908 continue;
944 } 909 }
945#ifdef EXTREME_ALCHEMY_DEBUG 910#ifdef EXTREME_ALCHEMY_DEBUG
946 else 911 else
947 { 912 {
948 LOG (llevDebug, " formula %s of %s (%d) matches\n", rp->arch_name[0], rp->title, rp->index); 913 LOG (llevDebug, " formula %s of %s (%d) matches\n", rp->arch_name[0], &rp->title, rp->index);
949 } 914 }
950#endif 915#endif
951 916
952 if (rndm (0, recipes_matching) == 0) 917 if (rndm (0, recipes_matching) == 0)
953 result = rp; 918 result = rp;
963 return NULL; 928 return NULL;
964 } 929 }
965 930
966#ifdef ALCHEMY_DEBUG 931#ifdef ALCHEMY_DEBUG
967 if (strcmp (result->title, "NONE") != 0) 932 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); 933 LOG (llevDebug, "got formula: %s of %s (nbatches:%d)\n", result->arch_name[0], &result->title, formula / result->index);
969 else 934 else
970 LOG (llevDebug, "got formula: %s (nbatches:%d)\n", result->arch_name[0], formula / result->index); 935 LOG (llevDebug, "got formula: %s (nbatches:%d)\n", result->arch_name[0], formula / result->index);
971#endif 936#endif
972 return result; 937 return result;
973} 938}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines