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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user