//randstats.cpp
#include "encounter.h"
#include "player.h"
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int_distribution.hpp>
#include <iostream>
#include "createchar.h"
#include "randstats.h"
boost::random::mt19937 gen;
//gen.seed(static_cast<unsigned int>(std::time(0)));
player_vars randStats()
{
/*
Randomize new characters stats if the player chooses to do so rather than manually assign them.
Also going to use this to test against random encounters for balance purposes.
*/
player.str = 8;
player.dex = 8;
player.con = 8;
player.intel = 8;
player.wis = 8;
player.cha = 8;
int remaining_points = 25; // starting pts to hand out freely
const int total_possible = player.str + player.dex + player.con + player.intel + player.wis + player.cha + remaining_points; // max points to assign
/*
Basically the whole purpose of this is to pick random numbers and spread them out among random stats.
The stats will not be higher than total_possible + remaining points (assigned above).
*/
while (remaining_points > 0)
{
boost::random::uniform_int_distribution<> dist13(1, 3);
int random_number = dist13(gen);
int x = 0;
// Get current or total points currently assigned
int totalpts = player.str + player.dex + player.con + player.intel + player.wis + player.cha;
//if we're in range and won't go over
if ((totalpts < total_possible) && ((random_number + totalpts) < total_possible))
{
x = random_number;
// remaining_points - x;
}
//if we're going to go over, only assign the number of points from random that will stop us at 73 points
else if ((random_number + totalpts) > total_possible)
{
// Since we're going over the max total points, how many do we assign to a stat?
int y = totalpts - total_possible;
x = abs(y);
remaining_points = 0; //force this because we exceeded
}
//random numbering choosing which stat the points go to
boost::random::uniform_int_distribution<> dist16(1, 6);
switch(dist16(gen))
{
case 1 :
player.str += x;
break;
case 2 :
player.dex += x;
break;
case 3 :
player.con += x;
break;
case 4 :
player.intel += x;
break;
case 5 :
player.wis += x;
break;
case 6 :
player.cha += x;
break;
default :
break;
}
}
//print the new results
std::cout << "\nNew Character Stats:\n";
std::cout << "Strength: [" << player.str << "]\n";
std::cout << "Dexterity: [" << player.dex << "]\n";
std::cout << "Constitution: [" << player.con << "]\n";
std::cout << "Intelligence: [" << player.intel << "]\n";
std::cout << "Wisdom: [" << player.wis << "]\n";
std::cout << "Charisma: [" << player.cha << "]\n";
std::cout << "Total Points Assigned: " << player.str + player.dex + player.con + player.intel + player.wis + player.cha << std::endl;
std::cout << "Accept these results? [y/n]: ";
char selection;
std::cin >> selection;
switch(selection)
{
case 'Y' :
case 'y' :
createPlayer();
break;
case 'N' :
case 'n' :
randStats();
break;
default:
std::cout << "\nInvalid response. Keeping results.\n";
createPlayer();
}
return player;
}//close function