Planeshift

weather.h

Go to the documentation of this file.
00001 
00002 #ifndef MODE_WEATHER_HEADER
00003 #define MODE_WEATHER_HEADER
00004 
00005 
00006 #include "isndsys/ss_structs.h"
00007 #include "isndsys/ss_data.h"
00008 #include "isndsys/ss_stream.h"
00009 #include "isndsys/ss_source.h"
00010 
00011 /* Defines for the various weather conditions. Some things may need to trigger on 
00012    a  'general' time of day. */
00013 enum WeatherConditions
00014 {
00015     WEATHER_ANY,
00016     WEATHER_CLEAR,
00017     WEATHER_RAIN,
00018     WEATHER_SNOW,
00019     WEATHER_FOG
00020 };
00021 
00022 enum WeatherSound
00023 {
00024     WEATHER_SOUND_CLEAR = 1,
00025     WEATHER_SOUND_RAIN_LIGHT,
00026     WEATHER_SOUND_RAIN_MEDIUM,
00027     WEATHER_SOUND_RAIN_HEAVY,
00028     WEATHER_SOUND_SNOW_LIGHT,
00029     WEATHER_SOUND_SNOW_HEAVY,
00030     WEATHER_SOUND_FOG
00031 };
00032 
00033 class WeatherObject;
00034 
00035 struct WeatherParams
00036 {
00037     int value;
00038     int fade_value;
00039     int fade_time;
00040 };
00041 
00042 
00044 struct WeatherInfo
00045 {
00046     csString sector;
00047     WeatherConditions downfall_condition;
00048     WeatherParams     downfall_params;
00049     WeatherConditions fog_condition;
00050     WeatherParams     fog_params;
00051 
00052     WeatherObject*    fog;
00053     
00054     int r,g,b;
00055 
00056     static void Fade(WeatherParams* wp, int delta);
00057 };
00058 
00059 //-----------------------------------------------------------------------------
00060 
00064 class WeatherObject
00065 {
00066 public:
00067     WeatherObject(WeatherInfo* parent);
00068     virtual ~WeatherObject();
00069 
00070     // General
00072     virtual void Destroy();
00073         
00074     virtual bool Valid();
00075     virtual void MoveTo(WeatherInfo* new_parent,iSector* sector);
00076     virtual void MoveTo(csVector3 pos);
00077     virtual void StartFollow();
00078     virtual void StopFollow();
00079     virtual iSector* GetSector();
00080     // If you use this function, you need to call SetupMesh and stuff like that too
00081     virtual void SetParent(WeatherInfo* new_parent) { parent = new_parent;}
00082     virtual WeatherInfo* GetParent() {return parent;}
00083     virtual void SetColor(float /*r*/, float /*g*/, float /*b*/){};
00084     virtual void Update(csTicks /*delta*/){};
00085     
00086     // Specific
00087     virtual bool CreateMesh() = 0;
00088     virtual void SetupMesh(csBox3 bbox) = 0;
00089     virtual WeatherSound GetWeatherSound()      { return WEATHER_SOUND_CLEAR; }
00090     virtual WeatherSound GetWeatherSoundForced(){ return WEATHER_SOUND_CLEAR; }
00091 
00092     virtual WeatherConditions GetType() { return WEATHER_ANY; }
00093 
00094     // Calculations
00095     //virtual float GetDensity(int drops) = 0;
00096     virtual csBox3 CreateDefaultBBox() = 0;
00097 
00098 protected:
00099 
00100     void RefreshSector(); // For flags
00101 
00102     // standard members
00103     csBox3                      bbox; // Used for sector movements
00104     WeatherInfo*                parent;
00105     csRef<iMeshWrapper>         mesh;
00106     csRef<iMeshFactoryWrapper>  mfw;
00107     csRef<iMaterialWrapper>     mat;
00108 
00109     //csRef<iSndSysSource>        weather_sound;  // looping background weather sound
00110 };
00111 
00112 class RainWeatherObject;
00113 class SnowWeatherObject;
00114 class FogWeatherObject;
00115 
00116 //-----------------------------------------------------------------------------
00117 
00118 
00120 class RainWeatherObject : public WeatherObject
00121 {
00122 public:
00123     RainWeatherObject(WeatherInfo* parent);
00124     virtual ~RainWeatherObject();
00125 
00126     void Destroy();
00127     void MoveTo(WeatherInfo* newParent,iSector* sector);
00128 
00129     bool CreateMesh();
00130     void SetupMesh(csBox3 bbox);
00131     void SetDrops(int drops);
00132 
00133     virtual void Update(csTicks delta);
00134     
00135     WeatherSound      GetWeatherSound();
00136     WeatherSound      GetWeatherSoundForced();
00137     WeatherConditions GetType() { return WEATHER_RAIN; }
00138 
00139     // Calculations
00140     static float GetDensity(int drops);
00141     csBox3 CreateDefaultBBox();
00142 };
00143 
00144 //-----------------------------------------------------------------------------
00145 
00147 class SnowWeatherObject : public WeatherObject
00148 {
00149 public:
00150     SnowWeatherObject(WeatherInfo* parent);
00151     virtual ~SnowWeatherObject();
00152 
00153     void Destroy();
00154     void MoveTo(WeatherInfo* newParent,iSector* sector);
00155 
00156     bool CreateMesh();
00157     void SetupMesh(csBox3 bbox);
00158     void SetDrops(int drops);
00159 
00160     virtual void Update(csTicks delta);
00161 
00162     WeatherSound      GetWeatherSound();
00163     WeatherSound      GetWeatherSoundForced();
00164     WeatherConditions GetType() { return WEATHER_SNOW; }
00165 
00166     // Calculations
00167     static float GetDensity(int drops);
00168     csBox3 CreateDefaultBBox();
00169 
00170 private:
00171     csRef<csShaderVariable> snowDensitySV;
00172     CS::ShaderVarStringID snowDensity;
00173 };
00174 
00175 //-----------------------------------------------------------------------------
00176 
00178 class FogWeatherObject : public WeatherObject
00179 {
00180 public:
00181     FogWeatherObject(WeatherInfo* parent);
00182     virtual ~FogWeatherObject();
00183 
00184     void Destroy();
00185     bool Valid();
00186     bool CreateMesh();
00187     void MoveTo(WeatherInfo* newParent,iSector* sector);
00188     void SetupMesh(csBox3 /*bbox*/){}
00189     iSector* GetSector();
00190 
00191     void MoveTo(csVector3 /*pos*/)  {}
00192     void StartFollow()          {}
00193     void StopFollow()           {}
00194 
00195     void SetColor(float r,float g,float b);
00196     virtual void Update(csTicks delta);
00197 
00198     WeatherSound      GetWeatherSound();
00199     WeatherSound      GetWeatherSoundForced();
00200     WeatherConditions GetType() { return WEATHER_FOG; }
00201 
00202     // Calculations
00203     static float GetDensity(int density);
00204     csBox3 CreateDefaultBBox()  {return csBox3(0,0,0,0,0,0); }
00205 
00206     WeatherInfo* GetWeatherInfo() { return parent;} // WeatherInfos are noremaly created for these objects
00207 private:
00208     bool applied;
00209 
00210     csColor color;
00211     iSector* sector;
00212 };
00213 
00214 #endif