]> git.mxchange.org Git - flightgear.git/blob - src/WeatherCM/FGThunderstorm.cpp
Update from JSBSim
[flightgear.git] / src / WeatherCM / FGThunderstorm.cpp
1 /*****************************************************************************
2
3  Module:       FGThunderstorm.cpp
4  Author:       Christian Mayer
5  Date started: 02.11.99
6
7  -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) --------
8
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
12  version.
13
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
17  details.
18
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.
22
23  Further information about the GNU General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25
26 FUNCTIONAL DESCRIPTION
27 ------------------------------------------------------------------------------
28 Function that calls other parts of fg when a lightning has happened
29
30 HISTORY
31 ------------------------------------------------------------------------------
32 02.11.1999 Christian Mayer      Created
33 *****************************************************************************/
34
35 /****************************************************************************/
36 /* INCLUDES                                                                 */
37 /****************************************************************************/
38 #ifdef HAVE_CONFIG_H
39 #  include <config.h>
40 #endif
41
42 #include <simgear/compiler.h>
43
44 #include <stdlib.h>
45 #include <time.h>
46
47 #include <plib/sg.h>
48
49 #include "FGThunderstorm.h"
50
51 /****************************************************************************/
52 /********************************** CODE ************************************/
53 /****************************************************************************/
54 FGThunderstorm::FGThunderstorm(const float n, const float e, const float s, const float w, const float p, const unsigned int seed)
55 {
56     northBorder = n;
57     eastBorder  = e;
58     southBorder = s;
59     westBorder  = w;
60
61     lightningProbability = p;
62     currentProbability = 0.0;
63
64     switch(seed)
65     {
66     case 0:
67         //a seed of 0 means that I have to initialize the seed myself
68         srand( (unsigned)time( NULL ) );
69         break;
70
71     case 1:
72         //a seed of 1 means that I must not initialize the seed
73         break;
74
75     default:
76         //any other seed means that I have to initialize with that seed
77         srand( seed );
78     }
79 }
80
81 FGThunderstorm::~FGThunderstorm(void)
82 {
83     //I don't need to do anything
84 }
85
86 void FGThunderstorm::update(const float dt)
87 {
88     //increase currentProbability by a value x that's 0.5 dt <= x <= 1.5 dt
89     currentProbability += dt * ( 0.5 - (float(rand())/RAND_MAX) );
90
91     if (currentProbability > lightningProbability)
92     {   //ok, I've got a lightning now
93
94         //figure out where the lightning is:
95         sgVec2 lightningPosition;
96         sgSetVec2( 
97             lightningPosition, 
98             southBorder + (northBorder - southBorder)*(float(rand())/RAND_MAX), 
99             westBorder  + (eastBorder  - westBorder )*(float(rand())/RAND_MAX)
100         );
101
102         //call OpenGl:
103         /* ... */
104
105         //call Sound:
106         /* ... */
107
108         //call Radio module:
109         /* ... */
110
111         currentProbability = 0.0;   //and begin again
112     }
113 }
114
115
116
117