]> git.mxchange.org Git - flightgear.git/blob - src/WeatherCM/FGThunderstorm.cpp
Updates by Christian Mayer.
[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 #include <stdlib.h>
39 #include <time.h>
40
41 #include <sg.h>
42
43 #include "FGThunderstorm.h"
44
45 /****************************************************************************/
46 /********************************** CODE ************************************/
47 /****************************************************************************/
48 FGThunderstorm::FGThunderstorm(const float n, const float e, const float s, const float w, const float p, const unsigned int seed)
49 {
50     northBorder = n;
51     eastBorder  = e;
52     southBorder = s;
53     westBorder  = w;
54
55     lightningProbability = p;
56     currentProbability = 0.0;
57
58     switch(seed)
59     {
60     case 0:
61         //a seed of 0 means that I have to initialize the seed myself
62         srand( (unsigned)time( NULL ) );
63         break;
64
65     case 1:
66         //a seed of 1 means that I must not initialize the seed
67         break;
68
69     default:
70         //any other seed means that I have to initialize with that seed
71         srand( seed );
72     }
73 }
74
75 FGThunderstorm::~FGThunderstorm(void)
76 {
77     //I don't need to do anything
78 }
79
80 void FGThunderstorm::update(const float dt)
81 {
82     //increase currentProbability by a value x that's 0.5 dt <= x <= 1.5 dt
83     currentProbability += dt * ( 0.5 - (float(rand())/RAND_MAX) );
84
85     if (currentProbability > lightningProbability)
86     {   //ok, I've got a lightning now
87
88         //figure out where the lightning is:
89         sgVec2 lightningPosition;
90         sgSetVec2( 
91             lightningPosition, 
92             southBorder + (northBorder - southBorder)*(float(rand())/RAND_MAX), 
93             westBorder  + (eastBorder  - westBorder )*(float(rand())/RAND_MAX)
94         );
95
96         //call OpenGl:
97         /* ... */
98
99         //call Sound:
100         /* ... */
101
102         //call Radio module:
103         /* ... */
104
105         currentProbability = 0.0;   //and begin again
106     }
107 }
108
109
110
111