Clearer errors for C Interface.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-07-28 17:22:43 +02:00
parent 1d03adf0d1
commit e2e706693b
3 changed files with 44 additions and 21 deletions

View File

@@ -28,15 +28,21 @@ bool Battle::TrySetChoice(BaseTurnChoice* choice) {
}
void Battle::CheckChoicesSetAndRun() {
for (auto side : _sides) {
if (!side->AllChoicesSet()) {
return;
try {
for (auto side : _sides) {
if (!side->AllChoicesSet()) {
return;
}
}
}
for (auto side : _sides) {
if (!side->AllPossibleSlotsFilled()) {
return;
for (auto side : _sides) {
if (!side->AllPossibleSlotsFilled()) {
return;
}
}
} catch (const CreatureException& e) {
throw e;
} catch (const std::exception& e) {
THROW_CREATURE("Exception during choices set validation: '" << e.what() << "'.");
}
auto choices = std::vector<std::shared_ptr<BaseTurnChoice>>(_numberOfSides * _creaturesPerSide);
@@ -71,7 +77,13 @@ void Battle::CheckChoicesSetAndRun() {
THROW_CREATURE("Exception during turn ordering: '" << e.what() << "'.")
}
this->_currentTurnQueue.reset(new ChoiceQueue(choices));
TurnHandler::RunTurn(this->_currentTurnQueue);
try {
TurnHandler::RunTurn(this->_currentTurnQueue);
} catch (const CreatureException& e) {
throw e;
} catch (const std::exception& e) {
THROW_CREATURE("Error during running a turn: '" << e.what() << "'.");
}
if (this->_currentTurnQueue->HasCompletedQueue) {
this->_currentTurnQueue = nullptr;
}