diff --git a/apps/openmw/mwmp/Cell.cpp b/apps/openmw/mwmp/Cell.cpp index ad0692cd2..b8cdbb73c 100644 --- a/apps/openmw/mwmp/Cell.cpp +++ b/apps/openmw/mwmp/Cell.cpp @@ -243,28 +243,47 @@ void Cell::readCellChange(ActorList& actorList) if (dedicatedActors.count(mapIndex) > 0) { - DedicatedActor *actor = dedicatedActors[mapIndex]; - actor->cell = baseActor.cell; - actor->position = baseActor.position; + DedicatedActor *dedicatedActor = dedicatedActors[mapIndex]; + dedicatedActor->cell = baseActor.cell; + dedicatedActor->position = baseActor.position; + dedicatedActor->direction = baseActor.direction; - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Server says DedicatedActor %s moved to %s", mapIndex.c_str(), actor->cell.getDescription().c_str()); + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Server says DedicatedActor %s moved to %s", mapIndex.c_str(), dedicatedActor->cell.getDescription().c_str()); - MWWorld::CellStore *newStore = cellController->getCellStore(actor->cell); - actor->setCell(newStore); + MWWorld::CellStore *newStore = cellController->getCellStore(dedicatedActor->cell); + dedicatedActor->setCell(newStore); // If the cell this actor has moved to is active and not under our authority, move them to it - if (cellController->isInitializedCell(actor->cell)) + if (cellController->isActiveWorldCell(dedicatedActor->cell) && !cellController->hasLocalAuthority(dedicatedActor->cell)) { - LOG_APPEND(Log::LOG_INFO, "- Moving DedicatedActor %s to our active cell %s", mapIndex.c_str(), actor->cell.getDescription().c_str()); - Cell *newCell = cellController->getCell(actor->cell); - newCell->dedicatedActors[mapIndex] = actor; + LOG_APPEND(Log::LOG_INFO, "- Moving DedicatedActor %s to our active cell %s", mapIndex.c_str(), dedicatedActor->cell.getDescription().c_str()); + Cell *newCell = cellController->getCell(dedicatedActor->cell); + newCell->dedicatedActors[mapIndex] = dedicatedActor; cellController->setDedicatedActorRecord(mapIndex, newCell->getDescription()); } else { - LOG_APPEND(Log::LOG_INFO, "- Deleting DedicatedActor %s which is no longer in an active cell", mapIndex.c_str(), getDescription().c_str()); + if (cellController->hasLocalAuthority(dedicatedActor->cell)) + { + LOG_APPEND(Log::LOG_INFO, "- Creating new LocalActor based on %s in %s", mapIndex.c_str(), dedicatedActor->cell.getDescription().c_str()); + Cell *newCell = cellController->getCell(dedicatedActor->cell); + LocalActor *localActor = new LocalActor(); + localActor->cell = dedicatedActor->cell; + localActor->setPtr(dedicatedActor->getPtr()); + localActor->position = dedicatedActor->position; + localActor->direction = dedicatedActor->direction; + localActor->movementFlags = dedicatedActor->movementFlags; + localActor->drawState = dedicatedActor->drawState; + localActor->isFlying = dedicatedActor->isFlying; + localActor->creatureStats = dedicatedActor->creatureStats; + + newCell->localActors[mapIndex] = localActor; + cellController->setLocalActorRecord(mapIndex, newCell->getDescription()); + } + + LOG_APPEND(Log::LOG_INFO, "- Deleting DedicatedActor %s which is no longer needed", mapIndex.c_str(), getDescription().c_str()); cellController->removeDedicatedActorRecord(mapIndex); - delete actor; + delete dedicatedActor; } dedicatedActors.erase(mapIndex); diff --git a/apps/openmw/mwmp/DedicatedActor.cpp b/apps/openmw/mwmp/DedicatedActor.cpp index 5e95d47cb..e646f8120 100644 --- a/apps/openmw/mwmp/DedicatedActor.cpp +++ b/apps/openmw/mwmp/DedicatedActor.cpp @@ -55,6 +55,7 @@ void DedicatedActor::setCell(MWWorld::CellStore *cellStore) MWBase::World *world = MWBase::Environment::get().getWorld(); ptr = world->moveObject(ptr, cellStore, position.pos[0], position.pos[1], position.pos[2]); + setMovementSettings(); hasChangedCell = true; } @@ -79,15 +80,20 @@ void DedicatedActor::move(float dt) else { setPosition(); + setMovementSettings(); hasChangedCell = false; } + setMovementSettings(); + world->rotateObject(ptr, position.rot[0], position.rot[1], position.rot[2]); +} + +void DedicatedActor::setMovementSettings() +{ MWMechanics::Movement *move = &ptr.getClass().getMovementSettings(ptr); move->mPosition[0] = direction.pos[0]; move->mPosition[1] = direction.pos[1]; move->mPosition[2] = direction.pos[2]; - - world->rotateObject(ptr, position.rot[0], position.rot[1], position.rot[2]); } void DedicatedActor::setPosition() diff --git a/apps/openmw/mwmp/DedicatedActor.hpp b/apps/openmw/mwmp/DedicatedActor.hpp index 059101751..dd9b8b23c 100644 --- a/apps/openmw/mwmp/DedicatedActor.hpp +++ b/apps/openmw/mwmp/DedicatedActor.hpp @@ -17,6 +17,7 @@ namespace mwmp void update(float dt); void move(float dt); void setCell(MWWorld::CellStore *cellStore); + void setMovementSettings(); void setPosition(); void setAnimFlags(); void playAnimation(); diff --git a/components/openmw-mp/Packets/Actor/PacketActorCellChange.cpp b/components/openmw-mp/Packets/Actor/PacketActorCellChange.cpp index 9618632d6..d6d3c1a15 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorCellChange.cpp +++ b/components/openmw-mp/Packets/Actor/PacketActorCellChange.cpp @@ -44,6 +44,7 @@ void PacketActorCellChange::Packet(RakNet::BitStream *bs, bool send) RW(actor.cell.mName, send); RW(actor.position, send); + RW(actor.direction, send); if (!send) {