diff --git a/apps/openmw-mp/Script/Functions/Cells.cpp b/apps/openmw-mp/Script/Functions/Cells.cpp index aed41528f..d3000e186 100644 --- a/apps/openmw-mp/Script/Functions/Cells.cpp +++ b/apps/openmw-mp/Script/Functions/Cells.cpp @@ -105,6 +105,22 @@ bool CellFunctions::IsInExterior(unsigned short pid) noexcept return player->cell.isExterior(); } +const char *CellFunctions::GetRegion(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player, 0); + + return player->cell.mRegion.c_str(); +} + +bool CellFunctions::IsChangingRegion(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player, false); + + return player->isChangingRegion; +} + void CellFunctions::SendCell(unsigned short pid) noexcept { Player *player; diff --git a/apps/openmw-mp/Script/Functions/Cells.hpp b/apps/openmw-mp/Script/Functions/Cells.hpp index 3110cb1d3..69b0fcf13 100644 --- a/apps/openmw-mp/Script/Functions/Cells.hpp +++ b/apps/openmw-mp/Script/Functions/Cells.hpp @@ -16,6 +16,9 @@ {"GetExteriorY", CellFunctions::GetExteriorY},\ {"IsInExterior", CellFunctions::IsInExterior},\ \ + {"GetRegion", CellFunctions::GetRegion},\ + {"IsChangingRegion", CellFunctions::IsChangingRegion},\ + \ {"SendCell", CellFunctions::SendCell} @@ -34,6 +37,9 @@ public: static int GetExteriorY(unsigned short pid) noexcept; static bool IsInExterior(unsigned short pid) noexcept; + static const char *GetRegion(unsigned short pid) noexcept; + static bool IsChangingRegion(unsigned short pid) noexcept; + static void SendCell(unsigned short pid) noexcept; }; diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 987f25c71..5d3116435 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -52,6 +52,7 @@ LocalPlayer::LocalPlayer() attack.shouldSend = false; deathReason = "suicide"; + isChangingRegion = false; } LocalPlayer::~LocalPlayer() @@ -363,6 +364,15 @@ void LocalPlayer::updateCell(bool forceUpdate) LOG_APPEND(Log::LOG_INFO, "- Moved from %s to %s", cell.getDescription().c_str(), ptrCell->getDescription().c_str()); + if (!Misc::StringUtils::ciEqual(cell.mRegion, ptrCell->mRegion)) + { + LOG_APPEND(Log::LOG_INFO, "- Changed region from %s to %s", + cell.mRegion.empty() ? "none" : cell.mRegion.c_str(), + ptrCell->mRegion.empty() ? "none" : ptrCell->mRegion.c_str()); + + isChangingRegion = true; + } + cell = *ptrCell; // Make sure the position is updated before a cell packet is sent, or else @@ -372,6 +382,8 @@ void LocalPlayer::updateCell(bool forceUpdate) getNetworking()->getPlayerPacket(ID_PLAYER_CELL_CHANGE)->setPlayer(this); getNetworking()->getPlayerPacket(ID_PLAYER_CELL_CHANGE)->Send(); + isChangingRegion = false; + // Also force an update to skills (to send all progress to skill increases) updateSkills(true); diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index 51ccb63f9..a7282ed75 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -199,6 +199,8 @@ namespace mwmp std::string creatureModel; bool useCreatureName; + bool isChangingRegion; + std::string deathReason; }; } diff --git a/components/openmw-mp/Packets/Actor/ActorPacket.cpp b/components/openmw-mp/Packets/Actor/ActorPacket.cpp index 6acb2d67c..ed0b703b8 100644 --- a/components/openmw-mp/Packets/Actor/ActorPacket.cpp +++ b/components/openmw-mp/Packets/Actor/ActorPacket.cpp @@ -35,7 +35,7 @@ void ActorPacket::Packet(RakNet::BitStream *bs, bool send) for (unsigned int i = 0; i < actorList->count; i++) { if (send) - actor = actorList->baseActors[i]; + actor = actorList->baseActors.at(i); RW(actor.refNumIndex, send); RW(actor.mpNum, send); diff --git a/components/openmw-mp/Packets/Player/PacketPlayerCellChange.cpp b/components/openmw-mp/Packets/Player/PacketPlayerCellChange.cpp index 665ce7d7d..acc5415df 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerCellChange.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerCellChange.cpp @@ -19,4 +19,9 @@ void mwmp::PacketPlayerCellChange::Packet(RakNet::BitStream *bs, bool send) RW(player->cell.mData, send, 1); RW(player->cell.mName, send, 1); + + RW(player->isChangingRegion, send); + + if (player->isChangingRegion) + RW(player->cell.mRegion, send, 1); }