Renamed Target class to CreatureIndex

This commit is contained in:
Deukhoofd 2019-12-05 09:53:48 +01:00
parent a8730d983f
commit 5d6ac316eb
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
4 changed files with 20 additions and 20 deletions

View File

@ -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());
}

View File

@ -1,16 +1,16 @@
#ifndef CREATURELIB_TARGET_HPP
#define CREATURELIB_TARGET_HPP
#ifndef CREATURELIB_CREATUREINDEX_HPP
#define CREATURELIB_CREATUREINDEX_HPP
#include <cstdint>
#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

View File

@ -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; }

View File

@ -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<BaseTurnChoice*>{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<BaseTurnChoice*>{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<BaseTurnChoice*>{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<BaseTurnChoice*>{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<BaseTurnChoice*>{choice1, choice2};
auto rand = Core::Random();
TurnOrdering::OrderChoices(vec, rand);