From d77d5080bd0911286e76a8fdded01af60f795cbe Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 25 Feb 2012 21:34:38 +0100 Subject: [PATCH] implemented GetCurrentWeather script function --- apps/openmw/mwscript/docs/vmformat.txt | 3 ++- apps/openmw/mwscript/skyextensions.cpp | 16 +++++++++++++ apps/openmw/mwworld/weather.cpp | 32 ++++++++++++++++++++++++++ apps/openmw/mwworld/weather.hpp | 2 ++ apps/openmw/mwworld/world.cpp | 5 ++++ apps/openmw/mwworld/world.hpp | 2 ++ 6 files changed, 59 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index b1c5acb96e..cf9b00f006 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -119,4 +119,5 @@ op 0x200013b: twf op 0x200013c: FadeIn op 0x200013d: FadeOut op 0x200013e: FadeTo -opcodes 0x200013f-0x3ffffff unused +op 0x200013f: GetCurrentWeather +opcodes 0x2000140-0x3ffffff unused diff --git a/apps/openmw/mwscript/skyextensions.cpp b/apps/openmw/mwscript/skyextensions.cpp index caa07c0952..2c05d00111 100644 --- a/apps/openmw/mwscript/skyextensions.cpp +++ b/apps/openmw/mwscript/skyextensions.cpp @@ -79,12 +79,26 @@ namespace MWScript runtime.push (context.getWorld().getSecundaPhase()); } }; + + class OpGetCurrentWeather : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + InterpreterContext& context = + static_cast (runtime.getContext()); + + runtime.push (context.getWorld().getCurrentWeather()); + } + }; const int opcodeToggleSky = 0x2000021; const int opcodeTurnMoonWhite = 0x2000022; const int opcodeTurnMoonRed = 0x2000023; const int opcodeGetMasserPhase = 0x2000024; const int opcodeGetSecundaPhase = 0x2000025; + const int opcodeGetCurrentWeather = 0x200013f; void registerExtensions (Compiler::Extensions& extensions) { @@ -94,6 +108,7 @@ namespace MWScript extensions.registerInstruction ("turnmoonred", "", opcodeTurnMoonRed); extensions.registerFunction ("getmasserphase", 'l', "", opcodeGetMasserPhase); extensions.registerFunction ("getsecundaphase", 'l', "", opcodeGetSecundaPhase); + extensions.registerFunction ("getcurrentweather", 'l', "", opcodeGetCurrentWeather); } void installOpcodes (Interpreter::Interpreter& interpreter) @@ -103,6 +118,7 @@ namespace MWScript interpreter.installSegment5 (opcodeTurnMoonRed, new OpTurnMoonRed); interpreter.installSegment5 (opcodeGetMasserPhase, new OpGetMasserPhase); interpreter.installSegment5 (opcodeGetSecundaPhase, new OpGetSecundaPhase); + interpreter.installSegment5 (opcodeGetCurrentWeather, new OpGetCurrentWeather); } } } diff --git a/apps/openmw/mwworld/weather.cpp b/apps/openmw/mwworld/weather.cpp index f2d558852d..0a5a4a26fb 100644 --- a/apps/openmw/mwworld/weather.cpp +++ b/apps/openmw/mwworld/weather.cpp @@ -316,6 +316,9 @@ WeatherManager::WeatherManager(MWRender::RenderingManager* rendering, Environmen mWeatherSettings["blizzard"] = blizzard; setWeather("foggy", true); + + // const ESM::Region *region = + // context.getWorld().getStore().regions.find (cell->region); } void WeatherManager::setWeather(const String& weather, bool instant) @@ -661,3 +664,32 @@ void WeatherManager::setDate(const int day, const int month) mDay = day; mMonth = month; } + +unsigned int WeatherManager::getWeatherID() const +{ + // Source: http://www.uesp.net/wiki/Tes3Mod:GetCurrentWeather + + if (mCurrentWeather == "clear") + return 0; + else if (mCurrentWeather == "cloudy") + return 1; + else if (mCurrentWeather == "foggy") + return 2; + else if (mCurrentWeather == "overcast") + return 3; + else if (mCurrentWeather == "rain") + return 4; + else if (mCurrentWeather == "thunder") + return 5; + else if (mCurrentWeather == "ashstorm") + return 6; + else if (mCurrentWeather == "blight") + return 7; + else if (mCurrentWeather == "snow") + return 8; + else if (mCurrentWeather == "blizzard") + return 9; + + else + return 0; +} diff --git a/apps/openmw/mwworld/weather.hpp b/apps/openmw/mwworld/weather.hpp index 3451235047..8217acd407 100644 --- a/apps/openmw/mwworld/weather.hpp +++ b/apps/openmw/mwworld/weather.hpp @@ -233,6 +233,8 @@ namespace MWWorld void setDate(const int day, const int month); + unsigned int getWeatherID() const; + private: float mHour; int mDay, mMonth; diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index bb6498e2af..a1e2a253dc 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -736,6 +736,11 @@ namespace MWWorld return false; } + int World::getCurrentWeather() const + { + return mWeatherManager->getWeatherID(); + } + OEngine::Render::Fader* World::getFader() { return mRendering->getFader(); diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index 304d105fc4..46e55484cd 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -163,6 +163,8 @@ namespace MWWorld bool toggleSky(); ///< \return Resulting mode + + int getCurrentWeather() const; int getMasserPhase() const;