From f0d4f1bbe5533c63ed927c02a2835afbec9aa391 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Thu, 12 Jul 2018 23:08:17 +0300 Subject: [PATCH] [Client] Send ActorAI packets when followed by an NPC The packet is sent regardless of whether we are the cell authority or not, so the server can decide what it wants to do with it. --- apps/openmw/mwscript/aiextensions.cpp | 55 +++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/apps/openmw/mwscript/aiextensions.cpp b/apps/openmw/mwscript/aiextensions.cpp index c51a55b50..b48a94e1a 100644 --- a/apps/openmw/mwscript/aiextensions.cpp +++ b/apps/openmw/mwscript/aiextensions.cpp @@ -3,6 +3,20 @@ #include #include +/* + Start of tes3mp addition + + Include additional headers for multiplayer purposes +*/ +#include +#include "../mwmp/Main.hpp" +#include "../mwmp/Networking.hpp" +#include "../mwmp/ActorList.hpp" +#include "../mwmp/MechanicsHelper.hpp" +/* + End of tes3mp addition +*/ + #include #include @@ -318,6 +332,47 @@ namespace MWScript std::cout << "AiFollow: " << actorID << ", " << x << ", " << y << ", " << z << ", " << duration << std::endl; + + /* + Start of tes3mp addition + + Send ActorAI packets when an actor follows us, regardless of whether we're the cell + authority or not; the server can decide if it wants to comply with them by forwarding + them to the cell authority + */ + MWWorld::Ptr targetPtr = MWBase::Environment::get().getWorld()->searchPtr(actorID, true); + + if (targetPtr) + { + mwmp::BaseActor baseActor; + baseActor.refNumIndex = ptr.getCellRef().getRefNum().mIndex; + baseActor.mpNum = ptr.getCellRef().getMpNum(); + baseActor.aiAction = mwmp::BaseActorList::FOLLOW; + baseActor.aiTarget = MechanicsHelper::getTarget(targetPtr); + + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Sending ID_ACTOR_AI about %s %i-%i to server", + ptr.getCellRef().getRefId(), baseActor.refNumIndex, baseActor.mpNum); + + if (baseActor.aiTarget.isPlayer) + { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "- Following player %s", + targetPtr.getClass().getName(targetPtr).c_str()); + } + else + { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "- Following actor %s %i-%i", + targetPtr.getCellRef().getRefId(), baseActor.aiTarget.refNumIndex, baseActor.aiTarget.mpNum); + } + + mwmp::ActorList *actorList = mwmp::Main::get().getNetworking()->getActorList(); + actorList->reset(); + actorList->cell = *ptr.getCell()->getCell(); + actorList->addAiActor(baseActor); + actorList->sendAiActors(); + } + /* + End of tes3mp addition + */ } };