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