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 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> |
28 | #ifndef __CEXTRACT__ |
|
|
29 | # include <sproto.h> |
28 | #include <sproto.h> |
30 | #endif |
|
|
31 | #include <skills.h> |
29 | #include <skills.h> |
32 | #include <spells.h> |
30 | #include <spells.h> |
33 | |
31 | |
34 | /** define this for some helpful debuging information */ |
32 | /** define this for some helpful debuging information */ |
35 | #if 0 |
33 | #if 0 |
… | |
… | |
96 | * around. :) |
94 | * around. :) |
97 | * -b.t. |
95 | * -b.t. |
98 | */ |
96 | */ |
99 | |
97 | |
100 | void |
98 | void |
101 | attempt_do_alchemy (object *caster, object *cauldron) |
99 | attempt_do_alchemy (object *caster, object *cauldron, object *skill) |
102 | { |
100 | { |
103 | recipelist *fl; |
101 | recipelist *fl; |
104 | recipe *rp = NULL; |
102 | recipe *rp = NULL; |
105 | float success_chance; |
103 | float success_chance; |
106 | int numb, ability = 1; |
104 | int numb, ability = 1; |
… | |
… | |
142 | return; |
140 | return; |
143 | } /* End of WIZ alchemy */ |
141 | } /* End of WIZ alchemy */ |
144 | |
142 | |
145 | /* find the recipe */ |
143 | /* find the recipe */ |
146 | rp = find_recipe (fl, formula, cauldron->inv); |
144 | rp = find_recipe (fl, formula, cauldron->inv); |
147 | if (rp) |
145 | if (rp |
|
|
146 | && rp->skill == skill->skill |
|
|
147 | && (!rp->cauldron |
|
|
148 | || rp->cauldron == cauldron->arch->archname)) |
148 | { |
149 | { |
149 | uint64 value_ingredients; |
150 | uint64 value_ingredients; |
150 | uint64 value_item; |
151 | uint64 value_item; |
151 | object *tmp; |
152 | object *tmp; |
152 | int attempt_shadow_alchemy; |
153 | int attempt_shadow_alchemy; |
153 | |
154 | |
154 | ave_chance = fl->total_chance / (float) fl->number; |
155 | ave_chance = fl->total_chance / (float) fl->number; |
155 | /* the caster gets an increase in ability based on thier skill lvl */ |
156 | |
156 | if (rp->skill) |
|
|
157 | { |
|
|
158 | skop = find_skill_by_name (caster, rp->skill); |
|
|
159 | if (!skop) |
|
|
160 | new_draw_info (NDI_UNIQUE, 0, caster, "You do not have the proper skill for this recipe"); |
|
|
161 | else |
|
|
162 | ability += (int) (skop->level * ((4.0 + cauldron->magic) / 4.0)); |
157 | ability += (int) (skill->level * ((4.0 + cauldron->magic) / 4.0)); |
163 | } |
|
|
164 | else |
|
|
165 | { |
|
|
166 | LOG (llevDebug, "Recipe %s has NULL skill!\n", &rp->title); |
|
|
167 | return; |
|
|
168 | } |
|
|
169 | |
|
|
170 | if (!rp->cauldron) |
|
|
171 | { |
|
|
172 | LOG (llevDebug, "Recipe %s has NULL cauldron!\n", &rp->title); |
|
|
173 | return; |
|
|
174 | } |
|
|
175 | |
158 | |
176 | /* determine value of ingredients */ |
159 | /* determine value of ingredients */ |
177 | value_ingredients = 0; |
160 | value_ingredients = 0; |
178 | for (tmp = cauldron->inv; tmp != NULL; tmp = tmp->below) |
161 | for (tmp = cauldron->inv; tmp != NULL; tmp = tmp->below) |
179 | value_ingredients += query_cost (tmp, NULL, F_TRUE); |
162 | value_ingredients += query_cost (tmp, NULL, F_TRUE); |
… | |
… | |
233 | int tval = 0, formula = 0; |
216 | int tval = 0, formula = 0; |
234 | |
217 | |
235 | while (tmp) |
218 | while (tmp) |
236 | { |
219 | { |
237 | tval = 0; |
220 | tval = 0; |
238 | strcpy (name, tmp->name); |
221 | assign (name, tmp->name); |
239 | if (tmp->title) |
222 | if (tmp->title) |
240 | sprintf (name, "%s %s", &tmp->name, &tmp->title); |
223 | sprintf (name, "%s %s", &tmp->name, &tmp->title); |
241 | tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1)); |
224 | tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1)); |
242 | #ifdef ALCHEMY_DEBUG |
225 | #ifdef ALCHEMY_DEBUG |
243 | 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); |
… | |
… | |
291 | object *item = NULL, *skop; |
274 | object *item = NULL, *skop; |
292 | |
275 | |
293 | /* 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 */ |
294 | int batches = abs (nbatches); |
277 | int batches = abs (nbatches); |
295 | |
278 | |
296 | |
|
|
297 | LOG (llevDebug, "A %s <=> %s\n", &(rp->cauldron), &(cauldron->arch->name)); |
|
|
298 | /* is the cauldron the right type? */ |
279 | /* is the cauldron the right type? */ |
299 | if (strcmp (rp->cauldron, cauldron->arch->name) != 0) |
280 | if (rp->cauldron && rp->cauldron != cauldron->arch->archname) |
300 | { |
|
|
301 | new_draw_info (NDI_UNIQUE, 0, caster, "You are not using the proper" " facilities for this formula."); |
|
|
302 | return 0; |
281 | return 0; |
303 | } |
|
|
304 | |
282 | |
305 | skop = find_skill_by_name (caster, rp->skill); |
283 | skop = find_skill_by_name (caster, rp->skill); |
306 | /* does the caster have the skill? */ |
284 | /* does the caster have the skill? */ |
307 | if (!skop) |
285 | if (!skop) |
308 | return 0; |
286 | return 0; |
… | |
… | |
310 | /* code required for this recipe, search the caster */ |
288 | /* code required for this recipe, search the caster */ |
311 | if (rp->keycode) |
289 | if (rp->keycode) |
312 | { |
290 | { |
313 | object *tmp; |
291 | object *tmp; |
314 | |
292 | |
315 | for (tmp = caster->inv; tmp != NULL; tmp = tmp->below) |
293 | for (tmp = caster->inv; tmp; tmp = tmp->below) |
316 | { |
294 | { |
317 | if (tmp->type == FORCE && tmp->slaying && !strcmp (rp->keycode, tmp->slaying)) |
295 | if (tmp->type == FORCE && tmp->slaying && rp->keycode == tmp->slaying) |
318 | break; |
296 | break; |
319 | } |
297 | } |
|
|
298 | |
320 | if (tmp == NULL) |
299 | if (!tmp) |
321 | { /* failure--no code found */ |
300 | { /* failure--no code found */ |
322 | 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."); |
323 | return 0; |
302 | return 0; |
324 | } |
303 | } |
325 | } |
304 | } |
326 | |
305 | |
327 | #ifdef EXTREME_ALCHEMY_DEBUG |
306 | #ifdef EXTREME_ALCHEMY_DEBUG |
… | |
… | |
331 | |
310 | |
332 | if ((item = make_item_from_recipe (cauldron, rp)) != NULL) |
311 | if ((item = make_item_from_recipe (cauldron, rp)) != NULL) |
333 | { |
312 | { |
334 | remove_contents (cauldron->inv, item); |
313 | remove_contents (cauldron->inv, item); |
335 | /* 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 */ |
336 | sum_weight (cauldron); |
315 | cauldron->update_weight (); |
337 | /* adj lvl, nrof on caster level */ |
316 | /* adj lvl, nrof on caster level */ |
338 | adjust_product (item, ability, rp->yield ? (rp->yield * batches) : batches); |
317 | adjust_product (item, ability, rp->yield ? (rp->yield * batches) : batches); |
339 | if (!item->env && (item = insert_ob_in_ob (item, cauldron)) == NULL) |
318 | if (!item->env && (item = insert_ob_in_ob (item, cauldron)) == NULL) |
340 | { |
319 | { |
341 | new_draw_info (NDI_UNIQUE, 0, caster, "Nothing happened."); |
320 | new_draw_info (NDI_UNIQUE, 0, caster, "Nothing happened."); |
342 | /* new_draw_info_format(NDI_UNIQUE, 0,caster, |
321 | /* new_draw_info_format(NDI_UNIQUE, 0,caster, |
343 | "Your spell causes the %s to explode!",&cauldron->name); */ |
322 | "Your spell causes the %s to explode!",&cauldron->name); */ |
344 | /* kaboom_cauldron(); */ |
323 | /* kaboom_cauldron(); */ |
345 | } |
324 | } |
346 | else |
325 | else |
347 | { |
|
|
348 | 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 ()); |
349 | } |
|
|
350 | } |
327 | } |
|
|
328 | |
351 | return item; |
329 | return item; |
352 | } |
330 | } |
353 | |
331 | |
354 | |
332 | |
355 | |
333 | |
356 | /**
|
334 | /** |
357 | * 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 |
358 | * 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.
|
359 | */ |
337 | */ |
360 |
void |
338 | void |
361 | adjust_product (object *item, int lvl, int yield) |
339 | adjust_product (object *item, int lvl, int yield) |
362 | { |
340 | { |
363 | int nrof = 1; |
341 | int nrof = 1; |
364 | |
342 | |
365 | if (!yield) |
343 | if (!yield) |
366 | yield = 1; |
344 | yield = 1; |
|
|
345 | |
367 | if (lvl <= 0) |
346 | if (lvl <= 0) |
368 | lvl = 1; /* lets avoid div by zero! */ |
347 | lvl = 1; /* lets avoid div by zero! */ |
|
|
348 | |
369 | if (item->nrof) |
349 | if (item->nrof) |
370 | { |
350 | { |
371 | 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 | |
372 | if (nrof > yield) |
353 | if (nrof > yield) |
373 | nrof = yield; |
354 | nrof = yield; |
|
|
355 | |
374 | item->nrof = nrof; |
356 | item->nrof = nrof; |
375 | } |
357 | } |
376 | } |
358 | } |
377 | |
359 | |
378 | |
360 | |
… | |
… | |
402 | LOG (llevDebug, "make_alchemy_item(): failed to create alchemical object.\n"); |
384 | LOG (llevDebug, "make_alchemy_item(): failed to create alchemical object.\n"); |
403 | return (object *) NULL; |
385 | return (object *) NULL; |
404 | } |
386 | } |
405 | |
387 | |
406 | /* Find the appropriate artifact template... */ |
388 | /* Find the appropriate artifact template... */ |
407 | if (strcmp (rp->title, "NONE")) |
389 | if (rp->title != shstr_NONE) |
408 | { |
390 | { |
409 | if ((art = locate_recipe_artifact (rp, rp_arch_index)) == NULL) |
391 | if ((art = locate_recipe_artifact (rp, rp_arch_index)) == NULL) |
410 | { |
392 | { |
411 | LOG (llevError, "make_alchemy_item(): failed to locate recipe artifact.\n"); |
393 | LOG (llevError, "make_alchemy_item(): failed to locate recipe artifact.\n"); |
412 | 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); |
413 | return (object *) NULL; |
395 | return (object *) NULL; |
414 | } |
396 | } |
|
|
397 | |
415 | transmute_materialname (item, art->item); |
398 | transmute_materialname (item, art->item); |
416 | give_artifact_abilities (item, art->item); |
399 | give_artifact_abilities (item, art->item); |
417 | } |
400 | } |
418 | |
401 | |
419 | if (QUERY_FLAG (cauldron, FLAG_CURSED)) |
402 | if (QUERY_FLAG (cauldron, FLAG_CURSED)) |
… | |
… | |
442 | *rp_arch_index = 0; |
425 | *rp_arch_index = 0; |
443 | |
426 | |
444 | if (rp->transmute) /* look for matching ingredient/prod archs */ |
427 | if (rp->transmute) /* look for matching ingredient/prod archs */ |
445 | for (item = first_ingred; item; item = item->below) |
428 | for (item = first_ingred; item; item = item->below) |
446 | { |
429 | { |
447 | size_t i; |
430 | int i; |
448 | |
431 | |
449 | for (i = 0; i < rp->arch_names; i++) |
432 | for (int i = 0; i < rp->arch_names; i++) |
450 | { |
433 | //TODO: should be a shstr comparison |
451 | if (strcmp (item->arch->name, rp->arch_name[i]) == 0) |
434 | if (&item->arch->archname == rp->arch_name[i]) |
452 | { |
435 | { |
453 | *rp_arch_index = i; |
436 | *rp_arch_index = i; |
454 | break; |
437 | break; |
455 | } |
438 | } |
456 | } |
439 | |
457 | if (i < rp->arch_names) |
440 | if (i < rp->arch_names) |
458 | break; |
441 | break; |
459 | } |
442 | } |
460 | |
443 | |
461 | /* 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 |
462 | * allow players to create massive amounts of artifacts easily */ |
445 | * allow players to create massive amounts of artifacts easily */ |
463 | if (create_item && (!item || item->nrof > 1)) |
446 | if (create_item && (!item || item->nrof > 1)) |
464 | { |
447 | { |
465 | *rp_arch_index = RANDOM () % rp->arch_names; |
448 | *rp_arch_index = rndm (rp->arch_names); |
466 | item = get_archetype (rp->arch_name[*rp_arch_index]); |
449 | item = get_archetype (rp->arch_name[*rp_arch_index]); |
467 | } |
450 | } |
468 | |
451 | |
469 | #ifdef ALCHEMY_DEBUG |
452 | #ifdef ALCHEMY_DEBUG |
470 | LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no "); |
453 | LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no "); |
… | |
… | |
508 | |
491 | |
509 | if (rndm (0, 2)) |
492 | if (rndm (0, 2)) |
510 | { /* slag created */ |
493 | { /* slag created */ |
511 | object *tmp = cauldron->inv; |
494 | object *tmp = cauldron->inv; |
512 | int weight = 0; |
495 | int weight = 0; |
513 | uint16 material = M_STONE; |
|
|
514 | |
496 | |
515 | while (tmp) |
|
|
516 | { /* slag has coadded ingredient properties */ |
|
|
517 | weight += tmp->weight; |
|
|
518 | if (!(material & tmp->material)) |
|
|
519 | material |= tmp->material; |
|
|
520 | tmp = tmp->below; |
|
|
521 | } |
|
|
522 | tmp = get_archetype ("rock"); |
497 | tmp = get_archetype ("rock"); |
523 | tmp->weight = weight; |
498 | tmp->weight = weight; |
524 | tmp->value = 0; |
499 | tmp->value = 0; |
525 | tmp->material = material; |
|
|
526 | tmp->materialname = "stone"; |
500 | tmp->materialname = "stone"; |
527 | tmp->name = "slag"; |
501 | tmp->name = "slag"; |
528 | tmp->name_pl = "slags"; |
502 | tmp->name_pl = "slags"; |
529 | item = insert_ob_in_ob (tmp, cauldron); |
503 | item = insert_ob_in_ob (tmp, cauldron); |
530 | CLEAR_FLAG (tmp, FLAG_CAN_ROLL); |
504 | CLEAR_FLAG (tmp, FLAG_CAN_ROLL); |
531 | CLEAR_FLAG (tmp, FLAG_NO_PICK); |
505 | CLEAR_FLAG (tmp, FLAG_NO_PICK); |
532 | tmp->move_block = 0; |
506 | tmp->move_block = 0; |
533 | } |
507 | } |
|
|
508 | |
534 | remove_contents (cauldron->inv, item); |
509 | remove_contents (cauldron->inv, item); |
535 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); |
510 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); |
536 | return; |
511 | return; |
537 | } |
512 | } |
538 | else if (level < 40) |
513 | else if (level < 40) |
… | |
… | |
564 | } |
539 | } |
565 | while (rndm (0, 2)); |
540 | while (rndm (0, 2)); |
566 | } |
541 | } |
567 | return; |
542 | return; |
568 | } |
543 | } |
|
|
544 | |
569 | if (level == 40) |
545 | if (level == 40) |
570 | { /* MAKE RANDOM RECIPE */ |
546 | { /* MAKE RANDOM RECIPE */ |
571 | recipelist *fl; |
547 | recipelist *fl; |
572 | int numb = numb_ob_inside (cauldron); |
548 | int numb = numb_ob_inside (cauldron); |
573 | |
549 | |
… | |
… | |
575 | if (fl && (rp = get_random_recipe (fl))) |
551 | if (fl && (rp = get_random_recipe (fl))) |
576 | /* even though random, don't grant user any EXP for it */ |
552 | /* even though random, don't grant user any EXP for it */ |
577 | (void) attempt_recipe (op, cauldron, 1, rp, -1); |
553 | (void) attempt_recipe (op, cauldron, 1, rp, -1); |
578 | else |
554 | else |
579 | alchemy_failure_effect (op, cauldron, rp, level - 1); |
555 | alchemy_failure_effect (op, cauldron, rp, level - 1); |
580 | return; |
|
|
581 | |
|
|
582 | } |
556 | } |
583 | else if (level < 45) |
557 | else if (level < 45) |
584 | { /* INFURIATE NPC's */ |
558 | { /* INFURIATE NPC's */ |
585 | /* this is kind of kludgy I know... */ |
559 | /* this is kind of kludgy I know... */ |
586 | cauldron->enemy = op; |
560 | cauldron->enemy = op; |
587 | npc_call_help (cauldron); |
561 | npc_call_help (cauldron); |
588 | cauldron->enemy = NULL; |
562 | cauldron->enemy = NULL; |
589 | |
563 | |
590 | alchemy_failure_effect (op, cauldron, rp, level - 5); |
564 | alchemy_failure_effect (op, cauldron, rp, level - 5); |
591 | return; |
|
|
592 | } |
565 | } |
593 | else if (level < 50) |
566 | else if (level < 50) |
594 | { /* MINOR EXPLOSION/FIREBALL */ |
567 | { /* MINOR EXPLOSION/FIREBALL */ |
595 | object *tmp; |
568 | object *tmp; |
596 | |
569 | |
597 | remove_contents (cauldron->inv, NULL); |
570 | remove_contents (cauldron->inv, NULL); |
598 | switch (rndm (0, 2)) |
571 | switch (rndm (0, 2)) |
599 | { |
572 | { |
600 | case 0: |
573 | case 0: |
601 | tmp = get_archetype ("bomb"); |
574 | tmp = get_archetype ("bomb"); |
602 | tmp->stats.dam = random_roll (1, level, op, PREFER_LOW); |
575 | tmp->stats.dam = random_roll (1, level, op, PREFER_LOW); |
603 | tmp->stats.hp = random_roll (1, level, op, PREFER_LOW); |
576 | tmp->stats.hp = random_roll (1, level, op, PREFER_LOW); |
604 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s creates a bomb!", &cauldron->name); |
577 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s creates a bomb!", &cauldron->name); |
605 | break; |
578 | break; |
606 | |
579 | |
607 | default: |
580 | default: |
608 | tmp = get_archetype ("fireball"); |
581 | tmp = get_archetype ("fireball"); |
609 | tmp->stats.dam = random_roll (1, level, op, PREFER_LOW) / 5 + 1; |
582 | tmp->stats.dam = random_roll (1, level, op, PREFER_LOW) / 5 + 1; |
610 | tmp->stats.hp = random_roll (1, level, op, PREFER_LOW) / 10 + 2; |
583 | tmp->stats.hp = random_roll (1, level, op, PREFER_LOW) / 10 + 2; |
611 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); |
584 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); |
612 | break; |
585 | break; |
613 | } |
586 | } |
614 | tmp->x = cauldron->x, tmp->y = cauldron->y; |
|
|
615 | insert_ob_in_map (tmp, op->map, NULL, 0); |
|
|
616 | return; |
|
|
617 | |
587 | |
|
|
588 | tmp->insert_at (cauldron); |
618 | } |
589 | } |
619 | else if (level < 60) |
590 | else if (level < 60) |
620 | { /* CREATE MONSTER */ |
591 | { /* CREATE MONSTER */ |
621 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); |
592 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); |
622 | remove_contents (cauldron->inv, NULL); |
593 | remove_contents (cauldron->inv, NULL); |
623 | return; |
|
|
624 | } |
594 | } |
625 | else if (level < 80) |
595 | else if (level < 80) |
626 | { /* MAJOR FIRE */ |
596 | { /* MAJOR FIRE */ |
627 | object *fb = get_archetype (SP_MED_FIREBALL); |
597 | object *fb = get_archetype (SP_MED_FIREBALL); |
628 | |
598 | |
629 | remove_contents (cauldron->inv, NULL); |
599 | remove_contents (cauldron->inv, NULL); |
630 | fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb); |
600 | fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb); |
631 | free_object (fb); |
601 | fb->destroy (); |
632 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); |
602 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); |
633 | return; |
|
|
634 | |
|
|
635 | } |
603 | } |
636 | else if (level < 100) |
604 | else if (level < 100) |
637 | { /* WHAMMY the CAULDRON */ |
605 | { /* WHAMMY the CAULDRON */ |
638 | if (!QUERY_FLAG (cauldron, FLAG_CURSED)) |
606 | if (!QUERY_FLAG (cauldron, FLAG_CURSED)) |
639 | SET_FLAG (cauldron, FLAG_CURSED); |
607 | SET_FLAG (cauldron, FLAG_CURSED); |
640 | else |
608 | else |
641 | cauldron->magic--; |
609 | cauldron->magic--; |
|
|
610 | |
642 | cauldron->magic -= random_roll (0, 4, op, PREFER_LOW); |
611 | cauldron->magic -= random_roll (0, 4, op, PREFER_LOW); |
|
|
612 | |
643 | if (rndm (0, 1)) |
613 | if (rndm (0, 1)) |
644 | { |
614 | { |
645 | remove_contents (cauldron->inv, NULL); |
615 | remove_contents (cauldron->inv, NULL); |
646 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s turns darker then makes a gulping sound!", &cauldron->name); |
616 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s turns darker then makes a gulping sound!", &cauldron->name); |
647 | } |
617 | } |
648 | else |
618 | else |
649 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s becomes darker.", &cauldron->name); |
619 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s becomes darker.", &cauldron->name); |
650 | return; |
|
|
651 | |
|
|
652 | } |
620 | } |
653 | else if (level < 110) |
621 | else if (level < 110) |
654 | { /* SUMMON EVIL MONSTERS */ |
622 | { /* SUMMON EVIL MONSTERS */ |
655 | object *tmp = get_random_mon (level / 5); |
623 | object *tmp = get_random_mon (level / 5); |
656 | |
624 | |
657 | remove_contents (cauldron->inv, NULL); |
625 | remove_contents (cauldron->inv, NULL); |
|
|
626 | |
658 | if (!tmp) |
627 | if (!tmp) |
659 | alchemy_failure_effect (op, cauldron, rp, level); |
628 | alchemy_failure_effect (op, cauldron, rp, level); |
660 | else if (summon_hostile_monsters (cauldron, random_roll (1, 10, op, PREFER_LOW), tmp->arch->name)) |
629 | else if (summon_hostile_monsters (cauldron, random_roll (1, 10, op, PREFER_LOW), tmp->arch->archname)) |
661 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s and then pours forth monsters!", &cauldron->name, cauldron_sound ()); |
630 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s and then pours forth monsters!", &cauldron->name, cauldron_sound ()); |
662 | return; |
|
|
663 | |
|
|
664 | } |
631 | } |
665 | else if (level < 150) |
632 | else if (level < 150) |
666 | { /* COMBO EFFECT */ |
633 | { /* COMBO EFFECT */ |
667 | int roll = rndm (1, 3); |
634 | int roll = rndm (1, 3); |
668 | |
635 | |
669 | while (roll) |
636 | while (roll) |
670 | { |
637 | { |
671 | alchemy_failure_effect (op, cauldron, rp, level - 39); |
638 | alchemy_failure_effect (op, cauldron, rp, level - 39); |
672 | roll--; |
639 | roll--; |
673 | } |
640 | } |
674 | return; |
|
|
675 | } |
641 | } |
676 | else if (level == 151) |
642 | else if (level == 151) |
677 | { /* CREATE RANDOM ARTIFACT */ |
643 | { /* CREATE RANDOM ARTIFACT */ |
678 | object *tmp; |
644 | object *tmp; |
679 | |
645 | |
… | |
… | |
681 | * in this one, we allow *any* valid alchemy artifact |
647 | * in this one, we allow *any* valid alchemy artifact |
682 | * to be made (rather than only those on the given |
648 | * to be made (rather than only those on the given |
683 | * formulalist) */ |
649 | * formulalist) */ |
684 | if (!rp) |
650 | if (!rp) |
685 | rp = get_random_recipe ((recipelist *) NULL); |
651 | rp = get_random_recipe ((recipelist *) NULL); |
|
|
652 | |
686 | if (rp && (tmp = get_archetype (rp->arch_name[RANDOM () % rp->arch_names]))) |
653 | if (rp && (tmp = get_archetype (rp->arch_name [rndm (rp->arch_names)]))) |
687 | { |
654 | { |
688 | generate_artifact (tmp, random_roll (1, op->level / 2 + 1, op, PREFER_HIGH) + 1); |
655 | generate_artifact (tmp, random_roll (1, op->level / 2 + 1, op, PREFER_HIGH) + 1); |
689 | if ((tmp = insert_ob_in_ob (tmp, cauldron))) |
656 | if ((tmp = insert_ob_in_ob (tmp, cauldron))) |
690 | { |
657 | { |
691 | remove_contents (cauldron->inv, tmp); |
658 | remove_contents (cauldron->inv, tmp); |
692 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); |
659 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); |
693 | } |
660 | } |
694 | } |
661 | } |
695 | return; |
|
|
696 | } |
662 | } |
697 | else |
663 | else |
698 | { /* MANA STORM - watch out!! */ |
664 | { /* MANA STORM - watch out!! */ |
699 | object *tmp = get_archetype (LOOSE_MANA); |
665 | object *tmp = get_archetype (LOOSE_MANA); |
700 | |
666 | |
701 | new_draw_info (NDI_UNIQUE, 0, op, "You unwisely release potent forces!"); |
667 | new_draw_info (NDI_UNIQUE, 0, op, "You unwisely release potent forces!"); |
702 | remove_contents (cauldron->inv, NULL); |
668 | remove_contents (cauldron->inv, NULL); |
703 | cast_magic_storm (op, tmp, level); |
669 | cast_magic_storm (op, tmp, level); |
704 | return; |
|
|
705 | } |
670 | } |
706 | } |
671 | } |
707 | |
672 | |
708 | |
673 | /* |
709 | /**
|
|
|
710 | * All but object "save_item" are elimentated from |
674 | * All but object "save_item" are elimentated from |
711 | * the container list. Note we have to becareful to remove the inventories |
675 | * the container list. Note we have to becareful to remove the inventories |
712 | * of objects in the cauldron inventory (ex icecube has stuff in it). |
676 | * of objects in the cauldron inventory (ex icecube has stuff in it). |
713 | */ |
677 | */ |
714 | |
|
|
715 | void |
678 | void |
716 | remove_contents (object *first_ob, object *save_item) |
679 | remove_contents (object *first_ob, object *save_item) |
717 | { |
680 | { |
|
|
681 | // this cries for a cleaner rewrite, removing save_item first possibly |
718 | object *next, *tmp = first_ob; |
682 | object *next, *tmp = first_ob; |
719 | |
683 | |
720 | while (tmp) |
684 | while (tmp) |
721 | { |
685 | { |
722 | next = tmp->below; |
686 | next = tmp->below; |
|
|
687 | |
723 | if (tmp == save_item) |
688 | if (tmp == save_item) |
724 | { |
689 | { |
725 | if (!(tmp = next)) |
690 | if (!(tmp = next)) |
726 | break; |
691 | break; |
727 | else |
692 | else |
728 | next = next->below; |
693 | next = next->below; |
729 | } |
694 | } |
|
|
695 | |
730 | if (tmp->inv) |
696 | if (tmp->inv) |
731 | remove_contents (tmp->inv, NULL); |
697 | remove_contents (tmp->inv, NULL); |
732 | remove_ob (tmp); |
698 | |
733 | free_object (tmp); |
699 | tmp->destroy (); |
734 | tmp = next; |
700 | tmp = next; |
735 | } |
701 | } |
736 | } |
702 | } |
737 | |
703 | |
738 | /**
|
704 | /** |
739 | *"Danger" level, will determine how bad the backfire |
705 | *"Danger" level, will determine how bad the backfire |
740 | * could be if the user fails to concoct a recipe properly. Factors include |
706 | * 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, |
707 | * 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 |
708 | * 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 |
709 | * 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 |
710 | * 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) |
711 | * skill *before* this routine is called. (no longer auto-readies that skill) |
746 | * -b.t. |
712 | * -b.t. |
747 | */ |
713 | */ |
748 | |
|
|
749 | int |
714 | int |
750 | calc_alch_danger (object *caster, object *cauldron, recipe *rp) |
715 | calc_alch_danger (object *caster, object *cauldron, recipe *rp) |
751 | { |
716 | { |
752 | object *item; |
717 | object *item; |
753 | char name[MAX_BUF]; |
718 | char name[MAX_BUF]; |
754 | int danger = 0, nrofi = 0; |
719 | int danger = 0, nrofi = 0; |
755 | |
720 | |
756 | /* Knowing alchemy skill reduces yer risk */ |
721 | /* Knowing alchemy skill reduces yer risk */ |
757 | danger -= caster->chosen_skill ? caster->chosen_skill->level : caster->level; |
722 | danger -= caster->chosen_skill ? caster->chosen_skill->level : caster->level; |
|
|
723 | |
|
|
724 | if (!caster->chosen_skill) |
|
|
725 | LOG (llevError | logBacktrace, "calc_alch_danger called without a chosen skill, caster %s, cauldron %s\n", |
|
|
726 | caster->debug_desc (), cauldron->debug_desc ()); |
758 | |
727 | |
759 | /* better cauldrons reduce risk */ |
728 | /* better cauldrons reduce risk */ |
760 | danger -= cauldron->magic; |
729 | danger -= cauldron->magic; |
761 | |
730 | |
762 | /* Higher Int, lower the risk */ |
731 | /* Higher Int, lower the risk */ |
… | |
… | |
766 | * Thus the backfire is worse. Also, more ingredients |
735 | * Thus the backfire is worse. Also, more ingredients |
767 | * means we are attempting a more powerfull potion, |
736 | * means we are attempting a more powerfull potion, |
768 | * and thus the backfire will be worse. */ |
737 | * and thus the backfire will be worse. */ |
769 | for (item = cauldron->inv; item; item = item->below) |
738 | for (item = cauldron->inv; item; item = item->below) |
770 | { |
739 | { |
771 | strcpy (name, item->name); |
740 | assign (name, item->name); |
772 | if (item->title) |
741 | if (item->title) |
773 | sprintf (name, "%s %s", &item->name, &item->title); |
742 | sprintf (name, "%s %s", &item->name, &item->title); |
774 | danger += (strtoint (name) / 1000) + 3; |
743 | danger += (strtoint (name) / 1000) + 3; |
775 | nrofi++; |
744 | nrofi++; |
776 | } |
745 | } |
|
|
746 | |
777 | if (rp == NULL) |
747 | if (rp == NULL) |
778 | danger += 110; |
748 | danger += 110; |
779 | else |
749 | else |
780 | danger += rp->diff * 3; |
750 | danger += rp->diff * 3; |
781 | |
751 | |
… | |
… | |
790 | #endif |
760 | #endif |
791 | |
761 | |
792 | return danger; |
762 | return danger; |
793 | } |
763 | } |
794 | |
764 | |
795 | /**
|
765 | /** |
796 | * Determines if ingredients in a container match the |
766 | * Determines if ingredients in a container match the |
797 | * proper ingredients for a recipe. |
767 | * proper ingredients for a recipe. |
798 | * |
768 | * |
799 | * rp is the recipe to check |
769 | * rp is the recipe to check |
800 | * cauldron is the container that holds the ingredients |
770 | * cauldron is the container that holds the ingredients |
… | |
… | |
849 | for (ob = cauldron->inv; ob != NULL; ob = ob->below) |
819 | for (ob = cauldron->inv; ob != NULL; ob = ob->below) |
850 | { |
820 | { |
851 | char name_ob[MAX_BUF]; |
821 | char name_ob[MAX_BUF]; |
852 | const char *name2; |
822 | const char *name2; |
853 | |
823 | |
854 | if (ob->title == NULL) |
824 | if (!ob->title) |
855 | name2 = ob->name; |
825 | name2 = ob->name; |
856 | else |
826 | else |
857 | { |
827 | { |
858 | snprintf (name_ob, sizeof (name_ob), "%s %s", &ob->name, &ob->title); |
828 | snprintf (name_ob, sizeof (name_ob), "%s %s", &ob->name, &ob->title); |
859 | name2 = name_ob; |
829 | name2 = name_ob; |
… | |
… | |
904 | LOG (llevDebug, "looking for formula %d:\n", formula); |
874 | LOG (llevDebug, "looking for formula %d:\n", formula); |
905 | #endif |
875 | #endif |
906 | result = NULL; |
876 | result = NULL; |
907 | recipes_matching = 0; |
877 | recipes_matching = 0; |
908 | transmute_found = 0; |
878 | transmute_found = 0; |
|
|
879 | |
909 | for (rp = fl->items; rp != NULL; rp = rp->next) |
880 | for (rp = fl->items; rp; rp = rp->next) |
910 | { |
881 | { |
911 | /* check if recipe matches at all */ |
882 | /* check if recipe matches at all */ |
912 | if (formula % rp->index != 0) |
883 | if (formula % rp->index != 0) |
913 | { |
884 | { |
914 | #ifdef EXTREME_ALCHEMY_DEBUG |
885 | #ifdef EXTREME_ALCHEMY_DEBUG |