1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game for X-windows |
3 | |
3 | * |
|
|
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | |
7 | * |
7 | 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 |
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 2 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, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | |
21 | * |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
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> |
28 | #ifndef __CEXTRACT__ |
|
|
29 | # include <sproto.h> |
29 | #include <sproto.h> |
30 | #endif |
|
|
31 | #include <skills.h> |
30 | #include <skills.h> |
32 | #include <spells.h> |
31 | #include <spells.h> |
33 | |
32 | |
34 | /** define this for some helpful debuging information */ |
33 | /** define this for some helpful debuging information */ |
35 | #if 0 |
34 | #if 0 |
… | |
… | |
155 | /* 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 */ |
156 | if (rp->skill) |
155 | if (rp->skill) |
157 | { |
156 | { |
158 | skop = find_skill_by_name (caster, rp->skill); |
157 | skop = find_skill_by_name (caster, rp->skill); |
159 | if (!skop) |
158 | if (!skop) |
160 | { |
|
|
161 | 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"); |
162 | } |
|
|
163 | else |
160 | else |
164 | { |
|
|
165 | ability += (int) (skop->level * ((4.0 + cauldron->magic) / 4.0)); |
161 | ability += (int) (skop->level * ((4.0 + cauldron->magic) / 4.0)); |
166 | } |
|
|
167 | } |
162 | } |
168 | else |
163 | else |
169 | { |
164 | { |
170 | LOG (llevDebug, "Recipe %s has NULL skill!\n", &rp->title); |
165 | LOG (llevDebug, "Recipe %s has NULL skill!\n", &rp->title); |
171 | return; |
166 | return; |
172 | } |
167 | } |
173 | |
168 | |
174 | if (rp->cauldron) |
169 | if (!rp->cauldron) |
175 | { |
170 | { |
176 | LOG (llevDebug, "Recipe %s has NULL cauldron!\n", &rp->title); |
171 | LOG (llevDebug, "Recipe %s has NULL cauldron!\n", &rp->title); |
177 | return; |
172 | return; |
178 | } |
173 | } |
179 | |
174 | |
… | |
… | |
198 | |
193 | |
199 | 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); |
200 | if (attempt_shadow_alchemy && value_item > value_ingredients) |
195 | if (attempt_shadow_alchemy && value_item > value_ingredients) |
201 | { |
196 | { |
202 | #ifdef ALCHEMY_DEBUG |
197 | #ifdef ALCHEMY_DEBUG |
203 | # ifndef WIN32 |
|
|
204 | LOG (llevDebug, |
198 | LOG (llevDebug, |
205 | "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", |
206 | value_ingredients, value_item); |
200 | value_ingredients, value_item); |
207 | # else |
|
|
208 | LOG (llevDebug, |
|
|
209 | "Forcing failure for shadow alchemy recipe because price of ingredients (%I64d) is less than price of result (%I64d).\n", |
|
|
210 | value_ingredients, value_item); |
|
|
211 | # endif |
|
|
212 | #endif |
201 | #endif |
213 | } |
202 | } |
214 | /* roll the dice */ |
203 | /* roll the dice */ |
215 | 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) |
216 | { |
205 | { |
217 | 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 | |
218 | return; |
211 | return; |
219 | } |
212 | } |
220 | } |
213 | } |
221 | } |
214 | } |
222 | } |
215 | } |
|
|
216 | |
223 | /* if we get here, we failed!! */ |
217 | /* if we get here, we failed!! */ |
224 | 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)); |
225 | } |
219 | } |
226 | |
220 | |
227 | /**
|
221 | /**
|
… | |
… | |
238 | int tval = 0, formula = 0; |
232 | int tval = 0, formula = 0; |
239 | |
233 | |
240 | while (tmp) |
234 | while (tmp) |
241 | { |
235 | { |
242 | tval = 0; |
236 | tval = 0; |
243 | strcpy (name, tmp->name); |
237 | assign (name, tmp->name); |
244 | if (tmp->title) |
238 | if (tmp->title) |
245 | sprintf (name, "%s %s", &tmp->name, &tmp->title); |
239 | sprintf (name, "%s %s", &tmp->name, &tmp->title); |
246 | tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1)); |
240 | tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1)); |
247 | #ifdef ALCHEMY_DEBUG |
241 | #ifdef ALCHEMY_DEBUG |
248 | LOG (llevDebug, "Got ingredient %d %s(%d)\n", tmp->nrof ? tmp->nrof : 1, name, tval); |
242 | LOG (llevDebug, "Got ingredient %d %s(%d)\n", tmp->nrof ? tmp->nrof : 1, name, tval); |
… | |
… | |
297 | |
291 | |
298 | /* 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 */ |
299 | int batches = abs (nbatches); |
293 | int batches = abs (nbatches); |
300 | |
294 | |
301 | |
295 | |
302 | LOG (llevDebug, "A %s <=> %s\n", &(rp->cauldron), &(cauldron->arch->name)); |
|
|
303 | /* is the cauldron the right type? */ |
296 | /* is the cauldron the right type? */ |
304 | if (strcmp (rp->cauldron, cauldron->arch->name) != 0) |
297 | if (rp->cauldron != cauldron->arch->name) |
305 | { |
298 | { |
306 | 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."); |
307 | return 0; |
300 | return 0; |
308 | } |
301 | } |
309 | |
302 | |
… | |
… | |
315 | /* code required for this recipe, search the caster */ |
308 | /* code required for this recipe, search the caster */ |
316 | if (rp->keycode) |
309 | if (rp->keycode) |
317 | { |
310 | { |
318 | object *tmp; |
311 | object *tmp; |
319 | |
312 | |
320 | for (tmp = caster->inv; tmp != NULL; tmp = tmp->below) |
313 | for (tmp = caster->inv; tmp; tmp = tmp->below) |
321 | { |
314 | { |
322 | if (tmp->type == FORCE && tmp->slaying && !strcmp (rp->keycode, tmp->slaying)) |
315 | if (tmp->type == FORCE && tmp->slaying && rp->keycode == tmp->slaying) |
323 | break; |
316 | break; |
324 | } |
317 | } |
|
|
318 | |
325 | if (tmp == NULL) |
319 | if (!tmp) |
326 | { /* failure--no code found */ |
320 | { /* failure--no code found */ |
327 | 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."); |
328 | return 0; |
322 | return 0; |
329 | } |
323 | } |
330 | } |
324 | } |
… | |
… | |
347 | /* new_draw_info_format(NDI_UNIQUE, 0,caster, |
341 | /* new_draw_info_format(NDI_UNIQUE, 0,caster, |
348 | "Your spell causes the %s to explode!",&cauldron->name); */ |
342 | "Your spell causes the %s to explode!",&cauldron->name); */ |
349 | /* kaboom_cauldron(); */ |
343 | /* kaboom_cauldron(); */ |
350 | } |
344 | } |
351 | else |
345 | else |
352 | { |
|
|
353 | 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 ()); |
354 | } |
|
|
355 | } |
347 | } |
|
|
348 | |
356 | return item; |
349 | return item; |
357 | } |
350 | } |
358 | |
351 | |
359 | |
352 | |
360 | |
353 | |
361 | /**
|
354 | /** |
362 | * 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 |
363 | * 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.
|
364 | */ |
357 | */ |
365 |
void |
358 | void |
366 | adjust_product (object *item, int lvl, int yield) |
359 | adjust_product (object *item, int lvl, int yield) |
367 | { |
360 | { |
368 | int nrof = 1; |
361 | int nrof = 1; |
369 | |
362 | |
370 | if (!yield) |
363 | if (!yield) |
371 | yield = 1; |
364 | yield = 1; |
|
|
365 | |
372 | if (lvl <= 0) |
366 | if (lvl <= 0) |
373 | lvl = 1; /* lets avoid div by zero! */ |
367 | lvl = 1; /* lets avoid div by zero! */ |
|
|
368 | |
374 | if (item->nrof) |
369 | if (item->nrof) |
375 | { |
370 | { |
376 | 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 | |
377 | if (nrof > yield) |
373 | if (nrof > yield) |
378 | nrof = yield; |
374 | nrof = yield; |
|
|
375 | |
379 | item->nrof = nrof; |
376 | item->nrof = nrof; |
380 | } |
377 | } |
381 | } |
378 | } |
382 | |
379 | |
383 | |
380 | |
… | |
… | |
451 | { |
448 | { |
452 | size_t i; |
449 | size_t i; |
453 | |
450 | |
454 | for (i = 0; i < rp->arch_names; i++) |
451 | for (i = 0; i < rp->arch_names; i++) |
455 | { |
452 | { |
456 | if (strcmp (item->arch->name, rp->arch_name[i]) == 0) |
453 | if (item->arch->name == rp->arch_name[i]) |
457 | { |
454 | { |
458 | *rp_arch_index = i; |
455 | *rp_arch_index = i; |
459 | break; |
456 | break; |
460 | } |
457 | } |
461 | } |
458 | } |
|
|
459 | |
462 | if (i < rp->arch_names) |
460 | if (i < rp->arch_names) |
463 | break; |
461 | break; |
464 | } |
462 | } |
465 | |
463 | |
466 | /* failed, create a fresh object. Note no nrof>1 because that would |
464 | /* failed, create a fresh object. Note no nrof>1 because that would |
… | |
… | |
600 | object *tmp; |
598 | object *tmp; |
601 | |
599 | |
602 | remove_contents (cauldron->inv, NULL); |
600 | remove_contents (cauldron->inv, NULL); |
603 | switch (rndm (0, 2)) |
601 | switch (rndm (0, 2)) |
604 | { |
602 | { |
605 | case 0: |
603 | case 0: |
606 | tmp = get_archetype ("bomb"); |
604 | tmp = get_archetype ("bomb"); |
607 | tmp->stats.dam = random_roll (1, level, op, PREFER_LOW); |
605 | tmp->stats.dam = random_roll (1, level, op, PREFER_LOW); |
608 | tmp->stats.hp = random_roll (1, level, op, PREFER_LOW); |
606 | tmp->stats.hp = random_roll (1, level, op, PREFER_LOW); |
609 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s creates a bomb!", &cauldron->name); |
607 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s creates a bomb!", &cauldron->name); |
610 | break; |
608 | break; |
611 | |
609 | |
612 | default: |
610 | default: |
613 | tmp = get_archetype ("fireball"); |
611 | tmp = get_archetype ("fireball"); |
614 | tmp->stats.dam = random_roll (1, level, op, PREFER_LOW) / 5 + 1; |
612 | tmp->stats.dam = random_roll (1, level, op, PREFER_LOW) / 5 + 1; |
615 | tmp->stats.hp = random_roll (1, level, op, PREFER_LOW) / 10 + 2; |
613 | tmp->stats.hp = random_roll (1, level, op, PREFER_LOW) / 10 + 2; |
616 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); |
614 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); |
617 | break; |
615 | break; |
618 | } |
616 | } |
619 | tmp->x = cauldron->x, tmp->y = cauldron->y; |
617 | |
620 | insert_ob_in_map (tmp, op->map, NULL, 0); |
618 | op->insert_at (cauldron); |
621 | return; |
619 | return; |
622 | |
620 | |
623 | } |
621 | } |
624 | else if (level < 60) |
622 | else if (level < 60) |
625 | { /* CREATE MONSTER */ |
623 | { /* CREATE MONSTER */ |
… | |
… | |
631 | { /* MAJOR FIRE */ |
629 | { /* MAJOR FIRE */ |
632 | object *fb = get_archetype (SP_MED_FIREBALL); |
630 | object *fb = get_archetype (SP_MED_FIREBALL); |
633 | |
631 | |
634 | remove_contents (cauldron->inv, NULL); |
632 | remove_contents (cauldron->inv, NULL); |
635 | fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb); |
633 | fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb); |
636 | free_object (fb); |
634 | fb->destroy (); |
637 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); |
635 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); |
638 | return; |
636 | return; |
639 | |
637 | |
640 | } |
638 | } |
641 | else if (level < 100) |
639 | else if (level < 100) |
… | |
… | |
709 | return; |
707 | return; |
710 | } |
708 | } |
711 | } |
709 | } |
712 | |
710 | |
713 | |
711 | |
714 | /**
|
712 | /* |
715 | * All but object "save_item" are elimentated from |
713 | * All but object "save_item" are elimentated from |
716 | * the container list. Note we have to becareful to remove the inventories |
714 | * the container list. Note we have to becareful to remove the inventories |
717 | * of objects in the cauldron inventory (ex icecube has stuff in it). |
715 | * of objects in the cauldron inventory (ex icecube has stuff in it). |
718 | */ |
716 | */ |
719 | |
717 | |
… | |
… | |
723 | object *next, *tmp = first_ob; |
721 | object *next, *tmp = first_ob; |
724 | |
722 | |
725 | while (tmp) |
723 | while (tmp) |
726 | { |
724 | { |
727 | next = tmp->below; |
725 | next = tmp->below; |
|
|
726 | |
728 | if (tmp == save_item) |
727 | if (tmp == save_item) |
729 | { |
728 | { |
730 | if (!(tmp = next)) |
729 | if (!(tmp = next)) |
731 | break; |
730 | break; |
732 | else |
731 | else |
733 | next = next->below; |
732 | next = next->below; |
734 | } |
733 | } |
|
|
734 | |
735 | if (tmp->inv) |
735 | if (tmp->inv) |
736 | remove_contents (tmp->inv, NULL); |
736 | remove_contents (tmp->inv, NULL); |
737 | remove_ob (tmp); |
737 | |
738 | free_object (tmp); |
738 | tmp->destroy (); |
739 | tmp = next; |
739 | tmp = next; |
740 | } |
740 | } |
741 | } |
741 | } |
742 | |
742 | |
743 | /**
|
743 | /**
|
… | |
… | |
771 | * Thus the backfire is worse. Also, more ingredients |
771 | * Thus the backfire is worse. Also, more ingredients |
772 | * means we are attempting a more powerfull potion, |
772 | * means we are attempting a more powerfull potion, |
773 | * and thus the backfire will be worse. */ |
773 | * and thus the backfire will be worse. */ |
774 | for (item = cauldron->inv; item; item = item->below) |
774 | for (item = cauldron->inv; item; item = item->below) |
775 | { |
775 | { |
776 | strcpy (name, item->name); |
776 | assign (name, item->name); |
777 | if (item->title) |
777 | if (item->title) |
778 | sprintf (name, "%s %s", &item->name, &item->title); |
778 | sprintf (name, "%s %s", &item->name, &item->title); |
779 | danger += (strtoint (name) / 1000) + 3; |
779 | danger += (strtoint (name) / 1000) + 3; |
780 | nrofi++; |
780 | nrofi++; |
781 | } |
781 | } |