diff --git a/CInterface/Library/GrowthRate.cpp b/CInterface/Library/GrowthRate.cpp new file mode 100644 index 0000000..a361108 --- /dev/null +++ b/CInterface/Library/GrowthRate.cpp @@ -0,0 +1,19 @@ +#include "../../src/Library/GrowthRates/GrowthRate.hpp" +#include "../../src/Library/GrowthRates/LookupGrowthRate.hpp" +#define export extern "C" +using namespace CreatureLib::Library; + +export GrowthRate* CreatureLib_LookupGrowthRate_Construct(uint32_t experiencePerLevel[], size_t count) { + std::vector exp(experiencePerLevel, experiencePerLevel + count); + return new LookupGrowthRate(exp); +}; + +export void CreatureLib_GrowthRate_Destruct(const GrowthRate* p) { delete p; } + +export uint8_t CreatureLib_GrowthRate_CalculateLevel(const GrowthRate* p, uint32_t experience) { + return p->CalculateLevel(experience); +} + +export uint32_t CreatureLib_GrowthRate_CalculateExperience(const GrowthRate* p, uint8_t level) { + return p->CalculateExperience(level); +} \ No newline at end of file diff --git a/src/Library/GrowthRates/LookupGrowthRate.hpp b/src/Library/GrowthRates/LookupGrowthRate.hpp index 58e5a75..53b626c 100644 --- a/src/Library/GrowthRates/LookupGrowthRate.hpp +++ b/src/Library/GrowthRates/LookupGrowthRate.hpp @@ -6,17 +6,11 @@ namespace CreatureLib::Library { class LookupGrowthRate : public GrowthRate { protected: - std::vector _experience = { - 0, 15, 52, 122, 237, 406, 637, 942, 1326, 1800, 2369, 3041, 3822, - 4719, 5737, 6881, 8155, 9564, 11111, 12800, 14632, 16610, 18737, 21012, 23437, 26012, - 28737, 31610, 34632, 37800, 41111, 44564, 48155, 51881, 55737, 59719, 63822, 68041, 72369, - 76800, 81326, 85942, 90637, 95406, 100237, 105122, 110052, 115015, 120001, 125000, 131324, 137795, - 144410, 151165, 158056, 165079, 172229, 179503, 186894, 194400, 202013, 209728, 217540, 225443, 233431, - 241496, 249633, 257834, 267406, 276458, 286328, 296358, 305767, 316074, 326531, 336255, 346965, 357812, - 367807, 378880, 390077, 400293, 411686, 423190, 433572, 445239, 457001, 467489, 479378, 491346, 501878, - 513934, 526049, 536557, 548720, 560922, 571333, 583539, 591882, 600000}; + std::vector _experience; public: + LookupGrowthRate(const std::vector& experience) : _experience(experience) {} + uint8_t CalculateLevel(uint32_t experience) const override { for (uint8_t i = 0; i < _experience.size(); i++) { if (_experience[i] > experience) { diff --git a/tests/TestLibrary/TestLibrary.cpp b/tests/TestLibrary/TestLibrary.cpp index 67b04d4..afa3361 100644 --- a/tests/TestLibrary/TestLibrary.cpp +++ b/tests/TestLibrary/TestLibrary.cpp @@ -51,7 +51,17 @@ ItemLibrary* TestLibrary::BuildItemLibrary() { GrowthRateLibrary* TestLibrary::BuildGrowthRateLibrary() { auto l = new GrowthRateLibrary(); - l->AddGrowthRate("testGrowthRate"_cnc, new LookupGrowthRate()); + l->AddGrowthRate( + "testGrowthRate"_cnc, + new LookupGrowthRate( + {0, 15, 52, 122, 237, 406, 637, 942, 1326, 1800, 2369, 3041, 3822, + 4719, 5737, 6881, 8155, 9564, 11111, 12800, 14632, 16610, 18737, 21012, 23437, 26012, + 28737, 31610, 34632, 37800, 41111, 44564, 48155, 51881, 55737, 59719, 63822, 68041, 72369, + 76800, 81326, 85942, 90637, 95406, 100237, 105122, 110052, 115015, 120001, 125000, 131324, 137795, + 144410, 151165, 158056, 165079, 172229, 179503, 186894, 194400, 202013, 209728, 217540, 225443, 233431, + 241496, 249633, 257834, 267406, 276458, 286328, 296358, 305767, 316074, 326531, 336255, 346965, 357812, + 367807, 378880, 390077, 400293, 411686, 423190, 433572, 445239, 457001, 467489, 479378, 491346, 501878, + 513934, 526049, 536557, 548720, 560922, 571333, 583539, 591882, 600000})); return l; }