]> git.mxchange.org Git - flightgear.git/blob - src/Main/fg_commands.cxx
1d209220b2ba351bfb9681e933c0d5df6303ae92
[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
491 /**
492  * Built-in command: hires capture screen.
493  */
494 static bool
495 do_hires_screen_capture (const SGPropertyNode * arg)
496 {
497   fgHiResDump();
498   return true;
499 }
500
501
502 /**
503  * Reload the tile cache.
504  */
505 static bool
506 do_tile_cache_reload (const SGPropertyNode * arg)
507 {
508     static const SGPropertyNode *master_freeze
509         = fgGetNode("/sim/freeze/master");
510     bool freeze = master_freeze->getBoolValue();
511     SG_LOG(SG_INPUT, SG_INFO, "ReIniting TileCache");
512     if ( !freeze ) {
513         fgSetBool("/sim/freeze/master", true);
514     }
515     if ( globals->get_tile_mgr()->init() ) {
516         // Load the local scenery data
517         double visibility_meters = fgGetDouble("/environment/visibility-m");
518         globals->get_tile_mgr()->update( visibility_meters );
519     } else {
520         SG_LOG( SG_GENERAL, SG_ALERT, 
521                 "Error in Tile Manager initialization!" );
522         exit(-1);
523     }
524     if ( !freeze ) {
525         fgSetBool("/sim/freeze/master", false);
526     }
527     return true;
528 }
529
530
531 /**
532  * Set the sea level outside air temperature and assigning that to all
533  * boundary and aloft environment layers.
534  */
535 static bool
536 do_set_sea_level_degc (const SGPropertyNode * arg)
537 {
538     double temp_sea_level_degc = arg->getDoubleValue("temp-degc", 15.0);
539
540     SGPropertyNode *node, *child;
541
542     // boundary layers
543     node = fgGetNode( "/environment/config/boundary" );
544     if ( node != NULL ) {
545       int i = 0;
546       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
547         child->setDoubleValue( "temperature-sea-level-degc",
548                                temp_sea_level_degc );
549         ++i;
550       }
551     }
552
553     // aloft layers
554     node = fgGetNode( "/environment/config/aloft" );
555     if ( node != NULL ) {
556       int i = 0;
557       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
558         child->setDoubleValue( "temperature-sea-level-degc",
559                                temp_sea_level_degc );
560         ++i;
561       }
562     }
563
564     return true;
565 }
566
567
568 /**
569  * Set the outside air temperature at the "current" altitude by first
570  * calculating the corresponding sea level temp, and assigning that to
571  * all boundary and aloft environment layers.
572  */
573 static bool
574 do_set_oat_degc (const SGPropertyNode * arg)
575 {
576     const string &temp_str = arg->getStringValue("temp-degc", "15.0");
577
578     // check for an altitude specified in the arguments, otherwise use
579     // current aircraft altitude.
580     const SGPropertyNode *altitude_ft = arg->getChild("altitude-ft");
581     if ( altitude_ft == NULL ) {
582         altitude_ft = fgGetNode("/position/altitude-ft");
583     }
584
585     FGEnvironment dummy;        // instantiate a dummy so we can leech a method
586     dummy.set_elevation_ft( altitude_ft->getDoubleValue() );
587     dummy.set_temperature_degc( atof( temp_str.c_str() ) );
588     double temp_sea_level_degc = dummy.get_temperature_sea_level_degc();
589
590     //cout << "Altitude = " << altitude_ft->getDoubleValue() << endl;
591     //cout << "Temp at alt (C) = " << atof( temp_str.c_str() ) << endl;
592     //cout << "Temp sea level (C) = " << temp_sea_level_degc << endl;
593  
594     SGPropertyNode *node, *child;
595
596     // boundary layers
597     node = fgGetNode( "/environment/config/boundary" );
598     if ( node != NULL ) {
599       int i = 0;
600       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
601         child->setDoubleValue( "temperature-sea-level-degc",
602                                temp_sea_level_degc );
603         ++i;
604       }
605     }
606
607     // aloft layers
608     node = fgGetNode( "/environment/config/aloft" );
609     if ( node != NULL ) {
610       int i = 0;
611       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
612         child->setDoubleValue( "temperature-sea-level-degc",
613                                temp_sea_level_degc );
614         ++i;
615       }
616     }
617
618     return true;
619 }
620
621 /**
622  * Set the sea level outside air dewpoint and assigning that to all
623  * boundary and aloft environment layers.
624  */
625 static bool
626 do_set_dewpoint_sea_level_degc (const SGPropertyNode * arg)
627 {
628     double dewpoint_sea_level_degc = arg->getDoubleValue("dewpoint-degc", 5.0);
629
630     SGPropertyNode *node, *child;
631
632     // boundary layers
633     node = fgGetNode( "/environment/config/boundary" );
634     if ( node != NULL ) {
635       int i = 0;
636       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
637         child->setDoubleValue( "dewpoint-sea-level-degc",
638                                dewpoint_sea_level_degc );
639         ++i;
640       }
641     }
642
643     // aloft layers
644     node = fgGetNode( "/environment/config/aloft" );
645     if ( node != NULL ) {
646       int i = 0;
647       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
648         child->setDoubleValue( "dewpoint-sea-level-degc",
649                                dewpoint_sea_level_degc );
650         ++i;
651       }
652     }
653
654     return true;
655 }
656
657
658 /**
659  * Set the outside air dewpoint at the "current" altitude by first
660  * calculating the corresponding sea level dewpoint, and assigning
661  * that to all boundary and aloft environment layers.
662  */
663 static bool
664 do_set_dewpoint_degc (const SGPropertyNode * arg)
665 {
666     const string &dewpoint_str = arg->getStringValue("dewpoint-degc", "5.0");
667
668     // check for an altitude specified in the arguments, otherwise use
669     // current aircraft altitude.
670     const SGPropertyNode *altitude_ft = arg->getChild("altitude-ft");
671     if ( altitude_ft == NULL ) {
672         altitude_ft = fgGetNode("/position/altitude-ft");
673     }
674
675     FGEnvironment dummy;        // instantiate a dummy so we can leech a method
676     dummy.set_elevation_ft( altitude_ft->getDoubleValue() );
677     dummy.set_dewpoint_degc( atof( dewpoint_str.c_str() ) );
678     double dewpoint_sea_level_degc = dummy.get_dewpoint_sea_level_degc();
679
680     //cout << "Altitude = " << altitude_ft->getDoubleValue() << endl;
681     //cout << "Dewpoint at alt (C) = " << atof( dewpoint_str.c_str() ) << endl;
682     //cout << "Dewpoint at sea level (C) = " << dewpoint_sea_level_degc << endl;
683  
684     SGPropertyNode *node, *child;
685
686     // boundary layers
687     node = fgGetNode( "/environment/config/boundary" );
688     if ( node != NULL ) {
689       int i = 0;
690       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
691         child->setDoubleValue( "dewpoint-sea-level-degc",
692                                dewpoint_sea_level_degc );
693         ++i;
694       }
695     }
696
697     // aloft layers
698     node = fgGetNode( "/environment/config/aloft" );
699     if ( node != NULL ) {
700       int i = 0;
701       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
702         child->setDoubleValue( "dewpoint-sea-level-degc",
703                                dewpoint_sea_level_degc );
704         ++i;
705       }
706     }
707
708     return true;
709 }
710
711 /**
712  * Update the lighting manually.
713  */
714 static bool
715 do_timeofday (const SGPropertyNode * arg)
716 {
717     const string &offset_type = arg->getStringValue("timeofday", "noon");
718
719     static const SGPropertyNode *longitude
720         = fgGetNode("/position/longitude-deg");
721     static const SGPropertyNode *latitude
722         = fgGetNode("/position/latitude-deg");
723     static const SGPropertyNode *cur_time_override
724         = fgGetNode("/sim/time/cur-time-override", true);
725
726     int orig_warp = globals->get_warp();
727     SGTime *t = globals->get_time_params();
728     time_t cur_time = t->get_cur_time();
729     // cout << "cur_time = " << cur_time << endl;
730     // cout << "orig_warp = " << orig_warp << endl;
731
732     int warp = 0;
733     if ( offset_type == "real" ) {
734         warp = -orig_warp;
735     } else if ( offset_type == "dawn" ) {
736         warp = fgTimeSecondsUntilSunAngle( cur_time,
737                                            longitude->getDoubleValue()
738                                              * SGD_DEGREES_TO_RADIANS,
739                                            latitude->getDoubleValue()
740                                              * SGD_DEGREES_TO_RADIANS,
741                                            90.0, true ); 
742     } else if ( offset_type == "morning" ) {
743         warp = fgTimeSecondsUntilSunAngle( cur_time,
744                                            longitude->getDoubleValue()
745                                              * SGD_DEGREES_TO_RADIANS,
746                                            latitude->getDoubleValue()
747                                              * SGD_DEGREES_TO_RADIANS,
748                                            75.0, true ); 
749     } else if ( offset_type == "noon" ) {
750         warp = fgTimeSecondsUntilSunAngle( cur_time,
751                                            longitude->getDoubleValue()
752                                              * SGD_DEGREES_TO_RADIANS,
753                                            latitude->getDoubleValue()
754                                              * SGD_DEGREES_TO_RADIANS,
755                                            0.0, true ); 
756     } else if ( offset_type == "afternoon" ) {
757         warp = fgTimeSecondsUntilSunAngle( cur_time,
758                                            longitude->getDoubleValue()
759                                              * SGD_DEGREES_TO_RADIANS,
760                                            latitude->getDoubleValue()
761                                              * SGD_DEGREES_TO_RADIANS,
762                                            60.0, false ); 
763      } else if ( offset_type == "dusk" ) {
764         warp = fgTimeSecondsUntilSunAngle( cur_time,
765                                            longitude->getDoubleValue()
766                                              * SGD_DEGREES_TO_RADIANS,
767                                            latitude->getDoubleValue()
768                                              * SGD_DEGREES_TO_RADIANS,
769                                            90.0, false ); 
770      } else if ( offset_type == "evening" ) {
771         warp = fgTimeSecondsUntilSunAngle( cur_time,
772                                            longitude->getDoubleValue()
773                                              * SGD_DEGREES_TO_RADIANS,
774                                            latitude->getDoubleValue()
775                                              * SGD_DEGREES_TO_RADIANS,
776                                            100.0, false ); 
777     } else if ( offset_type == "midnight" ) {
778         warp = fgTimeSecondsUntilSunAngle( cur_time,
779                                            longitude->getDoubleValue()
780                                              * SGD_DEGREES_TO_RADIANS,
781                                            latitude->getDoubleValue()
782                                              * SGD_DEGREES_TO_RADIANS,
783                                            180.0, false ); 
784     }
785     // cout << "warp = " << warp << endl;
786     globals->set_warp( orig_warp + warp );
787
788     t->update( longitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
789                latitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
790                cur_time_override->getLongValue(),
791                globals->get_warp() );
792
793     return true;
794 }
795
796
797 /**
798  * Built-in command: toggle a bool property value.
799  *
800  * property: The name of the property to toggle.
801  */
802 static bool
803 do_property_toggle (const SGPropertyNode * arg)
804 {
805   SGPropertyNode * prop = get_prop(arg);
806   return prop->setBoolValue(!prop->getBoolValue());
807 }
808
809
810 /**
811  * Built-in command: assign a value to a property.
812  *
813  * property: the name of the property to assign.
814  * value: the value to assign; or
815  * property[1]: the property to copy from.
816  */
817 static bool
818 do_property_assign (const SGPropertyNode * arg)
819 {
820   SGPropertyNode * prop = get_prop(arg);
821   const SGPropertyNode * prop2 = get_prop2(arg);
822   const SGPropertyNode * value = arg->getNode("value");
823
824   if (value != 0)
825       return prop->setUnspecifiedValue(value->getStringValue());
826   else if (prop2)
827       return prop->setUnspecifiedValue(prop2->getStringValue());
828   else
829       return false;
830 }
831
832
833 /**
834  * Built-in command: increment or decrement a property value.
835  *
836  * If the 'step' argument is present, it will be used; otherwise,
837  * the command uses 'offset' and 'factor', usually from the mouse.
838  *
839  * property: the name of the property to increment or decrement.
840  * step: the amount of the increment or decrement (default: 0).
841  * offset: offset from the current setting (used for the mouse; multiplied 
842  *         by factor)
843  * factor: scaling amount for the offset (defaults to 1).
844  * min: the minimum allowed value (default: no minimum).
845  * max: the maximum allowed value (default: no maximum).
846  * mask: 'integer' to apply only to the left of the decimal point, 
847  *       'decimal' to apply only to the right of the decimal point,
848  *       or 'all' to apply to the whole number (the default).
849  * wrap: true if the value should be wrapped when it passes min or max;
850  *       both min and max must be present for this to work (default:
851  *       false).
852  */
853 static bool
854 do_property_adjust (const SGPropertyNode * arg)
855 {
856   SGPropertyNode * prop = get_prop(arg);
857
858   double amount = 0;
859   if (arg->hasValue("step"))
860       amount = arg->getDoubleValue("step");
861   else
862       amount = (arg->getDoubleValue("factor", 1)
863                 * arg->getDoubleValue("offset"));
864           
865   double unmodifiable, modifiable;
866   split_value(prop->getDoubleValue(), arg->getStringValue("mask", "all"),
867               &unmodifiable, &modifiable);
868   modifiable += amount;
869   limit_value(&modifiable, arg);
870
871   prop->setDoubleValue(unmodifiable + modifiable);
872
873   return true;
874 }
875
876
877 /**
878  * Built-in command: multiply a property value.
879  *
880  * property: the name of the property to multiply.
881  * factor: the amount by which to multiply.
882  * min: the minimum allowed value (default: no minimum).
883  * max: the maximum allowed value (default: no maximum).
884  * mask: 'integer' to apply only to the left of the decimal point, 
885  *       'decimal' to apply only to the right of the decimal point,
886  *       or 'all' to apply to the whole number (the default).
887  * wrap: true if the value should be wrapped when it passes min or max;
888  *       both min and max must be present for this to work (default:
889  *       false).
890  */
891 static bool
892 do_property_multiply (const SGPropertyNode * arg)
893 {
894   SGPropertyNode * prop = get_prop(arg);
895   double factor = arg->getDoubleValue("factor", 1);
896
897   double unmodifiable, modifiable;
898   split_value(prop->getDoubleValue(), arg->getStringValue("mask", "all"),
899               &unmodifiable, &modifiable);
900   modifiable *= factor;
901   limit_value(&modifiable, arg);
902
903   prop->setDoubleValue(unmodifiable + modifiable);
904
905   return true;
906 }
907
908
909 /**
910  * Built-in command: swap two property values.
911  *
912  * property[0]: the name of the first property.
913  * property[1]: the name of the second property.
914  */
915 static bool
916 do_property_swap (const SGPropertyNode * arg)
917 {
918   SGPropertyNode * prop1 = get_prop(arg);
919   SGPropertyNode * prop2 = get_prop2(arg);
920
921                                 // FIXME: inefficient
922   const string & tmp = prop1->getStringValue();
923   return (prop1->setUnspecifiedValue(prop2->getStringValue()) &&
924           prop2->setUnspecifiedValue(tmp.c_str()));
925 }
926
927
928 /**
929  * Built-in command: Set a property to an axis or other moving input.
930  *
931  * property: the name of the property to set.
932  * setting: the current input setting, usually between -1.0 and 1.0.
933  * offset: the offset to shift by, before applying the factor.
934  * factor: the factor to multiply by (use negative to reverse).
935  */
936 static bool
937 do_property_scale (const SGPropertyNode * arg)
938 {
939   SGPropertyNode * prop = get_prop(arg);
940   double setting = arg->getDoubleValue("setting");
941   double offset = arg->getDoubleValue("offset", 0.0);
942   double factor = arg->getDoubleValue("factor", 1.0);
943   bool squared = arg->getBoolValue("squared", false);
944   int power = arg->getIntValue("power", (squared ? 2 : 1));
945
946   int sign = (setting < 0 ? -1 : 1);
947
948   switch (power) {
949   case 1:
950       break;
951   case 2:
952       setting = setting * setting * sign;
953       break;
954   case 3:
955       setting = setting * setting * setting;
956       break;
957   case 4:
958       setting = setting * setting * setting * setting * sign;
959       break;
960   default:
961       setting =  pow(setting, power);
962       if ((power % 2) == 0)
963           setting *= sign;
964       break;
965   }
966
967   return prop->setDoubleValue((setting + offset) * factor);
968 }
969
970
971 /**
972  * Built-in command: cycle a property through a set of values.
973  *
974  * If the current value isn't in the list, the cycle will
975  * (re)start from the beginning.
976  *
977  * property: the name of the property to cycle.
978  * value[*]: the list of values to cycle through.
979  */
980 static bool
981 do_property_cycle (const SGPropertyNode * arg)
982 {
983     SGPropertyNode * prop = get_prop(arg);
984     vector<SGPropertyNode_ptr> values = arg->getChildren("value");
985     int selection = -1;
986     int nSelections = values.size();
987
988     if (nSelections < 1) {
989         SG_LOG(SG_GENERAL, SG_ALERT, "No values for property-cycle");
990         return false;
991     }
992
993                                 // Try to find the current selection
994     for (int i = 0; i < nSelections; i++) {
995         if (compare_values(prop, values[i])) {
996             selection = i + 1;
997             break;
998         }
999     }
1000
1001                                 // Default or wrap to the first selection
1002     if (selection < 0 || selection >= nSelections)
1003         selection = 0;
1004
1005     prop->setUnspecifiedValue(values[selection]->getStringValue());
1006     return true;
1007 }
1008
1009
1010 /**
1011  * Built-in command: randomize a numeric property value.
1012  *
1013  * property: the name of the property value to randomize.
1014  * min: the minimum allowed value.
1015  * max: the maximum allowed value.
1016  */
1017 static bool
1018 do_property_randomize (const SGPropertyNode * arg)
1019 {
1020     SGPropertyNode * prop = get_prop(arg);
1021     double min = arg->getDoubleValue("min", DBL_MIN);
1022     double max = arg->getDoubleValue("max", DBL_MAX);
1023     prop->setDoubleValue(sg_random() * (max - min) + min);
1024     return true;
1025 }
1026
1027
1028 /**
1029  * Built-in command: reinit the data logging system based on the
1030  * current contents of the /logger tree.
1031  */
1032 static bool
1033 do_data_logging_commit (const SGPropertyNode * arg)
1034 {
1035     FGLogger *log = (FGLogger *)globals->get_subsystem("logger");
1036     log->reinit();
1037     return true;
1038 }
1039
1040 /**
1041  * Built-in command: Add a dialog to the GUI system.  Does *not*
1042  * display the dialog.  The property node should have the same format
1043  * as a dialog XML configuration.  It must include:
1044  *
1045  * name: the name of the GUI dialog for future reference.
1046  */
1047 static bool
1048 do_dialog_new (const SGPropertyNode * arg)
1049 {
1050     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1051
1052     // Note the casting away of const: this is *real*.  Doing a
1053     // "dialog-apply" command later on will mutate this property node.
1054     // I'm not convinced that this isn't the Right Thing though; it
1055     // allows client to create a node, pass it to dialog-new, and get
1056     // the values back from the dialog by reading the same node.
1057     // Perhaps command arguments are not as "const" as they would
1058     // seem?
1059     gui->newDialog((SGPropertyNode*)arg);
1060     return true;
1061 }
1062
1063 /**
1064  * Built-in command: Show an XML-configured dialog.
1065  *
1066  * dialog-name: the name of the GUI dialog to display.
1067  */
1068 static bool
1069 do_dialog_show (const SGPropertyNode * arg)
1070 {
1071     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1072     gui->showDialog(arg->getStringValue("dialog-name"));
1073     return true;
1074 }
1075
1076
1077 /**
1078  * Built-in Command: Hide the active XML-configured dialog.
1079  */
1080 static bool
1081 do_dialog_close (const SGPropertyNode * arg)
1082 {
1083     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1084     if(arg->hasValue("dialog-name"))
1085         return gui->closeDialog(arg->getStringValue("dialog-name"));
1086     return gui->closeActiveDialog();
1087 }
1088
1089
1090 /**
1091  * Update a value in the active XML-configured dialog.
1092  *
1093  * object-name: The name of the GUI object(s) (all GUI objects if omitted).
1094  */
1095 static bool
1096 do_dialog_update (const SGPropertyNode * arg)
1097 {
1098     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1099     FGDialog * dialog;
1100     if (arg->hasValue("dialog-name"))
1101         dialog = gui->getDialog(arg->getStringValue("dialog-name"));
1102     else
1103         dialog = gui->getActiveDialog();
1104
1105     if (dialog != 0) {
1106         dialog->updateValues(arg->getStringValue("object-name"));
1107         return true;
1108     } else {
1109         return false;
1110     }
1111 }
1112
1113
1114 /**
1115  * Apply a value in the active XML-configured dialog.
1116  *
1117  * object-name: The name of the GUI object(s) (all GUI objects if omitted).
1118  */
1119 static bool
1120 do_dialog_apply (const SGPropertyNode * arg)
1121 {
1122     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1123     FGDialog * dialog;
1124     if (arg->hasValue("dialog-name"))
1125         dialog = gui->getDialog(arg->getStringValue("dialog-name"));
1126     else
1127         dialog = gui->getActiveDialog();
1128
1129     if (dialog != 0) {
1130         dialog->applyValues(arg->getStringValue("object-name"));
1131         return true;
1132     } else {
1133         return false;
1134     }
1135 }
1136
1137
1138 /**
1139  * Redraw GUI (applying new widget colors). Doesn't reload the dialogs,
1140  * unlike reinit().
1141  */
1142 static bool
1143 do_gui_redraw (const SGPropertyNode * arg)
1144 {
1145     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1146     gui->redraw();
1147     return true;
1148 }
1149
1150 /**
1151  * Built-in command: play an audio message (i.e. a wav file) This is
1152  * fire and forget.  Call this once per message and it will get dumped
1153  * into a queue.  Messages are played sequentially so they do not
1154  * overlap.
1155  */
1156 static bool
1157 do_play_audio_message (const SGPropertyNode * arg)
1158 {
1159     FGFX *fx = (FGFX *)globals->get_subsystem("fx");
1160     string path = arg->getStringValue("path");
1161     string file = arg->getStringValue("file");
1162     double volume = arg->getDoubleValue("volume");
1163     // cout << "playing " << path << " / " << file << endl;
1164     fx->play_message( path, file, volume );
1165
1166     return true;
1167 }
1168
1169 /**
1170  * Built-in command: commit presets (read from in /sim/presets/)
1171  */
1172 static bool
1173 do_presets_commit (const SGPropertyNode * arg)
1174 {
1175     // unbind the current fdm state so property changes
1176     // don't get lost when we subsequently delete this fdm
1177     // and create a new one.
1178     cur_fdm_state->unbind();
1179         
1180     // set position from presets
1181     fgInitPosition();
1182
1183     fgReInitSubsystems();
1184
1185     globals->get_tile_mgr()->update( fgGetDouble("/environment/visibility-m") );
1186
1187 #if 0
1188     if ( ! fgGetBool("/sim/presets/onground") ) {
1189         fgSetBool( "/sim/freeze/master", true );
1190         fgSetBool( "/sim/freeze/clock", true );
1191     }
1192 #endif
1193
1194     return true;
1195 }
1196
1197 /**
1198  * Built-in command: set log level (0 ... 7)
1199  */
1200 static bool
1201 do_log_level (const SGPropertyNode * arg)
1202 {
1203    sglog().setLogLevels( SG_ALL, (sgDebugPriority)arg->getIntValue() );
1204
1205    return true;
1206 }
1207
1208 /**
1209  * Built-in command: replay the FDR buffer
1210  */
1211 static bool
1212 do_replay (const SGPropertyNode * arg)
1213 {
1214     // freeze the master fdm
1215     fgSetInt( "/sim/freeze/replay-state", 1 );
1216
1217     FGReplay *r = (FGReplay *)(globals->get_subsystem( "replay" ));
1218
1219     fgSetDouble( "/sim/replay/start-time", r->get_start_time() );
1220     fgSetDouble( "/sim/replay/end-time", r->get_end_time() );
1221     double duration = fgGetDouble( "/sim/replay/duration" );
1222     if( duration && duration < (r->get_end_time() - r->get_start_time()) ) {
1223         fgSetDouble( "/sim/replay/time", r->get_end_time() - duration );
1224     } else {
1225         fgSetDouble( "/sim/replay/time", r->get_start_time() );
1226     }
1227
1228     // cout << "start = " << r->get_start_time()
1229     //      << "  end = " << r->get_end_time() << endl;
1230
1231     return true;
1232 }
1233
1234
1235 /**
1236  * Return terrain elevation for given longitude/latitude pair.
1237  */
1238 static bool
1239 do_terrain_elevation (const SGPropertyNode * arg)
1240 {
1241     SGPropertyNode *a = const_cast<SGPropertyNode *>(arg);
1242     const SGMaterial *mat;
1243     double elev;
1244
1245     double lon = a->getDoubleValue("longitude-deg", 0.0);
1246     double lat = a->getDoubleValue("latitude-deg", 0.0);
1247     bool ret = globals->get_scenery()->get_elevation_m(lat, lon, 10000.0, elev, &mat);
1248
1249     bool solid = true;
1250     const char *matname = "";
1251     if (mat) {
1252         solid = mat->get_solid();
1253         const vector<string> names = mat->get_names();
1254         if (!names.empty())
1255             matname = names[0].c_str();
1256     }
1257     a->setBoolValue("solid", solid);
1258     a->setStringValue("material", matname);
1259     a->setDoubleValue("elevation-m", elev);
1260     return ret;
1261 }
1262
1263
1264 static bool
1265 do_decrease_visibility (const SGPropertyNode * arg)
1266 {
1267     double new_value = fgGetDouble("/environment/visibility-m") * 0.9;
1268     fgSetDouble("/environment/visibility-m", new_value);
1269     fgDefaultWeatherValue("visibility-m", new_value);
1270     globals->get_subsystem("environment")->reinit();
1271
1272     return true;
1273 }
1274  
1275 static bool
1276 do_increase_visibility (const SGPropertyNode * arg)
1277 {
1278     double new_value = fgGetDouble("/environment/visibility-m") * 1.1;
1279     fgSetDouble("/environment/visibility-m", new_value);
1280     fgDefaultWeatherValue("visibility-m", new_value);
1281     globals->get_subsystem("environment")->reinit();
1282
1283     return true;
1284 }
1285
1286 static bool
1287 do_hud_init(const SGPropertyNode *)
1288 {
1289     fgHUDInit(0); // minimal HUD
1290     return true;
1291 }
1292
1293 static bool
1294 do_hud_init2(const SGPropertyNode *)
1295 {
1296     fgHUDInit2(0);  // normal HUD
1297     return true;
1298 }
1299
1300 /**
1301  * An fgcommand to allow loading of xml files via nasal,
1302  * the xml file's structure will be made available within
1303  * a (definable) property tree node
1304  *
1305  * @param filename a string to hold the complete path & filename of a XML file
1306  * @param targetnode a string pointing to a location within the property tree
1307  * where to store the parsed XML file
1308  */
1309
1310 static bool 
1311 do_load_xml_to_proptree(const SGPropertyNode * node)
1312 {
1313     // SG_LOG(SG_GENERAL, SG_ALERT, "fgcommand loadxml executed");
1314
1315     SGPropertyNode * targetnode;
1316     targetnode = fgGetNode(node->getNode("targetnode")->getStringValue(),true);
1317                 
1318     const char *filename = node->getNode("filename")->getStringValue();
1319     try {
1320         fgLoadProps(filename, targetnode);
1321     } catch (const sg_exception &e) {
1322         string errmsg = "Error reading file " + string(filename) + ":\n";
1323         guiErrorMessage(errmsg.c_str(), e);
1324         return false;
1325     }
1326
1327     return  true;
1328 }
1329
1330
1331 /**
1332  * an fgcommand to allow saving of xml files via nasal,
1333  * the file's structure will be determined based on what's
1334  * encountered in the passed (source) property tree node
1335  *
1336  * @param filename a string to hold the complete path & filename of the (new)
1337  * XML file
1338  * @param sourcenode a string pointing to a location within the property tree
1339  * where to find the nodes that should be written recursively into an XML file
1340  *
1341  * TODO: 
1342  *   deal with already existing filenames, optionally return error/success
1343  *   values in a separate node to provide status information
1344  *
1345  * note: it's directly using writeProperties, which is not necessarily
1346  *       preferable, but for now it should work ...
1347  */
1348
1349 static bool 
1350 do_save_xml_from_proptree(const SGPropertyNode * node)
1351 {
1352     //TODO: do Parameter validation !
1353     SGPropertyNode * sourcenode;
1354     sourcenode = fgGetNode(node->getNode("sourcenode")->getStringValue(),true);
1355
1356     const char *filename = node->getNode("filename")->getStringValue();
1357     try {
1358         writeProperties (filename, sourcenode, true);
1359     } catch (const sg_exception &e) {
1360         string errmsg = "Error writing file " + string(filename) + ":\n";
1361         guiErrorMessage(errmsg.c_str(), e);
1362         return false;
1363     }
1364
1365     return true;
1366 }
1367
1368 static bool
1369 do_press_cockpit_button (const SGPropertyNode *arg)
1370 {
1371   const char *prefix = arg->getStringValue("prefix");
1372
1373   if (arg->getBoolValue("guarded") && fgGetDouble((string(prefix) + "-guard").c_str()) < 1)
1374     return true;
1375
1376   string prop = string(prefix) + "-button";
1377   double value;
1378
1379   if (arg->getBoolValue("latching"))
1380     value = fgGetDouble(prop.c_str()) > 0 ? 0 : 1;
1381   else
1382     value = 1;
1383
1384   fgSetDouble(prop.c_str(), value);
1385   fgSetBool(arg->getStringValue("discrete"), value > 0);
1386
1387   return true;
1388 }
1389
1390 static bool
1391 do_release_cockpit_button (const SGPropertyNode *arg)
1392 {
1393   const char *prefix = arg->getStringValue("prefix");
1394
1395   if (arg->getBoolValue("guarded")) {
1396     string prop = string(prefix) + "-guard";
1397     if (fgGetDouble(prop.c_str()) < 1) {
1398       fgSetDouble(prop.c_str(), 1);
1399       return true;
1400     }
1401   }
1402
1403   if (! arg->getBoolValue("latching")) {
1404     fgSetDouble((string(prefix) + "-button").c_str(), 0);
1405     fgSetBool(arg->getStringValue("discrete"), false);
1406   }
1407
1408   return true;
1409 }
1410
1411
1412 ////////////////////////////////////////////////////////////////////////
1413 // Command setup.
1414 ////////////////////////////////////////////////////////////////////////
1415
1416
1417 /**
1418  * Table of built-in commands.
1419  *
1420  * New commands do not have to be added here; any module in the application
1421  * can add a new command using globals->get_commands()->addCommand(...).
1422  */
1423 static struct {
1424   const char * name;
1425   SGCommandMgr::command_t command;
1426 } built_ins [] = {
1427     { "null", do_null },
1428 #if defined(HAVE_PLIB_PSL)
1429     { "script", do_script },
1430 #endif // HAVE_PLIB_PSL
1431     { "nasal", do_nasal },
1432     { "exit", do_exit },
1433     { "reinit", do_reinit },
1434     { "suspend", do_reinit },
1435     { "resume", do_reinit },
1436     { "load", do_load },
1437     { "save", do_save },
1438     { "panel-load", do_panel_load },
1439     { "panel-mouse-click", do_panel_mouse_click },
1440     { "preferences-load", do_preferences_load },
1441     { "view-cycle", do_view_cycle },
1442     { "screen-capture", do_screen_capture },
1443     { "hires-screen-capture", do_hires_screen_capture },
1444     { "tile-cache-reload", do_tile_cache_reload },
1445     { "set-sea-level-air-temp-degc", do_set_sea_level_degc },
1446     { "set-outside-air-temp-degc", do_set_oat_degc },
1447     { "set-dewpoint-sea-level-air-temp-degc", do_set_dewpoint_sea_level_degc },
1448     { "set-dewpoint-temp-degc", do_set_dewpoint_degc },
1449     { "timeofday", do_timeofday },
1450     { "property-toggle", do_property_toggle },
1451     { "property-assign", do_property_assign },
1452     { "property-adjust", do_property_adjust },
1453     { "property-multiply", do_property_multiply },
1454     { "property-swap", do_property_swap },
1455     { "property-scale", do_property_scale },
1456     { "property-cycle", do_property_cycle },
1457     { "property-randomize", do_property_randomize },
1458     { "data-logging-commit", do_data_logging_commit },
1459     { "dialog-new", do_dialog_new },
1460     { "dialog-show", do_dialog_show },
1461     { "dialog-close", do_dialog_close },
1462     { "dialog-update", do_dialog_update },
1463     { "dialog-apply", do_dialog_apply },
1464     { "gui-redraw", do_gui_redraw },
1465     { "play-audio-message", do_play_audio_message },
1466     { "presets-commit", do_presets_commit },
1467     { "log-level", do_log_level },
1468     { "replay", do_replay },
1469     { "terrain-elevation", do_terrain_elevation },
1470     { "decrease-visibility", do_decrease_visibility },
1471     { "increase-visibility", do_increase_visibility },
1472     { "hud-init", do_hud_init },
1473     { "hud-init2", do_hud_init2 },
1474     { "loadxml", do_load_xml_to_proptree},
1475     { "savexml", do_save_xml_from_proptree },    
1476     { "press-cockpit-button", do_press_cockpit_button },
1477     { "release-cockpit-button", do_release_cockpit_button },
1478     { 0, 0 }                    // zero-terminated
1479 };
1480
1481
1482 /**
1483  * Initialize the default built-in commands.
1484  *
1485  * Other commands may be added by other parts of the application.
1486  */
1487 void
1488 fgInitCommands ()
1489 {
1490   SG_LOG(SG_GENERAL, SG_INFO, "Initializing basic built-in commands:");
1491   for (int i = 0; built_ins[i].name != 0; i++) {
1492     SG_LOG(SG_GENERAL, SG_INFO, "  " << built_ins[i].name);
1493     globals->get_commands()->addCommand(built_ins[i].name,
1494                                         built_ins[i].command);
1495   }
1496
1497   typedef bool (*dummy)();
1498   fgTie( "/command/view/next", dummy(0), do_view_next );
1499   fgTie( "/command/view/prev", dummy(0), do_view_prev );
1500 }
1501
1502 // end of fg_commands.cxx