mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Initial work on medical extension
This commit is contained in:
parent
f678fb8fbf
commit
c2388aa80c
@ -58,5 +58,6 @@ add_subdirectory(fcs)
|
|||||||
add_subdirectory(break_line)
|
add_subdirectory(break_line)
|
||||||
add_subdirectory(clipboard)
|
add_subdirectory(clipboard)
|
||||||
add_subdirectory(advanced_ballistics)
|
add_subdirectory(advanced_ballistics)
|
||||||
|
add_subdirectory(medical)
|
||||||
|
|
||||||
message("Build Type: ${CMAKE_BUILD_TYPE}")
|
message("Build Type: ${CMAKE_BUILD_TYPE}")
|
13
extensions/medical/CMakeLists.txt
Normal file
13
extensions/medical/CMakeLists.txt
Normal file
@ -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()
|
13
extensions/medical/DamageType.cpp
Normal file
13
extensions/medical/DamageType.cpp
Normal file
@ -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()
|
||||||
|
{
|
||||||
|
}
|
26
extensions/medical/DamageType.h
Normal file
26
extensions/medical/DamageType.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
|
||||||
|
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<std::shared_ptr<InjuryType>> possibleInjuries;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
14
extensions/medical/InjuryType.cpp
Normal file
14
extensions/medical/InjuryType.cpp
Normal file
@ -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<std::string>& allowedSelections, signed int theBloodLoss, signed int thePain, signed int minimumDamage, signed int maximumDamage, std::vector<std::string>& 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()
|
||||||
|
{
|
||||||
|
}
|
27
extensions/medical/InjuryType.h
Normal file
27
extensions/medical/InjuryType.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace ace {
|
||||||
|
namespace medical {
|
||||||
|
namespace injuries {
|
||||||
|
class DamageType;
|
||||||
|
|
||||||
|
class InjuryType
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
InjuryType(signed int anId, const std::string& aClassname, std::vector<std::string>& allowedSelections, signed int theBloodLoss, signed int thePain, signed int minimumDamage, signed int maximumDamage, std::vector<std::string>& possibleCauses, std::string& aDisplayname);
|
||||||
|
~InjuryType();
|
||||||
|
|
||||||
|
signed int ID;
|
||||||
|
std::string className;
|
||||||
|
std::vector<std::string> selections;
|
||||||
|
signed int bloodLoss;
|
||||||
|
signed int pain;
|
||||||
|
signed int minDamage;
|
||||||
|
signed int maxDamage;
|
||||||
|
std::vector<std::string> causes;
|
||||||
|
std::string displayName;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
19
extensions/medical/OpenWound.cpp
Normal file
19
extensions/medical/OpenWound.cpp
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include "OpenWound.h"
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
23
extensions/medical/OpenWound.h
Normal file
23
extensions/medical/OpenWound.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
94
extensions/medical/handleDamage.cpp
Normal file
94
extensions/medical/handleDamage.cpp
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
#include "handleDamage.h"
|
||||||
|
#include "OpenWound.h"
|
||||||
|
#include "DamageType.h"
|
||||||
|
#include "InjuryType.h"
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
using namespace ace::medical;
|
||||||
|
|
||||||
|
handleDamage::handleDamage()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
handleDamage::~handleDamage()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */ std::vector<injuries::OpenWound> handleDamage::HandleDamageWounds(const std::string& selectionName, signed int amountOfDamage, const std::string& typeOfDamage)
|
||||||
|
{
|
||||||
|
std::vector<injuries::OpenWound> wounds;
|
||||||
|
int selectionN = SelectionToNumber(selectionName);
|
||||||
|
if (selectionN >= 0)
|
||||||
|
{
|
||||||
|
std::vector<std::shared_ptr<injuries::InjuryType>> injuryTypeInfo = GetInjuryInfoFor(typeOfDamage);
|
||||||
|
}
|
||||||
|
|
||||||
|
return wounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */ void handleDamage::AddDamageType(const std::vector<std::string>& 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<injuries::DamageType> type(new injuries::DamageType(typeName, minimalLethalDamage, minDamageThreshold, maxDamageThreshold));
|
||||||
|
damageTypes.push_back(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */ void handleDamage::AddInjuryType(const std::vector<std::string>& input)
|
||||||
|
{
|
||||||
|
if (input.size() == 9)
|
||||||
|
{
|
||||||
|
// TODO parse arrays from string input
|
||||||
|
|
||||||
|
int ID = std::stod(input[0]);
|
||||||
|
std::string className = input[1];
|
||||||
|
std::vector<std::string> 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<std::string> possibleCauses; // input[7];
|
||||||
|
std::string displayName = input[8];
|
||||||
|
|
||||||
|
std::shared_ptr<injuries::InjuryType> 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<injuries::DamageType> damageType in damageTypes)
|
||||||
|
{
|
||||||
|
for each (std::shared_ptr<injuries::InjuryType> 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<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
|
||||||
|
}
|
||||||
|
}
|
66
extensions/medical/handleDamage.h
Normal file
66
extensions/medical/handleDamage.h
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace ace {
|
||||||
|
namespace medical {
|
||||||
|
|
||||||
|
namespace injuries {
|
||||||
|
class DamageType;
|
||||||
|
class InjuryType;
|
||||||
|
class OpenWound;
|
||||||
|
}
|
||||||
|
|
||||||
|
class handleDamage
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
~handleDamage();
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static std::vector<injuries::OpenWound> HandleDamageWounds(const std::string& selectionName, signed int amountOfDamage, const std::string& typeOfDamage);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static void AddDamageType(const std::vector<std::string>& sqfDamageTypeDefinition);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static void AddInjuryType(const std::vector<std::string>& sqfInjuryDefinition);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static std::string SetInjuryTypeData(const std::string& data);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static int SelectionToNumber(const std::string& selectionName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static std::vector<std::shared_ptr<injuries::InjuryType>> GetInjuryInfoFor(const std::string& damageType);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static void FinalizeDefinitions();
|
||||||
|
|
||||||
|
private:
|
||||||
|
handleDamage();
|
||||||
|
|
||||||
|
static std::vector<std::shared_ptr<injuries::DamageType>> damageTypes;
|
||||||
|
static std::vector<std::shared_ptr<injuries::InjuryType>> injuryTypes;
|
||||||
|
static std::vector<std::string> selections;
|
||||||
|
static std::vector<std::string> hitPoints;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
57
extensions/medical/medical.cpp
Normal file
57
extensions/medical/medical.cpp
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* ace_medical.cpp
|
||||||
|
*
|
||||||
|
* Author:
|
||||||
|
* Glowbal
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ace_common.h"
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
#include "handleDamage.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
__declspec (dllexport) void __stdcall RVExtension(char *output, int outputSize, const char *function);
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<std::string> parseExtensionInput(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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void __stdcall RVExtension(char *output, int outputSize, const char *function) {
|
||||||
|
if (!strcmp(function, "version")) {
|
||||||
|
strncpy(output, ACE_FULL_VERSION_STR, outputSize);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::vector<std::string> 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';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user