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