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