diff --git a/apps/openmw/mwmp/Cell.cpp b/apps/openmw/mwmp/Cell.cpp index fbc6d836c..38e62b694 100644 --- a/apps/openmw/mwmp/Cell.cpp +++ b/apps/openmw/mwmp/Cell.cpp @@ -44,14 +44,19 @@ void Cell::updateLocal() else { //LOG_APPEND(Log::LOG_VERBOSE, "- Updating LocalActor %s", it->first.c_str()); - //actor->update(); + actor->update(); MWWorld::Ptr ptr = actor->getPtr(); mwmp::WorldObject worldObject; worldObject.refId = ptr.getCellRef().getRefId(); worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex; worldObject.mpNum = ptr.getCellRef().getMpNum(); - worldObject.pos = ptr.getRefData().getPosition(); + worldObject.pos = actor->position; + worldObject.direction = actor->direction; + worldObject.drawState = actor->drawState; + worldObject.movementFlags = actor->movementFlags; + worldObject.headPitch = actor->headPitch; + worldObject.headYaw = actor->headYaw; worldEvent->addObject(worldObject); @@ -121,7 +126,15 @@ void Cell::readCellFrame(mwmp::WorldEvent& worldEvent) { DedicatedActor *actor = dedicatedActors[mapIndex]; actor->position = worldObject.pos; + actor->direction = worldObject.direction; + actor->drawState = worldObject.drawState; + actor->movementFlags = worldObject.movementFlags; + actor->headPitch = worldObject.headPitch; + actor->headYaw = worldObject.headYaw; actor->move(); + actor->setDrawState(); + actor->setMovementFlags(); + actor->setAnimation(); } } } diff --git a/apps/openmw/mwmp/DedicatedActor.cpp b/apps/openmw/mwmp/DedicatedActor.cpp index bf80ede70..b8593dcc1 100644 --- a/apps/openmw/mwmp/DedicatedActor.cpp +++ b/apps/openmw/mwmp/DedicatedActor.cpp @@ -1,6 +1,7 @@ #include "../mwbase/environment.hpp" -#include "../mwmechanics/creaturestats.hpp" +#include "../mwmechanics/movement.hpp" #include "../mwmechanics/npcstats.hpp" +#include "../mwrender/animation.hpp" #include "../mwworld/class.hpp" #include "../mwworld/worldimp.hpp" @@ -11,7 +12,7 @@ using namespace std; DedicatedActor::DedicatedActor() { - + movementFlags = 0; } DedicatedActor::~DedicatedActor() @@ -29,9 +30,54 @@ void DedicatedActor::move() MWBase::World *world = MWBase::Environment::get().getWorld(); world->moveObject(ptr, position.pos[0], position.pos[1], position.pos[2]); + + 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::setDrawState() +{ + using namespace MWMechanics; + + if (drawState == 0) + ptr.getClass().getNpcStats(ptr).setDrawState(DrawState_Nothing); + else if (drawState == 1) + ptr.getClass().getNpcStats(ptr).setDrawState(DrawState_Weapon); + else if (drawState == 2) + ptr.getClass().getNpcStats(ptr).setDrawState(DrawState_Spell); +} + +void DedicatedActor::setMovementFlags() +{ + using namespace MWMechanics; + + MWMechanics::NpcStats *ptrNpcStats = &ptr.getClass().getNpcStats(ptr); + ptrNpcStats->setMovementFlag(CreatureStats::Flag_Run, (movementFlags & CreatureStats::Flag_Run) != 0); + ptrNpcStats->setMovementFlag(CreatureStats::Flag_Sneak, (movementFlags & CreatureStats::Flag_Sneak) != 0); + ptrNpcStats->setMovementFlag(CreatureStats::Flag_ForceJump, (movementFlags & CreatureStats::Flag_ForceJump) != 0); + ptrNpcStats->setMovementFlag(CreatureStats::Flag_ForceMoveJump, (movementFlags & CreatureStats::Flag_ForceMoveJump) != 0); +} + +void DedicatedActor::setAnimation() +{ + MWBase::World *world = MWBase::Environment::get().getWorld(); + + if (headPitch != -1 && headYaw != -1) + { + MWRender::Animation *animation = world->getAnimation(ptr); + + if (animation) + { + animation->setHeadPitch(headPitch); + animation->setHeadYaw(headYaw); + } + } +} + MWWorld::Ptr DedicatedActor::getPtr() { return ptr; diff --git a/apps/openmw/mwmp/DedicatedActor.hpp b/apps/openmw/mwmp/DedicatedActor.hpp index d92e48637..f4c8814e4 100644 --- a/apps/openmw/mwmp/DedicatedActor.hpp +++ b/apps/openmw/mwmp/DedicatedActor.hpp @@ -2,6 +2,7 @@ #define OPENMW_DEDICATEDACTOR_HPP #include +#include "../mwmechanics/aisequence.hpp" #include "../mwworld/manualref.hpp" namespace mwmp @@ -15,6 +16,9 @@ namespace mwmp void update(); void move(); + void setDrawState(); + void setMovementFlags(); + void setAnimation(); MWWorld::Ptr getPtr(); void setPtr(const MWWorld::Ptr& newPtr); diff --git a/apps/openmw/mwmp/LocalActor.cpp b/apps/openmw/mwmp/LocalActor.cpp index dd6e215f3..ca4635c63 100644 --- a/apps/openmw/mwmp/LocalActor.cpp +++ b/apps/openmw/mwmp/LocalActor.cpp @@ -1,4 +1,9 @@ -#include +#include "../mwbase/environment.hpp" +#include "../mwmechanics/movement.hpp" +#include "../mwmechanics/npcstats.hpp" +#include "../mwrender/animation.hpp" +#include "../mwworld/class.hpp" +#include "../mwworld/worldimp.hpp" #include "LocalActor.hpp" @@ -7,7 +12,8 @@ using namespace std; LocalActor::LocalActor() { - + headPitch = -1; + headYaw = -1; } LocalActor::~LocalActor() @@ -17,7 +23,60 @@ LocalActor::~LocalActor() void LocalActor::update() { + updatePosition(); + updateDrawState(); + updateMovementFlags(); + updateAnimation(); +} + +void LocalActor::updatePosition() +{ + position = ptr.getRefData().getPosition(); + + MWMechanics::Movement &move = ptr.getClass().getMovementSettings(ptr); + direction.pos[0] = move.mPosition[0]; + direction.pos[1] = move.mPosition[1]; + direction.pos[2] = move.mPosition[2]; +} + +void LocalActor::updateDrawState() +{ + drawState = ptr.getClass().getNpcStats(ptr).getDrawState(); +} + +void LocalActor::updateMovementFlags() +{ + using namespace MWMechanics; + + MWBase::World *world = MWBase::Environment::get().getWorld(); + MWMechanics::NpcStats ptrNpcStats = ptr.getClass().getNpcStats(ptr); + + bool run = ptrNpcStats.getMovementFlag(CreatureStats::Flag_Run); + bool sneak = ptrNpcStats.getMovementFlag(CreatureStats::Flag_Sneak); + bool forceJump = ptrNpcStats.getMovementFlag(CreatureStats::Flag_ForceJump); + bool forceMoveJump = ptrNpcStats.getMovementFlag(CreatureStats::Flag_ForceMoveJump); + +#define __SETFLAG(flag, value) (value) ? (movementFlags | flag) : (movementFlags & ~flag) + + movementFlags = __SETFLAG(CreatureStats::Flag_Sneak, sneak); + movementFlags = __SETFLAG(CreatureStats::Flag_Run, run); + movementFlags = __SETFLAG(CreatureStats::Flag_ForceJump, forceJump); + movementFlags = __SETFLAG(CreatureStats::Flag_ForceMoveJump, forceMoveJump); + +#undef __SETFLAG +} + +void LocalActor::updateAnimation() +{ + MWBase::World *world = MWBase::Environment::get().getWorld(); + + MWRender::Animation *animation = world->getAnimation(ptr); + if (animation) + { + headPitch = animation->getHeadPitch(); + headYaw = animation->getHeadYaw(); + } } MWWorld::Ptr LocalActor::getPtr() diff --git a/apps/openmw/mwmp/LocalActor.hpp b/apps/openmw/mwmp/LocalActor.hpp index 3eab1a8d7..e844bc198 100644 --- a/apps/openmw/mwmp/LocalActor.hpp +++ b/apps/openmw/mwmp/LocalActor.hpp @@ -15,6 +15,11 @@ namespace mwmp void update(); + void updatePosition(); + void updateDrawState(); + void updateMovementFlags(); + void updateAnimation(); + MWWorld::Ptr getPtr(); void setPtr(const MWWorld::Ptr& newPtr); diff --git a/components/openmw-mp/Base/BaseActor.hpp b/components/openmw-mp/Base/BaseActor.hpp index a57c60a0b..e915958b0 100644 --- a/components/openmw-mp/Base/BaseActor.hpp +++ b/components/openmw-mp/Base/BaseActor.hpp @@ -22,6 +22,9 @@ namespace mwmp ESM::Position position; ESM::Position direction; ESM::Cell cell; + + float headPitch; + float headYaw; }; } diff --git a/components/openmw-mp/Base/BaseEvent.hpp b/components/openmw-mp/Base/BaseEvent.hpp index a5f4a4dcd..d87d38f43 100644 --- a/components/openmw-mp/Base/BaseEvent.hpp +++ b/components/openmw-mp/Base/BaseEvent.hpp @@ -35,7 +35,16 @@ namespace mwmp int count; int charge; int goldValue; + ESM::Position pos; + ESM::Position direction; + + unsigned int movementFlags; + char movementAnim; + int drawState; + + float headPitch; + float headYaw; int doorState; int lockLevel; diff --git a/components/openmw-mp/Packets/World/PacketActorFrame.cpp b/components/openmw-mp/Packets/World/PacketActorFrame.cpp index eb1271908..1e65b39c3 100644 --- a/components/openmw-mp/Packets/World/PacketActorFrame.cpp +++ b/components/openmw-mp/Packets/World/PacketActorFrame.cpp @@ -37,6 +37,12 @@ void PacketActorFrame::Packet(RakNet::BitStream *bs, bool send) RW(worldObject.refNumIndex, send); RW(worldObject.mpNum, send); RW(worldObject.pos, send); + RW(worldObject.direction, send); + RW(worldObject.movementFlags, send); + RW(worldObject.drawState, send); + + RW(worldObject.headPitch, send); + RW(worldObject.headYaw, send); if (!send) {