Make ChoiceQueue use smart pointers.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-05-31 18:00:39 +02:00
parent ff181204ae
commit 29cb4eac37
8 changed files with 32 additions and 35 deletions

View File

@@ -13,12 +13,11 @@ void TurnHandler::RunTurn(ChoiceQueue* queue) {
while (queue->HasNext()) {
auto item = queue->Dequeue();
ExecuteChoice(item);
delete item;
}
queue->HasCompletedQueue = true;
}
void TurnHandler::ExecuteChoice(BaseTurnChoice* choice) {
void TurnHandler::ExecuteChoice(ArbUt::BorrowedPtr<BaseTurnChoice> choice) {
AssertNotNull(choice);
auto choiceKind = choice->GetKind();
if (choiceKind == TurnChoiceKind::Pass) {
@@ -42,18 +41,18 @@ void TurnHandler::ExecuteChoice(BaseTurnChoice* choice) {
switch (choiceKind) {
case TurnChoiceKind::Pass: throw NotReachableException();
case TurnChoiceKind::Attack: return ExecuteAttackChoice(dynamic_cast<AttackTurnChoice*>(choice));
case TurnChoiceKind::Switch: return ExecuteSwitchChoice(dynamic_cast<SwitchTurnChoice*>(choice));
case TurnChoiceKind::Flee: return ExecuteFleeChoice(dynamic_cast<FleeTurnChoice*>(choice));
case TurnChoiceKind::Attack: return ExecuteAttackChoice(choice.ForceAs<AttackTurnChoice>());
case TurnChoiceKind::Switch: return ExecuteSwitchChoice(choice.ForceAs<SwitchTurnChoice>());
case TurnChoiceKind::Flee: return ExecuteFleeChoice(choice.ForceAs<FleeTurnChoice>());
case TurnChoiceKind::Item: throw NotImplementedException();
}
}
void TurnHandler::ExecuteAttackChoice(AttackTurnChoice* choice) {
void TurnHandler::ExecuteAttackChoice(ArbUt::BorrowedPtr<AttackTurnChoice> choice) {
AssertNotNull(choice)
auto attackName = choice->GetAttack()->GetAttack()->GetName();
HOOK(ChangeAttack, choice, choice, &attackName);
HOOK(ChangeAttack, choice, choice.GetRaw(), &attackName);
if (attackName != choice->GetAttack()->GetAttack()->GetName()) {
// TODO: Change attack
}
@@ -196,9 +195,9 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* targe
}
}
void TurnHandler::ExecuteSwitchChoice(CreatureLib::Battling::SwitchTurnChoice* choice) {
void TurnHandler::ExecuteSwitchChoice(ArbUt::BorrowedPtr<SwitchTurnChoice> choice) {
bool preventSwitch = false;
HOOK(PreventSelfSwitch, choice, choice, &preventSwitch);
HOOK(PreventSelfSwitch, choice, choice.GetRaw(), &preventSwitch);
if (preventSwitch) {
return;
}
@@ -210,7 +209,7 @@ void TurnHandler::ExecuteSwitchChoice(CreatureLib::Battling::SwitchTurnChoice* c
auto userIndex = userSide->GetCreatureIndex(user);
userSide->SetCreature(choice->GetNewCreature(), userIndex);
}
void TurnHandler::ExecuteFleeChoice(FleeTurnChoice* choice) {
void TurnHandler::ExecuteFleeChoice(ArbUt::BorrowedPtr<FleeTurnChoice> choice) {
auto user = choice->GetUser();
auto battle = user->GetBattle();
if (!battle->CanFlee()) {
@@ -219,7 +218,7 @@ void TurnHandler::ExecuteFleeChoice(FleeTurnChoice* choice) {
// TODO: If any of the creatures on the users side has a script that prevents it from running, block.
// TODO: If any of the creatures on any other side has a script that prevents this side from running, block.
if (battle->GetLibrary()->GetMiscLibrary()->CanFlee(choice)) {
if (battle->GetLibrary()->GetMiscLibrary()->CanFlee(choice.GetRaw())) {
user->GetBattleSide()->MarkAsFled();
battle->ValidateBattleState();
}