1 // save.cxx -- class to save and restore a flight.
3 // Written by Curtis Olson, started November 1999.
5 // Copyright (C) 1999 David Megginson - david@megginson.com
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 - use a separate options object so that we can roll back on error
27 - use proper FGFS logging
28 - add view direction, and other stuff
37 #include <simgear/constants.h>
38 #include <simgear/math/fg_types.hxx>
42 FG_USING_NAMESPACE(std);
44 #define SAVE(name, value) { output << name << ": " << value << endl; }
47 * Save the current state of the simulator to a stream.
50 fgSaveFlight (ostream &output)
52 output << "#!fgfs" << endl;
57 SAVE("flight-model", FGBFI::getFlightModel());
58 if (FGBFI::getAircraft().length() > 0)
59 SAVE("aircraft", FGBFI::getAircraft());
60 if (FGBFI::getAircraftDir().length() > 0)
61 SAVE("aircraft-dir", FGBFI::getAircraftDir());
62 SAVE("time", FGBFI::getTimeGMT());
63 SAVE("hud", FGBFI::getHUDVisible());
64 SAVE("panel", FGBFI::getPanelVisible());
69 SAVE("latitude", FGBFI::getLatitude());
70 SAVE("longitude", FGBFI::getLongitude());
72 // KLUDGE: deal with gear wierdness
73 // if (FGBFI::getAGL() < 6) {
74 // SAVE("altitude", FGBFI::getAltitude() - FGBFI::getAGL());
76 SAVE("altitude", FGBFI::getAltitude());
82 SAVE("heading", FGBFI::getHeading());
83 SAVE("pitch", FGBFI::getPitch());
84 SAVE("roll", FGBFI::getRoll());
89 SAVE("speed-north", FGBFI::getSpeedNorth());
90 SAVE("speed-east", FGBFI::getSpeedEast());
91 SAVE("speed-down", FGBFI::getSpeedDown());
96 SAVE("elevator", FGBFI::getElevator());
97 SAVE("aileron", FGBFI::getAileron());
98 SAVE("rudder", FGBFI::getRudder());
99 // FIXME: save each throttle separately
100 SAVE("throttle", FGBFI::getThrottle());
103 // Secondary controls
105 SAVE("elevator-trim", FGBFI::getElevatorTrim());
106 SAVE("flaps", FGBFI::getFlaps());
107 // FIXME: save each brake separately
108 SAVE("brake", FGBFI::getBrake());
113 SAVE("nav1-active-frequency", FGBFI::getNAV1Freq());
114 SAVE("nav1-standby-frequency", FGBFI::getNAV1AltFreq());
115 SAVE("nav1-selected-radial", FGBFI::getNAV1SelRadial());
116 SAVE("nav2-active-frequency", FGBFI::getNAV2Freq());
117 SAVE("nav2-standby-frequency", FGBFI::getNAV2AltFreq());
118 SAVE("nav2-selected-radial", FGBFI::getNAV2SelRadial());
119 SAVE("adf-active-frequency", FGBFI::getADFFreq());
120 SAVE("adf-standby-frequency", FGBFI::getADFAltFreq());
121 SAVE("adf-rotation", FGBFI::getADFRotation());
126 if (FGBFI::getTargetAirport().length() > 0)
127 SAVE("target-airport", FGBFI::getTargetAirport());
128 SAVE("autopilot-altitude-lock", FGBFI::getAPAltitudeLock());
129 SAVE("autopilot-altitude", FGBFI::getAPAltitude());
130 SAVE("autopilot-heading-lock", FGBFI::getAPHeadingLock());
131 SAVE("autopilot-heading", FGBFI::getAPHeadingMag());
132 SAVE("autopilot-gps-lock", FGBFI::getGPSLock());
133 SAVE("autopilot-gps-lat", FGBFI::getGPSTargetLatitude());
134 SAVE("autopilot-gps-lon", FGBFI::getGPSTargetLongitude());
139 SAVE("visibility", FGBFI::getVisibility());
140 SAVE("clouds", FGBFI::getClouds());
141 SAVE("clouds-asl", FGBFI::getCloudsASL());
148 * Restore the current state of the simulator from a stream.
151 fgLoadFlight (istream &input)
153 // FGInterface * f = current_aircraft.fdm_state;
158 if (!input.good() || input.eof()) {
159 cout << "Stream is no good!\n";
164 if (text != "#!fgfs") {
165 cerr << "Bad save file format!\n";
170 while (input.good() && !input.eof()) {
177 if (text == "flight-model:") {
179 cout << "flight model is " << i << endl;
180 FGBFI::setFlightModel(i);
183 else if (text == "aircraft:") {
185 cout << "aircraft is " << text << endl;
186 FGBFI::setAircraft(text);
189 else if (text == "aircraft-dir:") {
191 cout << "aircraft-dir is " << text << endl;
192 FGBFI::setAircraftDir(text);
195 else if (text == "time:") {
197 cout << "saved time is " << i << endl;
198 FGBFI::setTimeGMT(i);
201 else if (text == "hud:") {
203 cout << "hud status is " << i << endl;
204 FGBFI::setHUDVisible(i);
207 else if (text == "panel:") {
209 cout << "panel status is " << i << endl;
210 FGBFI::setPanelVisible(i);
217 else if (text == "latitude:") {
219 cout << "latitude is " << n << endl;
220 FGBFI::setLatitude(n);
223 else if (text == "longitude:") {
225 cout << "longitude is " << n << endl;
226 FGBFI::setLongitude(n);
229 else if (text == "altitude:") {
231 cout << "altitude is " << n << endl;
232 FGBFI::setAltitude(n);
239 else if (text == "heading:") {
241 cout << "heading is " << n << endl;
242 FGBFI::setHeading(n);
245 else if (text == "pitch:") {
247 cout << "pitch is " << n << endl;
251 else if (text == "roll:") {
253 cout << "roll is " << n << endl;
261 else if (text == "speed-north:") {
263 cout << "speed north is " << n << endl;
264 FGBFI::setSpeedNorth(n);
267 else if (text == "speed-east:") {
269 cout << "speed east is " << n << endl;
270 FGBFI::setSpeedEast(n);
273 else if (text == "speed-down:") {
275 cout << "speed down is " << n << endl;
276 FGBFI::setSpeedDown(n);
283 else if (text == "elevator:") {
285 cout << "elevator is " << n << endl;
286 FGBFI::setElevator(n);
289 else if (text == "aileron:") {
291 cout << "aileron is " << n << endl;
292 FGBFI::setAileron(n);
295 else if (text == "rudder:") {
297 cout << "rudder is " << n << endl;
301 // FIXME: assumes single engine
302 else if (text == "throttle:") {
304 cout << "throttle is " << n << endl;
305 FGBFI::setThrottle(n);
309 // Secondary controls
311 else if (text == "elevator-trim:") {
313 cout << "elevator trim is " << n << endl;
314 FGBFI::setElevatorTrim(n);
317 else if (text == "flaps:") {
319 cout << "flaps are " << n << endl;
323 else if (text == "brake:") {
325 cout << "brake is " << n << endl;
334 else if (text == "nav1-active-frequency:") {
336 FGBFI::setNAV1Freq(n);
339 else if (text == "nav1-standby-frequency:") {
341 FGBFI::setNAV1AltFreq(n);
344 else if (text == "nav1-selected-radial:") {
346 FGBFI::setNAV1SelRadial(n);
349 else if (text == "nav2-active-frequency:") {
351 FGBFI::setNAV2Freq(n);
354 else if (text == "nav2-standby-frequency:") {
356 FGBFI::setNAV2AltFreq(n);
359 else if (text == "nav2-selected-radial:") {
361 FGBFI::setNAV2SelRadial(n);
364 else if (text == "adf-active-frequency:") {
366 FGBFI::setADFFreq(n);
369 else if (text == "adf-standby-frequency:") {
371 FGBFI::setADFAltFreq(n);
374 else if (text == "adf-rotation:") {
376 FGBFI::setADFRotation(n);
384 else if (text == "target-airport:") {
386 cout << "target airport is " << text << endl;
387 FGBFI::setTargetAirport(text);
390 else if (text == "autopilot-altitude-lock:") {
392 cout << "autopilot altitude lock is " << i << endl;
393 FGBFI::setAPAltitudeLock(i);
396 else if (text == "autopilot-altitude:") {
398 cout << "autopilot altitude is " << n << endl;
399 FGBFI::setAPAltitude(n);
402 else if (text == "autopilot-heading-lock:") {
404 cout << "autopilot heading lock is " << i << endl;
405 FGBFI::setAPHeadingLock(i);
408 else if (text == "autopilot-heading:") {
410 cout << "autopilot heading is " << n << endl;
411 FGBFI::setAPHeadingMag(n);
414 else if (text == "autopilot-gps-lock:") {
416 cout << "autopilot GPS lock is " << i << endl;
417 FGBFI::setGPSLock(i);
420 else if (text == "autopilot-gps-lat:") {
422 cout << "GPS target latitude is " << n << endl;
423 FGBFI::setGPSTargetLatitude(n);
426 else if (text == "autopilot-gps-lon:") {
428 cout << "GPS target longitude is " << n << endl;
429 FGBFI::setGPSTargetLongitude(n);
436 else if (text == "visibility:") {
438 cout << "visibility is " << n << endl;
439 FGBFI::setVisibility(n);
442 else if (text == "clouds:") {
444 cout << "clouds is " << i << endl;
448 else if (text == "clouds-asl:") {
450 cout << "clouds-asl is " << n << endl;
451 FGBFI::setCloudsASL(n);
455 // Don't die if we don't recognize something
459 cerr << "Skipping unknown field: " << text << endl;