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

@@ -8,6 +8,7 @@ using namespace CreatureLib::Battling;
bool BattleSide::AllChoicesSet() const { return _choicesSet == _creaturesPerSide; }
bool BattleSide::AllPossibleSlotsFilled() const {
AssertNotNull(_battle)
for (size_t i = 0; i < _creatures.size(); i++) {
auto c = _creatures[i];
if (c == nullptr || c->IsFainted()) {
@@ -28,6 +29,7 @@ void BattleSide::ResetChoices() {
const std::vector<BaseTurnChoice*>& BattleSide::GetChoices() const { return _choices; }
void BattleSide::SetChoice(BaseTurnChoice* choice) {
AssertNotNull(choice)
auto find = std::find(_creatures.begin(), _creatures.end(), choice->GetUser());
if (find == _creatures.end())
throw CreatureException("User not found");
@@ -37,6 +39,7 @@ void BattleSide::SetChoice(BaseTurnChoice* choice) {
}
void BattleSide::SetCreature(Creature* creature, uint8_t index) {
AssertNotNull(creature)
auto old = _creatures[index];
if (old != nullptr) {
old->SetOnBattleField(false);
@@ -59,6 +62,7 @@ void BattleSide::SetCreature(Creature* creature, uint8_t index) {
}
bool BattleSide::CreatureOnSide(const Creature* creature) const {
AssertNotNull(creature)
return std::find(_creatures.begin(), _creatures.end(), creature) != _creatures.end();
}
@@ -70,5 +74,6 @@ void BattleSide::GetActiveScripts(std::vector<ScriptWrapper>& scripts) {
}
uint8_t BattleSide::GetRandomCreatureIndex() {
// TODO: Consider adding parameter to only get index for available creatures.
AssertNotNull(_battle)
return _battle->GetRandom()->Get(_creaturesPerSide);
}