This commit is contained in:
Deukhoofd 2020-04-22 21:20:07 +02:00
parent d2cf26e950
commit 75baf19ebd
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
4 changed files with 32 additions and 30 deletions

View File

@ -17,10 +17,10 @@ if (NOT EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
SET(VERSION ${VERSION}.${MINOR}) SET(VERSION ${VERSION}.${MINOR})
endif () endif ()
if (NOT WINDOWS) 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}) -s compiler=clang -s compiler.libcxx=libstdc++11 -s compiler.version=${VERSION})
else () 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) -s compiler=gcc -s compiler.libcxx=libstdc++11 -s compiler.version=${VERSION} -s os=Windows)
endif () endif ()
endif () endif ()

View File

@ -19,9 +19,7 @@ void TurnHandler::RunTurn(ChoiceQueue* queue) {
} }
void TurnHandler::ExecuteChoice(BaseTurnChoice* choice) { void TurnHandler::ExecuteChoice(BaseTurnChoice* choice) {
if (choice == nullptr) { AssertNotNull(choice);
return;
}
auto choiceKind = choice->GetKind(); auto choiceKind = choice->GetKind();
if (choiceKind == TurnChoiceKind::Pass) { if (choiceKind == TurnChoiceKind::Pass) {
return; return;
@ -116,7 +114,7 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* targe
return; return;
} }
bool invulnerable = fail; bool invulnerable = false;
HOOK(IsInvulnerable, targetSource, attack, target, &invulnerable); HOOK(IsInvulnerable, targetSource, attack, target, &invulnerable);
if (invulnerable) { if (invulnerable) {
// TODO: We should probably do something when a target is invulnerable. // TODO: We should probably do something when a target is invulnerable.
@ -140,7 +138,6 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* targe
break; break;
} }
if (target->IsFainted()) { if (target->IsFainted()) {
// STOP, STOP! HE'S ALREADY DEAD ;_;
break; break;
} }
auto hit = targetData->GetHit(hitIndex); auto hit = targetData->GetHit(hitIndex);

View File

@ -6,29 +6,32 @@
using namespace CreatureLib; using namespace CreatureLib;
using namespace Battling; using namespace Battling;
bool ___ChoiceOrderFunc(const BaseTurnChoice* a, const BaseTurnChoice* b, Arbutils::Random& rand) { class ChoiceCompare {
auto aKind = a->GetKind(); Arbutils::Random& _rand;
auto bKind = b->GetKind();
if (aKind != bKind)
return aKind > bKind;
if (aKind == TurnChoiceKind::Attack) {
auto aPriority = dynamic_cast<const AttackTurnChoice*>(a)->GetPriority();
auto bPriority = dynamic_cast<const AttackTurnChoice*>(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); public:
return randomValue == 0; 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<const AttackTurnChoice*>(a)->GetPriority();
auto bPriority = dynamic_cast<const AttackTurnChoice*>(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<BaseTurnChoice*>& vec, Arbutils::Random& rand) { void TurnOrdering::OrderChoices(std::vector<BaseTurnChoice*>& vec, Arbutils::Random& rand) {
auto comp = [&](const BaseTurnChoice* a, const BaseTurnChoice* b) -> bool { std::sort(vec.begin(), vec.end(), ChoiceCompare(rand));
return ___ChoiceOrderFunc(a, b, rand);
};
std::sort(vec.begin(), vec.end(), comp);
} }

View File

@ -96,7 +96,7 @@ Battling::Battle* Battling::Creature::GetBattle() const { return _battle; }
Battling::BattleSide* Battling::Creature::GetBattleSide() const { return _side; } 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() { void Battling::Creature::OnFaint() {
// HOOK: On Faint // HOOK: On Faint
@ -115,6 +115,8 @@ void Battling::Creature::Damage(uint32_t damage, Battling::DamageSource source)
if (damage > _currentHealth) { if (damage > _currentHealth) {
damage = _currentHealth; damage = _currentHealth;
} }
if (damage == 0)
return;
// HOOK: On Damage // HOOK: On Damage
auto newHealth = _currentHealth - damage; auto newHealth = _currentHealth - damage;
auto battle = this->GetBattle(); auto battle = this->GetBattle();