From c984fc0881ce9e63641d882a4ba3784e175ad473 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Tue, 10 Jul 2018 08:21:24 +0300 Subject: [PATCH] [Client] Allow AiActivate to be used with specific Ptrs, not just refIds --- apps/openmw/mwmechanics/aiactivate.cpp | 24 +++++++++++++++++++- apps/openmw/mwmechanics/aiactivate.hpp | 31 ++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwmechanics/aiactivate.cpp b/apps/openmw/mwmechanics/aiactivate.cpp index d38a1299f..1677e56f2 100644 --- a/apps/openmw/mwmechanics/aiactivate.cpp +++ b/apps/openmw/mwmechanics/aiactivate.cpp @@ -18,6 +18,20 @@ namespace MWMechanics { } + /* + Start of tes3mp addition + + Allow AiActivate to be initialized using a Ptr instead of a refId + */ + AiActivate::AiActivate(MWWorld::Ptr object) + : mObjectId("") + { + mObjectPtr = object; + } + /* + End of tes3mp addition + */ + AiActivate *MWMechanics::AiActivate::clone() const { return new AiActivate(*this); @@ -25,7 +39,15 @@ namespace MWMechanics 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 + /* + Start of tes3mp change (major) + + Only search for an object based on its refId if we haven't provided a specific object already + */ + const MWWorld::Ptr target = mObjectId.empty() ? mObjectPtr : MWBase::Environment::get().getWorld()->searchPtr(mObjectId, false); + /* + End of tes3mp change (major) + */ actor.getClass().getCreatureStats(actor).setDrawState(DrawState_Nothing); diff --git a/apps/openmw/mwmechanics/aiactivate.hpp b/apps/openmw/mwmechanics/aiactivate.hpp index 8de4be69f..d85c377c6 100644 --- a/apps/openmw/mwmechanics/aiactivate.hpp +++ b/apps/openmw/mwmechanics/aiactivate.hpp @@ -3,6 +3,16 @@ #include "aipackage.hpp" +/* + Start of tes3mp addition + + Include additional headers for multiplayer purposes +*/ +#include "../mwworld/ptr.hpp" +/* + End of tes3mp addition +*/ + #include #include "pathfinding.hpp" @@ -26,6 +36,17 @@ namespace MWMechanics /** \param objectId Reference to object to activate **/ AiActivate(const std::string &objectId); + /* + Start of tes3mp addition + + Make it possible to initialize an AiActivate package with a specific Ptr + as the target, allowing for more fine-tuned activation of objects + */ + AiActivate(MWWorld::Ptr object); + /* + End of tes3mp addition + */ + AiActivate(const ESM::AiSequence::AiActivate* activate); virtual AiActivate *clone() const; @@ -36,6 +57,16 @@ namespace MWMechanics private: std::string mObjectId; + + /* + Start of tes3mp addition + + Track the object associated with this AiActivate package + */ + MWWorld::Ptr mObjectPtr; + /* + End of tes3mp addition + */ }; } #endif // GAME_MWMECHANICS_AIACTIVATE_H