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