69 lines
3.3 KiB
C++
69 lines
3.3 KiB
C++
#ifndef PKMNLIB_AI_POKEMONAI_HPP
|
|
#define PKMNLIB_AI_POKEMONAI_HPP
|
|
#include <CreatureLib/Battling/TurnChoices/AttackTurnChoice.hpp>
|
|
#include <CreatureLib/Battling/TurnChoices/BaseTurnChoice.hpp>
|
|
#include <CreatureLib/Library/Attacks/AttackTarget.hpp>
|
|
#include <PkmnLib/Battling/Battle/Battle.hpp>
|
|
#include <PkmnLib/Battling/Pokemon/Pokemon.hpp>
|
|
|
|
namespace PkmnLibAI {
|
|
class PokemonAI {
|
|
private:
|
|
public:
|
|
virtual ~PokemonAI() = default;
|
|
|
|
virtual CreatureLib::Battling::BaseTurnChoice* GetChoice(PkmnLib::Battling::Battle* battle,
|
|
PkmnLib::Battling::Pokemon* user) = 0;
|
|
|
|
virtual std::string GetName() const noexcept = 0;
|
|
|
|
protected:
|
|
CreatureLib::Battling::CreatureIndex GetOppositeIndex(PkmnLib::Battling::Pokemon* user) {
|
|
auto side = user->GetBattleSide().GetValue();
|
|
if (side->GetSideIndex() == 0) {
|
|
return CreatureLib::Battling::CreatureIndex(1, 0);
|
|
} else {
|
|
return CreatureLib::Battling::CreatureIndex(0, 0);
|
|
}
|
|
}
|
|
|
|
std::optional<CreatureLib::Battling::CreatureIndex> GetTargetIndex(PkmnLib::Battling::Battle* battle,
|
|
PkmnLib::Battling::Pokemon* user,
|
|
PkmnLib::Battling::LearnedMove* move) {
|
|
auto moveTarget = move->GetMoveData()->GetTarget();
|
|
auto userIndex = user->GetBattleIndex();
|
|
switch (moveTarget) {
|
|
case CreatureLib::Library::AttackTarget::Adjacent:
|
|
case CreatureLib::Library::AttackTarget::AdjacentOpponent:
|
|
case CreatureLib::Library::AttackTarget::All:
|
|
case CreatureLib::Library::AttackTarget::AllAdjacent:
|
|
case CreatureLib::Library::AttackTarget::AllAdjacentOpponent:
|
|
case CreatureLib::Library::AttackTarget::AllOpponent:
|
|
case CreatureLib::Library::AttackTarget::Any:
|
|
case CreatureLib::Library::AttackTarget::RandomOpponent: {
|
|
return GetOppositeIndex(user);
|
|
}
|
|
case CreatureLib::Library::AttackTarget::AdjacentAlly: {
|
|
if (battle->GetCreaturesPerSide() < 2) {
|
|
return {};
|
|
};
|
|
if (userIndex.GetCreatureIndex() > 0) {
|
|
return CreatureLib::Battling::CreatureIndex(userIndex.GetSideIndex(),
|
|
userIndex.GetCreatureIndex() - 1);
|
|
}
|
|
return CreatureLib::Battling::CreatureIndex(userIndex.GetSideIndex(),
|
|
userIndex.GetCreatureIndex() + 1);
|
|
}
|
|
case CreatureLib::Library::AttackTarget::AdjacentAllySelf:
|
|
case CreatureLib::Library::AttackTarget::AllAlly:
|
|
case CreatureLib::Library::AttackTarget::Self: {
|
|
return userIndex;
|
|
}
|
|
}
|
|
THROW("Unknown attack target kind: '", CreatureLib::Library::AttackTargetHelper::ToString(moveTarget), "'.")
|
|
}
|
|
};
|
|
}
|
|
|
|
#endif // PKMNLIB_AI_POKEMONAI_HPP
|