diff --git a/apps/openmw/mwmechanics/aiactivate.cpp b/apps/openmw/mwmechanics/aiactivate.cpp index c412a7ea1d..6764eba23f 100644 --- a/apps/openmw/mwmechanics/aiactivate.cpp +++ b/apps/openmw/mwmechanics/aiactivate.cpp @@ -18,11 +18,6 @@ namespace MWMechanics { } - AiActivate *MWMechanics::AiActivate::clone() const - { - return new AiActivate(*this); - } - bool AiActivate::execute(const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) { const MWWorld::Ptr target = MWBase::Environment::get().getWorld()->searchPtr(mObjectId, false); //The target to follow diff --git a/apps/openmw/mwmechanics/aiactivate.hpp b/apps/openmw/mwmechanics/aiactivate.hpp index 4cc9f3036f..5a9e3d6d85 100644 --- a/apps/openmw/mwmechanics/aiactivate.hpp +++ b/apps/openmw/mwmechanics/aiactivate.hpp @@ -1,7 +1,7 @@ #ifndef GAME_MWMECHANICS_AIACTIVATE_H #define GAME_MWMECHANICS_AIACTIVATE_H -#include "aipackage.hpp" +#include "typedaipackage.hpp" #include @@ -19,7 +19,7 @@ namespace MWMechanics { /// \brief Causes actor to walk to activatable object and activate it /** Will activate when close to object **/ - class AiActivate final : public AiPackage + class AiActivate final : public TypedAiPackage { public: /// Constructor @@ -28,7 +28,6 @@ namespace MWMechanics AiActivate(const ESM::AiSequence::AiActivate* activate); - AiActivate *clone() const final; bool execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) final; int getTypeId() const final; diff --git a/apps/openmw/mwmechanics/aiavoiddoor.cpp b/apps/openmw/mwmechanics/aiavoiddoor.cpp index c476c9b576..9cdb8d90bd 100644 --- a/apps/openmw/mwmechanics/aiavoiddoor.cpp +++ b/apps/openmw/mwmechanics/aiavoiddoor.cpp @@ -16,7 +16,7 @@ static const int MAX_DIRECTIONS = 4; MWMechanics::AiAvoidDoor::AiAvoidDoor(const MWWorld::ConstPtr& doorPtr) -: AiPackage(), mDuration(1), mDoorPtr(doorPtr), mDirection(0) +: mDuration(1), mDoorPtr(doorPtr), mDirection(0) { } @@ -72,11 +72,6 @@ bool MWMechanics::AiAvoidDoor::execute (const MWWorld::Ptr& actor, CharacterCont return false; } -MWMechanics::AiAvoidDoor *MWMechanics::AiAvoidDoor::clone() const -{ - return new AiAvoidDoor(*this); -} - int MWMechanics::AiAvoidDoor::getTypeId() const { return TypeIdAvoidDoor; diff --git a/apps/openmw/mwmechanics/aiavoiddoor.hpp b/apps/openmw/mwmechanics/aiavoiddoor.hpp index 39a78192bc..cc02c4de18 100644 --- a/apps/openmw/mwmechanics/aiavoiddoor.hpp +++ b/apps/openmw/mwmechanics/aiavoiddoor.hpp @@ -1,7 +1,7 @@ #ifndef GAME_MWMECHANICS_AIAVOIDDOOR_H #define GAME_MWMECHANICS_AIAVOIDDOOR_H -#include "aipackage.hpp" +#include "typedaipackage.hpp" #include @@ -16,14 +16,12 @@ namespace MWMechanics /// \brief AiPackage to have an actor avoid an opening door /** The AI will retreat from the door until it has finished opening, walked far away from it, or one second has passed, in an attempt to avoid it **/ - class AiAvoidDoor final : public AiPackage + class AiAvoidDoor final : public TypedAiPackage { public: /// Avoid door until the door is fully open AiAvoidDoor(const MWWorld::ConstPtr& doorPtr); - AiAvoidDoor *clone() const final; - bool execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) final; int getTypeId() const final; diff --git a/apps/openmw/mwmechanics/aibreathe.cpp b/apps/openmw/mwmechanics/aibreathe.cpp index 4955f683c5..5cb81b3d89 100644 --- a/apps/openmw/mwmechanics/aibreathe.cpp +++ b/apps/openmw/mwmechanics/aibreathe.cpp @@ -11,12 +11,6 @@ #include "movement.hpp" #include "steering.hpp" -MWMechanics::AiBreathe::AiBreathe() -: AiPackage() -{ - -} - bool MWMechanics::AiBreathe::execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) { static const float fHoldBreathTime = MWBase::Environment::get().getWorld()->getStore().get().find("fHoldBreathTime")->mValue.getFloat(); @@ -38,11 +32,6 @@ bool MWMechanics::AiBreathe::execute (const MWWorld::Ptr& actor, CharacterContro return true; } -MWMechanics::AiBreathe *MWMechanics::AiBreathe::clone() const -{ - return new AiBreathe(*this); -} - int MWMechanics::AiBreathe::getTypeId() const { return TypeIdBreathe; diff --git a/apps/openmw/mwmechanics/aibreathe.hpp b/apps/openmw/mwmechanics/aibreathe.hpp index daa2782c29..6e3bb912a5 100644 --- a/apps/openmw/mwmechanics/aibreathe.hpp +++ b/apps/openmw/mwmechanics/aibreathe.hpp @@ -1,19 +1,15 @@ #ifndef GAME_MWMECHANICS_AIBREATHE_H #define GAME_MWMECHANICS_AIBREATHE_H -#include "aipackage.hpp" +#include "typedaipackage.hpp" namespace MWMechanics { /// \brief AiPackage to have an actor resurface to breathe // The AI will go up if lesser than half breath left - class AiBreathe final : public AiPackage + class AiBreathe final : public TypedAiPackage { public: - AiBreathe(); - - AiBreathe *clone() const final; - bool execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) final; int getTypeId() const final; diff --git a/apps/openmw/mwmechanics/aicast.cpp b/apps/openmw/mwmechanics/aicast.cpp index b7c9bac3ba..de61851cd9 100644 --- a/apps/openmw/mwmechanics/aicast.cpp +++ b/apps/openmw/mwmechanics/aicast.cpp @@ -18,11 +18,6 @@ MWMechanics::AiCast::AiCast(const std::string& targetId, const std::string& spel mDistance = action.getCombatRange(isRanged); } -MWMechanics::AiPackage *MWMechanics::AiCast::clone() const -{ - return new AiCast(*this); -} - bool MWMechanics::AiCast::execute(const MWWorld::Ptr& actor, MWMechanics::CharacterController& characterController, MWMechanics::AiState& state, float duration) { MWWorld::Ptr target; diff --git a/apps/openmw/mwmechanics/aicast.hpp b/apps/openmw/mwmechanics/aicast.hpp index 6b10370c6d..21b629f245 100644 --- a/apps/openmw/mwmechanics/aicast.hpp +++ b/apps/openmw/mwmechanics/aicast.hpp @@ -1,7 +1,7 @@ #ifndef GAME_MWMECHANICS_AICAST_H #define GAME_MWMECHANICS_AICAST_H -#include "aipackage.hpp" +#include "typedaipackage.hpp" namespace MWWorld { @@ -11,12 +11,10 @@ namespace MWWorld namespace MWMechanics { /// AiPackage which makes an actor to cast given spell. - class AiCast final : public AiPackage { + class AiCast final : public TypedAiPackage { public: AiCast(const std::string& targetId, const std::string& spellId, bool manualSpell=false); - AiPackage *clone() const final; - bool execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) final; int getTypeId() const final; diff --git a/apps/openmw/mwmechanics/aicombat.cpp b/apps/openmw/mwmechanics/aicombat.cpp index ee1b9cecdc..4a3c7aee67 100644 --- a/apps/openmw/mwmechanics/aicombat.cpp +++ b/apps/openmw/mwmechanics/aicombat.cpp @@ -421,11 +421,6 @@ namespace MWMechanics return MWBase::Environment::get().getWorld()->searchPtrViaActorId(mTargetActorId); } - AiCombat *MWMechanics::AiCombat::clone() const - { - return new AiCombat(*this); - } - void AiCombat::writeState(ESM::AiSequence::AiSequence &sequence) const { std::unique_ptr combat(new ESM::AiSequence::AiCombat()); diff --git a/apps/openmw/mwmechanics/aicombat.hpp b/apps/openmw/mwmechanics/aicombat.hpp index 049857e71d..2ef0298fcc 100644 --- a/apps/openmw/mwmechanics/aicombat.hpp +++ b/apps/openmw/mwmechanics/aicombat.hpp @@ -1,7 +1,7 @@ #ifndef GAME_MWMECHANICS_AICOMBAT_H #define GAME_MWMECHANICS_AICOMBAT_H -#include "aipackage.hpp" +#include "typedaipackage.hpp" #include "../mwworld/cellstore.hpp" // for Doors @@ -91,7 +91,7 @@ namespace MWMechanics }; /// \brief Causes the actor to fight another actor - class AiCombat final : public AiPackage + class AiCombat final : public TypedAiPackage { public: ///Constructor @@ -102,8 +102,6 @@ namespace MWMechanics void init(); - AiCombat *clone() const final; - bool execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) final; int getTypeId() const final; diff --git a/apps/openmw/mwmechanics/aiescort.cpp b/apps/openmw/mwmechanics/aiescort.cpp index 03951d2798..5e1d38331d 100644 --- a/apps/openmw/mwmechanics/aiescort.cpp +++ b/apps/openmw/mwmechanics/aiescort.cpp @@ -55,12 +55,6 @@ namespace MWMechanics mDuration = 0; } - - AiEscort *MWMechanics::AiEscort::clone() const - { - return new AiEscort(*this); - } - bool AiEscort::execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) { // If AiEscort has ran for as long or longer then the duration specified diff --git a/apps/openmw/mwmechanics/aiescort.hpp b/apps/openmw/mwmechanics/aiescort.hpp index 5b49807a2d..9f5ac2f422 100644 --- a/apps/openmw/mwmechanics/aiescort.hpp +++ b/apps/openmw/mwmechanics/aiescort.hpp @@ -1,7 +1,7 @@ #ifndef GAME_MWMECHANICS_AIESCORT_H #define GAME_MWMECHANICS_AIESCORT_H -#include "aipackage.hpp" +#include "typedaipackage.hpp" #include @@ -16,7 +16,7 @@ namespace AiSequence namespace MWMechanics { /// \brief AI Package to have an NPC lead the player to a specific point - class AiEscort final : public AiPackage + class AiEscort final : public TypedAiPackage { public: /// Implementation of AiEscort @@ -30,8 +30,6 @@ namespace MWMechanics AiEscort(const ESM::AiSequence::AiEscort* escort); - AiEscort *clone() const final; - bool execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) final; int getTypeId() const final; diff --git a/apps/openmw/mwmechanics/aiface.cpp b/apps/openmw/mwmechanics/aiface.cpp index b99a8c1f45..0bfd00c878 100644 --- a/apps/openmw/mwmechanics/aiface.cpp +++ b/apps/openmw/mwmechanics/aiface.cpp @@ -9,11 +9,6 @@ MWMechanics::AiFace::AiFace(float targetX, float targetY) { } -MWMechanics::AiPackage *MWMechanics::AiFace::clone() const -{ - return new AiFace(*this); -} - bool MWMechanics::AiFace::execute(const MWWorld::Ptr& actor, MWMechanics::CharacterController& /*characterController*/, MWMechanics::AiState& /*state*/, float /*duration*/) { osg::Vec3f dir = osg::Vec3f(mTargetX, mTargetY, 0) - actor.getRefData().getPosition().asVec3(); diff --git a/apps/openmw/mwmechanics/aiface.hpp b/apps/openmw/mwmechanics/aiface.hpp index 98d9ea04b8..ce1c9847bd 100644 --- a/apps/openmw/mwmechanics/aiface.hpp +++ b/apps/openmw/mwmechanics/aiface.hpp @@ -1,17 +1,15 @@ #ifndef GAME_MWMECHANICS_AIFACE_H #define GAME_MWMECHANICS_AIFACE_H -#include "aipackage.hpp" +#include "typedaipackage.hpp" namespace MWMechanics { /// AiPackage which makes an actor face a certain direction. - class AiFace final : public AiPackage { + class AiFace final : public TypedAiPackage { public: AiFace(float targetX, float targetY); - AiPackage *clone() const final; - bool execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) final; int getTypeId() const final; diff --git a/apps/openmw/mwmechanics/aifollow.cpp b/apps/openmw/mwmechanics/aifollow.cpp index 09e8d0ecd8..bffa238d5d 100644 --- a/apps/openmw/mwmechanics/aifollow.cpp +++ b/apps/openmw/mwmechanics/aifollow.cpp @@ -201,11 +201,6 @@ std::string AiFollow::getFollowedActor() return mTargetActorRefId; } -AiFollow *MWMechanics::AiFollow::clone() const -{ - return new AiFollow(*this); -} - int AiFollow::getTypeId() const { return TypeIdFollow; diff --git a/apps/openmw/mwmechanics/aifollow.hpp b/apps/openmw/mwmechanics/aifollow.hpp index fc4b7fc0bb..39a10294b1 100644 --- a/apps/openmw/mwmechanics/aifollow.hpp +++ b/apps/openmw/mwmechanics/aifollow.hpp @@ -1,7 +1,7 @@ #ifndef GAME_MWMECHANICS_AIFOLLOW_H #define GAME_MWMECHANICS_AIFOLLOW_H -#include "aipackage.hpp" +#include "typedaipackage.hpp" #include @@ -39,7 +39,7 @@ namespace MWMechanics /// \brief AiPackage for an actor to follow another actor/the PC /** The AI will follow the target until a condition (time, or position) are set. Both can be disabled to cause the actor to follow the other indefinitely **/ - class AiFollow final : public AiPackage + class AiFollow final : public TypedAiPackage { public: AiFollow(const std::string &actorId, float duration, float x, float y, float z); @@ -57,8 +57,6 @@ namespace MWMechanics bool followTargetThroughDoors() const final { return true; } bool shouldCancelPreviousAi() const final { return !mCommanded; } - AiFollow *clone() const final; - bool execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) final; int getTypeId() const final; diff --git a/apps/openmw/mwmechanics/aipursue.cpp b/apps/openmw/mwmechanics/aipursue.cpp index 52b2866bba..76b4ac0c9f 100644 --- a/apps/openmw/mwmechanics/aipursue.cpp +++ b/apps/openmw/mwmechanics/aipursue.cpp @@ -27,10 +27,6 @@ AiPursue::AiPursue(const ESM::AiSequence::AiPursue *pursue) mTargetActorId = pursue->mTargetActorId; } -AiPursue *MWMechanics::AiPursue::clone() const -{ - return new AiPursue(*this); -} bool AiPursue::execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) { if(actor.getClass().getCreatureStats(actor).isDead()) diff --git a/apps/openmw/mwmechanics/aipursue.hpp b/apps/openmw/mwmechanics/aipursue.hpp index 3f2c2923e5..6898a8dd34 100644 --- a/apps/openmw/mwmechanics/aipursue.hpp +++ b/apps/openmw/mwmechanics/aipursue.hpp @@ -1,7 +1,7 @@ #ifndef GAME_MWMECHANICS_AIPURSUE_H #define GAME_MWMECHANICS_AIPURSUE_H -#include "aipackage.hpp" +#include "typedaipackage.hpp" namespace ESM { @@ -17,7 +17,7 @@ namespace MWMechanics /** Used for arresting players. Causes the actor to run to the pursued actor and activate them, to arrest them. Note that while very similar to AiActivate, it will ONLY activate when evry close to target (Not also when the path is completed). **/ - class AiPursue final : public AiPackage + class AiPursue final : public TypedAiPackage { public: ///Constructor @@ -26,7 +26,6 @@ namespace MWMechanics AiPursue(const ESM::AiSequence::AiPursue* pursue); - AiPursue *clone() const final; bool execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) final; int getTypeId() const final; diff --git a/apps/openmw/mwmechanics/aitravel.cpp b/apps/openmw/mwmechanics/aitravel.cpp index 822523c766..ea65f46703 100644 --- a/apps/openmw/mwmechanics/aitravel.cpp +++ b/apps/openmw/mwmechanics/aitravel.cpp @@ -37,11 +37,6 @@ namespace MWMechanics { } - AiTravel *MWMechanics::AiTravel::clone() const - { - return new AiTravel(*this); - } - bool AiTravel::execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) { MWBase::MechanicsManager* mechMgr = MWBase::Environment::get().getMechanicsManager(); diff --git a/apps/openmw/mwmechanics/aitravel.hpp b/apps/openmw/mwmechanics/aitravel.hpp index 43b6c9d16c..beaf2819fe 100644 --- a/apps/openmw/mwmechanics/aitravel.hpp +++ b/apps/openmw/mwmechanics/aitravel.hpp @@ -1,7 +1,7 @@ #ifndef GAME_MWMECHANICS_AITRAVEL_H #define GAME_MWMECHANICS_AITRAVEL_H -#include "aipackage.hpp" +#include "typedaipackage.hpp" namespace ESM { @@ -14,7 +14,7 @@ namespace AiSequence namespace MWMechanics { /// \brief Causes the AI to travel to the specified point - class AiTravel final : public AiPackage + class AiTravel final : public TypedAiPackage { public: /// Default constructor @@ -26,8 +26,6 @@ namespace MWMechanics void writeState(ESM::AiSequence::AiSequence &sequence) const final; - AiTravel *clone() const final; - bool execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) final; int getTypeId() const final; diff --git a/apps/openmw/mwmechanics/aiwander.cpp b/apps/openmw/mwmechanics/aiwander.cpp index 2c40c1ba5e..50a46432b0 100644 --- a/apps/openmw/mwmechanics/aiwander.cpp +++ b/apps/openmw/mwmechanics/aiwander.cpp @@ -115,11 +115,6 @@ namespace MWMechanics mDuration = 0; } - AiPackage * MWMechanics::AiWander::clone() const - { - return new AiWander(*this); - } - /* * AiWander high level states (0.29.0). Not entirely accurate in some cases * e.g. non-NPC actors do not greet and some creatures may be moving even in diff --git a/apps/openmw/mwmechanics/aiwander.hpp b/apps/openmw/mwmechanics/aiwander.hpp index f6e7f6d0c0..bb5872eef2 100644 --- a/apps/openmw/mwmechanics/aiwander.hpp +++ b/apps/openmw/mwmechanics/aiwander.hpp @@ -1,7 +1,7 @@ #ifndef GAME_MWMECHANICS_AIWANDER_H #define GAME_MWMECHANICS_AIWANDER_H -#include "aipackage.hpp" +#include "typedaipackage.hpp" #include @@ -78,7 +78,7 @@ namespace MWMechanics }; /// \brief Causes the Actor to wander within a specified range - class AiWander final : public AiPackage + class AiWander final : public TypedAiPackage { public: /// Constructor @@ -91,8 +91,6 @@ namespace MWMechanics AiWander (const ESM::AiSequence::AiWander* wander); - AiPackage *clone() const final; - bool execute(const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) final; int getTypeId() const final; diff --git a/apps/openmw/mwmechanics/typedaipackage.hpp b/apps/openmw/mwmechanics/typedaipackage.hpp new file mode 100644 index 0000000000..2801accc4c --- /dev/null +++ b/apps/openmw/mwmechanics/typedaipackage.hpp @@ -0,0 +1,18 @@ +#ifndef GAME_MWMECHANICS_TYPEDAIPACKAGE_H +#define GAME_MWMECHANICS_TYPEDAIPACKAGE_H + +#include "aipackage.hpp" + +namespace MWMechanics +{ + template + struct TypedAiPackage : public AiPackage + { + virtual TypedAiPackage *clone() const override + { + return new T(*static_cast(this)); + } + }; +} + +#endif