diff --git a/apps/openmw-mp/Script/Functions/Mechanics.cpp b/apps/openmw-mp/Script/Functions/Mechanics.cpp index d4ddcef87..2635748bc 100644 --- a/apps/openmw-mp/Script/Functions/Mechanics.cpp +++ b/apps/openmw-mp/Script/Functions/Mechanics.cpp @@ -92,6 +92,22 @@ bool MechanicsFunctions::IsWerewolf(unsigned short pid) noexcept return player->isWerewolf; } +const char *MechanicsFunctions::GetCreatureRefId(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player, 0); + + return player->creatureRefId.c_str(); +} + +bool MechanicsFunctions::DisplaysCreatureName(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player, 0); + + return player->displayCreatureName; +} + void MechanicsFunctions::SetMarkCell(unsigned short pid, const char *cellDescription) noexcept { Player *player; @@ -143,6 +159,15 @@ void MechanicsFunctions::SetWerewolfState(unsigned short pid, bool isWerewolf) n player->isWerewolf = isWerewolf; } +void MechanicsFunctions::SetCreatureRefId(unsigned short pid, const char *refId, bool displayCreatureName) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + player->creatureRefId = refId; + player->displayCreatureName = displayCreatureName; +} + void MechanicsFunctions::SendMarkLocation(unsigned short pid) { Player *player; diff --git a/apps/openmw-mp/Script/Functions/Mechanics.hpp b/apps/openmw-mp/Script/Functions/Mechanics.hpp index f0e3e13d3..0ab87c303 100644 --- a/apps/openmw-mp/Script/Functions/Mechanics.hpp +++ b/apps/openmw-mp/Script/Functions/Mechanics.hpp @@ -16,6 +16,8 @@ \ {"GetScale", MechanicsFunctions::GetScale},\ {"IsWerewolf", MechanicsFunctions::IsWerewolf},\ + {"GetCreatureRefId", MechanicsFunctions::GetCreatureRefId},\ + {"DisplaysCreatureName", MechanicsFunctions::DisplaysCreatureName},\ \ {"SetMarkCell", MechanicsFunctions::SetMarkCell},\ {"SetMarkPos", MechanicsFunctions::SetMarkPos},\ @@ -24,6 +26,7 @@ \ {"SetScale", MechanicsFunctions::SetScale},\ {"SetWerewolfState", MechanicsFunctions::SetWerewolfState},\ + {"SetCreatureRefId", MechanicsFunctions::SetCreatureRefId},\ \ {"SendMarkLocation", MechanicsFunctions::SendMarkLocation},\ {"SendSelectedSpell", MechanicsFunctions::SendSelectedSpell},\ @@ -118,6 +121,25 @@ public: */ static bool IsWerewolf(unsigned short pid) noexcept; + /** + * \brief Get the refId of the creature the player is disguised as. + * + * \param pid The player ID. + * \return The creature refId. + */ + static const char *GetCreatureRefId(unsigned short pid) noexcept; + + /** + * \brief Check whether a player's name is replaced by that of the creature they are + * disguised as when other players hover over them. + * + * This is based on the last PlayerShapeshift packet received or sent for that player. + * + * \param pid The player ID. + * \return The creature name display state. + */ + static bool DisplaysCreatureName(unsigned short pid) noexcept; + /** * \brief Set the Mark cell of a player. * @@ -196,6 +218,20 @@ public: */ static void SetWerewolfState(unsigned short pid, bool isWerewolf) noexcept; + /** + * \brief Set the refId of the creature a player is disguised as. + * + * This changes the creature refId recorded for that player in the server memory, but + * does not by itself send a packet. + * + * \param pid The player ID. + * \param refId The creature refId. + * \param displaysCreatureName Whether the player's name appears as that of the creature + * when hovered over by others. + * \return void + */ + static void SetCreatureRefId(unsigned short pid, const char *refId, bool displayCreatureName) noexcept; + /** * \brief Send a PlayerMiscellaneous packet with a Mark location to a player. * diff --git a/apps/openmw-mp/Script/Functions/Stats.cpp b/apps/openmw-mp/Script/Functions/Stats.cpp index 141425246..32b22144a 100644 --- a/apps/openmw-mp/Script/Functions/Stats.cpp +++ b/apps/openmw-mp/Script/Functions/Stats.cpp @@ -118,22 +118,6 @@ const char *StatsFunctions::GetBirthsign(unsigned short pid) noexcept return player->birthsign.c_str(); } -const char *StatsFunctions::GetCreatureModel(unsigned short pid) noexcept -{ - Player *player; - GET_PLAYER(pid, player, 0); - - return player->creatureModel.c_str(); -} - -bool StatsFunctions::IsCreatureName(unsigned short pid) noexcept -{ - Player *player; - GET_PLAYER(pid, player, 0); - - return player->useCreatureName; -} - const char *StatsFunctions::GetDeathReason(unsigned short pid) noexcept { Player *player; @@ -346,16 +330,6 @@ void StatsFunctions::SetBirthsign(unsigned short pid, const char *sign) noexcept player->birthsign = sign; } -void StatsFunctions::SetCreatureModel(unsigned short pid, const char *name, bool useCreatureName) noexcept -{ - Player *player; - GET_PLAYER(pid, player, ); - - player->creatureModel = name; - player->useCreatureName = useCreatureName; - -} - void StatsFunctions::SetLevel(unsigned short pid, int value) noexcept { Player *player; diff --git a/apps/openmw-mp/Script/Functions/Stats.hpp b/apps/openmw-mp/Script/Functions/Stats.hpp index ff2421ef7..3d0da464d 100644 --- a/apps/openmw-mp/Script/Functions/Stats.hpp +++ b/apps/openmw-mp/Script/Functions/Stats.hpp @@ -19,8 +19,6 @@ {"GetHair", StatsFunctions::GetHairstyle},\ {"GetIsMale", StatsFunctions::GetIsMale},\ {"GetBirthsign", StatsFunctions::GetBirthsign},\ - {"GetCreatureModel", StatsFunctions::GetCreatureModel},\ - {"IsCreatureName", StatsFunctions::IsCreatureName},\ {"GetDeathReason", StatsFunctions::GetDeathReason},\ \ {"GetLevel", StatsFunctions::GetLevel},\ @@ -51,7 +49,6 @@ {"SetHair", StatsFunctions::SetHairstyle},\ {"SetIsMale", StatsFunctions::SetIsMale},\ {"SetBirthsign", StatsFunctions::SetBirthsign},\ - {"SetCreatureModel", StatsFunctions::SetCreatureModel},\ \ {"SetLevel", StatsFunctions::SetLevel},\ {"SetLevelProgress", StatsFunctions::SetLevelProgress},\ @@ -98,8 +95,6 @@ public: static const char *GetHairstyle(unsigned short pid) noexcept; static int GetIsMale(unsigned short pid) noexcept; static const char *GetBirthsign(unsigned short pid) noexcept; - static const char *GetCreatureModel(unsigned short pid) noexcept; - static bool IsCreatureName(unsigned short pid) noexcept; static const char *GetDeathReason(unsigned short pid) noexcept; static int GetLevel(unsigned short pid) noexcept; @@ -128,7 +123,6 @@ public: static void SetHairstyle(unsigned short pid, const char *style) noexcept; static void SetIsMale(unsigned short pid, int male) noexcept; static void SetBirthsign(unsigned short pid, const char *name) noexcept; - static void SetCreatureModel(unsigned short pid, const char *name, bool useCreatureName) noexcept; static void SetLevel(unsigned short pid, int value) noexcept; static void SetLevelProgress(unsigned short pid, int value) noexcept; diff --git a/apps/openmw/mwmp/PlayerList.cpp b/apps/openmw/mwmp/PlayerList.cpp index 8c636a2de..f154938fa 100644 --- a/apps/openmw/mwmp/PlayerList.cpp +++ b/apps/openmw/mwmp/PlayerList.cpp @@ -44,21 +44,21 @@ void PlayerList::createPlayer(RakNet::RakNetGUID guid) ESM::Creature creature; ESM::NPC npc; - if (!dedicPlayer->creatureModel.empty()) + if (!dedicPlayer->creatureRefId.empty()) { - const ESM::Creature *tmpCreature = world->getStore().get().search(dedicPlayer->creatureModel); + const ESM::Creature *tmpCreature = world->getStore().get().search(dedicPlayer->creatureRefId); if (tmpCreature == 0) { - dedicPlayer->creatureModel = ""; + dedicPlayer->creatureRefId = ""; createPlayer(guid); return; } creature = *tmpCreature; creature.mScript = ""; - if (!dedicPlayer->useCreatureName) + if (!dedicPlayer->displayCreatureName) creature.mName = dedicPlayer->npc.mName; LOG_APPEND(Log::LOG_INFO, "Player %s looks like %s", dedicPlayer->npc.mName.c_str(), - dedicPlayer->creatureModel.c_str()); + dedicPlayer->creatureRefId.c_str()); } else { @@ -82,8 +82,8 @@ void PlayerList::createPlayer(RakNet::RakNetGUID guid) if (dedicPlayer->reference) { bool isNPC = dedicPlayer->reference->getPtr().getTypeName() == typeid(ESM::NPC).name(); - if ((!dedicPlayer->creatureModel.empty() && isNPC) || - (dedicPlayer->creatureModel.empty() && !isNPC)) + if ((!dedicPlayer->creatureRefId.empty() && isNPC) || + (dedicPlayer->creatureRefId.empty() && !isNPC)) { if (dedicPlayer->reference) { @@ -106,7 +106,7 @@ void PlayerList::createPlayer(RakNet::RakNetGUID guid) if (dedicPlayer->state == 0) { string recid; - if (dedicPlayer->creatureModel.empty()) + if (dedicPlayer->creatureRefId.empty()) { LOG_APPEND(Log::LOG_INFO, "- Creating new NPC record"); npc.mId = "Dedicated Player"; @@ -158,7 +158,7 @@ void PlayerList::createPlayer(RakNet::RakNetGUID guid) MWWorld::Store *creature_store = const_cast *> (&store->get()); MWWorld::Store *npc_store = const_cast *> (&store->get()); - if (!dedicPlayer->creatureModel.empty()) + if (!dedicPlayer->creatureRefId.empty()) { if (!npc.mId.empty() || npc.mId != "Dedicated Player") { diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index 717ddd266..0544f3fb1 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -224,7 +224,7 @@ namespace mwmp inventoryChanges.count = 0; spellbookChanges.action = 0; spellbookChanges.count = 0; - useCreatureName = false; + displayCreatureName = false; } BasePlayer() @@ -287,8 +287,9 @@ namespace mwmp float scale; bool isWerewolf; - std::string creatureModel; - bool useCreatureName; + + bool displayCreatureName; + std::string creatureRefId; bool isChangingRegion; diff --git a/components/openmw-mp/Packets/Player/PacketPlayerBaseInfo.cpp b/components/openmw-mp/Packets/Player/PacketPlayerBaseInfo.cpp index e026e5798..051c26e83 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerBaseInfo.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerBaseInfo.cpp @@ -25,7 +25,4 @@ void PacketPlayerBaseInfo::Packet(RakNet::BitStream *bs, bool send) RW(player->npc.mFlags, send); RW(player->birthsign, send, 1); - - RW(player->creatureModel, send, 1); - RW(player->useCreatureName, send); } diff --git a/components/openmw-mp/Packets/Player/PacketPlayerShapeshift.cpp b/components/openmw-mp/Packets/Player/PacketPlayerShapeshift.cpp index 352342ccd..a1757d20e 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerShapeshift.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerShapeshift.cpp @@ -14,4 +14,7 @@ void PacketPlayerShapeshift::Packet(RakNet::BitStream *bs, bool send) RW(player->scale, send); RW(player->isWerewolf, send); + + RW(player->displayCreatureName, send); + RW(player->creatureRefId, send, 1); }