CreatureLib/CInterface/Library/SpeciesVariant.cpp

57 lines
3.0 KiB
C++

#include "../../src/Library/CreatureData/SpeciesVariant.hpp"
#include "../Core.hpp"
using namespace CreatureLib::Library;
export_func SpeciesVariant* CreatureLib_SpeciesVariant_Construct(
const char* name, float height, float weight, u32 baseExperience, u8 types[], size_t typeLength, u16 baseHealth,
u16 baseAttack, u16 baseDefense, u16 baseMagicalAttack, u16 baseMagicalDefense, u16 baseSpeed,
const Talent* talents[], size_t talentsLength, const Talent* secretTalents[], size_t secretTalentsLength,
const LearnableAttacks* attacks, const char* flags[], size_t flagsCount) {
std::unordered_set<u32> conversedFlags(flagsCount);
for (size_t i = 0; i < flagsCount; i++) {
conversedFlags.insert(ArbUt::StringView::CalculateHash(flags[i]));
}
auto talentsWrapped = ArbUt::List<ArbUt::BorrowedPtr<const Talent>>(talentsLength);
for (size_t i = 0; i < talentsLength; i++) {
talentsWrapped.Append(talents[i]);
}
auto secretTalentsWrapped = ArbUt::List<ArbUt::BorrowedPtr<const Talent>>(secretTalentsLength);
for (size_t i = 0; i < secretTalentsLength; i++) {
secretTalentsWrapped.Append(secretTalents[i]);
}
return new SpeciesVariant(ArbUt::StringView(name), height, weight, baseExperience,
ArbUt::List<u8>(types, types + typeLength),
CreatureLib::Library::StatisticSet<u16>(baseHealth, baseAttack, baseDefense,
baseMagicalAttack, baseMagicalDefense, baseSpeed),
talentsWrapped, secretTalentsWrapped, attacks, conversedFlags);
}
export_func void CreatureLib_SpeciesVariant_Destruct(SpeciesVariant* p) { delete p; }
export_func const char* CreatureLib_SpeciesVariant_GetName(SpeciesVariant* p) { return p->GetName().c_str(); }
SIMPLE_GET_FUNC(SpeciesVariant, GetHeight, float);
SIMPLE_GET_FUNC(SpeciesVariant, GetWeight, float);
SIMPLE_GET_FUNC(SpeciesVariant, GetBaseExperience, u32);
SIMPLE_GET_FUNC(SpeciesVariant, GetTypeCount, size_t);
export_func u8 CreatureLib_SpeciesVariant_GetType(SpeciesVariant* p, size_t index) { return p->GetType(index); }
export_func u16 CreatureLib_SpeciesVariant_GetStatistic(SpeciesVariant* p, CreatureLib::Library::Statistic stat) {
return p->GetStatistic(stat);
}
SIMPLE_GET_FUNC(SpeciesVariant, GetTalentCount, size_t);
SIMPLE_GET_FUNC(SpeciesVariant, GetSecretTalentCount, size_t);
export_func u8 CreatureLib_SpeciesVariant_GetTalent(SpeciesVariant* p, bool secret, u8 index, const Talent*& out) {
Try(out = p->GetTalent(TalentIndex(secret, index)).GetRaw();)
}
export_func const LearnableAttacks* CreatureLib_SpeciesVariant_GetLearnableAttacks(SpeciesVariant* p) {
return p->GetLearnableAttacks().GetRaw();
}
export_func u8 CreatureLib_SpeciesVariant_GetRandomTalent(SpeciesVariant* p, ArbUt::Random* rand) {
return p->GetRandomTalent(*rand).GetIndex();
}
export_func bool CreatureLib_SpeciesVariant_HasFlag(const SpeciesVariant* p, const char* key) {
return p->HasFlag(ArbUt::StringView::CalculateHash(key));
}