diff --git a/CInterface/Battling/BattleSide.cpp b/CInterface/Battling/BattleSide.cpp new file mode 100644 index 0000000..3084049 --- /dev/null +++ b/CInterface/Battling/BattleSide.cpp @@ -0,0 +1,42 @@ +#include "../../src/Battling/Models/BattleSide.hpp" +#include "../Core.hpp" +using namespace CreatureLib::Battling; + +export BattleSide* CreatureLib_BattleSide_Construct(uint8_t index, Battle* battle, uint8_t creaturesPerSide) { + return new BattleSide(index, battle, creaturesPerSide); +} + +export void CreatureLib_BattleSide_Destruct(BattleSide* p) { delete p; } + +export bool CreatureLib_BattleSide_AllChoicesSet(BattleSide* p) { return p->AllChoicesSet(); } + +export BaseTurnChoice* const* CreatureLib_BattleSide_GetChoices(BattleSide* p) { return p->GetChoices().RawData(); } + +export uint8_t CreatureLib_BattleSide_AllPossibleSlotsFilled(bool& out, BattleSide* p) { + Try(out = p->AllPossibleSlotsFilled()); +} + +export uint8_t CreatureLib_BattleSide_SetChoice(BattleSide* p, BaseTurnChoice* choice) { Try(p->SetChoice(choice);) } + +export void CreatureLib_BattleSide_ResetChoices(BattleSide* p) { p->ResetChoices(); } + +export uint8_t CreatureLib_BattleSide_SetCreature(BattleSide* p, Creature* creature, uint8_t index) { + Try(p->SetCreature(creature, index)); +} + +export uint8_t CreatureLib_BattleSide_GetCreature(Creature*& out, BattleSide* p, uint8_t index) { + Try(out = p->GetCreature(index)); +} + +export uint8_t CreatureLib_BattleSide_GetSideIndex(BattleSide* p) { return p->GetSideIndex(); } +export uint8_t CreatureLib_BattleSide_GetCreatureIndex(uint8_t& out, BattleSide* p, Creature* c) { + Try(out = p->GetCreatureIndex(c)); +} + +export uint8_t CreatureLib_BattleSide_MarkSlotAsUnfillable(BattleSide* p, Creature* c) { + Try(p->MarkSlotAsUnfillable(c)); +} + +export bool CreatureLib_BattleSide_IsDefeated(BattleSide* p) { return p->IsDefeated(); } +export bool CreatureLib_BattleSide_HasFled(BattleSide* p) { return p->HasFled(); } +export void CreatureLib_BattleSide_MarkAsFled(BattleSide* p) { p->MarkAsFled(); } \ No newline at end of file diff --git a/src/Battling/Models/BattleSide.cpp b/src/Battling/Models/BattleSide.cpp index d335fc0..1ca934f 100644 --- a/src/Battling/Models/BattleSide.cpp +++ b/src/Battling/Models/BattleSide.cpp @@ -5,7 +5,7 @@ using namespace CreatureLib::Battling; -bool BattleSide::AllChoicesSet() const { return _choicesSet == _creaturesPerSide; } +bool BattleSide::AllChoicesSet() const noexcept { return _choicesSet == _creaturesPerSide; } bool BattleSide::AllPossibleSlotsFilled() const { AssertNotNull(_battle) @@ -19,14 +19,14 @@ bool BattleSide::AllPossibleSlotsFilled() const { return true; } -void BattleSide::ResetChoices() { +void BattleSide::ResetChoices() noexcept { _choicesSet = 0; for (uint8_t i = 0; i < _creaturesPerSide; i++) { _choices[i] = nullptr; } } -const List& BattleSide::GetChoices() const { return _choices; } +const List& BattleSide::GetChoices() const noexcept { return _choices; } void BattleSide::SetChoice(BaseTurnChoice* choice) { AssertNotNull(choice) diff --git a/src/Battling/Models/BattleSide.hpp b/src/Battling/Models/BattleSide.hpp index 914343d..5189d89 100644 --- a/src/Battling/Models/BattleSide.hpp +++ b/src/Battling/Models/BattleSide.hpp @@ -22,7 +22,7 @@ namespace CreatureLib::Battling { bool _hasFled = false; public: - explicit BattleSide(uint8_t index, Battle* battle, uint8_t creaturesPerSide) + BattleSide(uint8_t index, Battle* battle, uint8_t creaturesPerSide) noexcept : _index(index), _creaturesPerSide(creaturesPerSide), _creatures(creaturesPerSide), _choices(creaturesPerSide), _fillableSlots(creaturesPerSide), _battle(battle) { for (size_t i = 0; i < creaturesPerSide; i++) { @@ -35,24 +35,24 @@ namespace CreatureLib::Battling { virtual ~BattleSide() = default; - [[nodiscard]] bool AllChoicesSet() const; - [[nodiscard]] const List& GetChoices() const; + [[nodiscard]] bool AllChoicesSet() const noexcept; + [[nodiscard]] const List& GetChoices() const noexcept; [[nodiscard]] bool AllPossibleSlotsFilled() const; void SetChoice(BaseTurnChoice* choice); - void ResetChoices(); + void ResetChoices() noexcept; void SetCreature(Creature* creature, uint8_t index); Creature* GetCreature(uint8_t index) const; bool CreatureOnSide(const Creature* creature) const; - void GetActiveScripts(Arbutils::Collections::List& scripts) final; + void GetActiveScripts(Arbutils::Collections::List& scripts) override; const List& GetCreatures() { return _creatures; } - uint8_t GetSideIndex() { return _index; } + uint8_t GetSideIndex() noexcept { return _index; } uint8_t GetCreatureIndex(Creature* c) { for (size_t i = 0; i < _creatures.Count(); i++) { if (c == _creatures[i]) @@ -61,7 +61,7 @@ namespace CreatureLib::Battling { throw CreatureException("Unable to find creature on field."); } - void MarkSlotAsUnfillable(Creature* creature) { + void MarkSlotAsUnfillable(Creature* creature) noexcept { for (uint8_t i = 0; i < _creaturesPerSide; i++) { if (_creatures[i] == creature) { _fillableSlots.At(i) = false; @@ -70,7 +70,7 @@ namespace CreatureLib::Battling { } } - bool IsDefeated() { + bool IsDefeated() noexcept { for (auto b : _fillableSlots) { if (b) return false; @@ -78,9 +78,9 @@ namespace CreatureLib::Battling { return true; } - bool HasFled() { return _hasFled; } + bool HasFled() noexcept { return _hasFled; } - void MarkAsFled() { _hasFled = true; } + void MarkAsFled() noexcept { _hasFled = true; } uint8_t GetRandomCreatureIndex(); }; diff --git a/src/Battling/Models/Creature.cpp b/src/Battling/Models/Creature.cpp index b682aea..688e7b5 100644 --- a/src/Battling/Models/Creature.cpp +++ b/src/Battling/Models/Creature.cpp @@ -103,8 +103,8 @@ void Battling::Creature::OnFaint() { _battle->TriggerEventListener(new FaintEvent(this)); } _library->GetExperienceLibrary()->HandleExperienceGain(this, _seenOpponents); - - if (!_battle->CanSlotBeFilled(_side->GetSideIndex(), _side->GetCreatureIndex(this))) { + auto sideIndex = _side->GetCreatureIndex(this); + if (!_battle->CanSlotBeFilled(_side->GetSideIndex(), sideIndex)) { _side->MarkSlotAsUnfillable(this); } _battle->ValidateBattleState();