91 lines
3.3 KiB
C++
91 lines
3.3 KiB
C++
#ifndef CREATURELIB_BATTLE_HPP
|
|
#define CREATURELIB_BATTLE_HPP
|
|
|
|
#include <vector>
|
|
#include "../EventHooks/EventHook.hpp"
|
|
#include "../Flow/ChoiceQueue.hpp"
|
|
#include "../Library/BattleLibrary.hpp"
|
|
#include "../TurnChoices/BaseTurnChoice.hpp"
|
|
#include "BattleParty.hpp"
|
|
#include "BattleRandom.hpp"
|
|
#include "BattleResult.hpp"
|
|
#include "BattleSide.hpp"
|
|
#include "CreatureIndex.hpp"
|
|
|
|
namespace CreatureLib::Battling {
|
|
class Battle : public ScriptSource {
|
|
const BattleLibrary* _library;
|
|
std::vector<BattleParty> _parties;
|
|
bool _canFlee;
|
|
uint8_t _numberOfSides;
|
|
uint8_t _creaturesPerSide;
|
|
std::vector<BattleSide*> _sides;
|
|
BattleRandom _random;
|
|
ChoiceQueue* _currentTurnQueue = nullptr;
|
|
bool _hasEnded = false;
|
|
BattleResult _battleResult = BattleResult::Empty();
|
|
EventHook _eventHook = EventHook();
|
|
|
|
ScriptSet _volatile;
|
|
|
|
public:
|
|
Battle(const BattleLibrary* library, std::vector<BattleParty> parties, bool canFlee = true,
|
|
uint8_t numberOfSides = 2, uint8_t creaturesPerSide = 1)
|
|
: _library(library), _parties(parties), _canFlee(canFlee), _numberOfSides(numberOfSides),
|
|
_creaturesPerSide(creaturesPerSide) {
|
|
_sides = std::vector<BattleSide*>(numberOfSides);
|
|
for (size_t i = 0; i < numberOfSides; i++) {
|
|
_sides[i] = new BattleSide(i, this, creaturesPerSide);
|
|
}
|
|
}
|
|
|
|
virtual ~Battle() {
|
|
for (auto s : _sides) {
|
|
delete s;
|
|
}
|
|
delete _currentTurnQueue;
|
|
}
|
|
|
|
[[nodiscard]] const BattleLibrary* GetLibrary() const;
|
|
|
|
virtual bool CanUse(const BaseTurnChoice* choice);
|
|
virtual bool TrySetChoice(BaseTurnChoice* choice);
|
|
|
|
bool CanFlee() const { return _canFlee; }
|
|
|
|
void CheckChoicesSetAndRun();
|
|
|
|
[[nodiscard]] ChoiceQueue* GetCurrentTurnQueue() const;
|
|
BattleRandom* GetRandom();
|
|
|
|
bool CreatureInField(const Creature* creature) const;
|
|
|
|
Creature* GetTarget(const CreatureIndex& target) {
|
|
return _sides[target.GetSideIndex()]->GetCreature(target.GetCreatureIndex());
|
|
}
|
|
|
|
void ForceRecall(uint8_t side, uint8_t index);
|
|
void SwitchCreature(uint8_t side, uint8_t index, Creature* c);
|
|
bool CanSlotBeFilled(uint8_t side, uint8_t index) const;
|
|
|
|
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) override;
|
|
|
|
void ValidateBattleState();
|
|
inline bool HasEnded() const { return _hasEnded; }
|
|
inline const BattleResult& GetResult() const { return _battleResult; }
|
|
|
|
const std::vector<BattleSide*>& GetSides() const { return _sides; }
|
|
Script* GetVolatileScript(const std::string& key) const { return _volatile.Get(key); }
|
|
void AddVolatileScript(const std::string& key);
|
|
void AddVolatileScript(Script* script);
|
|
void RemoveVolatileScript(const std::string& name);
|
|
void RemoveVolatileScript(Script* script);
|
|
void HasVolatileScript(const std::string& name) const;
|
|
|
|
void RegisterEventListener(EVENT_HOOK_FUNC(listener)) { this->_eventHook.RegisterListener(listener); }
|
|
void TriggerEventListener(EventData* data) { this->_eventHook.TriggerEvent(data); }
|
|
};
|
|
}
|
|
|
|
#endif // CREATURELIB_BATTLE_HPP
|