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