ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/treasure.C
(Generate patch)

Comparing deliantra/server/common/treasure.C (file contents):
Revision 1.30 by elmex, Wed Jan 3 02:30:51 2007 UTC vs.
Revision 1.34 by root, Sat Jan 20 22:09:51 2007 UTC

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#define ALLOWED_COMBINATION 25#define ALLOWED_COMBINATION
25 26
26/* TREASURE_DEBUG does some checking on the treasurelists after loading. 27/* TREASURE_DEBUG does some checking on the treasurelists after loading.
27 * 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
330void 331void
331create_all_treasures (treasure *t, object *op, int flag, int difficulty, int tries) 332create_all_treasures (treasure *t, object *op, int flag, int difficulty, int tries)
332{ 333{
333 object *tmp; 334 object *tmp;
334 335
335 if ((int) t->chance >= 100 || (RANDOM () % 100 + 1) < (int) t->chance) 336 if ((int) t->chance >= 100 || (rndm (100) + 1) < (int) t->chance)
336 { 337 {
337 if (t->name) 338 if (t->name)
338 { 339 {
339 if (difficulty >= t->magic) 340 if (difficulty >= t->magic)
340 { 341 {
569 scaled_diff = 0; 570 scaled_diff = 0;
570 571
571 if (scaled_diff >= DIFFLEVELS) 572 if (scaled_diff >= DIFFLEVELS)
572 scaled_diff = DIFFLEVELS - 1; 573 scaled_diff = DIFFLEVELS - 1;
573 574
574 percent = RANDOM () % 100; 575 percent = rndm (100);
575 576
576 for (magic = 0; magic < (MAXMAGIC + 1); magic++) 577 for (magic = 0; magic < (MAXMAGIC + 1); magic++)
577 { 578 {
578 percent -= difftomagic_list[scaled_diff][magic]; 579 percent -= difftomagic_list[scaled_diff][magic];
579 580
585 { 586 {
586 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);
587 magic = 0; 588 magic = 0;
588 } 589 }
589 590
590 magic = (RANDOM () % 3) ? magic : -magic; 591 magic = (rndm (3)) ? magic : -magic;
591 /* 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); */
592 593
593 return magic; 594 return magic;
594} 595}
595 596
610 if (op->arch) 611 if (op->arch)
611 { 612 {
612 if (op->type == ARMOUR) 613 if (op->type == ARMOUR)
613 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;
614 615
615 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 */
616 magic = (-magic); 617 magic = (-magic);
617 op->weight = (op->arch->clone.weight * (100 - magic * 10)) / 100; 618 op->weight = (op->arch->clone.weight * (100 - magic * 10)) / 100;
618 } 619 }
619 else 620 else
620 { 621 {
621 if (op->type == ARMOUR) 622 if (op->type == ARMOUR)
622 ARMOUR_SPEED (op) = (ARMOUR_SPEED (op) * (100 + magic * 10)) / 100; 623 ARMOUR_SPEED (op) = (ARMOUR_SPEED (op) * (100 + magic * 10)) / 100;
623 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 */
624 magic = (-magic); 625 magic = (-magic);
625 op->weight = (op->weight * (100 - magic * 10)) / 100; 626 op->weight = (op->weight * (100 - magic * 10)) / 100;
626 } 627 }
627} 628}
628 629
661 662
662 int r = RANDOM () % (bonus > 0 ? 25 : 11); 663 int r = RANDOM () % (bonus > 0 ? 25 : 11);
663 664
664 if (op->type == AMULET) 665 if (op->type == AMULET)
665 { 666 {
666 if (!(RANDOM () % 21)) 667 if (!(rndm (21)))
667 r = 20 + RANDOM () % 2; 668 r = 20 + rndm (2);
668 else 669 else
669 { 670 {
670 if (RANDOM () & 2) 671 if (RANDOM () & 2)
671 r = 10; 672 r = 10;
672 else 673 else
673 r = 11 + RANDOM () % 9; 674 r = 11 + rndm (9);
674 } 675 }
675 } 676 }
676 677
677 switch (r) 678 switch (r)
678 { 679 {
715 case 16: 716 case 16:
716 case 17: 717 case 17:
717 case 18: 718 case 18:
718 case 19: 719 case 19:
719 { 720 {
720 int b = 5 + FABS (bonus), val, resist = RANDOM () % num_resist_table; 721 int b = 5 + abs (bonus), val, resist = rndm (num_resist_table);
721 722
722 /* 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) */
723 val = 10 + RANDOM () % b + RANDOM () % b + RANDOM () % b + RANDOM () % b; 724 val = 10 + rndm (b) + rndm (b) + rndm (b) + rndm (b);
724 725
725 /* 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
726 * positive values for how protections work out. Put another 727 * positive values for how protections work out. Put another
727 * 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
728 * even values. 729 * even values.
730 if (bonus < 0) 731 if (bonus < 0)
731 val = 2 * -val - RANDOM () % b; 732 val = 2 * -val - RANDOM () % b;
732 if (val > 35) 733 if (val > 35)
733 val = 35; /* Upper limit */ 734 val = 35; /* Upper limit */
734 b = 0; 735 b = 0;
736
735 while (op->resist[resist_table[resist]] != 0 && b < 4) 737 while (op->resist[resist_table[resist]] != 0 && b < 4)
736 {
737 resist = RANDOM () % num_resist_table; 738 resist = rndm (num_resist_table);
738 } 739
739 if (b == 4) 740 if (b == 4)
740 return; /* Not able to find a free resistance */ 741 return; /* Not able to find a free resistance */
742
741 op->resist[resist_table[resist]] = val; 743 op->resist[resist_table[resist]] = val;
742 /* We should probably do something more clever here to adjust value 744 /* We should probably do something more clever here to adjust value
743 * based on how good a resistance we gave. 745 * based on how good a resistance we gave.
744 */ 746 */
745 break; 747 break;
773 case 22: 775 case 22:
774 op->stats.exp += bonus; /* Speed! */ 776 op->stats.exp += bonus; /* Speed! */
775 op->value = (op->value * 2) / 3; 777 op->value = (op->value * 2) / 3;
776 break; 778 break;
777 } 779 }
780
778 if (bonus > 0) 781 if (bonus > 0)
779 op->value *= 2 * bonus; 782 op->value *= 2 * bonus;
780 else 783 else
781 op->value = -(op->value * 2 * bonus) / 3; 784 op->value = -(op->value * 2 * bonus) / 3;
782} 785}
802 return i; 805 return i;
803 return 4; 806 return 4;
804} 807}
805 808
806#define DICE2 (get_magic(2)==2?2:1) 809#define DICE2 (get_magic(2)==2?2:1)
807#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)
808 811
809/* 812/*
810 * 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
811 * 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
812 * into scrolls/books/wands, makes it unidentified, hides the value, etc. 815 * into scrolls/books/wands, makes it unidentified, hides the value, etc.
941 case WEAPON: 944 case WEAPON:
942 case ARMOUR: 945 case ARMOUR:
943 case SHIELD: 946 case SHIELD:
944 case HELMET: 947 case HELMET:
945 case CLOAK: 948 case CLOAK:
946 if (QUERY_FLAG (op, FLAG_CURSED) && !(RANDOM () % 4)) 949 if (QUERY_FLAG (op, FLAG_CURSED) && !(rndm (4)))
947 set_ring_bonus (op, -DICE2); 950 set_ring_bonus (op, -DICE2);
948 break; 951 break;
949 952
950 case BRACERS: 953 case BRACERS:
951 if (!(RANDOM () % (QUERY_FLAG (op, FLAG_CURSED) ? 5 : 20))) 954 if (!(RANDOM () % (QUERY_FLAG (op, FLAG_CURSED) ? 5 : 20)))
990 { 993 {
991 op->name = "potion"; 994 op->name = "potion";
992 op->name_pl = "potions"; 995 op->name_pl = "potions";
993 } 996 }
994 997
995 if (!(flags & GT_ONLY_GOOD) && RANDOM () % 2) 998 if (!(flags & GT_ONLY_GOOD) && rndm (2))
996 SET_FLAG (op, FLAG_CURSED); 999 SET_FLAG (op, FLAG_CURSED);
997 break; 1000 break;
998 } 1001 }
999 1002
1000 case AMULET: 1003 case AMULET:
1010 } 1013 }
1011 1014
1012 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! */
1013 break; 1016 break;
1014 1017
1015 if (!(flags & GT_ONLY_GOOD) && !(RANDOM () % 3)) 1018 if (!(flags & GT_ONLY_GOOD) && !(rndm (3)))
1016 SET_FLAG (op, FLAG_CURSED); 1019 SET_FLAG (op, FLAG_CURSED);
1017 1020
1018 set_ring_bonus (op, QUERY_FLAG (op, FLAG_CURSED) ? -DICE2 : DICE2); 1021 set_ring_bonus (op, QUERY_FLAG (op, FLAG_CURSED) ? -DICE2 : DICE2);
1019 1022
1020 if (op->type != RING) /* Amulets have only one ability */ 1023 if (op->type != RING) /* Amulets have only one ability */
1021 break; 1024 break;
1022 1025
1023 if (!(RANDOM () % 4)) 1026 if (!(rndm (4)))
1024 { 1027 {
1025 int d = (RANDOM () % 2 || QUERY_FLAG (op, FLAG_CURSED)) ? -DICE2 : DICE2; 1028 int d = (rndm (2) || QUERY_FLAG (op, FLAG_CURSED)) ? -DICE2 : DICE2;
1026 1029
1027 if (d > 0) 1030 if (d > 0)
1028 op->value *= 3; 1031 op->value *= 3;
1029 1032
1030 set_ring_bonus (op, d); 1033 set_ring_bonus (op, d);
1031 1034
1032 if (!(RANDOM () % 4)) 1035 if (!(rndm (4)))
1033 { 1036 {
1034 int d = (RANDOM () % 3 || QUERY_FLAG (op, FLAG_CURSED)) ? -DICE2 : DICE2; 1037 int d = (rndm (3) || QUERY_FLAG (op, FLAG_CURSED)) ? -DICE2 : DICE2;
1035 1038
1036 if (d > 0) 1039 if (d > 0)
1037 op->value *= 5; 1040 op->value *= 5;
1038 set_ring_bonus (op, d); 1041 set_ring_bonus (op, d);
1039 } 1042 }
1047 case BOOK: 1050 case BOOK:
1048 /* Is it an empty book?, if yes lets make a special· 1051 /* Is it an empty book?, if yes lets make a special·
1049 * msg for it, and tailor its properties based on the· 1052 * msg for it, and tailor its properties based on the·
1050 * creator and/or map level we found it on. 1053 * creator and/or map level we found it on.
1051 */ 1054 */
1052 if (!op->msg && RANDOM () % 10) 1055 if (!op->msg && rndm (10))
1053 { 1056 {
1054 /* set the book level properly */ 1057 /* set the book level properly */
1055 if (creator->level == 0 || QUERY_FLAG (creator, FLAG_ALIVE)) 1058 if (creator->level == 0 || QUERY_FLAG (creator, FLAG_ALIVE))
1056 { 1059 {
1057 if (op->map && op->map->difficulty) 1060 if (op->map && op->map->difficulty)
1058 op->level = RANDOM () % (op->map->difficulty) + RANDOM () % 10 + 1; 1061 op->level = RANDOM () % (op->map->difficulty) + rndm (10) + 1;
1059 else 1062 else
1060 op->level = RANDOM () % 20 + 1; 1063 op->level = rndm (20) + 1;
1061 } 1064 }
1062 else 1065 else
1063 op->level = RANDOM () % creator->level; 1066 op->level = RANDOM () % creator->level;
1064 1067
1065 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);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines