Initial support for ordering choices and getting them ready for execution.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
#include "Battle.hpp"
|
||||
#include "../Flow/TurnHandler.hpp"
|
||||
#include "../TurnChoices/AttackTurnChoice.hpp"
|
||||
#include "../Flow/TurnOrdering.hpp"
|
||||
|
||||
const CreatureLib::Battling::BattleLibrary *CreatureLib::Battling::Battle::GetLibrary() const {
|
||||
using namespace CreatureLib::Battling;
|
||||
|
||||
const BattleLibrary *Battle::GetLibrary() const {
|
||||
return _library;
|
||||
}
|
||||
|
||||
bool CreatureLib::Battling::Battle::CanUse(CreatureLib::Battling::BaseTurnChoice *choice) {
|
||||
bool Battle::CanUse(BaseTurnChoice *choice) {
|
||||
if (choice->GetKind() == TurnChoiceKind::Attack){
|
||||
//HOOK: change number of uses needed.
|
||||
return static_cast<AttackTurnChoice*>(choice)->GetAttack()->GetRemainingUses() > 1;
|
||||
@@ -13,9 +17,35 @@ bool CreatureLib::Battling::Battle::CanUse(CreatureLib::Battling::BaseTurnChoice
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CreatureLib::Battling::Battle::TrySetChoice(CreatureLib::Battling::BaseTurnChoice *choice) {
|
||||
bool Battle::TrySetChoice(BaseTurnChoice *choice) {
|
||||
if (!CanUse(choice))
|
||||
return false;
|
||||
choice->GetUser()->GetBattleSide()->SetChoice(choice);
|
||||
CheckChoicesSetAndRun();
|
||||
return true;
|
||||
}
|
||||
|
||||
void Battle::CheckChoicesSetAndRun() {
|
||||
for (auto side: _sides){
|
||||
if (!side->AllChoicesSet()){
|
||||
return;
|
||||
}
|
||||
}
|
||||
auto choices = std::vector<const BaseTurnChoice*>(_numberOfSides * _creaturesPerSide);
|
||||
auto i = 0;
|
||||
for (auto side: _sides){
|
||||
for (auto choice: side->GetChoices()){
|
||||
choices[i] = choice;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
TurnOrdering::OrderChoices(choices);
|
||||
auto choiceQueue = ChoiceQueue(choices);
|
||||
this->_currentTurnQueue = &choiceQueue;
|
||||
TurnHandler::RunTurn(choiceQueue);
|
||||
this->_currentTurnQueue = nullptr;
|
||||
}
|
||||
|
||||
ChoiceQueue* Battle::GetCurrentTurnQueue() const {
|
||||
return _currentTurnQueue;
|
||||
}
|
||||
|
||||
@@ -5,16 +5,25 @@
|
||||
#include "BattleSide.hpp"
|
||||
#include "../Library/BattleLibrary.hpp"
|
||||
#include "../TurnChoices/BaseTurnChoice.hpp"
|
||||
#include "../Flow/ChoiceQueue.hpp"
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class Battle {
|
||||
const BattleLibrary* _library;
|
||||
uint8_t _numberOfSides;
|
||||
uint8_t _creaturesPerSide;
|
||||
std::vector<BattleSide*> _sides;
|
||||
|
||||
ChoiceQueue* _currentTurnQueue = nullptr;
|
||||
public:
|
||||
const BattleLibrary* GetLibrary() const;
|
||||
|
||||
virtual bool CanUse(BaseTurnChoice* choice);
|
||||
virtual bool TrySetChoice(BaseTurnChoice* choice);
|
||||
|
||||
void CheckChoicesSetAndRun();
|
||||
|
||||
ChoiceQueue* GetCurrentTurnQueue() const;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user