From 5d6ac316eb5ada2aade3e498aa44a954626e3a53 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Thu, 5 Dec 2019 09:53:48 +0100 Subject: [PATCH] Renamed Target class to CreatureIndex --- src/Battling/Models/Battle.hpp | 4 ++-- .../Models/{Target.hpp => CreatureIndex.hpp} | 10 +++++----- src/Battling/TurnChoices/AttackTurnChoice.hpp | 8 ++++---- tests/BattleTests/TurnOrderTests.cpp | 18 +++++++++--------- 4 files changed, 20 insertions(+), 20 deletions(-) rename src/Battling/Models/{Target.hpp => CreatureIndex.hpp} (53%) diff --git a/src/Battling/Models/Battle.hpp b/src/Battling/Models/Battle.hpp index a0274f4..2221b71 100644 --- a/src/Battling/Models/Battle.hpp +++ b/src/Battling/Models/Battle.hpp @@ -6,7 +6,7 @@ #include "../Library/BattleLibrary.hpp" #include "../TurnChoices/BaseTurnChoice.hpp" #include "BattleSide.hpp" -#include "Target.hpp" +#include "CreatureIndex.hpp" namespace CreatureLib::Battling { class Battle : public ScriptSource { @@ -33,7 +33,7 @@ namespace CreatureLib::Battling { bool CreatureInField(const Creature* creature) const; - Creature* GetTarget(const Target& target) { + Creature* GetTarget(const CreatureIndex& target) { return _sides[target.GetSideIndex()]->GetCreature(target.GetCreatureIndex()); } diff --git a/src/Battling/Models/Target.hpp b/src/Battling/Models/CreatureIndex.hpp similarity index 53% rename from src/Battling/Models/Target.hpp rename to src/Battling/Models/CreatureIndex.hpp index e76a945..4a7d219 100644 --- a/src/Battling/Models/Target.hpp +++ b/src/Battling/Models/CreatureIndex.hpp @@ -1,16 +1,16 @@ -#ifndef CREATURELIB_TARGET_HPP -#define CREATURELIB_TARGET_HPP +#ifndef CREATURELIB_CREATUREINDEX_HPP +#define CREATURELIB_CREATUREINDEX_HPP #include #include "Creature.hpp" namespace CreatureLib::Battling { - class Target { + class CreatureIndex { uint8_t _side; uint8_t _creature; public: - Target(uint8_t side, uint8_t creature) : _side(side), _creature(creature) {} + CreatureIndex(uint8_t side, uint8_t creature) : _side(side), _creature(creature) {} uint8_t GetSideIndex() const { return _side; } @@ -18,4 +18,4 @@ namespace CreatureLib::Battling { }; } -#endif // CREATURELIB_TARGET_HPP +#endif // CREATURELIB_CREATUREINDEX_HPP diff --git a/src/Battling/TurnChoices/AttackTurnChoice.hpp b/src/Battling/TurnChoices/AttackTurnChoice.hpp index f162cfd..c0391ff 100644 --- a/src/Battling/TurnChoices/AttackTurnChoice.hpp +++ b/src/Battling/TurnChoices/AttackTurnChoice.hpp @@ -1,18 +1,18 @@ #ifndef CREATURELIB_ATTACKTURNCHOICE_HPP #define CREATURELIB_ATTACKTURNCHOICE_HPP +#include "../Models/CreatureIndex.hpp" #include "../Models/LearnedAttack.hpp" -#include "../Models/Target.hpp" #include "BaseTurnChoice.hpp" namespace CreatureLib::Battling { class AttackTurnChoice : public BaseTurnChoice { LearnedAttack* _attack; - Target _target; + CreatureIndex _target; Script* _attackScript; public: - AttackTurnChoice(Creature* user, LearnedAttack* attack, const Target& target) + AttackTurnChoice(Creature* user, LearnedAttack* attack, const CreatureIndex& target) : BaseTurnChoice(user), _attack(attack), _target(target) {} inline LearnedAttack* GetAttack() const { return _attack; } @@ -24,7 +24,7 @@ namespace CreatureLib::Battling { return _attack->GetAttack()->GetPriority(); } - const Target& GetTarget() const { return _target; } + const CreatureIndex& GetTarget() const { return _target; } Script* GetAttackScript() { return _attackScript; } diff --git a/tests/BattleTests/TurnOrderTests.cpp b/tests/BattleTests/TurnOrderTests.cpp index fbc7355..861b312 100644 --- a/tests/BattleTests/TurnOrderTests.cpp +++ b/tests/BattleTests/TurnOrderTests.cpp @@ -10,7 +10,7 @@ using namespace CreatureLib::Battling; TEST_CASE("Turn ordering: Attack before pass", "[Battling]") { auto choice1 = new PassTurnChoice(nullptr); - auto choice2 = new AttackTurnChoice(nullptr, nullptr, Target(0, 0)); + auto choice2 = new AttackTurnChoice(nullptr, nullptr, CreatureIndex(0, 0)); auto vec = std::vector{choice1, choice2}; auto rand = Core::Random(); TurnOrdering::OrderChoices(vec, rand); @@ -29,8 +29,8 @@ TEST_CASE("Turn ordering: High priority goes before no priority", "[Battling]") auto l = GetLibrary()->GetAttackLibrary(); auto a1 = new LearnedAttack(l->GetAttack("standard"), AttackLearnMethod::Unknown); auto a2 = new LearnedAttack(l->GetAttack("highPriority"), AttackLearnMethod::Unknown); - auto choice1 = new AttackTurnChoice(nullptr, a1, Target(0, 0)); - auto choice2 = new AttackTurnChoice(nullptr, a2, Target(0, 0)); + auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0)); + auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0)); auto vec = std::vector{choice1, choice2}; auto rand = Core::Random(); TurnOrdering::OrderChoices(vec, rand); @@ -51,8 +51,8 @@ TEST_CASE("Turn ordering: Higher priority goes before high priority", "[Battling auto l = GetLibrary()->GetAttackLibrary(); auto a1 = new LearnedAttack(l->GetAttack("highPriority"), AttackLearnMethod::Unknown); auto a2 = new LearnedAttack(l->GetAttack("higherPriority"), AttackLearnMethod::Unknown); - auto choice1 = new AttackTurnChoice(nullptr, a1, Target(0, 0)); - auto choice2 = new AttackTurnChoice(nullptr, a2, Target(0, 0)); + auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0)); + auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0)); auto vec = std::vector{choice1, choice2}; auto rand = Core::Random(); TurnOrdering::OrderChoices(vec, rand); @@ -73,8 +73,8 @@ TEST_CASE("Turn ordering: High priority goes before low priority", "[Battling]") auto l = GetLibrary()->GetAttackLibrary(); auto a1 = new LearnedAttack(l->GetAttack("lowPriority"), AttackLearnMethod::Unknown); auto a2 = new LearnedAttack(l->GetAttack("higherPriority"), AttackLearnMethod::Unknown); - auto choice1 = new AttackTurnChoice(nullptr, a1, Target(0, 0)); - auto choice2 = new AttackTurnChoice(nullptr, a2, Target(0, 0)); + auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0)); + auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0)); auto vec = std::vector{choice1, choice2}; auto rand = Core::Random(); TurnOrdering::OrderChoices(vec, rand); @@ -95,8 +95,8 @@ TEST_CASE("Turn ordering: No priority goes before low priority", "[Battling]") { auto l = GetLibrary()->GetAttackLibrary(); auto a1 = new LearnedAttack(l->GetAttack("lowPriority"), AttackLearnMethod::Unknown); auto a2 = new LearnedAttack(l->GetAttack("standard"), AttackLearnMethod::Unknown); - auto choice1 = new AttackTurnChoice(nullptr, a1, Target(0, 0)); - auto choice2 = new AttackTurnChoice(nullptr, a2, Target(0, 0)); + auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0)); + auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0)); auto vec = std::vector{choice1, choice2}; auto rand = Core::Random(); TurnOrdering::OrderChoices(vec, rand);