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