CreatureLib/src/Battling/Flow/ChoiceQueue.cpp

30 lines
1.1 KiB
C++

#include "ChoiceQueue.hpp"
bool CreatureLib::Battling::ChoiceQueue::MoveCreatureChoiceNext(CreatureLib::Battling::Creature* creature) {
EnsureNotNull(creature)
// Find which index the creature choice is at.
size_t choiceIndex = SIZE_MAX;
for (size_t index = _current; index < _queue.size(); index++) {
if (_queue[index]->GetUser() == creature) {
// If the creature choice is already next up, return.
if (index == _current)
return false;
choiceIndex = index;
}
}
// If the creature has no choice anymore, return.
if (choiceIndex == SIZE_MAX)
return false;
// Save the pointer to the creature choice.
auto creatureChoice = _queue[choiceIndex];
// Starting at the position before the current creature choice, and iterating backwards up till the current choice.
for (size_t i = choiceIndex - 1; i >= _current && i != SIZE_MAX; i--) {
// Place everything in one spot later.
_queue[i + 1] = _queue[i];
}
// Set the creature choice up next.
_queue[_current] = creatureChoice;
return true;
}