home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / d_d / caltech / inbound / gems.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-22  |  11.6 KB  |  332 lines

  1. /*    AD&D gem rolling program,
  2.  *        written August, 1992, by Ken Jenks, 
  3.  *        kjenks@gothamcity.jsc.nasa.gov
  4.  *
  5.  *    This program randomly determines the properties of non-magical
  6.  *      gems.
  7.  *
  8.  *    Compile and run with no command line options to see 'usage.'
  9.  */
  10.  
  11. #include <ctype.h>
  12. #include <math.h>
  13. #include <stdio.h>
  14.  
  15. static int
  16. bv_table[13][2] = {
  17.   { 25,     10.0},
  18.   { 50,     50.0},
  19.   { 70,    100.0},
  20.   { 90,    500.0},
  21.   { 99,   1000.0},
  22.   {100,   5000.0},
  23.   {  0,  10000.0},
  24.   {  0,  25000.0},
  25.   {  0,  50000.0},
  26.   {  0, 100000.0},
  27.   {  0, 250000.0},
  28.   {  0, 500000.0},
  29.   {  0,1000000.0}};
  30.  
  31. static float
  32. decreased_bv_table[6] = {5.0, 1.0, 0.5, 0.25, 0.05};
  33.  
  34. static char *
  35. descriptions[6] = {
  36.   "Ornamental Stones",        /*   10 */
  37.   "Semi-precious Stones",     /*   50 */
  38.   "Fancy Stones",             /*  100 */
  39.   "Fancy Stones (Precious)",  /*  500 */
  40.   "Gem Stones",               /* 1000 */
  41.   "Gem Stones (Jewels)"};     /* 5000 */
  42.  
  43. static char *
  44. properties[6][14][3] = {
  45.  
  46.   {  /* Ornamental Stones, base value 10 GP */
  47. /* 1*/    {"azurite","opaque","mottled deep blue"},
  48. /* 2*/    {"banded agate","transparent","striped brown and blue and white and reddish"},
  49. /* 3*/    {"blue quartz","transparent","pale blue"},
  50. /* 4*/    {"eye agate","transluscent","circles of gray, white, brown, blue and/or green"},
  51. /* 5*/    {"hematite","opaque","gray-black"},
  52. /* 6*/    {"lapis lazuli","opaque","light and dark blue with yellow flecks"},
  53. /* 7*/    {"malachite","opaque","striated light and dark green"},
  54. /* 8*/    {"moss agate","transluscent","pink or white with grayish or greenish 'moss markings'"},
  55. /* 9*/    {"obsidian","opaque","black"},
  56. /*10*/    {"rhodochrosite","opaque","light pink"},
  57. /*11*/    {"tiger eye","transluscent","rich brown with golden center under-hue"},
  58. /*12*/    {"turquiose","opaque","light blue-green"},
  59. /*13*/    {"","",""},
  60. /*14*/    {"","",""}},
  61.  
  62.   {  /* Semi-precious Stones, base value 50 GP */
  63. /* 1*/    {"amber","opaque","watery gold to rich gold"},
  64. /* 2*/    {"carnelian","opaque","orange to reddish brown (also called Sard)"},
  65. /* 3*/    {"chalcedony","opaque","white"},
  66. /* 4*/    {"chrysoprase","transluscent","apple green to emerald green"},
  67. /* 5*/    {"citrine","transparent","pale yellow brown"},
  68. /* 6*/    {"jasper","opaque","blue, black to brown"},
  69. /* 7*/    {"moonstone","transluscent","white with pale blue glow"},
  70. /* 8*/    {"onyx","opaque","bands of black and white or pure black and white"},
  71. /* 9*/    {"rock crystal","transparent","clear"},
  72. /*10*/    {"sardonyx","opaque","bands of sard (red) and onyx (white) or sard"},
  73. /*11*/    {"smoky quartz","transparent","gray, yellow, or blue (Cairngorm), all light"},
  74. /*12*/    {"star rose quartz","transluscent","rosy stone with white 'star' center"},
  75. /*13*/    {"zircon","transparent","clear pale blue-green"},
  76. /*14*/    {"","",""}},
  77.  
  78.   {  /* Fancy Stones, base value 100 GP */
  79. /* 1*/    {"amber","transparent","watery gold to rich gold"},
  80. /* 2*/    {"alexandrite","transparent","dark green"},
  81. /* 3*/    {"amethyst","transparent","deep purple"},
  82. /* 4*/    {"","",""},
  83. /* 5*/    {"chrysoberyl","transparent","yellow green to green"},
  84. /* 6*/    {"coral","opaque","crimson"},
  85. /* 7*/    {"garnet","transparent","red, brown-green, or violet (the most prized)"},
  86. /* 8*/    {"jade","translucent","light green, deep green, green and white, white"},
  87. /* 9*/    {"jet","opaque","deep black"},
  88. /*10*/    {"pearl","transparent","lustrous white, yellowish, pinkish, etc. to pure black (the most prized)"},
  89. /*11*/    {"","",""},
  90. /*12*/    {"spinel","transparent","red, red-brown, deep green, or very deep blue (the most prized)"},
  91. /*13*/    {"","",""},
  92. /*14*/    {"tourmaline","transparent","green pale, blue pale, brown pale, or reddish pale"}},
  93.  
  94.   {  /* Fancy Stones, base value 500 GP */
  95. /* 1*/    {"","",""},
  96. /* 2*/    {"","",""},
  97. /* 3*/    {"","",""},
  98. /* 4*/    {"aquamarine","transparent","pale blue green"},
  99. /* 5*/    {"","",""},
  100. /* 6*/    {"","",""},
  101. /* 7*/    {"garnet","transparent","red, brown-green, or violet (the most prized)"},
  102. /* 8*/    {"","",""},
  103. /* 9*/    {"","",""},
  104. /*10*/    {"pearl","opaque","lustrous white, yellowish, pinkish, etc. to pure black (the most prized)"},
  105. /*11*/    {"peridot","transparent","rich olive green (Chrysolite)"},
  106. /*12*/    {"spinel","transparent","red, red-brown, deep green, or very deep blue (the most prized)"},
  107. /*13*/    {"topaz","transparent","golden yellow"},
  108. /*14*/    {"","",""}},
  109.  
  110.   {  /* Gem Stones, base value 1000 GP */
  111. /* 1*/    {"black opal","translucent","dark green with black mottling and golden flakes"},
  112. /* 2*/    {"","",""},
  113. /* 3*/    {"","",""},
  114. /* 4*/    {"emerald","transparent","deep bright green"},
  115. /* 5*/    {"fire opal","translucent","fiery red"},
  116. /* 6*/    {"","",""},
  117. /* 7*/    {"opal","translucent","pale blue with green and golden mottling"},
  118. /* 8*/    {"oriental amethyst","transparent","rich purple (Corundum)"},
  119. /* 9*/    {"","",""},
  120. /*10*/    {"oriental topaz","transparent","fiery yellow (Corundum)"},
  121. /*11*/    {"","",""},
  122. /*12*/    {"sapphire","transparent","clear to medium blue (Corundum)"},
  123. /*13*/    {"star ruby","translucent","translucent ruby with white 'star' center"},
  124. /*14*/    {"star sapphire","translucent","translucent sapphire with white 'star' center"}},
  125.  
  126.   {  /* Gem Stones, base value 5000 GP */
  127. /* 1*/    {"black opal","translucent","dark green with black mottling and golden flakes"},
  128. /* 2*/    {"black sapphire","translucent","lustrous black with glowing highlights"},
  129. /* 3*/    {"diamond","transparent","clear blue-white with lesser stones clear whote or pale tints"},
  130. /* 4*/    {"emerald","transparent","deep bright green"},
  131. /* 5*/    {"fire opal","translucent","fiery red"},
  132. /* 6*/    {"jacinth","transparent","fiery orange (Corundum)"},
  133. /* 7*/    {"opal","translucent","pale blue with green and golden mottling"},
  134. /* 8*/    {"oriental amethyst","transparent","rich purple (Corundum)"},
  135. /* 9*/    {"oriental emerald","transparent","clear bright green (Corundum)"},
  136. /*10*/    {"oriental topaz","transparent","fiery yellow (Corundum)"},
  137. /*11*/    {"ruby","transparent","clear red to deep crimsom (Corundum)"},
  138. /*12*/    {"sapphire","transparent","clear to medium blue (Corundum)"},
  139. /*13*/    {"star ruby","translucent","translucent ruby with white 'star' center"},
  140. /*14*/    {"star sapphire","translucent","translucent sapphire with white 'star' center"}}
  141.   };
  142.  
  143. /************************************************************************
  144. * die_roll() - simple function to roll one die of the given size
  145. ************************************************************************/
  146.  
  147. int die_roll(size)
  148. int size;
  149. {
  150.    return ((rand() % size) + 1);
  151. }
  152.  
  153. /************************************************************************
  154. * random_gems() - randomly determine gems
  155. *
  156. ************************************************************************/
  157.  
  158. void
  159. random_gems(num_gems, base_value, outfile)
  160. int num_gems, base_value;
  161. FILE *outfile;
  162. {
  163.   int i;
  164.   float bv, total = 0;
  165.   int bv_die;
  166.   int orig_base_value_place, current_base_value_place;
  167.   int ignore_results_below_2 = 0;
  168.   int inc_or_dec_die;
  169.   int prop;
  170.  
  171.   fprintf(outfile,"%i gem%s, ",num_gems,
  172.     (num_gems!=1)?"s":"");
  173.  
  174.   if(base_value)
  175.     fprintf(outfile,"base value %i\n\n",base_value);
  176.   else
  177.     fprintf(outfile,"random base values\n\n");
  178.  
  179.   for (i=1; i<=num_gems; i++) {
  180.  
  181.     if(base_value) {
  182.       bv = base_value;
  183.       /* Calculate orig_base_value_place for later, since no gem may *
  184.        * increase more than 7 places beyond its original base value  */
  185.       orig_base_value_place=0;
  186.       while ((orig_base_value_place<12)
  187.         && (base_value > bv_table[orig_base_value_place][1]))
  188.         ++orig_base_value_place;
  189.       if(orig_base_value_place >= 6)
  190.         orig_base_value_place = 5;
  191.  
  192.     } else {
  193.       bv_die = die_roll(100);
  194.       orig_base_value_place=0;
  195.       while((orig_base_value_place<5)
  196.         && (bv_die >= bv_table[orig_base_value_place][0]))
  197.         orig_base_value_place++;
  198.  
  199.       bv = bv_table[orig_base_value_place][1];
  200. #ifdef DEBUG
  201.   fprintf(stderr,"Found bv=%f, base value place: %i\n",bv,orig_base_value_place);
  202. #endif;
  203.       /* Remember orig_base_value_place for later, since no gem may increase *
  204.        * more than 7 places beyond its original base value              */
  205.     }
  206.     current_base_value_place = orig_base_value_place;
  207.  
  208. #ifdef DEBUG
  209.   fprintf(stderr,"\nGem #%i, base value: %f\n\n",i,bv);
  210.   fprintf(stderr,"  Base value place: %i\n",orig_base_value_place);
  211.   fprintf(stderr,"  Calculating increase or decrease beyond base value...\n");
  212. #endif
  213.  
  214.     ignore_results_below_2 = 0; /* Later, if we roll a 10, we ignore 1's */
  215.  
  216. inc_or_dec:
  217.     inc_or_dec_die = die_roll(10);
  218.  
  219. #ifdef DEBUG
  220.   fprintf(stderr,"  Inc/Dec die: %i\n",inc_or_dec_die);
  221. #endif
  222.  
  223.     switch(inc_or_dec_die) {
  224.       case 1: if((current_base_value_place <= 12) 
  225.               && (current_base_value_place <= orig_base_value_place +6)
  226.               && !ignore_results_below_2)
  227.                 bv = bv_table[++current_base_value_place][1];
  228. #ifdef DEBUG
  229.   fprintf(stderr,"    Value increases one place to %f; roll again.\n",bv);
  230. #endif
  231.               goto inc_or_dec;
  232.  
  233.       case 2: bv = 2.0*bv;
  234. #ifdef DEBUG
  235.   fprintf(stderr,"    Value doubles to %f\n",bv);
  236. #endif
  237.               break;
  238.  
  239.       case 3: bv = bv * (1.0 + (((float) die_roll(6))/10.0));
  240. #ifdef DEBUG
  241.   fprintf(stderr,"    Value increases by 10-60 percent to %f\n",bv);
  242. #endif
  243.               break;
  244.  
  245.       case 4: 
  246.       case 5: 
  247.       case 6: 
  248.       case 7: 
  249.       case 8: 
  250. #ifdef DEBUG
  251.   fprintf(stderr,"    No change in value\n");
  252. #endif
  253.               break;
  254.  
  255.       case 9: bv = bv * (1.0 - (((float) die_roll(4))/10.0));
  256. #ifdef DEBUG
  257.   fprintf(stderr,"    Value decreases by 10-40 percent to %f\n",bv);
  258. #endif
  259.               break;
  260.  
  261.       case 10: ignore_results_below_2 = 1;
  262.               if(current_base_value_place >= orig_base_value_place -4) {
  263.                 if(current_base_value_place > 0)
  264.                   bv = bv_table[--current_base_value_place][1];
  265.                 else
  266.                   bv = decreased_bv_table[-1-(--current_base_value_place)];
  267. #ifdef DEBUG
  268.   fprintf(stderr,"    Place decreases one place to %i (started at %i)\n",
  269.                         current_base_value_place, orig_base_value_place);
  270.   fprintf(stderr,"    Value decreases one place to %f; roll again.\n",bv);
  271. #endif
  272.                 goto inc_or_dec; 
  273.               }
  274.  
  275.     } /* end switch */;
  276.  
  277. try_again:
  278.     prop = die_roll(14)-1;
  279.     if(strlen(properties[orig_base_value_place][prop][0]) == 0)
  280.       goto try_again;
  281. #ifdef DEBUG
  282.   fprintf(stderr,"  Prop = %i\n",prop);
  283. #endif
  284.  
  285.     fprintf(outfile,"%3i  %6.0f  %s\n",
  286.       i,
  287.       bv, 
  288.       properties[orig_base_value_place][prop][0]);
  289.  
  290.     total = total + bv;
  291.  
  292.   } /* end for i */
  293.   fprintf(outfile,"\nTotal: %f\n",total);
  294.  
  295. }; /* end proc random_gems */
  296.  
  297. main(argc,argv)
  298. int argc;
  299. char **argv;
  300. {
  301.   int num_gems;
  302.   int base_value;
  303.  
  304.   if((argc != 2) && (argc != 3)) {
  305.     fprintf(stderr,"Randomly determines the properties of gems.\n");
  306.     fprintf(stderr,"\n");
  307.     fprintf(stderr," usage: %s number [base-value]\n",argv[0]);
  308.     fprintf(stderr,"   where 'number' is the number of gems desired\n");
  309.     fprintf(stderr,"         'base-value' is [optional] base value in GP\n");
  310.     fprintf(stderr,"           (default base-value is random)\n",
  311.              '%','%');
  312.     fprintf(stderr,"\n  Examples: %s 318      (generates 318 random gems)\n",
  313.              argv[0]);
  314.     fprintf(stderr,"            %s 12 100   (generates 12 gems, base 100 GPV)\n",argv[0]);
  315.     exit(0);
  316.   }
  317.  
  318.   num_gems = atoi(argv[1]);
  319.  
  320.   if(argc==3)
  321.     base_value = atoi(argv[2]);
  322.   else
  323.     base_value = 0;
  324.  
  325.   /* seed random generator, may require system dependant command if
  326.    * time(0) does not work, or might need to use a scanf to get seed */
  327.   srand(time(0));
  328.  
  329.   random_gems(num_gems, base_value, stdout);
  330.  
  331. } /* end main */
  332.