[General] Implement DoorDestination packet & associated script functions

This commit is contained in:
David Cernat 2018-04-29 22:32:22 +03:00
parent d47b06fe7a
commit 4b501a39f4
10 changed files with 233 additions and 26 deletions

View file

@ -229,11 +229,6 @@ void WorldFunctions::SetObjectState(bool objectState) noexcept
tempWorldObject.objectState = objectState; tempWorldObject.objectState = objectState;
} }
void WorldFunctions::SetObjectDoorState(int doorState) noexcept
{
tempWorldObject.doorState = doorState;
}
void WorldFunctions::SetObjectLockLevel(int lockLevel) noexcept void WorldFunctions::SetObjectLockLevel(int lockLevel) noexcept
{ {
tempWorldObject.lockLevel = lockLevel; tempWorldObject.lockLevel = lockLevel;
@ -263,6 +258,34 @@ void WorldFunctions::SetObjectRotation(double x, double y, double z) noexcept
tempWorldObject.position.rot[2] = z; tempWorldObject.position.rot[2] = z;
} }
void WorldFunctions::SetObjectDoorState(int doorState) noexcept
{
tempWorldObject.doorState = doorState;
}
void WorldFunctions::SetObjectDoorTeleportState(bool teleportState) noexcept
{
tempWorldObject.teleportState = teleportState;
}
void WorldFunctions::SetObjectDoorDestinationCell(const char* cellDescription) noexcept
{
tempWorldObject.destinationCell = Utils::getCellFromDescription(cellDescription);
}
void WorldFunctions::SetObjectDoorDestinationPosition(double x, double y, double z) noexcept
{
tempWorldObject.destinationPosition.pos[0] = x;
tempWorldObject.destinationPosition.pos[1] = y;
tempWorldObject.destinationPosition.pos[2] = z;
}
void WorldFunctions::SetObjectDoorDestinationRotation(double x, double z) noexcept
{
tempWorldObject.destinationPosition.rot[0] = x;
tempWorldObject.destinationPosition.rot[2] = z;
}
void WorldFunctions::SetPlayerAsObject(unsigned short pid) noexcept void WorldFunctions::SetPlayerAsObject(unsigned short pid) noexcept
{ {
Player *player; Player *player;
@ -392,6 +415,16 @@ void WorldFunctions::SendDoorState(bool broadcast) noexcept
packet->Send(true); packet->Send(true);
} }
void WorldFunctions::SendDoorDestination(bool broadcast) noexcept
{
mwmp::WorldPacket *packet = mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_DOOR_DESTINATION);
packet->setEvent(&writeEvent);
packet->Send(false);
if (broadcast)
packet->Send(true);
}
void WorldFunctions::SendContainer(bool broadcast, bool useLastReadEvent) noexcept void WorldFunctions::SendContainer(bool broadcast, bool useLastReadEvent) noexcept
{ {
mwmp::WorldPacket *packet = mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_CONTAINER); mwmp::WorldPacket *packet = mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_CONTAINER);

View file

@ -47,12 +47,18 @@
{"SetObjectGoldValue", WorldFunctions::SetObjectGoldValue},\ {"SetObjectGoldValue", WorldFunctions::SetObjectGoldValue},\
{"SetObjectScale", WorldFunctions::SetObjectScale},\ {"SetObjectScale", WorldFunctions::SetObjectScale},\
{"SetObjectState", WorldFunctions::SetObjectState},\ {"SetObjectState", WorldFunctions::SetObjectState},\
{"SetObjectDoorState", WorldFunctions::SetObjectDoorState},\
{"SetObjectLockLevel", WorldFunctions::SetObjectLockLevel},\ {"SetObjectLockLevel", WorldFunctions::SetObjectLockLevel},\
{"SetObjectDisarmState", WorldFunctions::SetObjectDisarmState},\ {"SetObjectDisarmState", WorldFunctions::SetObjectDisarmState},\
{"SetObjectMasterState", WorldFunctions::SetObjectMasterState},\ {"SetObjectMasterState", WorldFunctions::SetObjectMasterState},\
{"SetObjectPosition", WorldFunctions::SetObjectPosition},\ {"SetObjectPosition", WorldFunctions::SetObjectPosition},\
{"SetObjectRotation", WorldFunctions::SetObjectRotation},\ {"SetObjectRotation", WorldFunctions::SetObjectRotation},\
\
{"SetObjectDoorState", WorldFunctions::SetObjectDoorState},\
{"SetObjectDoorTeleportState", WorldFunctions::SetObjectDoorTeleportState},\
{"SetObjectDoorDestinationCell", WorldFunctions::SetObjectDoorDestinationCell},\
{"SetObjectDoorDestinationPosition", WorldFunctions::SetObjectDoorDestinationPosition},\
{"SetObjectDoorDestinationRotation", WorldFunctions::SetObjectDoorDestinationRotation},\
\
{"SetPlayerAsObject", WorldFunctions::SetPlayerAsObject},\ {"SetPlayerAsObject", WorldFunctions::SetPlayerAsObject},\
\ \
{"SetContainerItemRefId", WorldFunctions::SetContainerItemRefId},\ {"SetContainerItemRefId", WorldFunctions::SetContainerItemRefId},\
@ -73,6 +79,7 @@
{"SendObjectScale", WorldFunctions::SendObjectScale},\ {"SendObjectScale", WorldFunctions::SendObjectScale},\
{"SendObjectState", WorldFunctions::SendObjectState},\ {"SendObjectState", WorldFunctions::SendObjectState},\
{"SendDoorState", WorldFunctions::SendDoorState},\ {"SendDoorState", WorldFunctions::SendDoorState},\
{"SendDoorDestination", WorldFunctions::SendDoorDestination},\
{"SendContainer", WorldFunctions::SendContainer},\ {"SendContainer", WorldFunctions::SendContainer},\
{"SendConsoleCommand", WorldFunctions::SendConsoleCommand},\ {"SendConsoleCommand", WorldFunctions::SendConsoleCommand},\
\ \
@ -80,7 +87,7 @@
{"SetMonth", WorldFunctions::SetMonth},\ {"SetMonth", WorldFunctions::SetMonth},\
{"SetDay", WorldFunctions::SetDay} {"SetDay", WorldFunctions::SetDay}
class WorldFunctions class WorldFunctions
{ {
public: public:
@ -456,16 +463,6 @@ public:
*/ */
static void SetObjectState(bool objectState) noexcept; static void SetObjectState(bool objectState) noexcept;
/**
* \brief Set the door state of the temporary world object stored on the server.
*
* Doors are open or closed based on their door state.
*
* \param doorState The door state.
* \return void
*/
static void SetObjectDoorState(int doorState) noexcept;
/** /**
* \brief Set the lock level of the temporary world object stored on the server. * \brief Set the lock level of the temporary world object stored on the server.
* *
@ -513,6 +510,60 @@ public:
*/ */
static void SetObjectRotation(double x, double y, double z) noexcept; static void SetObjectRotation(double x, double y, double z) noexcept;
/**
* \brief Set the door state of the temporary world object stored on the server.
*
* Doors are open or closed based on their door state.
*
* \param doorState The door state.
* \return void
*/
static void SetObjectDoorState(int doorState) noexcept;
/**
* \brief Set the teleport state of the temporary world object stored on the server.
*
* If a door's teleport state is true, interacting with the door teleports a player to its
* destination. If it's false, it opens and closes like a regular door.
*
* \param teleportState The teleport state.
* \return void
*/
static void SetObjectDoorTeleportState(bool teleportState) noexcept;
/**
* \brief Set the door destination cell of the temporary world object stored on the server.
*
* The cell is determined to be an exterior cell if it fits the pattern of a number followed
* by a comma followed by another number.
*
* \param cellDescription The description of the cell.
* \return void
*/
static void SetObjectDoorDestinationCell(const char* cellDescription) noexcept;
/**
* \brief Set the door destination position of the temporary world object stored on the server.
*
* \param x The X position.
* \param y The Y position.
* \param z The Z position.
* \return void
*/
static void SetObjectDoorDestinationPosition(double x, double y, double z) noexcept;
/**
* \brief Set the door destination rotation of the temporary world object stored on the server.
*
* Note: Because this sets the rotation a player will have upon using the door, and rotation
* on the Y axis has no effect on players, the Y value has been omitted as an argument.
*
* \param x The X rotation.
* \param z The Z rotation.
* \return void
*/
static void SetObjectDoorDestinationRotation(double x, double z) noexcept;
/** /**
* \brief Set a player as the object in the temporary world object stored on the server. * \brief Set a player as the object in the temporary world object stored on the server.
* Currently only used for ConsoleCommand packets. * Currently only used for ConsoleCommand packets.
@ -670,6 +721,16 @@ public:
*/ */
static void SendDoorState(bool broadcast = false) noexcept; static void SendDoorState(bool broadcast = false) noexcept;
/**
* \brief Send a DoorDestination packet.
*
* \param broadcast Whether this packet should be sent only to the player for whom the current
* event was initialized or to everyone on the server.
*
* \return void
*/
static void SendDoorDestination(bool broadcast = false) noexcept;
/** /**
* \brief Send a Container packet. * \brief Send a Container packet.
* *

View file

@ -124,12 +124,12 @@ add_openmw_dir (mwmp/processors/player ProcessorChatMessage ProcessorGUIMessageB
ProcessorPlayerSpellbook ProcessorPlayerStatsDynamic ProcessorPlayerTopic ProcessorPlayerSpellbook ProcessorPlayerStatsDynamic ProcessorPlayerTopic
) )
add_openmw_dir (mwmp/processors/world BaseObjectProcessor ProcessorConsoleCommand ProcessorContainer ProcessorDoorState add_openmw_dir (mwmp/processors/world BaseObjectProcessor ProcessorConsoleCommand ProcessorContainer ProcessorDoorDestination
ProcessorMusicPlay ProcessorVideoPlay ProcessorObjectAnimPlay ProcessorObjectAttach ProcessorObjectCollision ProcessorDoorState ProcessorMusicPlay ProcessorVideoPlay ProcessorObjectAnimPlay ProcessorObjectAttach
ProcessorObjectDelete ProcessorObjectLock ProcessorObjectMove ProcessorObjectPlace ProcessorObjectReset ProcessorObjectCollision ProcessorObjectDelete ProcessorObjectLock ProcessorObjectMove ProcessorObjectPlace
ProcessorObjectRotate ProcessorObjectScale ProcessorObjectSpawn ProcessorObjectState ProcessorObjectTrap ProcessorObjectReset ProcessorObjectRotate ProcessorObjectScale ProcessorObjectSpawn ProcessorObjectState
ProcessorScriptLocalShort ProcessorScriptLocalFloat ProcessorScriptMemberShort ProcessorScriptMemberFloat ProcessorObjectTrap ProcessorScriptLocalShort ProcessorScriptLocalFloat ProcessorScriptMemberShort
ProcessorScriptGlobalShort ProcessorScriptGlobalFloat ProcessorScriptMemberFloat ProcessorScriptGlobalShort ProcessorScriptGlobalFloat
) )
# Main executable # Main executable

View file

@ -566,6 +566,34 @@ void WorldEvent::activateDoors(MWWorld::CellStore* cellStore)
} }
} }
void WorldEvent::setDoorDestinations(MWWorld::CellStore* cellStore)
{
for (const auto &worldObject : worldObjects)
{
LOG_APPEND(Log::LOG_VERBOSE, "- cellRef: %s, %i, %i", worldObject.refId.c_str(), worldObject.refNumIndex, worldObject.mpNum);
MWWorld::Ptr ptrFound = cellStore->searchExact(worldObject.refNumIndex, worldObject.mpNum);
if (ptrFound)
{
LOG_APPEND(Log::LOG_VERBOSE, "-- Found %s, %i, %i", ptrFound.getCellRef().getRefId().c_str(),
ptrFound.getCellRef().getRefNum(), ptrFound.getCellRef().getMpNum());
ptrFound.getCellRef().setTeleport(worldObject.teleportState);
if (worldObject.teleportState)
{
ptrFound.getCellRef().setDoorDest(worldObject.destinationPosition);
if (worldObject.destinationCell.isExterior())
ptrFound.getCellRef().setDestCell("");
else
ptrFound.getCellRef().setDestCell(worldObject.destinationCell.getDescription());
}
}
}
}
void WorldEvent::runConsoleCommands(MWWorld::CellStore* cellStore) void WorldEvent::runConsoleCommands(MWWorld::CellStore* cellStore)
{ {
MWBase::WindowManager *windowManager = MWBase::Environment::get().getWindowManager(); MWBase::WindowManager *windowManager = MWBase::Environment::get().getWindowManager();

View file

@ -35,6 +35,7 @@ namespace mwmp
void rotateObjects(MWWorld::CellStore* cellStore); void rotateObjects(MWWorld::CellStore* cellStore);
void animateObjects(MWWorld::CellStore* cellStore); void animateObjects(MWWorld::CellStore* cellStore);
void activateDoors(MWWorld::CellStore* cellStore); void activateDoors(MWWorld::CellStore* cellStore);
void setDoorDestinations(MWWorld::CellStore* cellStore);
void runConsoleCommands(MWWorld::CellStore* cellStore); void runConsoleCommands(MWWorld::CellStore* cellStore);
void setLocalShorts(MWWorld::CellStore* cellStore); void setLocalShorts(MWWorld::CellStore* cellStore);

View file

@ -17,7 +17,7 @@ namespace mwmp
{ {
BaseObjectProcessor::Do(packet, event); BaseObjectProcessor::Do(packet, event);
//event.setDoorDestinations(ptrCellStore); event.setDoorDestinations(ptrCellStore);
} }
}; };
} }

View file

@ -56,16 +56,55 @@ namespace MWWorld
return mCellRef.mTeleport; return mCellRef.mTeleport;
} }
/*
Start of tes3mp addition
Make it possible to change the teleport state from elsewhere
*/
void CellRef::setTeleport(bool teleportState)
{
mCellRef.mTeleport = teleportState;
}
/*
End of tes3mp addition
*/
ESM::Position CellRef::getDoorDest() const ESM::Position CellRef::getDoorDest() const
{ {
return mCellRef.mDoorDest; return mCellRef.mDoorDest;
} }
/*
Start of tes3mp addition
Make it possible to change the destination position from elsewhere
*/
void CellRef::setDoorDest(const ESM::Position& position)
{
mCellRef.mDoorDest = position;
}
/*
End of tes3mp addition
*/
std::string CellRef::getDestCell() const std::string CellRef::getDestCell() const
{ {
return mCellRef.mDestCell; return mCellRef.mDestCell;
} }
/*
Start of tes3mp addition
Make it possible to change the destination cell from elsewhere
*/
void CellRef::setDestCell(const std::string& cellDescription)
{
mCellRef.mDestCell = cellDescription;
}
/*
End of tes3mp addition
*/
float CellRef::getScale() const float CellRef::getScale() const
{ {
return mCellRef.mScale; return mCellRef.mScale;

View file

@ -58,12 +58,42 @@ namespace MWWorld
// if it should open through animation. // if it should open through animation.
bool getTeleport() const; bool getTeleport() const;
/*
Start of tes3mp addition
Make it possible to change the teleport state from elsewhere
*/
void setTeleport(bool teleportState);
/*
End of tes3mp addition
*/
// Teleport location for the door, if this is a teleporting door. // Teleport location for the door, if this is a teleporting door.
ESM::Position getDoorDest() const; ESM::Position getDoorDest() const;
/*
Start of tes3mp addition
Make it possible to change the destination position from elsewhere
*/
void setDoorDest(const ESM::Position& position);
/*
End of tes3mp addition
*/
// Destination cell for doors (optional) // Destination cell for doors (optional)
std::string getDestCell() const; std::string getDestCell() const;
/*
Start of tes3mp addition
Make it possible to change the destination cell from elsewhere
*/
void setDestCell(const std::string& cellDescription);
/*
End of tes3mp addition
*/
// Scale applied to mesh // Scale applied to mesh
float getScale() const; float getScale() const;
void setScale(float scale); void setScale(float scale);

View file

@ -35,10 +35,14 @@ namespace mwmp
ESM::Position position; ESM::Position position;
bool objectState; bool objectState;
int doorState;
int lockLevel; int lockLevel;
float scale; float scale;
int doorState;
bool teleportState;
ESM::Cell destinationCell;
ESM::Position destinationPosition;
std::string filename; std::string filename;
bool allowSkipping; bool allowSkipping;

View file

@ -12,5 +12,16 @@ PacketDoorDestination::PacketDoorDestination(RakNet::RakPeerInterface *peer) : W
void PacketDoorDestination::Object(WorldObject &worldObject, bool send) void PacketDoorDestination::Object(WorldObject &worldObject, bool send)
{ {
WorldPacket::Object(worldObject, send); WorldPacket::Object(worldObject, send);
// Placeholder
RW(worldObject.teleportState, send);
if (worldObject.teleportState)
{
RW(worldObject.destinationCell.mData, send, 1);
RW(worldObject.destinationCell.mName, send, 1);
RW(worldObject.destinationPosition.pos, send, 1);
RW(worldObject.destinationPosition.rot[0], send, 1);
RW(worldObject.destinationPosition.rot[2], send, 1);
}
} }