//Contains functions and classes for character attributes.
#include "StdAfx.h"
#include "std_lib_facilities.h"
#include "common.h"
//Attribute structure
class Attribute {
public:
string name;
int points;
Attribute()
:name(), points() { }
Attribute(string n)
:name(n), points(0) { }
Attribute(string n, int p)
:name(n), points(p) { }
};
class Attribute_Table {
// class containing table of attributes and interface.
public:
int get(string name); //return point value of attribute
int check(); //return remaining spending points
void increase(string name, int points); //increase point value of attribute
void decrease(string name, int points); //decrease point value of attribute
void define(string name); //define a new attribute
void define(string name, int points);
Attribute_Table()
:spend(0), table() { }
Attribute_Table(int s)
:spend(s), table() { }
private:
int spend; //remaining unused points.
vector<Attribute> table; //Vector of attributes
};
int Attribute_Table::get(string name)
//Return point value of an attribute
{
for (int i = 0; i < table.size(); ++i){
if (name == table.name)
return table.points;
}
error("Attribute does not exist");
}
int Attribute_Table::check(){
//returns unused points
return spend;
}
void Attribute_Table::increase(string name, int points)
//increases an attribute's points
{
bool found = false;
for (int i = 0; i < table.size(); ++i){
if (name == table.name){
table.points += points;
found = true;
}
}
if(!found){
error("Attribute does not exist");
}
}
void Attribute_Table::decrease(string name, int points)
//decreases an attribute's points
{
bool found = false;
for (int i = 0; i < table.size(); ++i){
if (name == table.name){
table.points -= points;
found = true;
}
}
if(!found){
error("Attribute does not exist");
}
}
void Attribute_Table::define(string name)
//define a new attribute
{
for (int i = 0; i < table.size(); ++i){
if (name == table.name){
error("Attribute already exists");
}
}
table.push_back(name);
}
void Attribute_Table::define(string name, int points)
//define a new attributen
{
for (int i = 0; i < table.size(); ++i){
if (name == table.name){
error("Attribute already exists");
}
}
Attribute temp;
temp.name = name;
temp.points = points;
table.push_back(temp);
}