Defensive programming for Party

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
2020-08-24 20:37:22 +02:00
parent fcdc58176f
commit 86ed173d30
2 changed files with 5 additions and 2 deletions

View File

@@ -24,6 +24,9 @@ namespace CreatureLib::Battling {
void Switch(size_t a, size_t b) noexcept { _party.Swap(a, b); }
Creature* SwapInto(size_t index, Creature* creature) {
if (index >= _party.Count()) {
THROW("Index was out of bounds for party.")
}
auto p = _party.TakeOwnership(index);
_party.Set(index, creature);
return p;