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 SAVE("time", FGBFI::getTimeGMT());
59 SAVE("hud", FGBFI::getHUDVisible());
60 SAVE("panel", FGBFI::getPanelVisible());
65 SAVE("latitude", FGBFI::getLatitude());
66 SAVE("longitude", FGBFI::getLongitude());
67 SAVE("altitude", FGBFI::getAltitude());
72 SAVE("heading", FGBFI::getHeading());
73 SAVE("pitch", FGBFI::getPitch());
74 SAVE("roll", FGBFI::getRoll());
79 SAVE("speed-north", FGBFI::getSpeedNorth());
80 SAVE("speed-east", FGBFI::getSpeedEast());
81 SAVE("speed-down", FGBFI::getSpeedDown());
86 SAVE("elevator", FGBFI::getElevator());
87 SAVE("aileron", FGBFI::getAileron());
88 SAVE("rudder", FGBFI::getRudder());
89 // FIXME: save each throttle separately
90 SAVE("throttle", FGBFI::getThrottle());
95 SAVE("elevator-trim", FGBFI::getElevatorTrim());
96 SAVE("flaps", FGBFI::getFlaps());
97 // FIXME: save each brake separately
98 SAVE("brake", FGBFI::getBrake());
103 if (FGBFI::getTargetAirport().length() > 0) {
104 SAVE("target-airport", FGBFI::getTargetAirport());
106 SAVE("autopilot-altitude-lock", FGBFI::getAPAltitudeLock());
107 SAVE("autopilot-altitude", FGBFI::getAPAltitude());
108 SAVE("autopilot-heading-lock", FGBFI::getAPHeadingLock());
109 SAVE("autopilot-heading", FGBFI::getAPHeading());
110 SAVE("autopilot-gps-lock", FGBFI::getGPSLock());
111 SAVE("autopilot-gps-lat", FGBFI::getGPSTargetLatitude());
112 SAVE("autopilot-gps-lon", FGBFI::getGPSTargetLongitude());
117 SAVE("visibility", FGBFI::getVisibility());
124 * Restore the current state of the simulator from a stream.
127 fgLoadFlight (istream &input)
129 // FGInterface * f = current_aircraft.fdm_state;
134 if (!input.good() || input.eof()) {
135 cout << "Stream is no good!\n";
140 if (text != "#!fgfs") {
141 cerr << "Bad save file format!\n";
146 while (input.good() && !input.eof()) {
153 if (text == "flight-model:") {
155 cout << "flight model is " << i << endl;
156 FGBFI::setFlightModel(i);
159 else if (text == "time:") {
161 cout << "saved time is " << i << endl;
162 FGBFI::setTimeGMT(i);
165 else if (text == "hud:") {
167 cout << "hud status is " << i << endl;
168 FGBFI::setHUDVisible(i);
171 else if (text == "panel:") {
173 cout << "panel status is " << i << endl;
174 FGBFI::setPanelVisible(i);
181 else if (text == "latitude:") {
183 cout << "latitude is " << n << endl;
184 FGBFI::setLatitude(n);
187 else if (text == "longitude:") {
189 cout << "longitude is " << n << endl;
190 FGBFI::setLongitude(n);
193 else if (text == "altitude:") {
195 cout << "altitude is " << n << endl;
196 FGBFI::setAltitude(n);
203 else if (text == "heading:") {
205 cout << "heading is " << n << endl;
206 FGBFI::setHeading(n);
209 else if (text == "pitch:") {
211 cout << "pitch is " << n << endl;
215 else if (text == "roll:") {
217 cout << "roll is " << n << endl;
225 else if (text == "speed-north:") {
227 cout << "speed north is " << n << endl;
228 FGBFI::setSpeedNorth(n);
231 else if (text == "speed-east:") {
233 cout << "speed east is " << n << endl;
234 FGBFI::setSpeedEast(n);
237 else if (text == "speed-down:") {
239 cout << "speed down is " << n << endl;
240 FGBFI::setSpeedDown(n);
247 else if (text == "elevator:") {
249 cout << "elevator is " << n << endl;
250 FGBFI::setElevator(n);
253 else if (text == "aileron:") {
255 cout << "aileron is " << n << endl;
256 FGBFI::setAileron(n);
259 else if (text == "rudder:") {
261 cout << "rudder is " << n << endl;
265 // FIXME: assumes single engine
266 else if (text == "throttle:") {
268 cout << "throttle is " << n << endl;
269 FGBFI::setThrottle(n);
273 // Secondary controls
275 else if (text == "elevator-trim:") {
277 cout << "elevator trim is " << n << endl;
278 FGBFI::setElevatorTrim(n);
281 else if (text == "flaps:") {
283 cout << "flaps are " << n << endl;
287 else if (text == "brake:") {
289 cout << "brake is " << n << endl;
297 else if (text == "target-airport:") {
299 cout << "target airport is " << text << endl;
300 FGBFI::setTargetAirport(text);
303 else if (text == "autopilot-altitude-lock:") {
305 cout << "autopilot altitude lock is " << i << endl;
306 FGBFI::setAPAltitudeLock(i);
309 else if (text == "autopilot-altitude:") {
311 cout << "autopilot altitude is " << n << endl;
312 FGBFI::setAPAltitude(n);
315 else if (text == "autopilot-heading-lock:") {
317 cout << "autopilot heading lock is " << i << endl;
318 FGBFI::setAPHeadingLock(i);
321 else if (text == "autopilot-heading:") {
323 cout << "autopilot heading is " << n << endl;
324 FGBFI::setAPHeading(n);
327 else if (text == "autopilot-gps-lock:") {
329 cout << "autopilot GPS lock is " << i << endl;
330 FGBFI::setGPSLock(i);
333 else if (text == "autopilot-gps-lat:") {
335 cout << "GPS target latitude is " << n << endl;
336 FGBFI::setGPSTargetLatitude(n);
339 else if (text == "autopilot-gps-lon:") {
341 cout << "GPS target longitude is " << n << endl;
342 FGBFI::setGPSTargetLongitude(n);
349 else if (text == "visibility:") {
351 cout << "visibility is " << n << endl;
352 FGBFI::setVisibility(n);
356 // Don't die if we don't recognize something
360 cerr << "Skipping unknown field: " << text << endl;