Further cleanup of TargetResolver.

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
Deukhoofd 2021-05-24 10:34:42 +02:00
parent b036efaf18
commit 69dab061da
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
2 changed files with 15 additions and 15 deletions

View File

@ -3,6 +3,8 @@ using namespace ArbUt;
using namespace CreatureLib::Library;
using namespace CreatureLib::Battling;
using TargetList = List<OptionalBorrowedPtr<Creature>>;
static inline constexpr uint8_t GetOppositeSide(uint8_t v) {
if (v == 1) {
return 0;
@ -10,8 +12,8 @@ static inline constexpr uint8_t GetOppositeSide(uint8_t v) {
return 1;
}
static inline List<OptionalBorrowedPtr<Creature>> GetAll(const BorrowedPtr<Battle>& battle) {
List<OptionalBorrowedPtr<Creature>> arr(battle->GetCreaturesPerSide() * battle->GetSides().Count());
static inline TargetList GetAll(const BorrowedPtr<Battle>& battle) {
TargetList arr(battle->GetCreaturesPerSide() * battle->GetSides().Count());
for (auto* side : battle->GetSides()) {
for (const auto& mon : side->GetCreatures()) {
arr.Append(mon);
@ -20,8 +22,7 @@ static inline List<OptionalBorrowedPtr<Creature>> GetAll(const BorrowedPtr<Battl
return arr;
}
static inline List<OptionalBorrowedPtr<Creature>> GetAllAdjacent(const CreatureIndex& index,
const BorrowedPtr<Battle>& battle) {
static inline TargetList GetAllAdjacent(const CreatureIndex& index, const BorrowedPtr<Battle>& battle) {
auto left = index.GetCreatureIndex() - 1;
auto right = index.GetCreatureIndex() + 1;
if (left < 0 && right >= battle->GetCreaturesPerSide()) {
@ -41,8 +42,7 @@ static inline List<OptionalBorrowedPtr<Creature>> GetAllAdjacent(const CreatureI
battle->GetCreature(GetOppositeSide(index.GetSideIndex()), index.GetCreatureIndex())};
}
static inline List<OptionalBorrowedPtr<Creature>> GetAllAdjacentOpponent(const CreatureIndex& index,
const BorrowedPtr<Battle>& battle) {
static inline TargetList GetAllAdjacentOpponent(const CreatureIndex& index, const BorrowedPtr<Battle>& battle) {
auto left = index.GetCreatureIndex() - 1;
auto right = index.GetCreatureIndex() + 1;
if (left < 0 && right >= battle->GetCreaturesPerSide()) {
@ -58,8 +58,8 @@ static inline List<OptionalBorrowedPtr<Creature>> GetAllAdjacentOpponent(const C
return {battle->GetCreature(index), battle->GetCreature(index.GetSideIndex(), right)};
}
List<OptionalBorrowedPtr<Creature>> TargetResolver::ResolveTargets(const CreatureIndex& index, AttackTarget target,
const BorrowedPtr<Battle>& battle) {
TargetList TargetResolver::ResolveTargets(const CreatureIndex& index, AttackTarget target,
const BorrowedPtr<Battle>& battle) {
switch (target) {
// Single targets should just return the mon at the index.
case AttackTarget::Adjacent:
@ -81,18 +81,18 @@ List<OptionalBorrowedPtr<Creature>> TargetResolver::ResolveTargets(const Creatur
return GetAllAdjacentOpponent(index, battle);
}
case AttackTarget::AllAlly: {
List<OptionalBorrowedPtr<Creature>> arr(battle->GetCreaturesPerSide());
TargetList arr(battle->GetCreaturesPerSide());
for (const auto& mon : battle->GetSides()[index.GetSideIndex()]->GetCreatures()) {
arr.Append(mon);
}
return arr;
}
case AttackTarget::AllOpponent: {
List<OptionalBorrowedPtr<Creature>> arr(battle->GetCreaturesPerSide());
TargetList arr(battle->GetCreaturesPerSide());
for (const auto& mon : battle->GetSides()[index.GetSideIndex()]->GetCreatures()) {
arr.Append(mon);
}
return List<OptionalBorrowedPtr<Creature>>(arr);
return arr;
}
}
THROW("Unknown attack target kind: '" << AttackTargetHelper::ToString(target) << "'.")

View File

@ -4,14 +4,14 @@
#include "../Models/Battle.hpp"
#include "../Models/Creature.hpp"
#include "../Models/CreatureIndex.hpp"
using namespace CreatureLib::Battling;
namespace CreatureLib::Battling {
class TargetResolver {
typedef ArbUt::List<ArbUt::OptionalBorrowedPtr<Creature>> TargetList;
public:
static ArbUt::List<ArbUt::OptionalBorrowedPtr<Creature>>
ResolveTargets(const CreatureIndex& index, CreatureLib::Library::AttackTarget target,
const ArbUt::BorrowedPtr<Battle>& battle);
static TargetList ResolveTargets(const CreatureIndex& index, CreatureLib::Library::AttackTarget target,
const ArbUt::BorrowedPtr<Battle>& battle);
};
}