diff --git a/apps/openmw/mwmp/CellController.cpp b/apps/openmw/mwmp/CellController.cpp index 7ed73a4f5..6ded044b2 100644 --- a/apps/openmw/mwmp/CellController.cpp +++ b/apps/openmw/mwmp/CellController.cpp @@ -302,6 +302,18 @@ MWWorld::CellStore *CellController::getCellStore(const ESM::Cell& cell) return cellStore; } +bool CellController::isSameCell(const ESM::Cell& cell, const ESM::Cell& otherCell) +{ + if (cell.isExterior() && otherCell.isExterior()) + { + if (cell.mData.mX == otherCell.mData.mX && cell.mData.mY == otherCell.mData.mY) + return true; + } + else if (Misc::StringUtils::ciEqual(cell.mName, otherCell.mName)) + return true; + + return false; +} void CellController::openContainer(const MWWorld::Ptr &container, bool loot) { diff --git a/apps/openmw/mwmp/CellController.hpp b/apps/openmw/mwmp/CellController.hpp index b9e47e66e..d1a799a1c 100644 --- a/apps/openmw/mwmp/CellController.hpp +++ b/apps/openmw/mwmp/CellController.hpp @@ -54,6 +54,8 @@ namespace mwmp virtual MWWorld::CellStore *getCellStore(const ESM::Cell& cell); + bool isSameCell(const ESM::Cell& cell, const ESM::Cell& otherCell); + void openContainer(const MWWorld::Ptr& container, bool loot); void closeContainer(const MWWorld::Ptr& container); diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 5bb9cd1e3..617bda3a0 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -336,34 +336,10 @@ void LocalPlayer::updateCell(bool forceUpdate) const ESM::Cell *ptrCell = MWBase::Environment::get().getWorld()->getPlayerPtr().getCell()->getCell(); bool cellChanged = false; - // Send a packet to server to update this LocalPlayer's cell if: - // 1) forceUpdate is true - // 2) The LocalPlayer's cell name does not equal the World Player's cell name - // 3) The LocalPlayer's exterior cell coordinates do not equal the World Player's - // exterior cell coordinates - if (forceUpdate) + // If the LocalPlayer's Ptr cell is different from the LocalPlayer's packet cell, proceed + if (forceUpdate || !Main::get().getCellController()->isSameCell(*ptrCell, cell)) { - cellChanged = true; - } - else if (!Misc::StringUtils::ciEqual(ptrCell->mName, cell.mName)) - { - cellChanged = true; - } - else if (ptrCell->isExterior()) - { - if (ptrCell->mData.mX != cell.mData.mX) - { - cellChanged = true; - } - else if (ptrCell->mData.mY != cell.mData.mY) - { - cellChanged = true; - } - } - - if (cellChanged) - { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Sending ID_PLAYER_CELL_CHANGE to server"); + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Sending ID_PLAYER_CELL_CHANGE about LocalPlayer to server"); LOG_APPEND(Log::LOG_INFO, "- Moved from %s to %s", cell.getDescription().c_str(), ptrCell->getDescription().c_str());