From 743933134d30bca4e693349a7cb844b9c34531e8 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 14 Jul 2018 01:00:27 +0300 Subject: [PATCH] [Client] Simplify sending of ActorAI packets for uninitialized actors --- apps/openmw/mwmp/ActorList.cpp | 28 +++++++++++++++++ apps/openmw/mwmp/ActorList.hpp | 1 + apps/openmw/mwmp/DedicatedActor.cpp | 4 +-- apps/openmw/mwscript/aiextensions.cpp | 44 ++------------------------- 4 files changed, 33 insertions(+), 44 deletions(-) diff --git a/apps/openmw/mwmp/ActorList.cpp b/apps/openmw/mwmp/ActorList.cpp index 6e0fa5125..46787c132 100644 --- a/apps/openmw/mwmp/ActorList.cpp +++ b/apps/openmw/mwmp/ActorList.cpp @@ -2,6 +2,9 @@ #include "Main.hpp" #include "Networking.hpp" #include "LocalPlayer.hpp" +#include "MechanicsHelper.hpp" + +#include "../mwworld/class.hpp" #include @@ -84,6 +87,31 @@ void ActorList::addAiActor(BaseActor baseActor) aiActors.push_back(baseActor); } +void ActorList::addAiActor(const MWWorld::Ptr& actorPtr, const MWWorld::Ptr& targetPtr, unsigned int aiAction) +{ + mwmp::BaseActor baseActor; + baseActor.refNum = actorPtr.getCellRef().getRefNum().mIndex; + baseActor.mpNum = actorPtr.getCellRef().getMpNum(); + baseActor.aiAction = aiAction; + baseActor.aiTarget = MechanicsHelper::getTarget(targetPtr); + + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Preparing to send ID_ACTOR_AI about %s %i-%i\n- action: %i", + actorPtr.getCellRef().getRefId().c_str(), baseActor.refNum, baseActor.mpNum, aiAction); + + if (baseActor.aiTarget.isPlayer) + { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "- Has player target %s", + targetPtr.getClass().getName(targetPtr).c_str()); + } + else + { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "- Has actor target %s %i-%i", + targetPtr.getCellRef().getRefId().c_str(), baseActor.aiTarget.refNum, baseActor.aiTarget.mpNum); + } + + addAiActor(baseActor); +} + void ActorList::addAttackActor(BaseActor baseActor) { attackActors.push_back(baseActor); diff --git a/apps/openmw/mwmp/ActorList.hpp b/apps/openmw/mwmp/ActorList.hpp index ed1b3bf96..4290f8d07 100644 --- a/apps/openmw/mwmp/ActorList.hpp +++ b/apps/openmw/mwmp/ActorList.hpp @@ -28,6 +28,7 @@ namespace mwmp void addDeathActor(BaseActor baseActor); void addEquipmentActor(BaseActor baseActor); void addAiActor(BaseActor baseActor); + void addAiActor(const MWWorld::Ptr& actorPtr, const MWWorld::Ptr& targetPtr, unsigned int aiAction); void addAttackActor(BaseActor baseActor); void addCellChangeActor(BaseActor baseActor); diff --git a/apps/openmw/mwmp/DedicatedActor.cpp b/apps/openmw/mwmp/DedicatedActor.cpp index 29788317b..9a118176b 100644 --- a/apps/openmw/mwmp/DedicatedActor.cpp +++ b/apps/openmw/mwmp/DedicatedActor.cpp @@ -265,12 +265,12 @@ void DedicatedActor::setAi() if (targetPtr) { - LOG_APPEND(Log::LOG_VERBOSE, "-- Has AI target %s %i-%i", + LOG_APPEND(Log::LOG_VERBOSE, "-- Has actor target %s %i-%i", targetPtr.getCellRef().getRefId().c_str(), aiTarget.refNum, aiTarget.mpNum); } else { - LOG_APPEND(Log::LOG_VERBOSE, "-- Has invalid target AI target %i-%i", + LOG_APPEND(Log::LOG_VERBOSE, "-- Has invalid actor target %i-%i", aiTarget.refNum, aiTarget.mpNum); } diff --git a/apps/openmw/mwscript/aiextensions.cpp b/apps/openmw/mwscript/aiextensions.cpp index b2d344bae..b240f9781 100644 --- a/apps/openmw/mwscript/aiextensions.cpp +++ b/apps/openmw/mwscript/aiextensions.cpp @@ -344,30 +344,10 @@ namespace MWScript if (targetPtr) { - mwmp::BaseActor baseActor; - baseActor.refNum = 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().c_str(), baseActor.refNum, 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().c_str(), baseActor.aiTarget.refNum, baseActor.aiTarget.mpNum); - } - mwmp::ActorList *actorList = mwmp::Main::get().getNetworking()->getActorList(); actorList->reset(); actorList->cell = *ptr.getCell()->getCell(); - actorList->addAiActor(baseActor); + actorList->addAiActor(ptr, targetPtr, mwmp::BaseActorList::FOLLOW); actorList->sendAiActors(); } /* @@ -517,30 +497,10 @@ namespace MWScript */ if (target) { - mwmp::BaseActor baseActor; - baseActor.refNum = actor.getCellRef().getRefNum().mIndex; - baseActor.mpNum = actor.getCellRef().getMpNum(); - baseActor.aiAction = mwmp::BaseActorList::COMBAT; - baseActor.aiTarget = MechanicsHelper::getTarget(target); - - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Sending ID_ACTOR_AI about %s %i-%i to server", - actor.getCellRef().getRefId().c_str(), baseActor.refNum, baseActor.mpNum); - - if (baseActor.aiTarget.isPlayer) - { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "- Starting combat with player %s", - target.getClass().getName(target).c_str()); - } - else - { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "- Starting combat with actor %s %i-%i", - target.getCellRef().getRefId().c_str(), baseActor.aiTarget.refNum, baseActor.aiTarget.mpNum); - } - mwmp::ActorList *actorList = mwmp::Main::get().getNetworking()->getActorList(); actorList->reset(); actorList->cell = *actor.getCell()->getCell(); - actorList->addAiActor(baseActor); + actorList->addAiActor(actor, target, mwmp::BaseActorList::COMBAT); actorList->sendAiActors(); } /*