ACE3/extensions/medical/medical.cpp

91 lines
3.2 KiB
C++
Raw Normal View History

2015-05-03 22:02:39 +00:00
/*
* ace_medical.cpp
*
* Author:
* Glowbal
*/
#include "shared.hpp"
2016-02-17 22:26:14 +00:00
#include <stdlib.h>
2015-05-03 22:02:39 +00:00
#include <vector>
#include <string>
#include <sstream>
#include "handleDamage.h"
2015-05-16 21:20:17 +00:00
#include "OpenWound.h"
2015-05-03 22:02:39 +00:00
extern "C" {
EXPORT void __stdcall RVExtension(char *output, int outputSize, const char *function);
}
2015-05-03 22:02:39 +00:00
std::vector<std::string> parseExtensionInput(const std::string& input)
{
2015-05-03 22:32:44 +00:00
std::istringstream ss(input);
std::string token;
std::vector<std::string> output;
while (std::getline(ss, token, ',')) {
output.push_back(token);
}
return output;
2015-05-03 22:02:39 +00:00
}
void __stdcall RVExtension(char *output, int outputSize, const char *function) {
2015-05-03 22:32:44 +00:00
if (!strcmp(function, "version")) {
2016-02-17 22:26:14 +00:00
strncpy_s(output, outputSize, ACE_FULL_VERSION_STR, _TRUNCATE);
2015-05-03 22:32:44 +00:00
}
2016-02-17 22:26:14 +00:00
else
2015-05-03 22:32:44 +00:00
{
2015-05-16 21:20:17 +00:00
std::string returnValue = "";
2015-05-03 22:32:44 +00:00
std::vector<std::string> arguments = parseExtensionInput(function);
2016-02-17 22:26:14 +00:00
if (arguments.size() > 0)
2015-05-03 22:32:44 +00:00
{
try {
std::string command = arguments.at(0);
arguments.erase(arguments.begin());
if (command == "addInjuryType") {
returnValue = ace::medical::handleDamage::GetInstance().AddInjuryType(arguments);
}
else if (command == "addDamageType") {
returnValue = ace::medical::handleDamage::GetInstance().AddDamageType(arguments);
}
else if (command == "HandleDamageWounds") {
if (arguments.size() >= 4) {
std::string selectionName = arguments.at(0);
double amountOfDamage = std::stod(arguments.at(1));
std::string typeOfDamage = arguments.at(2);
int woundID = std::stoi(arguments.at(3));
returnValue = ace::medical::handleDamage::GetInstance().HandleDamageWounds(selectionName, amountOfDamage, typeOfDamage, woundID);
}
}
else if (command == "ConfigComplete") {
ace::medical::handleDamage::GetInstance().FinalizeDefinitions();
}
2015-05-16 21:20:17 +00:00
}
catch (std::exception e) {
std::stringstream debugreturn;
debugreturn << "diag_log format['ACE3 ERROR - Medical Extension: Something went wrong. Input: '];";
int i = 0;
for (auto arg : arguments) {
debugreturn << "diag_log format[' arg " << i++ << ":" << arg << "'];";
2015-05-16 21:20:17 +00:00
}
debugreturn << "diag_log format['Exception: " << e.what() << "'];";
returnValue = debugreturn.str();
2015-05-03 22:32:44 +00:00
}
catch (...) {
std::stringstream debugreturn;
debugreturn << "diag_log format['ACE3 ERROR - Medical Extension: Something went wrong. Input: '];";
int i = 0;
for (auto arg : arguments) {
debugreturn << "diag_log format[' arg " << i++ << ":" << arg << "'];";
}
returnValue = debugreturn.str();
2015-05-03 22:32:44 +00:00
}
}
2016-02-17 22:26:14 +00:00
strncpy_s(output, outputSize, returnValue.c_str(), _TRUNCATE);
2015-05-03 22:32:44 +00:00
}
2015-05-03 22:02:39 +00:00
}