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) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
5 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
6 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
7 | |
7 | * |
8 | 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 |
9 | 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 |
10 | the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation; either version 2 of the License, or |
11 | (at your option) any later version. |
11 | * (at your option) 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, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
16 | * GNU General Public License 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 |
19 | along with this program; if not, write to the Free Software |
19 | * along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 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 at <crossfire@schmorp.de> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | #define ALLOWED_COMBINATION |
25 | #define ALLOWED_COMBINATION |
26 | |
26 | |
27 | /* TREASURE_DEBUG does some checking on the treasurelists after loading. |
27 | /* TREASURE_DEBUG does some checking on the treasurelists after loading. |
28 | * It is useful for finding bugs in the treasures file. Since it only |
28 | * It is useful for finding bugs in the treasures file. Since it only |
… | |
… | |
331 | void |
331 | void |
332 | create_all_treasures (treasure *t, object *op, int flag, int difficulty, int tries) |
332 | create_all_treasures (treasure *t, object *op, int flag, int difficulty, int tries) |
333 | { |
333 | { |
334 | object *tmp; |
334 | object *tmp; |
335 | |
335 | |
336 | if ((int) t->chance >= 100 || (RANDOM () % 100 + 1) < (int) t->chance) |
336 | if ((int) t->chance >= 100 || (rndm (100) + 1) < (int) t->chance) |
337 | { |
337 | { |
338 | if (t->name) |
338 | if (t->name) |
339 | { |
339 | { |
340 | if (difficulty >= t->magic) |
340 | if (difficulty >= t->magic) |
341 | { |
341 | { |
… | |
… | |
570 | scaled_diff = 0; |
570 | scaled_diff = 0; |
571 | |
571 | |
572 | if (scaled_diff >= DIFFLEVELS) |
572 | if (scaled_diff >= DIFFLEVELS) |
573 | scaled_diff = DIFFLEVELS - 1; |
573 | scaled_diff = DIFFLEVELS - 1; |
574 | |
574 | |
575 | percent = RANDOM () % 100; |
575 | percent = rndm (100); |
576 | |
576 | |
577 | for (magic = 0; magic < (MAXMAGIC + 1); magic++) |
577 | for (magic = 0; magic < (MAXMAGIC + 1); magic++) |
578 | { |
578 | { |
579 | percent -= difftomagic_list[scaled_diff][magic]; |
579 | percent -= difftomagic_list[scaled_diff][magic]; |
580 | |
580 | |
… | |
… | |
586 | { |
586 | { |
587 | LOG (llevError, "Warning, table for difficulty (scaled %d) %d bad.\n", scaled_diff, difficulty); |
587 | LOG (llevError, "Warning, table for difficulty (scaled %d) %d bad.\n", scaled_diff, difficulty); |
588 | magic = 0; |
588 | magic = 0; |
589 | } |
589 | } |
590 | |
590 | |
591 | magic = (RANDOM () % 3) ? magic : -magic; |
591 | magic = (rndm (3)) ? magic : -magic; |
592 | /* LOG(llevDebug, "Chose magic %d for difficulty (scaled %d) %d\n", magic, scaled_diff, difficulty); */ |
592 | /* LOG(llevDebug, "Chose magic %d for difficulty (scaled %d) %d\n", magic, scaled_diff, difficulty); */ |
593 | |
593 | |
594 | return magic; |
594 | return magic; |
595 | } |
595 | } |
596 | |
596 | |
… | |
… | |
611 | if (op->arch) |
611 | if (op->arch) |
612 | { |
612 | { |
613 | if (op->type == ARMOUR) |
613 | if (op->type == ARMOUR) |
614 | ARMOUR_SPEED (op) = (ARMOUR_SPEED (&op->arch->clone) * (100 + magic * 10)) / 100; |
614 | ARMOUR_SPEED (op) = (ARMOUR_SPEED (&op->arch->clone) * (100 + magic * 10)) / 100; |
615 | |
615 | |
616 | if (magic < 0 && !(RANDOM () % 3)) /* You can't just check the weight always */ |
616 | if (magic < 0 && !(rndm (3))) /* You can't just check the weight always */ |
617 | magic = (-magic); |
617 | magic = (-magic); |
618 | op->weight = (op->arch->clone.weight * (100 - magic * 10)) / 100; |
618 | op->weight = (op->arch->clone.weight * (100 - magic * 10)) / 100; |
619 | } |
619 | } |
620 | else |
620 | else |
621 | { |
621 | { |
622 | if (op->type == ARMOUR) |
622 | if (op->type == ARMOUR) |
623 | ARMOUR_SPEED (op) = (ARMOUR_SPEED (op) * (100 + magic * 10)) / 100; |
623 | ARMOUR_SPEED (op) = (ARMOUR_SPEED (op) * (100 + magic * 10)) / 100; |
624 | if (magic < 0 && !(RANDOM () % 3)) /* You can't just check the weight always */ |
624 | if (magic < 0 && !(rndm (3))) /* You can't just check the weight always */ |
625 | magic = (-magic); |
625 | magic = (-magic); |
626 | op->weight = (op->weight * (100 - magic * 10)) / 100; |
626 | op->weight = (op->weight * (100 - magic * 10)) / 100; |
627 | } |
627 | } |
628 | } |
628 | } |
629 | |
629 | |
… | |
… | |
662 | |
662 | |
663 | int r = RANDOM () % (bonus > 0 ? 25 : 11); |
663 | int r = RANDOM () % (bonus > 0 ? 25 : 11); |
664 | |
664 | |
665 | if (op->type == AMULET) |
665 | if (op->type == AMULET) |
666 | { |
666 | { |
667 | if (!(RANDOM () % 21)) |
667 | if (!(rndm (21))) |
668 | r = 20 + RANDOM () % 2; |
668 | r = 20 + rndm (2); |
669 | else |
669 | else |
670 | { |
670 | { |
671 | if (RANDOM () & 2) |
671 | if (RANDOM () & 2) |
672 | r = 10; |
672 | r = 10; |
673 | else |
673 | else |
674 | r = 11 + RANDOM () % 9; |
674 | r = 11 + rndm (9); |
675 | } |
675 | } |
676 | } |
676 | } |
677 | |
677 | |
678 | switch (r) |
678 | switch (r) |
679 | { |
679 | { |
… | |
… | |
716 | case 16: |
716 | case 16: |
717 | case 17: |
717 | case 17: |
718 | case 18: |
718 | case 18: |
719 | case 19: |
719 | case 19: |
720 | { |
720 | { |
721 | int b = 5 + FABS (bonus), val, resist = RANDOM () % num_resist_table; |
721 | int b = 5 + abs (bonus), val, resist = rndm (num_resist_table); |
722 | |
722 | |
723 | /* Roughly generate a bonus between 100 and 35 (depending on the bonus) */ |
723 | /* Roughly generate a bonus between 100 and 35 (depending on the bonus) */ |
724 | val = 10 + RANDOM () % b + RANDOM () % b + RANDOM () % b + RANDOM () % b; |
724 | val = 10 + rndm (b) + rndm (b) + rndm (b) + rndm (b); |
725 | |
725 | |
726 | /* Cursed items need to have higher negative values to equal out with |
726 | /* Cursed items need to have higher negative values to equal out with |
727 | * positive values for how protections work out. Put another |
727 | * positive values for how protections work out. Put another |
728 | * little random element in since that they don't always end up with |
728 | * little random element in since that they don't always end up with |
729 | * even values. |
729 | * even values. |
… | |
… | |
731 | if (bonus < 0) |
731 | if (bonus < 0) |
732 | val = 2 * -val - RANDOM () % b; |
732 | val = 2 * -val - RANDOM () % b; |
733 | if (val > 35) |
733 | if (val > 35) |
734 | val = 35; /* Upper limit */ |
734 | val = 35; /* Upper limit */ |
735 | b = 0; |
735 | b = 0; |
|
|
736 | |
736 | while (op->resist[resist_table[resist]] != 0 && b < 4) |
737 | while (op->resist[resist_table[resist]] != 0 && b < 4) |
737 | { |
|
|
738 | resist = RANDOM () % num_resist_table; |
738 | resist = rndm (num_resist_table); |
739 | } |
739 | |
740 | if (b == 4) |
740 | if (b == 4) |
741 | return; /* Not able to find a free resistance */ |
741 | return; /* Not able to find a free resistance */ |
|
|
742 | |
742 | op->resist[resist_table[resist]] = val; |
743 | op->resist[resist_table[resist]] = val; |
743 | /* We should probably do something more clever here to adjust value |
744 | /* We should probably do something more clever here to adjust value |
744 | * based on how good a resistance we gave. |
745 | * based on how good a resistance we gave. |
745 | */ |
746 | */ |
746 | break; |
747 | break; |
… | |
… | |
774 | case 22: |
775 | case 22: |
775 | op->stats.exp += bonus; /* Speed! */ |
776 | op->stats.exp += bonus; /* Speed! */ |
776 | op->value = (op->value * 2) / 3; |
777 | op->value = (op->value * 2) / 3; |
777 | break; |
778 | break; |
778 | } |
779 | } |
|
|
780 | |
779 | if (bonus > 0) |
781 | if (bonus > 0) |
780 | op->value *= 2 * bonus; |
782 | op->value *= 2 * bonus; |
781 | else |
783 | else |
782 | op->value = -(op->value * 2 * bonus) / 3; |
784 | op->value = -(op->value * 2 * bonus) / 3; |
783 | } |
785 | } |
… | |
… | |
803 | return i; |
805 | return i; |
804 | return 4; |
806 | return 4; |
805 | } |
807 | } |
806 | |
808 | |
807 | #define DICE2 (get_magic(2)==2?2:1) |
809 | #define DICE2 (get_magic(2)==2?2:1) |
808 | #define DICESPELL (RANDOM()%3+RANDOM()%3+RANDOM()%3+RANDOM()%3+RANDOM()%3) |
810 | #define DICESPELL (rndm (3)+RANDOM()%3+RANDOM()%3+RANDOM()%3+RANDOM()%3) |
809 | |
811 | |
810 | /* |
812 | /* |
811 | * fix_generated_item(): This is called after an item is generated, in |
813 | * fix_generated_item(): This is called after an item is generated, in |
812 | * order to set it up right. This produced magical bonuses, puts spells |
814 | * order to set it up right. This produced magical bonuses, puts spells |
813 | * into scrolls/books/wands, makes it unidentified, hides the value, etc. |
815 | * into scrolls/books/wands, makes it unidentified, hides the value, etc. |
… | |
… | |
942 | case WEAPON: |
944 | case WEAPON: |
943 | case ARMOUR: |
945 | case ARMOUR: |
944 | case SHIELD: |
946 | case SHIELD: |
945 | case HELMET: |
947 | case HELMET: |
946 | case CLOAK: |
948 | case CLOAK: |
947 | if (QUERY_FLAG (op, FLAG_CURSED) && !(RANDOM () % 4)) |
949 | if (QUERY_FLAG (op, FLAG_CURSED) && !(rndm (4))) |
948 | set_ring_bonus (op, -DICE2); |
950 | set_ring_bonus (op, -DICE2); |
949 | break; |
951 | break; |
950 | |
952 | |
951 | case BRACERS: |
953 | case BRACERS: |
952 | if (!(RANDOM () % (QUERY_FLAG (op, FLAG_CURSED) ? 5 : 20))) |
954 | if (!(RANDOM () % (QUERY_FLAG (op, FLAG_CURSED) ? 5 : 20))) |
… | |
… | |
991 | { |
993 | { |
992 | op->name = "potion"; |
994 | op->name = "potion"; |
993 | op->name_pl = "potions"; |
995 | op->name_pl = "potions"; |
994 | } |
996 | } |
995 | |
997 | |
996 | if (!(flags & GT_ONLY_GOOD) && RANDOM () % 2) |
998 | if (!(flags & GT_ONLY_GOOD) && rndm (2)) |
997 | SET_FLAG (op, FLAG_CURSED); |
999 | SET_FLAG (op, FLAG_CURSED); |
998 | break; |
1000 | break; |
999 | } |
1001 | } |
1000 | |
1002 | |
1001 | case AMULET: |
1003 | case AMULET: |
… | |
… | |
1011 | } |
1013 | } |
1012 | |
1014 | |
1013 | if (op->arch != ring_arch && op->arch != amulet_arch) /* It's a special artifact! */ |
1015 | if (op->arch != ring_arch && op->arch != amulet_arch) /* It's a special artifact! */ |
1014 | break; |
1016 | break; |
1015 | |
1017 | |
1016 | if (!(flags & GT_ONLY_GOOD) && !(RANDOM () % 3)) |
1018 | if (!(flags & GT_ONLY_GOOD) && !(rndm (3))) |
1017 | SET_FLAG (op, FLAG_CURSED); |
1019 | SET_FLAG (op, FLAG_CURSED); |
1018 | |
1020 | |
1019 | set_ring_bonus (op, QUERY_FLAG (op, FLAG_CURSED) ? -DICE2 : DICE2); |
1021 | set_ring_bonus (op, QUERY_FLAG (op, FLAG_CURSED) ? -DICE2 : DICE2); |
1020 | |
1022 | |
1021 | if (op->type != RING) /* Amulets have only one ability */ |
1023 | if (op->type != RING) /* Amulets have only one ability */ |
1022 | break; |
1024 | break; |
1023 | |
1025 | |
1024 | if (!(RANDOM () % 4)) |
1026 | if (!(rndm (4))) |
1025 | { |
1027 | { |
1026 | int d = (RANDOM () % 2 || QUERY_FLAG (op, FLAG_CURSED)) ? -DICE2 : DICE2; |
1028 | int d = (rndm (2) || QUERY_FLAG (op, FLAG_CURSED)) ? -DICE2 : DICE2; |
1027 | |
1029 | |
1028 | if (d > 0) |
1030 | if (d > 0) |
1029 | op->value *= 3; |
1031 | op->value *= 3; |
1030 | |
1032 | |
1031 | set_ring_bonus (op, d); |
1033 | set_ring_bonus (op, d); |
1032 | |
1034 | |
1033 | if (!(RANDOM () % 4)) |
1035 | if (!(rndm (4))) |
1034 | { |
1036 | { |
1035 | int d = (RANDOM () % 3 || QUERY_FLAG (op, FLAG_CURSED)) ? -DICE2 : DICE2; |
1037 | int d = (rndm (3) || QUERY_FLAG (op, FLAG_CURSED)) ? -DICE2 : DICE2; |
1036 | |
1038 | |
1037 | if (d > 0) |
1039 | if (d > 0) |
1038 | op->value *= 5; |
1040 | op->value *= 5; |
1039 | set_ring_bonus (op, d); |
1041 | set_ring_bonus (op, d); |
1040 | } |
1042 | } |
… | |
… | |
1048 | case BOOK: |
1050 | case BOOK: |
1049 | /* Is it an empty book?, if yes lets make a special· |
1051 | /* Is it an empty book?, if yes lets make a special· |
1050 | * msg for it, and tailor its properties based on the· |
1052 | * msg for it, and tailor its properties based on the· |
1051 | * creator and/or map level we found it on. |
1053 | * creator and/or map level we found it on. |
1052 | */ |
1054 | */ |
1053 | if (!op->msg && RANDOM () % 10) |
1055 | if (!op->msg && rndm (10)) |
1054 | { |
1056 | { |
1055 | /* set the book level properly */ |
1057 | /* set the book level properly */ |
1056 | if (creator->level == 0 || QUERY_FLAG (creator, FLAG_ALIVE)) |
1058 | if (creator->level == 0 || QUERY_FLAG (creator, FLAG_ALIVE)) |
1057 | { |
1059 | { |
1058 | if (op->map && op->map->difficulty) |
1060 | if (op->map && op->map->difficulty) |
1059 | op->level = RANDOM () % (op->map->difficulty) + RANDOM () % 10 + 1; |
1061 | op->level = RANDOM () % (op->map->difficulty) + rndm (10) + 1; |
1060 | else |
1062 | else |
1061 | op->level = RANDOM () % 20 + 1; |
1063 | op->level = rndm (20) + 1; |
1062 | } |
1064 | } |
1063 | else |
1065 | else |
1064 | op->level = RANDOM () % creator->level; |
1066 | op->level = RANDOM () % creator->level; |
1065 | |
1067 | |
1066 | tailor_readable_ob (op, (creator && creator->stats.sp) ? creator->stats.sp : -1); |
1068 | tailor_readable_ob (op, (creator && creator->stats.sp) ? creator->stats.sp : -1); |