Defensive programming.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-08-03 17:44:29 +02:00
parent 93b3847b31
commit 08ef84f6d6
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
1 changed files with 8 additions and 3 deletions

View File

@ -14,10 +14,15 @@ void TurnHandler::RunTurn(ArbUt::BorrowedPtr<ChoiceQueue> queue) {
} }
while (queue->HasNext()) { while (queue->HasNext()) {
auto item = queue->Dequeue(); auto item = queue->Dequeue();
AssertNotNull(item)
AssertNotNull(item->GetUser())
AssertNotNull(item->GetUser()->GetBattle())
AssertNotNull(item->GetUser()->GetBattleSide())
auto index = (uint32_t)item->GetUser()->GetBattleSide()->GetCreatureIndex(item->GetUser());
try_creature(ExecuteChoice(item.get()), try_creature(ExecuteChoice(item.get()),
"Executing choice failed for choice by mon on side " "Executing choice failed for choice by mon on side "
<< ((uint32_t)item.get()->GetUser()->GetBattleSide()->GetSideIndex()) << " and index " << ((uint32_t)item->GetUser()->GetBattleSide()->GetSideIndex()) << " and index " << index
<< ((uint32_t)item.get()->GetUser()->GetBattleSide()->GetCreatureIndex(item->GetUser()))
<< ". Choice had choice kind " << ". Choice had choice kind "
<< CreatureLib::Battling::TurnChoiceKindHelper::ToString(item->GetKind()) << " " << CreatureLib::Battling::TurnChoiceKindHelper::ToString(item->GetKind()) << " "
<< " with message"); << " with message");
@ -106,7 +111,7 @@ void TurnHandler::ExecuteAttackChoice(ArbUt::BorrowedPtr<AttackTurnChoice> choic
for (uint8_t i = 0; i < attack.GetTargetCount(); i++) { for (uint8_t i = 0; i < attack.GetTargetCount(); i++) {
auto target = attack.GetTargets()[i]; auto target = attack.GetTargets()[i];
try_creature(HandleAttackForTarget(&attack, target), "Exception occured during handling attack for target"); try_creature(HandleAttackForTarget(&attack, target), "Exception occurred during handling attack for target");
} }
} }