CreatureLib/CInterface/Battling/Battle.cpp

88 lines
4.5 KiB
C++
Raw Normal View History

#include "../../src/Battling/Models/Battle.hpp"
#include "../Core.hpp"
using namespace CreatureLib::Battling;
export u8 CreatureLib_Battle_Construct(Battle*& out, const BattleLibrary* library, BattleParty* partyArr[],
size_t numberOfParties, bool canFlee, u8 numberOfSides, u8 creaturesPerSide,
uint_fast32_t randomSeed) {
2020-05-26 16:31:06 +00:00
Try(ArbUt::List<BattleParty*> parties(partyArr, partyArr + numberOfParties);
2020-07-26 08:16:25 +00:00
out = new Battle(library, parties, canFlee, numberOfSides, creaturesPerSide, randomSeed);)
}
export void CreatureLib_Battle_Destruct(const Battle* p) { delete p; }
2020-05-26 16:31:06 +00:00
export const BattleLibrary* CreatureLib_Battle_GetLibrary(const Battle* p) { return p->GetLibrary().GetRaw(); }
export u8 CreatureLib_Battle_CanUse(bool& out, Battle* p, BaseTurnChoice* turnChoice) {
Try(out = p->CanUse(turnChoice);)
}
export u8 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 u8 CreatureLib_Battle_CheckChoicesSetAndRun(Battle* p) { Try(p->CheckChoicesSetAndRun();) }
export u32 CreatureLib_Battle_GetCurrentTurn(Battle* p) { return p->GetCurrentTurn(); }
export u32 CreatureLib_Battle_GetCreaturesPerSide(Battle* p) { return p->GetCreaturesPerSide(); }
export ChoiceQueue* CreatureLib_Battle_GetCurrentTurnQueue(const Battle* p) {
return p->GetCurrentTurnQueue().GetRaw();
}
export BattleRandom* CreatureLib_Battle_GetRandom(Battle* p) { return p->GetRandom(); }
export u8 CreatureLib_Battle_CreatureInField(bool& out, const Battle* p, Creature* c) {
Try(out = p->CreatureInField(c);)
}
export u8 CreatureLib_Battle_GetCreature(Creature*& out, const Battle* p, u8 side, u8 target) {
Try(out = p->GetCreature(side, target).GetValue();)
}
export u8 CreatureLib_Battle_ForceRecall(Battle* p, u8 side, u8 target) { Try(p->ForceRecall(side, target);) }
export u8 CreatureLib_Battle_SwitchCreature(Battle* p, u8 side, u8 target, Creature* c) {
Try(p->SwitchCreature(side, target, c);)
}
export u8 CreatureLib_Battle_CanSlotBeFilled(bool& out, const Battle* p, u8 side, u8 target) {
Try(out = p->CanSlotBeFilled(side, target);)
}
export u8 CreatureLib_Battle_ValidateBattleState(Battle* p) { Try(p->ValidateBattleState();) }
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_GetWinningSide(const Battle* p) { return p->GetResult().GetWinningSide(); }
export size_t CreatureLib_Battle_GetSidesCount(const Battle* p) { return p->GetSides().Count(); }
export BattleSide* const* CreatureLib_Battle_GetSides(const Battle* p) { return p->GetSides().RawData(); }
2020-05-24 10:57:12 +00:00
export size_t CreatureLib_Battle_GetPartiesCount(const Battle* p) { return p->GetParties().Count(); }
2020-05-26 16:31:06 +00:00
export BattleParty* const* CreatureLib_Battle_GetParties(const Battle* p) {
return reinterpret_cast<BattleParty* const*>(p->GetParties().RawData());
}
2020-05-24 10:57:12 +00:00
export BattleScript* CreatureLib_Battle_GetVolatileScript(Battle* p, const char* key) {
auto v = p->GetVolatileScript(ArbUt::StringView::CalculateHash(key));
if (!v.HasValue()) {
return nullptr;
}
return v.GetValue();
}
export u8 CreatureLib_Battle_AddVolatileScriptByName(Battle* p, const char* key) {
2020-06-26 15:08:23 +00:00
Try(p->AddVolatileScript(ArbUt::StringView(key));)
}
export u8 CreatureLib_Battle_AddVolatileScript(Battle* p, BattleScript* script) { Try(p->AddVolatileScript(script);) }
export u8 CreatureLib_Battle_RemoveVolatileScript(Battle* p, const char* key) {
2020-06-26 15:08:23 +00:00
Try(p->RemoveVolatileScript(ArbUt::StringView::CalculateHash(key));)
}
export u8 CreatureLib_Battle_RemoveVolatileScriptWithScript(Battle* p, BattleScript* script) {
Try(p->RemoveVolatileScript(script);)
}
export bool CreatureLib_Battle_HasVolatileScript(Battle* p, const char* key) {
2020-06-26 15:08:23 +00:00
return p->HasVolatileScript(ArbUt::StringView::CalculateHash(key));
}
export u8 CreatureLib_Battle_RegisterEventListener(Battle* p, void (*func)(const EventData*)) {
Try(p->RegisterEventListener(func);)
}
export const HistoryHolder* CreatureLib_Battle_GetHistory(Battle* p) { return p->GetHistory(); }
export u8 CreatureLib_Battle_EndBattle(Battle* p) { Try(p->EndBattle()) }
export u8 CreatureLib_Battle_ClearBattle(Battle* p) { Try(p->ClearBattle()) }
SIMPLE_GET_FUNC(Battle, GetLastTurnTimeMicroseconds, long);