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