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
src/Battling/Flow/ChoiceQueue.cpp
Normal file
1
src/Battling/Flow/ChoiceQueue.cpp
Normal file
@@ -0,0 +1 @@
|
||||
#include "ChoiceQueue.hpp"
|
||||
28
src/Battling/Flow/ChoiceQueue.hpp
Normal file
28
src/Battling/Flow/ChoiceQueue.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef CREATURELIB_CHOICEQUEUE_HPP
|
||||
#define CREATURELIB_CHOICEQUEUE_HPP
|
||||
|
||||
#include <vector>
|
||||
#include "../TurnChoices/BaseTurnChoice.hpp"
|
||||
|
||||
namespace CreatureLib::Battling{
|
||||
class ChoiceQueue {
|
||||
std::vector<const BaseTurnChoice*> _queue;
|
||||
size_t _current = 0;
|
||||
public:
|
||||
ChoiceQueue(const std::vector<const BaseTurnChoice*>& queue)
|
||||
:_queue(queue){}
|
||||
|
||||
const BaseTurnChoice* Dequeue(){
|
||||
auto b = _queue[_current];
|
||||
_current++;
|
||||
return b;
|
||||
}
|
||||
|
||||
bool HasNext() const{
|
||||
return _current < _queue.size();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif //CREATURELIB_CHOICEQUEUE_HPP
|
||||
5
src/Battling/Flow/TurnHandler.cpp
Normal file
5
src/Battling/Flow/TurnHandler.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
#include "TurnHandler.hpp"
|
||||
|
||||
void CreatureLib::Battling::TurnHandler::RunTurn(CreatureLib::Battling::ChoiceQueue &queue) {
|
||||
|
||||
}
|
||||
15
src/Battling/Flow/TurnHandler.hpp
Normal file
15
src/Battling/Flow/TurnHandler.hpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef CREATURELIB_TURNHANDLER_HPP
|
||||
#define CREATURELIB_TURNHANDLER_HPP
|
||||
|
||||
#include "ChoiceQueue.hpp"
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class Battle;
|
||||
|
||||
class TurnHandler {
|
||||
public:
|
||||
static void RunTurn(ChoiceQueue& queue);
|
||||
};
|
||||
}
|
||||
|
||||
#endif //CREATURELIB_TURNHANDLER_HPP
|
||||
18
src/Battling/Flow/TurnOrdering.cpp
Normal file
18
src/Battling/Flow/TurnOrdering.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include "TurnOrdering.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
using namespace CreatureLib::Battling;
|
||||
|
||||
bool ___ChoiceOrderFunc(const BaseTurnChoice* a, const BaseTurnChoice* b){
|
||||
auto aKind = a->GetKind();
|
||||
auto bKind = b->GetKind();
|
||||
if (aKind != bKind)
|
||||
return aKind > bKind;
|
||||
//FIXME: choices need to be ordered when they're the same type
|
||||
throw 1;
|
||||
}
|
||||
|
||||
void TurnOrdering::OrderChoices(std::vector<const BaseTurnChoice *> &vec) {
|
||||
std::sort(vec.begin(), vec.end(), ___ChoiceOrderFunc);
|
||||
}
|
||||
14
src/Battling/Flow/TurnOrdering.hpp
Normal file
14
src/Battling/Flow/TurnOrdering.hpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef CREATURELIB_TURNORDERING_HPP
|
||||
#define CREATURELIB_TURNORDERING_HPP
|
||||
|
||||
#include "../TurnChoices/BaseTurnChoice.hpp"
|
||||
#include <vector>
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class TurnOrdering {
|
||||
public:
|
||||
static void OrderChoices(std::vector<const BaseTurnChoice*>& vec);
|
||||
};
|
||||
}
|
||||
|
||||
#endif //CREATURELIB_TURNORDERING_HPP
|
||||
Reference in New Issue
Block a user