This commit is contained in:
Glowbal 2015-05-14 18:56:23 +02:00
parent 5756c8530f
commit eb2383a6f0
6 changed files with 150 additions and 150 deletions

View File

@ -17,9 +17,9 @@ namespace ace {
std::string typeName; std::string typeName;
double minLethalDamage; double minLethalDamage;
std::vector<double> minDamageThreshold; std::vector<double> minDamageThreshold;
std::vector<double> amountOfInjuresOnDamage; std::vector<double> amountOfInjuresOnDamage;
bool selectionSpecific; bool selectionSpecific;
std::vector<std::shared_ptr<InjuryType>> possibleInjuries; std::vector<std::shared_ptr<InjuryType>> possibleInjuries;
}; };

View File

@ -9,7 +9,7 @@ namespace ace {
class InjuryType class InjuryType
{ {
public: public:
InjuryType(signed int anId, const std::string& aClassname, std::vector<std::string>& allowedSelections, double theBloodLoss, double thePain, double minimumDamage, double maximumDamage, std::vector<std::string>& possibleCauses, std::string& aDisplayname); InjuryType(signed int anId, const std::string& aClassname, std::vector<std::string>& allowedSelections, double theBloodLoss, double thePain, double minimumDamage, double maximumDamage, std::vector<std::string>& possibleCauses, std::string& aDisplayname);
~InjuryType(); ~InjuryType();
signed int ID; signed int ID;

View File

@ -2,7 +2,7 @@
#include <sstream> #include <sstream>
ace::medical::injuries::OpenWound::OpenWound(int aClassID, int aBodyPartId, double aPercentage, double aBl, double painAmount) : ace::medical::injuries::OpenWound::OpenWound(int aClassID, int aBodyPartId, double aPercentage, double aBl, double painAmount) :
classID(aClassID), bodyPart(aBodyPartId), percentage(aPercentage), bloodlossRate(aBl), pain(painAmount) classID(aClassID), bodyPart(aBodyPartId), percentage(aPercentage), bloodlossRate(aBl), pain(painAmount)
{ {
} }

View File

@ -14,10 +14,10 @@ namespace ace {
std::string AsString(); std::string AsString();
int classID; int classID;
int percentage; int percentage;
double bodyPart; double bodyPart;
double bloodlossRate; double bloodlossRate;
double pain; double pain;
}; };
} }

View File

@ -5,159 +5,159 @@
#include <sstream> #include <sstream>
namespace ace { namespace ace {
namespace medical { namespace medical {
handleDamage::handleDamage() handleDamage::handleDamage()
{ {
} }
handleDamage& handleDamage::GetInstance() handleDamage& handleDamage::GetInstance()
{ {
static handleDamage instance; static handleDamage instance;
return instance; return instance;
} }
handleDamage::~handleDamage() handleDamage::~handleDamage()
{ {
} }
/* static */ std::vector<ace::medical::injuries::OpenWound> handleDamage::HandleDamageWounds(const std::string& selectionName, double amountOfDamage, const std::string& typeOfDamage) /* static */ std::vector<ace::medical::injuries::OpenWound> handleDamage::HandleDamageWounds(const std::string& selectionName, double amountOfDamage, const std::string& typeOfDamage)
{ {
std::vector<ace::medical::injuries::OpenWound> wounds; std::vector<ace::medical::injuries::OpenWound> wounds;
int selectionN = SelectionToNumber(selectionName); int selectionN = SelectionToNumber(selectionName);
if (selectionN >= 0) if (selectionN >= 0)
{ {
wounds = GetInjuryInfoFor(typeOfDamage, amountOfDamage, selectionN); wounds = GetInjuryInfoFor(typeOfDamage, amountOfDamage, selectionN);
} }
return wounds; return wounds;
} }
std::vector<ace::medical::injuries::OpenWound> handleDamage::GetInjuryInfoFor(const std::string& typeOfDamage, double amountOfDamage, int selection) std::vector<ace::medical::injuries::OpenWound> handleDamage::GetInjuryInfoFor(const std::string& typeOfDamage, double amountOfDamage, int selection)
{ {
std::vector<ace::medical::injuries::OpenWound> injuriesToAdd; std::vector<ace::medical::injuries::OpenWound> injuriesToAdd;
std::vector<std::shared_ptr<ace::medical::injuries::InjuryType>> information; std::vector<std::shared_ptr<ace::medical::injuries::InjuryType>> information;
std::shared_ptr<ace::medical::injuries::InjuryType> highestSpot; std::shared_ptr<ace::medical::injuries::InjuryType> highestSpot;
for each (std::shared_ptr<ace::medical::injuries::DamageType> damageType in damageTypes) for each (std::shared_ptr<ace::medical::injuries::DamageType> damageType in damageTypes)
{ {
if (damageType->typeName == typeOfDamage) if (damageType->typeName == typeOfDamage)
{ {
for each (std::shared_ptr<ace::medical::injuries::InjuryType> possibleInjury in damageType->possibleInjuries) for each (std::shared_ptr<ace::medical::injuries::InjuryType> possibleInjury in damageType->possibleInjuries)
{ {
if (amountOfDamage >= possibleInjury->minDamage && (amountOfDamage <= possibleInjury->maxDamage || possibleInjury->maxDamage == 0)) if (amountOfDamage >= possibleInjury->minDamage && (amountOfDamage <= possibleInjury->maxDamage || possibleInjury->maxDamage == 0))
{ {
if (highestSpot == NULL) if (highestSpot == NULL)
highestSpot = possibleInjury; highestSpot = possibleInjury;
if (possibleInjury->minDamage > highestSpot->minDamage) if (possibleInjury->minDamage > highestSpot->minDamage)
highestSpot = possibleInjury; highestSpot = possibleInjury;
information.push_back(possibleInjury); information.push_back(possibleInjury);
} }
} }
int c = 0; int c = 0;
for each (double threshold in damageType->minDamageThreshold) for each (double threshold in damageType->minDamageThreshold)
{ {
if (threshold >= amountOfDamage) if (threshold >= amountOfDamage)
{ {
double amountOfInjuriesOnDamage = damageType->amountOfInjuresOnDamage.at(c); double amountOfInjuriesOnDamage = damageType->amountOfInjuresOnDamage.at(c);
for (double injuryAmount = 0; injuryAmount < amountOfInjuriesOnDamage; ++injuryAmount) for (double injuryAmount = 0; injuryAmount < amountOfInjuriesOnDamage; ++injuryAmount)
{ {
std::shared_ptr<ace::medical::injuries::InjuryType> injuryToAdd; std::shared_ptr<ace::medical::injuries::InjuryType> injuryToAdd;
if (rand() % 1 >= 0.85) if (rand() % 1 >= 0.85)
{ {
injuryToAdd = highestSpot; injuryToAdd = highestSpot;
} }
else else
{ {
injuryToAdd = information.at(0); injuryToAdd = information.at(0);
} }
int bodyPartID = selection; int bodyPartID = selection;
if (!damageType->selectionSpecific) if (!damageType->selectionSpecific)
{ {
bodyPartID = rand() % 6; bodyPartID = rand() % 6;
} }
injuries::OpenWound newWound(injuryToAdd->ID, bodyPartID, 1, injuryToAdd->bloodLoss, injuryToAdd->pain); injuries::OpenWound newWound(injuryToAdd->ID, bodyPartID, 1, injuryToAdd->bloodLoss, injuryToAdd->pain);
injuriesToAdd.push_back(newWound); injuriesToAdd.push_back(newWound);
} }
} }
++c; ++c;
} }
return injuriesToAdd; return injuriesToAdd;
} }
} }
return injuriesToAdd; return injuriesToAdd;
} }
/* static */ void handleDamage::AddDamageType(const std::vector<std::string>& input) /* static */ void handleDamage::AddDamageType(const std::vector<std::string>& input)
{ {
if (input.size() == 5) if (input.size() == 5)
{ {
std::string typeName = input[0]; std::string typeName = input[0];
double minimalLethalDamage = std::stod(input[1]); double minimalLethalDamage = std::stod(input[1]);
std::vector<double> minDamageThreshold;// = std::stod(input[2]); std::vector<double> minDamageThreshold;// = std::stod(input[2]);
std::vector<double> amountOfInjuresOnDamage; //= std::stod(input[3]); std::vector<double> amountOfInjuresOnDamage; //= std::stod(input[3]);
bool selectionSpecific = std::stod(input[4]) > 0; bool selectionSpecific = std::stod(input[4]) > 0;
std::shared_ptr<ace::medical::injuries::DamageType> type(new ace::medical::injuries::DamageType(typeName, minimalLethalDamage, minDamageThreshold, amountOfInjuresOnDamage, selectionSpecific)); std::shared_ptr<ace::medical::injuries::DamageType> type(new ace::medical::injuries::DamageType(typeName, minimalLethalDamage, minDamageThreshold, amountOfInjuresOnDamage, selectionSpecific));
damageTypes.push_back(type); damageTypes.push_back(type);
} }
} }
void handleDamage::AddInjuryType(const std::vector<std::string>& input) void handleDamage::AddInjuryType(const std::vector<std::string>& input)
{ {
if (input.size() == 9) if (input.size() == 9)
{ {
// TODO parse arrays from string input // TODO parse arrays from string input
int ID = std::stod(input[0]); int ID = std::stod(input[0]);
std::string className = input[1]; std::string className = input[1];
std::vector<std::string> allowedSelections; // input[2]; std::vector<std::string> allowedSelections; // input[2];
double bloodLoss = std::stod(input[3]); double bloodLoss = std::stod(input[3]);
double pain = std::stod(input[4]); double pain = std::stod(input[4]);
double minDamage = std::stod(input[5]); double minDamage = std::stod(input[5]);
double maxDamage = std::stod(input[6]); double maxDamage = std::stod(input[6]);
std::vector<std::string> possibleCauses; // input[7]; std::vector<std::string> possibleCauses; // input[7];
std::string displayName = input[8]; std::string displayName = input[8];
std::shared_ptr<ace::medical::injuries::InjuryType> type(new ace::medical::injuries::InjuryType(ID, className, allowedSelections, bloodLoss, pain, minDamage, maxDamage, possibleCauses, displayName)); std::shared_ptr<ace::medical::injuries::InjuryType> type(new ace::medical::injuries::InjuryType(ID, className, allowedSelections, bloodLoss, pain, minDamage, maxDamage, possibleCauses, displayName));
injuryTypes.push_back(type); injuryTypes.push_back(type);
} }
} }
void handleDamage::FinalizeDefinitions() void handleDamage::FinalizeDefinitions()
{ {
// We are finding all possible injuries for a specific damage type here, so we don't have to figure that out at a later stage. // We are finding all possible injuries for a specific damage type here, so we don't have to figure that out at a later stage.
for each (std::shared_ptr<ace::medical::injuries::DamageType> damageType in damageTypes) for each (std::shared_ptr<ace::medical::injuries::DamageType> damageType in damageTypes)
{ {
for each (std::shared_ptr<ace::medical::injuries::InjuryType> injuryType in injuryTypes) for each (std::shared_ptr<ace::medical::injuries::InjuryType> injuryType in injuryTypes)
{ {
if (find(injuryType->causes.begin(), injuryType->causes.end(), damageType->typeName) != injuryType->causes.end()) if (find(injuryType->causes.begin(), injuryType->causes.end(), damageType->typeName) != injuryType->causes.end())
{ {
damageType->possibleInjuries.push_back(injuryType); damageType->possibleInjuries.push_back(injuryType);
} }
} }
} }
} }
int handleDamage::SelectionToNumber(const std::string& selectionName) int handleDamage::SelectionToNumber(const std::string& selectionName)
{ {
// TODO use dynamic selections instead // TODO use dynamic selections instead
std::vector<std::string> selections = { "head", "body", "hand_l", "hand_r", "leg_l", "leg_r" }; std::vector<std::string> selections = { "head", "body", "hand_l", "hand_r", "leg_l", "leg_r" };
std::vector<std::string>::iterator it = find(selections.begin(), selections.end(), selectionName); std::vector<std::string>::iterator it = find(selections.begin(), selections.end(), selectionName);
if (it != selections.end()) if (it != selections.end())
{ {
return it - selections.begin(); return it - selections.begin();
} }
else else
{ {
return -1; // TODO throw exception return -1; // TODO throw exception
} }
} }
} }
} }

View File

@ -16,10 +16,10 @@ namespace ace {
class handleDamage class handleDamage
{ {
public: public:
/** /**
* *
*/ */
static handleDamage& GetInstance(); static handleDamage& GetInstance();
~handleDamage(); ~handleDamage();
@ -28,7 +28,7 @@ namespace ace {
*/ */
std::vector<ace::medical::injuries::OpenWound> HandleDamageWounds(const std::string& selectionName, double amountOfDamage, const std::string& typeOfDamage); std::vector<ace::medical::injuries::OpenWound> HandleDamageWounds(const std::string& selectionName, double amountOfDamage, const std::string& typeOfDamage);
std::vector<ace::medical::injuries::OpenWound> GetInjuryInfoFor(const std::string& typeOfDamage, double amountOfDamage, int selection); std::vector<ace::medical::injuries::OpenWound> GetInjuryInfoFor(const std::string& typeOfDamage, double amountOfDamage, int selection);
/** /**
* *
@ -63,9 +63,9 @@ namespace ace {
private: private:
handleDamage(); handleDamage();
handleDamage(handleDamage const&) = delete; handleDamage(handleDamage const&) = delete;
void operator=(handleDamage const&) = delete; void operator=(handleDamage const&) = delete;
std::vector<std::shared_ptr<ace::medical::injuries::DamageType>> damageTypes; std::vector<std::shared_ptr<ace::medical::injuries::DamageType>> damageTypes;
std::vector<std::shared_ptr<ace::medical::injuries::InjuryType>> injuryTypes; std::vector<std::shared_ptr<ace::medical::injuries::InjuryType>> injuryTypes;