Skip to content

An OpenMW mod that lets you play the whole Elder Scrolls III: Morrowind as a top-down isometric game — with full online co-op or MMO modes.

C++

Multiplayer: NPCs that walk into another cell are followed there (escorts, followers)

pw-tf83493486a9a9
diff --git a/apps/openmw/mwmp/Cell.cpp b/apps/openmw/mwmp/Cell.cpp
index b62b2ff..5892ff4 100644
--- a/apps/openmw/mwmp/Cell.cpp
+++ b/apps/openmw/mwmp/Cell.cpp
@@ -520,8 +520,10 @@ void Cell::initializeLocalActors()
std::string mapIndex = Main::get().getCellController()->generateMapIndex(ptr);
- // Only initialize this actor if it isn't already initialized
- if (localActors.count(mapIndex) == 0)
+ // Only initialize this actor if it isn't already initialized, here or in another cell: one that walked in
+ // from another cell is handed over by that cell's updateLocal, which tells the server of its cell change (a
+ // second LocalActor here would leave the first one behind, its cell change never sent)
+ if (localActors.count(mapIndex) == 0 && !Main::get().getCellController()->isLocalActor(ptr))
initializeLocalActor(ptr);
}
diff --git a/apps/openmw/mwmp/Hooks.cpp b/apps/openmw/mwmp/Hooks.cpp
index e2c83ab..a7b7f11 100644
--- a/apps/openmw/mwmp/Hooks.cpp
+++ b/apps/openmw/mwmp/Hooks.cpp
@@ -287,7 +287,10 @@ namespace mwmp::hooks
void updatePtr(const MWWorld::Ptr& oldPtr, const MWWorld::Ptr& newPtr)
{
- if (!isMultiplayer() || oldPtr == newPtr)
+ // Not skipped when the two compare equal: a Ptr compares only its reference, which an object moved to
+ // another cell keeps (CellStore::moveTo), so the new Ptr differs only in its cell, which is what's tracked
+ // (an actor's cell change is seen by its Ptr's cell: mwmp::Cell::updateLocal)
+ if (!isMultiplayer())
return;
CellController* cellController = Main::get().getCellController();
if (cellController->isLocalActor(oldPtr))