Make Clone functions const.

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
Deukhoofd 2021-04-11 16:01:18 +02:00
parent 84a14cff2b
commit 2b1a1792bf
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
11 changed files with 11 additions and 11 deletions

View File

@ -68,7 +68,7 @@ namespace CreatureLib::Battling {
return {}; return {};
} }
void CloneOnto(HistoryHolder& other) { void CloneOnto(HistoryHolder& other) const {
if (other._top != nullptr) { if (other._top != nullptr) {
other._top->Clear(); other._top->Clear();
} }

View File

@ -169,7 +169,7 @@ BattleScript* Battle::AddVolatileScript(BattleScript* script) { return _volatile
void Battle::RemoveVolatileScript(BattleScript* script) { _volatile.Remove(script->GetName()); } void Battle::RemoveVolatileScript(BattleScript* script) { _volatile.Remove(script->GetName()); }
void Battle::DisplayText(const ArbUt::StringView& text) { TriggerEventListener<DisplayTextEvent>(text); } void Battle::DisplayText(const ArbUt::StringView& text) { TriggerEventListener<DisplayTextEvent>(text); }
Battle* Battle::Clone() { Battle* Battle::Clone() const {
auto parties = ArbUt::List<BattleParty*>(_parties.Count()); auto parties = ArbUt::List<BattleParty*>(_parties.Count());
for (auto* party : _parties) { for (auto* party : _parties) {
parties.Append(party->Clone()); parties.Append(party->Clone());

View File

@ -132,7 +132,7 @@ namespace CreatureLib::Battling {
} }
} }
Battle* Clone(); virtual Battle* Clone() const;
}; };
} }

View File

@ -43,7 +43,7 @@ namespace CreatureLib::Battling {
return false; return false;
} }
virtual BattleParty* Clone() { return new BattleParty(_party->Clone(), _responsibleIndices); } virtual BattleParty* Clone() const { return new BattleParty(_party->Clone(), _responsibleIndices); }
}; };
} }

View File

@ -123,7 +123,7 @@ bool BattleSide::SwapPositions(u8 a, u8 b) {
_battle->TriggerEventListener<SwapEvent>(_index, a, b); _battle->TriggerEventListener<SwapEvent>(_index, a, b);
return true; return true;
} }
BattleSide* BattleSide::CloneWithoutCreatures() { BattleSide* BattleSide::CloneWithoutCreatures() const {
auto* side = new BattleSide(_index, _battle, _creaturesPerSide); auto* side = new BattleSide(_index, _battle, _creaturesPerSide);
side->_choicesSet = _choicesSet; side->_choicesSet = _choicesSet;
_volatile.Clone(side->_volatile); _volatile.Clone(side->_volatile);

View File

@ -88,7 +88,7 @@ namespace CreatureLib::Battling {
bool SwapPositions(u8 a, u8 b); bool SwapPositions(u8 a, u8 b);
BattleSide* CloneWithoutCreatures(); BattleSide* CloneWithoutCreatures() const;
}; };
} }

View File

@ -331,7 +331,7 @@ namespace CreatureLib::Battling {
_attacks.Set(index, attack); _attacks.Set(index, attack);
} }
Creature* Creature::Clone() { Creature* Creature::Clone() const {
auto attacks = std::vector<LearnedAttack*>(_attacks.Count()); auto attacks = std::vector<LearnedAttack*>(_attacks.Count());
auto i = 0; auto i = 0;
for (auto* attack : _attacks) { for (auto* attack : _attacks) {

View File

@ -187,7 +187,7 @@ namespace CreatureLib::Battling {
// endregion // endregion
virtual Creature* Clone(); virtual Creature* Clone() const;
}; };
} }

View File

@ -64,7 +64,7 @@ namespace CreatureLib::Battling {
} }
} }
virtual CreatureParty* Clone() { virtual CreatureParty* Clone() const {
auto party = new CreatureParty(_party.Count()); auto party = new CreatureParty(_party.Count());
auto i = 0; auto i = 0;
for (auto c : _party) { for (auto c : _party) {

View File

@ -29,7 +29,7 @@ namespace CreatureLib::Battling {
virtual void RestoreUses(uint8_t amount) noexcept; virtual void RestoreUses(uint8_t amount) noexcept;
virtual void RestoreAllUses() noexcept; virtual void RestoreAllUses() noexcept;
virtual LearnedAttack* Clone() { virtual LearnedAttack* Clone() const {
auto* attack = new LearnedAttack(_attack, _maxUses, _learnMethod); auto* attack = new LearnedAttack(_attack, _maxUses, _learnMethod);
attack->_remainingUses = _remainingUses; attack->_remainingUses = _remainingUses;
return attack; return attack;

View File

@ -15,7 +15,7 @@ namespace CreatureLib::Battling {
static constexpr size_t defaultCapacity = 8; static constexpr size_t defaultCapacity = 8;
ScriptSet() : _scripts(defaultCapacity), _lookup(defaultCapacity){}; ScriptSet() : _scripts(defaultCapacity), _lookup(defaultCapacity){};
void Clone(ScriptSet& s) { void Clone(ScriptSet& s) const {
for (auto* script : _scripts) { for (auto* script : _scripts) {
s.Add(script->Clone()); s.Add(script->Clone());
} }