Defensive programming for Party

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

View File

@ -16,8 +16,8 @@ export uint8_t CreatureLib_CreatureParty_GetAtIndex(Creature*& out, const Creatu
export uint8_t CreatureLib_CreatureParty_Switch(CreatureParty* p, size_t a, size_t b) { Try(p->Switch(a, b);) }
export uint8_t CreatureLib_CreatureParty_PackParty(CreatureParty* p) { Try(p->PackParty();) }
export Creature* CreatureLib_CreatureParty_SwapInto(CreatureParty* p, size_t index, Creature* creature) {
return p->SwapInto(index, creature);
export uint8_t CreatureLib_CreatureParty_SwapInto(Creature*& out, CreatureParty* p, size_t index, Creature* creature) {
Try(out = p->SwapInto(index, creature);)
}
export bool CreatureLib_CreatureParty_HasAvailableCreatures(const CreatureParty* p) {

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;