forked from teamnwah/openmw-tes3coop
[Client] Make DedicatedActors transition into LocalActors when eligible
This commit is contained in:
parent
06f3c07116
commit
60cf623455
4 changed files with 41 additions and 14 deletions
|
@ -243,28 +243,47 @@ void Cell::readCellChange(ActorList& actorList)
|
||||||
|
|
||||||
if (dedicatedActors.count(mapIndex) > 0)
|
if (dedicatedActors.count(mapIndex) > 0)
|
||||||
{
|
{
|
||||||
DedicatedActor *actor = dedicatedActors[mapIndex];
|
DedicatedActor *dedicatedActor = dedicatedActors[mapIndex];
|
||||||
actor->cell = baseActor.cell;
|
dedicatedActor->cell = baseActor.cell;
|
||||||
actor->position = baseActor.position;
|
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);
|
MWWorld::CellStore *newStore = cellController->getCellStore(dedicatedActor->cell);
|
||||||
actor->setCell(newStore);
|
dedicatedActor->setCell(newStore);
|
||||||
|
|
||||||
// If the cell this actor has moved to is active and not under our authority, move them to it
|
// 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());
|
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(actor->cell);
|
Cell *newCell = cellController->getCell(dedicatedActor->cell);
|
||||||
newCell->dedicatedActors[mapIndex] = actor;
|
newCell->dedicatedActors[mapIndex] = dedicatedActor;
|
||||||
cellController->setDedicatedActorRecord(mapIndex, newCell->getDescription());
|
cellController->setDedicatedActorRecord(mapIndex, newCell->getDescription());
|
||||||
}
|
}
|
||||||
else
|
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);
|
cellController->removeDedicatedActorRecord(mapIndex);
|
||||||
delete actor;
|
delete dedicatedActor;
|
||||||
}
|
}
|
||||||
|
|
||||||
dedicatedActors.erase(mapIndex);
|
dedicatedActors.erase(mapIndex);
|
||||||
|
|
|
@ -55,6 +55,7 @@ void DedicatedActor::setCell(MWWorld::CellStore *cellStore)
|
||||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||||
|
|
||||||
ptr = world->moveObject(ptr, cellStore, position.pos[0], position.pos[1], position.pos[2]);
|
ptr = world->moveObject(ptr, cellStore, position.pos[0], position.pos[1], position.pos[2]);
|
||||||
|
setMovementSettings();
|
||||||
|
|
||||||
hasChangedCell = true;
|
hasChangedCell = true;
|
||||||
}
|
}
|
||||||
|
@ -79,15 +80,20 @@ void DedicatedActor::move(float dt)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setPosition();
|
setPosition();
|
||||||
|
setMovementSettings();
|
||||||
hasChangedCell = false;
|
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);
|
MWMechanics::Movement *move = &ptr.getClass().getMovementSettings(ptr);
|
||||||
move->mPosition[0] = direction.pos[0];
|
move->mPosition[0] = direction.pos[0];
|
||||||
move->mPosition[1] = direction.pos[1];
|
move->mPosition[1] = direction.pos[1];
|
||||||
move->mPosition[2] = direction.pos[2];
|
move->mPosition[2] = direction.pos[2];
|
||||||
|
|
||||||
world->rotateObject(ptr, position.rot[0], position.rot[1], position.rot[2]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DedicatedActor::setPosition()
|
void DedicatedActor::setPosition()
|
||||||
|
|
|
@ -17,6 +17,7 @@ namespace mwmp
|
||||||
void update(float dt);
|
void update(float dt);
|
||||||
void move(float dt);
|
void move(float dt);
|
||||||
void setCell(MWWorld::CellStore *cellStore);
|
void setCell(MWWorld::CellStore *cellStore);
|
||||||
|
void setMovementSettings();
|
||||||
void setPosition();
|
void setPosition();
|
||||||
void setAnimFlags();
|
void setAnimFlags();
|
||||||
void playAnimation();
|
void playAnimation();
|
||||||
|
|
|
@ -44,6 +44,7 @@ void PacketActorCellChange::Packet(RakNet::BitStream *bs, bool send)
|
||||||
RW(actor.cell.mName, send);
|
RW(actor.cell.mName, send);
|
||||||
|
|
||||||
RW(actor.position, send);
|
RW(actor.position, send);
|
||||||
|
RW(actor.direction, send);
|
||||||
|
|
||||||
if (!send)
|
if (!send)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue