OpenMW
apps/openmw/mwworld/weather.hpp
Go to the documentation of this file.
00001 #ifndef GAME_MWWORLD_WEATHER_H
00002 #define GAME_MWWORLD_WEATHER_H
00003 
00004 #include <OgreString.h>
00005 #include <OgreColourValue.h>
00006 
00007 namespace ESM
00008 {
00009     struct Region;
00010 }
00011 
00012 namespace MWRender
00013 {
00014     class RenderingManager;
00015 }
00016 
00017 namespace MWWorld
00018 {
00019     class Fallback;
00020 
00022     struct WeatherResult
00023     {
00024         Ogre::String mCloudTexture;
00025         Ogre::String mNextCloudTexture;
00026         float mCloudBlendFactor;
00027 
00028         Ogre::ColourValue mFogColor;
00029 
00030         Ogre::ColourValue mAmbientColor;
00031 
00032         Ogre::ColourValue mSkyColor;
00033 
00034         Ogre::ColourValue mSunColor;
00035 
00036         Ogre::ColourValue mSunDiscColor;
00037 
00038         float mFogDepth;
00039 
00040         float mWindSpeed;
00041 
00042         float mCloudSpeed;
00043 
00044         float mCloudOpacity;
00045 
00046         float mGlareView;
00047 
00048         bool mNight; // use night skybox
00049         float mNightFade; // fading factor for night skybox
00050 
00051         Ogre::String mAmbientLoopSoundID;
00052     };
00053 
00054 
00056     struct Weather
00057     {
00058         Ogre::String mCloudTexture;
00059 
00060         // Sky (atmosphere) colors
00061         Ogre::ColourValue   mSkySunriseColor,
00062                             mSkyDayColor,
00063                             mSkySunsetColor,
00064                             mSkyNightColor;
00065 
00066         // Fog colors
00067         Ogre::ColourValue   mFogSunriseColor,
00068                             mFogDayColor,
00069                             mFogSunsetColor,
00070                             mFogNightColor;
00071 
00072         // Ambient lighting colors
00073         Ogre::ColourValue   mAmbientSunriseColor,
00074                             mAmbientDayColor,
00075                             mAmbientSunsetColor,
00076                             mAmbientNightColor;
00077 
00078         // Sun (directional) lighting colors
00079         Ogre::ColourValue   mSunSunriseColor,
00080                             mSunDayColor,
00081                             mSunSunsetColor,
00082                             mSunNightColor;
00083 
00084         // Fog depth/density
00085         float   mLandFogDayDepth,
00086                 mLandFogNightDepth;
00087 
00088         // Color modulation for the sun itself during sunset (not completely sure)
00089         Ogre::ColourValue mSunDiscSunsetColor;
00090 
00091         // Duration of weather transition (in days)
00092         float mTransitionDelta;
00093 
00094         // No idea what this one is used for?
00095         float mWindSpeed;
00096 
00097         // Cloud animation speed multiplier
00098         float mCloudSpeed;
00099 
00100         // Multiplier for clouds transparency
00101         float mCloudsMaximumPercent;
00102 
00103         // Value between 0 and 1, defines the strength of the sun glare effect
00104         float mGlareView;
00105 
00106         // Sound effect
00107         // This is used for Blight, Ashstorm and Blizzard (Bloodmoon)
00108         Ogre::String mAmbientLoopSoundID;
00109 
00110         // Rain sound effect
00111         Ogre::String mRainLoopSoundID;
00112 
00114     };
00115 
00119     class WeatherManager
00120     {
00121     public:
00122         WeatherManager(MWRender::RenderingManager*,MWWorld::Fallback* fallback);
00123         ~WeatherManager();
00124 
00130         void changeWeather(const std::string& region, const unsigned int id);
00131         void switchToNextWeather(bool instantly = true);
00132 
00137         void update(float duration);
00138 
00139         void stopSounds(bool stopAll);
00140 
00141         void setHour(const float hour);
00142 
00143         float getWindSpeed() const;
00144 
00145         void setDate(const int day, const int month);
00146 
00147         void advanceTime(double hours)
00148         {
00149             mTimePassed += hours*3600;
00150         }
00151 
00152         unsigned int getWeatherID() const;
00153 
00154         void modRegion(const std::string &regionid, const std::vector<char> &chances);
00155 
00157         bool isDark() const;
00158 
00159     private:
00160         float mHour;
00161         int mDay, mMonth;
00162         float mWindSpeed;
00163         MWWorld::Fallback* mFallback;
00164         void setFallbackWeather(Weather& weather,const std::string& name);
00165         MWRender::RenderingManager* mRendering;
00166 
00167         std::map<Ogre::String, Weather> mWeatherSettings;
00168 
00169         std::map<std::string, std::string> mRegionOverrides;
00170 
00171         std::vector<std::string> mSoundsPlaying;
00172 
00173         Ogre::String mCurrentWeather;
00174         Ogre::String mNextWeather;
00175 
00176         std::string mCurrentRegion;
00177 
00178         bool mFirstUpdate;
00179 
00180         float mRemainingTransitionTime;
00181 
00182         float mThunderFlash;
00183         float mThunderChance;
00184         float mThunderChanceNeeded;
00185 
00186         double mTimePassed; // time passed since last update
00187 
00188         void transition(const float factor);
00189         void setResult(const Ogre::String& weatherType);
00190 
00191         float calculateHourFade (const std::string& moonName) const;
00192         float calculateAngleFade (const std::string& moonName, float angle) const;
00193 
00194         void setWeather(const Ogre::String& weatherType, bool instant=false);
00195         Ogre::String nextWeather(const ESM::Region* region) const;
00196         WeatherResult mResult;
00197 
00198         typedef std::map<std::string,std::vector<char> > RegionModMap;
00199         RegionModMap mRegionMods;
00200 
00201         float mSunriseTime;
00202         float mSunsetTime;
00203         float mSunriseDuration;
00204         float mSunsetDuration;
00205         float mWeatherUpdateTime;
00206         float mHoursBetweenWeatherChanges;
00207         float mThunderFrequency;
00208         float mThunderThreshold;
00209         float mThunderSoundDelay;
00210         float mNightStart;
00211         float mNightEnd;
00212         float mDayStart;
00213         float mDayEnd;
00214         std::string mThunderSoundID0;
00215         std::string mThunderSoundID1;
00216         std::string mThunderSoundID2;
00217         std::string mThunderSoundID3;
00218     };
00219 }
00220 
00221 #endif // GAME_MWWORLD_WEATHER_H