From 3b5fb9cd6b5b454633867e4f83807450b483c1d2 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Fri, 25 May 2018 03:33:12 +0300 Subject: [PATCH] [General] Make it possible to set year via WorldTime --- .../openmw-mp/Script/Functions/Worldstate.cpp | 5 ++ .../openmw-mp/Script/Functions/Worldstate.hpp | 10 +++ apps/openmw/mwbase/world.hpp | 28 +++++--- .../worldstate/ProcessorWorldTime.hpp | 4 ++ apps/openmw/mwworld/worldimp.cpp | 65 +++++++++++-------- apps/openmw/mwworld/worldimp.hpp | 28 +++++--- components/openmw-mp/Base/BaseWorldstate.hpp | 5 +- .../Packets/Worldstate/PacketWorldTime.cpp | 5 +- 8 files changed, 102 insertions(+), 48 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/Worldstate.cpp b/apps/openmw-mp/Script/Functions/Worldstate.cpp index e395ac91c..3793e034a 100644 --- a/apps/openmw-mp/Script/Functions/Worldstate.cpp +++ b/apps/openmw-mp/Script/Functions/Worldstate.cpp @@ -27,6 +27,11 @@ void WorldstateFunctions::SetMonth(int month) noexcept writeWorldstate.month = month; } +void WorldstateFunctions::SetYear(int year) noexcept +{ + writeWorldstate.year = year; +} + void WorldstateFunctions::SetDaysPassed(int daysPassed) noexcept { writeWorldstate.daysPassed = daysPassed; diff --git a/apps/openmw-mp/Script/Functions/Worldstate.hpp b/apps/openmw-mp/Script/Functions/Worldstate.hpp index 56c2baf15..ff60047df 100644 --- a/apps/openmw-mp/Script/Functions/Worldstate.hpp +++ b/apps/openmw-mp/Script/Functions/Worldstate.hpp @@ -7,6 +7,8 @@ {"SetHour", WorldstateFunctions::SetHour},\ {"SetDay", WorldstateFunctions::SetDay},\ {"SetMonth", WorldstateFunctions::SetMonth},\ + {"SetYear", WorldstateFunctions::SetYear},\ + \ {"SetDaysPassed", WorldstateFunctions::SetDaysPassed},\ {"SetTimeScale", WorldstateFunctions::SetTimeScale},\ \ @@ -40,6 +42,14 @@ public: */ static void SetMonth(int month) noexcept; + /** + * \brief Set the world's year in the worldstate stored on the server. + * + * \param year The year. + * \return void + */ + static void SetYear(int year) noexcept; + /** * \brief Set the world's days passed in the worldstate stored on the server. * diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index b09f2425b..53a530216 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -197,12 +197,21 @@ namespace MWBase virtual void advanceTime (double hours, bool incremental = false) = 0; ///< Advance in-game time. + virtual void setHour (double hour) = 0; + ///< Set in-game time hour. + + virtual void setMonth (int month) = 0; + ///< Set in-game time month. + + virtual void setDay (int day) = 0; + ///< Set in-game time day. + /* Start of tes3mp addition - Make it possible to set a custom timeScale from elsewhere + Make it possible to set the year from elsewhere */ - virtual void setTimeScale(float timeScale) = 0; + virtual void setYear(int year) = 0; /* End of tes3mp addition */ @@ -217,14 +226,15 @@ namespace MWBase End of tes3mp addition */ - virtual void setHour (double hour) = 0; - ///< Set in-game time hour. - - virtual void setMonth (int month) = 0; - ///< Set in-game time month. + /* + Start of tes3mp addition - virtual void setDay (int day) = 0; - ///< Set in-game time day. + Make it possible to set a custom timeScale from elsewhere + */ + virtual void setTimeScale(float timeScale) = 0; + /* + End of tes3mp addition + */ virtual int getDay() const = 0; virtual int getMonth() const = 0; diff --git a/apps/openmw/mwmp/processors/worldstate/ProcessorWorldTime.hpp b/apps/openmw/mwmp/processors/worldstate/ProcessorWorldTime.hpp index acff155c7..ef1c20487 100644 --- a/apps/openmw/mwmp/processors/worldstate/ProcessorWorldTime.hpp +++ b/apps/openmw/mwmp/processors/worldstate/ProcessorWorldTime.hpp @@ -21,6 +21,7 @@ namespace mwmp if (isLocal()) { MWBase::World *world = MWBase::Environment::get().getWorld(); + if (worldstate.hour != -1) world->setHour(worldstate.hour); @@ -30,6 +31,9 @@ namespace mwmp if (worldstate.month != -1) world->setMonth(worldstate.month); + if (worldstate.year != -1) + world->setYear(worldstate.year); + if (worldstate.daysPassed != -1) world->setDaysPassed(worldstate.daysPassed); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index c2a2a1230..423b16d3a 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -865,32 +865,6 @@ namespace MWWorld days + mDaysPassed->getInteger()); } - /* - Start of tes3mp addition - - Make it possible to set a custom timeScale from elsewhere - */ - void World::setTimeScale(float timeScale) - { - mTimeScale->setFloat(timeScale); - } - /* - End of tes3mp addition - */ - - /* - Start of tes3mp addition - - Make it possible to set the number of days passed from elsewhere - */ - void World::setDaysPassed(int days) - { - mDaysPassed->setInteger(days); - } - /* - End of tes3mp addition - */ - void World::setHour (double hour) { if (hour<0) @@ -959,6 +933,45 @@ namespace MWWorld mRendering->skySetDate (mDay->getInteger(), month); } + /* + Start of tes3mp addition + + Make it possible to set the year from elsewhere + */ + void World::setYear(int year) + { + mYear->setInteger(year); + } + /* + End of tes3mp addition + */ + + /* + Start of tes3mp addition + + Make it possible to set the number of days passed from elsewhere + */ + void World::setDaysPassed(int days) + { + mDaysPassed->setInteger(days); + } + /* + End of tes3mp addition + */ + + /* + Start of tes3mp addition + + Make it possible to set a custom timeScale from elsewhere + */ + void World::setTimeScale(float timeScale) + { + mTimeScale->setFloat(timeScale); + } + /* + End of tes3mp addition + */ + int World::getDay() const { return mDay->getInteger(); diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 484d92041..b639e23bd 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -306,12 +306,21 @@ namespace MWWorld void advanceTime (double hours, bool incremental = false) override; ///< Advance in-game time. + void setHour (double hour) override; + ///< Set in-game time hour. + + void setMonth (int month) override; + ///< Set in-game time month. + + void setDay (int day) override; + ///< Set in-game time day. + /* Start of tes3mp addition - Make it possible to set a custom timeScale from elsewhere + Make it possible to set the year from elsewhere */ - void setTimeScale(float timeScale) override; + void setYear(int year) override; /* End of tes3mp addition */ @@ -326,14 +335,15 @@ namespace MWWorld End of tes3mp addition */ - void setHour (double hour) override; - ///< Set in-game time hour. - - void setMonth (int month) override; - ///< Set in-game time month. + /* + Start of tes3mp addition - void setDay (int day) override; - ///< Set in-game time day. + Make it possible to set a custom timeScale from elsewhere + */ + void setTimeScale(float timeScale) override; + /* + End of tes3mp addition + */ int getDay() const override; int getMonth() const override; diff --git a/components/openmw-mp/Base/BaseWorldstate.hpp b/components/openmw-mp/Base/BaseWorldstate.hpp index 990435f80..f8549b74e 100644 --- a/components/openmw-mp/Base/BaseWorldstate.hpp +++ b/components/openmw-mp/Base/BaseWorldstate.hpp @@ -24,9 +24,10 @@ namespace mwmp RakNet::RakNetGUID guid; - int month; - int day; double hour; + int day; + int month; + int year; int daysPassed; float timeScale; diff --git a/components/openmw-mp/Packets/Worldstate/PacketWorldTime.cpp b/components/openmw-mp/Packets/Worldstate/PacketWorldTime.cpp index fd13014ed..d19831d90 100644 --- a/components/openmw-mp/Packets/Worldstate/PacketWorldTime.cpp +++ b/components/openmw-mp/Packets/Worldstate/PacketWorldTime.cpp @@ -13,9 +13,10 @@ void PacketWorldTime::Packet(RakNet::BitStream *bs, bool send) { WorldstatePacket::Packet(bs, send); - RW(worldstate->month, send); - RW(worldstate->day, send); RW(worldstate->hour, send); + RW(worldstate->day, send); + RW(worldstate->month, send); + RW(worldstate->year, send); RW(worldstate->daysPassed, send); RW(worldstate->timeScale, send);