From db78d15fc4d7329bc2531d00da24d53085bdec60 Mon Sep 17 00:00:00 2001
From: scrawl <scrawl@baseoftrash.de>
Date: Sun, 28 Apr 2013 05:29:34 +0200
Subject: [PATCH] Fix changeWeather

---
 apps/openmw/mwworld/weather.cpp | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/apps/openmw/mwworld/weather.cpp b/apps/openmw/mwworld/weather.cpp
index 3e8525312..d0ed835dc 100644
--- a/apps/openmw/mwworld/weather.cpp
+++ b/apps/openmw/mwworld/weather.cpp
@@ -289,7 +289,7 @@ void WeatherManager::update(float duration)
 
     if (exterior)
     {
-        std::string regionstr = MWBase::Environment::get().getWorld()->getPlayer().getPlayer().getCell()->mCell->mRegion;
+        std::string regionstr = Misc::StringUtils::lowerCase(MWBase::Environment::get().getWorld()->getPlayer().getPlayer().getCell()->mCell->mRegion);
         Misc::StringUtils::toLower(regionstr);
 
         if (mWeatherUpdateTime <= 0 || regionstr != mCurrentRegion)
@@ -621,6 +621,10 @@ unsigned int WeatherManager::getWeatherID() const
 
 void WeatherManager::changeWeather(const std::string& region, const unsigned int id)
 {
+    // make sure this region exists
+    const ESM::Region *reg =
+        MWBase::Environment::get().getWorld()->getStore().get<ESM::Region>().find(region);
+
     std::string weather;
     if (id==0)
         weather = "clear";
@@ -645,5 +649,9 @@ void WeatherManager::changeWeather(const std::string& region, const unsigned int
     else
         weather = "clear";
 
-    mRegionOverrides[region] = weather;
+    mRegionOverrides[Misc::StringUtils::lowerCase(region)] = weather;
+
+    std::string playerRegion = MWBase::Environment::get().getWorld()->getPlayer().getPlayer().getCell()->mCell->mRegion;
+    if (Misc::StringUtils::ciEqual(region, playerRegion))
+        setWeather(weather);
 }