Added lots of security using asserts.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "Battle.hpp"
|
||||
#include <Arbutils/Assert.hpp>
|
||||
#include "../../Library/Exceptions/NotImplementedException.hpp"
|
||||
#include "../Flow/TurnHandler.hpp"
|
||||
#include "../Flow/TurnOrdering.hpp"
|
||||
@@ -9,6 +10,7 @@ using namespace CreatureLib::Battling;
|
||||
const BattleLibrary* Battle::GetLibrary() const { return _library; }
|
||||
|
||||
bool Battle::CanUse(const BaseTurnChoice* choice) {
|
||||
AssertNotNull(choice)
|
||||
if (choice->GetKind() == TurnChoiceKind::Attack) {
|
||||
// HOOK: change number of uses needed.
|
||||
return dynamic_cast<const AttackTurnChoice*>(choice)->GetAttack()->GetRemainingUses() > 1;
|
||||
@@ -17,6 +19,7 @@ bool Battle::CanUse(const BaseTurnChoice* choice) {
|
||||
}
|
||||
|
||||
bool Battle::TrySetChoice(BaseTurnChoice* choice) {
|
||||
AssertNotNull(choice)
|
||||
if (!CanUse(choice))
|
||||
return false;
|
||||
choice->GetUser()->GetBattleSide()->SetChoice(choice);
|
||||
@@ -40,9 +43,7 @@ void Battle::CheckChoicesSetAndRun() {
|
||||
auto i = 0;
|
||||
for (auto side : _sides) {
|
||||
for (BaseTurnChoice* choice : side->GetChoices()) {
|
||||
if (choice == nullptr) {
|
||||
throw CreatureException("Choice was null");
|
||||
}
|
||||
AssertNotNull(choice)
|
||||
if (choice->GetKind() == TurnChoiceKind::Attack) {
|
||||
auto attack = (dynamic_cast<AttackTurnChoice*>((choice)))->GetAttack();
|
||||
uint8_t uses = 1;
|
||||
@@ -60,7 +61,7 @@ void Battle::CheckChoicesSetAndRun() {
|
||||
}
|
||||
TurnOrdering::OrderChoices(choices, _random.GetRNG());
|
||||
this->_currentTurnQueue = new ChoiceQueue(choices);
|
||||
TurnHandler::RunTurn(this, this->_currentTurnQueue);
|
||||
TurnHandler::RunTurn(this->_currentTurnQueue);
|
||||
if (this->_currentTurnQueue->HasCompletedQueue) {
|
||||
delete this->_currentTurnQueue;
|
||||
this->_currentTurnQueue = nullptr;
|
||||
@@ -72,6 +73,7 @@ ChoiceQueue* Battle::GetCurrentTurnQueue() const { return _currentTurnQueue; }
|
||||
BattleRandom* Battle::GetRandom() { return &_random; }
|
||||
|
||||
bool Battle::CreatureInField(const Creature* creature) const {
|
||||
AssertNotNull(creature)
|
||||
for (auto s : _sides) {
|
||||
if (s->CreatureOnSide(creature))
|
||||
return true;
|
||||
@@ -84,6 +86,7 @@ void Battle::ForceRecall(uint8_t side, uint8_t index) { _sides[side]->SetCreatur
|
||||
void Battle::GetActiveScripts(std::vector<ScriptWrapper>& scripts) { scripts.emplace_back(&_volatile); }
|
||||
|
||||
void Battle::SwitchCreature(uint8_t sideIndex, uint8_t index, Creature* c) {
|
||||
AssertNotNull(c)
|
||||
auto side = this->_sides[sideIndex];
|
||||
side->SetCreature(c, index);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user