From 4a9a628a0f36c90ae3c104117f9cda233f35c5a7 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sun, 7 Jan 2018 02:35:30 +0200 Subject: [PATCH] [Client] When getting an actor, make sure their cell is initialized --- apps/openmw/mwmp/CellController.cpp | 33 +++++++++++++++++------------ apps/openmw/mwmp/CellController.hpp | 1 + 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/apps/openmw/mwmp/CellController.cpp b/apps/openmw/mwmp/CellController.cpp index 466a63c58..83aa32bae 100644 --- a/apps/openmw/mwmp/CellController.cpp +++ b/apps/openmw/mwmp/CellController.cpp @@ -191,15 +191,16 @@ bool CellController::isLocalActor(MWWorld::Ptr ptr) if (ptr.mRef == nullptr) return false; - std::string mapIndex = generateMapIndex(ptr); + std::string actorIndex = generateMapIndex(ptr); - return (localActorsToCells.count(mapIndex) > 0); + return (localActorsToCells.count(actorIndex) > 0 && isInitializedCell(localActorsToCells.at(actorIndex))); } bool CellController::isLocalActor(int refNumIndex, int mpNum) { - std::string mapIndex = generateMapIndex(refNumIndex, mpNum); - return (localActorsToCells.count(mapIndex) > 0); + std::string actorIndex = generateMapIndex(refNumIndex, mpNum); + + return (localActorsToCells.count(actorIndex) > 0 && isInitializedCell(localActorsToCells.at(actorIndex))); } LocalActor *CellController::getLocalActor(MWWorld::Ptr ptr) @@ -228,20 +229,21 @@ void CellController::removeDedicatedActorRecord(std::string actorIndex) dedicatedActorsToCells.erase(actorIndex); } -bool CellController::isDedicatedActor(int refNumIndex, int mpNum) -{ - std::string mapIndex = generateMapIndex(refNumIndex, mpNum); - return (dedicatedActorsToCells.count(mapIndex) > 0); -} - bool CellController::isDedicatedActor(MWWorld::Ptr ptr) { if (ptr.mRef == nullptr) return false; - std::string mapIndex = generateMapIndex(ptr); + std::string actorIndex = generateMapIndex(ptr); - return (dedicatedActorsToCells.count(mapIndex) > 0); + return (dedicatedActorsToCells.count(actorIndex) > 0 && isInitializedCell(dedicatedActorsToCells.at(actorIndex))); +} + +bool CellController::isDedicatedActor(int refNumIndex, int mpNum) +{ + std::string actorIndex = generateMapIndex(refNumIndex, mpNum); + + return (dedicatedActorsToCells.count(actorIndex) > 0 && isInitializedCell(dedicatedActorsToCells.at(actorIndex))); } DedicatedActor *CellController::getDedicatedActor(MWWorld::Ptr ptr) @@ -285,9 +287,14 @@ bool CellController::hasLocalAuthority(const ESM::Cell& cell) return false; } +bool CellController::isInitializedCell(const std::string& cellDescription) +{ + return (cellsInitialized.count(cellDescription) > 0); +} + bool CellController::isInitializedCell(const ESM::Cell& cell) { - return (cellsInitialized.count(cell.getDescription()) > 0); + return isInitializedCell(cell.getDescription()); } bool CellController::isActiveWorldCell(const ESM::Cell& cell) diff --git a/apps/openmw/mwmp/CellController.hpp b/apps/openmw/mwmp/CellController.hpp index 4b28043d3..78777913e 100644 --- a/apps/openmw/mwmp/CellController.hpp +++ b/apps/openmw/mwmp/CellController.hpp @@ -51,6 +51,7 @@ namespace mwmp std::string generateMapIndex(mwmp::BaseActor baseActor); bool hasLocalAuthority(const ESM::Cell& cell); + bool isInitializedCell(const std::string& cellDescription); bool isInitializedCell(const ESM::Cell& cell); bool isActiveWorldCell(const ESM::Cell& cell); virtual Cell *getCell(const ESM::Cell& cell);