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