1 | /* |
1 | /* |
2 | * CrossFire, A Multiplayer game for X-windows |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
3 | * |
3 | * |
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT 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 | * Crossfire TRT is free software; you can redistribute it and/or modify it |
9 | * it under the terms of the GNU General Public License as published by |
9 | * under the terms of the GNU General Public License as published by the Free |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | * Software Foundation; either version 2 of the License, or (at your option) |
11 | * (at your option) any later version. |
11 | * 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, but |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
16 | * GNU General Public License for more details. |
16 | * 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 GNU General Public License along |
19 | * along with this program; if not, write to the Free Software |
19 | * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
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 <crossfire@schmorp.de> |
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> |
… | |
… | |
232 | int tval = 0, formula = 0; |
232 | int tval = 0, formula = 0; |
233 | |
233 | |
234 | while (tmp) |
234 | while (tmp) |
235 | { |
235 | { |
236 | tval = 0; |
236 | tval = 0; |
237 | strcpy (name, tmp->name); |
237 | assign (name, tmp->name); |
238 | if (tmp->title) |
238 | if (tmp->title) |
239 | sprintf (name, "%s %s", &tmp->name, &tmp->title); |
239 | sprintf (name, "%s %s", &tmp->name, &tmp->title); |
240 | tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1)); |
240 | tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1)); |
241 | #ifdef ALCHEMY_DEBUG |
241 | #ifdef ALCHEMY_DEBUG |
242 | 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); |
… | |
… | |
292 | /* 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 */ |
293 | int batches = abs (nbatches); |
293 | int batches = abs (nbatches); |
294 | |
294 | |
295 | |
295 | |
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->archname) |
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 | |
… | |
… | |
310 | { |
310 | { |
311 | object *tmp; |
311 | object *tmp; |
312 | |
312 | |
313 | for (tmp = caster->inv; tmp; 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 | |
319 | if (!tmp) |
319 | if (!tmp) |
320 | { /* failure--no code found */ |
320 | { /* failure--no code found */ |
… | |
… | |
448 | { |
448 | { |
449 | size_t i; |
449 | size_t i; |
450 | |
450 | |
451 | for (i = 0; i < rp->arch_names; i++) |
451 | for (i = 0; i < rp->arch_names; i++) |
452 | { |
452 | { |
453 | if (strcmp (item->arch->name, rp->arch_name[i]) == 0) |
453 | if (item->arch->archname == rp->arch_name[i]) |
454 | { |
454 | { |
455 | *rp_arch_index = i; |
455 | *rp_arch_index = i; |
456 | break; |
456 | break; |
457 | } |
457 | } |
458 | } |
458 | } |
|
|
459 | |
459 | if (i < rp->arch_names) |
460 | if (i < rp->arch_names) |
460 | break; |
461 | break; |
461 | } |
462 | } |
462 | |
463 | |
463 | /* 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 |
… | |
… | |
510 | |
511 | |
511 | if (rndm (0, 2)) |
512 | if (rndm (0, 2)) |
512 | { /* slag created */ |
513 | { /* slag created */ |
513 | object *tmp = cauldron->inv; |
514 | object *tmp = cauldron->inv; |
514 | int weight = 0; |
515 | int weight = 0; |
515 | uint16 material = M_STONE; |
|
|
516 | |
516 | |
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"); |
517 | tmp = get_archetype ("rock"); |
525 | tmp->weight = weight; |
518 | tmp->weight = weight; |
526 | tmp->value = 0; |
519 | tmp->value = 0; |
527 | tmp->material = material; |
|
|
528 | tmp->materialname = "stone"; |
520 | tmp->materialname = "stone"; |
529 | tmp->name = "slag"; |
521 | tmp->name = "slag"; |
530 | tmp->name_pl = "slags"; |
522 | tmp->name_pl = "slags"; |
531 | item = insert_ob_in_ob (tmp, cauldron); |
523 | item = insert_ob_in_ob (tmp, cauldron); |
532 | CLEAR_FLAG (tmp, FLAG_CAN_ROLL); |
524 | CLEAR_FLAG (tmp, FLAG_CAN_ROLL); |
533 | CLEAR_FLAG (tmp, FLAG_NO_PICK); |
525 | CLEAR_FLAG (tmp, FLAG_NO_PICK); |
534 | tmp->move_block = 0; |
526 | tmp->move_block = 0; |
535 | } |
527 | } |
|
|
528 | |
536 | remove_contents (cauldron->inv, item); |
529 | remove_contents (cauldron->inv, item); |
537 | 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 ()); |
538 | return; |
531 | return; |
539 | } |
532 | } |
540 | else if (level < 40) |
533 | else if (level < 40) |
… | |
… | |
657 | object *tmp = get_random_mon (level / 5); |
650 | object *tmp = get_random_mon (level / 5); |
658 | |
651 | |
659 | remove_contents (cauldron->inv, NULL); |
652 | remove_contents (cauldron->inv, NULL); |
660 | if (!tmp) |
653 | if (!tmp) |
661 | alchemy_failure_effect (op, cauldron, rp, level); |
654 | alchemy_failure_effect (op, cauldron, rp, level); |
662 | else if (summon_hostile_monsters (cauldron, random_roll (1, 10, op, PREFER_LOW), tmp->arch->name)) |
655 | 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 ()); |
656 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s %s and then pours forth monsters!", &cauldron->name, cauldron_sound ()); |
664 | return; |
657 | return; |
665 | |
658 | |
666 | } |
659 | } |
667 | else if (level < 150) |
660 | else if (level < 150) |
… | |
… | |
737 | tmp->destroy (); |
730 | tmp->destroy (); |
738 | tmp = next; |
731 | tmp = next; |
739 | } |
732 | } |
740 | } |
733 | } |
741 | |
734 | |
742 | /**
|
735 | /** |
743 | *"Danger" level, will determine how bad the backfire |
736 | *"Danger" level, will determine how bad the backfire |
744 | * 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 |
745 | * 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, |
746 | * 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 |
747 | * mixing device (aka "cauldron"). Higher values of 'danger' indicate more |
740 | * 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 |
741 | * 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) |
742 | * skill *before* this routine is called. (no longer auto-readies that skill) |
750 | * -b.t. |
743 | * -b.t. |
751 | */ |
744 | */ |
752 | |
|
|
753 | int |
745 | int |
754 | calc_alch_danger (object *caster, object *cauldron, recipe *rp) |
746 | calc_alch_danger (object *caster, object *cauldron, recipe *rp) |
755 | { |
747 | { |
756 | object *item; |
748 | object *item; |
757 | char name[MAX_BUF]; |
749 | char name[MAX_BUF]; |
758 | int danger = 0, nrofi = 0; |
750 | int danger = 0, nrofi = 0; |
759 | |
751 | |
760 | /* Knowing alchemy skill reduces yer risk */ |
752 | /* Knowing alchemy skill reduces yer risk */ |
761 | 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 ()); |
762 | |
758 | |
763 | /* better cauldrons reduce risk */ |
759 | /* better cauldrons reduce risk */ |
764 | danger -= cauldron->magic; |
760 | danger -= cauldron->magic; |
765 | |
761 | |
766 | /* Higher Int, lower the risk */ |
762 | /* Higher Int, lower the risk */ |
… | |
… | |
770 | * Thus the backfire is worse. Also, more ingredients |
766 | * Thus the backfire is worse. Also, more ingredients |
771 | * means we are attempting a more powerfull potion, |
767 | * means we are attempting a more powerfull potion, |
772 | * and thus the backfire will be worse. */ |
768 | * and thus the backfire will be worse. */ |
773 | for (item = cauldron->inv; item; item = item->below) |
769 | for (item = cauldron->inv; item; item = item->below) |
774 | { |
770 | { |
775 | strcpy (name, item->name); |
771 | assign (name, item->name); |
776 | if (item->title) |
772 | if (item->title) |
777 | sprintf (name, "%s %s", &item->name, &item->title); |
773 | sprintf (name, "%s %s", &item->name, &item->title); |
778 | danger += (strtoint (name) / 1000) + 3; |
774 | danger += (strtoint (name) / 1000) + 3; |
779 | nrofi++; |
775 | nrofi++; |
780 | } |
776 | } |
|
|
777 | |
781 | if (rp == NULL) |
778 | if (rp == NULL) |
782 | danger += 110; |
779 | danger += 110; |
783 | else |
780 | else |
784 | danger += rp->diff * 3; |
781 | danger += rp->diff * 3; |
785 | |
782 | |
… | |
… | |
794 | #endif |
791 | #endif |
795 | |
792 | |
796 | return danger; |
793 | return danger; |
797 | } |
794 | } |
798 | |
795 | |
799 | /**
|
796 | /** |
800 | * Determines if ingredients in a container match the |
797 | * Determines if ingredients in a container match the |
801 | * proper ingredients for a recipe. |
798 | * proper ingredients for a recipe. |
802 | * |
799 | * |
803 | * rp is the recipe to check |
800 | * rp is the recipe to check |
804 | * cauldron is the container that holds the ingredients |
801 | * cauldron is the container that holds the ingredients |
… | |
… | |
908 | LOG (llevDebug, "looking for formula %d:\n", formula); |
905 | LOG (llevDebug, "looking for formula %d:\n", formula); |
909 | #endif |
906 | #endif |
910 | result = NULL; |
907 | result = NULL; |
911 | recipes_matching = 0; |
908 | recipes_matching = 0; |
912 | transmute_found = 0; |
909 | transmute_found = 0; |
|
|
910 | |
913 | for (rp = fl->items; rp != NULL; rp = rp->next) |
911 | for (rp = fl->items; rp; rp = rp->next) |
914 | { |
912 | { |
915 | /* check if recipe matches at all */ |
913 | /* check if recipe matches at all */ |
916 | if (formula % rp->index != 0) |
914 | if (formula % rp->index != 0) |
917 | { |
915 | { |
918 | #ifdef EXTREME_ALCHEMY_DEBUG |
916 | #ifdef EXTREME_ALCHEMY_DEBUG |