Debian Codegraph @

Models/Weather/big_thunderstorm.xml

raw symbols SCIP
1 <?xml version="1.0"?>
2
3 <PropertyList>
4 <path>bigstorm-3d.ac</path>
5 <nasal>
6 <load>
7 <![CDATA[
8 #############################################################################
9 #
10 # Routines checking and adjusting weather close to AI thunderstorms
11 #
12 # Thorsten Renk, started Feb. 2010
13 #
14 #############################################################################
15
16 var transition = func {
17
18 var n_steps = 10;
19 var stepsize = 4000 / (n_steps - 1);
20
21 if (transition_flag == 1) {visibility = 5000 - transition_counter * stepsize;}
22 else if (transition_flag == 2) {visibility = 1000 + transition_counter * stepsize;}
23
24 var econfig_aloftNode = props.globals.getNode("environment/config/aloft", 1);
25 var entries_aloft = econfig_aloftNode.getChildren("entry");
26 foreach (var e; entries_aloft) {
27 var v = e.getNode("visibility-m");
28 v.setValue(visibility);
29 }
30
31 var econfig_boundaryNode = props.globals.getNode("environment/config/boundary", 1);
32 var entries_boundary = econfig_boundaryNode.getChildren("entry");
33 foreach (var e; entries_boundary) {
34 var v = e.getNode("visibility-m");
35 v.setValue(visibility);
36 }
37 fgcommand("reinit", props.Node.new({subsystem:"environment"}));
38 transition_counter = transition_counter + 1;
39 if (transition_counter < n_steps) {settimer(transition, 0.1);}
40 else {
41 transition_counter = 0;
42 if (transition_flag==1) {transition_flag = 2;setprop("ai/models/thunderstorm[0]/in-cloud",'true');}
43 else {transition_flag = 1; setprop("ai/models/thunderstorm[0]/in-cloud",'false');};
44 }
45 }
46
47
48 var store = func {
49
50 setprop("tmp/clouds/layer[0]/elevation-ft",getprop("environment/clouds/layer[0]/elevation-ft"));
51 setprop("tmp/metar/rain-norm",getprop("environment/metar/rain-norm"));
52 setprop("tmp/metar/snow-norm",getprop("environment/metar/snow-norm"));
53
54 var econfig_aloftNode = props.globals.getNode("environment/config/aloft", 1);
55 var entries_aloft = econfig_aloftNode.getChildren("entry");
56 var i = 0;
57 foreach (var e; entries_aloft) {
58 var v = e.getNode("visibility-m");
59 aloft_vis[i] = v.getValue();
60 i=i+1;
61 }
62
63
64 var econfig_boundaryNode = props.globals.getNode("environment/config/boundary", 1);
65 var entries_boundary = econfig_boundaryNode.getChildren("entry");
66 i = 0;
67 foreach (var e; entries_boundary) {
68 var v = e.getNode("visibility-m");
69 boundary_vis[i] = v.getValue();
70 i=i+1;
71 }
72
73 }
74
75 var reset = func {
76
77 setprop("environment/clouds/layer[0]/elevation-ft",getprop("tmp/clouds/layer[0]/elevation-ft"));
78 setprop("environment/metar/rain-norm",getprop("tmp/metar/rain-norm"));
79 setprop("environment/metar/snow-norm",getprop("tmp/metar/snow-norm"));
80
81 var econfig_aloftNode = props.globals.getNode("environment/config/aloft", 1);
82 var entries_aloft = econfig_aloftNode.getChildren("entry");
83 var i = 0;
84 foreach (var e; entries_aloft) {
85 var v = e.getNode("visibility-m");
86 v.setValue(aloft_vis[i]);
87 i = i + 1;
88 }
89
90
91 var econfig_boundaryNode = props.globals.getNode("environment/config/boundary", 1);
92 var entries_boundary = econfig_boundaryNode.getChildren("entry");
93 var i = 0;
94 foreach (var e; entries_boundary) {
95 var v = e.getNode("visibility-m");
96 v.setValue(boundary_vis[i]);
97 i = i + 1;
98 }
99
100 fgcommand("reinit", props.Node.new({subsystem:"environment"}));
101 }
102
103 var thunderstorm_loop = func {
104
105 var clat = getprop("position/latitude-deg");
106 var clong = getprop("position/longitude-deg");
107 var altitude=getprop("position/altitude-ft");
108 var ccart = geodtocart(clat,clong ,1000);
109
110 var cx = ccart[0];
111 var cy = ccart[1];
112
113 var slat = getprop("ai/models/thunderstorm[0]/position/latitude-deg");
114 var slong = getprop("ai/models/thunderstorm[0]/position/longitude-deg");
115 var scart = geodtocart(slat,slong ,1000);
116 var spos = geo.Coord.new().set_latlon(slat, slong);
117
118 var sx=scart[0];
119 var sy=scart[1];
120
121
122 var sdistance = ((cx-sx)*(cx-sx) + (cy-sy)*(cy-sy) + 0.01);
123
124 if (sdistance > 100.0)
125 {var distance = math.sqrt(sdistance);}
126 else
127 {var distance = 0.0;}
128
129 if ((distance < 3000) and (distance > 2000.0) and (altitude<38000))
130 {
131
132 if (flag==1) # store the original settings when entering cloud
133 {
134 store();
135 flag=2; # set flag to prevent further action
136 }
137
138
139 if (transition_flag==1)
140 {
141 transition();
142 }
143 else
144 {
145
146 setprop("environment/metar/rain-norm",getprop("tmp/metar/rain-norm"));
147 setprop("environment/metar/snow-norm",getprop("tmp/metar/snow-norm"));
148
149 var econfig_aloftNode = props.globals.getNode("environment/config/aloft", 1);
150 var entries_aloft = econfig_aloftNode.getChildren("entry");
151 foreach (var e; entries_aloft) {
152 var v = e.getNode("visibility-m");
153 v.setValue(1000);
154 }
155
156
157 var econfig_boundaryNode = props.globals.getNode("environment/config/boundary", 1);
158 var entries_boundary = econfig_boundaryNode.getChildren("entry");
159 foreach (var e; entries_boundary) {
160 var v = e.getNode("visibility-m");
161 v.setValue(1000);
162 }
163
164 fgcommand("reinit", props.Node.new({subsystem:"environment"}));
165 }
166 }
167 else if ((distance < 2000) and (distance > 0.0) and (altitude<38000))
168 {
169
170 setprop("environment/clouds/layer[0]/elevation-ft",20000);
171 if (altitude < 10000)
172 {
173 setprop("environment/metar/rain-norm",0.8);
174 setprop("environment/metar/snow-norm",0);
175 }
176 else if ((altitude < 20000) and (altitude > 10000))
177 {
178 setprop("environment/metar/rain-norm",0);
179 setprop("environment/metar/snow-norm",0.8);
180 }
181 else
182 {
183 setprop("environment/metar/rain-norm",0);
184 setprop("environment/metar/snow-norm",0);
185
186 }
187 if (altitude<5000)
188 {
189 var econfig_aloftNode = props.globals.getNode("environment/config/aloft", 1);
190 var entries_aloft = econfig_aloftNode.getChildren("entry");
191 foreach (var e; entries_aloft) {
192 var v = e.getNode("visibility-m");
193 v.setValue(1000);
194 }
195
196 var econfig_boundaryNode = props.globals.getNode("environment/config/boundary", 1);
197 var entries_boundary = econfig_boundaryNode.getChildren("entry");
198 foreach (var e; entries_boundary) {
199 var v = e.getNode("visibility-m");
200 v.setValue(1000);
201 }
202 fgcommand("reinit", props.Node.new({subsystem:"environment"}));
203 }
204 else
205 {
206 var econfig_aloftNode = props.globals.getNode("environment/config/aloft", 1);
207 var entries_aloft = econfig_aloftNode.getChildren("entry");
208 foreach (var e; entries_aloft) {
209 var v = e.getNode("visibility-m");
210 v.setValue(100);
211 }
212 var econfig_boundaryNode = props.globals.getNode("environment/config/boundary", 1);
213 var entries_boundary = econfig_boundaryNode.getChildren("entry");
214 foreach (var e; entries_boundary) {
215 var v = e.getNode("visibility-m");
216 v.setValue(1000);
217 }
218 fgcommand("reinit", props.Node.new({subsystem:"environment"}));
219 }
220 }
221
222 else # we're not in the cloud
223 {
224
225 if ((flag==2) and (transition_flag==2)) # and we just left the cloud
226 {
227 # restore cloud layer altitude before initializing transition
228 setprop("environment/clouds/layer[0]/elevation-ft",getprop("tmp/clouds/layer[0]/elevation-ft"));
229 transition();
230 }
231 else if (flag==2) # we have left the cloud, restore the original settings
232 {
233 reset();
234 flag = 1;
235 }
236
237 }
238
239 settimer(thunderstorm_loop, 1);
240 }
241
242
243
244 var thunderstorm_turning_loop = func {
245
246 var clat = getprop("position/latitude-deg");
247 var clong = getprop("position/longitude-deg");
248 var slat = getprop("ai/models/thunderstorm[0]/position/latitude-deg");
249 var slong = getprop("ai/models/thunderstorm[0]/position/longitude-deg");
250 var angle = math.mod(math.atan2(math.sin(slong-clong) * math.cos(slat), math.cos(clat) * math.sin(slat)- math.sin(clat) * math.cos(slat) * math.cos(slong-clong)), 2 * math.pi) * R2D;
251
252 setprop("ai/models/thunderstorm[0]/orientation/rotation-deg",90-angle-heading);
253
254 settimer(thunderstorm_turning_loop, 0.05);
255 }
256
257
258 var count_nodes = func {
259 var econfig_aloftNode = props.globals.getNode("environment/config/aloft", 1);
260 var entries_aloft = econfig_aloftNode.getChildren("entry");
261 foreach (var e; entries_aloft) {
262 naloft=naloft+1;
263 }
264
265 var econfig_boundaryNode = props.globals.getNode("environment/config/boundary", 1);
266 var entries_boundary = econfig_boundaryNode.getChildren("entry");
267 foreach (var e; entries_boundary) {
268 nboundary=nboundary+1;
269 }
270 setsize(aloft_vis,naloft);
271 setsize(boundary_vis,nboundary);
272 }
273
274
275
276 print("Starting thunderstorm routines...");
277 var flag = 1;
278 var transition_flag = 1;
279 var transition_counter = 0;
280 var aloft_vis=[];
281 var naloft=0;
282 var boundary_vis=[];
283 var nboundary=0;
284
285 var heading = getprop("ai/models/thunderstorm[0]/orientation/true-heading-deg");
286
287
288 setprop("ai/models/thunderstorm[0]/in-cloud",'false');
289
290 settimer(count_nodes,1);
291 settimer(thunderstorm_loop,1.5); # start loop
292 settimer(thunderstorm_turning_loop,1.5); # start alignment transformation
293
294 print("Done.");
295 ]]>
296 </load>
297
298 <unload>
299 <![CDATA[
300 print("Unloading thunderstorm routines!");
301 ]]>
302 </unload>
303 </nasal>
304
305 <!--<animation>
306 <type>billboard</type>
307 <spherical>false</spherical>
308 </animation> -->
309
310
311 <!--<animation>
312 <type>translate</type>
313 <property>orientation/rotation-deg</property>
314 <factor>1.0</factor>
315 <axis>
316 <x>0.0</x>
317 <y>0.0</y>
318 <z>1.0</z>
319 </axis>
320 </animation>-->
321
322 <animation>
323 <type>rotate</type>
324 <property>orientation/rotation-deg</property>
325 <factor>1.0</factor>
326 <axis>
327 <x>0</x>
328 <y>0</y>
329 <z>1</z>
330 </axis>
331 </animation>
332
333
334 <animation>
335 <type>select</type>
336 <object-name>lightning</object-name>
337
338 <condition>
339 <property>/environment/lightning/flash</property>
340 </condition>
341 </animation>
342
343 <animation>
344 <enable-hot type="bool">false</enable-hot>
345 </animation>
346
347 <animation>
348 <type>select</type>
349 <object-name>rain</object-name>
350 <object-name>main cloud layer</object-name>
351 <object-name>background cloud layer</object-name>
352 <object-name>foreground cloud layer</object-name>
353 <condition>
354 <not>
355 <property>in-cloud</property>
356 </not>
357 </condition>
358 </animation>
359
360 <!--<animation>
361 <type>select</type>
362 <object-name>rain</object-name>
363 <condition>
364 <not>
365 <property>in-cloud</property>
366 </not>
367 </condition>
368 </animation>-->
369
370 <!--
371 turning rain off during a lightning flash helps make
372 the flash more visible, but it's kind of cheezy :)
373 -->
374
375 <!--<animation>
376 <type>select</type>
377 <object-name>rain</object-name>
378 <condition>
379 <not>
380 <property>/environment/lightning/flash</property>
381 </not>
382 </condition>
383 </animation>-->
384
385
386 <animation>
387 <type>noshadow</type>
388 </animation>
389 </PropertyList>