Rework for C Interfaces to handle exceptions a bit better.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-03-25 19:07:36 +01:00
parent 27288563cd
commit 7ce3e6940d
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
53 changed files with 7526 additions and 8340 deletions

View File

@ -1,39 +1,45 @@
#include "../../src/Battling/Models/Battle.hpp" #include "../../src/Battling/Models/Battle.hpp"
#define export extern "C" #include "../Core.hpp"
using namespace CreatureLib::Battling; using namespace CreatureLib::Battling;
export Battle* CreatureLib_Battle_Construct(const BattleLibrary* library, BattleParty* partyArr[], export uint8_t CreatureLib_Battle_Construct(Battle*& out, const BattleLibrary* library, BattleParty* partyArr[],
size_t numberOfParties, bool canFlee, uint8_t numberOfSides, size_t numberOfParties, bool canFlee, uint8_t numberOfSides,
uint8_t creaturesPerSide) { uint8_t creaturesPerSide) {
List<BattleParty*> parties(partyArr, partyArr + numberOfParties); Try(List<BattleParty*> parties(partyArr, partyArr + numberOfParties);
return new Battle(library, parties, canFlee, numberOfSides, creaturesPerSide); out = new Battle(library, parties, canFlee, numberOfSides, creaturesPerSide);)
} }
export void CreatureLib_Battle_Destruct(const Battle* p) { delete p; } export void CreatureLib_Battle_Destruct(const Battle* p) { delete p; }
export const BattleLibrary* CreatureLib_Battle_GetLibrary(const Battle* p) { return p->GetLibrary(); } export const BattleLibrary* CreatureLib_Battle_GetLibrary(const Battle* p) { return p->GetLibrary(); }
export bool CreatureLib_Battle_CanUse(Battle* p, const BaseTurnChoice* turnChoice) { return p->CanUse(turnChoice); } export uint8_t CreatureLib_Battle_CanUse(bool& out, Battle* p, const BaseTurnChoice* turnChoice) {
export bool CreatureLib_Battle_TrySetChoice(Battle* p, BaseTurnChoice* turnChoice) { Try(out = p->CanUse(turnChoice);)
return p->TrySetChoice(turnChoice); }
export uint8_t CreatureLib_Battle_TrySetChoice(bool& out, Battle* p, BaseTurnChoice* turnChoice) {
Try(out = p->TrySetChoice(turnChoice);)
} }
export bool CreatureLib_Battle_CanFlee(const Battle* p) { return p->CanFlee(); } export bool CreatureLib_Battle_CanFlee(const Battle* p) { return p->CanFlee(); }
export void CreatureLib_Battle_CheckChoicesSetAndRun(Battle* p) { p->CheckChoicesSetAndRun(); } export uint8_t CreatureLib_Battle_CheckChoicesSetAndRun(Battle* p) { Try(p->CheckChoicesSetAndRun();) }
export ChoiceQueue* CreatureLib_Battle_GetCurrentTurnQueue(const Battle* p) { return p->GetCurrentTurnQueue(); } export ChoiceQueue* CreatureLib_Battle_GetCurrentTurnQueue(const Battle* p) { return p->GetCurrentTurnQueue(); }
export BattleRandom* CreatureLib_Battle_GetRandom(Battle* p) { return p->GetRandom(); } export BattleRandom* CreatureLib_Battle_GetRandom(Battle* p) { return p->GetRandom(); }
export bool CreatureLib_Battle_CreatureInField(const Battle* p, Creature* c) { return p->CreatureInField(c); } export uint8_t CreatureLib_Battle_CreatureInField(bool& out, const Battle* p, Creature* c) {
export Creature* CreatureLib_Battle_GetCreature(const Battle* p, uint8_t side, uint8_t target) { Try(out = p->CreatureInField(c);)
return p->GetCreature(side, target); }
export uint8_t CreatureLib_Battle_GetCreature(Creature*& out, const Battle* p, uint8_t side, uint8_t target) {
Try(out = p->GetCreature(side, target);)
} }
export void CreatureLib_Battle_ForceRecall(Battle* p, uint8_t side, uint8_t target) { p->ForceRecall(side, target); } export uint8_t CreatureLib_Battle_ForceRecall(Battle* p, uint8_t side, uint8_t target) {
export void CreatureLib_Battle_SwitchCreature(Battle* p, uint8_t side, uint8_t target, Creature* c) { Try(p->ForceRecall(side, target);)
p->SwitchCreature(side, target, c);
} }
export bool CreatureLib_Battle_CanSlotBeFilled(const Battle* p, uint8_t side, uint8_t target) { export uint8_t CreatureLib_Battle_SwitchCreature(Battle* p, uint8_t side, uint8_t target, Creature* c) {
return p->CanSlotBeFilled(side, target); Try(p->SwitchCreature(side, target, c);)
} }
export void CreatureLib_Battle_ValidateBattleState(Battle* p) { p->ValidateBattleState(); } export uint8_t CreatureLib_Battle_CanSlotBeFilled(bool& out, const Battle* p, uint8_t side, uint8_t target) {
Try(out = p->CanSlotBeFilled(side, target);)
}
export uint8_t CreatureLib_Battle_ValidateBattleState(Battle* p) { Try(p->ValidateBattleState();) }
export bool CreatureLib_Battle_HasEnded(const Battle* p) { return p->HasEnded(); } export bool CreatureLib_Battle_HasEnded(const Battle* p) { return p->HasEnded(); }
export bool CreatureLib_Battle_HasConclusiveResult(const Battle* p) { return p->GetResult().IsConclusiveResult(); } export bool CreatureLib_Battle_HasConclusiveResult(const Battle* p) { return p->GetResult().IsConclusiveResult(); }
@ -45,22 +51,24 @@ export BattleSide* const* CreatureLib_Battle_GetSides(const Battle* p) { return
export Script* CreatureLib_Battle_GetVolatileScript(Battle* p, const char* key) { export Script* CreatureLib_Battle_GetVolatileScript(Battle* p, const char* key) {
return p->GetVolatileScript(ConstString::GetHash(key)); return p->GetVolatileScript(ConstString::GetHash(key));
} }
export void CreatureLib_Battle_AddVolatileScriptByName(Battle* p, const char* key) { export uint8_t CreatureLib_Battle_AddVolatileScriptByName(Battle* p, const char* key) {
p->AddVolatileScript(ConstString(key)); Try(p->AddVolatileScript(ConstString(key));)
} }
export void CreatureLib_Battle_AddVolatileScript(Battle* p, Script* script) { p->AddVolatileScript(script); } export uint8_t CreatureLib_Battle_AddVolatileScript(Battle* p, Script* script) { Try(p->AddVolatileScript(script);) }
export void CreatureLib_Battle_RemoveVolatileScript(Battle* p, const char* key) { export uint8_t CreatureLib_Battle_RemoveVolatileScript(Battle* p, const char* key) {
p->RemoveVolatileScript(ConstString::GetHash(key)); Try(p->RemoveVolatileScript(ConstString::GetHash(key));)
} }
export void CreatureLib_Battle_RemoveVolatileScriptWithScript(Battle* p, Script* script) { export uint8_t CreatureLib_Battle_RemoveVolatileScriptWithScript(Battle* p, Script* script) {
p->RemoveVolatileScript(script); Try(p->RemoveVolatileScript(script);)
} }
export bool CreatureLib_Battle_HasVolatileScript(Battle* p, const char* key) { export bool CreatureLib_Battle_HasVolatileScript(Battle* p, const char* key) {
return p->HasVolatileScript(ConstString::GetHash(key)); return p->HasVolatileScript(ConstString::GetHash(key));
} }
export void CreatureLib_Battle_RegisterEventListener(Battle* p, void (*func)(const EventData*)) { export uint8_t CreatureLib_Battle_RegisterEventListener(Battle* p, void (*func)(const EventData*)) {
p->RegisterEventListener(func); Try(p->RegisterEventListener(func);)
}
export uint8_t CreatureLib_Battle_TriggerEventListener(Battle* p, EventData* data) {
Try(p->TriggerEventListener(data);)
} }
export void CreatureLib_Battle_TriggerEventListener(Battle* p, EventData* data) { p->TriggerEventListener(data); }

View File

@ -1,5 +1,5 @@
#include "../../src/Battling/Library/BattleLibrary.hpp" #include "../../src/Battling/Library/BattleLibrary.hpp"
#define export extern "C" #include "../Core.hpp"
using namespace CreatureLib::Battling; using namespace CreatureLib::Battling;
export const BattleLibrary* CreatureLib_BattleLibrary_Construct(const CreatureLib::Library::DataLibrary* staticLib, export const BattleLibrary* CreatureLib_BattleLibrary_Construct(const CreatureLib::Library::DataLibrary* staticLib,

View File

@ -1,22 +1,22 @@
#include "../../src/Battling/Models/BattleParty.hpp" #include "../../src/Battling/Models/BattleParty.hpp"
#define export extern "C" #include "../Core.hpp"
using namespace CreatureLib::Battling; using namespace CreatureLib::Battling;
// Note that creatureIndices should be twice the size of numberOfIndices, and have index of side, index of creature on // Note that creatureIndices should be twice the size of numberOfIndices, and have index of side, index of creature on
// side, one after the other. // side, one after the other.
export BattleParty* CreatureLib_BattleParty_Construct(CreatureParty* p, uint8_t creatureIndices[], export uint8_t CreatureLib_BattleParty_Construct(BattleParty*& out, CreatureParty* p, uint8_t creatureIndices[],
size_t numberOfIndices) { size_t numberOfIndices) {
Arbutils::Collections::List<CreatureIndex> indices(numberOfIndices); Try(Arbutils::Collections::List<CreatureIndex> indices(numberOfIndices);
for (size_t i = 0; i < numberOfIndices; i++) { for (size_t i = 0; i < numberOfIndices; i++) {
indices[i] = CreatureIndex(creatureIndices[i * 2], creatureIndices[i * 2 + 1]); indices[i] = CreatureIndex(creatureIndices[i * 2], creatureIndices[i * 2 + 1]);
} } out = new BattleParty(p, indices);)
return new BattleParty(p, indices);
} }
export void CreatureLib_BattleParty_Destruct(const BattleParty* p) { delete p; } export void CreatureLib_BattleParty_Destruct(const BattleParty* p) { delete p; }
export bool CreatureLib_BattleParty_IsResponsibleForIndex(const BattleParty* p, uint8_t side, uint8_t creature) { export uint8_t CreatureLib_BattleParty_IsResponsibleForIndex(bool& out, const BattleParty* p, uint8_t side,
return p->IsResponsibleForIndex(side, creature); uint8_t creature) {
Try(out = p->IsResponsibleForIndex(side, creature);)
} }
export bool CreatureLib_BattleParty_HasCreaturesNotInField(const BattleParty* p) { return p->HasCreaturesNotInField(); } export bool CreatureLib_BattleParty_HasCreaturesNotInField(const BattleParty* p) { return p->HasCreaturesNotInField(); }

View File

@ -1,16 +1,18 @@
#include "../../src/Battling/Library/BattleStatCalculator.hpp" #include "../../src/Battling/Library/BattleStatCalculator.hpp"
#define export extern "C" #include "../Core.hpp"
using namespace CreatureLib::Battling; using namespace CreatureLib::Battling;
export const BattleStatCalculator* CreatureLib_BattleStatCalculator_Construct() { return new BattleStatCalculator(); } export const BattleStatCalculator* CreatureLib_BattleStatCalculator_Construct() { return new BattleStatCalculator(); }
export void CreatureLib_BattleStatCalculator_Destruct(const BattleStatCalculator* p) { delete p; } export void CreatureLib_BattleStatCalculator_Destruct(const BattleStatCalculator* p) { delete p; }
export uint32_t CreatureLib_BattleStatCalculator_CalculateFlatStat(const BattleStatCalculator* p, Creature* creature, export uint8_t CreatureLib_BattleStatCalculator_CalculateFlatStat(uint32_t& out, const BattleStatCalculator* p,
CreatureLib::Library::Statistic stat) { Creature* creature,
return p->CalculateFlatStat(creature, stat); CreatureLib::Library::Statistic stat) {
Try(out = p->CalculateFlatStat(creature, stat);)
} }
export uint32_t CreatureLib_BattleStatCalculator_CalculateBoostedStat(const BattleStatCalculator* p, Creature* creature, export uint8_t CreatureLib_BattleStatCalculator_CalculateBoostedStat(uint32_t& out, const BattleStatCalculator* p,
CreatureLib::Library::Statistic stat) { Creature* creature,
return p->CalculateBoostedStat(creature, stat); CreatureLib::Library::Statistic stat) {
Try(out = p->CalculateBoostedStat(creature, stat);)
} }

View File

@ -1,18 +1,18 @@
#include "../../src/Battling/Models/Creature.hpp" #include "../../src/Battling/Models/Creature.hpp"
#define export extern "C" #include "../Core.hpp"
using namespace CreatureLib::Battling; using namespace CreatureLib::Battling;
using ConstString = Arbutils::CaseInsensitiveConstString; using ConstString = Arbutils::CaseInsensitiveConstString;
export Creature* CreatureLib_Creature_Construct(const BattleLibrary* library, export uint8_t CreatureLib_Creature_Construct(Creature*& out, const BattleLibrary* library,
const CreatureLib::Library::CreatureSpecies* species, const CreatureLib::Library::CreatureSpecies* species,
const CreatureLib::Library::SpeciesVariant* variant, uint8_t level, const CreatureLib::Library::SpeciesVariant* variant, uint8_t level,
uint32_t experience, uint32_t uid, CreatureLib::Library::Gender gender, uint32_t experience, uint32_t uid, CreatureLib::Library::Gender gender,
uint8_t coloring, const CreatureLib::Library::Item* heldItem, uint8_t coloring, const CreatureLib::Library::Item* heldItem,
std::string nickname, bool secretTalent, const uint8_t talent, std::string nickname, bool secretTalent, const uint8_t talent,
LearnedAttack* attacks[], size_t attacksNum) { LearnedAttack* attacks[], size_t attacksNum) {
auto attacksVec = List<LearnedAttack*>(attacks, attacks + attacksNum); Try(auto attacksVec = List<LearnedAttack*>(attacks, attacks + attacksNum);
return new Creature(library, species, variant, level, experience, uid, gender, coloring, heldItem, nickname, out = new Creature(library, species, variant, level, experience, uid, gender, coloring, heldItem, nickname,
CreatureLib::Library::TalentIndex(secretTalent, talent), attacksVec); CreatureLib::Library::TalentIndex(secretTalent, talent), attacksVec);)
}; };
export void CreatureLib_Creature_Destruct(const Creature* p) { delete p; } export void CreatureLib_Creature_Destruct(const Creature* p) { delete p; }
@ -32,10 +32,10 @@ export bool CreatureLib_Creature_HasHeldItem(const Creature* p, const char* name
} }
export bool CreatureLib_Creature_HasHeldItemWithHash(const Creature* p, uint32_t hash) { return p->HasHeldItem(hash); } export bool CreatureLib_Creature_HasHeldItemWithHash(const Creature* p, uint32_t hash) { return p->HasHeldItem(hash); }
SIMPLE_GET_FUNC(Creature, GetHeldItem, const CreatureLib::Library::Item*); SIMPLE_GET_FUNC(Creature, GetHeldItem, const CreatureLib::Library::Item*);
export void CreatureLib_Creature_SetHeldItem(Creature* p, const char* name) { export uint8_t CreatureLib_Creature_SetHeldItem(Creature* p, const char* name) {
return p->SetHeldItem(ConstString(name)); Try(p->SetHeldItem(ConstString(name));)
} }
export void CreatureLib_Creature_SetHeldItemWithHash(Creature* p, uint32_t hash) { return p->SetHeldItem(hash); } export uint8_t CreatureLib_Creature_SetHeldItemWithHash(Creature* p, uint32_t hash) { Try(p->SetHeldItem(hash);) }
export void CreatureLib_Creature_SetHeldItemFromItem(Creature* p, const CreatureLib::Library::Item* item) { export void CreatureLib_Creature_SetHeldItemFromItem(Creature* p, const CreatureLib::Library::Item* item) {
return p->SetHeldItem(item); return p->SetHeldItem(item);
} }
@ -48,28 +48,31 @@ export size_t CreatureLib_Creature_GetTypesCount(Creature* p) { return p->GetTyp
export const uint8_t* CreatureLib_Creature_GetTypes(Creature* p) { return p->GetTypes().RawData(); } export const uint8_t* CreatureLib_Creature_GetTypes(Creature* p) { return p->GetTypes().RawData(); }
export bool CreatureLib_Creature_HasType(Creature* p, uint8_t type) { return p->HasType(type); } export bool CreatureLib_Creature_HasType(Creature* p, uint8_t type) { return p->HasType(type); }
SIMPLE_GET_FUNC(Creature, GetMaxHealth, uint32_t); SIMPLE_GET_FUNC(Creature, GetMaxHealth, uint32_t);
export void CreatureLib_Creature_ChangeLevelBy(Creature* p, int8_t level) { return p->ChangeLevelBy(level); } export uint8_t CreatureLib_Creature_ChangeLevelBy(Creature* p, int8_t level) { Try(p->ChangeLevelBy(level);) }
export void CreatureLib_Creature_Damage(Creature* p, uint32_t damage, DamageSource source) { export uint8_t CreatureLib_Creature_Damage(Creature* p, uint32_t damage, DamageSource source) {
p->Damage(damage, source); Try(p->Damage(damage, source);)
} }
export void CreatureLib_Creature_Heal(Creature* p, uint32_t health, bool canRevive) { p->Heal(health, canRevive); } export uint8_t CreatureLib_Creature_Heal(Creature* p, uint32_t health, bool canRevive) {
export void CreatureLib_Creature_OverrideActiveTalent(Creature* p, const char* talent) { Try(p->Heal(health, canRevive);)
p->OverrideActiveTalent(ConstString(talent));
} }
export void CreatureLib_Creature_AddExperience(Creature* p, uint32_t experience) { export uint8_t CreatureLib_Creature_OverrideActiveTalent(Creature* p, const char* talent) {
return p->AddExperience(experience); Try(p->OverrideActiveTalent(ConstString(talent));)
} }
export void CreatureLib_Creature_ClearVolatileScripts(Creature* p) { return p->ClearVolatileScripts(); } export uint8_t CreatureLib_Creature_AddExperience(Creature* p, uint32_t experience) {
export void CreatureLib_Creature_AddVolatileScriptByName(Creature* p, const char* scriptName) { Try(p->AddExperience(experience);)
return p->AddVolatileScript(ConstString(scriptName));
} }
export void CreatureLib_Creature_AddVolatileScript(Creature* p, Script* script) { export uint8_t CreatureLib_Creature_ClearVolatileScripts(Creature* p) { Try(p->ClearVolatileScripts();) }
return p->AddVolatileScript(script); } export uint8_t CreatureLib_Creature_AddVolatileScriptByName(Creature* p, const char* scriptName) {
export void CreatureLib_Creature_RemoveVolatileScriptByName(Creature* p, const char* scriptName) { Try(p->AddVolatileScript(ConstString(scriptName));)
return p->RemoveVolatileScript(ConstString(scriptName));
} }
export void CreatureLib_Creature_RemoveVolatileScript(Creature* p, Script* script) { export uint8_t CreatureLib_Creature_AddVolatileScript(Creature* p, Script* script) {
return p->RemoveVolatileScript(script); Try(p->AddVolatileScript(script);)
}
export uint8_t CreatureLib_Creature_RemoveVolatileScriptByName(Creature* p, const char* scriptName) {
Try(p->RemoveVolatileScript(ConstString(scriptName));)
}
export uint8_t CreatureLib_Creature_RemoveVolatileScript(Creature* p, Script* script) {
Try(p->RemoveVolatileScript(script);)
} }
export bool CreatureLib_Creature_HasVolatileScript(Creature* p, const char* scriptName) { export bool CreatureLib_Creature_HasVolatileScript(Creature* p, const char* scriptName) {
return p->HasVolatileScript(ConstString(scriptName)); return p->HasVolatileScript(ConstString(scriptName));

View File

@ -1,5 +1,5 @@
#include "../../src/Battling/Models/CreatureParty.hpp" #include "../../src/Battling/Models/CreatureParty.hpp"
#define export extern "C" #include "../Core.hpp"
using namespace CreatureLib::Battling; using namespace CreatureLib::Battling;
export CreatureParty* CreatureLib_CreatureParty_ConstructWithSize(size_t size) { return new CreatureParty(size); } export CreatureParty* CreatureLib_CreatureParty_ConstructWithSize(size_t size) { return new CreatureParty(size); }
@ -9,11 +9,11 @@ export CreatureParty* CreatureLib_CreatureParty_ConstructFromArray(Creature* cre
export void CreatureLib_CreatureParty_Destruct(const CreatureParty* p) { delete p; } export void CreatureLib_CreatureParty_Destruct(const CreatureParty* p) { delete p; }
export Creature* CreatureLib_CreatureParty_GetAtIndex(const CreatureParty* p, size_t index) { export uint8_t CreatureLib_CreatureParty_GetAtIndex(Creature*& out, const CreatureParty* p, size_t index) {
return p->GetAtIndex(index); Try(out = p->GetAtIndex(index);)
} }
export void CreatureLib_CreatureParty_Switch(CreatureParty* p, size_t a, size_t b) { p->Switch(a, b); } export uint8_t CreatureLib_CreatureParty_Switch(CreatureParty* p, size_t a, size_t b) { Try(p->Switch(a, b);) }
export bool CreatureLib_CreatureParty_HasAvailableCreatures(const CreatureParty* p) { export bool CreatureLib_CreatureParty_HasAvailableCreatures(const CreatureParty* p) {
return p->HasAvailableCreatures(); return p->HasAvailableCreatures();

View File

@ -1,25 +1,25 @@
#include "../../src/Battling/Library/DamageLibrary.hpp" #include "../../src/Battling/Library/DamageLibrary.hpp"
#define export extern "C" #include "../Core.hpp"
using namespace CreatureLib::Battling; using namespace CreatureLib::Battling;
export const DamageLibrary* CreatureLib_DamageLibrary_Construct() { return new DamageLibrary(); } export const DamageLibrary* CreatureLib_DamageLibrary_Construct() { return new DamageLibrary(); }
export void CreatureLib_DamageLibrary_Destruct(const DamageLibrary* p) { delete p; } export void CreatureLib_DamageLibrary_Destruct(const DamageLibrary* p) { delete p; }
export uint32_t CreatureLib_DamageLibrary_GetDamage(const DamageLibrary* p, ExecutingAttack* attack, Creature* target, export uint8_t CreatureLib_DamageLibrary_GetDamage(uint32_t& out, const DamageLibrary* p, ExecutingAttack* attack,
uint8_t hitIndex) { Creature* target, uint8_t hitIndex) {
return p->GetDamage(attack, target, hitIndex); Try(out = p->GetDamage(attack, target, hitIndex);)
} }
export uint8_t CreatureLib_DamageLibrary_GetBasePower(const DamageLibrary* p, ExecutingAttack* attack, Creature* target, export uint8_t CreatureLib_DamageLibrary_GetBasePower(uint8_t& out, const DamageLibrary* p, ExecutingAttack* attack,
uint8_t hitIndex) { Creature* target, uint8_t hitIndex) {
return p->GetBasePower(attack, target, hitIndex); Try(out = p->GetBasePower(attack, target, hitIndex);)
} }
export float CreatureLib_DamageLibrary_GetStatModifier(const DamageLibrary* p, ExecutingAttack* attack, export float CreatureLib_DamageLibrary_GetStatModifier(float& out, const DamageLibrary* p, ExecutingAttack* attack,
Creature* target, uint8_t hitIndex) { Creature* target, uint8_t hitIndex) {
return p->GetStatModifier(attack, target, hitIndex); Try(out = p->GetStatModifier(attack, target, hitIndex);)
} }
export float CreatureLib_DamageLibrary_GetDamageModifier(const DamageLibrary* p, ExecutingAttack* attack, export float CreatureLib_DamageLibrary_GetDamageModifier(float& out, const DamageLibrary* p, ExecutingAttack* attack,
Creature* target, uint8_t hitIndex) { Creature* target, uint8_t hitIndex) {
return p->GetDamageModifier(attack, target, hitIndex); Try(out = p->GetDamageModifier(attack, target, hitIndex);)
} }

View File

@ -1,5 +1,5 @@
#include "../../src/Battling/EventHooks/EventData.hpp" #include "../../src/Battling/EventHooks/EventData.hpp"
#define export extern "C" #include "../Core.hpp"
using namespace CreatureLib::Battling; using namespace CreatureLib::Battling;
export void CreatureLib_EventData_Destruct(const EventData* p) { delete p; } export void CreatureLib_EventData_Destruct(const EventData* p) { delete p; }

View File

@ -1,13 +1,13 @@
#include "../../src/Battling/Library/ExperienceLibrary.hpp" #include "../../src/Battling/Library/ExperienceLibrary.hpp"
#define export extern "C" #include "../Core.hpp"
using namespace CreatureLib::Battling; using namespace CreatureLib::Battling;
export const ExperienceLibrary* CreatureLib_ExperienceLibrary_Construct() { return new ExperienceLibrary(); } export const ExperienceLibrary* CreatureLib_ExperienceLibrary_Construct() { return new ExperienceLibrary(); }
export void CreatureLib_ExperienceLibrary_Destruct(const ExperienceLibrary* p) { delete p; } export void CreatureLib_ExperienceLibrary_Destruct(const ExperienceLibrary* p) { delete p; }
export void CreatureLib_ExperienceLibrary_HandleExperienceGain(const ExperienceLibrary* p, Creature* faintedMon, export uint8_t CreatureLib_ExperienceLibrary_HandleExperienceGain(const ExperienceLibrary* p, Creature* faintedMon,
Creature* opponents[], size_t opponentsCount) { Creature* opponents[], size_t opponentsCount) {
auto set = std::unordered_set<Creature*>(opponents, opponents + opponentsCount); Try(auto set = std::unordered_set<Creature*>(opponents, opponents + opponentsCount);
p->HandleExperienceGain(faintedMon, set); p->HandleExperienceGain(faintedMon, set);)
} }

View File

@ -1,18 +1,19 @@
#include "../../src/Battling/Library/MiscLibrary.hpp" #include "../../src/Battling/Library/MiscLibrary.hpp"
#define export extern "C" #include "../Core.hpp"
using namespace CreatureLib::Battling; using namespace CreatureLib::Battling;
export MiscLibrary* CreatureLib_MiscLibrary_Construct() { return new MiscLibrary(); } export MiscLibrary* CreatureLib_MiscLibrary_Construct() { return new MiscLibrary(); }
export void CreatureLib_MiscLibrary_Destruct(const MiscLibrary* p) { delete p; } export void CreatureLib_MiscLibrary_Destruct(const MiscLibrary* p) { delete p; }
export bool CreatureLib_MiscLibrary_IsCritical(MiscLibrary* p, ExecutingAttack* attack, Creature* target, uint8_t hit) { export uint8_t CreatureLib_MiscLibrary_IsCritical(bool& out, MiscLibrary* p, ExecutingAttack* attack, Creature* target,
return p->IsCritical(attack, target, hit); uint8_t hit) {
Try(out = p->IsCritical(attack, target, hit);)
}; };
export bool CreatureLib_MiscLibrary_CanFlee(MiscLibrary* p, FleeTurnChoice* switchChoice) { export uint8_t CreatureLib_MiscLibrary_CanFlee(bool& out, MiscLibrary* p, FleeTurnChoice* switchChoice) {
return p->CanFlee(switchChoice); Try(out = p->CanFlee(switchChoice);)
}; };
export BaseTurnChoice* CreatureLib_MiscLibrary_ReplacementAttack(MiscLibrary* p, Creature* user, uint8_t sideTarget, export uint8_t CreatureLib_MiscLibrary_ReplacementAttack(BaseTurnChoice*& out, MiscLibrary* p, Creature* user,
uint8_t creatureTarget) { uint8_t sideTarget, uint8_t creatureTarget) {
return p->ReplacementAttack(user, CreatureIndex(sideTarget, creatureTarget)); Try(out = p->ReplacementAttack(user, CreatureIndex(sideTarget, creatureTarget));)
}; };

View File

@ -1,15 +1,15 @@
#include "../../src/Battling/ScriptHandling/ScriptResolver.hpp" #include "../../src/Battling/ScriptHandling/ScriptResolver.hpp"
#define export extern "C" #include "../Core.hpp"
using namespace CreatureLib::Battling; using namespace CreatureLib::Battling;
export ScriptResolver* CreatureLib_ScriptResolver_Construct() { return new ScriptResolver(); } export ScriptResolver* CreatureLib_ScriptResolver_Construct() { return new ScriptResolver(); }
export void CreatureLib_ScriptResolver_Destruct(const ScriptResolver* p) { delete p; } export void CreatureLib_ScriptResolver_Destruct(const ScriptResolver* p) { delete p; }
export void CreatureLib_ScriptResolver_Initialize(ScriptResolver* p, BattleLibrary* library) { export uint8_t CreatureLib_ScriptResolver_Initialize(ScriptResolver* p, BattleLibrary* library) {
p->Initialize(library); Try(p->Initialize(library);)
}; };
export Script* CreatureLib_ScriptResolver_LoadScript(ScriptResolver* p, ScriptCategory category, export uint8_t CreatureLib_ScriptResolver_LoadScript(Script*& out, ScriptResolver* p, ScriptCategory category,
const char* scriptName) { const char* scriptName) {
return p->LoadScript(category, ConstString(scriptName)); Try(out = p->LoadScript(category, ConstString(scriptName));)
}; };

View File

@ -2,7 +2,7 @@
#include "../../src/Battling/TurnChoices/FleeTurnChoice.hpp" #include "../../src/Battling/TurnChoices/FleeTurnChoice.hpp"
#include "../../src/Battling/TurnChoices/PassTurnChoice.hpp" #include "../../src/Battling/TurnChoices/PassTurnChoice.hpp"
#include "../../src/Battling/TurnChoices/SwitchTurnChoice.hpp" #include "../../src/Battling/TurnChoices/SwitchTurnChoice.hpp"
#define export extern "C" #include "../Core.hpp"
using namespace CreatureLib::Battling; using namespace CreatureLib::Battling;
export AttackTurnChoice* CreatureLib_AttackTurnChoice_Construct(Creature* user, LearnedAttack* attack, export AttackTurnChoice* CreatureLib_AttackTurnChoice_Construct(Creature* user, LearnedAttack* attack,
@ -25,7 +25,9 @@ SIMPLE_GET_FUNC(BaseTurnChoice, GetUser, Creature*)
SIMPLE_GET_FUNC(AttackTurnChoice, GetAttack, LearnedAttack*) SIMPLE_GET_FUNC(AttackTurnChoice, GetAttack, LearnedAttack*)
SIMPLE_GET_FUNC(AttackTurnChoice, GetKind, TurnChoiceKind) SIMPLE_GET_FUNC(AttackTurnChoice, GetKind, TurnChoiceKind)
SIMPLE_GET_FUNC(AttackTurnChoice, GetPriority, int8_t)
export uint8_t CreatureLib_BaseTurnChoice_GetPriority(int8_t& out, AttackTurnChoice* p) { Try(out = p->GetPriority()); }
SIMPLE_GET_FUNC(AttackTurnChoice, GetAttackScript, Script*) SIMPLE_GET_FUNC(AttackTurnChoice, GetAttackScript, Script*)
export uint8_t CreatureLib_BaseTurnChoice_GetTargetSideIndex(const AttackTurnChoice* p) { export uint8_t CreatureLib_BaseTurnChoice_GetTargetSideIndex(const AttackTurnChoice* p) {
return p->GetTarget().GetSideIndex(); return p->GetTarget().GetSideIndex();

4
CInterface/Core.cpp Normal file
View File

@ -0,0 +1,4 @@
#include "Core.hpp"
std::string ExceptionHandler::_lastException = "";
export const char* GetLastException() { return ExceptionHandler::GetLastException(); }

26
CInterface/Core.hpp Normal file
View File

@ -0,0 +1,26 @@
#ifndef CREATURELIB_CORE_HPP
#define CREATURELIB_CORE_HPP
#include <cstring>
#include <exception>
#include <string>
#define export extern "C"
class ExceptionHandler {
static std::string _lastException;
public:
static void SetLastException(const std::exception& e) { _lastException = std::string(e.what()); }
static const char* GetLastException() { return _lastException.c_str(); }
};
#define Try(data) \
try { \
data; \
return 0; \
} catch (const std::exception& e) { \
ExceptionHandler::SetLastException(e); \
return 1; \
}
#endif // CREATURELIB_CORE_HPP

View File

@ -1,18 +1,16 @@
#include "../../src/Library/Attacks/AttackData.hpp" #include "../../src/Library/Attacks/AttackData.hpp"
#define export extern "C" #include "../Core.hpp"
using namespace CreatureLib::Library; using namespace CreatureLib::Library;
export AttackData* CreatureLib_AttackData_Construct(const char* name, uint8_t type, AttackCategory category, export uint8_t CreatureLib_AttackData_Construct(AttackData*& out, const char* name, uint8_t type,
uint8_t power, uint8_t accuracy, uint8_t baseUsage, AttackCategory category, uint8_t power, uint8_t accuracy,
AttackTarget target, int8_t priority, const char* flags[], uint8_t baseUsage, AttackTarget target, int8_t priority,
size_t flagsCount) { const char* flags[], size_t flagsCount) {
std::unordered_set<uint32_t> conversedFlags(flagsCount); Try(std::unordered_set<uint32_t> conversedFlags(flagsCount);
for (size_t i = 0; i < flagsCount; i++) { for (size_t i = 0; i < flagsCount; i++) { conversedFlags.insert(ConstString::GetHash(flags[i])); }
conversedFlags.insert(ConstString::GetHash(flags[i]));
}
return new AttackData(ConstString(name), type, category, power, accuracy, baseUsage, target, priority, out = new AttackData(ConstString(name), type, category, power, accuracy, baseUsage, target, priority,
conversedFlags); conversedFlags);)
}; };
export void CreatureLib_AttackData_Destruct(const AttackData* p) { delete p; } export void CreatureLib_AttackData_Destruct(const AttackData* p) { delete p; }

View File

@ -1,10 +1,9 @@
#include "../../src/Library/AttackLibrary.hpp" #include "../../src/Library/AttackLibrary.hpp"
#include "BaseLibrary.cpp" #include "BaseLibrary.cpp"
#define export extern "C"
using namespace CreatureLib::Library; using namespace CreatureLib::Library;
export const AttackLibrary* CreatureLib_AttackLibrary_Construct(size_t initialCapacity = 32) { export uint8_t CreatureLib_AttackLibrary_Construct(AttackLibrary*& library, size_t initialCapacity = 32) {
return new AttackLibrary(initialCapacity); Try(library = new AttackLibrary(initialCapacity);)
}; };
export void CreatureLib_AttackLibrary_Destruct(const AttackLibrary* p) { delete p; } export void CreatureLib_AttackLibrary_Destruct(const AttackLibrary* p) { delete p; }

View File

@ -1,32 +1,34 @@
#define export extern "C" #include "../Core.hpp"
#define BASELIBRARY(simpleName, fullname, returnType) \ #define BASELIBRARY(simpleName, fullname, returnType) \
export void simpleName##_Insert(fullname* p, const char* name, returnType* t) { \ export uint8_t simpleName##_Insert(fullname* p, const char* name, returnType* t) { \
p->Insert(Arbutils::CaseInsensitiveConstString::GetHash(name), t); \ Try(p->Insert(Arbutils::CaseInsensitiveConstString::GetHash(name), t);) \
} \ } \
\ \
export void simpleName##_InsertWithHash(fullname* p, uint32_t hashedKey, returnType* t) { \ export uint8_t simpleName##_InsertWithHash(fullname* p, uint32_t hashedKey, returnType* t) { \
p->Insert(hashedKey, t); \ Try(p->Insert(hashedKey, t);) \
} \ } \
\ \
export void simpleName##_Delete(fullname* p, const char* name) { \ export uint8_t simpleName##_Delete(fullname* p, const char* name) { \
p->Delete(Arbutils::CaseInsensitiveConstString::GetHash(name)); \ Try(p->Delete(Arbutils::CaseInsensitiveConstString::GetHash(name));) \
} \ } \
\ \
export void simpleName##_DeleteWithHash(fullname* p, uint32_t hashedKey) { p->Delete(hashedKey); } \ export uint8_t simpleName##_DeleteWithHash(fullname* p, uint32_t hashedKey) { Try(p->Delete(hashedKey);) } \
\ \
export bool simpleName##_TryGet(fullname* p, const char* name, const returnType* out) { \ export bool simpleName##_TryGet(fullname* p, const char* name, const returnType*& out) { \
return p->TryGet(Arbutils::CaseInsensitiveConstString::GetHash(name), out); \ return p->TryGet(Arbutils::CaseInsensitiveConstString::GetHash(name), out); \
} \ } \
\ \
export bool simpleName##_TryGetWithHash(fullname* p, uint32_t hashedKey, const returnType* out) { \ export bool simpleName##_TryGetWithHash(fullname* p, uint32_t hashedKey, const returnType*& out) { \
return p->TryGet(hashedKey, out); \ return p->TryGet(hashedKey, out); \
} \ } \
\ \
export bool simpleName##_Get(fullname* p, const char* name) { \ export uint8_t simpleName##_Get(fullname* p, const char* name, const returnType*& out) { \
return p->Get(Arbutils::CaseInsensitiveConstString::GetHash(name)); \ Try(out = p->Get(Arbutils::CaseInsensitiveConstString::GetHash(name));) \
} \ } \
\ \
export bool simpleName##_GetWithHash(fullname* p, uint32_t hashedKey) { return p->Get(hashedKey); } \ export uint8_t simpleName##_GetWithHash(fullname* p, uint32_t hashedKey, const returnType*& out) { \
Try(out = p->Get(hashedKey);) \
} \
\ \
export size_t simpleName##_GetCount(fullname* p) { return p->GetCount(); } export size_t simpleName##_GetCount(fullname* p) { return p->GetCount(); }

View File

@ -1,12 +1,13 @@
#include "../../src/Library/CreatureData/CreatureSpecies.hpp" #include "../../src/Library/CreatureData/CreatureSpecies.hpp"
#define export extern "C" #include "../Core.hpp"
using namespace CreatureLib::Library; using namespace CreatureLib::Library;
export CreatureSpecies* CreatureLib_CreatureSpecies_Construct(uint16_t id, const char* name, export uint8_t CreatureLib_CreatureSpecies_Construct(CreatureSpecies*& out, uint16_t id, const char* name,
SpeciesVariant* defaultVariant, float genderRatio, SpeciesVariant* defaultVariant, float genderRatio,
const char* growthRate, uint8_t captureRate) { const char* growthRate, uint8_t captureRate) {
return new CreatureSpecies(id, Arbutils::CaseInsensitiveConstString(name), defaultVariant, genderRatio,
Arbutils::CaseInsensitiveConstString(growthRate), captureRate); Try(out = new CreatureSpecies(id, Arbutils::CaseInsensitiveConstString(name), defaultVariant, genderRatio,
Arbutils::CaseInsensitiveConstString(growthRate), captureRate);)
} }
export void CreatureLib_CreatureSpecies_Destruct(const CreatureSpecies* p) { delete p; } export void CreatureLib_CreatureSpecies_Destruct(const CreatureSpecies* p) { delete p; }
@ -28,7 +29,7 @@ export bool CreatureLib_CreatureSpecies_HasVariantWithHash(const CreatureSpecies
return p->HasVariant(hash); return p->HasVariant(hash);
} }
export bool CreatureLib_CreatureSpecies_TryGetVariant(const CreatureSpecies* p, const char* name, export bool CreatureLib_CreatureSpecies_TryGetVariant(const CreatureSpecies* p, const char* name,
const SpeciesVariant* out) { const SpeciesVariant*& out) {
return p->TryGetVariant(Arbutils::CaseInsensitiveConstString::GetHash(name), out); return p->TryGetVariant(Arbutils::CaseInsensitiveConstString::GetHash(name), out);
} }
export bool CreatureLib_CreatureSpecies_TryGetVariantWithHash(const CreatureSpecies* p, uint32_t hash, export bool CreatureLib_CreatureSpecies_TryGetVariantWithHash(const CreatureSpecies* p, uint32_t hash,
@ -36,11 +37,13 @@ export bool CreatureLib_CreatureSpecies_TryGetVariantWithHash(const CreatureSpec
return p->TryGetVariant(hash, out); return p->TryGetVariant(hash, out);
} }
export const SpeciesVariant* CreatureLib_CreatureSpecies_GetVariant(const CreatureSpecies* p, const char* name) { export uint8_t CreatureLib_CreatureSpecies_GetVariant(const SpeciesVariant*& out, const CreatureSpecies* p,
return p->GetVariant(Arbutils::CaseInsensitiveConstString::GetHash(name)); const char* name) {
Try(out = p->GetVariant(Arbutils::CaseInsensitiveConstString::GetHash(name));)
} }
export const SpeciesVariant* CreatureLib_CreatureSpecies_GetVariantWithHash(const CreatureSpecies* p, uint32_t hash) { export uint8_t CreatureLib_CreatureSpecies_GetVariantWithHash(const SpeciesVariant* out, const CreatureSpecies* p,
return p->GetVariant(hash); uint32_t hash) {
Try(out = p->GetVariant(hash);)
} }
#undef SIMPLE_GET_FUNC #undef SIMPLE_GET_FUNC

View File

@ -1,11 +1,11 @@
#include "../../src/Library/DataLibrary.hpp" #include "../../src/Library/DataLibrary.hpp"
#define export extern "C" #include "../Core.hpp"
using namespace CreatureLib::Library; using namespace CreatureLib::Library;
export const DataLibrary* CreatureLib_DataLibrary_Construct(LibrarySettings* settings, SpeciesLibrary* species, export uint8_t CreatureLib_DataLibrary_Construct(const DataLibrary*& out, LibrarySettings* settings,
AttackLibrary* attacks, ItemLibrary* items, SpeciesLibrary* species, AttackLibrary* attacks, ItemLibrary* items,
GrowthRateLibrary* growthRates, TypeLibrary* typeLibrary) { GrowthRateLibrary* growthRates, TypeLibrary* typeLibrary) {
return new DataLibrary(settings, species, attacks, items, growthRates, typeLibrary); Try(out = new DataLibrary(settings, species, attacks, items, growthRates, typeLibrary);)
} }
export void CreatureLib_DataLibrary_Destruct(const DataLibrary* p) { delete p; } export void CreatureLib_DataLibrary_Destruct(const DataLibrary* p) { delete p; }

View File

@ -1,7 +1,7 @@
#include "../../src/Library/GrowthRates/GrowthRate.hpp" #include "../../src/Library/GrowthRates/GrowthRate.hpp"
#include "../../src/Library/GrowthRates/ExternGrowthRate.hpp" #include "../../src/Library/GrowthRates/ExternGrowthRate.hpp"
#include "../../src/Library/GrowthRates/LookupGrowthRate.hpp" #include "../../src/Library/GrowthRates/LookupGrowthRate.hpp"
#define export extern "C" #include "../Core.hpp"
using namespace CreatureLib::Library; using namespace CreatureLib::Library;
export GrowthRate* CreatureLib_LookupGrowthRate_Construct(uint32_t experiencePerLevel[], size_t count) { export GrowthRate* CreatureLib_LookupGrowthRate_Construct(uint32_t experiencePerLevel[], size_t count) {
@ -9,17 +9,17 @@ export GrowthRate* CreatureLib_LookupGrowthRate_Construct(uint32_t experiencePer
return new LookupGrowthRate(exp); return new LookupGrowthRate(exp);
}; };
export GrowthRate* CreatureLib_ExternGrowthRate_Construct(uint8_t (*calcLevel)(uint32_t), export uint8_t CreatureLib_ExternGrowthRate_Construct(GrowthRate*& out, uint8_t (*calcLevel)(uint32_t),
uint32_t (*calcExperience)(uint8_t)) { uint32_t (*calcExperience)(uint8_t)) {
return new ExternGrowthRate(calcLevel, calcExperience); Try(out = new ExternGrowthRate(calcLevel, calcExperience);)
}; };
export void CreatureLib_GrowthRate_Destruct(const GrowthRate* p) { delete p; } export void CreatureLib_GrowthRate_Destruct(const GrowthRate* p) { delete p; }
export uint8_t CreatureLib_GrowthRate_CalculateLevel(const GrowthRate* p, uint32_t experience) { export uint8_t CreatureLib_GrowthRate_CalculateLevel(uint8_t& out, const GrowthRate* p, uint32_t experience) {
return p->CalculateLevel(experience); Try(out = p->CalculateLevel(experience);)
} }
export uint32_t CreatureLib_GrowthRate_CalculateExperience(const GrowthRate* p, uint8_t level) { export uint8_t CreatureLib_GrowthRate_CalculateExperience(uint32_t& out, const GrowthRate* p, uint8_t level) {
return p->CalculateExperience(level); Try(out = p->CalculateExperience(level);)
} }

View File

@ -1,5 +1,5 @@
#include "../../src/Library/GrowthRates/GrowthRateLibrary.hpp" #include "../../src/Library/GrowthRates/GrowthRateLibrary.hpp"
#define export extern "C" #include "../Core.hpp"
using namespace CreatureLib::Library; using namespace CreatureLib::Library;
export GrowthRateLibrary* CreatureLib_GrowthRateLibrary_Construct(size_t initialCapacity) { export GrowthRateLibrary* CreatureLib_GrowthRateLibrary_Construct(size_t initialCapacity) {
@ -8,30 +8,30 @@ export GrowthRateLibrary* CreatureLib_GrowthRateLibrary_Construct(size_t initial
export void CreatureLib_GrowthRateLibrary_Destruct(GrowthRateLibrary* p) { delete p; } export void CreatureLib_GrowthRateLibrary_Destruct(GrowthRateLibrary* p) { delete p; }
export uint8_t CreatureLib_GrowthRateLibrary_CalculateLevel(GrowthRateLibrary* library, const char* growthRate, export uint8_t CreatureLib_GrowthRateLibrary_CalculateLevel(uint8_t& out, GrowthRateLibrary* library,
uint32_t experience) { const char* growthRate, uint32_t experience) {
return library->CalculateLevel(Arbutils::CaseInsensitiveConstString::GetHash(growthRate), experience); Try(out = library->CalculateLevel(Arbutils::CaseInsensitiveConstString::GetHash(growthRate), experience);)
} }
export uint8_t CreatureLib_GrowthRateLibrary_CalculateLevelWithHash(GrowthRateLibrary* library, uint32_t growthRateHash, export uint8_t CreatureLib_GrowthRateLibrary_CalculateLevelWithHash(uint8_t& out, GrowthRateLibrary* library,
uint32_t experience) { uint32_t growthRateHash, uint32_t experience) {
return library->CalculateLevel(growthRateHash, experience); Try(out = library->CalculateLevel(growthRateHash, experience);)
} }
export uint32_t CreatureLib_GrowthRateLibrary_CalculateExperience(GrowthRateLibrary* library, const char* growthRate, export uint8_t CreatureLib_GrowthRateLibrary_CalculateExperience(uint32_t& out, GrowthRateLibrary* library,
uint8_t level) { const char* growthRate, uint8_t level) {
return library->CalculateExperience(Arbutils::CaseInsensitiveConstString::GetHash(growthRate), level); Try(out = library->CalculateExperience(Arbutils::CaseInsensitiveConstString::GetHash(growthRate), level);)
} }
export uint32_t CreatureLib_GrowthRateLibrary_CalculateExperienceWithHash(GrowthRateLibrary* library, export uint8_t CreatureLib_GrowthRateLibrary_CalculateExperienceWithHash(uint32_t& out, GrowthRateLibrary* library,
uint32_t growthRateHash, uint8_t level) { uint32_t growthRateHash, uint8_t level) {
return library->CalculateExperience(growthRateHash, level); Try(out = library->CalculateExperience(growthRateHash, level);)
} }
export void CreatureLib_GrowthRateLibrary_AddGrowthRate(GrowthRateLibrary* library, const char* growthRateName, export uint8_t CreatureLib_GrowthRateLibrary_AddGrowthRate(GrowthRateLibrary* library, const char* growthRateName,
GrowthRate* growthRate) { GrowthRate* growthRate) {
return library->AddGrowthRate(Arbutils::CaseInsensitiveConstString::GetHash(growthRateName), growthRate); Try(library->AddGrowthRate(Arbutils::CaseInsensitiveConstString::GetHash(growthRateName), growthRate);)
} }
export void CreatureLib_GrowthRateLibrary_AddGrowthRateWithHash(GrowthRateLibrary* library, uint32_t growthRateHash, export uint8_t CreatureLib_GrowthRateLibrary_AddGrowthRateWithHash(GrowthRateLibrary* library, uint32_t growthRateHash,
GrowthRate* growthRate) { GrowthRate* growthRate) {
return library->AddGrowthRate(growthRateHash, growthRate); Try(library->AddGrowthRate(growthRateHash, growthRate);)
} }

View File

@ -1,5 +1,5 @@
#include "../../src/Library/Items/Item.hpp" #include "../../src/Library/Items/Item.hpp"
#define export extern "C" #include "../Core.hpp"
using namespace CreatureLib::Library; using namespace CreatureLib::Library;
using ConstString = Arbutils::CaseInsensitiveConstString; using ConstString = Arbutils::CaseInsensitiveConstString;

View File

@ -1,6 +1,6 @@
#include "../../src/Library/ItemLibrary.hpp" #include "../../src/Library/ItemLibrary.hpp"
#include "../Core.hpp"
#include "BaseLibrary.cpp" #include "BaseLibrary.cpp"
#define export extern "C"
using namespace CreatureLib::Library; using namespace CreatureLib::Library;
export const ItemLibrary* CreatureLib_ItemLibrary_Construct(size_t initialCapacity = 32) { export const ItemLibrary* CreatureLib_ItemLibrary_Construct(size_t initialCapacity = 32) {

View File

@ -1,9 +1,9 @@
#include "../../src/Library/CreatureData/LearnableAttacks.hpp" #include "../../src/Library/CreatureData/LearnableAttacks.hpp"
#define export extern "C" #include "../Core.hpp"
using namespace CreatureLib::Library; using namespace CreatureLib::Library;
export LearnableAttacks* CreatureLib_LearnableAttacks_Construct(size_t levelAttackCapacity) { export uint8_t CreatureLib_LearnableAttacks_Construct(LearnableAttacks*& out, size_t levelAttackCapacity) {
return new LearnableAttacks(levelAttackCapacity); Try(out = new LearnableAttacks(levelAttackCapacity);)
}; };
export void CreatureLib_LearnableAttacks_Destruct(LearnableAttacks* p) { delete p; } export void CreatureLib_LearnableAttacks_Destruct(LearnableAttacks* p) { delete p; }

View File

@ -1,5 +1,5 @@
#include "../../src/Library/LibrarySettings.hpp" #include "../../src/Library/LibrarySettings.hpp"
#define export extern "C" #include "../Core.hpp"
using namespace CreatureLib::Library; using namespace CreatureLib::Library;
export const LibrarySettings* CreatureLib_LibrarySettings_Construct(uint8_t maximalLevel, uint8_t maximalMoves) { export const LibrarySettings* CreatureLib_LibrarySettings_Construct(uint8_t maximalLevel, uint8_t maximalMoves) {

View File

@ -1,6 +1,6 @@
#include "../../src/Library/SpeciesLibrary.hpp" #include "../../src/Library/SpeciesLibrary.hpp"
#include "../Core.hpp"
#include "BaseLibrary.cpp" #include "BaseLibrary.cpp"
#define export extern "C"
using namespace CreatureLib::Library; using namespace CreatureLib::Library;
export const SpeciesLibrary* CreatureLib_SpeciesLibrary_Construct(size_t initialCapacity = 32) { export const SpeciesLibrary* CreatureLib_SpeciesLibrary_Construct(size_t initialCapacity = 32) {

View File

@ -1,5 +1,5 @@
#include "../../src/Library/CreatureData/SpeciesVariant.hpp" #include "../../src/Library/CreatureData/SpeciesVariant.hpp"
#define export extern "C" #include "../Core.hpp"
using namespace CreatureLib::Library; using namespace CreatureLib::Library;
using ConstString = Arbutils::CaseInsensitiveConstString; using ConstString = Arbutils::CaseInsensitiveConstString;

View File

@ -1,5 +1,5 @@
#include "../../src/Library/TypeLibrary.hpp" #include "../../src/Library/TypeLibrary.hpp"
#define export extern "C" #include "../Core.hpp"
using namespace CreatureLib::Library; using namespace CreatureLib::Library;
export TypeLibrary* CreatureLib_TypeLibrary_Construct(size_t initialCapacity) { export TypeLibrary* CreatureLib_TypeLibrary_Construct(size_t initialCapacity) {
@ -8,30 +8,31 @@ export TypeLibrary* CreatureLib_TypeLibrary_Construct(size_t initialCapacity) {
export void CreatureLib_TypeLibrary_Destruct(const TypeLibrary* p) { delete p; } export void CreatureLib_TypeLibrary_Destruct(const TypeLibrary* p) { delete p; }
export uint8_t CreatureLib_TypeLibrary_GetTypeId(const TypeLibrary* p, const char* type) { export uint8_t CreatureLib_TypeLibrary_GetTypeId(uint8_t& out, const TypeLibrary* p, const char* type) {
return p->GetTypeId(Arbutils::CaseInsensitiveConstString::GetHash(type)); Try(out = p->GetTypeId(Arbutils::CaseInsensitiveConstString::GetHash(type));)
} }
export uint8_t CreatureLib_TypeLibrary_GetTypeIdWithHash(const TypeLibrary* p, uint32_t type) { export uint8_t CreatureLib_TypeLibrary_GetTypeIdWithHash(uint8_t& out, const TypeLibrary* p, uint32_t type) {
return p->GetTypeId(type); Try(out = p->GetTypeId(type);)
} }
export uint8_t CreatureLib_TypeLibrary_RegisterType(TypeLibrary* p, const char* type) { export uint8_t CreatureLib_TypeLibrary_RegisterType(uint8_t& out, TypeLibrary* p, const char* type) {
return p->RegisterType(Arbutils::CaseInsensitiveConstString::GetHash(type)); Try(out = p->RegisterType(Arbutils::CaseInsensitiveConstString::GetHash(type));)
} }
export uint8_t CreatureLib_TypeLibrary_RegisterTypeWithHash(TypeLibrary* p, uint32_t type) { export uint8_t CreatureLib_TypeLibrary_RegisterTypeWithHash(uint8_t& out, TypeLibrary* p, uint32_t type) {
return p->RegisterType(type); Try(out = p->RegisterType(type);)
} }
export void CreatureLib_TypeLibrary_SetEffectiveness(TypeLibrary* p, uint8_t attacking, uint8_t defensive, export uint8_t CreatureLib_TypeLibrary_SetEffectiveness(TypeLibrary* p, uint8_t attacking, uint8_t defensive,
float effectiveness) { float effectiveness) {
p->SetEffectiveness(attacking, defensive, effectiveness); Try(p->SetEffectiveness(attacking, defensive, effectiveness);)
} }
export float CreatureLib_TypeLibrary_GetSingleEffectiveness(TypeLibrary* p, uint8_t attacking, uint8_t defensive) { export uint8_t CreatureLib_TypeLibrary_GetSingleEffectiveness(float& out, TypeLibrary* p, uint8_t attacking,
return p->GetSingleEffectiveness(attacking, defensive); uint8_t defensive) {
Try(out = p->GetSingleEffectiveness(attacking, defensive);)
} }
export float CreatureLib_TypeLibrary_GetEffectiveness(TypeLibrary* p, uint8_t attacking, uint8_t defensive[], export uint8_t CreatureLib_TypeLibrary_GetEffectiveness(float& out, TypeLibrary* p, uint8_t attacking,
size_t defensiveCount) { uint8_t defensive[], size_t defensiveCount) {
return p->GetEffectiveness(attacking, List<uint8_t>(defensive, defensive + defensiveCount)); Try(out = p->GetEffectiveness(attacking, List<uint8_t>(defensive, defensive + defensiveCount));)
} }

View File

@ -32,11 +32,11 @@ if (WINDOWS)
endif (WINDOWS) endif (WINDOWS)
# Create main Library library with files in src/Library # Create main Library library with files in src/Library
file(GLOB_RECURSE LIBRARY_SRC_FILES "src/Library/*.cpp" "src/Library/*.hpp" "CInterface/Library/*.cpp") file(GLOB_RECURSE LIBRARY_SRC_FILES "src/Library/*.cpp" "src/Library/*.hpp" "CInterface/Library/*.cpp" "CInterface/Core.*")
add_library(CreatureLibLibrary SHARED ${LIBRARY_SRC_FILES}) add_library(CreatureLibLibrary SHARED ${LIBRARY_SRC_FILES})
# Create Battling library with files in src/Battling # Create Battling library with files in src/Battling
file(GLOB_RECURSE BATTLING_SRC_FILES "src/Battling/*.cpp" "src/Battling/*.hpp" "CInterface/Battling/*.cpp") file(GLOB_RECURSE BATTLING_SRC_FILES "src/Battling/*.cpp" "src/Battling/*.hpp" "CInterface/Battling/*.cpp" "CInterface/Core.*")
add_library(CreatureLibBattling SHARED ${BATTLING_SRC_FILES}) add_library(CreatureLibBattling SHARED ${BATTLING_SRC_FILES})
if (NOT DEFINED CONAN_EXPORTED) if (NOT DEFINED CONAN_EXPORTED)

15077
extern/catch.hpp vendored

File diff suppressed because it is too large Load Diff

View File

@ -10,7 +10,7 @@ namespace CreatureLib::Battling {
class EventData { class EventData {
public: public:
virtual ~EventData() = default; virtual ~EventData() = default;
virtual EventDataKind GetKind() const = 0; virtual EventDataKind GetKind() const noexcept = 0;
}; };
class DamageEvent : public EventData { class DamageEvent : public EventData {
@ -20,13 +20,13 @@ namespace CreatureLib::Battling {
uint32_t _newHealth; uint32_t _newHealth;
public: public:
DamageEvent(Creature* c, DamageSource s, uint32_t oHealth, uint32_t newHealth) DamageEvent(Creature* c, DamageSource s, uint32_t oHealth, uint32_t newHealth) noexcept
: _creature(c), _damageSource(s), _originalHealth(oHealth), _newHealth(newHealth) {} : _creature(c), _damageSource(s), _originalHealth(oHealth), _newHealth(newHealth) {}
EventDataKind GetKind() const override { return EventDataKind ::Damage; } EventDataKind GetKind() const noexcept override { return EventDataKind ::Damage; }
Creature* GetCreature() const { return _creature; } Creature* GetCreature() const noexcept { return _creature; }
DamageSource GetDamageSource() const { return _damageSource; } DamageSource GetDamageSource() const noexcept { return _damageSource; }
uint32_t GetOriginalHealth() const { return _originalHealth; } uint32_t GetOriginalHealth() const noexcept { return _originalHealth; }
uint32_t GetNewHealth() const { return _newHealth; } uint32_t GetNewHealth() const noexcept { return _newHealth; }
}; };
class HealEvent : public EventData { class HealEvent : public EventData {
@ -35,30 +35,30 @@ namespace CreatureLib::Battling {
uint32_t _newHealth; uint32_t _newHealth;
public: public:
HealEvent(Creature* c, uint32_t oHealth, uint32_t newHealth) HealEvent(Creature* c, uint32_t oHealth, uint32_t newHealth) noexcept
: _creature(c), _originalHealth(oHealth), _newHealth(newHealth) {} : _creature(c), _originalHealth(oHealth), _newHealth(newHealth) {}
EventDataKind GetKind() const override { return EventDataKind ::Heal; } EventDataKind GetKind() const noexcept override { return EventDataKind ::Heal; }
Creature* GetCreature() const { return _creature; } Creature* GetCreature() const noexcept { return _creature; }
uint32_t GetOriginalHealth() const { return _originalHealth; } uint32_t GetOriginalHealth() const noexcept { return _originalHealth; }
uint32_t GetNewHealth() const { return _newHealth; } uint32_t GetNewHealth() const noexcept { return _newHealth; }
}; };
class FaintEvent : public EventData { class FaintEvent : public EventData {
Creature* _creature; Creature* _creature;
public: public:
FaintEvent(Creature* c) : _creature(c) {} FaintEvent(Creature* c) noexcept : _creature(c) {}
EventDataKind GetKind() const override { return EventDataKind ::Faint; } EventDataKind GetKind() const noexcept override { return EventDataKind ::Faint; }
Creature* GetCreature() const { return _creature; } Creature* GetCreature() const noexcept { return _creature; }
}; };
class DisplayTextEvent : public EventData { class DisplayTextEvent : public EventData {
const std::string _text; const std::string _text;
public: public:
DisplayTextEvent(const std::string& text) : _text(text) {} DisplayTextEvent(const std::string& text) noexcept : _text(text) {}
EventDataKind GetKind() const override { return EventDataKind ::DisplayText; } EventDataKind GetKind() const noexcept override { return EventDataKind ::DisplayText; }
const std::string& GetText() const { return _text; } const std::string& GetText() const noexcept { return _text; }
}; };
} }

View File

@ -17,25 +17,31 @@ BattleLibrary::~BattleLibrary() {
delete _miscLibrary; delete _miscLibrary;
} }
const CreatureLib::Library::LibrarySettings* BattleLibrary::GetSettings() const { return _staticLib->GetSettings(); } const CreatureLib::Library::LibrarySettings* BattleLibrary::GetSettings() const noexcept {
return _staticLib->GetSettings();
}
const BattleStatCalculator* BattleLibrary::GetStatCalculator() const { return _statCalculator; } const BattleStatCalculator* BattleLibrary::GetStatCalculator() const noexcept { return _statCalculator; }
const CreatureLib::Library::SpeciesLibrary* BattleLibrary::GetSpeciesLibrary() const { const CreatureLib::Library::SpeciesLibrary* BattleLibrary::GetSpeciesLibrary() const noexcept {
return _staticLib->GetSpeciesLibrary(); return _staticLib->GetSpeciesLibrary();
} }
const CreatureLib::Library::ItemLibrary* BattleLibrary::GetItemLibrary() const { return _staticLib->GetItemLibrary(); } const CreatureLib::Library::ItemLibrary* BattleLibrary::GetItemLibrary() const noexcept {
return _staticLib->GetItemLibrary();
}
const CreatureLib::Library::AttackLibrary* BattleLibrary::GetAttackLibrary() const { const CreatureLib::Library::AttackLibrary* BattleLibrary::GetAttackLibrary() const noexcept {
return _staticLib->GetAttackLibrary(); return _staticLib->GetAttackLibrary();
} }
const CreatureLib::Library::TypeLibrary* BattleLibrary::GetTypeLibrary() const { return _staticLib->GetTypeLibrary(); } const CreatureLib::Library::TypeLibrary* BattleLibrary::GetTypeLibrary() const noexcept {
return _staticLib->GetTypeLibrary();
}
const DamageLibrary* BattleLibrary::GetDamageLibrary() const { return _damageLibrary; } const DamageLibrary* BattleLibrary::GetDamageLibrary() const noexcept { return _damageLibrary; }
const MiscLibrary* BattleLibrary::GetMiscLibrary() const { return _miscLibrary; } const MiscLibrary* BattleLibrary::GetMiscLibrary() const noexcept { return _miscLibrary; }
Script* BattleLibrary::LoadScript(ScriptCategory category, const ConstString& scriptName) const { Script* BattleLibrary::LoadScript(ScriptCategory category, const ConstString& scriptName) const {
return _scriptResolver->LoadScript(category, scriptName); return _scriptResolver->LoadScript(category, scriptName);

View File

@ -23,21 +23,21 @@ namespace CreatureLib::Battling {
DamageLibrary* damageLibrary, ExperienceLibrary* experienceLibrary, DamageLibrary* damageLibrary, ExperienceLibrary* experienceLibrary,
ScriptResolver* scriptResolver, MiscLibrary* miscLibrary); ScriptResolver* scriptResolver, MiscLibrary* miscLibrary);
~BattleLibrary(); ~BattleLibrary();
inline const Library::DataLibrary* GetStaticLib() const { return _staticLib; } inline const Library::DataLibrary* GetStaticLib() const noexcept { return _staticLib; }
[[nodiscard]] const Library::LibrarySettings* GetSettings() const; [[nodiscard]] const Library::LibrarySettings* GetSettings() const noexcept;
[[nodiscard]] const Library::SpeciesLibrary* GetSpeciesLibrary() const; [[nodiscard]] const Library::SpeciesLibrary* GetSpeciesLibrary() const noexcept;
[[nodiscard]] const Library::ItemLibrary* GetItemLibrary() const; [[nodiscard]] const Library::ItemLibrary* GetItemLibrary() const noexcept;
[[nodiscard]] const Library::AttackLibrary* GetAttackLibrary() const; [[nodiscard]] const Library::AttackLibrary* GetAttackLibrary() const noexcept;
[[nodiscard]] const Library::TypeLibrary* GetTypeLibrary() const; [[nodiscard]] const Library::TypeLibrary* GetTypeLibrary() const noexcept;
[[nodiscard]] const Library::GrowthRateLibrary* GetGrowthRateLibrary() const { [[nodiscard]] const Library::GrowthRateLibrary* GetGrowthRateLibrary() const noexcept {
return _staticLib->GetGrowthRates(); return _staticLib->GetGrowthRates();
} }
[[nodiscard]] const BattleStatCalculator* GetStatCalculator() const; [[nodiscard]] const BattleStatCalculator* GetStatCalculator() const noexcept;
[[nodiscard]] const DamageLibrary* GetDamageLibrary() const; [[nodiscard]] const DamageLibrary* GetDamageLibrary() const noexcept;
[[nodiscard]] const MiscLibrary* GetMiscLibrary() const; [[nodiscard]] const MiscLibrary* GetMiscLibrary() const noexcept;
[[nodiscard]] const ExperienceLibrary* GetExperienceLibrary() const { return _experienceLibrary; } [[nodiscard]] const ExperienceLibrary* GetExperienceLibrary() const noexcept { return _experienceLibrary; }
[[nodiscard]] Script* LoadScript(ScriptCategory category, const ConstString& scriptName) const; [[nodiscard]] Script* LoadScript(ScriptCategory category, const ConstString& scriptName) const;
}; };

View File

@ -7,7 +7,7 @@
using namespace CreatureLib; using namespace CreatureLib;
using namespace CreatureLib::Battling; using namespace CreatureLib::Battling;
const BattleLibrary* Battle::GetLibrary() const { return _library; } const BattleLibrary* Battle::GetLibrary() const noexcept { return _library; }
bool Battle::CanUse(const BaseTurnChoice* choice) { bool Battle::CanUse(const BaseTurnChoice* choice) {
AssertNotNull(choice) AssertNotNull(choice)
@ -69,9 +69,9 @@ void Battle::CheckChoicesSetAndRun() {
} }
} }
ChoiceQueue* Battle::GetCurrentTurnQueue() const { return _currentTurnQueue; } ChoiceQueue* Battle::GetCurrentTurnQueue() const noexcept { return _currentTurnQueue; }
BattleRandom* Battle::GetRandom() { return &_random; } BattleRandom* Battle::GetRandom() noexcept { return &_random; }
bool Battle::CreatureInField(const Creature* creature) const { bool Battle::CreatureInField(const Creature* creature) const {
AssertNotNull(creature) AssertNotNull(creature)
@ -87,7 +87,6 @@ void Battle::ForceRecall(uint8_t side, uint8_t index) { _sides[side]->SetCreatur
void Battle::GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) { scripts.Append(&_volatile); } void Battle::GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) { scripts.Append(&_volatile); }
void Battle::SwitchCreature(uint8_t sideIndex, uint8_t index, Creature* c) { void Battle::SwitchCreature(uint8_t sideIndex, uint8_t index, Creature* c) {
AssertNotNull(c)
auto side = this->_sides[sideIndex]; auto side = this->_sides[sideIndex];
side->SetCreature(c, index); side->SetCreature(c, index);
} }

View File

@ -57,18 +57,18 @@ namespace CreatureLib::Battling {
delete _currentTurnQueue; delete _currentTurnQueue;
} }
[[nodiscard]] const BattleLibrary* GetLibrary() const; [[nodiscard]] const BattleLibrary* GetLibrary() const noexcept;
[[nodiscard]] uint32_t GetCurrentTurn() const noexcept { return _currentTurn; } [[nodiscard]] uint32_t GetCurrentTurn() const noexcept { return _currentTurn; }
virtual bool CanUse(const BaseTurnChoice* choice); virtual bool CanUse(const BaseTurnChoice* choice);
virtual bool TrySetChoice(BaseTurnChoice* choice); virtual bool TrySetChoice(BaseTurnChoice* choice);
bool CanFlee() const { return _canFlee; } bool CanFlee() const noexcept { return _canFlee; }
void CheckChoicesSetAndRun(); void CheckChoicesSetAndRun();
[[nodiscard]] ChoiceQueue* GetCurrentTurnQueue() const; [[nodiscard]] ChoiceQueue* GetCurrentTurnQueue() const noexcept;
BattleRandom* GetRandom(); BattleRandom* GetRandom() noexcept;
bool CreatureInField(const Creature* creature) const; bool CreatureInField(const Creature* creature) const;
@ -84,12 +84,12 @@ namespace CreatureLib::Battling {
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override; void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override;
void ValidateBattleState(); void ValidateBattleState();
inline bool HasEnded() const { return _hasEnded; } inline bool HasEnded() const noexcept { return _hasEnded; }
inline const BattleResult& GetResult() const { return _battleResult; } inline const BattleResult& GetResult() const noexcept { return _battleResult; }
const List<BattleSide*>& GetSides() const { return _sides; } const List<BattleSide*>& GetSides() const noexcept { return _sides; }
Script* GetVolatileScript(const ConstString& key) const { return _volatile.Get(key); } Script* GetVolatileScript(const ConstString& key) const { return _volatile.Get(key); }
Script* GetVolatileScript(uint32_t keyHash) const { return _volatile.Get(keyHash); } Script* GetVolatileScript(uint32_t keyHash) const noexcept { return _volatile.Get(keyHash); }
void AddVolatileScript(const ConstString& key); void AddVolatileScript(const ConstString& key);
void AddVolatileScript(Script* script); void AddVolatileScript(Script* script);
void RemoveVolatileScript(const ConstString& name) { _volatile.Remove(name); } void RemoveVolatileScript(const ConstString& name) { _volatile.Remove(name); }

View File

@ -16,9 +16,9 @@ namespace CreatureLib::Battling {
static BattleResult Empty() { return BattleResult(false, 0); } static BattleResult Empty() { return BattleResult(false, 0); }
/// Whether or not the battle has ended with a conclusive result. /// Whether or not the battle has ended with a conclusive result.
bool IsConclusiveResult() const { return _conclusiveResult; } bool IsConclusiveResult() const noexcept { return _conclusiveResult; }
/// Get the index of the side that has won the battle. Only valid if the battle has a conclusive result. /// Get the index of the side that has won the battle. Only valid if the battle has a conclusive result.
uint8_t GetWinningSide() const { return _winningSide; } uint8_t GetWinningSide() const noexcept { return _winningSide; }
}; };
} }

View File

@ -39,14 +39,15 @@ void BattleSide::SetChoice(BaseTurnChoice* choice) {
} }
void BattleSide::SetCreature(Creature* creature, uint8_t index) { void BattleSide::SetCreature(Creature* creature, uint8_t index) {
AssertNotNull(creature)
auto old = _creatures[index]; auto old = _creatures[index];
if (old != nullptr) { if (old != nullptr) {
old->SetOnBattleField(false); old->SetOnBattleField(false);
} }
_creatures[index] = creature; _creatures[index] = creature;
creature->SetBattleData(_battle, this); if (creature != nullptr) {
creature->SetOnBattleField(true); creature->SetBattleData(_battle, this);
creature->SetOnBattleField(true);
}
if (_battle == nullptr) if (_battle == nullptr)
return; return;
for (auto side : _battle->GetSides()) { for (auto side : _battle->GetSides()) {

View File

@ -24,7 +24,12 @@ Battling::Creature::Creature(const BattleLibrary* library, const Library::Creatu
} }
void Battling::Creature::ChangeLevelBy(int8_t amount) { void Battling::Creature::ChangeLevelBy(int8_t amount) {
this->_level += amount; auto level = _level + amount;
if (level > _library->GetSettings()->GetMaximalLevel())
level = _library->GetSettings()->GetMaximalLevel();
if (level < 1)
level = 1;
_level = level;
_experience = _library->GetGrowthRateLibrary()->CalculateExperience(_species->GetGrowthRate(), _level); _experience = _library->GetGrowthRateLibrary()->CalculateExperience(_species->GetGrowthRate(), _level);
RecalculateFlatStats(); RecalculateFlatStats();
} }
@ -52,13 +57,17 @@ void Battling::Creature::ChangeStatBoost(Library::Statistic stat, int8_t diffAmo
this->RecalculateBoostedStat(stat); this->RecalculateBoostedStat(stat);
} }
uint32_t Battling::Creature::GetFlatStat(Library::Statistic stat) const { return _flatStats.GetStat(stat); } uint32_t Battling::Creature::GetFlatStat(Library::Statistic stat) const noexcept { return _flatStats.GetStat(stat); }
uint32_t Battling::Creature::GetBoostedStat(Library::Statistic stat) const { return _boostedStats.GetStat(stat); } uint32_t Battling::Creature::GetBoostedStat(Library::Statistic stat) const noexcept {
return _boostedStats.GetStat(stat);
}
uint32_t Battling::Creature::GetBaseStat(Library::Statistic stat) const { return _variant->GetStatistic(stat); } uint32_t Battling::Creature::GetBaseStat(Library::Statistic stat) const noexcept {
return _variant->GetStatistic(stat);
}
int8_t Battling::Creature::GetStatBoost(Library::Statistic stat) const { return _statBoost.GetStat(stat); } int8_t Battling::Creature::GetStatBoost(Library::Statistic stat) const noexcept { return _statBoost.GetStat(stat); }
void Battling::Creature::RecalculateFlatStats() { void Battling::Creature::RecalculateFlatStats() {
auto statCalc = this->_library->GetStatCalculator(); auto statCalc = this->_library->GetStatCalculator();
@ -174,13 +183,13 @@ void Battling::Creature::AddExperience(uint32_t amount) {
_experience = exp; _experience = exp;
_level = level; _level = level;
} }
const Library::CreatureSpecies* Battling::Creature::GetDisplaySpecies() const { const Library::CreatureSpecies* Battling::Creature::GetDisplaySpecies() const noexcept {
auto species = _displaySpecies; auto species = _displaySpecies;
if (species == nullptr) if (species == nullptr)
species = _species; species = _species;
return species; return species;
} }
const Library::SpeciesVariant* Battling::Creature::GetDisplayVariant() const { const Library::SpeciesVariant* Battling::Creature::GetDisplayVariant() const noexcept {
auto variant = _displayVariant; auto variant = _displayVariant;
if (variant == nullptr) if (variant == nullptr)
variant = _variant; variant = _variant;

View File

@ -129,21 +129,21 @@ namespace CreatureLib::Battling {
void RemoveVolatileScript(Script* script); void RemoveVolatileScript(Script* script);
bool HasVolatileScript(const ConstString& name) const; bool HasVolatileScript(const ConstString& name) const;
List<LearnedAttack*>& GetAttacks() { return _attacks; } List<LearnedAttack*>& GetAttacks() noexcept { return _attacks; }
const Library::CreatureSpecies* GetDisplaySpecies() const; const Library::CreatureSpecies* GetDisplaySpecies() const noexcept;
const Library::SpeciesVariant* GetDisplayVariant() const; const Library::SpeciesVariant* GetDisplayVariant() const noexcept;
const void SetDisplaySpecies(const Library::CreatureSpecies* species) { _displaySpecies = species; } const void SetDisplaySpecies(const Library::CreatureSpecies* species) noexcept { _displaySpecies = species; }
const void SetDisplayVariant(const Library::SpeciesVariant* variant) { _displayVariant = variant; }; const void SetDisplayVariant(const Library::SpeciesVariant* variant) noexcept { _displayVariant = variant; };
// region Stat APIs // region Stat APIs
void ChangeStatBoost(Library::Statistic stat, int8_t diffAmount); void ChangeStatBoost(Library::Statistic stat, int8_t diffAmount);
[[nodiscard]] uint32_t GetFlatStat(Library::Statistic stat) const; [[nodiscard]] uint32_t GetFlatStat(Library::Statistic stat) const noexcept;
[[nodiscard]] uint32_t GetBoostedStat(Library::Statistic stat) const; [[nodiscard]] uint32_t GetBoostedStat(Library::Statistic stat) const noexcept;
[[nodiscard]] uint32_t GetBaseStat(Library::Statistic stat) const; [[nodiscard]] uint32_t GetBaseStat(Library::Statistic stat) const noexcept;
[[nodiscard]] int8_t GetStatBoost(Library::Statistic stat) const; [[nodiscard]] int8_t GetStatBoost(Library::Statistic stat) const noexcept;
void RecalculateFlatStats(); void RecalculateFlatStats();
void RecalculateBoostedStats(); void RecalculateBoostedStats();
void RecalculateFlatStat(Library::Statistic); void RecalculateFlatStat(Library::Statistic);

View File

@ -10,16 +10,18 @@ namespace CreatureLib::Battling {
uint8_t _creature; uint8_t _creature;
public: public:
CreatureIndex() : _side(0), _creature(0) {} CreatureIndex() noexcept : _side(0), _creature(0) {}
CreatureIndex(uint8_t side, uint8_t creature) : _side(side), _creature(creature) {} CreatureIndex(uint8_t side, uint8_t creature) noexcept : _side(side), _creature(creature) {}
uint8_t GetSideIndex() const { return _side; } uint8_t GetSideIndex() const noexcept { return _side; }
uint8_t GetCreatureIndex() const { return _creature; } uint8_t GetCreatureIndex() const noexcept { return _creature; }
bool operator==(const CreatureIndex& rhs) const { return (_side == rhs._side) && (_creature == rhs._creature); } bool operator==(const CreatureIndex& rhs) const noexcept {
return (_side == rhs._side) && (_creature == rhs._creature);
}
bool operator!=(const CreatureIndex& rhs) const { return !operator==(rhs); } bool operator!=(const CreatureIndex& rhs) const noexcept { return !operator==(rhs); }
}; };
} }

View File

@ -9,25 +9,25 @@ namespace CreatureLib::Battling {
Arbutils::Collections::List<Creature*> _party; Arbutils::Collections::List<Creature*> _party;
public: public:
CreatureParty(size_t size) : _party(size) {} CreatureParty(size_t size) noexcept : _party(size) {}
CreatureParty(Arbutils::Collections::List<Creature*> party) : _party(party) {} CreatureParty(Arbutils::Collections::List<Creature*> party) noexcept : _party(party) {}
CreatureParty(std::initializer_list<Creature*> party) : _party(party) {} CreatureParty(std::initializer_list<Creature*> party) noexcept : _party(party) {}
virtual ~CreatureParty() { virtual ~CreatureParty() noexcept {
for (auto c : _party) { for (auto c : _party) {
delete c; delete c;
} }
} }
Creature* GetAtIndex(size_t index) const { return _party[index]; } Creature* GetAtIndex(size_t index) const noexcept { return _party[index]; }
void Switch(size_t a, size_t b) { void Switch(size_t a, size_t b) noexcept {
auto ca = _party[a]; auto ca = _party[a];
_party[a] = _party[b]; _party[a] = _party[b];
_party[b] = ca; _party[b] = ca;
} }
bool HasAvailableCreatures() const { bool HasAvailableCreatures() const noexcept {
for (Creature* c : _party) { for (Creature* c : _party) {
if (c == nullptr) if (c == nullptr)
continue; continue;
@ -38,10 +38,10 @@ namespace CreatureLib::Battling {
return false; return false;
} }
Arbutils::Collections::List<Creature*>& GetParty() { return _party; } Arbutils::Collections::List<Creature*>& GetParty() noexcept { return _party; }
const Arbutils::Collections::List<Creature*>& GetParty() const { return _party; } const Arbutils::Collections::List<Creature*>& GetParty() const noexcept { return _party; }
size_t GetLength() const { return _party.Count(); } size_t GetLength() const noexcept { return _party.Count(); }
}; };
} }

View File

@ -8,7 +8,7 @@
namespace CreatureLib::Battling { namespace CreatureLib::Battling {
class ScriptSet { class ScriptSet {
Arbutils::Collections::List<Script*> _scripts; Arbutils::Collections::List<Script*> _scripts;
std::unordered_map<uint32_t, size_t> _lookup; Arbutils::Collections::Dictionary<uint32_t, size_t> _lookup;
public: public:
~ScriptSet() { ~ScriptSet() {
@ -18,22 +18,23 @@ namespace CreatureLib::Battling {
} }
void Add(Script* script) { void Add(Script* script) {
auto f = _lookup.find(script->GetName()); size_t v;
if (f != _lookup.end()) { if (_lookup.TryGet(script->GetName(), v)) {
_scripts[f.operator*().second]->Stack(); _scripts[v]->Stack();
delete script; delete script;
return; return;
} }
_scripts.Append(script); _scripts.Append(script);
_lookup.insert({script->GetName(), _scripts.Count() - 1}); _lookup.Insert(script->GetName(), _scripts.Count() - 1);
} }
Script* Get(const ConstString& key) const { return Get(key.GetHash()); } Script* Get(const ConstString& key) const { return Get(key.GetHash()); }
Script* Get(uint32_t keyHash) const { Script* Get(uint32_t keyHash) const noexcept {
auto f = _lookup.find(keyHash); size_t v;
if (f != _lookup.end()) { if (_lookup.TryGet(keyHash, v)) {
return _scripts[f->second]; return _scripts[v];
} }
return nullptr; return nullptr;
} }
@ -41,27 +42,28 @@ namespace CreatureLib::Battling {
void Remove(const ConstString& key) { Remove(key.GetHash()); } void Remove(const ConstString& key) { Remove(key.GetHash()); }
void Remove(uint32_t keyHash) { void Remove(uint32_t keyHash) {
auto find = _lookup.find(keyHash); size_t v;
if (find != _lookup.end()) { if (_lookup.TryGet(keyHash, v)) {
auto script = _scripts[find->second]; auto script = _scripts[v];
script->OnRemove(); script->OnRemove();
delete script; delete script;
_scripts.Remove(find.operator*().second); _scripts.Remove(v);
_lookup.erase(keyHash); _lookup.Remove(keyHash);
} }
} }
void Clear() { void Clear() {
for (auto s : _scripts) { for (auto s : _scripts) {
s->OnRemove();
delete s; delete s;
} }
_scripts.Clear(); _scripts.Clear();
_lookup.clear(); _lookup.Clear();
} }
bool Has(const ConstString& key) const { return _lookup.find(key) != _lookup.end(); } bool Has(const ConstString& key) const { return _lookup.Has(key); }
bool Has(uint32_t keyHash) const { return _lookup.find(keyHash) != _lookup.end(); } bool Has(uint32_t keyHash) const { return _lookup.Has(keyHash); }
size_t Count() const { return _scripts.Count(); } size_t Count() const { return _scripts.Count(); }

View File

@ -32,21 +32,21 @@ namespace CreatureLib::Battling {
AssertNotNull(attack) AssertNotNull(attack)
ResolveScript(); ResolveScript();
} }
AttackTurnChoice(Creature* user, LearnedAttack* attack, const CreatureIndex& target, Script* script) AttackTurnChoice(Creature* user, LearnedAttack* attack, const CreatureIndex& target, Script* script) noexcept
: BaseTurnChoice(user), _attack(attack), _target(target), _attackScript(script) {} : BaseTurnChoice(user), _attack(attack), _target(target), _attackScript(script) {}
inline LearnedAttack* GetAttack() const { return _attack; } inline LearnedAttack* GetAttack() const noexcept { return _attack; }
TurnChoiceKind GetKind() const override { return TurnChoiceKind ::Attack; } TurnChoiceKind GetKind() const noexcept override { return TurnChoiceKind ::Attack; }
int8_t GetPriority() const { int8_t GetPriority() const {
// HOOK: Change priority // HOOK: Change priority
return _attack->GetAttack()->GetPriority(); return _attack->GetAttack()->GetPriority();
} }
const CreatureIndex& GetTarget() const { return _target; } const CreatureIndex& GetTarget() const noexcept { return _target; }
Script* GetAttackScript() const { return _attackScript; } Script* GetAttackScript() const noexcept { return _attackScript; }
protected: protected:
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override { void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {

View File

@ -12,12 +12,12 @@ namespace CreatureLib::Battling {
Creature* _user; Creature* _user;
protected: protected:
BaseTurnChoice(Creature* user) : _user(user){}; BaseTurnChoice(Creature* user) noexcept : _user(user){};
public: public:
virtual ~BaseTurnChoice() = default; virtual ~BaseTurnChoice() = default;
[[nodiscard]] virtual TurnChoiceKind GetKind() const = 0; [[nodiscard]] virtual TurnChoiceKind GetKind() const noexcept = 0;
[[nodiscard]] inline Creature* GetUser() const { return _user; } [[nodiscard]] inline Creature* GetUser() const noexcept { return _user; }
}; };
} }

View File

@ -9,7 +9,7 @@ namespace CreatureLib::Battling {
public: public:
FleeTurnChoice(Creature* user) : BaseTurnChoice(user) {} FleeTurnChoice(Creature* user) : BaseTurnChoice(user) {}
TurnChoiceKind GetKind() const override { return TurnChoiceKind ::Flee; } TurnChoiceKind GetKind() const noexcept override { return TurnChoiceKind ::Flee; }
protected: protected:
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override { void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {

View File

@ -8,7 +8,7 @@ namespace CreatureLib::Battling {
public: public:
PassTurnChoice(Creature* c) : BaseTurnChoice(c) {} PassTurnChoice(Creature* c) : BaseTurnChoice(c) {}
TurnChoiceKind GetKind() const override { return TurnChoiceKind ::Pass; } TurnChoiceKind GetKind() const noexcept override { return TurnChoiceKind ::Pass; }
protected: protected:
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override { void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {

View File

@ -7,13 +7,12 @@ namespace CreatureLib::Battling {
Creature* _newCreature; Creature* _newCreature;
public: public:
SwitchTurnChoice(Creature* user, Creature* newCreature) : BaseTurnChoice(user), _newCreature(newCreature) { SwitchTurnChoice(Creature* user, Creature* newCreature) noexcept
AssertNotNull(_newCreature) : BaseTurnChoice(user), _newCreature(newCreature) {}
}
TurnChoiceKind GetKind() const final { return TurnChoiceKind::Switch; } TurnChoiceKind GetKind() const noexcept final { return TurnChoiceKind::Switch; }
inline Creature* GetNewCreature() const { return _newCreature; } inline Creature* GetNewCreature() const noexcept { return _newCreature; }
protected: protected:
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override { void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {

View File

@ -9,9 +9,9 @@ CreatureLib::Library::AttackData::AttackData(const ConstString& name, uint8_t ty
: _name(std::move(name)), _type(type), _category(category), _basePower(power), _accuracy(accuracy), : _name(std::move(name)), _type(type), _category(category), _basePower(power), _accuracy(accuracy),
_baseUsages(baseUsage), _target(target), _priority(priority), _flags(std::move(flags)) {} _baseUsages(baseUsage), _target(target), _priority(priority), _flags(std::move(flags)) {}
bool CreatureLib::Library::AttackData::HasFlag(const ConstString& key) const { bool CreatureLib::Library::AttackData::HasFlag(const ConstString& key) const noexcept {
return this->_flags.find(key) != this->_flags.end(); return this->_flags.find(key) != this->_flags.end();
} }
bool CreatureLib::Library::AttackData::HasFlag(uint32_t key) const { bool CreatureLib::Library::AttackData::HasFlag(uint32_t key) const noexcept {
return this->_flags.find(key) != this->_flags.end(); return this->_flags.find(key) != this->_flags.end();
} }

View File

@ -27,17 +27,17 @@ namespace CreatureLib::Library {
uint8_t baseUsage, AttackTarget target, int8_t priority, std::unordered_set<uint32_t> flags); uint8_t baseUsage, AttackTarget target, int8_t priority, std::unordered_set<uint32_t> flags);
virtual ~AttackData() = default; virtual ~AttackData() = default;
inline const ConstString& GetName() const { return _name; } inline const ConstString& GetName() const noexcept { return _name; }
inline const uint8_t GetType() const { return _type; } inline const uint8_t GetType() const noexcept { return _type; }
inline AttackCategory GetCategory() const { return _category; } inline AttackCategory GetCategory() const noexcept { return _category; }
inline uint8_t GetBasePower() const { return _basePower; } inline uint8_t GetBasePower() const noexcept { return _basePower; }
inline uint8_t GetAccuracy() const { return _accuracy; } inline uint8_t GetAccuracy() const noexcept { return _accuracy; }
inline uint8_t GetBaseUsages() const { return _baseUsages; } inline uint8_t GetBaseUsages() const noexcept { return _baseUsages; }
inline AttackTarget GetTarget() const { return _target; } inline AttackTarget GetTarget() const noexcept { return _target; }
inline int8_t GetPriority() const { return _priority; } inline int8_t GetPriority() const noexcept { return _priority; }
bool HasFlag(const ConstString& key) const; bool HasFlag(const ConstString& key) const noexcept;
bool HasFlag(uint32_t keyHash) const; bool HasFlag(uint32_t keyHash) const noexcept;
}; };
} }

View File

@ -15,24 +15,26 @@ CreatureLib::Library::DataLibrary::DataLibrary(LibrarySettings* settings, Creatu
AssertNotNull(_typeLibrary) AssertNotNull(_typeLibrary)
} }
const CreatureLib::Library::LibrarySettings* CreatureLib::Library::DataLibrary::GetSettings() const { const CreatureLib::Library::LibrarySettings* CreatureLib::Library::DataLibrary::GetSettings() const noexcept {
return _settings; return _settings;
} }
const CreatureLib::Library::SpeciesLibrary* CreatureLib::Library::DataLibrary::GetSpeciesLibrary() const { const CreatureLib::Library::SpeciesLibrary* CreatureLib::Library::DataLibrary::GetSpeciesLibrary() const noexcept {
return _species; return _species;
} }
const CreatureLib::Library::AttackLibrary* CreatureLib::Library::DataLibrary::GetAttackLibrary() const { const CreatureLib::Library::AttackLibrary* CreatureLib::Library::DataLibrary::GetAttackLibrary() const noexcept {
return _attacks; return _attacks;
} }
const CreatureLib::Library::ItemLibrary* CreatureLib::Library::DataLibrary::GetItemLibrary() const { return _items; } const CreatureLib::Library::ItemLibrary* CreatureLib::Library::DataLibrary::GetItemLibrary() const noexcept {
return _items;
}
const CreatureLib::Library::GrowthRateLibrary* CreatureLib::Library::DataLibrary::GetGrowthRates() const { const CreatureLib::Library::GrowthRateLibrary* CreatureLib::Library::DataLibrary::GetGrowthRates() const noexcept {
return _growthRates; return _growthRates;
} }
const CreatureLib::Library::TypeLibrary* CreatureLib::Library::DataLibrary::GetTypeLibrary() const { const CreatureLib::Library::TypeLibrary* CreatureLib::Library::DataLibrary::GetTypeLibrary() const noexcept {
return _typeLibrary; return _typeLibrary;
} }

View File

@ -34,12 +34,12 @@ namespace CreatureLib::Library {
delete _typeLibrary; delete _typeLibrary;
} }
[[nodiscard]] const LibrarySettings* GetSettings() const; [[nodiscard]] const LibrarySettings* GetSettings() const noexcept;
[[nodiscard]] const SpeciesLibrary* GetSpeciesLibrary() const; [[nodiscard]] const SpeciesLibrary* GetSpeciesLibrary() const noexcept;
[[nodiscard]] const AttackLibrary* GetAttackLibrary() const; [[nodiscard]] const AttackLibrary* GetAttackLibrary() const noexcept;
[[nodiscard]] const ItemLibrary* GetItemLibrary() const; [[nodiscard]] const ItemLibrary* GetItemLibrary() const noexcept;
[[nodiscard]] const GrowthRateLibrary* GetGrowthRates() const; [[nodiscard]] const GrowthRateLibrary* GetGrowthRates() const noexcept;
[[nodiscard]] const TypeLibrary* GetTypeLibrary() const; [[nodiscard]] const TypeLibrary* GetTypeLibrary() const noexcept;
}; };
} }

View File

@ -1,9 +1,11 @@
#include "Item.hpp" #include "Item.hpp"
bool CreatureLib::Library::Item::HasFlag(const Arbutils::CaseInsensitiveConstString& flag) const { bool CreatureLib::Library::Item::HasFlag(const Arbutils::CaseInsensitiveConstString& flag) const noexcept {
return this->_flags.find(flag) != this->_flags.end();
}
bool CreatureLib::Library::Item::HasFlag(uint32_t flag) const noexcept {
return this->_flags.find(flag) != this->_flags.end(); return this->_flags.find(flag) != this->_flags.end();
} }
bool CreatureLib::Library::Item::HasFlag(uint32_t flag) const { return this->_flags.find(flag) != this->_flags.end(); }
CreatureLib::Library::Item::Item(const Arbutils::CaseInsensitiveConstString& name, CreatureLib::Library::Item::Item(const Arbutils::CaseInsensitiveConstString& name,
CreatureLib::Library::ItemCategory category, CreatureLib::Library::ItemCategory category,

View File

@ -20,13 +20,13 @@ namespace CreatureLib::Library {
Item(const Arbutils::CaseInsensitiveConstString& name, ItemCategory category, BattleItemCategory battleCategory, Item(const Arbutils::CaseInsensitiveConstString& name, ItemCategory category, BattleItemCategory battleCategory,
int32_t price, std::unordered_set<uint32_t> flags); int32_t price, std::unordered_set<uint32_t> flags);
inline const Arbutils::CaseInsensitiveConstString& GetName() const { return _name; } inline const Arbutils::CaseInsensitiveConstString& GetName() const noexcept { return _name; }
inline ItemCategory GetCategory() const { return _category; } inline ItemCategory GetCategory() const noexcept { return _category; }
inline BattleItemCategory GetBattleCategory() const { return _battleCategory; } inline BattleItemCategory GetBattleCategory() const noexcept { return _battleCategory; }
inline const int32_t GetPrice() const { return _price; } inline const int32_t GetPrice() const noexcept { return _price; }
bool HasFlag(const Arbutils::CaseInsensitiveConstString& flag) const; bool HasFlag(const Arbutils::CaseInsensitiveConstString& flag) const noexcept;
bool HasFlag(uint32_t flag) const; bool HasFlag(uint32_t flag) const noexcept;
}; };
} }