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 /****************************************************************************/
63 #include "FGPhysicalProperties.h"
64 #include "FGPhysicalProperty.h"
67 #include "FGWeatherFeature.h"
68 #include "FGWeatherDefs.h"
69 #include "FGThunderstorm.h"
71 /****************************************************************************/
73 /****************************************************************************/
76 FG_USING_NAMESPACE(std);
78 /****************************************************************************/
79 /* CLASS DECLARATION */
80 /****************************************************************************/
81 class FGLocalWeatherDatabase
85 SphereInterpolate<FGPhysicalProperties> *database;
87 typedef vector<sgVec2> pointVector;
88 typedef vector<pointVector> tileVector;
90 /************************************************************************/
91 /* make tiles out of points on a 2D plane */
92 /************************************************************************/
93 WeatherPrecision WeatherVisibility; //how far do I need to simulate the
94 //local weather? Unit: metres
95 sgVec3 last_known_position;
97 bool Thunderstorm; //is there a thunderstorm near by?
98 FGThunderstorm *theThunderstorm; //pointer to the thunderstorm.
101 static FGLocalWeatherDatabase *theFGLocalWeatherDatabase;
103 enum DatabaseWorkingType {
104 use_global, //use global database for data !!obsolete!!
105 use_internet, //use the weather data that came from the internet
106 manual, //use only user inputs
107 distant, //use distant information, e.g. like LAN when used in
108 //a multiplayer environment
109 random, //generate weather randomly
110 default_mode //use only default values
113 DatabaseWorkingType DatabaseStatus;
115 void init( const WeatherPrecision visibility,
116 const DatabaseWorkingType type,
117 const string &root );
119 /************************************************************************/
120 /* Constructor and Destructor */
121 /************************************************************************/
122 FGLocalWeatherDatabase(
123 const sgVec3& position,
125 const WeatherPrecision visibility = DEFAULT_WEATHER_VISIBILITY,
126 const DatabaseWorkingType type = PREFERED_WORKING_TYPE)
128 sgCopyVec3( last_known_position, position );
130 init( visibility, type, root );
132 theFGLocalWeatherDatabase = this;
135 FGLocalWeatherDatabase(
136 const WeatherPrecision position_lat,
137 const WeatherPrecision position_lon,
138 const WeatherPrecision position_alt,
140 const WeatherPrecision visibility = DEFAULT_WEATHER_VISIBILITY,
141 const DatabaseWorkingType type = PREFERED_WORKING_TYPE)
143 sgSetVec3( last_known_position, position_lat, position_lon, position_alt );
145 init( visibility, type, root );
147 theFGLocalWeatherDatabase = this;
150 ~FGLocalWeatherDatabase();
152 /************************************************************************/
153 /* reset the whole database */
154 /************************************************************************/
155 void reset(const DatabaseWorkingType type = PREFERED_WORKING_TYPE);
157 /************************************************************************/
158 /* update the database. Since the last call we had dt seconds */
159 /************************************************************************/
160 void update(const WeatherPrecision dt); //time has changed
161 void update(const sgVec3& p); //position has changed
162 void update(const sgVec3& p, const WeatherPrecision dt); //time and/or position has changed
164 /************************************************************************/
165 /* Get the physical properties on the specified point p */
166 /************************************************************************/
168 /* fix a problem with mw compilers in that they don't know the
169 difference between the next two methods. Since the first one
170 doesn't seem to be used anywhere, I commented it out. This is
171 supposed to be fixed in the forthcoming CodeWarrior Release
174 FGPhysicalProperties get(const sgVec2& p) const;
176 FGPhysicalProperty get(const sgVec3& p) const;
178 WeatherPrecision getAirDensity(const sgVec3& p) const;
180 /************************************************************************/
181 /* Add a weather feature at the point p and surrounding area */
182 /************************************************************************/
183 // !! Adds aren't supported anymore !!
185 void setSnowRainIntensity (const WeatherPrecision x, const sgVec2& p);
186 void setSnowRainType (const SnowRainType x, const sgVec2& p);
187 void setLightningProbability(const WeatherPrecision x, const sgVec2& p);
189 void setProperties(const FGPhysicalProperties2D& x); //change a property
191 /************************************************************************/
192 /* get/set weather visibility */
193 /************************************************************************/
194 void setWeatherVisibility(const WeatherPrecision visibility);
195 WeatherPrecision getWeatherVisibility(void) const;
197 /************************************************************************/
198 /* figure out if there's a thunderstorm that has to be taken care of */
199 /************************************************************************/
200 void updateThunderstorm(const float dt)
202 if (Thunderstorm == false)
205 theThunderstorm->update( dt );
209 extern FGLocalWeatherDatabase *WeatherDatabase;
210 void fgUpdateWeatherDatabase(void);
212 /****************************************************************************/
213 /* get/set weather visibility */
214 /****************************************************************************/
215 void inline FGLocalWeatherDatabase::setWeatherVisibility(const WeatherPrecision visibility)
217 if (visibility >= MINIMUM_WEATHER_VISIBILITY)
218 WeatherVisibility = visibility;
220 WeatherVisibility = MINIMUM_WEATHER_VISIBILITY;
223 WeatherPrecision inline FGLocalWeatherDatabase::getWeatherVisibility(void) const
225 return WeatherVisibility;
229 /****************************************************************************/
230 #endif /*FGLocalWeatherDatabase_H*/