Support for swapping two creatures on a side.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
parent
cd3d665687
commit
9b7c271a20
|
@ -37,4 +37,8 @@ export uint8_t CreatureLib_BattleSide_MarkSlotAsUnfillable(BattleSide* p, Creatu
|
|||
|
||||
export bool CreatureLib_BattleSide_IsDefeated(BattleSide* p) { return p->IsDefeated(); }
|
||||
export bool CreatureLib_BattleSide_HasFled(BattleSide* p) { return p->HasFled(); }
|
||||
export void CreatureLib_BattleSide_MarkAsFled(BattleSide* p) { p->MarkAsFled(); }
|
||||
export void CreatureLib_BattleSide_MarkAsFled(BattleSide* p) { p->MarkAsFled(); }
|
||||
|
||||
export u8 CreatureLib_BattleSide_SwapPositions(u8& out, BattleSide* p, u8 a, u8 b) {
|
||||
Try(out = p->SwapPositions(a, b);)
|
||||
}
|
|
@ -90,3 +90,35 @@ uint8_t BattleSide::GetRandomCreatureIndex() {
|
|||
// TODO: Consider adding parameter to only get index for available creatures.
|
||||
return _battle->GetRandom()->Get(_creaturesPerSide);
|
||||
}
|
||||
bool BattleSide::SwapPositions(u8 a, u8 b) {
|
||||
// If out of range, don't allow swapping.
|
||||
if (a >= _creaturesPerSide || b >= _creaturesPerSide) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the two indices are the same, don't allow swapping.
|
||||
if (a == b) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Fetch parties for the two indices.
|
||||
BattleParty* partyA = nullptr;
|
||||
BattleParty* partyB = nullptr;
|
||||
for (auto* party : this->_battle->GetParties()) {
|
||||
if (party->IsResponsibleForIndex(_index, a)) {
|
||||
partyA = party;
|
||||
}
|
||||
if (party->IsResponsibleForIndex(_index, b)) {
|
||||
partyB = party;
|
||||
}
|
||||
}
|
||||
// Don't allow swapping if different parties are responsible for the indices.
|
||||
if (partyA != partyB) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto creatureA = _creatures[a];
|
||||
_creatures[a] = _creatures[b];
|
||||
_creatures[b] = creatureA;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -85,6 +85,8 @@ namespace CreatureLib::Battling {
|
|||
void MarkAsFled() noexcept { _hasFled = true; }
|
||||
|
||||
uint8_t GetRandomCreatureIndex();
|
||||
|
||||
bool SwapPositions(u8 a, u8 b);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue