diff --git a/apps/openmw-mp/Script/Functions/Worldstate.cpp b/apps/openmw-mp/Script/Functions/Worldstate.cpp index d8ee3d589..56e51ef36 100644 --- a/apps/openmw-mp/Script/Functions/Worldstate.cpp +++ b/apps/openmw-mp/Script/Functions/Worldstate.cpp @@ -20,8 +20,25 @@ void WorldstateFunctions::SetHour(unsigned short pid, double hour) noexcept writeWorldstate.guid = player->guid; writeWorldstate.hour = hour; - writeWorldstate.month = -1; writeWorldstate.day = -1; + writeWorldstate.month = -1; + writeWorldstate.timeScale = -1; + + mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_TIME)->setWorldstate(&writeWorldstate); + mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_TIME)->Send(false); +} + +void WorldstateFunctions::SetDay(unsigned short pid, int day) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + writeWorldstate.guid = player->guid; + + writeWorldstate.hour = -1; + writeWorldstate.day = day; + writeWorldstate.month = -1; + writeWorldstate.timeScale = -1; mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_TIME)->setWorldstate(&writeWorldstate); mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_TIME)->Send(false); @@ -35,15 +52,15 @@ void WorldstateFunctions::SetMonth(unsigned short pid, int month) noexcept writeWorldstate.guid = player->guid; writeWorldstate.hour = -1; - writeWorldstate.month = month; writeWorldstate.day = -1; + writeWorldstate.month = month; + writeWorldstate.timeScale = -1; mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_TIME)->setWorldstate(&writeWorldstate); mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_TIME)->Send(false); - } -void WorldstateFunctions::SetDay(unsigned short pid, int day) noexcept +void WorldstateFunctions::SetTimeScale(unsigned short pid, double timeScale) noexcept { Player *player; GET_PLAYER(pid, player, ); @@ -51,8 +68,9 @@ void WorldstateFunctions::SetDay(unsigned short pid, int day) noexcept writeWorldstate.guid = player->guid; writeWorldstate.hour = -1; + writeWorldstate.day = -1; writeWorldstate.month = -1; - writeWorldstate.day = day; + writeWorldstate.timeScale = timeScale; mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_TIME)->setWorldstate(&writeWorldstate); mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_TIME)->Send(false); diff --git a/apps/openmw-mp/Script/Functions/Worldstate.hpp b/apps/openmw-mp/Script/Functions/Worldstate.hpp index 1078a38f8..94435be40 100644 --- a/apps/openmw-mp/Script/Functions/Worldstate.hpp +++ b/apps/openmw-mp/Script/Functions/Worldstate.hpp @@ -5,15 +5,16 @@ #define WORLDSTATEAPI \ {"SetHour", WorldstateFunctions::SetHour},\ + {"SetDay", WorldstateFunctions::SetDay},\ {"SetMonth", WorldstateFunctions::SetMonth},\ - {"SetDay", WorldstateFunctions::SetDay} + {"SetTimeScale", WorldstateFunctions::SetTimeScale} class WorldstateFunctions { public: /** - * \brief Set the game hour for a player and send a WorldTime packet to that player. + * \brief Set the world's hour for a player and send a WorldTime packet to that player. * * \param pid The player ID. * \param hour The hour. @@ -22,7 +23,16 @@ public: static void SetHour(unsigned short pid, double hour) noexcept; /** - * \brief Set the game month for a player and send a WorldTime packet to that player. + * \brief Set the world's day of the month for a player and send a WorldTime packet to that player. + * + * \param pid The player ID. + * \param day The day. + * \return void + */ + static void SetDay(unsigned short pid, int day) noexcept; + + /** + * \brief Set the world's month for a player and send a WorldTime packet to that player. * * \param pid The player ID. * \param month The month. @@ -31,13 +41,13 @@ public: static void SetMonth(unsigned short pid, int month) noexcept; /** - * \brief Set the game day for a player and send a WorldTime packet to that player. + * \brief Set the world's time scale for a player and send a WorldTime packet to that player. * * \param pid The player ID. - * \param day The day. + * \param timeScale The time scale. * \return void */ - static void SetDay(unsigned short pid, int day) noexcept; + static void SetTimeScale(unsigned short pid, double timeScale) noexcept; }; diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 1ad1b37e7..1bb383690 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -194,6 +194,16 @@ namespace MWBase virtual void advanceTime (double hours, bool incremental = false) = 0; ///< Advance in-game time. + /* + Start of tes3mp addition + + Make it possible to set a custom timescale from a server + */ + virtual void setTimeScale(float timeScale) = 0; + /* + End of tes3mp addition + */ + virtual void setHour (double hour) = 0; ///< Set in-game time hour. diff --git a/apps/openmw/mwmp/processors/worldstate/ProcessorWorldTime.hpp b/apps/openmw/mwmp/processors/worldstate/ProcessorWorldTime.hpp index 965674e92..fd656b207 100644 --- a/apps/openmw/mwmp/processors/worldstate/ProcessorWorldTime.hpp +++ b/apps/openmw/mwmp/processors/worldstate/ProcessorWorldTime.hpp @@ -27,6 +27,8 @@ namespace mwmp world->setDay(worldstate.day); else if (worldstate.month != -1) world->setMonth(worldstate.month); + else if (worldstate.timeScale != -1) + world->setTimeScale(worldstate.timeScale); } } }; diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index aaf3e6147..6dcb83b48 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -865,6 +865,19 @@ namespace MWWorld days + mDaysPassed->getInteger()); } + /* + Start of tes3mp addition + + Make it possible to set a custom timescale from a server + */ + void World::setTimeScale(float timeScale) + { + mTimeScale->setFloat(timeScale); + } + /* + End of tes3mp addition + */ + void World::setHour (double hour) { if (hour<0) diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index a8deea784..9c39e38dd 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -306,6 +306,16 @@ namespace MWWorld void advanceTime (double hours, bool incremental = false) override; ///< Advance in-game time. + /* + Start of tes3mp addition + + Make it possible to set a custom timescale from a server + */ + void setTimeScale(float timeScale) override; + /* + End of tes3mp addition + */ + void setHour (double hour) override; ///< Set in-game time hour. diff --git a/components/openmw-mp/Base/BaseWorldstate.hpp b/components/openmw-mp/Base/BaseWorldstate.hpp index ba108a9e1..04a6283ac 100644 --- a/components/openmw-mp/Base/BaseWorldstate.hpp +++ b/components/openmw-mp/Base/BaseWorldstate.hpp @@ -22,6 +22,7 @@ namespace mwmp int month; int day; double hour; + float timeScale; bool isValid; }; diff --git a/components/openmw-mp/Packets/Worldstate/PacketWorldTime.cpp b/components/openmw-mp/Packets/Worldstate/PacketWorldTime.cpp index 7eddab9b6..ea20e6f0e 100644 --- a/components/openmw-mp/Packets/Worldstate/PacketWorldTime.cpp +++ b/components/openmw-mp/Packets/Worldstate/PacketWorldTime.cpp @@ -16,4 +16,5 @@ void PacketWorldTime::Packet(RakNet::BitStream *bs, bool send) RW(worldstate->month, send); RW(worldstate->day, send); RW(worldstate->hour, send); + RW(worldstate->timeScale, send); }