From 742d0c772cb7b77e4a1b59fe40a13c0f839e1519 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Wed, 22 Apr 2020 23:09:54 +0200 Subject: [PATCH] Handling for tie breaking --- src/Battling/Flow/TurnOrdering.cpp | 2 +- src/Battling/Models/Battle.cpp | 1 + src/Battling/TurnChoices/BaseTurnChoice.hpp | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Battling/Flow/TurnOrdering.cpp b/src/Battling/Flow/TurnOrdering.cpp index 28a4efc..f15c27f 100644 --- a/src/Battling/Flow/TurnOrdering.cpp +++ b/src/Battling/Flow/TurnOrdering.cpp @@ -25,7 +25,7 @@ public: if (aSpeed != bSpeed) return aSpeed > bSpeed; - return true; + return a->__GetRandomValue() > b->__GetRandomValue(); } }; diff --git a/src/Battling/Models/Battle.cpp b/src/Battling/Models/Battle.cpp index 4c56bf4..fe71ac7 100644 --- a/src/Battling/Models/Battle.cpp +++ b/src/Battling/Models/Battle.cpp @@ -54,6 +54,7 @@ void Battle::CheckChoicesSetAndRun() { } // HOOK: Check if we need to change the move } + choice->__SetRandomValue(_random.Get()); choices[i] = choice; i++; } diff --git a/src/Battling/TurnChoices/BaseTurnChoice.hpp b/src/Battling/TurnChoices/BaseTurnChoice.hpp index 697e65d..89f69fa 100644 --- a/src/Battling/TurnChoices/BaseTurnChoice.hpp +++ b/src/Battling/TurnChoices/BaseTurnChoice.hpp @@ -10,6 +10,7 @@ namespace CreatureLib::Battling { class BaseTurnChoice : public ScriptSource { Creature* _user; + int32_t _randomValue; protected: BaseTurnChoice(Creature* user) noexcept : _user(user){}; @@ -18,6 +19,9 @@ namespace CreatureLib::Battling { virtual ~BaseTurnChoice() = default; [[nodiscard]] virtual TurnChoiceKind GetKind() const noexcept = 0; [[nodiscard]] inline Creature* GetUser() const noexcept { return _user; } + + inline void __SetRandomValue(int32_t val) noexcept { _randomValue = val; } + inline int32_t __GetRandomValue() const noexcept { return _randomValue; } }; }