]> git.mxchange.org Git - flightgear.git/blob - src/Main/fg_commands.cxx
74551bc9170b683f7fc1aa87a7c82b97112e1d3e
[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 <Cockpit/hud.hxx>
29 #include <Environment/environment.hxx>
30 #include <FDM/flight.hxx>
31 #include <GUI/gui.h>
32 #include <GUI/new_gui.hxx>
33 #include <GUI/dialog.hxx>
34 #include <Aircraft/replay.hxx>
35 #include <Scenery/tilemgr.hxx>
36 #include <Scenery/scenery.hxx>
37 #include <Scripting/NasalSys.hxx>
38 #include <Sound/sample_queue.hxx>
39 #include <Time/sunsolver.hxx>
40
41 #include "fg_init.hxx"
42 #include "fg_io.hxx"
43 #include "fg_os.hxx"
44 #include "fg_commands.hxx"
45 #include "fg_props.hxx"
46 #include "globals.hxx"
47 #include "logger.hxx"
48 #include "util.hxx"
49 #include "viewmgr.hxx"
50 #include "main.hxx"
51 #include <Main/viewer.hxx>
52
53 using std::string;
54 using std::ifstream;
55 using std::ofstream;
56
57
58 \f
59 ////////////////////////////////////////////////////////////////////////
60 // Static helper functions.
61 ////////////////////////////////////////////////////////////////////////
62
63
64 static inline SGPropertyNode *
65 get_prop (const SGPropertyNode * arg)
66 {
67     return fgGetNode(arg->getStringValue("property[0]", "/null"), true);
68 }
69
70 static inline SGPropertyNode *
71 get_prop2 (const SGPropertyNode * arg)
72 {
73     return fgGetNode(arg->getStringValue("property[1]", "/null"), true);
74 }
75
76
77 /**
78  * Get a double value and split it as required.
79  */
80 static void
81 split_value (double full_value, const char * mask,
82              double * unmodifiable, double * modifiable)
83 {
84     if (!strcmp("integer", mask)) {
85         *modifiable = (full_value < 0 ? ceil(full_value) : floor (full_value));
86         *unmodifiable = full_value - *modifiable;
87     } else if (!strcmp("decimal", mask)) {
88         *unmodifiable = (full_value < 0 ? ceil(full_value) : floor(full_value));
89         *modifiable = full_value - *unmodifiable;
90     } else {
91         if (strcmp("all", mask))
92             SG_LOG(SG_GENERAL, SG_ALERT, "Bad value " << mask << " for mask;"
93                    << " assuming 'all'");
94         *unmodifiable = 0;
95         *modifiable = full_value;
96     }
97 }
98
99
100 /**
101  * Clamp or wrap a value as specified.
102  */
103 static void
104 limit_value (double * value, const SGPropertyNode * arg)
105 {
106     const SGPropertyNode * min_node = arg->getChild("min");
107     const SGPropertyNode * max_node = arg->getChild("max");
108
109     bool wrap = arg->getBoolValue("wrap");
110
111     if (min_node == 0 || max_node == 0)
112         wrap = false;
113   
114     if (wrap) {                 // wrap such that min <= x < max
115         double min_val = min_node->getDoubleValue();
116         double max_val = max_node->getDoubleValue();
117         double resolution = arg->getDoubleValue("resolution");
118         if (resolution > 0.0) {
119             // snap to (min + N*resolution), taking special care to handle imprecision
120             int n = (int)floor((*value - min_val) / resolution + 0.5);
121             int steps = (int)floor((max_val - min_val) / resolution + 0.5);
122             SG_NORMALIZE_RANGE(n, 0, steps);
123             *value = min_val + resolution * n;
124         } else {
125             // plain circular wrapping
126             SG_NORMALIZE_RANGE(*value, min_val, max_val);
127         }
128     } else {                    // clamp such that min <= x <= max
129         if ((min_node != 0) && (*value < min_node->getDoubleValue()))
130             *value = min_node->getDoubleValue();
131         else if ((max_node != 0) && (*value > max_node->getDoubleValue()))
132             *value = max_node->getDoubleValue();
133     }
134 }
135
136 static bool
137 compare_values (SGPropertyNode * value1, SGPropertyNode * value2)
138 {
139     switch (value1->getType()) {
140     case simgear::props::BOOL:
141         return (value1->getBoolValue() == value2->getBoolValue());
142     case simgear::props::INT:
143         return (value1->getIntValue() == value2->getIntValue());
144     case simgear::props::LONG:
145         return (value1->getLongValue() == value2->getLongValue());
146     case simgear::props::FLOAT:
147         return (value1->getFloatValue() == value2->getFloatValue());
148     case simgear::props::DOUBLE:
149         return (value1->getDoubleValue() == value2->getDoubleValue());
150     default:
151         return !strcmp(value1->getStringValue(), value2->getStringValue());
152     }
153 }
154
155
156 \f
157 ////////////////////////////////////////////////////////////////////////
158 // Command implementations.
159 ////////////////////////////////////////////////////////////////////////
160
161
162 /**
163  * Built-in command: do nothing.
164  */
165 static bool
166 do_null (const SGPropertyNode * arg)
167 {
168   return true;
169 }
170
171 /**
172  * Built-in command: run a Nasal script.
173  */
174 static bool
175 do_nasal (const SGPropertyNode * arg)
176 {
177     return ((FGNasalSys*)globals->get_subsystem("nasal"))->handleCommand(arg);
178 }
179
180 /**
181  * Built-in command: exit FlightGear.
182  *
183  * status: the exit status to return to the operating system (defaults to 0)
184  */
185 static bool
186 do_exit (const SGPropertyNode * arg)
187 {
188     SG_LOG(SG_INPUT, SG_INFO, "Program exit requested.");
189     fgSetBool("/sim/signals/exit", true);
190
191     if (fgGetBool("/sim/startup/save-on-exit")) {
192 #ifdef _WIN32
193         char* envp = ::getenv( "APPDATA" );
194         if ( envp != NULL ) {
195             SGPath config( envp );
196             config.append( "flightgear.org" );
197 #else
198         if ( homedir != NULL ) {
199             SGPath config( homedir );
200             config.append( ".fgfs" );
201 #endif
202             config.append( "autosave.xml" );
203             config.create_dir( 0700 );
204             SG_LOG(SG_IO, SG_INFO, "Saving user settings to " << config.str());
205             try {
206                 writeProperties(config.str(), globals->get_props(), false, SGPropertyNode::USERARCHIVE);
207             } catch (const sg_exception &e) {
208                 guiErrorMessage("Error writing autosave.xml: ", e);
209             }
210
211             SG_LOG(SG_INPUT, SG_DEBUG, "Finished Saving user settings");
212         }
213     }
214     
215     fgOSExit(arg->getIntValue("status", 0));
216     return true;
217 }
218
219
220 /**
221  * Reset FlightGear (Shift-Escape or Menu->File->Reset)
222  */
223 static bool
224 do_reset (const SGPropertyNode * arg)
225 {
226     doSimulatorReset();
227     return true;
228 }
229
230
231 /**
232  * Built-in command: reinitialize one or more subsystems.
233  *
234  * subsystem[*]: the name(s) of the subsystem(s) to reinitialize; if
235  * none is specified, reinitialize all of them.
236  */
237 static bool
238 do_reinit (const SGPropertyNode * arg)
239 {
240     bool result = true;
241
242     vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
243     if (subsystems.size() == 0) {
244         globals->get_subsystem_mgr()->reinit();
245     } else {
246         for ( unsigned int i = 0; i < subsystems.size(); i++ ) {
247             const char * name = subsystems[i]->getStringValue();
248             SGSubsystem * subsystem = globals->get_subsystem(name);
249             if (subsystem == 0) {
250                 result = false;
251                 SG_LOG( SG_GENERAL, SG_ALERT,
252                         "Subsystem " << name << "not found" );
253             } else {
254                 subsystem->reinit();
255             }
256         }
257     }
258
259     globals->get_event_mgr()->reinit();
260
261     return result;
262 }
263
264 #if 0
265   //
266   // these routines look useful ??? but are never used in the code ???
267   //
268
269 /**
270  * Built-in command: suspend one or more subsystems.
271  *
272  * subsystem[*] - the name(s) of the subsystem(s) to suspend.
273  */
274 static bool
275 do_suspend (const SGPropertyNode * arg)
276 {
277     bool result = true;
278
279     vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
280     for ( unsigned int i = 0; i < subsystems.size(); i++ ) {
281         const char * name = subsystems[i]->getStringValue();
282         SGSubsystem * subsystem = globals->get_subsystem(name);
283         if (subsystem == 0) {
284             result = false;
285             SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << "not found");
286         } else {
287             subsystem->suspend();
288         }
289     }
290     return result;
291 }
292
293 /**
294  * Built-in command: suspend one or more subsystems.
295  *
296  * subsystem[*] - the name(s) of the subsystem(s) to suspend.
297  */
298 static bool
299 do_resume (const SGPropertyNode * arg)
300 {
301     bool result = true;
302
303     vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
304     for ( unsigned int i = 0; i < subsystems.size(); i++ ) {
305         const char * name = subsystems[i]->getStringValue();
306         SGSubsystem * subsystem = globals->get_subsystem(name);
307         if (subsystem == 0) {
308             result = false;
309             SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << "not found");
310         } else {
311             subsystem->resume();
312         }
313     }
314     return result;
315 }
316
317 #endif
318
319
320 /**
321  * Built-in command: load flight.
322  *
323  * file (optional): the name of the file to load (relative to current
324  *   directory).  Defaults to "fgfs.sav"
325  */
326 static bool
327 do_load (const SGPropertyNode * arg)
328 {
329     string file = arg->getStringValue("file", "fgfs.sav");
330     if (file.size() < 4 || file.substr(file.size() - 4) != ".sav")
331         file += ".sav";
332
333     if (!fgValidatePath(file.c_str(), false)) {
334         SG_LOG(SG_IO, SG_ALERT, "load: reading '" << file << "' denied "
335                 "(unauthorized access)");
336         return false;
337     }
338
339     ifstream input(file.c_str());
340     if (input.good() && fgLoadFlight(input)) {
341         input.close();
342         SG_LOG(SG_INPUT, SG_INFO, "Restored flight from " << file);
343         return true;
344     } else {
345         SG_LOG(SG_INPUT, SG_WARN, "Cannot load flight from " << file);
346         return false;
347     }
348 }
349
350
351 /**
352  * Built-in command: save flight.
353  *
354  * file (optional): the name of the file to save (relative to the
355  * current directory).  Defaults to "fgfs.sav".
356  */
357 static bool
358 do_save (const SGPropertyNode * arg)
359 {
360     string file = arg->getStringValue("file", "fgfs.sav");
361     if (file.size() < 4 || file.substr(file.size() - 4) != ".sav")
362         file += ".sav";
363
364     if (!fgValidatePath(file.c_str(), false)) {
365         SG_LOG(SG_IO, SG_ALERT, "save: writing '" << file << "' denied "
366                 "(unauthorized access)");
367         return false;
368     }
369
370     bool write_all = arg->getBoolValue("write-all", false);
371     SG_LOG(SG_INPUT, SG_INFO, "Saving flight");
372     ofstream output(file.c_str());
373     if (output.good() && fgSaveFlight(output, write_all)) {
374         output.close();
375         SG_LOG(SG_INPUT, SG_INFO, "Saved flight to " << file);
376         return true;
377     } else {
378         SG_LOG(SG_INPUT, SG_ALERT, "Cannot save flight to " << file);
379         return false;
380     }
381 }
382
383
384 /**
385  * Built-in command: (re)load the panel.
386  *
387  * path (optional): the file name to load the panel from 
388  * (relative to FG_ROOT).  Defaults to the value of /sim/panel/path,
389  * and if that's unspecified, to "Panels/Default/default.xml".
390  */
391 static bool
392 do_panel_load (const SGPropertyNode * arg)
393 {
394   string panel_path =
395     arg->getStringValue("path",
396                         fgGetString("/sim/panel/path",
397                                     "Panels/Default/default.xml"));
398   FGPanel * new_panel = fgReadPanel(panel_path);
399   if (new_panel == 0) {
400     SG_LOG(SG_INPUT, SG_ALERT,
401            "Error reading new panel from " << panel_path);
402     return false;
403   }
404   SG_LOG(SG_INPUT, SG_INFO, "Loaded new panel from " << panel_path);
405   globals->get_current_panel()->unbind();
406   delete globals->get_current_panel();
407   globals->set_current_panel( new_panel );
408   globals->get_current_panel()->bind();
409   return true;
410 }
411
412
413 /**
414  * Built-in command: pass a mouse click to the panel.
415  *
416  * button: the mouse button number, zero-based.
417  * is-down: true if the button is down, false if it is up.
418  * x-pos: the x position of the mouse click.
419  * y-pos: the y position of the mouse click.
420  */
421 static bool
422 do_panel_mouse_click (const SGPropertyNode * arg)
423 {
424   if (globals->get_current_panel() != 0)
425     return globals->get_current_panel()
426       ->doMouseAction(arg->getIntValue("button"),
427                       arg->getBoolValue("is-down") ? PU_DOWN : PU_UP,
428                       arg->getIntValue("x-pos"),
429                       arg->getIntValue("y-pos"));
430   else
431     return false;
432 }
433
434
435 /**
436  * Built-in command: (re)load preferences.
437  *
438  * path (optional): the file name to load the panel from (relative
439  * to FG_ROOT). Defaults to "preferences.xml".
440  */
441 static bool
442 do_preferences_load (const SGPropertyNode * arg)
443 {
444   try {
445     fgLoadProps(arg->getStringValue("path", "preferences.xml"),
446                 globals->get_props());
447   } catch (const sg_exception &e) {
448     guiErrorMessage("Error reading global preferences: ", e);
449     return false;
450   }
451   SG_LOG(SG_INPUT, SG_INFO, "Successfully read global preferences.");
452   return true;
453 }
454
455
456 static void
457 fix_hud_visibility()
458 {
459   if ( !strcmp(fgGetString("/sim/flight-model"), "ada") ) {
460       globals->get_props()->setBoolValue( "/sim/hud/visibility", true );
461       if ( globals->get_viewmgr()->get_current() == 1 ) {
462           globals->get_props()->setBoolValue( "/sim/hud/visibility", false );
463       }
464   }
465 }
466
467 static void
468 do_view_next( bool )
469 {
470     globals->get_current_view()->setHeadingOffset_deg(0.0);
471     globals->get_viewmgr()->next_view();
472     fix_hud_visibility();
473 }
474
475 static void
476 do_view_prev( bool )
477 {
478     globals->get_current_view()->setHeadingOffset_deg(0.0);
479     globals->get_viewmgr()->prev_view();
480     fix_hud_visibility();
481 }
482
483 /**
484  * Built-in command: cycle view.
485  */
486 static bool
487 do_view_cycle (const SGPropertyNode * arg)
488 {
489   globals->get_current_view()->setHeadingOffset_deg(0.0);
490   globals->get_viewmgr()->next_view();
491   fix_hud_visibility();
492   return true;
493 }
494
495 /**
496  * Built-in command: capture screen.
497  */
498 static bool
499 do_screen_capture (const SGPropertyNode * arg)
500 {
501   return fgDumpSnapShot();
502 }
503
504 static bool
505 do_reload_shaders (const SGPropertyNode*)
506 {
507     simgear::reload_shaders();
508     return true;
509 }
510
511 static bool
512 do_dump_scene_graph (const SGPropertyNode*)
513 {
514     fgDumpSceneGraph();
515     return true;
516 }
517
518 static bool
519 do_dump_terrain_branch (const SGPropertyNode*)
520 {
521     fgDumpTerrainBranch();
522
523     double lon_deg = fgGetDouble("/position/longitude-deg");
524     double lat_deg = fgGetDouble("/position/latitude-deg");
525     SGGeod geodPos = SGGeod::fromDegFt(lon_deg, lat_deg, 0.0);
526     SGVec3d zero = SGVec3d::fromGeod(geodPos);
527
528     SG_LOG(SG_INPUT, SG_INFO, "Model parameters:");
529     SG_LOG(SG_INPUT, SG_INFO, "Center: " << zero.x() << ", " << zero.y() << ", " << zero.z() );
530     SG_LOG(SG_INPUT, SG_INFO, "Rotation: " << lat_deg << ", " << lon_deg );
531
532     return true;
533 }
534
535 /**
536  * Built-in command: hires capture screen.
537  */
538 static bool
539 do_hires_screen_capture (const SGPropertyNode * arg)
540 {
541   fgHiResDump();
542   return true;
543 }
544
545
546 /**
547  * Reload the tile cache.
548  */
549 static bool
550 do_tile_cache_reload (const SGPropertyNode * arg)
551 {
552     static const SGPropertyNode *master_freeze
553         = fgGetNode("/sim/freeze/master");
554     bool freeze = master_freeze->getBoolValue();
555     SG_LOG(SG_INPUT, SG_INFO, "ReIniting TileCache");
556     if ( !freeze ) {
557         fgSetBool("/sim/freeze/master", true);
558     }
559
560     globals->get_subsystem("tile-manager")->reinit();
561
562     if ( !freeze ) {
563         fgSetBool("/sim/freeze/master", false);
564     }
565     return true;
566 }
567
568
569 /**
570  * Set the sea level outside air temperature and assigning that to all
571  * boundary and aloft environment layers.
572  */
573 static bool
574 do_set_sea_level_degc ( double temp_sea_level_degc)
575 {
576     SGPropertyNode *node, *child;
577
578     // boundary layers
579     node = fgGetNode( "/environment/config/boundary" );
580     if ( node != NULL ) {
581       int i = 0;
582       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
583         child->setDoubleValue( "temperature-sea-level-degc",
584                                temp_sea_level_degc );
585         ++i;
586       }
587     }
588
589     // aloft layers
590     node = fgGetNode( "/environment/config/aloft" );
591     if ( node != NULL ) {
592       int i = 0;
593       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
594         child->setDoubleValue( "temperature-sea-level-degc",
595                                temp_sea_level_degc );
596         ++i;
597       }
598     }
599
600     return true;
601 }
602
603 static bool
604 do_set_sea_level_degc (const SGPropertyNode * arg)
605 {
606     return do_set_sea_level_degc( arg->getDoubleValue("temp-degc", 15.0) );
607 }
608
609
610 /**
611  * Set the outside air temperature at the "current" altitude by first
612  * calculating the corresponding sea level temp, and assigning that to
613  * all boundary and aloft environment layers.
614  */
615 static bool
616 do_set_oat_degc (const SGPropertyNode * arg)
617 {
618     double oat_degc = arg->getDoubleValue("temp-degc", 15.0);
619     // check for an altitude specified in the arguments, otherwise use
620     // current aircraft altitude.
621     const SGPropertyNode *altitude_ft = arg->getChild("altitude-ft");
622     if ( altitude_ft == NULL ) {
623         altitude_ft = fgGetNode("/position/altitude-ft");
624     }
625
626     FGEnvironment dummy;        // instantiate a dummy so we can leech a method
627     dummy.set_elevation_ft( altitude_ft->getDoubleValue() );
628     dummy.set_temperature_degc( oat_degc );
629     return do_set_sea_level_degc( dummy.get_temperature_sea_level_degc());
630 }
631
632 /**
633  * Set the sea level outside air dewpoint and assigning that to all
634  * boundary and aloft environment layers.
635  */
636 static bool
637 do_set_dewpoint_sea_level_degc (double dewpoint_sea_level_degc)
638 {
639
640     SGPropertyNode *node, *child;
641
642     // boundary layers
643     node = fgGetNode( "/environment/config/boundary" );
644     if ( node != NULL ) {
645       int i = 0;
646       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
647         child->setDoubleValue( "dewpoint-sea-level-degc",
648                                dewpoint_sea_level_degc );
649         ++i;
650       }
651     }
652
653     // aloft layers
654     node = fgGetNode( "/environment/config/aloft" );
655     if ( node != NULL ) {
656       int i = 0;
657       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
658         child->setDoubleValue( "dewpoint-sea-level-degc",
659                                dewpoint_sea_level_degc );
660         ++i;
661       }
662     }
663
664     return true;
665 }
666
667 static bool
668 do_set_dewpoint_sea_level_degc (const SGPropertyNode * arg)
669 {
670     return do_set_dewpoint_sea_level_degc(arg->getDoubleValue("dewpoint-degc", 5.0));
671 }
672
673 /**
674  * Set the outside air dewpoint at the "current" altitude by first
675  * calculating the corresponding sea level dewpoint, and assigning
676  * that to all boundary and aloft environment layers.
677  */
678 static bool
679 do_set_dewpoint_degc (const SGPropertyNode * arg)
680 {
681     double dewpoint_degc = arg->getDoubleValue("dewpoint-degc", 5.0);
682
683     // check for an altitude specified in the arguments, otherwise use
684     // current aircraft altitude.
685     const SGPropertyNode *altitude_ft = arg->getChild("altitude-ft");
686     if ( altitude_ft == NULL ) {
687         altitude_ft = fgGetNode("/position/altitude-ft");
688     }
689
690     FGEnvironment dummy;        // instantiate a dummy so we can leech a method
691     dummy.set_elevation_ft( altitude_ft->getDoubleValue() );
692     dummy.set_dewpoint_degc( dewpoint_degc );
693     return do_set_dewpoint_sea_level_degc(dummy.get_dewpoint_sea_level_degc());
694 }
695
696 /**
697  * Update the lighting manually.
698  */
699 static bool
700 do_timeofday (const SGPropertyNode * arg)
701 {
702     const string &offset_type = arg->getStringValue("timeofday", "noon");
703
704     static const SGPropertyNode *longitude
705         = fgGetNode("/position/longitude-deg");
706     static const SGPropertyNode *latitude
707         = fgGetNode("/position/latitude-deg");
708     static const SGPropertyNode *cur_time_override
709         = fgGetNode("/sim/time/cur-time-override", true);
710
711     int orig_warp = globals->get_warp();
712     SGTime *t = globals->get_time_params();
713     time_t cur_time = t->get_cur_time();
714     // cout << "cur_time = " << cur_time << endl;
715     // cout << "orig_warp = " << orig_warp << endl;
716
717     int warp = 0;
718     if ( offset_type == "real" ) {
719         warp = -orig_warp;
720     } else if ( offset_type == "dawn" ) {
721         warp = fgTimeSecondsUntilSunAngle( cur_time,
722                                            longitude->getDoubleValue()
723                                              * SGD_DEGREES_TO_RADIANS,
724                                            latitude->getDoubleValue()
725                                              * SGD_DEGREES_TO_RADIANS,
726                                            90.0, true ); 
727     } else if ( offset_type == "morning" ) {
728         warp = fgTimeSecondsUntilSunAngle( cur_time,
729                                            longitude->getDoubleValue()
730                                              * SGD_DEGREES_TO_RADIANS,
731                                            latitude->getDoubleValue()
732                                              * SGD_DEGREES_TO_RADIANS,
733                                            75.0, true ); 
734     } else if ( offset_type == "noon" ) {
735         warp = fgTimeSecondsUntilSunAngle( cur_time,
736                                            longitude->getDoubleValue()
737                                              * SGD_DEGREES_TO_RADIANS,
738                                            latitude->getDoubleValue()
739                                              * SGD_DEGREES_TO_RADIANS,
740                                            0.0, true ); 
741     } else if ( offset_type == "afternoon" ) {
742         warp = fgTimeSecondsUntilSunAngle( cur_time,
743                                            longitude->getDoubleValue()
744                                              * SGD_DEGREES_TO_RADIANS,
745                                            latitude->getDoubleValue()
746                                              * SGD_DEGREES_TO_RADIANS,
747                                            60.0, false ); 
748      } else if ( offset_type == "dusk" ) {
749         warp = fgTimeSecondsUntilSunAngle( cur_time,
750                                            longitude->getDoubleValue()
751                                              * SGD_DEGREES_TO_RADIANS,
752                                            latitude->getDoubleValue()
753                                              * SGD_DEGREES_TO_RADIANS,
754                                            90.0, false ); 
755      } else if ( offset_type == "evening" ) {
756         warp = fgTimeSecondsUntilSunAngle( cur_time,
757                                            longitude->getDoubleValue()
758                                              * SGD_DEGREES_TO_RADIANS,
759                                            latitude->getDoubleValue()
760                                              * SGD_DEGREES_TO_RADIANS,
761                                            100.0, false ); 
762     } else if ( offset_type == "midnight" ) {
763         warp = fgTimeSecondsUntilSunAngle( cur_time,
764                                            longitude->getDoubleValue()
765                                              * SGD_DEGREES_TO_RADIANS,
766                                            latitude->getDoubleValue()
767                                              * SGD_DEGREES_TO_RADIANS,
768                                            180.0, false ); 
769     }
770     // cout << "warp = " << warp << endl;
771     globals->set_warp( orig_warp + warp );
772
773     t->update( longitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
774                latitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
775                cur_time_override->getLongValue(),
776                globals->get_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     // unbind the current fdm state so property changes
1229     // don't get lost when we subsequently delete this fdm
1230     // and create a new one.
1231     globals->get_subsystem("flight")->unbind();
1232
1233     // set position from presets
1234     fgInitPosition();
1235
1236     fgReInitSubsystems();
1237
1238 #if 0
1239     if ( ! fgGetBool("/sim/presets/onground") ) {
1240         fgSetBool( "/sim/freeze/master", true );
1241         fgSetBool( "/sim/freeze/clock", true );
1242     }
1243 #endif
1244
1245     return true;
1246 }
1247
1248 /**
1249  * Built-in command: set log level (0 ... 7)
1250  */
1251 static bool
1252 do_log_level (const SGPropertyNode * arg)
1253 {
1254    sglog().setLogLevels( SG_ALL, (sgDebugPriority)arg->getIntValue() );
1255
1256    return true;
1257 }
1258
1259 /**
1260  * Built-in command: replay the FDR buffer
1261  */
1262 static bool
1263 do_replay (const SGPropertyNode * arg)
1264 {
1265     // freeze the master fdm
1266     fgSetInt( "/sim/freeze/replay-state", 1 );
1267
1268     FGReplay *r = (FGReplay *)(globals->get_subsystem( "replay" ));
1269
1270     fgSetDouble( "/sim/replay/start-time", r->get_start_time() );
1271     fgSetDouble( "/sim/replay/end-time", r->get_end_time() );
1272     double duration = fgGetDouble( "/sim/replay/duration" );
1273     if( duration && duration < (r->get_end_time() - r->get_start_time()) ) {
1274         fgSetDouble( "/sim/replay/time", r->get_end_time() - duration );
1275     } else {
1276         fgSetDouble( "/sim/replay/time", r->get_start_time() );
1277     }
1278
1279     // cout << "start = " << r->get_start_time()
1280     //      << "  end = " << r->get_end_time() << endl;
1281
1282     return true;
1283 }
1284
1285
1286 static bool
1287 do_decrease_visibility (const SGPropertyNode * arg)
1288 {
1289     double new_value = fgGetDouble("/environment/visibility-m") * 0.9;
1290     fgSetDouble("/environment/visibility-m", new_value);
1291     fgDefaultWeatherValue("visibility-m", new_value);
1292     globals->get_subsystem("environment")->reinit();
1293
1294     return true;
1295 }
1296  
1297 static bool
1298 do_increase_visibility (const SGPropertyNode * arg)
1299 {
1300     double new_value = fgGetDouble("/environment/visibility-m") * 1.1;
1301     fgSetDouble("/environment/visibility-m", new_value);
1302     fgDefaultWeatherValue("visibility-m", new_value);
1303     globals->get_subsystem("environment")->reinit();
1304
1305     return true;
1306 }
1307
1308 static bool
1309 do_hud_init(const SGPropertyNode *)
1310 {
1311     fgHUDInit(); // minimal HUD
1312     return true;
1313 }
1314
1315 static bool
1316 do_hud_init2(const SGPropertyNode *)
1317 {
1318     fgHUDInit2();  // normal HUD
1319     return true;
1320 }
1321
1322
1323 /**
1324  * An fgcommand to allow loading of xml files via nasal,
1325  * the xml file's structure will be made available within
1326  * a property tree node defined under argument "targetnode",
1327  * or in the given argument tree under "data" otherwise.
1328  *
1329  * @param filename a string to hold the complete path & filename of an XML file
1330  * @param targetnode a string pointing to a location within the property tree
1331  * where to store the parsed XML file. If <targetnode> is undefined, then the
1332  * file contents are stored under a node <data> in the argument tree.
1333  */
1334
1335 static bool
1336 do_load_xml_to_proptree(const SGPropertyNode * arg)
1337 {
1338     SGPath file(arg->getStringValue("filename"));
1339     if (file.str().empty())
1340         return false;
1341
1342     if (file.extension() != "xml")
1343         file.concat(".xml");
1344
1345     if (file.isRelative()) {
1346       file = globals->resolve_maybe_aircraft_path(file.str());
1347     }
1348
1349     if (!fgValidatePath(file.c_str(), false)) {
1350         SG_LOG(SG_IO, SG_ALERT, "loadxml: reading '" << file.str() << "' denied "
1351                 "(unauthorized access)");
1352         return false;
1353     }
1354
1355     SGPropertyNode *targetnode;
1356     if (arg->hasValue("targetnode"))
1357         targetnode = fgGetNode(arg->getStringValue("targetnode"), true);
1358     else
1359         targetnode = const_cast<SGPropertyNode *>(arg)->getNode("data", true);
1360
1361     try {
1362         readProperties(file.c_str(), targetnode, true);
1363     } catch (const sg_exception &e) {
1364         SG_LOG(SG_IO, SG_WARN, "loadxml: " << e.getFormattedMessage());
1365         return false;
1366     }
1367
1368     return true;
1369 }
1370
1371
1372 /**
1373  * An fgcommand to allow saving of xml files via nasal,
1374  * the file's structure will be determined based on what's
1375  * encountered in the passed (source) property tree node
1376  *
1377  * @param filename a string to hold the complete path & filename of the (new)
1378  * XML file
1379  * @param sourcenode a string pointing to a location within the property tree
1380  * where to find the nodes that should be written recursively into an XML file
1381  * @param data if no sourcenode is given, then the file contents are taken from
1382  * the argument tree's "data" node.
1383  */
1384
1385 static bool
1386 do_save_xml_from_proptree(const SGPropertyNode * arg)
1387 {
1388     SGPath file(arg->getStringValue("filename"));
1389     if (file.str().empty())
1390         return false;
1391
1392     if (file.extension() != "xml")
1393         file.concat(".xml");
1394
1395     if (!fgValidatePath(file.c_str(), true)) {
1396         SG_LOG(SG_IO, SG_ALERT, "savexml: writing to '" << file.str() << "' denied "
1397                 "(unauthorized access)");
1398         return false;
1399     }
1400
1401     SGPropertyNode *sourcenode;
1402     if (arg->hasValue("sourcenode"))
1403         sourcenode = fgGetNode(arg->getStringValue("sourcenode"), true);
1404     else if (arg->getNode("data", false))
1405         sourcenode = const_cast<SGPropertyNode *>(arg)->getNode("data");
1406     else
1407         return false;
1408
1409     try {
1410         writeProperties (file.c_str(), sourcenode, true);
1411     } catch (const sg_exception &e) {
1412         SG_LOG(SG_IO, SG_WARN, "savexml: " << e.getFormattedMessage());
1413         return false;
1414     }
1415
1416     return true;
1417 }
1418
1419 static bool
1420 do_press_cockpit_button (const SGPropertyNode *arg)
1421 {
1422   const char *prefix = arg->getStringValue("prefix");
1423
1424   if (arg->getBoolValue("guarded") && fgGetDouble((string(prefix) + "-guard").c_str()) < 1)
1425     return true;
1426
1427   string prop = string(prefix) + "-button";
1428   double value;
1429
1430   if (arg->getBoolValue("latching"))
1431     value = fgGetDouble(prop.c_str()) > 0 ? 0 : 1;
1432   else
1433     value = 1;
1434
1435   fgSetDouble(prop.c_str(), value);
1436   fgSetBool(arg->getStringValue("discrete"), value > 0);
1437
1438   return true;
1439 }
1440
1441 static bool
1442 do_release_cockpit_button (const SGPropertyNode *arg)
1443 {
1444   const char *prefix = arg->getStringValue("prefix");
1445
1446   if (arg->getBoolValue("guarded")) {
1447     string prop = string(prefix) + "-guard";
1448     if (fgGetDouble(prop.c_str()) < 1) {
1449       fgSetDouble(prop.c_str(), 1);
1450       return true;
1451     }
1452   }
1453
1454   if (! arg->getBoolValue("latching")) {
1455     fgSetDouble((string(prefix) + "-button").c_str(), 0);
1456     fgSetBool(arg->getStringValue("discrete"), false);
1457   }
1458
1459   return true;
1460 }
1461
1462
1463 ////////////////////////////////////////////////////////////////////////
1464 // Command setup.
1465 ////////////////////////////////////////////////////////////////////////
1466
1467
1468 /**
1469  * Table of built-in commands.
1470  *
1471  * New commands do not have to be added here; any module in the application
1472  * can add a new command using globals->get_commands()->addCommand(...).
1473  */
1474 static struct {
1475   const char * name;
1476   SGCommandMgr::command_t command;
1477 } built_ins [] = {
1478     { "null", do_null },
1479     { "nasal", do_nasal },
1480     { "exit", do_exit },
1481     { "reset", do_reset },
1482     { "reinit", do_reinit },
1483     { "suspend", do_reinit },
1484     { "resume", do_reinit },
1485     { "load", do_load },
1486     { "save", do_save },
1487     { "panel-load", do_panel_load },
1488     { "panel-mouse-click", do_panel_mouse_click },
1489     { "preferences-load", do_preferences_load },
1490     { "view-cycle", do_view_cycle },
1491     { "screen-capture", do_screen_capture },
1492     { "hires-screen-capture", do_hires_screen_capture },
1493     { "tile-cache-reload", do_tile_cache_reload },
1494     { "set-sea-level-air-temp-degc", do_set_sea_level_degc },
1495     { "set-outside-air-temp-degc", do_set_oat_degc },
1496     { "set-dewpoint-sea-level-air-temp-degc", do_set_dewpoint_sea_level_degc },
1497     { "set-dewpoint-temp-degc", do_set_dewpoint_degc },
1498     { "timeofday", do_timeofday },
1499     { "property-toggle", do_property_toggle },
1500     { "property-assign", do_property_assign },
1501     { "property-adjust", do_property_adjust },
1502     { "property-multiply", do_property_multiply },
1503     { "property-swap", do_property_swap },
1504     { "property-scale", do_property_scale },
1505     { "property-cycle", do_property_cycle },
1506     { "property-randomize", do_property_randomize },
1507     { "data-logging-commit", do_data_logging_commit },
1508     { "dialog-new", do_dialog_new },
1509     { "dialog-show", do_dialog_show },
1510     { "dialog-close", do_dialog_close },
1511     { "dialog-update", do_dialog_update },
1512     { "dialog-apply", do_dialog_apply },
1513     { "gui-redraw", do_gui_redraw },
1514     { "add-model", do_add_model },
1515     { "set-cursor", do_set_cursor },
1516     { "play-audio-sample", do_play_audio_sample },
1517     { "presets-commit", do_presets_commit },
1518     { "log-level", do_log_level },
1519     { "replay", do_replay },
1520     { "decrease-visibility", do_decrease_visibility },
1521     { "increase-visibility", do_increase_visibility },
1522     { "hud-init", do_hud_init },
1523     { "hud-init2", do_hud_init2 },
1524     { "loadxml", do_load_xml_to_proptree},
1525     { "savexml", do_save_xml_from_proptree },
1526     { "press-cockpit-button", do_press_cockpit_button },
1527     { "release-cockpit-button", do_release_cockpit_button },
1528     { "dump-scenegraph", do_dump_scene_graph },
1529     { "dump-terrainbranch", do_dump_terrain_branch },
1530     { "reload-shaders", do_reload_shaders },
1531     { 0, 0 }                    // zero-terminated
1532 };
1533
1534
1535 /**
1536  * Initialize the default built-in commands.
1537  *
1538  * Other commands may be added by other parts of the application.
1539  */
1540 void
1541 fgInitCommands ()
1542 {
1543   SG_LOG(SG_GENERAL, SG_BULK, "Initializing basic built-in commands:");
1544   for (int i = 0; built_ins[i].name != 0; i++) {
1545     SG_LOG(SG_GENERAL, SG_BULK, "  " << built_ins[i].name);
1546     globals->get_commands()->addCommand(built_ins[i].name,
1547                                         built_ins[i].command);
1548   }
1549
1550   typedef bool (*dummy)();
1551   fgTie( "/command/view/next", dummy(0), do_view_next );
1552   fgTie( "/command/view/prev", dummy(0), do_view_prev );
1553 }
1554
1555 // end of fg_commands.cxx