From f95c625971068920a93fd340e96866f0de8f8fea Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 29 Feb 2020 16:06:47 +0100 Subject: [PATCH] C interfaces for GrowthRateLibrary and TypeLibrary/ --- CInterface/Library/GrowthRateLibrary.cpp | 39 ++++++++++++++++++++++++ CInterface/Library/TypeLibrary.cpp | 37 ++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 CInterface/Library/GrowthRateLibrary.cpp create mode 100644 CInterface/Library/TypeLibrary.cpp diff --git a/CInterface/Library/GrowthRateLibrary.cpp b/CInterface/Library/GrowthRateLibrary.cpp new file mode 100644 index 0000000..74ddb0f --- /dev/null +++ b/CInterface/Library/GrowthRateLibrary.cpp @@ -0,0 +1,39 @@ +#include "../../src/Library/GrowthRates/GrowthRateLibrary.hpp" +#define export extern "C" + +export CreatureLib::Library::GrowthRateLibrary* CreatureLib_GrowthRateLibrary_Construct(size_t initialCapacity) { + return new CreatureLib::Library::GrowthRateLibrary(initialCapacity); +} + +export void CreatureLib_GrowthRateLibrary_Destruct(CreatureLib::Library::GrowthRateLibrary* p) { delete p; } + +export uint8_t CreatureLib_GrowthRateLibrary_CalculateLevel(CreatureLib::Library::GrowthRateLibrary* library, + const char* growthRate, uint32_t experience) { + return library->CalculateLevel(Arbutils::CaseInsensitiveConstString::GetHash(growthRate), experience); +} +export uint8_t CreatureLib_GrowthRateLibrary_CalculateLevelWithHash(CreatureLib::Library::GrowthRateLibrary* library, + uint32_t growthRateHash, uint32_t experience) { + return library->CalculateLevel(growthRateHash, experience); +} + +export uint32_t CreatureLib_GrowthRateLibrary_CalculateExperience(CreatureLib::Library::GrowthRateLibrary* library, + const char* growthRate, uint8_t level) { + return library->CalculateExperience(Arbutils::CaseInsensitiveConstString::GetHash(growthRate), level); +} + +export uint32_t +CreatureLib_GrowthRateLibrary_CalculateExperienceWithHash(CreatureLib::Library::GrowthRateLibrary* library, + uint32_t growthRateHash, uint8_t level) { + return library->CalculateExperience(growthRateHash, level); +} +export void CreatureLib_GrowthRateLibrary_AddGrowthRate(CreatureLib::Library::GrowthRateLibrary* library, + const char* growthRateName, + CreatureLib::Library::GrowthRate* growthRate) { + return library->AddGrowthRate(Arbutils::CaseInsensitiveConstString::GetHash(growthRateName), growthRate); +} + +export void CreatureLib_GrowthRateLibrary_AddGrowthRateWithHash(CreatureLib::Library::GrowthRateLibrary* library, + uint32_t growthRateHash, + CreatureLib::Library::GrowthRate* growthRate) { + return library->AddGrowthRate(growthRateHash, growthRate); +} diff --git a/CInterface/Library/TypeLibrary.cpp b/CInterface/Library/TypeLibrary.cpp new file mode 100644 index 0000000..b2e1e6c --- /dev/null +++ b/CInterface/Library/TypeLibrary.cpp @@ -0,0 +1,37 @@ +#include "../../src/Library/TypeLibrary.hpp" +#define export extern "C" + +export CreatureLib::Library::TypeLibrary* CreatureLib_TypeLibrary_Construct(size_t initialCapacity) { + return new CreatureLib::Library::TypeLibrary(initialCapacity); +}; + +export void CreatureLib_TypeLibrary_Destruct(const CreatureLib::Library::TypeLibrary* p) { delete p; } + +export uint8_t CreatureLib_TypeLibrary_GetTypeId(const CreatureLib::Library::TypeLibrary* p, const char* type) { + return p->GetTypeId(Arbutils::CaseInsensitiveConstString::GetHash(type)); +} +export uint8_t CreatureLib_TypeLibrary_GetTypeIdWithHash(const CreatureLib::Library::TypeLibrary* p, uint32_t type) { + return p->GetTypeId(type); +} + +export uint8_t CreatureLib_TypeLibrary_RegisterType(CreatureLib::Library::TypeLibrary* p, const char* type) { + return p->RegisterType(Arbutils::CaseInsensitiveConstString::GetHash(type)); +} +export uint8_t CreatureLib_TypeLibrary_RegisterTypeWithHash(CreatureLib::Library::TypeLibrary* p, uint32_t type) { + return p->RegisterType(type); +} + +export void CreatureLib_TypeLibrary_SetEffectiveness(CreatureLib::Library::TypeLibrary* p, uint8_t attacking, + uint8_t defensive, float effectiveness) { + p->SetEffectiveness(attacking, defensive, effectiveness); +} + +export float CreatureLib_TypeLibrary_GetSingleEffectiveness(CreatureLib::Library::TypeLibrary* p, uint8_t attacking, + uint8_t defensive) { + return p->GetSingleEffectiveness(attacking, defensive); +} + +export float CreatureLib_TypeLibrary_GetEffectiveness(CreatureLib::Library::TypeLibrary* p, uint8_t attacking, + uint8_t defensive[], size_t defensiveCount) { + return p->GetEffectiveness(attacking, std::vector(defensive, defensive + defensiveCount)); +}