From 5a41208fdba8200187ecaf1b39445696342e13e1 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 31 Jul 2020 10:45:20 +0200 Subject: [PATCH] Further clearer error handling. --- src/Battling/Flow/TurnHandler.cpp | 14 ++++++++++---- src/Battling/TurnChoices/TurnChoiceKind.hpp | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Battling/Flow/TurnHandler.cpp b/src/Battling/Flow/TurnHandler.cpp index ee6fb2a..14783d7 100644 --- a/src/Battling/Flow/TurnHandler.cpp +++ b/src/Battling/Flow/TurnHandler.cpp @@ -18,6 +18,8 @@ void TurnHandler::RunTurn(ArbUt::BorrowedPtr queue) { "Executing choice failed for choice by mon on side " << ((uint32_t)item.get()->GetUser()->GetBattleSide()->GetSideIndex()) << " and index " << ((uint32_t)item.get()->GetUser()->GetBattleSide()->GetCreatureIndex(item->GetUser())) + << ". Choice had choice kind " + << CreatureLib::Battling::TurnChoiceKindHelper::ToString(item->GetKind()) << " " << " with message"); } queue->HasCompletedQueue = true; @@ -68,9 +70,11 @@ void TurnHandler::ExecuteAttackChoice(ArbUt::BorrowedPtr choic // TODO: Change attack } - auto target = choice->GetUser()->GetBattle()->GetCreature(choice->GetTarget()); - ArbUt::List> targets = TargetResolver::ResolveTargets( - choice->GetTarget(), choice->GetAttack()->GetAttack()->GetTarget(), choice->GetUser()->GetBattle()); + auto targetType = choice->GetAttack()->GetAttack()->GetTarget(); + ArbUt::List> targets; + try_creature(targets = + TargetResolver::ResolveTargets(choice->GetTarget(), targetType, choice->GetUser()->GetBattle()); + , "Exception during target determination: '" << e.what() << "'."); auto attack = ExecutingAttack(targets, 1, choice->GetUser(), choice->GetAttack(), choice->GetAttackScript()); bool prevented = false; @@ -101,7 +105,9 @@ void TurnHandler::ExecuteAttackChoice(ArbUt::BorrowedPtr choic HOOK_LOCAL(OnBeforeAttack, attack, &attack); for (uint8_t i = 0; i < attack.GetTargetCount(); i++) { - HandleAttackForTarget(&attack, attack.GetTargets()[i]); + auto target = attack.GetTargets()[i]; + try_creature(HandleAttackForTarget(&attack, target), + "Exception occured during handling attack for target: '" << e.what() << "'."); } } diff --git a/src/Battling/TurnChoices/TurnChoiceKind.hpp b/src/Battling/TurnChoices/TurnChoiceKind.hpp index 1577c09..c358aa6 100644 --- a/src/Battling/TurnChoices/TurnChoiceKind.hpp +++ b/src/Battling/TurnChoices/TurnChoiceKind.hpp @@ -4,6 +4,6 @@ #include namespace CreatureLib::Battling { - enum class TurnChoiceKind : uint8_t { Pass, Attack, Item, Switch, Flee }; + ENUM(TurnChoiceKind, uint8_t, Pass, Attack, Item, Switch, Flee); } #endif // CREATURELIB_TURNCHOICEKIND_HPP