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