1 /*****************************************************************************
3 Header: FGLocalWeatherDatabase.h
4 Author: Christian Mayer
7 -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) --------
9 This program is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free Software
11 Foundation; either version 2 of the License, or (at your option) any later
14 This program is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 You should have received a copy of the GNU General Public License along with
20 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21 Place - Suite 330, Boston, MA 02111-1307, USA.
23 Further information about the GNU General Public License can also be found on
24 the world wide web at http://www.gnu.org.
26 FUNCTIONAL DESCRIPTION
27 ------------------------------------------------------------------------------
28 Database for the local weather
29 This database is the only one that gets called from FG
32 ------------------------------------------------------------------------------
33 28.05.1999 Christian Mayer Created
34 16.06.1999 Durk Talsma Portability for Linux
35 20.06.1999 Christian Mayer added lots of consts
36 30.06.1999 Christian Mayer STL portability
37 11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's
39 19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D
40 and lots of wee code cleaning
41 14.12.1999 Christian Mayer Changed the internal structure to use Dave
42 Eberly's spherical interpolation code. This
43 stops our dependancy on the (ugly) voronoi
44 code and simplyfies the code structure a lot.
45 *****************************************************************************/
47 /****************************************************************************/
49 /****************************************************************************/
50 #ifndef FGLocalWeatherDatabase_H
51 #define FGLocalWeatherDatabase_H
53 /****************************************************************************/
55 /****************************************************************************/
62 #include "FGPhysicalProperties.h"
63 #include "FGPhysicalProperty.h"
66 #include "FGWeatherFeature.h"
67 #include "FGWeatherDefs.h"
68 #include "FGThunderstorm.h"
70 /****************************************************************************/
72 /****************************************************************************/
74 FG_USING_NAMESPACE(std);
76 /****************************************************************************/
77 /* CLASS DECLARATION */
78 /****************************************************************************/
79 class FGLocalWeatherDatabase
83 SphereInterpolate<FGPhysicalProperties> *database;
85 typedef vector<sgVec2> pointVector;
86 typedef vector<pointVector> tileVector;
88 /************************************************************************/
89 /* make tiles out of points on a 2D plane */
90 /************************************************************************/
91 WeatherPrecision WeatherVisibility; //how far do I need to simulate the
92 //local weather? Unit: metres
93 sgVec3 last_known_position;
95 bool Thunderstorm; //is there a thunderstorm near by?
96 FGThunderstorm *theThunderstorm; //pointer to the thunderstorm.
99 static FGLocalWeatherDatabase *theFGLocalWeatherDatabase;
101 enum DatabaseWorkingType {
102 use_global, //use global database for data !!obsolete!!
103 use_internet, //use the weather data that came from the internet
104 manual, //use only user inputs
105 distant, //use distant information, e.g. like LAN when used in
106 //a multiplayer environment
107 random, //generate weather randomly
108 default_mode //use only default values
111 DatabaseWorkingType DatabaseStatus;
113 void init( const WeatherPrecision visibility, const DatabaseWorkingType type );
115 /************************************************************************/
116 /* Constructor and Destructor */
117 /************************************************************************/
118 FGLocalWeatherDatabase(
119 const sgVec3& position,
120 const WeatherPrecision visibility = DEFAULT_WEATHER_VISIBILITY,
121 const DatabaseWorkingType type = PREFERED_WORKING_TYPE)
123 sgCopyVec3( last_known_position, position );
125 init( visibility, type );
127 theFGLocalWeatherDatabase = this;
130 FGLocalWeatherDatabase(
131 const WeatherPrecision position_lat,
132 const WeatherPrecision position_lon,
133 const WeatherPrecision position_alt,
134 const WeatherPrecision visibility = DEFAULT_WEATHER_VISIBILITY,
135 const DatabaseWorkingType type = PREFERED_WORKING_TYPE)
137 sgSetVec3( last_known_position, position_lat, position_lon, position_alt );
139 init( visibility, type );
141 theFGLocalWeatherDatabase = this;
144 ~FGLocalWeatherDatabase();
146 /************************************************************************/
147 /* reset the whole database */
148 /************************************************************************/
149 void reset(const DatabaseWorkingType type = PREFERED_WORKING_TYPE);
151 /************************************************************************/
152 /* update the database. Since the last call we had dt seconds */
153 /************************************************************************/
154 void update(const WeatherPrecision dt); //time has changed
155 void update(const sgVec3& p); //position has changed
156 void update(const sgVec3& p, const WeatherPrecision dt); //time and/or position has changed
158 /************************************************************************/
159 /* Get the physical properties on the specified point p */
160 /************************************************************************/
162 /* fix a problem with mw compilers in that they don't know the
163 difference between the next two methods. Since the first one
164 doesn't seem to be used anywhere, I commented it out. This is
165 supposed to be fixed in the forthcoming CodeWarrior Release
168 FGPhysicalProperties get(const sgVec2& p) const;
170 FGPhysicalProperty get(const sgVec3& p) const;
172 WeatherPrecision getAirDensity(const sgVec3& p) const;
174 /************************************************************************/
175 /* Add a weather feature at the point p and surrounding area */
176 /************************************************************************/
177 // !! Adds aren't supported anymore !!
179 void setSnowRainIntensity (const WeatherPrecision x, const sgVec2& p);
180 void setSnowRainType (const SnowRainType x, const sgVec2& p);
181 void setLightningProbability(const WeatherPrecision x, const sgVec2& p);
183 void setProperties(const FGPhysicalProperties2D& x); //change a property
185 /************************************************************************/
186 /* get/set weather visibility */
187 /************************************************************************/
188 void setWeatherVisibility(const WeatherPrecision visibility);
189 WeatherPrecision getWeatherVisibility(void) const;
191 /************************************************************************/
192 /* figure out if there's a thunderstorm that has to be taken care of */
193 /************************************************************************/
194 void updateThunderstorm(const float dt)
196 if (Thunderstorm == false)
199 theThunderstorm->update( dt );
203 extern FGLocalWeatherDatabase *WeatherDatabase;
204 void fgUpdateWeatherDatabase(void);
206 /****************************************************************************/
207 /* get/set weather visibility */
208 /****************************************************************************/
209 void inline FGLocalWeatherDatabase::setWeatherVisibility(const WeatherPrecision visibility)
211 if (visibility >= MINIMUM_WEATHER_VISIBILITY)
212 WeatherVisibility = visibility;
214 WeatherVisibility = MINIMUM_WEATHER_VISIBILITY;
217 WeatherPrecision inline FGLocalWeatherDatabase::getWeatherVisibility(void) const
219 return WeatherVisibility;
223 /****************************************************************************/
224 #endif /*FGLocalWeatherDatabase_H*/