CreatureLib/CInterface/Battling/Creature.cpp

104 lines
6.0 KiB
C++
Raw Normal View History

#include "../../src/Battling/Models/Creature.hpp"
#define export extern "C"
using namespace CreatureLib::Battling;
using ConstString = Arbutils::CaseInsensitiveConstString;
export Creature* CreatureLib_Creature_Construct(const BattleLibrary* library,
const CreatureLib::Library::CreatureSpecies* species,
const CreatureLib::Library::SpeciesVariant* variant, uint8_t level,
uint32_t experience, uint32_t uid, CreatureLib::Library::Gender gender,
uint8_t coloring, const CreatureLib::Library::Item* heldItem,
std::string nickname, bool secretTalent, const uint8_t talent,
LearnedAttack* attacks[], size_t attacksNum) {
auto attacksVec = std::vector<LearnedAttack*>(attacks, attacks + attacksNum);
return new Creature(library, species, variant, level, experience, uid, gender, coloring, heldItem, nickname,
CreatureLib::Library::TalentIndex(secretTalent, talent), attacksVec);
};
export void CreatureLib_Creature_Destruct(const Creature* p) { delete p; }
#define SIMPLE_GET_FUNC(type, name, returnType) \
export returnType CreatureLib_##type##_##name(const type* p) { return p->name(); }
SIMPLE_GET_FUNC(Creature, GetSpecies, const CreatureLib::Library::CreatureSpecies*);
SIMPLE_GET_FUNC(Creature, GetVariant, const CreatureLib::Library::SpeciesVariant*);
SIMPLE_GET_FUNC(Creature, GetLevel, uint8_t);
SIMPLE_GET_FUNC(Creature, GetExperience, uint32_t);
SIMPLE_GET_FUNC(Creature, GetGender, CreatureLib::Library::Gender);
SIMPLE_GET_FUNC(Creature, GetColoring, uint8_t);
export bool CreatureLib_Creature_HasHeldItem(const Creature* p, const char* name) {
return p->HasHeldItem(ConstString(name));
}
export bool CreatureLib_Creature_HasHeldItemWithHash(const Creature* p, uint32_t hash) { return p->HasHeldItem(hash); }
SIMPLE_GET_FUNC(Creature, GetHeldItem, const CreatureLib::Library::Item*);
export void CreatureLib_Creature_SetHeldItem(Creature* p, const char* name) {
return p->SetHeldItem(ConstString(name));
}
export void CreatureLib_Creature_SetHeldItemWithHash(Creature* p, uint32_t hash) { return p->SetHeldItem(hash); }
export void CreatureLib_Creature_SetHeldItemFromItem(Creature* p, const CreatureLib::Library::Item* item) {
return p->SetHeldItem(item);
}
SIMPLE_GET_FUNC(Creature, GetCurrentHealth, uint32_t);
SIMPLE_GET_FUNC(Creature, GetBattle, Battle*);
SIMPLE_GET_FUNC(Creature, GetBattleSide, BattleSide*);
SIMPLE_GET_FUNC(Creature, IsOnBattleField, bool);
export const char* CreatureLib_Creature_GetNickname(Creature* p) { return p->GetNickname().c_str(); }
export size_t CreatureLib_Creature_GetTypesCount(Creature* p) { return p->GetTypes().size(); }
export const uint8_t* CreatureLib_Creature_GetTypes(Creature* p) { return p->GetTypes().data(); }
export bool CreatureLib_Creature_HasType(Creature* p, uint8_t type) { return p->HasType(type); }
SIMPLE_GET_FUNC(Creature, GetMaxHealth, uint32_t);
export void CreatureLib_Creature_ChangeLevelBy(Creature* p, int8_t level) { return p->ChangeLevelBy(level); }
export void CreatureLib_Creature_Damage(Creature* p, uint32_t damage, DamageSource source) {
p->Damage(damage, source);
}
export void CreatureLib_Creature_Heal(Creature* p, uint32_t health, bool canRevive) { p->Heal(health, canRevive); }
export void CreatureLib_Creature_OverrideActiveTalent(Creature* p, const char* talent) {
p->OverrideActiveTalent(ConstString(talent));
}
export void CreatureLib_Creature_AddExperience(Creature* p, uint32_t experience) {
return p->AddExperience(experience);
}
export void CreatureLib_Creature_ClearVolatileScripts(Creature* p) { return p->ClearVolatileScripts(); }
export void CreatureLib_Creature_AddVolatileScriptByName(Creature* p, const char* scriptName) {
return p->AddVolatileScript(ConstString(scriptName));
}
export void CreatureLib_Creature_AddVolatileScript(Creature* p, Script* script) {
return p->AddVolatileScript(script);
}
export void CreatureLib_Creature_RemoveVolatileScriptByName(Creature* p, const char* scriptName) {
return p->RemoveVolatileScript(ConstString(scriptName));
}
export void CreatureLib_Creature_RemoveVolatileScript(Creature* p, Script* script) {
return p->RemoveVolatileScript(script);
}
export bool CreatureLib_Creature_HasVolatileScript(Creature* p, const char* scriptName) {
return p->HasVolatileScript(ConstString(scriptName));
}
export size_t CreatureLib_Creature_GetAttacksCount(Creature* p) { return p->GetAttacks().size(); }
export LearnedAttack** CreatureLib_Creature_GetAttacks(Creature* p) { return p->GetAttacks().data(); }
SIMPLE_GET_FUNC(Creature, GetDisplaySpecies, const CreatureLib::Library::CreatureSpecies*);
SIMPLE_GET_FUNC(Creature, GetDisplayVariant, const CreatureLib::Library::SpeciesVariant*);
export void CreatureLib_Creature_SetDisplaySpecies(Creature* p, const CreatureLib::Library::CreatureSpecies* species) {
return p->SetDisplaySpecies(species);
}
export void CreatureLib_Creature_SetDisplayVariant(Creature* p, const CreatureLib::Library::SpeciesVariant* variant) {
return p->SetDisplayVariant(variant);
}
export void CreatureLib_Creature_ChangeStatBoost(Creature* p, CreatureLib::Library::Statistic stat, int8_t diffAmount) {
p->ChangeStatBoost(stat, diffAmount);
}
export uint32_t CreatureLib_Creature_GetFlatStat(Creature* p, CreatureLib::Library::Statistic stat) {
return p->GetFlatStat(stat);
}
export uint32_t CreatureLib_Creature_GetBoostedStat(Creature* p, CreatureLib::Library::Statistic stat) {
return p->GetBoostedStat(stat);
}
export uint32_t CreatureLib_Creature_GetBaseStat(Creature* p, CreatureLib::Library::Statistic stat) {
return p->GetBaseStat(stat);
}
export int8_t CreatureLib_Creature_GetStatBoost(Creature* p, CreatureLib::Library::Statistic stat) {
return p->GetStatBoost(stat);
}
#undef SIMPLE_GET_FUNC