]> git.mxchange.org Git - flightgear.git/blob - src/Main/fg_commands.cxx
cosmetic changes *only*:
[flightgear.git] / src / Main / fg_commands.cxx
1 // fg_commands.cxx - internal FGFS commands.
2
3 #ifdef HAVE_CONFIG_H
4 #  include "config.h"
5 #endif
6
7 #include <string.h>             // strcmp()
8
9 #include <simgear/compiler.h>
10
11 #include STL_STRING
12 #include STL_FSTREAM
13
14 #include <simgear/sg_inlines.h>
15 #include <simgear/debug/logstream.hxx>
16 #include <simgear/math/sg_random.h>
17 #include <simgear/scene/material/mat.hxx>
18 #include <simgear/structure/exception.hxx>
19 #include <simgear/structure/commands.hxx>
20 #include <simgear/props/props.hxx>
21
22 #include <Cockpit/panel.hxx>
23 #include <Cockpit/panel_io.hxx>
24 #include <Cockpit/hud.hxx>
25 #include <Environment/environment.hxx>
26 #include <FDM/flight.hxx>
27 #include <GUI/gui.h>
28 #include <GUI/new_gui.hxx>
29 #include <GUI/dialog.hxx>
30 #include <Aircraft/replay.hxx>
31 #include <Scenery/tilemgr.hxx>
32 #include <Scenery/scenery.hxx>
33 #include <Scripting/NasalSys.hxx>
34 #include <Sound/fg_fx.hxx>
35 #include <Time/sunsolver.hxx>
36 #include <Time/tmp.hxx>
37
38 #include "fg_init.hxx"
39 #include "fg_io.hxx"
40 #include "fg_commands.hxx"
41 #include "fg_props.hxx"
42 #include "globals.hxx"
43 #include "logger.hxx"
44 #include "util.hxx"
45 #include "viewmgr.hxx"
46 #include "main.hxx"
47
48 SG_USING_STD(string);
49 SG_USING_STD(ifstream);
50 SG_USING_STD(ofstream);
51
52
53 \f
54 ////////////////////////////////////////////////////////////////////////
55 // Static helper functions.
56 ////////////////////////////////////////////////////////////////////////
57
58
59 static inline SGPropertyNode *
60 get_prop (const SGPropertyNode * arg)
61 {
62     return fgGetNode(arg->getStringValue("property[0]", "/null"), true);
63 }
64
65 static inline SGPropertyNode *
66 get_prop2 (const SGPropertyNode * arg)
67 {
68     return fgGetNode(arg->getStringValue("property[1]", "/null"), true);
69 }
70
71
72 /**
73  * Get a double value and split it as required.
74  */
75 static void
76 split_value (double full_value, const char * mask,
77              double * unmodifiable, double * modifiable)
78 {
79     if (!strcmp("integer", mask)) {
80         *modifiable = (full_value < 0 ? ceil(full_value) : floor (full_value));
81         *unmodifiable = full_value - *modifiable;
82     } else if (!strcmp("decimal", mask)) {
83         *unmodifiable = (full_value < 0 ? ceil(full_value) : floor(full_value));
84         *modifiable = full_value - *unmodifiable;
85     } else {
86         if (strcmp("all", mask))
87             SG_LOG(SG_GENERAL, SG_ALERT, "Bad value " << mask << " for mask;"
88                    << " assuming 'all'");
89         *unmodifiable = 0;
90         *modifiable = full_value;
91     }
92 }
93
94
95 /**
96  * Clamp or wrap a value as specified.
97  */
98 static void
99 limit_value (double * value, const SGPropertyNode * arg)
100 {
101     const SGPropertyNode * min_node = arg->getChild("min");
102     const SGPropertyNode * max_node = arg->getChild("max");
103
104     bool wrap = arg->getBoolValue("wrap");
105
106     if (min_node == 0 || max_node == 0)
107         wrap = false;
108   
109     if (wrap) {                 // wrap such that min <= x < max
110         double min_val = min_node->getDoubleValue();
111         double max_val = max_node->getDoubleValue();
112         double resolution = arg->getDoubleValue("resolution");
113         if (resolution > 0.0) {
114             // snap to (min + N*resolution), taking special care to handle imprecision
115             int n = (int)floor((*value - min_val) / resolution + 0.5);
116             int steps = (int)floor((max_val - min_val) / resolution + 0.5);
117             SG_NORMALIZE_RANGE(n, 0, steps);
118             *value = min_val + resolution * n;
119         } else {
120             // plain circular wrapping
121             SG_NORMALIZE_RANGE(*value, min_val, max_val);
122         }
123     } else {                    // clamp such that min <= x <= max
124         if ((min_node != 0) && (*value < min_node->getDoubleValue()))
125             *value = min_node->getDoubleValue();
126         else if ((max_node != 0) && (*value > max_node->getDoubleValue()))
127             *value = max_node->getDoubleValue();
128     }
129 }
130
131 static bool
132 compare_values (SGPropertyNode * value1, SGPropertyNode * value2)
133 {
134     switch (value1->getType()) {
135     case SGPropertyNode::BOOL:
136         return (value1->getBoolValue() == value2->getBoolValue());
137     case SGPropertyNode::INT:
138         return (value1->getIntValue() == value2->getIntValue());
139     case SGPropertyNode::LONG:
140         return (value1->getLongValue() == value2->getLongValue());
141     case SGPropertyNode::FLOAT:
142         return (value1->getFloatValue() == value2->getFloatValue());
143     case SGPropertyNode::DOUBLE:
144         return (value1->getDoubleValue() == value2->getDoubleValue());
145     default:
146         return !strcmp(value1->getStringValue(), value2->getStringValue());
147     }
148 }
149
150
151 \f
152 ////////////////////////////////////////////////////////////////////////
153 // Command implementations.
154 ////////////////////////////////////////////////////////////////////////
155
156
157 /**
158  * Built-in command: do nothing.
159  */
160 static bool
161 do_null (const SGPropertyNode * arg)
162 {
163   return true;
164 }
165
166 /**
167  * Built-in command: run a Nasal script.
168  */
169 static bool
170 do_nasal (const SGPropertyNode * arg)
171 {
172     return ((FGNasalSys*)globals->get_subsystem("nasal"))->handleCommand(arg);
173 }
174
175 /**
176  * Built-in command: exit FlightGear.
177  *
178  * status: the exit status to return to the operating system (defaults to 0)
179  */
180 static bool
181 do_exit (const SGPropertyNode * arg)
182 {
183     SG_LOG(SG_INPUT, SG_INFO, "Program exit requested.");
184     fgSetBool("/sim/signals/exit", true);
185
186     if (fgGetBool("/sim/startup/save-on-exit")) {
187 #ifdef _MSC_VER
188         char* envp = ::getenv( "APPDATA" );
189         if ( envp != NULL ) {
190             SGPath config( envp );
191             config.append( "flightgear.org" );
192 #else
193         if ( homedir != NULL ) {
194             SGPath config( homedir );
195             config.append( ".fgfs" );
196 #endif
197             config.append( "autosave.xml" );
198             config.create_dir( 0700 );
199             SG_LOG(SG_IO, SG_INFO, "Saving user settings to " << config.str());
200             try {
201                 writeProperties(config.str(), globals->get_props(), false, SGPropertyNode::USERARCHIVE);
202             } catch (const sg_exception &e) {
203                 guiErrorMessage("Error writing autosave.xml: ", e);
204             }
205
206             SG_LOG(SG_INPUT, SG_DEBUG, "Finished Saving user settings");
207         }
208     }
209     fgExit(arg->getIntValue("status", 0));
210     return true;
211 }
212
213
214 /**
215  * Built-in command: reinitialize one or more subsystems.
216  *
217  * subsystem[*]: the name(s) of the subsystem(s) to reinitialize; if
218  * none is specified, reinitialize all of them.
219  */
220 static bool
221 do_reinit (const SGPropertyNode * arg)
222 {
223     bool result = true;
224
225     vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
226     if (subsystems.size() == 0) {
227         globals->get_subsystem_mgr()->reinit();
228     } else {
229         for ( unsigned int i = 0; i < subsystems.size(); i++ ) {
230             const char * name = subsystems[i]->getStringValue();
231             SGSubsystem * subsystem = globals->get_subsystem(name);
232             if (subsystem == 0) {
233                 result = false;
234                 SG_LOG( SG_GENERAL, SG_ALERT,
235                         "Subsystem " << name << "not found" );
236             } else {
237                 subsystem->reinit();
238             }
239         }
240     }
241
242     globals->get_event_mgr()->reinit();
243
244     return result;
245 }
246
247 #if 0
248   //
249   // these routines look useful ??? but are never used in the code ???
250   //
251
252 /**
253  * Built-in command: suspend one or more subsystems.
254  *
255  * subsystem[*] - the name(s) of the subsystem(s) to suspend.
256  */
257 static bool
258 do_suspend (const SGPropertyNode * arg)
259 {
260     bool result = true;
261
262     vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
263     for ( unsigned int i = 0; i < subsystems.size(); i++ ) {
264         const char * name = subsystems[i]->getStringValue();
265         SGSubsystem * subsystem = globals->get_subsystem(name);
266         if (subsystem == 0) {
267             result = false;
268             SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << "not found");
269         } else {
270             subsystem->suspend();
271         }
272     }
273     return result;
274 }
275
276 /**
277  * Built-in command: suspend one or more subsystems.
278  *
279  * subsystem[*] - the name(s) of the subsystem(s) to suspend.
280  */
281 static bool
282 do_resume (const SGPropertyNode * arg)
283 {
284     bool result = true;
285
286     vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
287     for ( unsigned int i = 0; i < subsystems.size(); i++ ) {
288         const char * name = subsystems[i]->getStringValue();
289         SGSubsystem * subsystem = globals->get_subsystem(name);
290         if (subsystem == 0) {
291             result = false;
292             SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << "not found");
293         } else {
294             subsystem->resume();
295         }
296     }
297     return result;
298 }
299
300 #endif
301
302
303 /**
304  * Built-in command: load flight.
305  *
306  * file (optional): the name of the file to load (relative to current
307  *   directory).  Defaults to "fgfs.sav"
308  */
309 static bool
310 do_load (const SGPropertyNode * arg)
311 {
312   const string &file = arg->getStringValue("file", "fgfs.sav");
313   ifstream input(file.c_str());
314   if (input.good() && fgLoadFlight(input)) {
315     input.close();
316     SG_LOG(SG_INPUT, SG_INFO, "Restored flight from " << file);
317     return true;
318   } else {
319     SG_LOG(SG_INPUT, SG_WARN, "Cannot load flight from " << file);
320     return false;
321   }
322 }
323
324
325 /**
326  * Built-in command: save flight.
327  *
328  * file (optional): the name of the file to save (relative to the
329  * current directory).  Defaults to "fgfs.sav".
330  */
331 static bool
332 do_save (const SGPropertyNode * arg)
333 {
334   const string &file = arg->getStringValue("file", "fgfs.sav");
335   bool write_all = arg->getBoolValue("write-all", false);
336   SG_LOG(SG_INPUT, SG_INFO, "Saving flight");
337   ofstream output(file.c_str());
338   if (output.good() && fgSaveFlight(output, write_all)) {
339     output.close();
340     SG_LOG(SG_INPUT, SG_INFO, "Saved flight to " << file);
341     return true;
342   } else {
343     SG_LOG(SG_INPUT, SG_ALERT, "Cannot save flight to " << file);
344     return false;
345   }
346 }
347
348
349 /**
350  * Built-in command: (re)load the panel.
351  *
352  * path (optional): the file name to load the panel from 
353  * (relative to FG_ROOT).  Defaults to the value of /sim/panel/path,
354  * and if that's unspecified, to "Panels/Default/default.xml".
355  */
356 static bool
357 do_panel_load (const SGPropertyNode * arg)
358 {
359   string panel_path =
360     arg->getStringValue("path",
361                         fgGetString("/sim/panel/path",
362                                     "Panels/Default/default.xml"));
363   FGPanel * new_panel = fgReadPanel(panel_path);
364   if (new_panel == 0) {
365     SG_LOG(SG_INPUT, SG_ALERT,
366            "Error reading new panel from " << panel_path);
367     return false;
368   }
369   SG_LOG(SG_INPUT, SG_INFO, "Loaded new panel from " << panel_path);
370   globals->get_current_panel()->unbind();
371   delete globals->get_current_panel();
372   globals->set_current_panel( new_panel );
373   globals->get_current_panel()->bind();
374   return true;
375 }
376
377
378 /**
379  * Built-in command: pass a mouse click to the panel.
380  *
381  * button: the mouse button number, zero-based.
382  * is-down: true if the button is down, false if it is up.
383  * x-pos: the x position of the mouse click.
384  * y-pos: the y position of the mouse click.
385  */
386 static bool
387 do_panel_mouse_click (const SGPropertyNode * arg)
388 {
389   if (globals->get_current_panel() != 0)
390     return globals->get_current_panel()
391       ->doMouseAction(arg->getIntValue("button"),
392                       arg->getBoolValue("is-down") ? PU_DOWN : PU_UP,
393                       arg->getIntValue("x-pos"),
394                       arg->getIntValue("y-pos"));
395   else
396     return false;
397 }
398
399
400 /**
401  * Built-in command: (re)load preferences.
402  *
403  * path (optional): the file name to load the panel from (relative
404  * to FG_ROOT). Defaults to "preferences.xml".
405  */
406 static bool
407 do_preferences_load (const SGPropertyNode * arg)
408 {
409   try {
410     fgLoadProps(arg->getStringValue("path", "preferences.xml"),
411                 globals->get_props());
412   } catch (const sg_exception &e) {
413     guiErrorMessage("Error reading global preferences: ", e);
414     return false;
415   }
416   SG_LOG(SG_INPUT, SG_INFO, "Successfully read global preferences.");
417   return true;
418 }
419
420
421 static void
422 fix_hud_visibility()
423 {
424   if ( !strcmp(fgGetString("/sim/flight-model"), "ada") ) {
425       globals->get_props()->setBoolValue( "/sim/hud/visibility", true );
426       if ( globals->get_viewmgr()->get_current() == 1 ) {
427           globals->get_props()->setBoolValue( "/sim/hud/visibility", false );
428       }
429   }
430 }
431
432 static void
433 do_view_next( bool )
434 {
435     globals->get_current_view()->setHeadingOffset_deg(0.0);
436     globals->get_viewmgr()->next_view();
437     fix_hud_visibility();
438 }
439
440 static void
441 do_view_prev( bool )
442 {
443     globals->get_current_view()->setHeadingOffset_deg(0.0);
444     globals->get_viewmgr()->prev_view();
445     fix_hud_visibility();
446 }
447
448 /**
449  * Built-in command: cycle view.
450  */
451 static bool
452 do_view_cycle (const SGPropertyNode * arg)
453 {
454   globals->get_current_view()->setHeadingOffset_deg(0.0);
455   globals->get_viewmgr()->next_view();
456   fix_hud_visibility();
457   return true;
458 }
459
460 /**
461  * Built-in command: capture screen.
462  */
463 static bool
464 do_screen_capture (const SGPropertyNode * arg)
465 {
466   return fgDumpSnapShot();
467 }
468
469 static bool
470 do_dump_scene_graph (const SGPropertyNode*)
471 {
472     fgDumpSceneGraph();
473     return true;
474 }
475
476 static bool
477 do_dump_terrain_branch (const SGPropertyNode*)
478 {
479     fgDumpTerrainBranch();
480
481     double lon_deg = fgGetDouble("/position/longitude-deg");
482     double lat_deg = fgGetDouble("/position/latitude-deg");
483     SGGeod geodPos = SGGeod::fromDegFt(lon_deg, lat_deg, 0.0);
484     SGVec3d zero = SGVec3d::fromGeod(geodPos);
485
486     SG_LOG(SG_INPUT, SG_INFO, "Model parameters:");
487     SG_LOG(SG_INPUT, SG_INFO, "Center: " << zero.x() << ", " << zero.y() << ", " << zero.z() );
488     SG_LOG(SG_INPUT, SG_INFO, "Rotation: " << lat_deg << ", " << lon_deg );
489
490     return true;
491 }
492
493 /**
494  * Built-in command: hires capture screen.
495  */
496 static bool
497 do_hires_screen_capture (const SGPropertyNode * arg)
498 {
499   fgHiResDump();
500   return true;
501 }
502
503
504 /**
505  * Reload the tile cache.
506  */
507 static bool
508 do_tile_cache_reload (const SGPropertyNode * arg)
509 {
510     static const SGPropertyNode *master_freeze
511         = fgGetNode("/sim/freeze/master");
512     bool freeze = master_freeze->getBoolValue();
513     SG_LOG(SG_INPUT, SG_INFO, "ReIniting TileCache");
514     if ( !freeze ) {
515         fgSetBool("/sim/freeze/master", true);
516     }
517     if ( globals->get_tile_mgr()->init() ) {
518         // Load the local scenery data
519         double visibility_meters = fgGetDouble("/environment/visibility-m");
520         globals->get_tile_mgr()->update( visibility_meters );
521     } else {
522         SG_LOG( SG_GENERAL, SG_ALERT, 
523                 "Error in Tile Manager initialization!" );
524         exit(-1);
525     }
526     if ( !freeze ) {
527         fgSetBool("/sim/freeze/master", false);
528     }
529     return true;
530 }
531
532
533 /**
534  * Set the sea level outside air temperature and assigning that to all
535  * boundary and aloft environment layers.
536  */
537 static bool
538 do_set_sea_level_degc (const SGPropertyNode * arg)
539 {
540     double temp_sea_level_degc = arg->getDoubleValue("temp-degc", 15.0);
541
542     SGPropertyNode *node, *child;
543
544     // boundary layers
545     node = fgGetNode( "/environment/config/boundary" );
546     if ( node != NULL ) {
547       int i = 0;
548       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
549         child->setDoubleValue( "temperature-sea-level-degc",
550                                temp_sea_level_degc );
551         ++i;
552       }
553     }
554
555     // aloft layers
556     node = fgGetNode( "/environment/config/aloft" );
557     if ( node != NULL ) {
558       int i = 0;
559       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
560         child->setDoubleValue( "temperature-sea-level-degc",
561                                temp_sea_level_degc );
562         ++i;
563       }
564     }
565
566     return true;
567 }
568
569
570 /**
571  * Set the outside air temperature at the "current" altitude by first
572  * calculating the corresponding sea level temp, and assigning that to
573  * all boundary and aloft environment layers.
574  */
575 static bool
576 do_set_oat_degc (const SGPropertyNode * arg)
577 {
578     const string &temp_str = arg->getStringValue("temp-degc", "15.0");
579
580     // check for an altitude specified in the arguments, otherwise use
581     // current aircraft altitude.
582     const SGPropertyNode *altitude_ft = arg->getChild("altitude-ft");
583     if ( altitude_ft == NULL ) {
584         altitude_ft = fgGetNode("/position/altitude-ft");
585     }
586
587     FGEnvironment dummy;        // instantiate a dummy so we can leech a method
588     dummy.set_elevation_ft( altitude_ft->getDoubleValue() );
589     dummy.set_temperature_degc( atof( temp_str.c_str() ) );
590     double temp_sea_level_degc = dummy.get_temperature_sea_level_degc();
591
592     //cout << "Altitude = " << altitude_ft->getDoubleValue() << endl;
593     //cout << "Temp at alt (C) = " << atof( temp_str.c_str() ) << endl;
594     //cout << "Temp sea level (C) = " << temp_sea_level_degc << endl;
595  
596     SGPropertyNode *node, *child;
597
598     // boundary layers
599     node = fgGetNode( "/environment/config/boundary" );
600     if ( node != NULL ) {
601       int i = 0;
602       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
603         child->setDoubleValue( "temperature-sea-level-degc",
604                                temp_sea_level_degc );
605         ++i;
606       }
607     }
608
609     // aloft layers
610     node = fgGetNode( "/environment/config/aloft" );
611     if ( node != NULL ) {
612       int i = 0;
613       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
614         child->setDoubleValue( "temperature-sea-level-degc",
615                                temp_sea_level_degc );
616         ++i;
617       }
618     }
619
620     return true;
621 }
622
623 /**
624  * Set the sea level outside air dewpoint and assigning that to all
625  * boundary and aloft environment layers.
626  */
627 static bool
628 do_set_dewpoint_sea_level_degc (const SGPropertyNode * arg)
629 {
630     double dewpoint_sea_level_degc = arg->getDoubleValue("dewpoint-degc", 5.0);
631
632     SGPropertyNode *node, *child;
633
634     // boundary layers
635     node = fgGetNode( "/environment/config/boundary" );
636     if ( node != NULL ) {
637       int i = 0;
638       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
639         child->setDoubleValue( "dewpoint-sea-level-degc",
640                                dewpoint_sea_level_degc );
641         ++i;
642       }
643     }
644
645     // aloft layers
646     node = fgGetNode( "/environment/config/aloft" );
647     if ( node != NULL ) {
648       int i = 0;
649       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
650         child->setDoubleValue( "dewpoint-sea-level-degc",
651                                dewpoint_sea_level_degc );
652         ++i;
653       }
654     }
655
656     return true;
657 }
658
659
660 /**
661  * Set the outside air dewpoint at the "current" altitude by first
662  * calculating the corresponding sea level dewpoint, and assigning
663  * that to all boundary and aloft environment layers.
664  */
665 static bool
666 do_set_dewpoint_degc (const SGPropertyNode * arg)
667 {
668     const string &dewpoint_str = arg->getStringValue("dewpoint-degc", "5.0");
669
670     // check for an altitude specified in the arguments, otherwise use
671     // current aircraft altitude.
672     const SGPropertyNode *altitude_ft = arg->getChild("altitude-ft");
673     if ( altitude_ft == NULL ) {
674         altitude_ft = fgGetNode("/position/altitude-ft");
675     }
676
677     FGEnvironment dummy;        // instantiate a dummy so we can leech a method
678     dummy.set_elevation_ft( altitude_ft->getDoubleValue() );
679     dummy.set_dewpoint_degc( atof( dewpoint_str.c_str() ) );
680     double dewpoint_sea_level_degc = dummy.get_dewpoint_sea_level_degc();
681
682     //cout << "Altitude = " << altitude_ft->getDoubleValue() << endl;
683     //cout << "Dewpoint at alt (C) = " << atof( dewpoint_str.c_str() ) << endl;
684     //cout << "Dewpoint at sea level (C) = " << dewpoint_sea_level_degc << endl;
685  
686     SGPropertyNode *node, *child;
687
688     // boundary layers
689     node = fgGetNode( "/environment/config/boundary" );
690     if ( node != NULL ) {
691       int i = 0;
692       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
693         child->setDoubleValue( "dewpoint-sea-level-degc",
694                                dewpoint_sea_level_degc );
695         ++i;
696       }
697     }
698
699     // aloft layers
700     node = fgGetNode( "/environment/config/aloft" );
701     if ( node != NULL ) {
702       int i = 0;
703       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
704         child->setDoubleValue( "dewpoint-sea-level-degc",
705                                dewpoint_sea_level_degc );
706         ++i;
707       }
708     }
709
710     return true;
711 }
712
713 /**
714  * Update the lighting manually.
715  */
716 static bool
717 do_timeofday (const SGPropertyNode * arg)
718 {
719     const string &offset_type = arg->getStringValue("timeofday", "noon");
720
721     static const SGPropertyNode *longitude
722         = fgGetNode("/position/longitude-deg");
723     static const SGPropertyNode *latitude
724         = fgGetNode("/position/latitude-deg");
725     static const SGPropertyNode *cur_time_override
726         = fgGetNode("/sim/time/cur-time-override", true);
727
728     int orig_warp = globals->get_warp();
729     SGTime *t = globals->get_time_params();
730     time_t cur_time = t->get_cur_time();
731     // cout << "cur_time = " << cur_time << endl;
732     // cout << "orig_warp = " << orig_warp << endl;
733
734     int warp = 0;
735     if ( offset_type == "real" ) {
736         warp = -orig_warp;
737     } else if ( offset_type == "dawn" ) {
738         warp = fgTimeSecondsUntilSunAngle( cur_time,
739                                            longitude->getDoubleValue()
740                                              * SGD_DEGREES_TO_RADIANS,
741                                            latitude->getDoubleValue()
742                                              * SGD_DEGREES_TO_RADIANS,
743                                            90.0, true ); 
744     } else if ( offset_type == "morning" ) {
745         warp = fgTimeSecondsUntilSunAngle( cur_time,
746                                            longitude->getDoubleValue()
747                                              * SGD_DEGREES_TO_RADIANS,
748                                            latitude->getDoubleValue()
749                                              * SGD_DEGREES_TO_RADIANS,
750                                            75.0, true ); 
751     } else if ( offset_type == "noon" ) {
752         warp = fgTimeSecondsUntilSunAngle( cur_time,
753                                            longitude->getDoubleValue()
754                                              * SGD_DEGREES_TO_RADIANS,
755                                            latitude->getDoubleValue()
756                                              * SGD_DEGREES_TO_RADIANS,
757                                            0.0, true ); 
758     } else if ( offset_type == "afternoon" ) {
759         warp = fgTimeSecondsUntilSunAngle( cur_time,
760                                            longitude->getDoubleValue()
761                                              * SGD_DEGREES_TO_RADIANS,
762                                            latitude->getDoubleValue()
763                                              * SGD_DEGREES_TO_RADIANS,
764                                            60.0, false ); 
765      } else if ( offset_type == "dusk" ) {
766         warp = fgTimeSecondsUntilSunAngle( cur_time,
767                                            longitude->getDoubleValue()
768                                              * SGD_DEGREES_TO_RADIANS,
769                                            latitude->getDoubleValue()
770                                              * SGD_DEGREES_TO_RADIANS,
771                                            90.0, false ); 
772      } else if ( offset_type == "evening" ) {
773         warp = fgTimeSecondsUntilSunAngle( cur_time,
774                                            longitude->getDoubleValue()
775                                              * SGD_DEGREES_TO_RADIANS,
776                                            latitude->getDoubleValue()
777                                              * SGD_DEGREES_TO_RADIANS,
778                                            100.0, false ); 
779     } else if ( offset_type == "midnight" ) {
780         warp = fgTimeSecondsUntilSunAngle( cur_time,
781                                            longitude->getDoubleValue()
782                                              * SGD_DEGREES_TO_RADIANS,
783                                            latitude->getDoubleValue()
784                                              * SGD_DEGREES_TO_RADIANS,
785                                            180.0, false ); 
786     }
787     // cout << "warp = " << warp << endl;
788     globals->set_warp( orig_warp + warp );
789
790     t->update( longitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
791                latitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
792                cur_time_override->getLongValue(),
793                globals->get_warp() );
794
795     return true;
796 }
797
798
799 /**
800  * Built-in command: toggle a bool property value.
801  *
802  * property: The name of the property to toggle.
803  */
804 static bool
805 do_property_toggle (const SGPropertyNode * arg)
806 {
807   SGPropertyNode * prop = get_prop(arg);
808   return prop->setBoolValue(!prop->getBoolValue());
809 }
810
811
812 /**
813  * Built-in command: assign a value to a property.
814  *
815  * property: the name of the property to assign.
816  * value: the value to assign; or
817  * property[1]: the property to copy from.
818  */
819 static bool
820 do_property_assign (const SGPropertyNode * arg)
821 {
822   SGPropertyNode * prop = get_prop(arg);
823   const SGPropertyNode * prop2 = get_prop2(arg);
824   const SGPropertyNode * value = arg->getNode("value");
825
826   if (value != 0)
827       return prop->setUnspecifiedValue(value->getStringValue());
828   else if (prop2)
829       return prop->setUnspecifiedValue(prop2->getStringValue());
830   else
831       return false;
832 }
833
834
835 /**
836  * Built-in command: increment or decrement a property value.
837  *
838  * If the 'step' argument is present, it will be used; otherwise,
839  * the command uses 'offset' and 'factor', usually from the mouse.
840  *
841  * property: the name of the property to increment or decrement.
842  * step: the amount of the increment or decrement (default: 0).
843  * offset: offset from the current setting (used for the mouse; multiplied 
844  *         by factor)
845  * factor: scaling amount for the offset (defaults to 1).
846  * min: the minimum allowed value (default: no minimum).
847  * max: the maximum allowed value (default: no maximum).
848  * mask: 'integer' to apply only to the left of the decimal point, 
849  *       'decimal' to apply only to the right of the decimal point,
850  *       or 'all' to apply to the whole number (the default).
851  * wrap: true if the value should be wrapped when it passes min or max;
852  *       both min and max must be present for this to work (default:
853  *       false).
854  */
855 static bool
856 do_property_adjust (const SGPropertyNode * arg)
857 {
858   SGPropertyNode * prop = get_prop(arg);
859
860   double amount = 0;
861   if (arg->hasValue("step"))
862       amount = arg->getDoubleValue("step");
863   else
864       amount = (arg->getDoubleValue("factor", 1)
865                 * arg->getDoubleValue("offset"));
866           
867   double unmodifiable, modifiable;
868   split_value(prop->getDoubleValue(), arg->getStringValue("mask", "all"),
869               &unmodifiable, &modifiable);
870   modifiable += amount;
871   limit_value(&modifiable, arg);
872
873   prop->setDoubleValue(unmodifiable + modifiable);
874
875   return true;
876 }
877
878
879 /**
880  * Built-in command: multiply a property value.
881  *
882  * property: the name of the property to multiply.
883  * factor: the amount by which to multiply.
884  * min: the minimum allowed value (default: no minimum).
885  * max: the maximum allowed value (default: no maximum).
886  * mask: 'integer' to apply only to the left of the decimal point, 
887  *       'decimal' to apply only to the right of the decimal point,
888  *       or 'all' to apply to the whole number (the default).
889  * wrap: true if the value should be wrapped when it passes min or max;
890  *       both min and max must be present for this to work (default:
891  *       false).
892  */
893 static bool
894 do_property_multiply (const SGPropertyNode * arg)
895 {
896   SGPropertyNode * prop = get_prop(arg);
897   double factor = arg->getDoubleValue("factor", 1);
898
899   double unmodifiable, modifiable;
900   split_value(prop->getDoubleValue(), arg->getStringValue("mask", "all"),
901               &unmodifiable, &modifiable);
902   modifiable *= factor;
903   limit_value(&modifiable, arg);
904
905   prop->setDoubleValue(unmodifiable + modifiable);
906
907   return true;
908 }
909
910
911 /**
912  * Built-in command: swap two property values.
913  *
914  * property[0]: the name of the first property.
915  * property[1]: the name of the second property.
916  */
917 static bool
918 do_property_swap (const SGPropertyNode * arg)
919 {
920   SGPropertyNode * prop1 = get_prop(arg);
921   SGPropertyNode * prop2 = get_prop2(arg);
922
923                                 // FIXME: inefficient
924   const string & tmp = prop1->getStringValue();
925   return (prop1->setUnspecifiedValue(prop2->getStringValue()) &&
926           prop2->setUnspecifiedValue(tmp.c_str()));
927 }
928
929
930 /**
931  * Built-in command: Set a property to an axis or other moving input.
932  *
933  * property: the name of the property to set.
934  * setting: the current input setting, usually between -1.0 and 1.0.
935  * offset: the offset to shift by, before applying the factor.
936  * factor: the factor to multiply by (use negative to reverse).
937  */
938 static bool
939 do_property_scale (const SGPropertyNode * arg)
940 {
941   SGPropertyNode * prop = get_prop(arg);
942   double setting = arg->getDoubleValue("setting");
943   double offset = arg->getDoubleValue("offset", 0.0);
944   double factor = arg->getDoubleValue("factor", 1.0);
945   bool squared = arg->getBoolValue("squared", false);
946   int power = arg->getIntValue("power", (squared ? 2 : 1));
947
948   int sign = (setting < 0 ? -1 : 1);
949
950   switch (power) {
951   case 1:
952       break;
953   case 2:
954       setting = setting * setting * sign;
955       break;
956   case 3:
957       setting = setting * setting * setting;
958       break;
959   case 4:
960       setting = setting * setting * setting * setting * sign;
961       break;
962   default:
963       setting =  pow(setting, power);
964       if ((power % 2) == 0)
965           setting *= sign;
966       break;
967   }
968
969   return prop->setDoubleValue((setting + offset) * factor);
970 }
971
972
973 /**
974  * Built-in command: cycle a property through a set of values.
975  *
976  * If the current value isn't in the list, the cycle will
977  * (re)start from the beginning.
978  *
979  * property: the name of the property to cycle.
980  * value[*]: the list of values to cycle through.
981  */
982 static bool
983 do_property_cycle (const SGPropertyNode * arg)
984 {
985     SGPropertyNode * prop = get_prop(arg);
986     vector<SGPropertyNode_ptr> values = arg->getChildren("value");
987     int selection = -1;
988     int nSelections = values.size();
989
990     if (nSelections < 1) {
991         SG_LOG(SG_GENERAL, SG_ALERT, "No values for property-cycle");
992         return false;
993     }
994
995                                 // Try to find the current selection
996     for (int i = 0; i < nSelections; i++) {
997         if (compare_values(prop, values[i])) {
998             selection = i + 1;
999             break;
1000         }
1001     }
1002
1003                                 // Default or wrap to the first selection
1004     if (selection < 0 || selection >= nSelections)
1005         selection = 0;
1006
1007     prop->setUnspecifiedValue(values[selection]->getStringValue());
1008     return true;
1009 }
1010
1011
1012 /**
1013  * Built-in command: randomize a numeric property value.
1014  *
1015  * property: the name of the property value to randomize.
1016  * min: the minimum allowed value.
1017  * max: the maximum allowed value.
1018  */
1019 static bool
1020 do_property_randomize (const SGPropertyNode * arg)
1021 {
1022     SGPropertyNode * prop = get_prop(arg);
1023     double min = arg->getDoubleValue("min", DBL_MIN);
1024     double max = arg->getDoubleValue("max", DBL_MAX);
1025     prop->setDoubleValue(sg_random() * (max - min) + min);
1026     return true;
1027 }
1028
1029
1030 /**
1031  * Built-in command: reinit the data logging system based on the
1032  * current contents of the /logger tree.
1033  */
1034 static bool
1035 do_data_logging_commit (const SGPropertyNode * arg)
1036 {
1037     FGLogger *log = (FGLogger *)globals->get_subsystem("logger");
1038     log->reinit();
1039     return true;
1040 }
1041
1042 /**
1043  * Built-in command: Add a dialog to the GUI system.  Does *not*
1044  * display the dialog.  The property node should have the same format
1045  * as a dialog XML configuration.  It must include:
1046  *
1047  * name: the name of the GUI dialog for future reference.
1048  */
1049 static bool
1050 do_dialog_new (const SGPropertyNode * arg)
1051 {
1052     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1053
1054     // Note the casting away of const: this is *real*.  Doing a
1055     // "dialog-apply" command later on will mutate this property node.
1056     // I'm not convinced that this isn't the Right Thing though; it
1057     // allows client to create a node, pass it to dialog-new, and get
1058     // the values back from the dialog by reading the same node.
1059     // Perhaps command arguments are not as "const" as they would
1060     // seem?
1061     gui->newDialog((SGPropertyNode*)arg);
1062     return true;
1063 }
1064
1065 /**
1066  * Built-in command: Show an XML-configured dialog.
1067  *
1068  * dialog-name: the name of the GUI dialog to display.
1069  */
1070 static bool
1071 do_dialog_show (const SGPropertyNode * arg)
1072 {
1073     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1074     gui->showDialog(arg->getStringValue("dialog-name"));
1075     return true;
1076 }
1077
1078
1079 /**
1080  * Built-in Command: Hide the active XML-configured dialog.
1081  */
1082 static bool
1083 do_dialog_close (const SGPropertyNode * arg)
1084 {
1085     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1086     if(arg->hasValue("dialog-name"))
1087         return gui->closeDialog(arg->getStringValue("dialog-name"));
1088     return gui->closeActiveDialog();
1089 }
1090
1091
1092 /**
1093  * Update a value in the active XML-configured dialog.
1094  *
1095  * object-name: The name of the GUI object(s) (all GUI objects if omitted).
1096  */
1097 static bool
1098 do_dialog_update (const SGPropertyNode * arg)
1099 {
1100     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1101     FGDialog * dialog;
1102     if (arg->hasValue("dialog-name"))
1103         dialog = gui->getDialog(arg->getStringValue("dialog-name"));
1104     else
1105         dialog = gui->getActiveDialog();
1106
1107     if (dialog != 0) {
1108         dialog->updateValues(arg->getStringValue("object-name"));
1109         return true;
1110     } else {
1111         return false;
1112     }
1113 }
1114
1115
1116 /**
1117  * Apply a value in the active XML-configured dialog.
1118  *
1119  * object-name: The name of the GUI object(s) (all GUI objects if omitted).
1120  */
1121 static bool
1122 do_dialog_apply (const SGPropertyNode * arg)
1123 {
1124     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1125     FGDialog * dialog;
1126     if (arg->hasValue("dialog-name"))
1127         dialog = gui->getDialog(arg->getStringValue("dialog-name"));
1128     else
1129         dialog = gui->getActiveDialog();
1130
1131     if (dialog != 0) {
1132         dialog->applyValues(arg->getStringValue("object-name"));
1133         return true;
1134     } else {
1135         return false;
1136     }
1137 }
1138
1139
1140 /**
1141  * Redraw GUI (applying new widget colors). Doesn't reload the dialogs,
1142  * unlike reinit().
1143  */
1144 static bool
1145 do_gui_redraw (const SGPropertyNode * arg)
1146 {
1147     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1148     gui->redraw();
1149     return true;
1150 }
1151
1152
1153 /**
1154  * Set mouse cursor coordinates and cursor shape.
1155  */
1156 static bool
1157 do_set_cursor (const SGPropertyNode * arg)
1158 {
1159     if (arg->hasValue("x") || arg->hasValue("y")) {
1160         SGPropertyNode *mx = fgGetNode("/devices/status/mice/mouse/x", true);
1161         SGPropertyNode *my = fgGetNode("/devices/status/mice/mouse/y", true);
1162         int x = arg->getIntValue("x", mx->getIntValue());
1163         int y = arg->getIntValue("y", my->getIntValue());
1164         fgWarpMouse(x, y);
1165         mx->setIntValue(x);
1166         my->setIntValue(y);
1167     }
1168
1169     SGPropertyNode *cursor = const_cast<SGPropertyNode *>(arg)->getNode("cursor", true);
1170     if (cursor->getType() != SGPropertyNode::NONE)
1171         fgSetMouseCursor(cursor->getIntValue());
1172
1173     cursor->setIntValue(fgGetMouseCursor());
1174     return true;
1175 }
1176
1177
1178 /**
1179  * Built-in command: play an audio message (i.e. a wav file) This is
1180  * fire and forget.  Call this once per message and it will get dumped
1181  * into a queue.  Messages are played sequentially so they do not
1182  * overlap.
1183  */
1184 static bool
1185 do_play_audio_sample (const SGPropertyNode * arg)
1186 {
1187     FGFX *fx = (FGFX *)globals->get_subsystem("fx");
1188     string path = arg->getStringValue("path");
1189     string file = arg->getStringValue("file");
1190     double volume = arg->getDoubleValue("volume");
1191     // cout << "playing " << path << " / " << file << endl;
1192     try {
1193         fx->play_message( path, file, volume );
1194         return true;
1195
1196     } catch (const sg_io_exception& e) {
1197         SG_LOG(SG_GENERAL, SG_ALERT, "play-audio-sample: "
1198                 "failed to load" << path << '/' << file);
1199         return false;
1200     }
1201 }
1202
1203 /**
1204  * Built-in command: commit presets (read from in /sim/presets/)
1205  */
1206 static bool
1207 do_presets_commit (const SGPropertyNode * arg)
1208 {
1209     // unbind the current fdm state so property changes
1210     // don't get lost when we subsequently delete this fdm
1211     // and create a new one.
1212     cur_fdm_state->unbind();
1213
1214     // set position from presets
1215     fgInitPosition();
1216
1217     fgReInitSubsystems();
1218
1219     globals->get_tile_mgr()->update( fgGetDouble("/environment/visibility-m") );
1220
1221 #if 0
1222     if ( ! fgGetBool("/sim/presets/onground") ) {
1223         fgSetBool( "/sim/freeze/master", true );
1224         fgSetBool( "/sim/freeze/clock", true );
1225     }
1226 #endif
1227
1228     return true;
1229 }
1230
1231 /**
1232  * Built-in command: set log level (0 ... 7)
1233  */
1234 static bool
1235 do_log_level (const SGPropertyNode * arg)
1236 {
1237    sglog().setLogLevels( SG_ALL, (sgDebugPriority)arg->getIntValue() );
1238
1239    return true;
1240 }
1241
1242 /**
1243  * Built-in command: replay the FDR buffer
1244  */
1245 static bool
1246 do_replay (const SGPropertyNode * arg)
1247 {
1248     // freeze the master fdm
1249     fgSetInt( "/sim/freeze/replay-state", 1 );
1250
1251     FGReplay *r = (FGReplay *)(globals->get_subsystem( "replay" ));
1252
1253     fgSetDouble( "/sim/replay/start-time", r->get_start_time() );
1254     fgSetDouble( "/sim/replay/end-time", r->get_end_time() );
1255     double duration = fgGetDouble( "/sim/replay/duration" );
1256     if( duration && duration < (r->get_end_time() - r->get_start_time()) ) {
1257         fgSetDouble( "/sim/replay/time", r->get_end_time() - duration );
1258     } else {
1259         fgSetDouble( "/sim/replay/time", r->get_start_time() );
1260     }
1261
1262     // cout << "start = " << r->get_start_time()
1263     //      << "  end = " << r->get_end_time() << endl;
1264
1265     return true;
1266 }
1267
1268
1269 static bool
1270 do_decrease_visibility (const SGPropertyNode * arg)
1271 {
1272     double new_value = fgGetDouble("/environment/visibility-m") * 0.9;
1273     fgSetDouble("/environment/visibility-m", new_value);
1274     fgDefaultWeatherValue("visibility-m", new_value);
1275     globals->get_subsystem("environment")->reinit();
1276
1277     return true;
1278 }
1279  
1280 static bool
1281 do_increase_visibility (const SGPropertyNode * arg)
1282 {
1283     double new_value = fgGetDouble("/environment/visibility-m") * 1.1;
1284     fgSetDouble("/environment/visibility-m", new_value);
1285     fgDefaultWeatherValue("visibility-m", new_value);
1286     globals->get_subsystem("environment")->reinit();
1287
1288     return true;
1289 }
1290
1291 static bool
1292 do_hud_init(const SGPropertyNode *)
1293 {
1294     fgHUDInit(0); // minimal HUD
1295     return true;
1296 }
1297
1298 static bool
1299 do_hud_init2(const SGPropertyNode *)
1300 {
1301     fgHUDInit2(0);  // normal HUD
1302     return true;
1303 }
1304
1305
1306 /**
1307  * An fgcommand to allow loading of xml files via nasal,
1308  * the xml file's structure will be made available within
1309  * a property tree node defined under argument "targetnode",
1310  * or in the given argument tree under "data" otherwise.
1311  *
1312  * @param filename a string to hold the complete path & filename of an XML file
1313  * @param targetnode a string pointing to a location within the property tree
1314  * where to store the parsed XML file. If <targetnode> is undefined, then the
1315  * file contents are stored under a node <data> in the argument tree.
1316  */
1317
1318 static bool
1319 do_load_xml_to_proptree(const SGPropertyNode * arg)
1320 {
1321     SGPath file(arg->getStringValue("filename"));
1322     if (file.str().empty())
1323         return false;
1324
1325     if (file.extension() != "xml")
1326         file.concat(".xml");
1327
1328     SGPropertyNode *targetnode;
1329     if (arg->hasValue("targetnode"))
1330         targetnode = fgGetNode(arg->getStringValue("targetnode"), true);
1331     else
1332         targetnode = const_cast<SGPropertyNode *>(arg)->getNode("data", true);
1333
1334     try {
1335         readProperties(file.c_str(), targetnode, true);
1336     } catch (const sg_exception &e) {
1337         SG_LOG(SG_IO, SG_WARN, "loadxml: " << e.getFormattedMessage());
1338         return false;
1339     }
1340
1341     return  true;
1342 }
1343
1344
1345 /**
1346  * An fgcommand to allow saving of xml files via nasal,
1347  * the file's structure will be determined based on what's
1348  * encountered in the passed (source) property tree node
1349  *
1350  * @param filename a string to hold the complete path & filename of the (new)
1351  * XML file
1352  * @param sourcenode a string pointing to a location within the property tree
1353  * where to find the nodes that should be written recursively into an XML file
1354  * @param data if no sourcenode is given, then the file contents are taken from
1355  * the argument tree's "data" node.
1356  */
1357
1358 static bool
1359 do_save_xml_from_proptree(const SGPropertyNode * arg)
1360 {
1361     SGPath file(arg->getStringValue("filename"));
1362     if (file.str().empty())
1363         return false;
1364
1365     if (file.extension() != "xml")
1366         file.concat(".xml");
1367
1368     SGPropertyNode *sourcenode;
1369     if (arg->hasValue("sourcenode"))
1370         sourcenode = fgGetNode(arg->getStringValue("sourcenode"), true);
1371     else if (arg->getNode("data", false))
1372         sourcenode = const_cast<SGPropertyNode *>(arg)->getNode("data");
1373     else
1374         return false;
1375
1376     try {
1377         writeProperties (file.c_str(), sourcenode, true);
1378     } catch (const sg_exception &e) {
1379         SG_LOG(SG_IO, SG_WARN, "savexml: " << e.getFormattedMessage());
1380         return false;
1381     }
1382
1383     return true;
1384 }
1385
1386 static bool
1387 do_press_cockpit_button (const SGPropertyNode *arg)
1388 {
1389   const char *prefix = arg->getStringValue("prefix");
1390
1391   if (arg->getBoolValue("guarded") && fgGetDouble((string(prefix) + "-guard").c_str()) < 1)
1392     return true;
1393
1394   string prop = string(prefix) + "-button";
1395   double value;
1396
1397   if (arg->getBoolValue("latching"))
1398     value = fgGetDouble(prop.c_str()) > 0 ? 0 : 1;
1399   else
1400     value = 1;
1401
1402   fgSetDouble(prop.c_str(), value);
1403   fgSetBool(arg->getStringValue("discrete"), value > 0);
1404
1405   return true;
1406 }
1407
1408 static bool
1409 do_release_cockpit_button (const SGPropertyNode *arg)
1410 {
1411   const char *prefix = arg->getStringValue("prefix");
1412
1413   if (arg->getBoolValue("guarded")) {
1414     string prop = string(prefix) + "-guard";
1415     if (fgGetDouble(prop.c_str()) < 1) {
1416       fgSetDouble(prop.c_str(), 1);
1417       return true;
1418     }
1419   }
1420
1421   if (! arg->getBoolValue("latching")) {
1422     fgSetDouble((string(prefix) + "-button").c_str(), 0);
1423     fgSetBool(arg->getStringValue("discrete"), false);
1424   }
1425
1426   return true;
1427 }
1428
1429
1430 ////////////////////////////////////////////////////////////////////////
1431 // Command setup.
1432 ////////////////////////////////////////////////////////////////////////
1433
1434
1435 /**
1436  * Table of built-in commands.
1437  *
1438  * New commands do not have to be added here; any module in the application
1439  * can add a new command using globals->get_commands()->addCommand(...).
1440  */
1441 static struct {
1442   const char * name;
1443   SGCommandMgr::command_t command;
1444 } built_ins [] = {
1445     { "null", do_null },
1446     { "nasal", do_nasal },
1447     { "exit", do_exit },
1448     { "reinit", do_reinit },
1449     { "suspend", do_reinit },
1450     { "resume", do_reinit },
1451     { "load", do_load },
1452     { "save", do_save },
1453     { "panel-load", do_panel_load },
1454     { "panel-mouse-click", do_panel_mouse_click },
1455     { "preferences-load", do_preferences_load },
1456     { "view-cycle", do_view_cycle },
1457     { "screen-capture", do_screen_capture },
1458     { "hires-screen-capture", do_hires_screen_capture },
1459     { "tile-cache-reload", do_tile_cache_reload },
1460     { "set-sea-level-air-temp-degc", do_set_sea_level_degc },
1461     { "set-outside-air-temp-degc", do_set_oat_degc },
1462     { "set-dewpoint-sea-level-air-temp-degc", do_set_dewpoint_sea_level_degc },
1463     { "set-dewpoint-temp-degc", do_set_dewpoint_degc },
1464     { "timeofday", do_timeofday },
1465     { "property-toggle", do_property_toggle },
1466     { "property-assign", do_property_assign },
1467     { "property-adjust", do_property_adjust },
1468     { "property-multiply", do_property_multiply },
1469     { "property-swap", do_property_swap },
1470     { "property-scale", do_property_scale },
1471     { "property-cycle", do_property_cycle },
1472     { "property-randomize", do_property_randomize },
1473     { "data-logging-commit", do_data_logging_commit },
1474     { "dialog-new", do_dialog_new },
1475     { "dialog-show", do_dialog_show },
1476     { "dialog-close", do_dialog_close },
1477     { "dialog-update", do_dialog_update },
1478     { "dialog-apply", do_dialog_apply },
1479     { "gui-redraw", do_gui_redraw },
1480     { "set-cursor", do_set_cursor },
1481     { "play-audio-sample", do_play_audio_sample },
1482     { "presets-commit", do_presets_commit },
1483     { "log-level", do_log_level },
1484     { "replay", do_replay },
1485     { "decrease-visibility", do_decrease_visibility },
1486     { "increase-visibility", do_increase_visibility },
1487     { "hud-init", do_hud_init },
1488     { "hud-init2", do_hud_init2 },
1489     { "loadxml", do_load_xml_to_proptree},
1490     { "savexml", do_save_xml_from_proptree },
1491     { "press-cockpit-button", do_press_cockpit_button },
1492     { "release-cockpit-button", do_release_cockpit_button },
1493     { "dump-scenegraph", do_dump_scene_graph },
1494     { "dump-terrainbranch", do_dump_terrain_branch },
1495     { 0, 0 }                    // zero-terminated
1496 };
1497
1498
1499 /**
1500  * Initialize the default built-in commands.
1501  *
1502  * Other commands may be added by other parts of the application.
1503  */
1504 void
1505 fgInitCommands ()
1506 {
1507   SG_LOG(SG_GENERAL, SG_INFO, "Initializing basic built-in commands:");
1508   for (int i = 0; built_ins[i].name != 0; i++) {
1509     SG_LOG(SG_GENERAL, SG_INFO, "  " << built_ins[i].name);
1510     globals->get_commands()->addCommand(built_ins[i].name,
1511                                         built_ins[i].command);
1512   }
1513
1514   typedef bool (*dummy)();
1515   fgTie( "/command/view/next", dummy(0), do_view_next );
1516   fgTie( "/command/view/prev", dummy(0), do_view_prev );
1517 }
1518
1519 // end of fg_commands.cxx