From f50f76e993414af658d1c8e331f803d882fa0470 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 20 Jun 2020 19:51:34 +0200 Subject: [PATCH] Move priority scripthook to more sensible place in turn flow. --- src/Battling/Flow/TurnOrdering.cpp | 8 ++++++++ src/Battling/TurnChoices/AttackTurnChoice.hpp | 7 ++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Battling/Flow/TurnOrdering.cpp b/src/Battling/Flow/TurnOrdering.cpp index c99d9f0..b761e16 100644 --- a/src/Battling/Flow/TurnOrdering.cpp +++ b/src/Battling/Flow/TurnOrdering.cpp @@ -30,5 +30,13 @@ public: }; void TurnOrdering::OrderChoices(std::vector>& vec, ArbUt::Random& rand) { + for (auto item : vec) { + if (item->GetKind() == TurnChoiceKind::Attack) { + auto attackChoice = static_cast(item.get()); + auto priority = attackChoice->GetPriority(); + HOOK(ChangePriority, attackChoice, attackChoice, &priority); + attackChoice->SetPriority(priority); + } + } std::sort(vec.begin(), vec.end(), ChoiceCompare()); } diff --git a/src/Battling/TurnChoices/AttackTurnChoice.hpp b/src/Battling/TurnChoices/AttackTurnChoice.hpp index c3ceb43..48248b3 100644 --- a/src/Battling/TurnChoices/AttackTurnChoice.hpp +++ b/src/Battling/TurnChoices/AttackTurnChoice.hpp @@ -43,7 +43,7 @@ namespace CreatureLib::Battling { AssertNotNull(attack) #endif ResolveScript(); - HOOK(ChangePriority, this, this, &_priority); + _priority = _attack->GetAttack()->GetPriority(); } AttackTurnChoice(Creature* user, const ArbUt::BorrowedPtr& attack, const CreatureIndex& target, Script* script) @@ -52,7 +52,7 @@ namespace CreatureLib::Battling { AssertNotNull(user) AssertNotNull(attack) #endif - HOOK(ChangePriority, this, this, &_priority); + _priority = _attack->GetAttack()->GetPriority(); } ~AttackTurnChoice() = default; @@ -61,7 +61,8 @@ namespace CreatureLib::Battling { TurnChoiceKind GetKind() const noexcept override { return TurnChoiceKind ::Attack; } - inline int8_t GetPriority() const { return _attack->GetAttack()->GetPriority(); } + inline int8_t GetPriority() const noexcept { return _priority; } + inline void SetPriority(int8_t priority) noexcept { _priority = priority; } const CreatureIndex& GetTarget() const noexcept { return _target; }