From 5756c8530f28a920817b615b12fbc4084a551d52 Mon Sep 17 00:00:00 2001 From: Glowbal Date: Thu, 14 May 2015 18:52:12 +0200 Subject: [PATCH] Ported over handleDamage_wounds --- extensions/medical/DamageType.cpp | 4 +- extensions/medical/DamageType.h | 8 ++-- extensions/medical/OpenWound.cpp | 3 +- extensions/medical/OpenWound.h | 6 ++- extensions/medical/handleDamage.cpp | 72 ++++++++++++++++++++++++++--- extensions/medical/handleDamage.h | 2 + 6 files changed, 81 insertions(+), 14 deletions(-) diff --git a/extensions/medical/DamageType.cpp b/extensions/medical/DamageType.cpp index aeccfa6896..3e6b08e507 100644 --- a/extensions/medical/DamageType.cpp +++ b/extensions/medical/DamageType.cpp @@ -1,7 +1,7 @@ #include "DamageType.h" -ace::medical::injuries::DamageType::DamageType(std::string aTypeName, double minimalLethalDamage, double minDamage, double maxDamage) - : typeName(aTypeName), minLethalDamage(minimalLethalDamage), minDamageThreshold(minDamage), maxDamageThreshold(maxDamage) +ace::medical::injuries::DamageType::DamageType(std::string aTypeName, double minimalLethalDamage, std::vector minDamage, std::vector amountOfInjuresOnDamage, bool specificOnly) + : typeName(aTypeName), minLethalDamage(minimalLethalDamage), minDamageThreshold(minDamage), amountOfInjuresOnDamage(amountOfInjuresOnDamage), selectionSpecific(specificOnly) { } diff --git a/extensions/medical/DamageType.h b/extensions/medical/DamageType.h index b690c46627..de8e73a07d 100644 --- a/extensions/medical/DamageType.h +++ b/extensions/medical/DamageType.h @@ -11,13 +11,15 @@ namespace ace { class DamageType { public: - DamageType(std::string aTypeName, double minimalLethalDamage, double minDamageThreshold, double maxDamageThreshold); + DamageType(std::string aTypeName, double minimalLethalDamage, std::vector minDamageThreshold, std::vector amountOfInjuresOnDamage, bool specificOnly); ~DamageType(); std::string typeName; double minLethalDamage; - double minDamageThreshold; - double maxDamageThreshold; + std::vector minDamageThreshold; + std::vector amountOfInjuresOnDamage; + + bool selectionSpecific; std::vector> possibleInjuries; }; diff --git a/extensions/medical/OpenWound.cpp b/extensions/medical/OpenWound.cpp index 6675704f03..b28cf79df5 100644 --- a/extensions/medical/OpenWound.cpp +++ b/extensions/medical/OpenWound.cpp @@ -1,7 +1,8 @@ #include "OpenWound.h" #include -ace::medical::injuries::OpenWound::OpenWound(double anID, double aBodyPart, double bloodloss) : classID(anID), bodyPart(aBodyPart), bloodlossRate(bloodloss) +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) { } diff --git a/extensions/medical/OpenWound.h b/extensions/medical/OpenWound.h index b2a9baccb8..4d2d7892eb 100644 --- a/extensions/medical/OpenWound.h +++ b/extensions/medical/OpenWound.h @@ -8,14 +8,16 @@ namespace ace { class OpenWound { public: - OpenWound(double anID, double aBodyPart, double bloodloss); + OpenWound(int aClassID, int aBodyPartId, double aPercentage, double aBl, double painAmount); ~OpenWound(); std::string AsString(); - double classID; + int classID; + int percentage; double bodyPart; double bloodlossRate; + double pain; }; } diff --git a/extensions/medical/handleDamage.cpp b/extensions/medical/handleDamage.cpp index 93094ab2bb..6fbc53e071 100644 --- a/extensions/medical/handleDamage.cpp +++ b/extensions/medical/handleDamage.cpp @@ -28,22 +28,82 @@ namespace ace { int selectionN = SelectionToNumber(selectionName); if (selectionN >= 0) { - // std::vector> injuryTypeInfo = GetInjuryInfoFor(typeOfDamage); + wounds = GetInjuryInfoFor(typeOfDamage, amountOfDamage, selectionN); } - return wounds; } + std::vector handleDamage::GetInjuryInfoFor(const std::string& typeOfDamage, double amountOfDamage, int selection) + { + std::vector injuriesToAdd; + std::vector> information; + std::shared_ptr highestSpot; + + for each (std::shared_ptr damageType in damageTypes) + { + if (damageType->typeName == typeOfDamage) + { + for each (std::shared_ptr possibleInjury in damageType->possibleInjuries) + { + if (amountOfDamage >= possibleInjury->minDamage && (amountOfDamage <= possibleInjury->maxDamage || possibleInjury->maxDamage == 0)) + { + if (highestSpot == NULL) + highestSpot = possibleInjury; + + if (possibleInjury->minDamage > highestSpot->minDamage) + highestSpot = possibleInjury; + + information.push_back(possibleInjury); + } + } + + int c = 0; + for each (double threshold in damageType->minDamageThreshold) + { + if (threshold >= amountOfDamage) + { + double amountOfInjuriesOnDamage = damageType->amountOfInjuresOnDamage.at(c); + for (double injuryAmount = 0; injuryAmount < amountOfInjuriesOnDamage; ++injuryAmount) + { + std::shared_ptr injuryToAdd; + if (rand() % 1 >= 0.85) + { + injuryToAdd = highestSpot; + } + else + { + injuryToAdd = information.at(0); + } + + int bodyPartID = selection; + if (!damageType->selectionSpecific) + { + bodyPartID = rand() % 6; + } + + injuries::OpenWound newWound(injuryToAdd->ID, bodyPartID, 1, injuryToAdd->bloodLoss, injuryToAdd->pain); + injuriesToAdd.push_back(newWound); + } + } + ++c; + } + return injuriesToAdd; + } + } + return injuriesToAdd; + } + /* static */ void handleDamage::AddDamageType(const std::vector& input) { - if (input.size() == 4) + if (input.size() == 5) { std::string typeName = input[0]; double minimalLethalDamage = std::stod(input[1]); - double minDamageThreshold = std::stod(input[2]); - double maxDamageThreshold = std::stod(input[3]); + std::vector minDamageThreshold;// = std::stod(input[2]); + std::vector amountOfInjuresOnDamage; //= std::stod(input[3]); + bool selectionSpecific = std::stod(input[4]) > 0; - std::shared_ptr type(new ace::medical::injuries::DamageType(typeName, minimalLethalDamage, minDamageThreshold, maxDamageThreshold)); + std::shared_ptr type(new ace::medical::injuries::DamageType(typeName, minimalLethalDamage, minDamageThreshold, amountOfInjuresOnDamage, selectionSpecific)); damageTypes.push_back(type); } } diff --git a/extensions/medical/handleDamage.h b/extensions/medical/handleDamage.h index 5959e58653..fdaa952bfd 100644 --- a/extensions/medical/handleDamage.h +++ b/extensions/medical/handleDamage.h @@ -28,6 +28,8 @@ namespace ace { */ std::vector HandleDamageWounds(const std::string& selectionName, double amountOfDamage, const std::string& typeOfDamage); + std::vector GetInjuryInfoFor(const std::string& typeOfDamage, double amountOfDamage, int selection); + /** * */