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