diff --git a/apps/openmw-mp/Script/Functions/Translocations.cpp b/apps/openmw-mp/Script/Functions/Translocations.cpp index 704801ef2..f34c48cd0 100644 --- a/apps/openmw-mp/Script/Functions/Translocations.cpp +++ b/apps/openmw-mp/Script/Functions/Translocations.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include using namespace std; @@ -65,19 +66,20 @@ void TranslocationFunctions::SetCell(unsigned short pid, const char *name) noexc Player *player; GET_PLAYER(pid, player,); - /*if (player->GetCell()->mName == name) - return;*/ + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Script is moving %s from %s to %s", + player->Npc()->mName.c_str(), + player->GetCell()->getDescription().c_str(), + name); - cout << "attempt to move player (pid: " << pid << " name: " << player->Npc()->mName << ") from "; - if (!player->GetCell()->isExterior()) - cout << "\"" << player->GetCell()->mName << "\""; - else - cout << "exterior"; + // If the player is currently in an exterior, turn on the interior flag + // from the cell so the player doesn't get teleported to their exterior + // grid position (which we haven't changed) + if (player->GetCell()->isExterior()) { + player->GetCell()->mData.mFlags |= ESM::Cell::Interior; + } player->GetCell()->mName = name; - cout << " in to cell \"" << player->GetCell()->mName << "\"" << endl; - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_CELL)->Send(player, false); } @@ -94,14 +96,18 @@ void TranslocationFunctions::SetExterior(unsigned short pid, int x, int y) noexc Player *player; GET_PLAYER(pid, player,); - cout << "attempt to move player (pid: " << pid << " name: " << player->Npc()->mName << ") from "; - if (!player->GetCell()->isExterior()) - cout << "\"" << player->GetCell()->mName << "\""; - else - cout << "exterior: " << player->GetCell()->mCellId.mIndex.mX << ", " << player->GetCell()->mCellId.mIndex.mY; - cout << " in to exterior cell \"" << x << ", " << y << "\"" << endl; + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Script is moving %s from %s to %i,%i", + player->Npc()->mName.c_str(), + player->GetCell()->getDescription().c_str(), + x, + y); + + // If the player is currently in an interior, turn off the interior flag + // from the cell + if (!player->GetCell()->isExterior()) { + player->GetCell()->mData.mFlags &= ~ESM::Cell::Interior; + } - player->GetCell()->mName = ""; player->GetCell()->mCellId.mIndex.mX = x; player->GetCell()->mCellId.mIndex.mY = y; @@ -122,12 +128,12 @@ int TranslocationFunctions::GetExteriorY(unsigned short pid) noexcept return player->GetCell()->mCellId.mIndex.mY; } -bool TranslocationFunctions::IsInInterior(unsigned short pid) noexcept +bool TranslocationFunctions::IsInExterior(unsigned short pid) noexcept { Player *player; GET_PLAYER(pid, player, false); - return !player->GetCell()->isExterior(); + return player->GetCell()->isExterior(); } void TranslocationFunctions::GetAngle(unsigned short pid, float *x, float *y, float *z) noexcept diff --git a/apps/openmw-mp/Script/Functions/Translocations.hpp b/apps/openmw-mp/Script/Functions/Translocations.hpp index c8ec560cd..b82ba1080 100644 --- a/apps/openmw-mp/Script/Functions/Translocations.hpp +++ b/apps/openmw-mp/Script/Functions/Translocations.hpp @@ -25,7 +25,7 @@ {"SetExterior", TranslocationFunctions::SetExterior},\ {"GetExteriorX", TranslocationFunctions::GetExteriorX},\ {"GetExteriorY", TranslocationFunctions::GetExteriorY},\ - {"IsInInterior", TranslocationFunctions::IsInInterior} + {"IsInExterior", TranslocationFunctions::IsInExterior} class TranslocationFunctions @@ -37,7 +37,6 @@ public: static double GetPosZ(unsigned short pid) noexcept; static void SetPos(unsigned short pid, double x, double y, double z) noexcept; - static void GetAngle(unsigned short pid, float *x, float *y, float *z) noexcept; static double GetAngleX(unsigned short pid) noexcept; static double GetAngleY(unsigned short pid) noexcept; @@ -51,7 +50,7 @@ public: static int GetExteriorX(unsigned short pid) noexcept; static int GetExteriorY(unsigned short pid) noexcept; - static bool IsInInterior(unsigned short pid) noexcept; + static bool IsInExterior(unsigned short pid) noexcept; }; #endif //OPENMW_TRANSLOCATIONS_HPP diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index d7e0a6fef..4a68f3f6d 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -201,7 +201,7 @@ void LocalPlayer::setCell() int y = GetCell()->mCellId.mIndex.mY; ESM::CellId curCell = player.mCell->getCell()->mCellId; - if (GetCell()->mName.empty()) + if (GetCell()->isExterior()) { world->indexToPosition(x, y, pos.pos[0], pos.pos[1], true); pos.pos[2] = 0; @@ -416,8 +416,7 @@ void LocalPlayer::updateCell(bool forceUpdate) shouldUpdate = true; } else if (_cell->isExterior()) - { - + { if (_cell->mCellId.mIndex.mX != GetCell()->mCellId.mIndex.mX) { shouldUpdate = true; @@ -439,7 +438,8 @@ void LocalPlayer::updateCell(bool forceUpdate) (*GetCell()) = *_cell; isExterior = _cell->isExterior(); - // Make sure the position is updated before a cell packet is sent + // Make sure the position is updated before a cell packet is sent, or else + // cell change events in server scripts will have the wrong player position updatePosition(true); RakNet::BitStream bs; diff --git a/components/openmw-mp/Packets/PacketCell.cpp b/components/openmw-mp/Packets/PacketCell.cpp index e37d36275..ce23c033e 100644 --- a/components/openmw-mp/Packets/PacketCell.cpp +++ b/components/openmw-mp/Packets/PacketCell.cpp @@ -19,7 +19,6 @@ void mwmp::PacketCell::Packet(RakNet::BitStream *bs, mwmp::BasePlayer *player, b RW(player->GetCell()->mData.mFlags, send); - RW(player->GetCell()->mCellId.mIndex.mX, send); RW(player->GetCell()->mCellId.mIndex.mY, send);