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,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;
|
||||
}
|
||||
|
|
|
@ -9,12 +9,16 @@ bool BattleSide::AllChoicesSet() const noexcept { return _choicesSet == _creatur
|
|||
|
||||
bool BattleSide::AllPossibleSlotsFilled() const {
|
||||
AssertNotNull(_battle)
|
||||
for (size_t i = 0; i < _creatures.Count(); i++) {
|
||||
auto c = _creatures[i];
|
||||
if (c == nullptr || c->IsFainted()) {
|
||||
if (_battle->CanSlotBeFilled(_index, i))
|
||||
return false;
|
||||
try {
|
||||
for (size_t i = 0; i < _creatures.Count(); i++) {
|
||||
auto c = _creatures[i];
|
||||
if (c == nullptr || c->IsFainted()) {
|
||||
if (_battle->CanSlotBeFilled(_index, i))
|
||||
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);
|
||||
_choicesSet++;
|
||||
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