Implements replacement attack when an attack can't be used anymore, adds clearer exception handling.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-07-26 18:00:58 +02:00
parent 36f1e5beeb
commit 1d03adf0d1
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
2 changed files with 32 additions and 17 deletions

View File

@ -14,7 +14,14 @@ void TurnHandler::RunTurn(ArbUt::BorrowedPtr<ChoiceQueue> queue) {
} }
while (queue->HasNext()) { while (queue->HasNext()) {
auto item = queue->Dequeue(); auto item = queue->Dequeue();
ExecuteChoice(item.get()); try {
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())
<< " with message '" << e.what() << "'.");
}
} }
queue->HasCompletedQueue = true; queue->HasCompletedQueue = true;
} }

View File

@ -41,27 +41,35 @@ void Battle::CheckChoicesSetAndRun() {
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;
for (auto side : _sides) { try {
for (const auto& choice : side->GetChoices()) { for (auto side : _sides) {
AssertNotNull(choice) for (auto choice : side->GetChoices()) {
if (choice->GetKind() == TurnChoiceKind::Attack) { AssertNotNull(choice)
auto attack = ((AttackTurnChoice*)choice.get())->GetAttack(); if (choice->GetKind() == TurnChoiceKind::Attack) {
uint8_t uses = 1; auto attack = ((AttackTurnChoice*)choice.get())->GetAttack();
// HOOK: change number of uses needed. uint8_t uses = 1;
if (attack->GetRemainingUses() < uses) { // HOOK: change number of uses needed.
// TODO: Implement default move if (attack->GetRemainingUses() < uses) {
throw NotImplementedException("Not enough remaining uses, change to default move."); choice = std::shared_ptr<BaseTurnChoice>(_library->GetMiscLibrary()->ReplacementAttack(
choice->GetUser().GetRaw(), ((AttackTurnChoice*)choice.get())->GetTarget()));
}
// HOOK: Check if we need to change the move
} }
// HOOK: Check if we need to change the move choice->__SetRandomValue(_random.Get());
choices[i] = choice;
i++;
} }
choice->__SetRandomValue(_random.Get()); side->ResetChoices();
choices[i] = choice;
i++;
} }
side->ResetChoices(); } catch (const std::exception& e) {
THROW_CREATURE("Exception during turn initialization: '" << e.what() << "'.")
} }
_currentTurn++; _currentTurn++;
TurnOrdering::OrderChoices(choices, _random.GetRNG()); try {
TurnOrdering::OrderChoices(choices, _random.GetRNG());
} catch (const std::exception& e) {
THROW_CREATURE("Exception during turn ordering: '" << e.what() << "'.")
}
this->_currentTurnQueue.reset(new ChoiceQueue(choices)); this->_currentTurnQueue.reset(new ChoiceQueue(choices));
TurnHandler::RunTurn(this->_currentTurnQueue); TurnHandler::RunTurn(this->_currentTurnQueue);
if (this->_currentTurnQueue->HasCompletedQueue) { if (this->_currentTurnQueue->HasCompletedQueue) {