OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
weather.hpp
Go to the documentation of this file.
1 #ifndef GAME_MWWORLD_WEATHER_H
2 #define GAME_MWWORLD_WEATHER_H
3 
4 #include <stdint.h>
5 #include <string>
6 #include <map>
7 
8 #include <osg/Vec4f>
9 
10 #include "../mwbase/soundmanager.hpp"
11 
12 #include "../mwrender/sky.hpp"
13 
14 namespace ESM
15 {
16  struct Region;
17  struct RegionWeatherState;
18  class ESMWriter;
19  class ESMReader;
20 }
21 
22 namespace MWRender
23 {
24  class RenderingManager;
25 }
26 
27 namespace Loading
28 {
29  class Listener;
30 }
31 
32 namespace Fallback
33 {
34  class Map;
35 }
36 
37 namespace MWWorld
38 {
39  class TimeStamp;
40 
41 
43  {
44  float mNightStart;
45  float mNightEnd;
46  float mDayStart;
47  float mDayEnd;
48  float mSunriseTime;
49  };
50 
53  template <typename T>
55  {
56  public:
57  TimeOfDayInterpolator(const T& sunrise, const T& day, const T& sunset, const T& night)
58  : mSunriseValue(sunrise), mDayValue(day), mSunsetValue(sunset), mNightValue(night)
59  {
60  }
61 
62  T getValue (const float gameHour, const TimeOfDaySettings& timeSettings) const;
63 
64  private:
66  };
67 
69  class Weather
70  {
71  public:
72  Weather(const std::string& name,
73  const Fallback::Map& fallback,
74  float stormWindSpeed,
75  float rainSpeed,
76  const std::string& particleEffect);
77 
78  std::string mCloudTexture;
79 
80  // Sky (atmosphere) color
82  // Fog color
84  // Ambient lighting color
86  // Sun (directional) lighting color
88 
89  // Fog depth/density
91 
92  // Color modulation for the sun itself during sunset
93  osg::Vec4f mSunDiscSunsetColor;
94 
95  // Used by scripts to animate signs, etc based on the wind (GetWindSpeed)
96  float mWindSpeed;
97 
98  // Cloud animation speed multiplier
99  float mCloudSpeed;
100 
101  // Value between 0 and 1, defines the strength of the sun glare effect.
102  // Also appears to modify how visible the sun, moons, and stars are for various weather effects.
103  float mGlareView;
104 
105  // Sound effect
106  // This is used for Blight, Ashstorm and Blizzard (Bloodmoon)
107  std::string mAmbientLoopSoundID;
108 
109  // Is this an ash storm / blight storm? If so, the following will happen:
110  // - The particles and clouds will be oriented so they appear to come from the Red Mountain.
111  // - Characters will animate their hand to protect eyes from the storm when looking in its direction (idlestorm animation)
112  // - Slower movement when walking against the storm (fStromWalkMult)
113  bool mIsStorm;
114 
115  // How fast does rain travel down?
116  // In Morrowind.ini this is set globally, but we may want to change it per weather later.
117  float mRainSpeed;
118 
119  // How often does a new rain mesh spawn?
121 
122  std::string mParticleEffect;
123 
124  std::string mRainEffect;
125 
126  // Note: For Weather Blight, there is a "Disease Chance" (=0.1) setting. But according to MWSFD this feature
127  // is broken in the vanilla game and was disabled.
128 
129  float transitionDelta() const;
130  float cloudBlendFactor(const float transitionRatio) const;
131 
132  float calculateThunder(const float transitionRatio, const float elapsedSeconds, const bool isPaused);
133 
134  private:
137 
138  // Note: In MW, only thunderstorms support these attributes, but in the interest of making weather more
139  // flexible, these settings are imported for all weather types. Only thunderstorms will normally have any
140  // non-zero values.
143  std::string mThunderSoundID[4];
145 
147 
148  void flashDecrement(const float elapsedSeconds);
149  float thunderChance(const float transitionRatio, const float elapsedSeconds) const;
150  void lightningAndThunder(void);
151  };
152 
155  {
156  public:
157  explicit RegionWeather(const ESM::Region& region);
158  explicit RegionWeather(const ESM::RegionWeatherState& state);
159 
160  operator ESM::RegionWeatherState() const;
161 
162  void setChances(const std::vector<char>& chances);
163 
164  void setWeather(int weatherID);
165 
166  int getWeather();
167 
168  private:
169  int mWeather;
170  std::vector<char> mChances;
171 
172  void chooseNewWeather();
173  };
174 
176  class MoonModel
177  {
178  public:
179  MoonModel(const std::string& name, const Fallback::Map& fallback);
180 
181  MWRender::MoonState calculateState(const TimeStamp& gameTime) const;
182 
183  private:
188  float mAxisOffset;
189  float mSpeed;
194 
195  float angle(const TimeStamp& gameTime) const;
196  float moonRiseHour(unsigned int daysPassed) const;
197  float rotation(float hours) const;
198  unsigned int phase(const TimeStamp& gameTime) const;
199  float shadowBlend(float angle) const;
200  float hourlyAlpha(float gameHour) const;
201  float earlyMoonShadowAlpha(float angle) const;
202  };
203 
206  {
207  public:
208  // Have to pass fallback and Store, can't use singleton since World isn't fully constructed yet at the time
210  const Fallback::Map& fallback,
211  MWWorld::ESMStore& store);
212  ~WeatherManager();
213 
219  void changeWeather(const std::string& regionID, const unsigned int weatherID);
220  void modRegion(const std::string& regionID, const std::vector<char>& chances);
221  void playerTeleported();
222 
228  void update(float duration, bool paused = false);
229 
230  void stopSounds();
231 
232  float getWindSpeed() const;
233 
235  bool isInStorm() const;
236 
237  osg::Vec3f getStormDirection() const;
238 
239  void advanceTime(double hours, bool incremental);
240 
241  unsigned int getWeatherID() const;
242 
244  bool isDark() const;
245 
246  void write(ESM::ESMWriter& writer, Loading::Listener& progress);
247 
248  bool readRecord(ESM::ESMReader& reader, uint32_t type);
249 
250  void clear();
251 
252  private:
256  float mSunsetTime;
260 
262 
263  // fading of night skydome
265 
267  float mRainSpeed;
268 
269  // underwater fog not really related to weather, but we handle it here because it's convenient
271 
272  std::vector<Weather> mWeatherSettings;
275 
276  float mWindSpeed;
277  bool mIsStorm;
278  osg::Vec3f mStormDirection;
279 
280  std::string mCurrentRegion;
281  float mTimePassed;
288  std::map<std::string, RegionWeather> mRegions;
290 
292  std::string mPlayingSoundID;
293 
294  void addWeather(const std::string& name,
295  const Fallback::Map& fallback,
296  const std::string& particleEffect = "");
297 
298  void importRegions();
299 
300  void regionalWeatherChanged(const std::string& regionID, RegionWeather& region);
301  bool updateWeatherTime();
302  bool updateWeatherRegion(const std::string& playerRegion);
303  void updateWeatherTransitions(const float elapsedRealSeconds);
304  void forceWeather(const int weatherID);
305 
306  bool inTransition();
307  void addWeatherTransition(const int weatherID);
308 
309  void calculateWeatherResult(const float gameHour, const float elapsedSeconds, const bool isPaused);
310  void calculateResult(const int weatherID, const float gameHour);
311  void calculateTransitionResult(const float factor, const float gameHour);
312  };
313 }
314 
315 #endif // GAME_MWWORLD_WEATHER_H
void addWeather(const std::string &name, const Fallback::Map &fallback, const std::string &particleEffect="")
Definition: weather.cpp:865
void calculateTransitionResult(const float factor, const float gameHour)
Definition: weather.cpp:1096
void calculateWeatherResult(const float gameHour, const float elapsedSeconds, const bool isPaused)
Definition: weather.cpp:1007
float mTransitionDelta
Definition: weather.hpp:135
TimeOfDayInterpolator< float > mNightFade
Definition: weather.hpp:264
float mMoonShadowEarlyFadeAngle
Definition: weather.hpp:193
osg::Vec4f mSunDiscSunsetColor
Definition: weather.hpp:93
void stopSounds()
Definition: weather.cpp:742
float mFadeInStart
Definition: weather.hpp:184
bool isDark() const
Definition: weather.cpp:778
float mWindSpeed
Definition: weather.hpp:276
float angle(const TimeStamp &gameTime) const
Definition: weather.cpp:366
TimeOfDayInterpolator< osg::Vec4f > mFogColor
Definition: weather.hpp:83
void setWeather(int weatherID)
Definition: weather.cpp:295
float mThunderThreshold
Definition: weather.hpp:142
void changeWeather(const std::string &regionID, const unsigned int weatherID)
Definition: weather.cpp:570
T getValue(const float gameHour, const TimeOfDaySettings &timeSettings) const
Definition: weather.cpp:47
float mRainSpeed
Definition: weather.hpp:117
std::vector< char > mChances
Definition: weather.hpp:170
float shadowBlend(float angle) const
Definition: weather.cpp:440
float mRainSpeed
Definition: weather.hpp:267
Definition: renderingmanager.hpp:63
Definition: sky.hpp:41
MoonModel mMasser
Definition: weather.hpp:273
T mNightValue
Definition: weather.hpp:65
Definition: esmreader.hpp:21
TimeOfDaySettings mTimeSettings
Definition: weather.hpp:261
int mNextWeather
Definition: weather.hpp:286
unsigned int phase(const TimeStamp &gameTime) const
Definition: weather.cpp:427
osg::Vec3f getStormDirection() const
Definition: weather.cpp:760
float mGlareView
Definition: weather.hpp:103
MWWorld::ESMStore & mStore
Definition: weather.hpp:253
MWBase::SoundPtr mAmbientSound
Definition: weather.hpp:291
contains settings imported from the Morrowind INI file.
Definition: fallback.hpp:12
unsigned int getWeatherID() const
Definition: weather.cpp:773
TimeOfDayInterpolator< float > mUnderwaterFog
Definition: weather.hpp:270
float mDayStart
Definition: weather.hpp:46
Definition: weather.hpp:54
MWRender::RenderingManager & mRendering
Definition: weather.hpp:254
TimeOfDayInterpolator< osg::Vec4f > mSkyColor
Definition: weather.hpp:81
float rotation(float hours) const
Definition: weather.cpp:419
MWRender::MoonState calculateState(const TimeStamp &gameTime) const
Definition: weather.cpp:351
osg::Vec3f mStormDirection
Definition: weather.hpp:278
Definition: loadregn.hpp:19
bool readRecord(ESM::ESMReader &reader, uint32_t type)
Definition: weather.cpp:809
MoonModel mSecunda
Definition: weather.hpp:274
float mSunsetTime
Definition: weather.hpp:256
Definition: loadinglistener.hpp:8
void clear()
Definition: weather.cpp:853
void playerTeleported()
Definition: weather.cpp:611
float mSunsetDuration
Definition: weather.hpp:258
void lightningAndThunder(void)
Definition: weather.cpp:229
float mNightStart
Definition: weather.hpp:44
bool mIsStorm
Definition: weather.hpp:277
bool inTransition()
Definition: weather.cpp:984
int mCurrentWeather
Definition: weather.hpp:285
std::map< std::string, RegionWeather > mRegions
Definition: weather.hpp:288
std::string mPlayingSoundID
Definition: weather.hpp:292
Definition: esmwriter.hpp:17
int mWeather
Definition: weather.hpp:169
Definition: sky.hpp:83
int getWeather()
Definition: weather.cpp:300
float mFlashBrightness
Definition: weather.hpp:146
float earlyMoonShadowAlpha(float angle) const
Definition: weather.cpp:482
Definition: esmstore.hpp:17
float mWeatherUpdateTime
Definition: weather.hpp:283
void updateWeatherTransitions(const float elapsedRealSeconds)
Definition: weather.cpp:932
int mQueuedWeather
Definition: weather.hpp:287
std::vector< Weather > mWeatherSettings
Definition: weather.hpp:272
TimeOfDayInterpolator(const T &sunrise, const T &day, const T &sunset, const T &night)
Definition: weather.hpp:57
std::string mAmbientLoopSoundID
Definition: weather.hpp:107
float mFadeOutStart
Definition: weather.hpp:186
float hourlyAlpha(float gameHour) const
Definition: weather.cpp:463
float mTransitionFactor
Definition: weather.hpp:284
TimeOfDayInterpolator< osg::Vec4f > mSunColor
Definition: weather.hpp:87
float mWindSpeed
Definition: weather.hpp:96
void regionalWeatherChanged(const std::string &regionID, RegionWeather &region)
Definition: weather.cpp:886
bool mIsStorm
Definition: weather.hpp:113
float moonRiseHour(unsigned int daysPassed) const
Definition: weather.cpp:405
MoonModel(const std::string &name, const Fallback::Map &fallback)
Definition: weather.cpp:334
float mFadeStartAngle
Definition: weather.hpp:191
T mDayValue
Definition: weather.hpp:65
A class that acts as a model for the moons.
Definition: weather.hpp:176
float mNightEnd
Definition: weather.hpp:45
float mDayEnd
Definition: weather.hpp:47
void calculateResult(const int weatherID, const float gameHour)
Definition: weather.cpp:1035
bool updateWeatherTime()
Definition: weather.cpp:899
In-game time stamp.
Definition: timestamp.hpp:14
float getWindSpeed() const
Definition: weather.cpp:750
std::string mCurrentRegion
Definition: weather.hpp:280
bool mFastForward
Definition: weather.hpp:282
float calculateThunder(const float transitionRatio, const float elapsedSeconds, const bool isPaused)
Definition: weather.cpp:187
bool updateWeatherRegion(const std::string &playerRegion)
Definition: weather.cpp:920
float mTimePassed
Definition: weather.hpp:281
Defines a single weather setting (according to INI)
Definition: weather.hpp:69
float mSpeed
Definition: weather.hpp:189
float mSunriseTime
Definition: weather.hpp:48
float mThunderFrequency
Definition: weather.hpp:141
float mFadeInFinish
Definition: weather.hpp:185
Definition: weatherstate.hpp:13
void addWeatherTransition(const int weatherID)
Definition: weather.cpp:989
float mFlashDecrement
Definition: weather.hpp:144
float mSunriseDuration
Definition: weather.hpp:257
bool isInStorm() const
Are we in an ash or blight storm?
Definition: weather.cpp:755
Interface for weather settings.
Definition: weather.hpp:205
void update(float duration, bool paused=false)
Definition: weather.cpp:628
float mFadeEndAngle
Definition: weather.hpp:192
~WeatherManager()
Definition: weather.cpp:565
std::string mThunderSoundID[4]
Definition: weather.hpp:143
float mDailyIncrement
Definition: weather.hpp:190
void write(ESM::ESMWriter &writer, Loading::Listener &progress)
Definition: weather.cpp:786
WeatherManager(MWRender::RenderingManager &rendering, const Fallback::Map &fallback, MWWorld::ESMStore &store)
Definition: weather.cpp:503
void advanceTime(double hours, bool incremental)
Definition: weather.cpp:765
T mSunsetValue
Definition: weather.hpp:65
float mCloudSpeed
Definition: weather.hpp:99
float cloudBlendFactor(const float transitionRatio) const
Definition: weather.cpp:181
float transitionDelta() const
Definition: weather.cpp:174
void importRegions()
Definition: weather.cpp:876
float mSunPreSunsetTime
Definition: weather.hpp:259
boost::shared_ptr< MWSound::Sound > SoundPtr
Definition: soundmanager.hpp:25
Definition: weather.hpp:42
RegionWeather(const ESM::Region &region)
Definition: weather.cpp:241
float thunderChance(const float transitionRatio, const float elapsedSeconds) const
Definition: weather.cpp:219
float mFadeOutFinish
Definition: weather.hpp:187
std::string mCloudTexture
Definition: weather.hpp:78
TimeOfDayInterpolator< osg::Vec4f > mAmbientColor
Definition: weather.hpp:85
std::string mRainEffect
Definition: weather.hpp:124
float mHoursBetweenWeatherChanges
Definition: weather.hpp:266
float mAxisOffset
Definition: weather.hpp:188
void chooseNewWeather()
Definition: weather.cpp:312
float mSunriseTime
Definition: weather.hpp:255
void flashDecrement(const float elapsedSeconds)
Definition: weather.cpp:211
std::string mParticleEffect
Definition: weather.hpp:122
void modRegion(const std::string &regionID, const std::vector< char > &chances)
Definition: weather.cpp:592
float mCloudsMaximumPercent
Definition: weather.hpp:136
T mSunriseValue
Definition: weather.hpp:65
MWRender::WeatherResult mResult
Definition: weather.hpp:289
float mRainFrequency
Definition: weather.hpp:120
TimeOfDayInterpolator< float > mLandFogDepth
Definition: weather.hpp:90
A class for storing a region's weather.
Definition: weather.hpp:154
const char * name
Definition: crashcatcher.cpp:59
Weather(const std::string &name, const Fallback::Map &fallback, float stormWindSpeed, float rainSpeed, const std::string &particleEffect)
Definition: weather.cpp:102
void setChances(const std::vector< char > &chances)
Definition: weather.cpp:275
void forceWeather(const int weatherID)
Definition: weather.cpp:976