Support for cloning battles for AI purposes.
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:
@@ -168,3 +168,45 @@ BattleScript* Battle::AddVolatileScript(const ArbUt::StringView& key) {
|
||||
BattleScript* Battle::AddVolatileScript(BattleScript* script) { return _volatile.Add(script); }
|
||||
void Battle::RemoveVolatileScript(BattleScript* script) { _volatile.Remove(script->GetName()); }
|
||||
void Battle::DisplayText(const ArbUt::StringView& text) { TriggerEventListener<DisplayTextEvent>(text); }
|
||||
|
||||
Battle* Battle::Clone() {
|
||||
auto parties = ArbUt::List<BattleParty*>(_parties.Count());
|
||||
for (auto* party : _parties) {
|
||||
parties.Append(party->Clone());
|
||||
}
|
||||
|
||||
auto* battle = new Battle(_library, parties, _canFlee, _numberOfSides, _creaturesPerSide);
|
||||
|
||||
for (int i = 0; i < _numberOfSides; ++i) {
|
||||
battle->_sides.Set(i, _sides[i]->CloneWithoutCreatures());
|
||||
// FIXME: This is horrible code to translate the creature from the old battle into the same creature in the
|
||||
// new battle. This needs to be cleaned up, as it's ugly and slow.
|
||||
for (int creatureIndex = 0; creatureIndex < _creaturesPerSide; ++creatureIndex) {
|
||||
auto creature = _sides[i]->GetCreature(creatureIndex);
|
||||
if (!creature.HasValue()) {
|
||||
continue;
|
||||
}
|
||||
for (size_t j = 0; j < _parties.Count(); ++j) {
|
||||
auto party = _parties[j];
|
||||
if (!party->IsResponsibleForIndex(i, creatureIndex)) {
|
||||
continue;
|
||||
}
|
||||
auto partyIndex = party->GetParty()->GetParty().IndexOf(creature.GetValue());
|
||||
if (partyIndex != -1U) {
|
||||
auto c = battle->_parties.At(j)->GetParty()->GetParty()[partyIndex];
|
||||
battle->_sides.At(i)->SetCreature(c, creatureIndex);
|
||||
j = _parties.Count();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
battle->_random = _random;
|
||||
battle->_hasEnded = _hasEnded;
|
||||
battle->_battleResult = _battleResult;
|
||||
_historyHolder.CloneOnto(battle->_historyHolder);
|
||||
battle->_currentTurn = _currentTurn;
|
||||
_volatile.Clone(battle->_volatile);
|
||||
|
||||
return battle;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user