2015-05-03 22:02:39 +00:00
|
|
|
#include "handleDamage.h"
|
|
|
|
#include "OpenWound.h"
|
|
|
|
#include "DamageType.h"
|
|
|
|
#include "InjuryType.h"
|
|
|
|
#include <sstream>
|
|
|
|
|
2015-05-14 15:36:58 +00:00
|
|
|
namespace ace {
|
2015-05-14 16:56:23 +00:00
|
|
|
namespace medical {
|
|
|
|
|
|
|
|
handleDamage::handleDamage()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
handleDamage& handleDamage::GetInstance()
|
|
|
|
{
|
|
|
|
static handleDamage instance;
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
handleDamage::~handleDamage()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-05-16 21:19:50 +00:00
|
|
|
std::string handleDamage::HandleDamageWounds(const std::string& selectionName, double amountOfDamage, const std::string& typeOfDamage, int woundID)
|
2015-05-14 16:56:23 +00:00
|
|
|
{
|
|
|
|
std::vector<ace::medical::injuries::OpenWound> wounds;
|
|
|
|
int selectionN = SelectionToNumber(selectionName);
|
2015-05-16 21:19:50 +00:00
|
|
|
std::stringstream stream;
|
|
|
|
|
2015-05-14 16:56:23 +00:00
|
|
|
if (selectionN >= 0)
|
|
|
|
{
|
2015-05-16 21:19:50 +00:00
|
|
|
double painToAdd = 0;
|
|
|
|
wounds = GetInjuryInfoFor(typeOfDamage, amountOfDamage, selectionN, woundID);
|
|
|
|
|
|
|
|
stream << "_woundsCreated = [";
|
|
|
|
for (int i = 0; i < wounds.size(); ++i)
|
|
|
|
{
|
|
|
|
stream << wounds.at(i).AsString();
|
|
|
|
if (i != wounds.size() - 1)
|
|
|
|
{
|
|
|
|
stream << ",";
|
|
|
|
}
|
|
|
|
|
|
|
|
painToAdd += wounds.at(i).pain;
|
|
|
|
}
|
|
|
|
stream << "];";
|
|
|
|
|
|
|
|
stream << "_painToAdd = " << painToAdd << ";";
|
|
|
|
|
|
|
|
return stream.str();
|
2015-05-14 16:56:23 +00:00
|
|
|
}
|
2015-05-16 21:19:50 +00:00
|
|
|
stream << "";
|
|
|
|
return stream.str();
|
2015-05-14 16:56:23 +00:00
|
|
|
}
|
|
|
|
|
2015-05-16 21:19:50 +00:00
|
|
|
std::vector<ace::medical::injuries::OpenWound> handleDamage::GetInjuryInfoFor(const std::string& typeOfDamage, double amountOfDamage, int selection, int woundID)
|
2015-05-14 16:56:23 +00:00
|
|
|
{
|
|
|
|
std::vector<ace::medical::injuries::OpenWound> injuriesToAdd;
|
|
|
|
std::vector<std::shared_ptr<ace::medical::injuries::InjuryType>> information;
|
2015-05-16 21:19:50 +00:00
|
|
|
std::shared_ptr<ace::medical::injuries::InjuryType> highestSpot = nullptr;
|
2015-05-14 16:56:23 +00:00
|
|
|
|
|
|
|
for each (std::shared_ptr<ace::medical::injuries::DamageType> damageType in damageTypes)
|
|
|
|
{
|
|
|
|
if (damageType->typeName == typeOfDamage)
|
|
|
|
{
|
|
|
|
for each (std::shared_ptr<ace::medical::injuries::InjuryType> possibleInjury in damageType->possibleInjuries)
|
|
|
|
{
|
2015-05-16 21:19:50 +00:00
|
|
|
if (amountOfDamage >= possibleInjury->minDamage && (amountOfDamage <= possibleInjury->maxDamage || possibleInjury->maxDamage <= 0))
|
2015-05-14 16:56:23 +00:00
|
|
|
{
|
|
|
|
if (highestSpot == NULL)
|
|
|
|
highestSpot = possibleInjury;
|
|
|
|
|
|
|
|
if (possibleInjury->minDamage > highestSpot->minDamage)
|
|
|
|
highestSpot = possibleInjury;
|
|
|
|
|
|
|
|
information.push_back(possibleInjury);
|
|
|
|
}
|
|
|
|
}
|
2015-05-16 21:19:50 +00:00
|
|
|
if (highestSpot == NULL) {
|
|
|
|
break;
|
|
|
|
}
|
2015-05-14 16:56:23 +00:00
|
|
|
|
|
|
|
int c = 0;
|
|
|
|
for each (double threshold in damageType->minDamageThreshold)
|
|
|
|
{
|
2015-05-16 21:19:50 +00:00
|
|
|
if (amountOfDamage >= threshold)
|
2015-05-14 16:56:23 +00:00
|
|
|
{
|
|
|
|
double amountOfInjuriesOnDamage = damageType->amountOfInjuresOnDamage.at(c);
|
|
|
|
for (double injuryAmount = 0; injuryAmount < amountOfInjuriesOnDamage; ++injuryAmount)
|
|
|
|
{
|
|
|
|
std::shared_ptr<ace::medical::injuries::InjuryType> injuryToAdd;
|
|
|
|
if (rand() % 1 >= 0.85)
|
|
|
|
{
|
|
|
|
injuryToAdd = highestSpot;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
injuryToAdd = information.at(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bodyPartID = selection;
|
|
|
|
if (!damageType->selectionSpecific)
|
|
|
|
{
|
|
|
|
bodyPartID = rand() % 6;
|
|
|
|
}
|
|
|
|
|
2015-05-16 21:19:50 +00:00
|
|
|
injuries::OpenWound newWound(woundID++, injuryToAdd->ID, bodyPartID, 1, injuryToAdd->bloodLoss, injuryToAdd->pain);
|
2015-05-14 16:56:23 +00:00
|
|
|
injuriesToAdd.push_back(newWound);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++c;
|
|
|
|
}
|
|
|
|
return injuriesToAdd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return injuriesToAdd;
|
|
|
|
}
|
|
|
|
|
2015-05-16 21:19:50 +00:00
|
|
|
std::string handleDamage::AddDamageType(const std::vector<std::string>& input)
|
2015-05-14 16:56:23 +00:00
|
|
|
{
|
|
|
|
if (input.size() == 5)
|
|
|
|
{
|
|
|
|
std::string typeName = input[0];
|
|
|
|
double minimalLethalDamage = std::stod(input[1]);
|
2015-05-16 21:19:50 +00:00
|
|
|
std::vector<double> minDamageThreshold = inputToVectorDouble(input[2]);
|
|
|
|
std::vector<double> amountOfInjuresOnDamage = inputToVectorDouble(input[3]);
|
2015-05-14 16:56:23 +00:00
|
|
|
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));
|
|
|
|
damageTypes.push_back(type);
|
2015-05-16 21:19:50 +00:00
|
|
|
|
|
|
|
std::stringstream stream;
|
|
|
|
|
|
|
|
stream << "ADDED: " << typeName << " - " << minimalLethalDamage << " - [";
|
|
|
|
for each (double sel in minDamageThreshold)
|
|
|
|
{
|
|
|
|
stream << sel << " -";
|
|
|
|
}
|
|
|
|
stream << "] - [";
|
|
|
|
for each (double sel in amountOfInjuresOnDamage)
|
|
|
|
{
|
|
|
|
stream << sel << " -";
|
|
|
|
}
|
|
|
|
stream << "] - " << selectionSpecific;
|
|
|
|
return stream.str();
|
2015-05-14 16:56:23 +00:00
|
|
|
}
|
2015-05-16 21:19:50 +00:00
|
|
|
return "failed";
|
2015-05-14 16:56:23 +00:00
|
|
|
}
|
|
|
|
|
2015-05-16 21:19:50 +00:00
|
|
|
std::string handleDamage::AddInjuryType(const std::vector<std::string>& input)
|
2015-05-14 16:56:23 +00:00
|
|
|
{
|
|
|
|
if (input.size() == 9)
|
|
|
|
{
|
|
|
|
// TODO parse arrays from string input
|
|
|
|
|
|
|
|
int ID = std::stod(input[0]);
|
|
|
|
std::string className = input[1];
|
2015-05-16 21:19:50 +00:00
|
|
|
std::vector<std::string> allowedSelections = inputToVector(input[2]);
|
2015-05-14 16:56:23 +00:00
|
|
|
double bloodLoss = std::stod(input[3]);
|
|
|
|
double pain = std::stod(input[4]);
|
|
|
|
|
|
|
|
double minDamage = std::stod(input[5]);
|
|
|
|
double maxDamage = std::stod(input[6]);
|
2015-05-16 21:19:50 +00:00
|
|
|
std::vector<std::string> possibleCauses = inputToVector(input[7]);
|
2015-05-14 16:56:23 +00:00
|
|
|
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));
|
|
|
|
injuryTypes.push_back(type);
|
2015-05-16 21:19:50 +00:00
|
|
|
std::stringstream stream;
|
|
|
|
|
|
|
|
stream << "ADDED: " << ID << " - " << className << " - [";
|
|
|
|
for each (std::string sel in allowedSelections)
|
|
|
|
{
|
|
|
|
stream << sel << " -";
|
|
|
|
}
|
|
|
|
stream << "] - ";
|
|
|
|
stream << bloodLoss << " - " << pain << " - " << minDamage << " - " << maxDamage;
|
|
|
|
for each (std::string sel in possibleCauses)
|
|
|
|
{
|
|
|
|
stream << sel << " -";
|
|
|
|
}
|
|
|
|
stream << displayName;
|
|
|
|
return stream.str();
|
2015-05-14 16:56:23 +00:00
|
|
|
}
|
2015-05-16 21:19:50 +00:00
|
|
|
return "failed";
|
2015-05-14 16:56:23 +00:00
|
|
|
}
|
|
|
|
|
2015-05-16 21:19:50 +00:00
|
|
|
std::string handleDamage::FinalizeDefinitions()
|
2015-05-14 16:56:23 +00:00
|
|
|
{
|
2015-05-16 21:19:50 +00:00
|
|
|
std::stringstream outputstream;
|
|
|
|
|
2015-05-14 16:56:23 +00:00
|
|
|
// 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::InjuryType> injuryType in injuryTypes)
|
|
|
|
{
|
2015-05-16 21:19:50 +00:00
|
|
|
std::vector<std::string>::iterator it = find(injuryType->causes.begin(), injuryType->causes.end(), damageType->typeName);
|
|
|
|
// outputstream << " Evaluating causes: " << (it != injuryType->causes.end()) << " ";
|
|
|
|
if (it != injuryType->causes.end())
|
2015-05-14 16:56:23 +00:00
|
|
|
{
|
|
|
|
damageType->possibleInjuries.push_back(injuryType);
|
|
|
|
}
|
|
|
|
}
|
2015-05-16 21:19:50 +00:00
|
|
|
outputstream << " ---- For: " << damageType->typeName << " Added: " << damageType->possibleInjuries.size() << " --- ";
|
2015-05-14 16:56:23 +00:00
|
|
|
}
|
2015-05-16 21:19:50 +00:00
|
|
|
return outputstream.str();
|
2015-05-14 16:56:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int handleDamage::SelectionToNumber(const std::string& selectionName)
|
|
|
|
{
|
|
|
|
// TODO use dynamic selections instead
|
|
|
|
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);
|
|
|
|
if (it != selections.end())
|
|
|
|
{
|
|
|
|
return it - selections.begin();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return -1; // TODO throw exception
|
|
|
|
}
|
|
|
|
}
|
2015-05-16 21:19:50 +00:00
|
|
|
|
|
|
|
std::vector<std::string> handleDamage::inputToVector(const std::string& input)
|
|
|
|
{
|
|
|
|
std::istringstream ss(input);
|
|
|
|
std::string token;
|
|
|
|
|
|
|
|
std::vector<std::string> output;
|
|
|
|
while (std::getline(ss, token, ':')) {
|
|
|
|
output.push_back(token);
|
|
|
|
}
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
std::vector<double> handleDamage::inputToVectorDouble(const std::string& input)
|
|
|
|
{
|
|
|
|
std::istringstream ss(input);
|
|
|
|
std::string token;
|
|
|
|
|
|
|
|
std::vector<double> output;
|
|
|
|
while (std::getline(ss, token, ':')) {
|
|
|
|
output.push_back(std::stod(token));
|
|
|
|
}
|
|
|
|
return output;
|
|
|
|
}
|
2015-05-14 16:56:23 +00:00
|
|
|
}
|
2015-05-03 22:02:39 +00:00
|
|
|
}
|