From c2388aa80ce72fa4ebf2a1a7a8721fa93169b67d Mon Sep 17 00:00:00 2001 From: Glowbal Date: Mon, 4 May 2015 00:02:39 +0200 Subject: [PATCH] Initial work on medical extension --- extensions/CMakeLists.txt | 1 + extensions/medical/CMakeLists.txt | 13 ++++ extensions/medical/DamageType.cpp | 13 ++++ extensions/medical/DamageType.h | 26 ++++++++ extensions/medical/InjuryType.cpp | 14 +++++ extensions/medical/InjuryType.h | 27 +++++++++ extensions/medical/OpenWound.cpp | 19 ++++++ extensions/medical/OpenWound.h | 23 +++++++ extensions/medical/handleDamage.cpp | 94 +++++++++++++++++++++++++++++ extensions/medical/handleDamage.h | 66 ++++++++++++++++++++ extensions/medical/medical.cpp | 57 +++++++++++++++++ 11 files changed, 353 insertions(+) create mode 100644 extensions/medical/CMakeLists.txt create mode 100644 extensions/medical/DamageType.cpp create mode 100644 extensions/medical/DamageType.h create mode 100644 extensions/medical/InjuryType.cpp create mode 100644 extensions/medical/InjuryType.h create mode 100644 extensions/medical/OpenWound.cpp create mode 100644 extensions/medical/OpenWound.h create mode 100644 extensions/medical/handleDamage.cpp create mode 100644 extensions/medical/handleDamage.h create mode 100644 extensions/medical/medical.cpp diff --git a/extensions/CMakeLists.txt b/extensions/CMakeLists.txt index 9f4a8a29fa..bcef05d810 100644 --- a/extensions/CMakeLists.txt +++ b/extensions/CMakeLists.txt @@ -58,5 +58,6 @@ add_subdirectory(fcs) add_subdirectory(break_line) add_subdirectory(clipboard) add_subdirectory(advanced_ballistics) +add_subdirectory(medical) message("Build Type: ${CMAKE_BUILD_TYPE}") \ No newline at end of file diff --git a/extensions/medical/CMakeLists.txt b/extensions/medical/CMakeLists.txt new file mode 100644 index 0000000000..63d7105810 --- /dev/null +++ b/extensions/medical/CMakeLists.txt @@ -0,0 +1,13 @@ +set(ACE_EXTENSION_NAME "ace_medical") + +file(GLOB SOURCES *.h *.hpp *.c *.cpp) + +add_library( ${ACE_EXTENSION_NAME} SHARED ${SOURCES} ${GLOBAL_SOURCES}) +target_link_libraries(${ACE_EXTENSION_NAME} ace_common) +set_target_properties(${ACE_EXTENSION_NAME} PROPERTIES PREFIX "") +set_target_properties(${ACE_EXTENSION_NAME} PROPERTIES FOLDER Extensions) + +if(CMAKE_COMPILER_IS_GNUCXX) + set_target_properties(${ACE_EXTENSION_NAME} PROPERTIES LINK_SEARCH_START_STATIC 1) + set_target_properties(${ACE_EXTENSION_NAME} PROPERTIES LINK_SEARCH_END_STATIC 1) +endif() \ No newline at end of file diff --git a/extensions/medical/DamageType.cpp b/extensions/medical/DamageType.cpp new file mode 100644 index 0000000000..5fb9a4846d --- /dev/null +++ b/extensions/medical/DamageType.cpp @@ -0,0 +1,13 @@ +#include "DamageType.h" + +using namespace ace::medical; + +injuries::DamageType::DamageType(std::string aTypeName, unsigned int minimalLethalDamage, unsigned int minDamage, unsigned int maxDamage) + : typeName(aTypeName), minLethalDamage(minimalLethalDamage), minDamageThreshold(minDamage), maxDamageThreshold(maxDamage) +{ +} + + +injuries::DamageType::~DamageType() +{ +} diff --git a/extensions/medical/DamageType.h b/extensions/medical/DamageType.h new file mode 100644 index 0000000000..7106588f03 --- /dev/null +++ b/extensions/medical/DamageType.h @@ -0,0 +1,26 @@ +#include +#include +#include + + +namespace ace { + namespace medical { + namespace injuries { + class InjuryType; + + class DamageType + { + public: + DamageType(std::string aTypeName, unsigned int minimalLethalDamage, unsigned int minDamageThreshold, unsigned int maxDamageThreshold); + ~DamageType(); + + std::string typeName; + unsigned int minLethalDamage; + unsigned int minDamageThreshold; + unsigned int maxDamageThreshold; + + std::vector> possibleInjuries; + }; + } + } +} diff --git a/extensions/medical/InjuryType.cpp b/extensions/medical/InjuryType.cpp new file mode 100644 index 0000000000..07f902816f --- /dev/null +++ b/extensions/medical/InjuryType.cpp @@ -0,0 +1,14 @@ +#include "InjuryType.h" +#include "DamageType.h" + +using namespace ace::medical; + +injuries::InjuryType::InjuryType(signed int anId, const std::string& aClassname, std::vector& allowedSelections, signed int theBloodLoss, signed int thePain, signed int minimumDamage, signed int maximumDamage, std::vector& possibleCauses, std::string& aDisplayname) + : ID(anId), className(aClassname), selections(allowedSelections), bloodLoss(theBloodLoss), pain(thePain), minDamage(minimumDamage), maxDamage(maximumDamage), causes(possibleCauses), displayName(aDisplayname) +{ +} + + +injuries::InjuryType::~InjuryType() +{ +} diff --git a/extensions/medical/InjuryType.h b/extensions/medical/InjuryType.h new file mode 100644 index 0000000000..92766dd315 --- /dev/null +++ b/extensions/medical/InjuryType.h @@ -0,0 +1,27 @@ +#include +#include + +namespace ace { + namespace medical { + namespace injuries { + class DamageType; + + class InjuryType + { + public: + InjuryType(signed int anId, const std::string& aClassname, std::vector& allowedSelections, signed int theBloodLoss, signed int thePain, signed int minimumDamage, signed int maximumDamage, std::vector& possibleCauses, std::string& aDisplayname); + ~InjuryType(); + + signed int ID; + std::string className; + std::vector selections; + signed int bloodLoss; + signed int pain; + signed int minDamage; + signed int maxDamage; + std::vector causes; + std::string displayName; + }; + } + } +} \ No newline at end of file diff --git a/extensions/medical/OpenWound.cpp b/extensions/medical/OpenWound.cpp new file mode 100644 index 0000000000..77e38a9359 --- /dev/null +++ b/extensions/medical/OpenWound.cpp @@ -0,0 +1,19 @@ +#include "OpenWound.h" +#include + +using namespace ace::medical; + +injuries::OpenWound::OpenWound(unsigned int anID, unsigned int aBodyPart, unsigned int bloodloss) : classID(anID), bodyPart(aBodyPart), bloodlossRate(bloodloss) +{ +} + +injuries::OpenWound::~OpenWound() +{ +} + +std::string injuries::OpenWound::AsString() +{ + std::stringstream stream; + stream << classID << "," << bodyPart << "," << 1 << "," << bloodlossRate; + return stream.str(); +} diff --git a/extensions/medical/OpenWound.h b/extensions/medical/OpenWound.h new file mode 100644 index 0000000000..770004d917 --- /dev/null +++ b/extensions/medical/OpenWound.h @@ -0,0 +1,23 @@ +#pragma once + +#include + +namespace ace { + namespace medical { + namespace injuries { + class OpenWound + { + public: + OpenWound(unsigned int anID, unsigned int aBodyPart, unsigned int bloodloss); + ~OpenWound(); + + std::string AsString(); + + unsigned int classID; + unsigned int bodyPart; + unsigned int bloodlossRate; + }; + + } + } +} diff --git a/extensions/medical/handleDamage.cpp b/extensions/medical/handleDamage.cpp new file mode 100644 index 0000000000..6695c5c50c --- /dev/null +++ b/extensions/medical/handleDamage.cpp @@ -0,0 +1,94 @@ +#include "handleDamage.h" +#include "OpenWound.h" +#include "DamageType.h" +#include "InjuryType.h" +#include + +using namespace ace::medical; + +handleDamage::handleDamage() +{ +} + + +handleDamage::~handleDamage() +{ +} + +/* static */ std::vector handleDamage::HandleDamageWounds(const std::string& selectionName, signed int amountOfDamage, const std::string& typeOfDamage) +{ + std::vector wounds; + int selectionN = SelectionToNumber(selectionName); + if (selectionN >= 0) + { + std::vector> injuryTypeInfo = GetInjuryInfoFor(typeOfDamage); + } + + return wounds; +} + +/* static */ void handleDamage::AddDamageType(const std::vector& input) +{ + if (input.size() == 4) + { + std::string typeName = input[0]; + unsigned int minimalLethalDamage = std::stod(input[1]); + unsigned int minDamageThreshold = std::stod(input[2]); + unsigned int maxDamageThreshold = std::stod(input[3]); + + std::shared_ptr type(new injuries::DamageType(typeName, minimalLethalDamage, minDamageThreshold, maxDamageThreshold)); + damageTypes.push_back(type); + } +} + +/* static */ void handleDamage::AddInjuryType(const std::vector& input) +{ + if (input.size() == 9) + { + // TODO parse arrays from string input + + int ID = std::stod(input[0]); + std::string className = input[1]; + std::vector allowedSelections; // input[2]; + unsigned int bloodLoss = std::stod(input[3]); + unsigned int pain = std::stod(input[4]); + + unsigned int minDamage = std::stod(input[5]); + unsigned int maxDamage = std::stod(input[6]); + std::vector possibleCauses; // input[7]; + std::string displayName = input[8]; + + std::shared_ptr type(new injuries::InjuryType(ID, className, allowedSelections, bloodLoss, pain, minDamage, maxDamage, possibleCauses, displayName)); + injuryTypes.push_back(type); + } +} + +/* static */ 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. + for each (std::shared_ptr damageType in damageTypes) + { + for each (std::shared_ptr injuryType in injuryTypes) + { + if (find(injuryType->causes.begin(), injuryType->causes.end(), damageType->typeName) != injuryType->causes.end()) + { + damageType->possibleInjuries.push_back(injuryType); + } + } + } +} + +/* static */ int SelectionToNumber(const std::string& selectionName) +{ + // TODO use dynamic selections instead + std::vector selections = {"head", "body", "hand_l", "hand_r", "leg_l", "leg_r"}; + std::vector::iterator it = find(selections.begin(), selections.end(), selectionName); + if (it != selections.end()) + { + return it - selections.begin(); + } + else + { + return -1; // TODO throw exception + } +} diff --git a/extensions/medical/handleDamage.h b/extensions/medical/handleDamage.h new file mode 100644 index 0000000000..16aba8d791 --- /dev/null +++ b/extensions/medical/handleDamage.h @@ -0,0 +1,66 @@ +#pragma once + +#include +#include +#include + +namespace ace { + namespace medical { + + namespace injuries { + class DamageType; + class InjuryType; + class OpenWound; + } + + class handleDamage + { + public: + ~handleDamage(); + + /** + * + */ + static std::vector HandleDamageWounds(const std::string& selectionName, signed int amountOfDamage, const std::string& typeOfDamage); + + /** + * + */ + static void AddDamageType(const std::vector& sqfDamageTypeDefinition); + + /** + * + */ + static void AddInjuryType(const std::vector& sqfInjuryDefinition); + + /** + * + */ + static std::string SetInjuryTypeData(const std::string& data); + + + /** + * + */ + static int SelectionToNumber(const std::string& selectionName); + + /** + * + */ + static std::vector> GetInjuryInfoFor(const std::string& damageType); + + /** + * + */ + static void FinalizeDefinitions(); + + private: + handleDamage(); + + static std::vector> damageTypes; + static std::vector> injuryTypes; + static std::vector selections; + static std::vector hitPoints; + }; + } +} diff --git a/extensions/medical/medical.cpp b/extensions/medical/medical.cpp new file mode 100644 index 0000000000..4531db475a --- /dev/null +++ b/extensions/medical/medical.cpp @@ -0,0 +1,57 @@ +/* +* ace_medical.cpp +* +* Author: +* Glowbal +*/ + +#include "ace_common.h" +#include +#include +#include +#include "handleDamage.h" + +extern "C" { + __declspec (dllexport) void __stdcall RVExtension(char *output, int outputSize, const char *function); +}; + +std::vector parseExtensionInput(const std::string& input) +{ + std::istringstream ss(input); + std::string token; + + std::vector output; + while (std::getline(ss, token, ',')) { + output.push_back(token); + } + return output; +} + + +void __stdcall RVExtension(char *output, int outputSize, const char *function) { + if (!strcmp(function, "version")) { + strncpy(output, ACE_FULL_VERSION_STR, outputSize); + } + else + { + std::vector arguments = parseExtensionInput(function); + if (arguments.size > 0) + { + std::string command = arguments.at(0); + // can we not just use C++11? + if (command == "addInjuryType") { + + } + else if (command == "addDamageType") { + + } + else if (command == "getInjury") { + // ace::medical::handleDamage(); + } + } + std::string returnValue = ""; + strncpy(output, returnValue.c_str(), outputSize); + output[outputSize - 1] = '\0'; + } +} +