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 SAVE("brake", FGBFI::getBrakes());
112 SAVE("nav1-active-frequency", FGBFI::getNAV1Freq());
113 SAVE("nav1-standby-frequency", FGBFI::getNAV1AltFreq());
114 SAVE("nav1-selected-radial", FGBFI::getNAV1SelRadial());
115 SAVE("nav2-active-frequency", FGBFI::getNAV2Freq());
116 SAVE("nav2-standby-frequency", FGBFI::getNAV2AltFreq());
117 SAVE("nav2-selected-radial", FGBFI::getNAV2SelRadial());
118 SAVE("adf-active-frequency", FGBFI::getADFFreq());
119 SAVE("adf-standby-frequency", FGBFI::getADFAltFreq());
120 SAVE("adf-rotation", FGBFI::getADFRotation());
125 if (FGBFI::getTargetAirport().length() > 0)
126 SAVE("target-airport", FGBFI::getTargetAirport());
127 SAVE("autopilot-altitude-lock", FGBFI::getAPAltitudeLock());
128 SAVE("autopilot-altitude", FGBFI::getAPAltitude());
129 SAVE("autopilot-heading-lock", FGBFI::getAPHeadingLock());
130 SAVE("autopilot-heading", FGBFI::getAPHeadingMag());
131 SAVE("autopilot-gps-lock", FGBFI::getGPSLock());
132 SAVE("autopilot-gps-lat", FGBFI::getGPSTargetLatitude());
133 SAVE("autopilot-gps-lon", FGBFI::getGPSTargetLongitude());
138 SAVE("visibility", FGBFI::getVisibility());
139 SAVE("clouds", FGBFI::getClouds());
140 SAVE("clouds-asl", FGBFI::getCloudsASL());
147 * Restore the current state of the simulator from a stream.
150 fgLoadFlight (istream &input)
152 // FGInterface * f = current_aircraft.fdm_state;
157 if (!input.good() || input.eof()) {
158 cout << "Stream is no good!\n";
163 if (text != "#!fgfs") {
164 cerr << "Bad save file format!\n";
169 while (input.good() && !input.eof()) {
176 if (text == "flight-model:") {
178 cout << "flight model is " << i << endl;
179 FGBFI::setFlightModel(i);
182 else if (text == "aircraft:") {
184 cout << "aircraft is " << text << endl;
185 FGBFI::setAircraft(text);
188 else if (text == "aircraft-dir:") {
190 cout << "aircraft-dir is " << text << endl;
191 FGBFI::setAircraftDir(text);
194 else if (text == "time:") {
196 cout << "saved time is " << i << endl;
197 FGBFI::setTimeGMT(i);
200 else if (text == "hud:") {
202 cout << "hud status is " << i << endl;
203 FGBFI::setHUDVisible(i);
206 else if (text == "panel:") {
208 cout << "panel status is " << i << endl;
209 FGBFI::setPanelVisible(i);
216 else if (text == "latitude:") {
218 cout << "latitude is " << n << endl;
219 FGBFI::setLatitude(n);
222 else if (text == "longitude:") {
224 cout << "longitude is " << n << endl;
225 FGBFI::setLongitude(n);
228 else if (text == "altitude:") {
230 cout << "altitude is " << n << endl;
231 FGBFI::setAltitude(n);
238 else if (text == "heading:") {
240 cout << "heading is " << n << endl;
241 FGBFI::setHeading(n);
244 else if (text == "pitch:") {
246 cout << "pitch is " << n << endl;
250 else if (text == "roll:") {
252 cout << "roll is " << n << endl;
260 else if (text == "speed-north:") {
262 cout << "speed north is " << n << endl;
263 FGBFI::setSpeedNorth(n);
266 else if (text == "speed-east:") {
268 cout << "speed east is " << n << endl;
269 FGBFI::setSpeedEast(n);
272 else if (text == "speed-down:") {
274 cout << "speed down is " << n << endl;
275 FGBFI::setSpeedDown(n);
282 else if (text == "elevator:") {
284 cout << "elevator is " << n << endl;
285 FGBFI::setElevator(n);
288 else if (text == "aileron:") {
290 cout << "aileron is " << n << endl;
291 FGBFI::setAileron(n);
294 else if (text == "rudder:") {
296 cout << "rudder is " << n << endl;
300 // FIXME: assumes single engine
301 else if (text == "throttle:") {
303 cout << "throttle is " << n << endl;
304 FGBFI::setThrottle(n);
308 // Secondary controls
310 else if (text == "elevator-trim:") {
312 cout << "elevator trim is " << n << endl;
313 FGBFI::setElevatorTrim(n);
316 else if (text == "flaps:") {
318 cout << "flaps are " << n << endl;
322 else if (text == "brake:") {
324 cout << "brake is " << n << endl;
333 else if (text == "nav1-active-frequency:") {
335 FGBFI::setNAV1Freq(n);
338 else if (text == "nav1-standby-frequency:") {
340 FGBFI::setNAV1AltFreq(n);
343 else if (text == "nav1-selected-radial:") {
345 FGBFI::setNAV1SelRadial(n);
348 else if (text == "nav2-active-frequency:") {
350 FGBFI::setNAV2Freq(n);
353 else if (text == "nav2-standby-frequency:") {
355 FGBFI::setNAV2AltFreq(n);
358 else if (text == "nav2-selected-radial:") {
360 FGBFI::setNAV2SelRadial(n);
363 else if (text == "adf-active-frequency:") {
365 FGBFI::setADFFreq(n);
368 else if (text == "adf-standby-frequency:") {
370 FGBFI::setADFAltFreq(n);
373 else if (text == "adf-rotation:") {
375 FGBFI::setADFRotation(n);
383 else if (text == "target-airport:") {
385 cout << "target airport is " << text << endl;
386 FGBFI::setTargetAirport(text);
389 else if (text == "autopilot-altitude-lock:") {
391 cout << "autopilot altitude lock is " << i << endl;
392 FGBFI::setAPAltitudeLock(i);
395 else if (text == "autopilot-altitude:") {
397 cout << "autopilot altitude is " << n << endl;
398 FGBFI::setAPAltitude(n);
401 else if (text == "autopilot-heading-lock:") {
403 cout << "autopilot heading lock is " << i << endl;
404 FGBFI::setAPHeadingLock(i);
407 else if (text == "autopilot-heading:") {
409 cout << "autopilot heading is " << n << endl;
410 FGBFI::setAPHeadingMag(n);
413 else if (text == "autopilot-gps-lock:") {
415 cout << "autopilot GPS lock is " << i << endl;
416 FGBFI::setGPSLock(i);
419 else if (text == "autopilot-gps-lat:") {
421 cout << "GPS target latitude is " << n << endl;
422 FGBFI::setGPSTargetLatitude(n);
425 else if (text == "autopilot-gps-lon:") {
427 cout << "GPS target longitude is " << n << endl;
428 FGBFI::setGPSTargetLongitude(n);
435 else if (text == "visibility:") {
437 cout << "visibility is " << n << endl;
438 FGBFI::setVisibility(n);
441 else if (text == "clouds:") {
443 cout << "clouds is " << i << endl;
447 else if (text == "clouds-asl:") {
449 cout << "clouds-asl is " << n << endl;
450 FGBFI::setCloudsASL(n);
454 // Don't die if we don't recognize something
458 cerr << "Skipping unknown field: " << text << endl;