weather.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. //******************************************************************************************
  2. // weather.h - This file contains the weather class header
  3. //
  4. // MechCommander 2
  5. //
  6. //---------------------------------------------------------------------------//
  7. // Copyright (C) Microsoft Corporation. All rights reserved. //
  8. //===========================================================================//
  9. #ifndef WEATHER_H
  10. #define WEATHER_H
  11. //----------------------------------------------------------------------------------
  12. // Include Files
  13. #ifndef MCLIB_H
  14. #include "mclib.h"
  15. #endif
  16. //----------------------------------------------------------------------------------
  17. // Macro Definitions
  18. #define BASE_RAIN_UPDATE_TIME 30.0f
  19. #define BASE_RAIN_HEIGHT 500.0f
  20. #define BASE_RAIN_LENGTH 10.0f
  21. #define BASE_RAIN_VEL 300.0f
  22. #define BASE_RAIN_TILT 10.0f
  23. #define BASE_RAIN_LIGHT_RATE 0.01f
  24. #define BASE_RAIN_RANDOM_POS_FACTOR 500.0f
  25. #define BASE_RAIN_RANDOM_HGT_FACTOR 250.0f
  26. #define BASE_RAIN_RANDOM_VEL_FACTOR 10.0f
  27. #define BASE_RAIN_RANDOM_LEN_FACTOR 10.0f
  28. #define BASE_LIGHTENING_CHANCE 0.03f
  29. #define BASE_LIGHTENING_FALLOFF 400.0f
  30. #define BASE_LIGHTENING_FLASH_AGAIN 2.0f
  31. #define BASE_LIGHTENING_FLASH_CHECK 1.0f
  32. #define BASE_THUNDER_RANDOM_START 5.0f
  33. //----------------------------------------------------------------------------------
  34. // Struct Definitions
  35. typedef struct _RainDrops
  36. {
  37. Stuff::Point3D position;
  38. float length;
  39. void init (void)
  40. {
  41. position.Zero();
  42. length = 0.0f;
  43. }
  44. } RainDrops;
  45. //----------------------------------------------------------------------------------
  46. // Class Definitions
  47. class Weather
  48. {
  49. protected:
  50. bool weatherActive; //Should we even bother calling update or render?
  51. float rainLevel; // How bad is it raining
  52. // This determines probability of thunder/lightening
  53. // how many drops we are drawing and how dark it is.
  54. // Levels are:
  55. // 0.0f Not raining.
  56. // >0.0f - <1.0f Threatening. Getting darker. Some ambient wind noise. Distant thunder.
  57. // >=1.0f - <1.2f Drizzle. ambient wind. No thunder.
  58. // >=1.2f - <2.0f Raining. Steady downpour. Not much thunder. Dark enough for lights.
  59. // >=2.0f - <3.0f Raining Hard. Some lightening/thunder. Full night conditions.
  60. // >=3.0f Storm. Lots of thunder/lightening. Full Night Conditions.
  61. float lighteningLevel; // Brightness of lightening this frame. Effects Ambient/sun lighting.
  62. float thunderTime; // Time until crack of thunder is heard.
  63. DWORD thunderSFX; // Sound Effect of thunder to play
  64. float lighteningCheck; // Interval between checks of lightening.
  65. float baseLighteningChance; // Base chance lightening will flash at each check.
  66. DWORD totalRainDrops; // Total number of drops I can draw.
  67. DWORD currentRainDrops; // Current number of drops in use.
  68. RainDrops* rainDrops; // Pointer to data for the drops.
  69. float rainTrend; // Either plus 1.0f or minus 1.0f. Based on raining more or less then it was.
  70. float rainFactor; // Increase/decrease in rainLevel per second based on rainTrend.
  71. float rainLightLevel; // Matches the rainLevel but moves slowly per frame slow light fades out.
  72. float rainUpdateTime; // Time until next RainTrend check in seconds.
  73. long baseRainChance; // Chance of it raining on any given rainUpdateTime.
  74. float oldFog; // Original FOGFull Height value.
  75. public:
  76. Weather (void)
  77. {
  78. init();
  79. }
  80. void init (void)
  81. {
  82. rainLevel = lighteningLevel = rainLightLevel = 0.0f;
  83. lighteningCheck = 1.0f;
  84. totalRainDrops = currentRainDrops = 0;
  85. rainTrend = 1.0f;
  86. rainFactor = 0.0f;
  87. rainUpdateTime = BASE_RAIN_UPDATE_TIME;
  88. baseRainChance = 0;
  89. rainDrops = NULL;
  90. thunderSFX = 0xffffffff;
  91. thunderTime = 0.0f;
  92. oldFog = 0.0f;
  93. weatherActive = false;
  94. }
  95. void destroy (void);
  96. ~Weather (void)
  97. {
  98. destroy();
  99. }
  100. void init (DWORD maxDrops, float startingRain, float baseRainChance, float baseLighteningChance = BASE_LIGHTENING_CHANCE);
  101. void init (FitIniFilePtr missionFile);
  102. void update (void);
  103. void render (void);
  104. void save (FitIniFile *file);
  105. void load (FitIniFile *file);
  106. };
  107. //----------------------------------------------------------------------------------
  108. extern Weather *weather;
  109. //----------------------------------------------------------------------------------
  110. #endif