1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game |
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> |
… | |
… | |
231 | int tval = 0, formula = 0; |
232 | int tval = 0, formula = 0; |
232 | |
233 | |
233 | while (tmp) |
234 | while (tmp) |
234 | { |
235 | { |
235 | tval = 0; |
236 | tval = 0; |
236 | strcpy (name, tmp->name); |
237 | assign (name, tmp->name); |
237 | if (tmp->title) |
238 | if (tmp->title) |
238 | sprintf (name, "%s %s", &tmp->name, &tmp->title); |
239 | sprintf (name, "%s %s", &tmp->name, &tmp->title); |
239 | tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1)); |
240 | tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1)); |
240 | #ifdef ALCHEMY_DEBUG |
241 | #ifdef ALCHEMY_DEBUG |
241 | 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); |
… | |
… | |
290 | |
291 | |
291 | /* 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 */ |
292 | int batches = abs (nbatches); |
293 | int batches = abs (nbatches); |
293 | |
294 | |
294 | |
295 | |
295 | LOG (llevDebug, "A %s <=> %s\n", &(rp->cauldron), &(cauldron->arch->name)); |
|
|
296 | /* is the cauldron the right type? */ |
296 | /* is the cauldron the right type? */ |
297 | if (strcmp (rp->cauldron, cauldron->arch->name) != 0) |
297 | if (rp->cauldron != cauldron->arch->name) |
298 | { |
298 | { |
299 | 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."); |
300 | return 0; |
300 | return 0; |
301 | } |
301 | } |
302 | |
302 | |
… | |
… | |
308 | /* code required for this recipe, search the caster */ |
308 | /* code required for this recipe, search the caster */ |
309 | if (rp->keycode) |
309 | if (rp->keycode) |
310 | { |
310 | { |
311 | object *tmp; |
311 | object *tmp; |
312 | |
312 | |
313 | for (tmp = caster->inv; tmp != NULL; tmp = tmp->below) |
313 | for (tmp = caster->inv; tmp; tmp = tmp->below) |
314 | { |
314 | { |
315 | if (tmp->type == FORCE && tmp->slaying && !strcmp (rp->keycode, tmp->slaying)) |
315 | if (tmp->type == FORCE && tmp->slaying && rp->keycode == tmp->slaying) |
316 | break; |
316 | break; |
317 | } |
317 | } |
|
|
318 | |
318 | if (tmp == NULL) |
319 | if (!tmp) |
319 | { /* failure--no code found */ |
320 | { /* failure--no code found */ |
320 | new_draw_info (NDI_UNIQUE, 0, caster, "You know the ingredients," " but not the technique. Go learn how to do this recipe."); |
321 | new_draw_info (NDI_UNIQUE, 0, caster, "You know the ingredients," " but not the technique. Go learn how to do this recipe."); |
321 | return 0; |
322 | return 0; |
322 | } |
323 | } |
323 | } |
324 | } |
… | |
… | |
340 | /* new_draw_info_format(NDI_UNIQUE, 0,caster, |
341 | /* new_draw_info_format(NDI_UNIQUE, 0,caster, |
341 | "Your spell causes the %s to explode!",&cauldron->name); */ |
342 | "Your spell causes the %s to explode!",&cauldron->name); */ |
342 | /* kaboom_cauldron(); */ |
343 | /* kaboom_cauldron(); */ |
343 | } |
344 | } |
344 | else |
345 | else |
345 | { |
|
|
346 | 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 ()); |
347 | } |
|
|
348 | } |
347 | } |
|
|
348 | |
349 | return item; |
349 | return item; |
350 | } |
350 | } |
351 | |
351 | |
352 | |
352 | |
353 | |
353 | |
354 | /**
|
354 | /** |
355 | * 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 |
356 | * 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.
|
357 | */ |
357 | */ |
358 |
void |
358 | void |
359 | adjust_product (object *item, int lvl, int yield) |
359 | adjust_product (object *item, int lvl, int yield) |
360 | { |
360 | { |
361 | int nrof = 1; |
361 | int nrof = 1; |
362 | |
362 | |
363 | if (!yield) |
363 | if (!yield) |
364 | yield = 1; |
364 | yield = 1; |
|
|
365 | |
365 | if (lvl <= 0) |
366 | if (lvl <= 0) |
366 | lvl = 1; /* lets avoid div by zero! */ |
367 | lvl = 1; /* lets avoid div by zero! */ |
|
|
368 | |
367 | if (item->nrof) |
369 | if (item->nrof) |
368 | { |
370 | { |
369 | nrof = (int) ((1.0 - 1.0 / (lvl / 10.0 + 1.0)) * (rndm (0, yield - 1) + rndm (0, yield - 1) + rndm (0, yield - 1)) + 1); |
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 | |
370 | if (nrof > yield) |
373 | if (nrof > yield) |
371 | nrof = yield; |
374 | nrof = yield; |
|
|
375 | |
372 | item->nrof = nrof; |
376 | item->nrof = nrof; |
373 | } |
377 | } |
374 | } |
378 | } |
375 | |
379 | |
376 | |
380 | |
… | |
… | |
444 | { |
448 | { |
445 | size_t i; |
449 | size_t i; |
446 | |
450 | |
447 | for (i = 0; i < rp->arch_names; i++) |
451 | for (i = 0; i < rp->arch_names; i++) |
448 | { |
452 | { |
449 | if (strcmp (item->arch->name, rp->arch_name[i]) == 0) |
453 | if (item->arch->name == rp->arch_name[i]) |
450 | { |
454 | { |
451 | *rp_arch_index = i; |
455 | *rp_arch_index = i; |
452 | break; |
456 | break; |
453 | } |
457 | } |
454 | } |
458 | } |
|
|
459 | |
455 | if (i < rp->arch_names) |
460 | if (i < rp->arch_names) |
456 | break; |
461 | break; |
457 | } |
462 | } |
458 | |
463 | |
459 | /* 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 |
… | |
… | |
506 | |
511 | |
507 | if (rndm (0, 2)) |
512 | if (rndm (0, 2)) |
508 | { /* slag created */ |
513 | { /* slag created */ |
509 | object *tmp = cauldron->inv; |
514 | object *tmp = cauldron->inv; |
510 | int weight = 0; |
515 | int weight = 0; |
511 | uint16 material = M_STONE; |
|
|
512 | |
516 | |
513 | while (tmp) |
|
|
514 | { /* slag has coadded ingredient properties */ |
|
|
515 | weight += tmp->weight; |
|
|
516 | if (!(material & tmp->material)) |
|
|
517 | material |= tmp->material; |
|
|
518 | tmp = tmp->below; |
|
|
519 | } |
|
|
520 | tmp = get_archetype ("rock"); |
517 | tmp = get_archetype ("rock"); |
521 | tmp->weight = weight; |
518 | tmp->weight = weight; |
522 | tmp->value = 0; |
519 | tmp->value = 0; |
523 | tmp->material = material; |
|
|
524 | tmp->materialname = "stone"; |
520 | tmp->materialname = "stone"; |
525 | tmp->name = "slag"; |
521 | tmp->name = "slag"; |
526 | tmp->name_pl = "slags"; |
522 | tmp->name_pl = "slags"; |
527 | item = insert_ob_in_ob (tmp, cauldron); |
523 | item = insert_ob_in_ob (tmp, cauldron); |
528 | CLEAR_FLAG (tmp, FLAG_CAN_ROLL); |
524 | CLEAR_FLAG (tmp, FLAG_CAN_ROLL); |
529 | CLEAR_FLAG (tmp, FLAG_NO_PICK); |
525 | CLEAR_FLAG (tmp, FLAG_NO_PICK); |
530 | tmp->move_block = 0; |
526 | tmp->move_block = 0; |
531 | } |
527 | } |
|
|
528 | |
532 | remove_contents (cauldron->inv, item); |
529 | remove_contents (cauldron->inv, item); |
533 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); |
530 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s.", &cauldron->name, cauldron_sound ()); |
534 | return; |
531 | return; |
535 | } |
532 | } |
536 | else if (level < 40) |
533 | else if (level < 40) |
… | |
… | |
733 | tmp->destroy (); |
730 | tmp->destroy (); |
734 | tmp = next; |
731 | tmp = next; |
735 | } |
732 | } |
736 | } |
733 | } |
737 | |
734 | |
738 | /**
|
735 | /** |
739 | *"Danger" level, will determine how bad the backfire |
736 | *"Danger" level, will determine how bad the backfire |
740 | * could be if the user fails to concoct a recipe properly. Factors include |
737 | * 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, |
738 | * 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 |
739 | * 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 |
740 | * 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 |
741 | * 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) |
742 | * skill *before* this routine is called. (no longer auto-readies that skill) |
746 | * -b.t. |
743 | * -b.t. |
747 | */ |
744 | */ |
748 | |
|
|
749 | int |
745 | int |
750 | calc_alch_danger (object *caster, object *cauldron, recipe *rp) |
746 | calc_alch_danger (object *caster, object *cauldron, recipe *rp) |
751 | { |
747 | { |
752 | object *item; |
748 | object *item; |
753 | char name[MAX_BUF]; |
749 | char name[MAX_BUF]; |
754 | int danger = 0, nrofi = 0; |
750 | int danger = 0, nrofi = 0; |
755 | |
751 | |
756 | /* Knowing alchemy skill reduces yer risk */ |
752 | /* Knowing alchemy skill reduces yer risk */ |
757 | danger -= caster->chosen_skill ? caster->chosen_skill->level : caster->level; |
753 | danger -= caster->chosen_skill ? caster->chosen_skill->level : caster->level; |
|
|
754 | |
|
|
755 | if (!caster->chosen_skill) |
|
|
756 | LOG (llevError | logBacktrace, "calc_alch_danger called without a chosen skill, caster %s, cauldron %s\n", |
|
|
757 | caster->debug_desc (), cauldron->debug_desc ()); |
758 | |
758 | |
759 | /* better cauldrons reduce risk */ |
759 | /* better cauldrons reduce risk */ |
760 | danger -= cauldron->magic; |
760 | danger -= cauldron->magic; |
761 | |
761 | |
762 | /* Higher Int, lower the risk */ |
762 | /* Higher Int, lower the risk */ |
… | |
… | |
766 | * Thus the backfire is worse. Also, more ingredients |
766 | * Thus the backfire is worse. Also, more ingredients |
767 | * means we are attempting a more powerfull potion, |
767 | * means we are attempting a more powerfull potion, |
768 | * and thus the backfire will be worse. */ |
768 | * and thus the backfire will be worse. */ |
769 | for (item = cauldron->inv; item; item = item->below) |
769 | for (item = cauldron->inv; item; item = item->below) |
770 | { |
770 | { |
771 | strcpy (name, item->name); |
771 | assign (name, item->name); |
772 | if (item->title) |
772 | if (item->title) |
773 | sprintf (name, "%s %s", &item->name, &item->title); |
773 | sprintf (name, "%s %s", &item->name, &item->title); |
774 | danger += (strtoint (name) / 1000) + 3; |
774 | danger += (strtoint (name) / 1000) + 3; |
775 | nrofi++; |
775 | nrofi++; |
776 | } |
776 | } |
|
|
777 | |
777 | if (rp == NULL) |
778 | if (rp == NULL) |
778 | danger += 110; |
779 | danger += 110; |
779 | else |
780 | else |
780 | danger += rp->diff * 3; |
781 | danger += rp->diff * 3; |
781 | |
782 | |
… | |
… | |
790 | #endif |
791 | #endif |
791 | |
792 | |
792 | return danger; |
793 | return danger; |
793 | } |
794 | } |
794 | |
795 | |
795 | /**
|
796 | /** |
796 | * Determines if ingredients in a container match the |
797 | * Determines if ingredients in a container match the |
797 | * proper ingredients for a recipe. |
798 | * proper ingredients for a recipe. |
798 | * |
799 | * |
799 | * rp is the recipe to check |
800 | * rp is the recipe to check |
800 | * cauldron is the container that holds the ingredients |
801 | * cauldron is the container that holds the ingredients |
… | |
… | |
904 | LOG (llevDebug, "looking for formula %d:\n", formula); |
905 | LOG (llevDebug, "looking for formula %d:\n", formula); |
905 | #endif |
906 | #endif |
906 | result = NULL; |
907 | result = NULL; |
907 | recipes_matching = 0; |
908 | recipes_matching = 0; |
908 | transmute_found = 0; |
909 | transmute_found = 0; |
|
|
910 | |
909 | for (rp = fl->items; rp != NULL; rp = rp->next) |
911 | for (rp = fl->items; rp; rp = rp->next) |
910 | { |
912 | { |
911 | /* check if recipe matches at all */ |
913 | /* check if recipe matches at all */ |
912 | if (formula % rp->index != 0) |
914 | if (formula % rp->index != 0) |
913 | { |
915 | { |
914 | #ifdef EXTREME_ALCHEMY_DEBUG |
916 | #ifdef EXTREME_ALCHEMY_DEBUG |