2019-10-31 11:02:23 +00:00
|
|
|
#include "ChoiceQueue.hpp"
|
2020-03-22 12:42:26 +00:00
|
|
|
#include <Arbutils/Assert.hpp>
|
2020-02-22 13:16:38 +00:00
|
|
|
|
|
|
|
bool CreatureLib::Battling::ChoiceQueue::MoveCreatureChoiceNext(CreatureLib::Battling::Creature* creature) {
|
2020-03-22 12:42:26 +00:00
|
|
|
AssertNotNull(creature)
|
2020-02-22 13:16:38 +00:00
|
|
|
// Find which index the creature choice is at.
|
2020-02-22 14:11:18 +00:00
|
|
|
size_t choiceIndex = SIZE_MAX;
|
2020-05-31 16:00:39 +00:00
|
|
|
for (size_t index = _current; index < _queue.Count(); index++) {
|
|
|
|
if (_queue.At(index)->GetUser() == creature) {
|
2020-02-22 13:16:38 +00:00
|
|
|
// If the creature choice is already next up, return.
|
|
|
|
if (index == _current)
|
|
|
|
return false;
|
|
|
|
choiceIndex = index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If the creature has no choice anymore, return.
|
2020-02-22 14:11:18 +00:00
|
|
|
if (choiceIndex == SIZE_MAX)
|
2020-02-22 13:16:38 +00:00
|
|
|
return false;
|
|
|
|
|
2020-05-31 16:00:39 +00:00
|
|
|
auto& vec = _queue.GetStdList();
|
2020-02-22 13:16:38 +00:00
|
|
|
// 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.
|
2020-05-31 16:00:39 +00:00
|
|
|
vec[i + 1] = vec[i];
|
2020-02-22 13:16:38 +00:00
|
|
|
}
|
|
|
|
// Set the creature choice up next.
|
2020-05-31 16:00:39 +00:00
|
|
|
vec[_current] = creatureChoice.GetRaw();
|
2020-02-22 13:16:38 +00:00
|
|
|
return true;
|
|
|
|
}
|