Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

Airplane.cpp

Go to the documentation of this file.
00001 /*
00002  * Airplane.cpp
00003  *
00004  * Part of Fly! Legacy project
00005  *
00006  * Copyright 2003 Chris Wallace
00007  *
00008  * Fly! Legacy is free software; you can redistribute it and/or modify
00009  *   it under the terms of the GNU General Public License as published by
00010  *   the Free Software Foundation; either version 2 of the License, or
00011  *   (at your option) any later version.
00012  *
00013  * Fly! Legacy is distributed in the hope that it will be useful,
00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  *   GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  *   along with Fly! Legacy; if not, write to the Free Software
00020  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  */
00023 
00034 #include "../Include/Airplane.h"
00035 #include "../Include/Utility.h"
00036 #include "../Include/Globals.h"
00037 
00038 /*
00039  * CAirplane Implementation
00040  */
00041 
00042 CAirplane::CAirplane (const char* nfoFilename)
00043 {
00044   // Initialize data members
00045   strcpy (make, "");
00046   strcpy (iconFilename, "");
00047   classification = 0;
00048   usage = 0;
00049   strcpy (svhFilename, "");
00050   strcpy (gasFilename, "");
00051   strcpy (wngFilename, "");
00052   strcpy (ampFilename, "");
00053   strcpy (pssFilename, "");
00054   strcpy (whlFilename, "");
00055   strcpy (vldFilename, "");
00056   strcpy (pitFilename, "");
00057   strcpy (camFilename, "");
00058   strcpy (lodFilename, "");
00059   strcpy (rdoFilename, "");
00060   strcpy (eltFilename, "");
00061   strcpy (engFilename, "");
00062   strcpy (mixFilename, "");
00063   strcpy (cklFilename, "");
00064   strcpy (fcsFilename, "");
00065   strcpy (swdFilename, "");
00066   strcpy (sitFilename, "");
00067 
00068   svh = NULL;
00069   gas = NULL;
00070   wng = NULL;
00071   amp = NULL;
00072   pss = NULL;
00073   whl = NULL;
00074   vld = NULL;
00075   pit = NULL;
00076   cam = NULL;
00077   lod = NULL;
00078   rdo = NULL;
00079   elt = NULL;
00080   eng = NULL;
00081   mix = NULL;
00082   ckl = NULL;
00083   fcs = NULL;
00084   swd = NULL;
00085 
00086   // Open stream for NFO file
00087   SStream s;
00088   strcpy (s.filename, "World\\");
00089   strcat (s.filename, nfoFilename);
00090   strcpy (s.mode, "r");
00091   if (OpenStream (&s)) {
00092     ReadFrom (this, &s);
00093   } else {
00094     gtfo ("CAirplane : Could not open NFO stream %s", nfoFilename);
00095   }
00096   CloseStream (&s);
00097 }
00098 
00099 CAirplane::~CAirplane (void)
00100 {
00101   if (svh != NULL) delete svh;
00102   if (gas != NULL) delete gas;
00103   if (wng != NULL) delete wng;
00104   if (amp != NULL) delete amp;
00105   if (pss != NULL) delete pss;
00106   if (whl != NULL) delete whl;
00107   if (vld != NULL) delete vld;
00108   if (pit != NULL) delete pit;
00109   if (cam != NULL) delete cam;
00110   if (lod != NULL) delete lod;
00111   if (rdo != NULL) delete rdo;
00112   if (elt != NULL) delete elt;
00113   if (eng != NULL) delete eng;
00114   if (mix != NULL) delete mix;
00115   if (ckl != NULL) delete ckl;
00116   if (fcs != NULL) delete fcs;
00117   if (swd != NULL) delete swd;
00118 }
00119 
00120 int   CAirplane::Read (SStream *stream, Tag tag)
00121 {
00122   int rc = TAG_IGNORED;
00123   char s[256];
00124 
00125   switch (tag) {
00126   case 'sign':
00127     // Signature, must always be 'plan'
00128     ReadString (s, 256, stream);
00129     break;
00130 
00131   case 'make':
00132     // Make/model of aircraft
00133     ReadString (make, sizeof(make), stream);
00134     break;
00135 
00136   case 'icon':
00137     // Aircraft selection menu icon filename
00138     ReadString (iconFilename, sizeof(iconFilename), stream);
00139     break;
00140 
00141   case 'CLAS':
00142     // Classification
00143     ReadInt (&classification, stream);
00144     break;
00145 
00146   case 'USAG':
00147     // Usage
00148     ReadInt (&usage, stream);
00149     break;
00150 
00151   case '_SVH':
00152     // SVH - General Info filename
00153     ReadString (svhFilename, sizeof(svhFilename), stream);
00154     break;
00155 
00156   case '_GAS':
00157     // GAS - Fuel Systems filename
00158     ReadString (gasFilename, sizeof(svhFilename), stream);
00159     break;
00160 
00161   case '_WNG':
00162     // WNG - Wing aerodynamics filename
00163     ReadString (wngFilename, sizeof(wngFilename), stream);
00164     break;
00165 
00166   case '_AMP':
00167     // AMP - Electrical Subsystems filename
00168     ReadString (ampFilename, sizeof(ampFilename), stream);
00169     break;
00170 
00171   case '_PSS':
00172     // PSS - Pitot/Static filename
00173     ReadString (pssFilename, sizeof(pssFilename), stream);
00174     break;
00175 
00176   case '_WHL':
00177     // WHL - Ground Suspension filename
00178     ReadString (whlFilename, sizeof(whlFilename), stream);
00179     break;
00180 
00181   case '_VLD':
00182     // VLD - Variable Loadout filename
00183     ReadString (vldFilename, sizeof(vldFilename), stream);
00184     break;
00185 
00186   case '_PIT':
00187     // PIT - Cockpt Manager filename
00188     ReadString (pitFilename, sizeof(pitFilename), stream);
00189     break;
00190 
00191   case '_CAM':
00192     // CAM - Camera Manager filename
00193     ReadString (camFilename, sizeof(camFilename), stream);
00194     break;
00195 
00196   case '_LOD':
00197     // LOD - Level of Detail filename
00198     ReadString (lodFilename, sizeof(lodFilename), stream);
00199     break;
00200 
00201   case '_RDO':
00202     // RDO - Radio Manager filename
00203     ReadString (rdoFilename, sizeof(rdoFilename), stream);
00204     break;
00205 
00206   case '_ELT':
00207     // ELT - External Lights filename
00208     ReadString (eltFilename, sizeof(eltFilename), stream);
00209     break;
00210 
00211   case '_ENG':
00212     // ENG - Engine Manager filename
00213     ReadString (engFilename, sizeof(engFilename), stream);
00214     break;
00215 
00216   case '_MIX':
00217     // MIX - Control Mixer filename
00218     ReadString (mixFilename, sizeof(mixFilename), stream);
00219     break;
00220 
00221   case '_CKL':
00222     // CKL - Checklists filename 
00223     ReadString (cklFilename, sizeof(cklFilename), stream);
00224     break;
00225 
00226   case '_FCS':
00227     // FCS - Flight Control System filename
00228     ReadString (fcsFilename, sizeof(fcsFilename), stream);
00229     break;
00230 
00231   case '_SWD':
00232     // SWD - Slope Wind Data filename
00233     ReadString (swdFilename, sizeof(swdFilename), stream);
00234     break;
00235 
00236   case '_SIT':
00237     // SIT - Debug Situation filename
00238     ReadString (sitFilename, sizeof(sitFilename), stream);
00239     break;
00240 
00241   default:
00242     {
00243       char tagstring[8];
00244       TagToString (tagstring, tag);
00245       gtfo ("CAirplane::Read : Unknown tag %s", tagstring);
00246     }
00247   }
00248 
00249   return rc;
00250 }
00251 
00252 void  CAirplane::ReadFinished (void)
00253 {
00254   // Read Simulated Vehicle Info
00255   svh = new CSimulatedVehicle (svhFilename);
00256 
00257   // Read Fuel System
00258   gas = new CFuelSystem (gasFilename);
00259 
00260   // Read Aerodynamic Model
00261   wng = new CAerodynamicModel (wngFilename);
00262 
00263   char *mark1 = new char[32];
00264   strcpy (mark1, "amp start");
00265 
00266   // Read Electrical Subystems
00267   amp = new CElectricalSystem (ampFilename);
00268 
00269   char *mark2 = new char[32];
00270   strcpy (mark2, "amp end");
00271 
00272   // Read Pitot/Static Systems
00273   pss = new CPitotStaticSystem (pssFilename);
00274 
00275   // Read Ground Suspension
00276 //  whl = new CGroundSuspension (whlFilename);
00277 
00278   // Read Variable Loadouts
00279   vld = new CVariableLoadouts (vldFilename);
00280 
00281   // Read Camera Manager
00282   cam = new CCameraManager (camFilename);
00283 
00284   // Read Cockpit Manager
00286   char *mark3 = new char[32];
00287   strcpy (mark3, "CockpitMgr Start");
00288   pit = new CCockpitManager (pitFilename);
00289   char *mark4 = new char[32];
00290   strcpy (mark4, "CockpitMgr End");
00291 
00292   // Read Level of Detail and select first day model
00293   lod = new CLevelOfDetail (lodFilename);
00294   lod->daynight->select (1);
00295   lod->day->select (1);
00296   
00297   // Read Radio Manager
00298   rdo = new CRadioManager (rdoFilename);
00299 
00300   // Read External Lights
00301 //  elt = new CExternalLights (eltFilename);
00302 
00303   // Read Engine Manager
00304 //  eng = new CEngineManager (engFilename);
00305 
00306   // Read Control Mixer
00307 //  mix = new CControlMixer (mixFilename);
00308 
00309   // Read Checklists
00310 //  ckl = new CChecklists (cklFilename);
00311 
00312   // Read Flight Control System
00313 //  fcs = new CFlightControlSystem (fcsFilename);
00314 
00315   // Read Slope Wind Data
00316 //  swd = new CSlopeWindData (swdFilename);
00317 }
00318 
00319 void CAirplane::AileronIncr (void)
00320 {
00321   // Get pointer to control subsystem in electrical systems
00322   CBaseControl *p = amp->pAileron;
00323   if (p != NULL) {
00324     p->Incr ();
00325   }
00326 }
00327 
00328 void CAirplane::AileronDecr (void)
00329 {
00330   // Get pointer to control subsystem in electrical systems
00331   CBaseControl *p = amp->pAileron;
00332   if (p != NULL) {
00333     p->Decr ();
00334   }
00335 }
00336 
00337 void CAirplane::ElevatorIncr (void)
00338 {
00339   // Get pointer to control subsystem in electrical systems
00340   CBaseControl *p = amp->pElevator;
00341   if (p != NULL) {
00342     p->Incr ();
00343   }
00344 }
00345 
00346 void CAirplane::ElevatorDecr (void)
00347 {
00348   // Get pointer to control subsystem in electrical systems
00349   CBaseControl *p = amp->pElevator;
00350   if (p != NULL) {
00351     p->Decr ();
00352   }
00353 }
00354 
00355 void CAirplane::RudderIncr (void)
00356 {
00357   // Get pointer to control subsystem in electrical systems
00358   CBaseControl *p = amp->pRudder;
00359   if (p != NULL) {
00360     p->Incr ();
00361   }
00362 }
00363 
00364 void CAirplane::RudderDecr (void)
00365 {
00366   // Get pointer to control subsystem in electrical systems
00367   CBaseControl *p = amp->pRudder;
00368   if (p != NULL) {
00369     p->Decr ();
00370   }
00371 }
00372 
00373 void CAirplane::AileronTrimIncr (void)
00374 {
00375   // Get pointer to control subsystem in electrical systems
00376   CBaseControl *p = amp->pAileronTrim;
00377   if (p != NULL) {
00378     p->Incr ();
00379   }
00380 }
00381 
00382 void CAirplane::AileronTrimDecr (void)
00383 {
00384   // Get pointer to control subsystem in electrical systems
00385   CBaseControl *p = amp->pAileronTrim;
00386   if (p != NULL) {
00387     p->Decr ();
00388   }
00389 }
00390 
00391 void CAirplane::ElevatorTrimIncr (void)
00392 {
00393   // Get pointer to control subsystem in electrical systems
00394   CBaseControl *p = amp->pElevatorTrim;
00395   if (p != NULL) {
00396     p->Incr ();
00397   }
00398 }
00399 
00400 void CAirplane::ElevatorTrimDecr (void)
00401 {
00402   // Get pointer to control subsystem in electrical systems
00403   CBaseControl *p = amp->pElevatorTrim;
00404   if (p != NULL) {
00405     p->Decr ();
00406   }
00407 }
00408 
00409 void CAirplane::RudderTrimIncr (void)
00410 {
00411   // Get pointer to control subsystem in electrical systems
00412   CBaseControl *p = amp->pRudderTrim;
00413   if (p != NULL) {
00414     p->Incr ();
00415   }
00416 }
00417 
00418 void CAirplane::RudderTrimDecr (void)
00419 {
00420   // Get pointer to control subsystem in electrical systems
00421   CBaseControl *p = amp->pRudderTrim;
00422   if (p != NULL) {
00423     p->Decr ();
00424   }
00425 }
00426 
00427 void CAirplane::Timeslice (float dT)
00428 {
00429   // Timeslice electrical subsystems
00430   if (amp) {
00431     amp->Timeslice (dT);
00432   }
00433 }
00434 
SourceForge.net Logo Documentation generated by doxygen