Support for packing party.
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
2020-08-10 17:37:30 +02:00
parent 3a75a40671
commit 1807e720dd
3 changed files with 65 additions and 5 deletions

View File

@@ -21,11 +21,7 @@ namespace CreatureLib::Battling {
ArbUt::BorrowedPtr<Creature> GetAtIndex(size_t index) const noexcept { return _party[index]; }
void Switch(size_t a, size_t b) noexcept {
auto ca = _party[a];
_party[a] = _party[b];
_party[b] = ca;
}
void Switch(size_t a, size_t b) noexcept { _party.Swap(a, b); }
Creature* SwapInto(size_t index, Creature* creature) {
auto p = _party.TakeOwnership(index);
@@ -48,6 +44,23 @@ namespace CreatureLib::Battling {
const ArbUt::UniquePtrList<Creature>& GetParty() const noexcept { return _party; }
size_t GetLength() const noexcept { return _party.Count(); }
void PackParty() {
int32_t firstNil = -1;
for (size_t i = 0; i < _party.Count(); i++) {
if (_party[i] == nullptr) {
if (firstNil == -1) {
firstNil = i;
}
} else {
if (firstNil != -1) {
_party.Swap(firstNil, i);
i = firstNil;
firstNil = -1;
}
}
}
}
};
}