From 9f27a0d095784955f536fdc399780a3d258d895a Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Tue, 10 Mar 2020 10:28:23 +0400 Subject: [PATCH] Keep an AiWanderStorage when cloning an actor (bug #5267) --- apps/openmw/mwmechanics/aisequence.cpp | 4 ++++ apps/openmw/mwmechanics/aistate.hpp | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/apps/openmw/mwmechanics/aisequence.cpp b/apps/openmw/mwmechanics/aisequence.cpp index 5760069e7..5f3931fcf 100644 --- a/apps/openmw/mwmechanics/aisequence.cpp +++ b/apps/openmw/mwmechanics/aisequence.cpp @@ -28,6 +28,10 @@ void AiSequence::copy (const AiSequence& sequence) for (std::list::const_iterator iter (sequence.mPackages.begin()); iter!=sequence.mPackages.end(); ++iter) mPackages.push_back ((*iter)->clone()); + + // We need to keep an AiWander storage, if present - it has a state machine. + // Not sure about another temporary storages + sequence.mAiState.copy(mAiState); } AiSequence::AiSequence() : mDone (false), mRepeat(false), mLastAiPackage(-1) {} diff --git a/apps/openmw/mwmechanics/aistate.hpp b/apps/openmw/mwmechanics/aistate.hpp index 949fb74dd..976e21c65 100644 --- a/apps/openmw/mwmechanics/aistate.hpp +++ b/apps/openmw/mwmechanics/aistate.hpp @@ -38,6 +38,14 @@ namespace MWMechanics //return a reference to the (new allocated) object return *result; } + + template< class Derived > + void copy(DerivedClassStorage& destination) const + { + Derived* result = dynamic_cast(mStorage); + if (result != nullptr) + destination.store(*result); + } template< class Derived > void store( const Derived& payload )