1 | |
|
|
2 | /* |
1 | /* |
3 | * static char *rcsid_alchemy_c = |
|
|
4 | * "$Id: alchemy.C,v 1.7 2006/09/10 15:59:57 root Exp $"; |
|
|
5 | */ |
|
|
6 | |
|
|
7 | /* |
|
|
8 | CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game for X-windows |
9 | |
3 | * |
|
|
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
10 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
11 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
12 | |
7 | * |
13 | This program is free software; you can redistribute it and/or modify |
8 | * This program is free software; you can redistribute it and/or modify |
14 | 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 |
15 | the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation; either version 2 of the License, or |
16 | (at your option) any later version. |
11 | * (at your option) any later version. |
17 | |
12 | * |
18 | 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, |
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
21 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
22 | |
17 | * |
23 | 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 |
24 | along with this program; if not, write to the Free Software |
19 | * along with this program; if not, write to the Free Software |
25 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
26 | |
21 | * |
27 | The authors can be reached via e-mail at crossfire-devel@real-time.com |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
28 | */ |
23 | */ |
29 | |
24 | |
30 | /* 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 */ |
31 | |
26 | |
32 | #include <global.h> |
27 | #include <global.h> |
33 | #include <object.h> |
28 | #include <object.h> |
34 | #ifndef __CEXTRACT__ |
|
|
35 | # include <sproto.h> |
29 | #include <sproto.h> |
36 | #endif |
|
|
37 | #include <skills.h> |
30 | #include <skills.h> |
38 | #include <spells.h> |
31 | #include <spells.h> |
39 | |
32 | |
40 | /** define this for some helpful debuging information */ |
33 | /** define this for some helpful debuging information */ |
41 | #if 0 |
34 | #if 0 |
… | |
… | |
161 | /* the caster gets an increase in ability based on thier skill lvl */ |
154 | /* the caster gets an increase in ability based on thier skill lvl */ |
162 | if (rp->skill) |
155 | if (rp->skill) |
163 | { |
156 | { |
164 | skop = find_skill_by_name (caster, rp->skill); |
157 | skop = find_skill_by_name (caster, rp->skill); |
165 | if (!skop) |
158 | if (!skop) |
166 | { |
|
|
167 | new_draw_info (NDI_UNIQUE, 0, caster, "You do not have the proper skill for this recipe"); |
159 | new_draw_info (NDI_UNIQUE, 0, caster, "You do not have the proper skill for this recipe"); |
168 | } |
|
|
169 | else |
160 | else |
170 | { |
|
|
171 | ability += (int) (skop->level * ((4.0 + cauldron->magic) / 4.0)); |
161 | ability += (int) (skop->level * ((4.0 + cauldron->magic) / 4.0)); |
172 | } |
|
|
173 | } |
162 | } |
174 | else |
163 | else |
175 | { |
164 | { |
176 | LOG (llevDebug, "Recipe %s has NULL skill!\n", &rp->title); |
165 | LOG (llevDebug, "Recipe %s has NULL skill!\n", &rp->title); |
177 | return; |
166 | return; |
178 | } |
167 | } |
179 | |
168 | |
180 | if (rp->cauldron) |
169 | if (!rp->cauldron) |
181 | { |
170 | { |
182 | LOG (llevDebug, "Recipe %s has NULL cauldron!\n", &rp->title); |
171 | LOG (llevDebug, "Recipe %s has NULL cauldron!\n", &rp->title); |
183 | return; |
172 | return; |
184 | } |
173 | } |
185 | |
174 | |
… | |
… | |
204 | |
193 | |
205 | value_item = query_cost (item, NULL, F_TRUE | F_IDENTIFIED | F_NOT_CURSED); |
194 | value_item = query_cost (item, NULL, F_TRUE | F_IDENTIFIED | F_NOT_CURSED); |
206 | if (attempt_shadow_alchemy && value_item > value_ingredients) |
195 | if (attempt_shadow_alchemy && value_item > value_ingredients) |
207 | { |
196 | { |
208 | #ifdef ALCHEMY_DEBUG |
197 | #ifdef ALCHEMY_DEBUG |
209 | # ifndef WIN32 |
|
|
210 | LOG (llevDebug, |
198 | LOG (llevDebug, |
211 | "Forcing failure for shadow alchemy recipe because price of ingredients (%llu) is less than price of result (%llu).\n", |
199 | "Forcing failure for shadow alchemy recipe because price of ingredients (%llu) is less than price of result (%llu).\n", |
212 | value_ingredients, value_item); |
200 | value_ingredients, value_item); |
213 | # else |
|
|
214 | LOG (llevDebug, |
|
|
215 | "Forcing failure for shadow alchemy recipe because price of ingredients (%I64d) is less than price of result (%I64d).\n", |
|
|
216 | value_ingredients, value_item); |
|
|
217 | # endif |
|
|
218 | #endif |
201 | #endif |
219 | } |
202 | } |
220 | /* roll the dice */ |
203 | /* roll the dice */ |
221 | else if ((float) (random_roll (0, 101, caster, PREFER_LOW)) <= 100.0 * success_chance) |
204 | else if ((float) (random_roll (0, 101, caster, PREFER_LOW)) <= 100.0 * success_chance) |
222 | { |
205 | { |
223 | change_exp (caster, rp->exp, rp->skill, SK_EXP_NONE); |
206 | change_exp (caster, rp->exp, rp->skill, SK_EXP_NONE); |
|
|
207 | |
|
|
208 | // let alchemy consume some time, so that exploits are less easy |
|
|
209 | caster->speed_left -= 1.0; |
|
|
210 | |
224 | return; |
211 | return; |
225 | } |
212 | } |
226 | } |
213 | } |
227 | } |
214 | } |
228 | } |
215 | } |
|
|
216 | |
229 | /* if we get here, we failed!! */ |
217 | /* if we get here, we failed!! */ |
230 | alchemy_failure_effect (caster, cauldron, rp, calc_alch_danger (caster, cauldron, rp)); |
218 | alchemy_failure_effect (caster, cauldron, rp, calc_alch_danger (caster, cauldron, rp)); |
231 | } |
219 | } |
232 | |
220 | |
233 | /**
|
221 | /**
|
… | |
… | |
303 | |
291 | |
304 | /* this should be passed to this fctn, not effiecent cpu use this way */ |
292 | /* this should be passed to this fctn, not effiecent cpu use this way */ |
305 | int batches = abs (nbatches); |
293 | int batches = abs (nbatches); |
306 | |
294 | |
307 | |
295 | |
308 | LOG (llevDebug, "A %s <=> %s\n", &(rp->cauldron), &(cauldron->arch->name)); |
|
|
309 | /* is the cauldron the right type? */ |
296 | /* is the cauldron the right type? */ |
310 | if (strcmp (rp->cauldron, cauldron->arch->name) != 0) |
297 | if (strcmp (rp->cauldron, cauldron->arch->name) != 0) |
311 | { |
298 | { |
312 | new_draw_info (NDI_UNIQUE, 0, caster, "You are not using the proper" " facilities for this formula."); |
299 | new_draw_info (NDI_UNIQUE, 0, caster, "You are not using the proper" " facilities for this formula."); |
313 | return 0; |
300 | return 0; |
… | |
… | |
321 | /* code required for this recipe, search the caster */ |
308 | /* code required for this recipe, search the caster */ |
322 | if (rp->keycode) |
309 | if (rp->keycode) |
323 | { |
310 | { |
324 | object *tmp; |
311 | object *tmp; |
325 | |
312 | |
326 | for (tmp = caster->inv; tmp != NULL; tmp = tmp->below) |
313 | for (tmp = caster->inv; tmp; tmp = tmp->below) |
327 | { |
314 | { |
328 | if (tmp->type == FORCE && tmp->slaying && !strcmp (rp->keycode, tmp->slaying)) |
315 | if (tmp->type == FORCE && tmp->slaying && !strcmp (rp->keycode, tmp->slaying)) |
329 | break; |
316 | break; |
330 | } |
317 | } |
|
|
318 | |
331 | if (tmp == NULL) |
319 | if (!tmp) |
332 | { /* failure--no code found */ |
320 | { /* failure--no code found */ |
333 | new_draw_info (NDI_UNIQUE, 0, caster, "You know the ingredients," " but not the technique. Go learn how to do this recipe."); |
321 | new_draw_info (NDI_UNIQUE, 0, caster, "You know the ingredients," " but not the technique. Go learn how to do this recipe."); |
334 | return 0; |
322 | return 0; |
335 | } |
323 | } |
336 | } |
324 | } |
… | |
… | |
353 | /* new_draw_info_format(NDI_UNIQUE, 0,caster, |
341 | /* new_draw_info_format(NDI_UNIQUE, 0,caster, |
354 | "Your spell causes the %s to explode!",&cauldron->name); */ |
342 | "Your spell causes the %s to explode!",&cauldron->name); */ |
355 | /* kaboom_cauldron(); */ |
343 | /* kaboom_cauldron(); */ |
356 | } |
344 | } |
357 | else |
345 | else |
358 | { |
|
|
359 | new_draw_info_format (NDI_UNIQUE, 0, caster, "The %s %s.", &cauldron->name, cauldron_sound ()); |
346 | new_draw_info_format (NDI_UNIQUE, 0, caster, "The %s %s.", &cauldron->name, cauldron_sound ()); |
360 | } |
|
|
361 | } |
347 | } |
|
|
348 | |
362 | return item; |
349 | return item; |
363 | } |
350 | } |
364 | |
351 | |
365 | |
352 | |
366 | |
353 | |
367 | /**
|
354 | /** |
368 | * We adjust the nrof, exp and level of the final product, based |
355 | * We adjust the nrof, exp and level of the final product, based |
369 | * on the item's default parameters, and the relevant caster skill level.
|
356 | * on the item's default parameters, and the relevant caster skill level.
|
370 | */ |
357 | */ |
371 |
void |
358 | void |
372 | adjust_product (object *item, int lvl, int yield) |
359 | adjust_product (object *item, int lvl, int yield) |
373 | { |
360 | { |
374 | int nrof = 1; |
361 | int nrof = 1; |
375 | |
362 | |
376 | if (!yield) |
363 | if (!yield) |
377 | yield = 1; |
364 | yield = 1; |
|
|
365 | |
378 | if (lvl <= 0) |
366 | if (lvl <= 0) |
379 | lvl = 1; /* lets avoid div by zero! */ |
367 | lvl = 1; /* lets avoid div by zero! */ |
|
|
368 | |
380 | if (item->nrof) |
369 | if (item->nrof) |
381 | { |
370 | { |
382 | nrof = (int) ((1.0 - 1.0 / (lvl / 10.0 + 1.0)) * (rndm (0, yield - 1) + rndm (0, yield - 1) + rndm (0, yield - 1)) + 1); |
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); |
|
|
372 | |
383 | if (nrof > yield) |
373 | if (nrof > yield) |
384 | nrof = yield; |
374 | nrof = yield; |
|
|
375 | |
385 | item->nrof = nrof; |
376 | item->nrof = nrof; |
386 | } |
377 | } |
387 | } |
378 | } |
388 | |
379 | |
389 | |
380 | |
… | |
… | |
606 | object *tmp; |
597 | object *tmp; |
607 | |
598 | |
608 | remove_contents (cauldron->inv, NULL); |
599 | remove_contents (cauldron->inv, NULL); |
609 | switch (rndm (0, 2)) |
600 | switch (rndm (0, 2)) |
610 | { |
601 | { |
611 | case 0: |
602 | case 0: |
612 | tmp = get_archetype ("bomb"); |
603 | tmp = get_archetype ("bomb"); |
613 | tmp->stats.dam = random_roll (1, level, op, PREFER_LOW); |
604 | tmp->stats.dam = random_roll (1, level, op, PREFER_LOW); |
614 | tmp->stats.hp = random_roll (1, level, op, PREFER_LOW); |
605 | tmp->stats.hp = random_roll (1, level, op, PREFER_LOW); |
615 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s creates a bomb!", &cauldron->name); |
606 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s creates a bomb!", &cauldron->name); |
616 | break; |
607 | break; |
617 | |
608 | |
618 | default: |
609 | default: |
619 | tmp = get_archetype ("fireball"); |
610 | tmp = get_archetype ("fireball"); |
620 | tmp->stats.dam = random_roll (1, level, op, PREFER_LOW) / 5 + 1; |
611 | tmp->stats.dam = random_roll (1, level, op, PREFER_LOW) / 5 + 1; |
621 | tmp->stats.hp = random_roll (1, level, op, PREFER_LOW) / 10 + 2; |
612 | tmp->stats.hp = random_roll (1, level, op, PREFER_LOW) / 10 + 2; |
622 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); |
613 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); |
623 | break; |
614 | break; |
624 | } |
615 | } |
625 | tmp->x = cauldron->x, tmp->y = cauldron->y; |
616 | |
626 | insert_ob_in_map (tmp, op->map, NULL, 0); |
617 | op->insert_at (cauldron); |
627 | return; |
618 | return; |
628 | |
619 | |
629 | } |
620 | } |
630 | else if (level < 60) |
621 | else if (level < 60) |
631 | { /* CREATE MONSTER */ |
622 | { /* CREATE MONSTER */ |
… | |
… | |
637 | { /* MAJOR FIRE */ |
628 | { /* MAJOR FIRE */ |
638 | object *fb = get_archetype (SP_MED_FIREBALL); |
629 | object *fb = get_archetype (SP_MED_FIREBALL); |
639 | |
630 | |
640 | remove_contents (cauldron->inv, NULL); |
631 | remove_contents (cauldron->inv, NULL); |
641 | fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb); |
632 | fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb); |
642 | free_object (fb); |
633 | fb->destroy (); |
643 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); |
634 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); |
644 | return; |
635 | return; |
645 | |
636 | |
646 | } |
637 | } |
647 | else if (level < 100) |
638 | else if (level < 100) |
… | |
… | |
715 | return; |
706 | return; |
716 | } |
707 | } |
717 | } |
708 | } |
718 | |
709 | |
719 | |
710 | |
720 | /**
|
711 | /* |
721 | * All but object "save_item" are elimentated from |
712 | * All but object "save_item" are elimentated from |
722 | * the container list. Note we have to becareful to remove the inventories |
713 | * the container list. Note we have to becareful to remove the inventories |
723 | * of objects in the cauldron inventory (ex icecube has stuff in it). |
714 | * of objects in the cauldron inventory (ex icecube has stuff in it). |
724 | */ |
715 | */ |
725 | |
716 | |
… | |
… | |
729 | object *next, *tmp = first_ob; |
720 | object *next, *tmp = first_ob; |
730 | |
721 | |
731 | while (tmp) |
722 | while (tmp) |
732 | { |
723 | { |
733 | next = tmp->below; |
724 | next = tmp->below; |
|
|
725 | |
734 | if (tmp == save_item) |
726 | if (tmp == save_item) |
735 | { |
727 | { |
736 | if (!(tmp = next)) |
728 | if (!(tmp = next)) |
737 | break; |
729 | break; |
738 | else |
730 | else |
739 | next = next->below; |
731 | next = next->below; |
740 | } |
732 | } |
|
|
733 | |
741 | if (tmp->inv) |
734 | if (tmp->inv) |
742 | remove_contents (tmp->inv, NULL); |
735 | remove_contents (tmp->inv, NULL); |
743 | remove_ob (tmp); |
736 | |
744 | free_object (tmp); |
737 | tmp->destroy (); |
745 | tmp = next; |
738 | tmp = next; |
746 | } |
739 | } |
747 | } |
740 | } |
748 | |
741 | |
749 | /**
|
742 | /**
|