From 75baf19ebd1b6a5652907aa91097f499caca6ffa Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Wed, 22 Apr 2020 21:20:07 +0200 Subject: [PATCH] Cleanup --- CMakeLists.txt | 4 +-- src/Battling/Flow/TurnHandler.cpp | 7 ++--- src/Battling/Flow/TurnOrdering.cpp | 47 ++++++++++++++++-------------- src/Battling/Models/Creature.cpp | 4 ++- 4 files changed, 32 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 943a664..f85ddf4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,10 +17,10 @@ if (NOT EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) SET(VERSION ${VERSION}.${MINOR}) endif () if (NOT WINDOWS) - execute_process(COMMAND conan install ${CMAKE_SOURCE_DIR} --install-folder=${CMAKE_BINARY_DIR} --build missing + execute_process(COMMAND conan install ${CMAKE_SOURCE_DIR} --install-folder=${CMAKE_BINARY_DIR} --build outdated -s compiler=clang -s compiler.libcxx=libstdc++11 -s compiler.version=${VERSION}) else () - execute_process(COMMAND conan install ${CMAKE_SOURCE_DIR} --install-folder=${CMAKE_BINARY_DIR} --build missing + execute_process(COMMAND conan install ${CMAKE_SOURCE_DIR} --install-folder=${CMAKE_BINARY_DIR} --build outdated -s compiler=gcc -s compiler.libcxx=libstdc++11 -s compiler.version=${VERSION} -s os=Windows) endif () endif () diff --git a/src/Battling/Flow/TurnHandler.cpp b/src/Battling/Flow/TurnHandler.cpp index 348daef..961ea18 100644 --- a/src/Battling/Flow/TurnHandler.cpp +++ b/src/Battling/Flow/TurnHandler.cpp @@ -19,9 +19,7 @@ void TurnHandler::RunTurn(ChoiceQueue* queue) { } void TurnHandler::ExecuteChoice(BaseTurnChoice* choice) { - if (choice == nullptr) { - return; - } + AssertNotNull(choice); auto choiceKind = choice->GetKind(); if (choiceKind == TurnChoiceKind::Pass) { return; @@ -116,7 +114,7 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* targe return; } - bool invulnerable = fail; + bool invulnerable = false; HOOK(IsInvulnerable, targetSource, attack, target, &invulnerable); if (invulnerable) { // TODO: We should probably do something when a target is invulnerable. @@ -140,7 +138,6 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* targe break; } if (target->IsFainted()) { - // STOP, STOP! HE'S ALREADY DEAD ;_; break; } auto hit = targetData->GetHit(hitIndex); diff --git a/src/Battling/Flow/TurnOrdering.cpp b/src/Battling/Flow/TurnOrdering.cpp index a1a582d..6fee80c 100644 --- a/src/Battling/Flow/TurnOrdering.cpp +++ b/src/Battling/Flow/TurnOrdering.cpp @@ -6,29 +6,32 @@ using namespace CreatureLib; using namespace Battling; -bool ___ChoiceOrderFunc(const BaseTurnChoice* a, const BaseTurnChoice* b, Arbutils::Random& rand) { - auto aKind = a->GetKind(); - auto bKind = b->GetKind(); - if (aKind != bKind) - return aKind > bKind; - if (aKind == TurnChoiceKind::Attack) { - auto aPriority = dynamic_cast(a)->GetPriority(); - auto bPriority = dynamic_cast(b)->GetPriority(); - if (aPriority != bPriority) - return aPriority > bPriority; - } - auto aSpeed = a->GetUser()->GetBoostedStat(Library::Statistic::Speed); - auto bSpeed = b->GetUser()->GetBoostedStat(Library::Statistic::Speed); - if (aSpeed != bSpeed) - return aSpeed > bSpeed; +class ChoiceCompare { + Arbutils::Random& _rand; - auto randomValue = rand.Get(2); - return randomValue == 0; -} +public: + explicit ChoiceCompare(Arbutils::Random& rand) : _rand(rand) {} + bool operator()(const BaseTurnChoice* a, const BaseTurnChoice* b) { + auto aKind = a->GetKind(); + auto bKind = b->GetKind(); + if (aKind != bKind) + return aKind > bKind; + if (aKind == TurnChoiceKind::Attack) { + auto aPriority = dynamic_cast(a)->GetPriority(); + auto bPriority = dynamic_cast(b)->GetPriority(); + if (aPriority != bPriority) + return aPriority > bPriority; + } + auto aSpeed = a->GetUser()->GetBoostedStat(Library::Statistic::Speed); + auto bSpeed = b->GetUser()->GetBoostedStat(Library::Statistic::Speed); + if (aSpeed != bSpeed) + return aSpeed > bSpeed; + + auto randomValue = _rand.Get(2); + return randomValue == 0; + } +}; void TurnOrdering::OrderChoices(std::vector& vec, Arbutils::Random& rand) { - auto comp = [&](const BaseTurnChoice* a, const BaseTurnChoice* b) -> bool { - return ___ChoiceOrderFunc(a, b, rand); - }; - std::sort(vec.begin(), vec.end(), comp); + std::sort(vec.begin(), vec.end(), ChoiceCompare(rand)); } diff --git a/src/Battling/Models/Creature.cpp b/src/Battling/Models/Creature.cpp index 6ea0ec5..3929893 100644 --- a/src/Battling/Models/Creature.cpp +++ b/src/Battling/Models/Creature.cpp @@ -96,7 +96,7 @@ Battling::Battle* Battling::Creature::GetBattle() const { return _battle; } Battling::BattleSide* Battling::Creature::GetBattleSide() const { return _side; } -bool Battling::Creature::IsFainted() const noexcept { return this->_currentHealth <= 0; } +bool Battling::Creature::IsFainted() const noexcept { return this->_currentHealth == 0; } void Battling::Creature::OnFaint() { // HOOK: On Faint @@ -115,6 +115,8 @@ void Battling::Creature::Damage(uint32_t damage, Battling::DamageSource source) if (damage > _currentHealth) { damage = _currentHealth; } + if (damage == 0) + return; // HOOK: On Damage auto newHealth = _currentHealth - damage; auto battle = this->GetBattle();