Return cloned AiPackage as unique_ptr

pull/578/head
elsid 5 years ago
parent f5e2e53bcf
commit ce7c47ee12
No known key found for this signature in database
GPG Key ID: B845CB9FEE18AB40

@ -1,6 +1,8 @@
#ifndef GAME_MWMECHANICS_AIPACKAGE_H
#define GAME_MWMECHANICS_AIPACKAGE_H
#include <memory>
#include <components/esm/defs.hpp>
#include "pathfinding.hpp"
@ -59,7 +61,7 @@ namespace MWMechanics
virtual ~AiPackage() = default;
///Clones the package
virtual AiPackage *clone() const = 0;
virtual std::unique_ptr<AiPackage> clone() const = 0;
/// Updates and runs the package (Should run every frame)
/// \return Package completed?

@ -27,7 +27,7 @@ void AiSequence::copy (const AiSequence& sequence)
{
for (std::list<AiPackage *>::const_iterator iter (sequence.mPackages.begin());
iter!=sequence.mPackages.end(); ++iter)
mPackages.push_back ((*iter)->clone());
mPackages.push_back ((*iter)->clone().release());
// We need to keep an AiWander storage, if present - it has a state machine.
// Not sure about another temporary storages
@ -288,7 +288,7 @@ void AiSequence::execute (const MWWorld::Ptr& actor, CharacterController& charac
if (isActualAiPackage(packageTypeId) && (mRepeat || package->getRepeat()))
{
package->reset();
mPackages.push_back(package->clone());
mPackages.push_back(package->clone().release());
}
// To account for the rare case where AiPackage::execute() queued another AI package
// (e.g. AiPursue executing a dialogue script that uses startCombat)
@ -380,12 +380,12 @@ void AiSequence::stack (const AiPackage& package, const MWWorld::Ptr& actor, boo
if((*it)->getPriority() <= package.getPriority())
{
mPackages.insert(it,package.clone());
mPackages.insert(it,package.clone().release());
return;
}
}
mPackages.push_back (package.clone());
mPackages.push_back (package.clone().release());
// Make sure that temporary storage is empty
if (cancelOther)

@ -8,9 +8,9 @@ namespace MWMechanics
template <class T>
struct TypedAiPackage : public AiPackage
{
virtual TypedAiPackage<T> *clone() const override
virtual std::unique_ptr<AiPackage> clone() const override
{
return new T(*static_cast<const T*>(this));
return std::make_unique<T>(*static_cast<const T*>(this));
}
};
}

Loading…
Cancel
Save