From 5fd411397888b14f5a9e132e22f9e9c8ff08912e Mon Sep 17 00:00:00 2001 From: David Cernat Date: Mon, 13 Aug 2018 20:39:03 +0300 Subject: [PATCH] [General] Implement sending of ActorSpeech packets from server scripts --- apps/openmw-mp/Script/Functions/Actors.cpp | 24 ++++++++++++++++++++ apps/openmw-mp/Script/Functions/Actors.hpp | 22 ++++++++++++++++++ apps/openmw-mp/Script/Functions/Dialogue.hpp | 2 +- apps/openmw/mwmp/Cell.cpp | 2 ++ 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/apps/openmw-mp/Script/Functions/Actors.cpp b/apps/openmw-mp/Script/Functions/Actors.cpp index 9eba137ee..909d8a3e6 100644 --- a/apps/openmw-mp/Script/Functions/Actors.cpp +++ b/apps/openmw-mp/Script/Functions/Actors.cpp @@ -311,6 +311,11 @@ void ActorFunctions::SetActorFatigueModified(double value) noexcept tempActor.creatureStats.mDynamic[2].mMod = value; } +void ActorFunctions::SetActorSound(const char* sound) noexcept +{ + tempActor.sound = sound; +} + void ActorFunctions::SetActorAIAction(unsigned int action) noexcept { tempActor.aiAction = action; @@ -459,6 +464,25 @@ void ActorFunctions::SendActorEquipment(bool sendToOtherVisitors, bool skipAttac } } +void ActorFunctions::SendActorSpeech(bool sendToOtherVisitors, bool skipAttachedPlayer) noexcept +{ + mwmp::ActorPacket *actorPacket = mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_SPEECH); + actorPacket->setActorList(&writeActorList); + + if (!skipAttachedPlayer) + actorPacket->Send(writeActorList.guid); + + if (sendToOtherVisitors) + { + Cell *serverCell = CellController::get()->getCell(&writeActorList.cell); + + if (serverCell != nullptr) + { + serverCell->sendToLoaded(actorPacket, &writeActorList); + } + } +} + void ActorFunctions::SendActorAI(bool sendToOtherVisitors, bool skipAttachedPlayer) noexcept { mwmp::ActorPacket *actorPacket = mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_AI); diff --git a/apps/openmw-mp/Script/Functions/Actors.hpp b/apps/openmw-mp/Script/Functions/Actors.hpp index 0a9204ef5..a6035e9da 100644 --- a/apps/openmw-mp/Script/Functions/Actors.hpp +++ b/apps/openmw-mp/Script/Functions/Actors.hpp @@ -71,6 +71,8 @@ {"SetActorFatigueCurrent", ActorFunctions::SetActorFatigueCurrent},\ {"SetActorFatigueModified", ActorFunctions::SetActorFatigueModified},\ \ + {"SetActorSound", ActorFunctions::SetActorSound},\ + \ {"SetActorAIAction", ActorFunctions::SetActorAIAction},\ {"SetActorAITargetToPlayer", ActorFunctions::SetActorAITargetToPlayer},\ {"SetActorAITargetToObject", ActorFunctions::SetActorAITargetToObject},\ @@ -89,6 +91,7 @@ {"SendActorPosition", ActorFunctions::SendActorPosition},\ {"SendActorStatsDynamic", ActorFunctions::SendActorStatsDynamic},\ {"SendActorEquipment", ActorFunctions::SendActorEquipment},\ + {"SendActorSpeech", ActorFunctions::SendActorSpeech},\ {"SendActorAI", ActorFunctions::SendActorAI},\ {"SendActorCellChange", ActorFunctions::SendActorCellChange},\ \ @@ -570,6 +573,14 @@ public: */ static void SetActorFatigueModified(double value) noexcept; + /** + * \brief Set the sound of the temporary actor stored on the server. + * + * \param sound The sound. + * \return void + */ + static void SetActorSound(const char* sound) noexcept; + /** * \brief Set the AI action of the temporary actor stored on the server. * @@ -720,6 +731,17 @@ public: */ static void SendActorEquipment(bool sendToOtherVisitors, bool skipAttachedPlayer) noexcept; + /** + * \brief Send an ActorSpeech packet. + * + * \param sendToOtherVisitors Whether this packet should be sent to cell visitors other + * than the player attached to the packet (false by default). + * \param skipAttachedPlayer Whether the packet should skip being sent to the player attached + * to the packet (false by default). + * \return void + */ + static void SendActorSpeech(bool sendToOtherVisitors, bool skipAttachedPlayer) noexcept; + /** * \brief Send an ActorAI packet. * diff --git a/apps/openmw-mp/Script/Functions/Dialogue.hpp b/apps/openmw-mp/Script/Functions/Dialogue.hpp index f31e94fe6..63bf4a2b2 100644 --- a/apps/openmw-mp/Script/Functions/Dialogue.hpp +++ b/apps/openmw-mp/Script/Functions/Dialogue.hpp @@ -82,7 +82,7 @@ public: /** * \brief Play a certain sound for a player as spoken by their character by sending - * a PlayerSound packet. + * a PlayerSpeech packet. * * \param pid The player ID of the character playing the sound. * \param sound The path of the sound file. diff --git a/apps/openmw/mwmp/Cell.cpp b/apps/openmw/mwmp/Cell.cpp index a8884842b..6b3813f3e 100644 --- a/apps/openmw/mwmp/Cell.cpp +++ b/apps/openmw/mwmp/Cell.cpp @@ -233,6 +233,8 @@ void Cell::readEquipment(ActorList& actorList) void Cell::readSpeech(ActorList& actorList) { + initializeDedicatedActors(actorList); + for (const auto &baseActor : actorList.baseActors) { std::string mapIndex = Main::get().getCellController()->generateMapIndex(baseActor);