Make ChoiceQueue use smart pointers.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-05-31 18:00:39 +02:00
parent ff181204ae
commit 29cb4eac37
8 changed files with 32 additions and 35 deletions

View File

@@ -5,8 +5,8 @@ bool CreatureLib::Battling::ChoiceQueue::MoveCreatureChoiceNext(CreatureLib::Bat
AssertNotNull(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.at(index)->GetUser() == creature) {
for (size_t index = _current; index < _queue.Count(); index++) {
if (_queue.At(index)->GetUser() == creature) {
// If the creature choice is already next up, return.
if (index == _current)
return false;
@@ -17,14 +17,15 @@ bool CreatureLib::Battling::ChoiceQueue::MoveCreatureChoiceNext(CreatureLib::Bat
if (choiceIndex == SIZE_MAX)
return false;
auto& vec = _queue.GetStdList();
// 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];
vec[i + 1] = vec[i];
}
// Set the creature choice up next.
_queue[_current] = creatureChoice;
vec[_current] = creatureChoice.GetRaw();
return true;
}