Added lots of security using asserts.
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2020-03-22 13:42:26 +01:00
parent 970ca8ddd5
commit 899e432271
35 changed files with 138 additions and 56 deletions

View File

@@ -1,6 +1,8 @@
#include "ChoiceQueue.hpp"
#include <Arbutils/Assert.hpp>
bool CreatureLib::Battling::ChoiceQueue::MoveCreatureChoiceNext(CreatureLib::Battling::Creature* creature) {
AssertNotNull(creature)
// Find which index the creature choice is at.
size_t choiceIndex = SIZE_MAX;
for (size_t index = _current; index < _queue.size(); index++) {

View File

@@ -1,11 +1,12 @@
#include "TurnHandler.hpp"
#include <Arbutils/Assert.hpp>
#include "../../Library/Exceptions/NotImplementedException.hpp"
#include "../Models/Battle.hpp"
#include "../ScriptHandling/ScriptMacros.hpp"
using namespace CreatureLib::Battling;
void TurnHandler::RunTurn(Battle* battle, ChoiceQueue* queue) {
void TurnHandler::RunTurn(ChoiceQueue* queue) {
AssertNotNull(queue)
for (auto choice : queue->GetInnerQueue()) {
HOOK(OnBeforeTurn, choice, choice);
}
@@ -31,6 +32,7 @@ void TurnHandler::ExecuteChoice(BaseTurnChoice* choice) {
return;
}
auto battle = user->GetBattle();
AssertNotNull(battle)
// If the user is not in the field, we don't want to execute its choice.
if (!battle->CreatureInField(user)) {
return;
@@ -51,6 +53,7 @@ void TurnHandler::ExecuteChoice(BaseTurnChoice* choice) {
}
void TurnHandler::ExecuteAttackChoice(AttackTurnChoice* choice) {
AssertNotNull(choice)
auto attackName = choice->GetAttack()->GetAttack()->GetName();
HOOK(ChangeAttack, choice, choice, &attackName);
if (attackName != choice->GetAttack()->GetAttack()->GetName()) {

View File

@@ -21,7 +21,7 @@ namespace CreatureLib::Battling {
static void ExecuteFleeChoice(FleeTurnChoice* choice);
public:
static void RunTurn(Battle* battle, ChoiceQueue* queue);
static void RunTurn(ChoiceQueue* queue);
};
}