Clearer errors for C Interface.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
1d03adf0d1
commit
e2e706693b
|
@ -18,8 +18,8 @@ void TurnHandler::RunTurn(ArbUt::BorrowedPtr<ChoiceQueue> queue) {
|
|||
ExecuteChoice(item.get());
|
||||
} catch (const std::exception& e) {
|
||||
THROW_CREATURE("Executing choice failed for choice by mon on side "
|
||||
<< item.get()->GetUser()->GetBattleSide()->GetSideIndex() << " and index "
|
||||
<< item.get()->GetUser()->GetBattleSide()->GetCreatureIndex(item->GetUser())
|
||||
<< ((uint32_t)item.get()->GetUser()->GetBattleSide()->GetSideIndex()) << " and index "
|
||||
<< ((uint32_t)item.get()->GetUser()->GetBattleSide()->GetCreatureIndex(item->GetUser()))
|
||||
<< " with message '" << e.what() << "'.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ bool Battle::TrySetChoice(BaseTurnChoice* choice) {
|
|||
}
|
||||
|
||||
void Battle::CheckChoicesSetAndRun() {
|
||||
try {
|
||||
for (auto side : _sides) {
|
||||
if (!side->AllChoicesSet()) {
|
||||
return;
|
||||
|
@ -38,6 +39,11 @@ void Battle::CheckChoicesSetAndRun() {
|
|||
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);
|
||||
auto i = 0;
|
||||
|
@ -71,7 +77,13 @@ void Battle::CheckChoicesSetAndRun() {
|
|||
THROW_CREATURE("Exception during turn ordering: '" << e.what() << "'.")
|
||||
}
|
||||
this->_currentTurnQueue.reset(new ChoiceQueue(choices));
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ bool BattleSide::AllChoicesSet() const noexcept { return _choicesSet == _creatur
|
|||
|
||||
bool BattleSide::AllPossibleSlotsFilled() const {
|
||||
AssertNotNull(_battle)
|
||||
try {
|
||||
for (size_t i = 0; i < _creatures.Count(); i++) {
|
||||
auto c = _creatures[i];
|
||||
if (c == nullptr || c->IsFainted()) {
|
||||
|
@ -16,6 +17,9 @@ bool BattleSide::AllPossibleSlotsFilled() const {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
THROW_CREATURE("Exception during AllPossibleSlotsFilled check: '" << e.what() << "'.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -28,12 +32,19 @@ void BattleSide::ResetChoices() noexcept {
|
|||
|
||||
void BattleSide::SetChoice(BaseTurnChoice* choice) {
|
||||
AssertNotNull(choice)
|
||||
auto find = std::find(_creatures.begin(), _creatures.end(), choice->GetUser());
|
||||
if (find == _creatures.end())
|
||||
THROW_CREATURE("User not found");
|
||||
uint8_t index = std::distance(_creatures.begin(), find);
|
||||
_choices[index] = std::shared_ptr<BaseTurnChoice>(choice);
|
||||
try {
|
||||
for (size_t i = 0; i < _creatures.Count(); i++) {
|
||||
auto& c = _creatures[i];
|
||||
if (c == choice->GetUser()) {
|
||||
_choices[i] = std::shared_ptr<BaseTurnChoice>(choice);
|
||||
_choicesSet++;
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
THROW_CREATURE("Error during setting choice: '" << e.what() << "'.");
|
||||
}
|
||||
THROW_CREATURE("User not found");
|
||||
}
|
||||
|
||||
void BattleSide::SetCreature(ArbUt::BorrowedPtr<Creature> creature, uint8_t index) {
|
||||
|
|
Loading…
Reference in New Issue