diff --git a/src/Battling/Models/Battle.cpp b/src/Battling/Models/Battle.cpp index 7b0900a..c4f7989 100644 --- a/src/Battling/Models/Battle.cpp +++ b/src/Battling/Models/Battle.cpp @@ -213,7 +213,7 @@ Battle* Battle::Clone() const { battle->_hasEnded = _hasEnded; battle->_battleResult = _battleResult; battle->_currentTurn = _currentTurn; - _volatile.Clone(battle->_volatile); + _volatile.Clone(battle, battle->_volatile); return battle; } diff --git a/src/Battling/Models/BattleSide.cpp b/src/Battling/Models/BattleSide.cpp index bf4fbcf..9589b1e 100644 --- a/src/Battling/Models/BattleSide.cpp +++ b/src/Battling/Models/BattleSide.cpp @@ -131,7 +131,7 @@ bool BattleSide::SwapPositions(u8 a, u8 b) { BattleSide* BattleSide::CloneWithoutCreatures(ArbUt::BorrowedPtr battle) const { auto* side = new BattleSide(_index, battle, _creaturesPerSide); side->_choicesSet = _choicesSet; - _volatile.Clone(side->_volatile); + _volatile.Clone(side, side->_volatile); side->_hasFled = _hasFled; return side; } diff --git a/src/Battling/Models/Creature.cpp b/src/Battling/Models/Creature.cpp index eda69a0..769f7b0 100644 --- a/src/Battling/Models/Creature.cpp +++ b/src/Battling/Models/Creature.cpp @@ -366,14 +366,14 @@ namespace CreatureLib::Battling { c->_battleData.OnBattleField = _battleData.OnBattleField; c->_battleData.Index = _battleData.Index; if (_activeTalent != nullptr) { - c->_activeTalent = std::unique_ptr(_activeTalent->Clone()); + c->_activeTalent = std::unique_ptr(_activeTalent->Clone(c)); } c->_hasOverridenTalent = _hasOverridenTalent; c->_overridenTalentName = _overridenTalentName; if (_status != nullptr) { - c->_status = std::unique_ptr(_status->Clone()); + c->_status = std::unique_ptr(_status->Clone(c)); } - _volatile.Clone(c->_volatile); + _volatile.Clone(c, c->_volatile); c->_types = std::vector(_types); c->RecalculateFlatStats(); diff --git a/src/Battling/ScriptHandling/BattleScript.hpp b/src/Battling/ScriptHandling/BattleScript.hpp index 11daf08..1d99ae3 100644 --- a/src/Battling/ScriptHandling/BattleScript.hpp +++ b/src/Battling/ScriptHandling/BattleScript.hpp @@ -15,14 +15,14 @@ namespace CreatureLib::Battling { ArbUt::OptionalBorrowedPtr _owner; public: - BattleScript(ArbUt::OptionalBorrowedPtr owner) { _owner = owner; }; + BattleScript(const ArbUt::OptionalBorrowedPtr& owner) { _owner = owner; }; NO_COPY_OR_MOVE(BattleScript); inline ArbUt::OptionalBorrowedPtr GetOwner() const noexcept { return _owner; } virtual ~BattleScript() = default; - virtual BattleScript* Clone() = 0; + virtual BattleScript* Clone(const ArbUt::OptionalBorrowedPtr& owner) = 0; virtual void Stack(){}; virtual void OnRemove(){}; diff --git a/src/Battling/ScriptHandling/ScriptSet.hpp b/src/Battling/ScriptHandling/ScriptSet.hpp index 25a0aed..9fa2c9e 100644 --- a/src/Battling/ScriptHandling/ScriptSet.hpp +++ b/src/Battling/ScriptHandling/ScriptSet.hpp @@ -15,9 +15,9 @@ namespace CreatureLib::Battling { static constexpr size_t defaultCapacity = 8; ScriptSet() : _scripts(defaultCapacity), _lookup(defaultCapacity){}; - void Clone(ScriptSet& s) const { + void Clone(const ArbUt::OptionalBorrowedPtr& owner, ScriptSet& s) const { for (auto* script : _scripts) { - s.Add(script->Clone()); + s.Add(script->Clone(owner)); } } diff --git a/tests/BattleTests/ScriptTests/ScriptAggregatorTests.cpp b/tests/BattleTests/ScriptTests/ScriptAggregatorTests.cpp index a966e7b..1db3f24 100644 --- a/tests/BattleTests/ScriptTests/ScriptAggregatorTests.cpp +++ b/tests/BattleTests/ScriptTests/ScriptAggregatorTests.cpp @@ -18,7 +18,7 @@ public: void TestMethod(int& runCount) { runCount++; } - BattleScript* Clone() override { return new TestScript(_name); } + BattleScript* Clone(const ArbUt::OptionalBorrowedPtr&) override { return new TestScript(_name); } }; TEST_CASE("Script Aggregator properly iterates containing script.") { diff --git a/tests/BattleTests/ScriptTests/ScriptSetTests.cpp b/tests/BattleTests/ScriptTests/ScriptSetTests.cpp index 9c48c9c..7a4685e 100644 --- a/tests/BattleTests/ScriptTests/ScriptSetTests.cpp +++ b/tests/BattleTests/ScriptTests/ScriptSetTests.cpp @@ -15,7 +15,7 @@ public: explicit TestScript(const ArbUt::StringView& name) : BattleScript(nullptr), _name(name){}; const ArbUt::StringView& GetName() const noexcept override { return _name; } - BattleScript* Clone() override { return new TestScript(_name); } + BattleScript* Clone(const ArbUt::OptionalBorrowedPtr&) override { return new TestScript(_name); } }; TEST_CASE("Empty script set count == 0") { diff --git a/tests/BattleTests/ScriptTests/ScriptSourceTest.cpp b/tests/BattleTests/ScriptTests/ScriptSourceTest.cpp index fe7466e..153f560 100644 --- a/tests/BattleTests/ScriptTests/ScriptSourceTest.cpp +++ b/tests/BattleTests/ScriptTests/ScriptSourceTest.cpp @@ -15,7 +15,7 @@ public: const ArbUt::StringView& GetName() const noexcept override { return _name; } void TestMethod(int& runCount) { runCount++; } - BattleScript* Clone() override { return new TestScript(_name); } + BattleScript* Clone(const ArbUt::OptionalBorrowedPtr&) override { return new TestScript(_name); } }; class ScriptSourceWithScriptPtr : public ScriptSource {