Support for swapping two creatures on a side.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
@@ -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);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user