From 2d8fbc6e55bbff2c5008696f67bc6045d697cff3 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 22 Jul 2010 11:48:27 +0200 Subject: [PATCH] implemented month variable and fixed some day/gamehour bugs --- apps/openmw/mwrender/sky.cpp | 2 +- apps/openmw/mwrender/sky.hpp | 2 +- apps/openmw/mwscript/interpretercontext.cpp | 6 ++ apps/openmw/mwworld/world.cpp | 93 +++++++++++++++++---- apps/openmw/mwworld/world.hpp | 4 + 5 files changed, 87 insertions(+), 20 deletions(-) diff --git a/apps/openmw/mwrender/sky.cpp b/apps/openmw/mwrender/sky.cpp index ef6cb35788..d86ef35fbd 100644 --- a/apps/openmw/mwrender/sky.cpp +++ b/apps/openmw/mwrender/sky.cpp @@ -29,7 +29,7 @@ namespace MWRender virtual void setHour (double hour) {} ///< will be called even when sky is disabled. - virtual void setDay (int day) {} + virtual void setDate (int day, int month) {} ///< will be called even when sky is disabled. virtual int getMasserPhase() const { return 0; } diff --git a/apps/openmw/mwrender/sky.hpp b/apps/openmw/mwrender/sky.hpp index 54a32eb90c..1aae5126e4 100644 --- a/apps/openmw/mwrender/sky.hpp +++ b/apps/openmw/mwrender/sky.hpp @@ -25,7 +25,7 @@ namespace MWRender virtual void setHour (double hour) = 0; - virtual void setDay (int day) = 0; + virtual void setDate (int day, int month) = 0; virtual int getMasserPhase() const = 0; diff --git a/apps/openmw/mwscript/interpretercontext.cpp b/apps/openmw/mwscript/interpretercontext.cpp index 52cdea1f15..cc9d5f33bd 100644 --- a/apps/openmw/mwscript/interpretercontext.cpp +++ b/apps/openmw/mwscript/interpretercontext.cpp @@ -137,6 +137,8 @@ namespace MWScript mEnvironment.mWorld->setHour (value); else if (name=="day") mEnvironment.mWorld->setDay (value); + else if (name=="month") + mEnvironment.mWorld->setMonth (value); else mEnvironment.mWorld->getGlobalVariable (name).mShort = value; } @@ -147,6 +149,8 @@ namespace MWScript mEnvironment.mWorld->setHour (value); else if (name=="day") mEnvironment.mWorld->setDay (value); + else if (name=="month") + mEnvironment.mWorld->setMonth (value); else mEnvironment.mWorld->getGlobalVariable (name).mLong = value; } @@ -157,6 +161,8 @@ namespace MWScript mEnvironment.mWorld->setHour (value); else if (name=="day") mEnvironment.mWorld->setDay (value); + else if (name=="month") + mEnvironment.mWorld->setMonth (value); else mEnvironment.mWorld->getGlobalVariable (name).mFloat = value; } diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 7c806230a5..24bf27ea54 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -142,6 +142,27 @@ namespace MWWorld return 0; } + int World::getDaysPerMonth (int month) const + { + switch (month) + { + case 0: return 31; + case 1: return 28; + case 2: return 31; + case 3: return 30; + case 4: return 31; + case 5: return 30; + case 6: return 31; + case 7: return 31; + case 8: return 30; + case 9: return 31; + case 10: return 30; + case 11: return 31; + } + + throw std::runtime_error ("month out of range"); + } + World::World (OEngine::Render::OgreRenderer& renderer, const boost::filesystem::path& dataDir, const std::string& master, const std::string& startCell, bool newGame) : mSkyManager (0), mScene (renderer), mPlayerPos (0), mCurrentCell (0), mGlobalVariables (0), @@ -288,7 +309,13 @@ namespace MWWorld void World::advanceTime (double hours) { hours += mGlobalVariables->getFloat ("gamehour"); + setHour (hours); + + int days = hours / 24; + + if (days>0) + mGlobalVariables->setInt ("dayspassed", days + mGlobalVariables->getInt ("dayspassed")); } void World::setHour (double hour) @@ -305,33 +332,62 @@ namespace MWWorld mSkyManager->setHour (hour); if (days>0) - { - setDay (days + mGlobalVariables->getInt ("year")); - - days += mGlobalVariables->getInt ("dayspassed"); - mGlobalVariables->setInt ("dayspassed", days); - } + setDay (days + mGlobalVariables->getInt ("day")); } void World::setDay (int day) { if (day<0) day = 0; + + int month = mGlobalVariables->getInt ("month"); - int year = day / 365; - day = day % 365; - - mGlobalVariables->setInt ("day", day); - - mSkyManager->setDay (day); - - if (year>0) + while (true) { - year += mGlobalVariables->getInt ("year"); - mGlobalVariables->setInt ("year", year); - } + int days = getDaysPerMonth (month); + if (daysetInt ("year", mGlobalVariables->getInt ("year")+1); + } + + day -= days; + } + + mGlobalVariables->setInt ("day", day); + mGlobalVariables->setInt ("month", month); + + mSkyManager->setDate (day, month); } + void World::setMonth (int month) + { + if (month<0) + month = 0; + + int years = month / 12; + month = month % 12; + + int days = getDaysPerMonth (month); + + if (mGlobalVariables->getInt ("day")>=days) + mGlobalVariables->setInt ("day", days-1); + + mGlobalVariables->setInt ("month", month); + + if (years>0) + mGlobalVariables->setInt ("year", years+mGlobalVariables->getInt ("year")); + + mSkyManager->setDate (mGlobalVariables->getInt ("day"), month); + } + void World::toggleSky() { if (mSky) @@ -344,7 +400,8 @@ namespace MWWorld mSky = true; // TODO check for extorior or interior with sky. mSkyManager->setHour (mGlobalVariables->getFloat ("gamehour")); - mSkyManager->setDay (mGlobalVariables->getInt ("day")); + mSkyManager->setDate (mGlobalVariables->getInt ("day"), + mGlobalVariables->getInt ("month")); mSkyManager->enable(); } } diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index dda80054a1..cd12501bfb 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -63,6 +63,8 @@ namespace MWWorld MWRender::CellRender *searchRender (Ptr::CellStore *store); + int getDaysPerMonth (int month) const; + public: World (OEngine::Render::OgreRenderer& renderer, const boost::filesystem::path& master, @@ -97,6 +99,8 @@ namespace MWWorld void setHour (double hour); + void setMonth (int month); + void setDay (int day); void toggleSky();