]> git.mxchange.org Git - flightgear.git/blob - src/Main/fg_commands.cxx
Merge branch 'refs/heads/topics/loadfp' into next
[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 <FDM/flight.hxx>
29 #include <GUI/gui.h>
30 #include <GUI/new_gui.hxx>
31 #include <GUI/dialog.hxx>
32 #include <Aircraft/replay.hxx>
33 #include <Scenery/scenery.hxx>
34 #include <Scripting/NasalSys.hxx>
35 #include <Sound/sample_queue.hxx>
36 #include <Time/sunsolver.hxx>
37 #include <Airports/xmlloader.hxx>
38
39 #include "fg_init.hxx"
40 #include "fg_io.hxx"
41 #include "fg_os.hxx"
42 #include "fg_commands.hxx"
43 #include "fg_props.hxx"
44 #include "globals.hxx"
45 #include "logger.hxx"
46 #include "util.hxx"
47 #include "viewmgr.hxx"
48 #include "main.hxx"
49 #include <Main/viewer.hxx>
50 #include <Environment/presets.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     fgReInitSubsystems();
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 static bool
319 do_pause (const SGPropertyNode * arg)
320 {
321     bool paused = fgGetBool("/sim/freeze/master",true) || fgGetBool("/sim/freeze/clock",true);
322     fgSetBool("/sim/freeze/master",!paused);
323     fgSetBool("/sim/freeze/clock",!paused);
324     if (fgGetBool("/sim/freeze/replay-state",false))
325         fgSetBool("/sim/replay/disable",true);
326     return true;
327 }
328
329 /**
330  * Built-in command: load flight.
331  *
332  * file (optional): the name of the file to load (relative to current
333  *   directory).  Defaults to "fgfs.sav"
334  */
335 static bool
336 do_load (const SGPropertyNode * arg)
337 {
338     string file = arg->getStringValue("file", "fgfs.sav");
339     if (file.size() < 4 || file.substr(file.size() - 4) != ".sav")
340         file += ".sav";
341
342     if (!fgValidatePath(file.c_str(), false)) {
343         SG_LOG(SG_IO, SG_ALERT, "load: reading '" << file << "' denied "
344                 "(unauthorized access)");
345         return false;
346     }
347
348     ifstream input(file.c_str());
349     if (input.good() && fgLoadFlight(input)) {
350         input.close();
351         SG_LOG(SG_INPUT, SG_INFO, "Restored flight from " << file);
352         return true;
353     } else {
354         SG_LOG(SG_INPUT, SG_WARN, "Cannot load flight from " << file);
355         return false;
356     }
357 }
358
359
360 /**
361  * Built-in command: save flight.
362  *
363  * file (optional): the name of the file to save (relative to the
364  * current directory).  Defaults to "fgfs.sav".
365  */
366 static bool
367 do_save (const SGPropertyNode * arg)
368 {
369     string file = arg->getStringValue("file", "fgfs.sav");
370     if (file.size() < 4 || file.substr(file.size() - 4) != ".sav")
371         file += ".sav";
372
373     if (!fgValidatePath(file.c_str(), false)) {
374         SG_LOG(SG_IO, SG_ALERT, "save: writing '" << file << "' denied "
375                 "(unauthorized access)");
376         return false;
377     }
378
379     bool write_all = arg->getBoolValue("write-all", false);
380     SG_LOG(SG_INPUT, SG_INFO, "Saving flight");
381     ofstream output(file.c_str());
382     if (output.good() && fgSaveFlight(output, write_all)) {
383         output.close();
384         SG_LOG(SG_INPUT, SG_INFO, "Saved flight to " << file);
385         return true;
386     } else {
387         SG_LOG(SG_INPUT, SG_ALERT, "Cannot save flight to " << file);
388         return false;
389     }
390 }
391
392
393 /**
394  * Built-in command: (re)load the panel.
395  *
396  * path (optional): the file name to load the panel from 
397  * (relative to FG_ROOT).  Defaults to the value of /sim/panel/path,
398  * and if that's unspecified, to "Panels/Default/default.xml".
399  */
400 static bool
401 do_panel_load (const SGPropertyNode * arg)
402 {
403   string panel_path =
404     arg->getStringValue("path", fgGetString("/sim/panel/path"));
405   if (panel_path.empty()) {
406     return false;
407   }
408   
409   FGPanel * new_panel = fgReadPanel(panel_path);
410   if (new_panel == 0) {
411     SG_LOG(SG_INPUT, SG_ALERT,
412            "Error reading new panel from " << panel_path);
413     return false;
414   }
415   SG_LOG(SG_INPUT, SG_INFO, "Loaded new panel from " << panel_path);
416   globals->get_current_panel()->unbind();
417   delete globals->get_current_panel();
418   globals->set_current_panel( new_panel );
419   globals->get_current_panel()->bind();
420   return true;
421 }
422
423
424 /**
425  * Built-in command: pass a mouse click to the panel.
426  *
427  * button: the mouse button number, zero-based.
428  * is-down: true if the button is down, false if it is up.
429  * x-pos: the x position of the mouse click.
430  * y-pos: the y position of the mouse click.
431  */
432 static bool
433 do_panel_mouse_click (const SGPropertyNode * arg)
434 {
435   if (globals->get_current_panel() != 0)
436     return globals->get_current_panel()
437       ->doMouseAction(arg->getIntValue("button"),
438                       arg->getBoolValue("is-down") ? PU_DOWN : PU_UP,
439                       arg->getIntValue("x-pos"),
440                       arg->getIntValue("y-pos"));
441   else
442     return false;
443 }
444
445
446 /**
447  * Built-in command: (re)load preferences.
448  *
449  * path (optional): the file name to load the panel from (relative
450  * to FG_ROOT). Defaults to "preferences.xml".
451  */
452 static bool
453 do_preferences_load (const SGPropertyNode * arg)
454 {
455   try {
456     fgLoadProps(arg->getStringValue("path", "preferences.xml"),
457                 globals->get_props());
458   } catch (const sg_exception &e) {
459     guiErrorMessage("Error reading global preferences: ", e);
460     return false;
461   }
462   SG_LOG(SG_INPUT, SG_INFO, "Successfully read global preferences.");
463   return true;
464 }
465
466 static void
467 do_view_next( bool )
468 {
469     globals->get_current_view()->setHeadingOffset_deg(0.0);
470     globals->get_viewmgr()->next_view();
471 }
472
473 static void
474 do_view_prev( bool )
475 {
476     globals->get_current_view()->setHeadingOffset_deg(0.0);
477     globals->get_viewmgr()->prev_view();
478 }
479
480 /**
481  * Built-in command: cycle view.
482  */
483 static bool
484 do_view_cycle (const SGPropertyNode * arg)
485 {
486   globals->get_current_view()->setHeadingOffset_deg(0.0);
487   globals->get_viewmgr()->next_view();
488   return true;
489 }
490
491 /**
492  * Built-in command: capture screen.
493  */
494 static bool
495 do_screen_capture (const SGPropertyNode * arg)
496 {
497   return fgDumpSnapShot();
498 }
499
500 static bool
501 do_reload_shaders (const SGPropertyNode*)
502 {
503     simgear::reload_shaders();
504     return true;
505 }
506
507 static bool
508 do_dump_scene_graph (const SGPropertyNode*)
509 {
510     fgDumpSceneGraph();
511     return true;
512 }
513
514 static bool
515 do_dump_terrain_branch (const SGPropertyNode*)
516 {
517     fgDumpTerrainBranch();
518
519     double lon_deg = fgGetDouble("/position/longitude-deg");
520     double lat_deg = fgGetDouble("/position/latitude-deg");
521     SGGeod geodPos = SGGeod::fromDegFt(lon_deg, lat_deg, 0.0);
522     SGVec3d zero = SGVec3d::fromGeod(geodPos);
523
524     SG_LOG(SG_INPUT, SG_INFO, "Model parameters:");
525     SG_LOG(SG_INPUT, SG_INFO, "Center: " << zero.x() << ", " << zero.y() << ", " << zero.z() );
526     SG_LOG(SG_INPUT, SG_INFO, "Rotation: " << lat_deg << ", " << lon_deg );
527
528     return true;
529 }
530
531 static bool
532 do_print_visible_scene_info(const SGPropertyNode*)
533 {
534     fgPrintVisibleSceneInfoCommand();
535     return true;
536 }
537
538 /**
539  * Built-in command: hires capture screen.
540  */
541 static bool
542 do_hires_screen_capture (const SGPropertyNode * arg)
543 {
544   fgHiResDump();
545   return true;
546 }
547
548
549 /**
550  * Reload the tile cache.
551  */
552 static bool
553 do_tile_cache_reload (const SGPropertyNode * arg)
554 {
555     static const SGPropertyNode *master_freeze
556         = fgGetNode("/sim/freeze/master");
557     bool freeze = master_freeze->getBoolValue();
558     SG_LOG(SG_INPUT, SG_INFO, "ReIniting TileCache");
559     if ( !freeze ) {
560         fgSetBool("/sim/freeze/master", true);
561     }
562
563     globals->get_subsystem("tile-manager")->reinit();
564
565     if ( !freeze ) {
566         fgSetBool("/sim/freeze/master", false);
567     }
568     return true;
569 }
570
571
572 #if 0
573 These do_set_(some-environment-parameters) are deprecated and no longer 
574 useful/functional - Torsten Dreyer, January 2011
575 /**
576  * Set the sea level outside air temperature and assigning that to all
577  * boundary and aloft environment layers.
578  */
579 static bool
580 do_set_sea_level_degc ( double temp_sea_level_degc)
581 {
582     SGPropertyNode *node, *child;
583
584     // boundary layers
585     node = fgGetNode( "/environment/config/boundary" );
586     if ( node != NULL ) {
587       int i = 0;
588       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
589         child->setDoubleValue( "temperature-sea-level-degc",
590                                temp_sea_level_degc );
591         ++i;
592       }
593     }
594
595     // aloft layers
596     node = fgGetNode( "/environment/config/aloft" );
597     if ( node != NULL ) {
598       int i = 0;
599       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
600         child->setDoubleValue( "temperature-sea-level-degc",
601                                temp_sea_level_degc );
602         ++i;
603       }
604     }
605
606     return true;
607 }
608
609 static bool
610 do_set_sea_level_degc (const SGPropertyNode * arg)
611 {
612     return do_set_sea_level_degc( arg->getDoubleValue("temp-degc", 15.0) );
613 }
614
615
616 /**
617  * Set the outside air temperature at the "current" altitude by first
618  * calculating the corresponding sea level temp, and assigning that to
619  * all boundary and aloft environment layers.
620  */
621 static bool
622 do_set_oat_degc (const SGPropertyNode * arg)
623 {
624     double oat_degc = arg->getDoubleValue("temp-degc", 15.0);
625     // check for an altitude specified in the arguments, otherwise use
626     // current aircraft altitude.
627     const SGPropertyNode *altitude_ft = arg->getChild("altitude-ft");
628     if ( altitude_ft == NULL ) {
629         altitude_ft = fgGetNode("/position/altitude-ft");
630     }
631
632     FGEnvironment dummy;        // instantiate a dummy so we can leech a method
633     dummy.set_elevation_ft( altitude_ft->getDoubleValue() );
634     dummy.set_temperature_degc( oat_degc );
635     return do_set_sea_level_degc( dummy.get_temperature_sea_level_degc());
636 }
637
638 /**
639  * Set the sea level outside air dewpoint and assigning that to all
640  * boundary and aloft environment layers.
641  */
642 static bool
643 do_set_dewpoint_sea_level_degc (double dewpoint_sea_level_degc)
644 {
645
646     SGPropertyNode *node, *child;
647
648     // boundary layers
649     node = fgGetNode( "/environment/config/boundary" );
650     if ( node != NULL ) {
651       int i = 0;
652       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
653         child->setDoubleValue( "dewpoint-sea-level-degc",
654                                dewpoint_sea_level_degc );
655         ++i;
656       }
657     }
658
659     // aloft layers
660     node = fgGetNode( "/environment/config/aloft" );
661     if ( node != NULL ) {
662       int i = 0;
663       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
664         child->setDoubleValue( "dewpoint-sea-level-degc",
665                                dewpoint_sea_level_degc );
666         ++i;
667       }
668     }
669
670     return true;
671 }
672
673 static bool
674 do_set_dewpoint_sea_level_degc (const SGPropertyNode * arg)
675 {
676     return do_set_dewpoint_sea_level_degc(arg->getDoubleValue("dewpoint-degc", 5.0));
677 }
678
679 /**
680  * Set the outside air dewpoint at the "current" altitude by first
681  * calculating the corresponding sea level dewpoint, and assigning
682  * that to all boundary and aloft environment layers.
683  */
684 static bool
685 do_set_dewpoint_degc (const SGPropertyNode * arg)
686 {
687     double dewpoint_degc = arg->getDoubleValue("dewpoint-degc", 5.0);
688
689     // check for an altitude specified in the arguments, otherwise use
690     // current aircraft altitude.
691     const SGPropertyNode *altitude_ft = arg->getChild("altitude-ft");
692     if ( altitude_ft == NULL ) {
693         altitude_ft = fgGetNode("/position/altitude-ft");
694     }
695
696     FGEnvironment dummy;        // instantiate a dummy so we can leech a method
697     dummy.set_elevation_ft( altitude_ft->getDoubleValue() );
698     dummy.set_dewpoint_degc( dewpoint_degc );
699     return do_set_dewpoint_sea_level_degc(dummy.get_dewpoint_sea_level_degc());
700 }
701 #endif
702 /**
703  * Update the lighting manually.
704  */
705 static bool
706 do_timeofday (const SGPropertyNode * arg)
707 {
708     const string &offset_type = arg->getStringValue("timeofday", "noon");
709
710     static const SGPropertyNode *longitude
711         = fgGetNode("/position/longitude-deg");
712     static const SGPropertyNode *latitude
713         = fgGetNode("/position/latitude-deg");
714
715     int orig_warp = globals->get_warp();
716     SGTime *t = globals->get_time_params();
717     time_t cur_time = t->get_cur_time();
718     // cout << "cur_time = " << cur_time << endl;
719     // cout << "orig_warp = " << orig_warp << endl;
720
721     int warp = 0;
722     if ( offset_type == "real" ) {
723         warp = -orig_warp;
724     } else if ( offset_type == "dawn" ) {
725         warp = fgTimeSecondsUntilSunAngle( cur_time,
726                                            longitude->getDoubleValue()
727                                              * SGD_DEGREES_TO_RADIANS,
728                                            latitude->getDoubleValue()
729                                              * SGD_DEGREES_TO_RADIANS,
730                                            90.0, true ); 
731     } else if ( offset_type == "morning" ) {
732         warp = fgTimeSecondsUntilSunAngle( cur_time,
733                                            longitude->getDoubleValue()
734                                              * SGD_DEGREES_TO_RADIANS,
735                                            latitude->getDoubleValue()
736                                              * SGD_DEGREES_TO_RADIANS,
737                                            75.0, true ); 
738     } else if ( offset_type == "noon" ) {
739         warp = fgTimeSecondsUntilSunAngle( cur_time,
740                                            longitude->getDoubleValue()
741                                              * SGD_DEGREES_TO_RADIANS,
742                                            latitude->getDoubleValue()
743                                              * SGD_DEGREES_TO_RADIANS,
744                                            0.0, true ); 
745     } else if ( offset_type == "afternoon" ) {
746         warp = fgTimeSecondsUntilSunAngle( cur_time,
747                                            longitude->getDoubleValue()
748                                              * SGD_DEGREES_TO_RADIANS,
749                                            latitude->getDoubleValue()
750                                              * SGD_DEGREES_TO_RADIANS,
751                                            60.0, false ); 
752      } else if ( offset_type == "dusk" ) {
753         warp = fgTimeSecondsUntilSunAngle( cur_time,
754                                            longitude->getDoubleValue()
755                                              * SGD_DEGREES_TO_RADIANS,
756                                            latitude->getDoubleValue()
757                                              * SGD_DEGREES_TO_RADIANS,
758                                            90.0, false ); 
759      } else if ( offset_type == "evening" ) {
760         warp = fgTimeSecondsUntilSunAngle( cur_time,
761                                            longitude->getDoubleValue()
762                                              * SGD_DEGREES_TO_RADIANS,
763                                            latitude->getDoubleValue()
764                                              * SGD_DEGREES_TO_RADIANS,
765                                            100.0, false ); 
766     } else if ( offset_type == "midnight" ) {
767         warp = fgTimeSecondsUntilSunAngle( cur_time,
768                                            longitude->getDoubleValue()
769                                              * SGD_DEGREES_TO_RADIANS,
770                                            latitude->getDoubleValue()
771                                              * SGD_DEGREES_TO_RADIANS,
772                                            180.0, false ); 
773     }
774     
775
776     fgSetInt("/sim/time/warp", orig_warp + warp);
777     
778     return true;
779 }
780
781
782 /**
783  * Built-in command: toggle a bool property value.
784  *
785  * property: The name of the property to toggle.
786  */
787 static bool
788 do_property_toggle (const SGPropertyNode * arg)
789 {
790   SGPropertyNode * prop = get_prop(arg);
791   return prop->setBoolValue(!prop->getBoolValue());
792 }
793
794
795 /**
796  * Built-in command: assign a value to a property.
797  *
798  * property: the name of the property to assign.
799  * value: the value to assign; or
800  * property[1]: the property to copy from.
801  */
802 static bool
803 do_property_assign (const SGPropertyNode * arg)
804 {
805   SGPropertyNode * prop = get_prop(arg);
806   const SGPropertyNode * prop2 = get_prop2(arg);
807   const SGPropertyNode * value = arg->getNode("value");
808
809   if (value != 0)
810       return prop->setUnspecifiedValue(value->getStringValue());
811   else if (prop2)
812       return prop->setUnspecifiedValue(prop2->getStringValue());
813   else
814       return false;
815 }
816
817
818 /**
819  * Built-in command: increment or decrement a property value.
820  *
821  * If the 'step' argument is present, it will be used; otherwise,
822  * the command uses 'offset' and 'factor', usually from the mouse.
823  *
824  * property: the name of the property to increment or decrement.
825  * step: the amount of the increment or decrement (default: 0).
826  * offset: offset from the current setting (used for the mouse; multiplied 
827  *         by factor)
828  * factor: scaling amount for the offset (defaults to 1).
829  * min: the minimum allowed value (default: no minimum).
830  * max: the maximum allowed value (default: no maximum).
831  * mask: 'integer' to apply only to the left of the decimal point, 
832  *       'decimal' to apply only to the right of the decimal point,
833  *       or 'all' to apply to the whole number (the default).
834  * wrap: true if the value should be wrapped when it passes min or max;
835  *       both min and max must be present for this to work (default:
836  *       false).
837  */
838 static bool
839 do_property_adjust (const SGPropertyNode * arg)
840 {
841   SGPropertyNode * prop = get_prop(arg);
842
843   double amount = 0;
844   if (arg->hasValue("step"))
845       amount = arg->getDoubleValue("step");
846   else
847       amount = (arg->getDoubleValue("factor", 1)
848                 * arg->getDoubleValue("offset"));
849           
850   double unmodifiable, modifiable;
851   split_value(prop->getDoubleValue(), arg->getStringValue("mask", "all"),
852               &unmodifiable, &modifiable);
853   modifiable += amount;
854   limit_value(&modifiable, arg);
855
856   prop->setDoubleValue(unmodifiable + modifiable);
857
858   return true;
859 }
860
861
862 /**
863  * Built-in command: multiply a property value.
864  *
865  * property: the name of the property to multiply.
866  * factor: the amount by which to multiply.
867  * min: the minimum allowed value (default: no minimum).
868  * max: the maximum allowed value (default: no maximum).
869  * mask: 'integer' to apply only to the left of the decimal point, 
870  *       'decimal' to apply only to the right of the decimal point,
871  *       or 'all' to apply to the whole number (the default).
872  * wrap: true if the value should be wrapped when it passes min or max;
873  *       both min and max must be present for this to work (default:
874  *       false).
875  */
876 static bool
877 do_property_multiply (const SGPropertyNode * arg)
878 {
879   SGPropertyNode * prop = get_prop(arg);
880   double factor = arg->getDoubleValue("factor", 1);
881
882   double unmodifiable, modifiable;
883   split_value(prop->getDoubleValue(), arg->getStringValue("mask", "all"),
884               &unmodifiable, &modifiable);
885   modifiable *= factor;
886   limit_value(&modifiable, arg);
887
888   prop->setDoubleValue(unmodifiable + modifiable);
889
890   return true;
891 }
892
893
894 /**
895  * Built-in command: swap two property values.
896  *
897  * property[0]: the name of the first property.
898  * property[1]: the name of the second property.
899  */
900 static bool
901 do_property_swap (const SGPropertyNode * arg)
902 {
903   SGPropertyNode * prop1 = get_prop(arg);
904   SGPropertyNode * prop2 = get_prop2(arg);
905
906                                 // FIXME: inefficient
907   const string & tmp = prop1->getStringValue();
908   return (prop1->setUnspecifiedValue(prop2->getStringValue()) &&
909           prop2->setUnspecifiedValue(tmp.c_str()));
910 }
911
912
913 /**
914  * Built-in command: Set a property to an axis or other moving input.
915  *
916  * property: the name of the property to set.
917  * setting: the current input setting, usually between -1.0 and 1.0.
918  * offset: the offset to shift by, before applying the factor.
919  * factor: the factor to multiply by (use negative to reverse).
920  */
921 static bool
922 do_property_scale (const SGPropertyNode * arg)
923 {
924   SGPropertyNode * prop = get_prop(arg);
925   double setting = arg->getDoubleValue("setting");
926   double offset = arg->getDoubleValue("offset", 0.0);
927   double factor = arg->getDoubleValue("factor", 1.0);
928   bool squared = arg->getBoolValue("squared", false);
929   int power = arg->getIntValue("power", (squared ? 2 : 1));
930
931   int sign = (setting < 0 ? -1 : 1);
932
933   switch (power) {
934   case 1:
935       break;
936   case 2:
937       setting = setting * setting * sign;
938       break;
939   case 3:
940       setting = setting * setting * setting;
941       break;
942   case 4:
943       setting = setting * setting * setting * setting * sign;
944       break;
945   default:
946       setting =  pow(setting, power);
947       if ((power % 2) == 0)
948           setting *= sign;
949       break;
950   }
951
952   return prop->setDoubleValue((setting + offset) * factor);
953 }
954
955
956 /**
957  * Built-in command: cycle a property through a set of values.
958  *
959  * If the current value isn't in the list, the cycle will
960  * (re)start from the beginning.
961  *
962  * property: the name of the property to cycle.
963  * value[*]: the list of values to cycle through.
964  */
965 static bool
966 do_property_cycle (const SGPropertyNode * arg)
967 {
968     SGPropertyNode * prop = get_prop(arg);
969     vector<SGPropertyNode_ptr> values = arg->getChildren("value");
970     int selection = -1;
971     int nSelections = values.size();
972
973     if (nSelections < 1) {
974         SG_LOG(SG_GENERAL, SG_ALERT, "No values for property-cycle");
975         return false;
976     }
977
978                                 // Try to find the current selection
979     for (int i = 0; i < nSelections; i++) {
980         if (compare_values(prop, values[i])) {
981             selection = i + 1;
982             break;
983         }
984     }
985
986                                 // Default or wrap to the first selection
987     if (selection < 0 || selection >= nSelections)
988         selection = 0;
989
990     prop->setUnspecifiedValue(values[selection]->getStringValue());
991     return true;
992 }
993
994
995 /**
996  * Built-in command: randomize a numeric property value.
997  *
998  * property: the name of the property value to randomize.
999  * min: the minimum allowed value.
1000  * max: the maximum allowed value.
1001  */
1002 static bool
1003 do_property_randomize (const SGPropertyNode * arg)
1004 {
1005     SGPropertyNode * prop = get_prop(arg);
1006     double min = arg->getDoubleValue("min", DBL_MIN);
1007     double max = arg->getDoubleValue("max", DBL_MAX);
1008     prop->setDoubleValue(sg_random() * (max - min) + min);
1009     return true;
1010 }
1011
1012
1013 /**
1014  * Built-in command: reinit the data logging system based on the
1015  * current contents of the /logger tree.
1016  */
1017 static bool
1018 do_data_logging_commit (const SGPropertyNode * arg)
1019 {
1020     FGLogger *log = (FGLogger *)globals->get_subsystem("logger");
1021     log->reinit();
1022     return true;
1023 }
1024
1025 /**
1026  * Built-in command: Add a dialog to the GUI system.  Does *not*
1027  * display the dialog.  The property node should have the same format
1028  * as a dialog XML configuration.  It must include:
1029  *
1030  * name: the name of the GUI dialog for future reference.
1031  */
1032 static bool
1033 do_dialog_new (const SGPropertyNode * arg)
1034 {
1035     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1036
1037     // Note the casting away of const: this is *real*.  Doing a
1038     // "dialog-apply" command later on will mutate this property node.
1039     // I'm not convinced that this isn't the Right Thing though; it
1040     // allows client to create a node, pass it to dialog-new, and get
1041     // the values back from the dialog by reading the same node.
1042     // Perhaps command arguments are not as "const" as they would
1043     // seem?
1044     gui->newDialog((SGPropertyNode*)arg);
1045     return true;
1046 }
1047
1048 /**
1049  * Built-in command: Show an XML-configured dialog.
1050  *
1051  * dialog-name: the name of the GUI dialog to display.
1052  */
1053 static bool
1054 do_dialog_show (const SGPropertyNode * arg)
1055 {
1056     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1057     gui->showDialog(arg->getStringValue("dialog-name"));
1058     return true;
1059 }
1060
1061
1062 /**
1063  * Built-in Command: Hide the active XML-configured dialog.
1064  */
1065 static bool
1066 do_dialog_close (const SGPropertyNode * arg)
1067 {
1068     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1069     if(arg->hasValue("dialog-name"))
1070         return gui->closeDialog(arg->getStringValue("dialog-name"));
1071     return gui->closeActiveDialog();
1072 }
1073
1074
1075 /**
1076  * Update a value in the active XML-configured dialog.
1077  *
1078  * object-name: The name of the GUI object(s) (all GUI objects if omitted).
1079  */
1080 static bool
1081 do_dialog_update (const SGPropertyNode * arg)
1082 {
1083     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1084     FGDialog * dialog;
1085     if (arg->hasValue("dialog-name"))
1086         dialog = gui->getDialog(arg->getStringValue("dialog-name"));
1087     else
1088         dialog = gui->getActiveDialog();
1089
1090     if (dialog != 0) {
1091         dialog->updateValues(arg->getStringValue("object-name"));
1092         return true;
1093     } else {
1094         return false;
1095     }
1096 }
1097
1098
1099 /**
1100  * Apply a value in the active XML-configured dialog.
1101  *
1102  * object-name: The name of the GUI object(s) (all GUI objects if omitted).
1103  */
1104 static bool
1105 do_dialog_apply (const SGPropertyNode * arg)
1106 {
1107     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1108     FGDialog * dialog;
1109     if (arg->hasValue("dialog-name"))
1110         dialog = gui->getDialog(arg->getStringValue("dialog-name"));
1111     else
1112         dialog = gui->getActiveDialog();
1113
1114     if (dialog != 0) {
1115         dialog->applyValues(arg->getStringValue("object-name"));
1116         return true;
1117     } else {
1118         return false;
1119     }
1120 }
1121
1122
1123 /**
1124  * Redraw GUI (applying new widget colors). Doesn't reload the dialogs,
1125  * unlike reinit().
1126  */
1127 static bool
1128 do_gui_redraw (const SGPropertyNode * arg)
1129 {
1130     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1131     gui->redraw();
1132     return true;
1133 }
1134
1135
1136 /**
1137  * Adds model to the scenery. The path to the added branch (/models/model[*])
1138  * is returned in property "property".
1139  */
1140 static bool
1141 do_add_model (const SGPropertyNode * arg)
1142 {
1143     SGPropertyNode * model = fgGetNode("models", true);
1144     for (int i = 0;; i++) {
1145         if (i < 0)
1146             return false;
1147         if (!model->getChild("model", i, false)) {
1148             model = model->getChild("model", i, true);
1149             break;
1150         }
1151     }
1152     copyProperties(arg, model);
1153     if (model->hasValue("elevation-m"))
1154         model->setDoubleValue("elevation-ft", model->getDoubleValue("elevation-m")
1155                 * SG_METER_TO_FEET);
1156     model->getNode("load", true);
1157     model->removeChildren("load");
1158     const_cast<SGPropertyNode *>(arg)->setStringValue("property", model->getPath());
1159     return true;
1160 }
1161
1162
1163 /**
1164  * Set mouse cursor coordinates and cursor shape.
1165  */
1166 static bool
1167 do_set_cursor (const SGPropertyNode * arg)
1168 {
1169     if (arg->hasValue("x") || arg->hasValue("y")) {
1170         SGPropertyNode *mx = fgGetNode("/devices/status/mice/mouse/x", true);
1171         SGPropertyNode *my = fgGetNode("/devices/status/mice/mouse/y", true);
1172         int x = arg->getIntValue("x", mx->getIntValue());
1173         int y = arg->getIntValue("y", my->getIntValue());
1174         fgWarpMouse(x, y);
1175         mx->setIntValue(x);
1176         my->setIntValue(y);
1177     }
1178
1179     SGPropertyNode *cursor = const_cast<SGPropertyNode *>(arg)->getNode("cursor", true);
1180     if (cursor->getType() != simgear::props::NONE)
1181         fgSetMouseCursor(cursor->getIntValue());
1182
1183     cursor->setIntValue(fgGetMouseCursor());
1184     return true;
1185 }
1186
1187
1188 /**
1189  * Built-in command: play an audio message (i.e. a wav file) This is
1190  * fire and forget.  Call this once per message and it will get dumped
1191  * into a queue.  Messages are played sequentially so they do not
1192  * overlap.
1193  */
1194 static bool
1195 do_play_audio_sample (const SGPropertyNode * arg)
1196 {
1197     string path = arg->getStringValue("path");
1198     string file = arg->getStringValue("file");
1199     float volume = arg->getFloatValue("volume");
1200     // cout << "playing " << path << " / " << file << endl;
1201     try {
1202         static FGSampleQueue *queue = 0;
1203         if ( !queue ) {
1204            SGSoundMgr *smgr = globals->get_soundmgr();
1205            queue = new FGSampleQueue(smgr, "chatter");
1206            queue->tie_to_listener();
1207         }
1208
1209         SGSoundSample *msg = new SGSoundSample(file.c_str(), path);
1210         msg->set_volume( volume );
1211         queue->add( msg );
1212
1213         return true;
1214
1215     } catch (const sg_io_exception&) {
1216         SG_LOG(SG_GENERAL, SG_ALERT, "play-audio-sample: "
1217                 "failed to load" << path << '/' << file);
1218         return false;
1219     }
1220 }
1221
1222 /**
1223  * Built-in command: commit presets (read from in /sim/presets/)
1224  */
1225 static bool
1226 do_presets_commit (const SGPropertyNode * arg)
1227 {
1228     if (fgGetBool("/sim/initialized", false)) {
1229       fgReInitSubsystems();
1230     } else {
1231       // Nasal can trigger this during initial init, which confuses
1232       // the logic in ReInitSubsystems, since initial state has not been
1233       // saved at that time. Short-circuit everything here.
1234       fgInitPosition();
1235     }
1236     
1237     return true;
1238 }
1239
1240 /**
1241  * Built-in command: set log level (0 ... 7)
1242  */
1243 static bool
1244 do_log_level (const SGPropertyNode * arg)
1245 {
1246    sglog().setLogLevels( SG_ALL, (sgDebugPriority)arg->getIntValue() );
1247
1248    return true;
1249 }
1250
1251 /**
1252  * Built-in command: replay the FDR buffer
1253  */
1254 static bool
1255 do_replay (const SGPropertyNode * arg)
1256 {
1257     // freeze the fdm, resume from sim pause 
1258     fgSetInt( "/sim/freeze/replay-state", 1 );
1259     fgSetBool("/sim/freeze/master", 0 );
1260     fgSetBool("/sim/freeze/clock", 0 );
1261     fgSetDouble( "/sim/replay/time", -1 );
1262
1263     // cout << "start = " << r->get_start_time()
1264     //      << "  end = " << r->get_end_time() << endl;
1265
1266     return true;
1267 }
1268
1269 /*
1270 static bool
1271 do_decrease_visibility (const SGPropertyNode * arg)
1272 {
1273     Environment::Presets::VisibilitySingleton::instance()->adjust( 0.9 );
1274     return true;
1275 }
1276  
1277 static bool
1278 do_increase_visibility (const SGPropertyNode * arg)
1279 {
1280     Environment::Presets::VisibilitySingleton::instance()->adjust( 1.1 );
1281     return true;
1282 }
1283 */
1284 /**
1285  * An fgcommand to allow loading of xml files via nasal,
1286  * the xml file's structure will be made available within
1287  * a property tree node defined under argument "targetnode",
1288  * or in the given argument tree under "data" otherwise.
1289  *
1290  * @param filename a string to hold the complete path & filename of an XML file
1291  * @param targetnode a string pointing to a location within the property tree
1292  * where to store the parsed XML file. If <targetnode> is undefined, then the
1293  * file contents are stored under a node <data> in the argument tree.
1294  */
1295
1296 static bool
1297 do_load_xml_to_proptree(const SGPropertyNode * arg)
1298 {
1299     SGPath file(arg->getStringValue("filename"));
1300     if (file.str().empty())
1301         return false;
1302
1303     if (file.extension() != "xml")
1304         file.concat(".xml");
1305     
1306     std::string icao = arg->getStringValue("icao");
1307     if (icao.empty()) {
1308         if (file.isRelative()) {
1309           file = globals->resolve_maybe_aircraft_path(file.str());
1310         }
1311     } else {
1312         if (!XMLLoader::findAirportData(icao, file.str(), file)) {
1313           SG_LOG(SG_IO, SG_INFO, "loadxml: failed to find airport data for "
1314             << file.str() << " at ICAO:" << icao);
1315           return false;
1316         }
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     { "pause", do_pause },
1456     { "load", do_load },
1457     { "save", do_save },
1458     { "panel-load", do_panel_load },
1459     { "panel-mouse-click", do_panel_mouse_click },
1460     { "preferences-load", do_preferences_load },
1461     { "view-cycle", do_view_cycle },
1462     { "screen-capture", do_screen_capture },
1463     { "hires-screen-capture", do_hires_screen_capture },
1464     { "tile-cache-reload", do_tile_cache_reload },
1465     /*
1466     { "set-sea-level-air-temp-degc", do_set_sea_level_degc },
1467     { "set-outside-air-temp-degc", do_set_oat_degc },
1468     { "set-dewpoint-sea-level-air-temp-degc", do_set_dewpoint_sea_level_degc },
1469     { "set-dewpoint-temp-degc", do_set_dewpoint_degc },
1470     */
1471     { "timeofday", do_timeofday },
1472     { "property-toggle", do_property_toggle },
1473     { "property-assign", do_property_assign },
1474     { "property-adjust", do_property_adjust },
1475     { "property-multiply", do_property_multiply },
1476     { "property-swap", do_property_swap },
1477     { "property-scale", do_property_scale },
1478     { "property-cycle", do_property_cycle },
1479     { "property-randomize", do_property_randomize },
1480     { "data-logging-commit", do_data_logging_commit },
1481     { "dialog-new", do_dialog_new },
1482     { "dialog-show", do_dialog_show },
1483     { "dialog-close", do_dialog_close },
1484     { "dialog-update", do_dialog_update },
1485     { "dialog-apply", do_dialog_apply },
1486     { "gui-redraw", do_gui_redraw },
1487     { "add-model", do_add_model },
1488     { "set-cursor", do_set_cursor },
1489     { "play-audio-sample", do_play_audio_sample },
1490     { "presets-commit", do_presets_commit },
1491     { "log-level", do_log_level },
1492     { "replay", do_replay },
1493     /*
1494     { "decrease-visibility", do_decrease_visibility },
1495     { "increase-visibility", do_increase_visibility },
1496     */
1497     { "loadxml", do_load_xml_to_proptree},
1498     { "savexml", do_save_xml_from_proptree },
1499     { "press-cockpit-button", do_press_cockpit_button },
1500     { "release-cockpit-button", do_release_cockpit_button },
1501     { "dump-scenegraph", do_dump_scene_graph },
1502     { "dump-terrainbranch", do_dump_terrain_branch },
1503     { "print-visible-scene", do_print_visible_scene_info },
1504     { "reload-shaders", do_reload_shaders },
1505     { 0, 0 }                    // zero-terminated
1506 };
1507
1508
1509 /**
1510  * Initialize the default built-in commands.
1511  *
1512  * Other commands may be added by other parts of the application.
1513  */
1514 void
1515 fgInitCommands ()
1516 {
1517   SG_LOG(SG_GENERAL, SG_BULK, "Initializing basic built-in commands:");
1518   for (int i = 0; built_ins[i].name != 0; i++) {
1519     SG_LOG(SG_GENERAL, SG_BULK, "  " << built_ins[i].name);
1520     globals->get_commands()->addCommand(built_ins[i].name,
1521                                         built_ins[i].command);
1522   }
1523
1524   typedef bool (*dummy)();
1525   fgTie( "/command/view/next", dummy(0), do_view_next );
1526   fgTie( "/command/view/prev", dummy(0), do_view_prev );
1527 }
1528
1529 // end of fg_commands.cxx