fork download
  1. //randstats.cpp
  2.  
  3. #include "encounter.h"
  4. #include "player.h"
  5. #include <boost/random/mersenne_twister.hpp>
  6. #include <boost/random/uniform_int_distribution.hpp>
  7. #include <iostream>
  8. #include "createchar.h"
  9. #include "randstats.h"
  10.  
  11. boost::random::mt19937 gen;
  12. //gen.seed(static_cast<unsigned int>(std::time(0)));
  13.  
  14. player_vars randStats()
  15. {
  16. /*
  17.   Randomize new characters stats if the player chooses to do so rather than manually assign them.
  18.   Also going to use this to test against random encounters for balance purposes.
  19.   */
  20.  
  21. player.str = 8;
  22. player.dex = 8;
  23. player.con = 8;
  24. player.intel = 8;
  25. player.wis = 8;
  26. player.cha = 8;
  27. int remaining_points = 25; // starting pts to hand out freely
  28. const int total_possible = player.str + player.dex + player.con + player.intel + player.wis + player.cha + remaining_points; // max points to assign
  29.  
  30. /*
  31.   Basically the whole purpose of this is to pick random numbers and spread them out among random stats.
  32.   The stats will not be higher than total_possible + remaining points (assigned above).
  33.   */
  34.  
  35. while (remaining_points > 0)
  36. {
  37.  
  38. boost::random::uniform_int_distribution<> dist13(1, 3);
  39. int random_number = dist13(gen);
  40.  
  41. int x = 0;
  42. // Get current or total points currently assigned
  43. int totalpts = player.str + player.dex + player.con + player.intel + player.wis + player.cha;
  44.  
  45. //if we're in range and won't go over
  46. if ((totalpts < total_possible) && ((random_number + totalpts) < total_possible))
  47. {
  48. x = random_number;
  49. // remaining_points - x;
  50. }
  51. //if we're going to go over, only assign the number of points from random that will stop us at 73 points
  52. else if ((random_number + totalpts) > total_possible)
  53. {
  54. // Since we're going over the max total points, how many do we assign to a stat?
  55. int y = totalpts - total_possible;
  56. x = abs(y);
  57. remaining_points = 0; //force this because we exceeded
  58. }
  59.  
  60. //random numbering choosing which stat the points go to
  61. boost::random::uniform_int_distribution<> dist16(1, 6);
  62.  
  63. switch(dist16(gen))
  64. {
  65. case 1 :
  66. player.str += x;
  67. break;
  68. case 2 :
  69. player.dex += x;
  70. break;
  71. case 3 :
  72. player.con += x;
  73. break;
  74. case 4 :
  75. player.intel += x;
  76. break;
  77. case 5 :
  78. player.wis += x;
  79. break;
  80. case 6 :
  81. player.cha += x;
  82. break;
  83. default :
  84. break;
  85. }
  86.  
  87. }
  88.  
  89. //print the new results
  90. std::cout << "\nNew Character Stats:\n";
  91. std::cout << "Strength: [" << player.str << "]\n";
  92. std::cout << "Dexterity: [" << player.dex << "]\n";
  93. std::cout << "Constitution: [" << player.con << "]\n";
  94. std::cout << "Intelligence: [" << player.intel << "]\n";
  95. std::cout << "Wisdom: [" << player.wis << "]\n";
  96. std::cout << "Charisma: [" << player.cha << "]\n";
  97. std::cout << "Total Points Assigned: " << player.str + player.dex + player.con + player.intel + player.wis + player.cha << std::endl;
  98.  
  99. std::cout << "Accept these results? [y/n]: ";
  100. char selection;
  101. std::cin >> selection;
  102.  
  103. switch(selection)
  104. {
  105. case 'Y' :
  106. case 'y' :
  107. createPlayer();
  108. break;
  109. case 'N' :
  110. case 'n' :
  111. randStats();
  112. break;
  113. default:
  114. std::cout << "\nInvalid response. Keeping results.\n";
  115. createPlayer();
  116. }
  117.  
  118. return player;
  119.  
  120. }//close function
  121.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3:23: fatal error: encounter.h: No such file or directory
compilation terminated.
stdout
Standard output is empty