[Gcblue-commits] gcb_wx/src/sim tcAirfieldObject.cpp,NONE,1.1 Game.cpp,1.86,1.87 tc3DViewer.cpp,1.31
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2004-07-18 03:18:12
|
Update of /cvsroot/gcblue/gcb_wx/src/sim In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11624/src/sim Modified Files: Game.cpp tc3DViewer.cpp tcCarrierObject.cpp tcFlightOpsObject.cpp tcFlightPort.cpp tcGameObject.cpp tcPlatformObject.cpp tcSimState.cpp Added Files: tcAirfieldObject.cpp Log Message: Index: tcSimState.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcSimState.cpp,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** tcSimState.cpp 24 May 2004 00:14:47 -0000 1.44 --- tcSimState.cpp 18 Jul 2004 03:18:01 -0000 1.45 *************** *** 35,38 **** --- 35,39 ---- #include "tcMissileObject.h" #include "tcAirObject.h" + #include "tcAirfieldObject.h" #include "tcAeroAirObject.h" #include "tcLauncher.h" *************** *** 1008,1012 **** tnPoolIndex nKey; maPlatformState.GetNextAssoc(pos,nKey,gameObj); ! if (dynamic_cast<tcCarrierObject*>(gameObj)) { flightportPlatforms.push_back(gameObj->mnID); --- 1009,1013 ---- tnPoolIndex nKey; maPlatformState.GetNextAssoc(pos,nKey,gameObj); ! if (dynamic_cast<tcFlightOpsObject*>(gameObj)) { flightportPlatforms.push_back(gameObj->mnID); *************** *** 1257,1260 **** --- 1258,1262 ---- /** + * Factory method to create new objects from a database object. * Recently reworked this so that game objects initialize themselves. */ *************** *** 1282,1285 **** --- 1284,1291 ---- return new tcCarrierObject(pGenericData); } + else if (apDBObject->mnModelType == MTYPE_AIRFIELD) + { + return new tcAirfieldObject(pGenericData); + } else { *************** *** 1512,1522 **** float range = landing_unit->mcKin.RangeToKmAlt(receiver->mcKin); bool notClimbing = landing_unit->mcKin.mfClimbAngle_rad < 0.01f; ! if ((range < 0.3f)&&(notClimbing)&&(air->readyForLanding)) { ! if (tcCarrierObject *carrier = dynamic_cast<tcCarrierObject*>(receiver)) { // save key since AddChild can be called from CheckLanding, replaces mnID tnPoolIndex key = landing_unit->mnID; ! if (carrier->CheckLanding(landing_unit)==1) // if landing is successful { // remove child model from parent to allow repositioning in scenegraph --- 1518,1529 ---- float range = landing_unit->mcKin.RangeToKmAlt(receiver->mcKin); bool notClimbing = landing_unit->mcKin.mfClimbAngle_rad < 0.01f; ! ! if ((range < 0.8f)&&(notClimbing)&&(air->readyForLanding)) { ! if (tcFlightOpsObject* flightOps = dynamic_cast<tcFlightOpsObject*>(receiver)) { // save key since AddChild can be called from CheckLanding, replaces mnID tnPoolIndex key = landing_unit->mnID; ! if (flightOps->CheckLanding(landing_unit) == 1) // if landing is successful { // remove child model from parent to allow repositioning in scenegraph Index: tcFlightOpsObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcFlightOpsObject.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** tcFlightOpsObject.cpp 13 Jul 2004 23:28:02 -0000 1.1 --- tcFlightOpsObject.cpp 18 Jul 2004 03:18:01 -0000 1.2 *************** *** 23,26 **** --- 23,27 ---- #include "tcFlightOpsObject.h" + #include "tcGameObject.h" #include "tcAirObject.h" #include "tcAeroAirObject.h" *************** *** 28,34 **** #include "tcFlightportDBObject.h" ! /******************************************************************************/ ! /****************************** tcFlightOpsObject *******************************/ ! /******************************************************************************/ /** --- 29,33 ---- #include "tcFlightportDBObject.h" ! Database::tcDatabase* tcFlightOpsObject::database = 0; /** *************** *** 42,50 **** int tcFlightOpsObject::CheckLanding(tcGameObject *obj) { ! GetRelPosOf(obj, obj->rel_pos); // set update rel_pos field of landing candidate int result = flight_deck.CheckLanding(obj); if (result == 1) { ! AddChild(obj); } return result; --- 41,49 ---- int tcFlightOpsObject::CheckLanding(tcGameObject *obj) { ! gameObj->GetRelPosOf(obj, obj->rel_pos); // set update rel_pos field of landing candidate int result = flight_deck.CheckLanding(obj); if (result == 1) { ! gameObj->AddChild(obj); } return result; *************** *** 53,61 **** void tcFlightOpsObject::Clear() { - tcSurfaceObject::Clear(); flight_deck.Clear(); } /** * Supports aero air model and air generic models. Adding other * model types will fail. --- 52,75 ---- void tcFlightOpsObject::Clear() { flight_deck.Clear(); } /** + * @return pointer to flight_deck + */ + tcFlightPort* tcFlightOpsObject::GetFlightPort() + { + return &flight_deck; + } + + /** + * @return track with landing point coord and heading with orientation + */ + tcTrack tcFlightOpsObject::GetLandingData() + { + return flight_deck.GetLandingData(gameObj); + } + + /** * Supports aero air model and air generic models. Adding other * model types will fail. *************** *** 67,85 **** tcGameObject *child = NULL; // object to add to flight_deck ! tcDatabaseObject *dbObj = database->GetObject(className); ! if (tcAirDBObject *airDBObj = dynamic_cast<tcAirDBObject*>(dbObj)) ! { ! child = new tcAeroAirObject(airDBObj); ! } ! else if (tcGenericDBObject *genericDBObj = dynamic_cast<tcGenericDBObject*>(dbObj)) ! { ! if (genericDBObj->mnModelType == MTYPE_FIXEDWING) ! { ! child = new tcAirObject(genericDBObj); } else { ! std::cerr << "Attempted to add non-air generic object type to carrier: " << className << "\n"; return false; --- 81,99 ---- tcGameObject *child = NULL; // object to add to flight_deck ! tcDatabaseObject *dbObj = database->GetObject(className); ! if (tcAirDBObject *airDBObj = dynamic_cast<tcAirDBObject*>(dbObj)) ! { ! child = new tcAeroAirObject(airDBObj); ! } ! else if (tcGenericDBObject *genericDBObj = dynamic_cast<tcGenericDBObject*>(dbObj)) ! { ! if (genericDBObj->mnModelType == MTYPE_FIXEDWING) ! { ! child = new tcAirObject(genericDBObj); } else { ! std::cerr << "Attempted to add non-air generic object type to FO obj: " << className << "\n"; return false; *************** *** 88,92 **** else { ! std::cerr << "Attempted to add non-air object type to carrier: " << className << "\n"; return false; --- 102,106 ---- else { ! std::cerr << "Attempted to add non-air object type to FO obj: " << className << "\n"; return false; *************** *** 94,122 **** child->mzUnit = unitName.c_str(); ! child->mnAlliance = mnAlliance; child->SetRelativePosition(0,0,0); child->SetRelativeOrientation(0,0,0); ! AddChild(child); // add child to carrier object flight_deck.AddObject(child, loc); // add child to flight_deck return true; } ! /******************************************************************************/ ! void tcFlightOpsObject::RandInitNear(float afLon_deg, float afLat_deg) { // tcGameObject::RandInitNear(afLon,afLat); // why can't we call base here ? virtual issue? ! if (mpDBObject == NULL) {return;} ! strcpy(mzClass.mz,mpDBObject->mzClass.mz); ! mzUnit = "CV_"; ! mzUnit.AssignRandomSuffix(); ! mnAlliance = 0; ! mfStatusTime = 0; ! mcKin.mfLon_rad = C_PIOVER180*(afLon_deg + randfc(1.1f)); ! mcKin.mfLat_rad = C_PIOVER180*(afLat_deg + randfc(1.1f)); ! mcKin.mfAlt_m = 0.0f; ! mcKin.mfHeading_rad = C_TWOPI*randf(); ! mcKin.mfSpeed_kts = mpDBObject->mfMaxSpeed_kts; ! mfDamageLevel = 0; ! mcGS.SetHeading(mcKin.mfHeading_rad); ! mcGS.SetSpeed(mcKin.mfSpeed_kts); ! mcGS.SetAltitude(mcKin.mfAlt_m); int nAircraft = flight_deck.GetHangarCapacity(); --- 108,126 ---- child->mzUnit = unitName.c_str(); ! child->mnAlliance = gameObj->mnAlliance; child->SetRelativePosition(0,0,0); child->SetRelativeOrientation(0,0,0); ! gameObj->AddChild(child); // add child to flight ops object flight_deck.AddObject(child, loc); // add child to flight_deck return true; } ! ! /** ! * Randomly initializes object ! */ ! void tcFlightOpsObject::RandInitNear(float afLon_deg, float afLat_deg) ! { // tcGameObject::RandInitNear(afLon,afLat); // why can't we call base here ? virtual issue? ! if (gameObj->mpDBObject == NULL) {return;} int nAircraft = flight_deck.GetHangarCapacity(); *************** *** 136,140 **** child->SetRelativePosition(7.5,12.0,z); child->SetRelativeOrientation(0,0,0); ! AddChild(child); flight_deck.AddObject(child, LAUNCH); } --- 140,144 ---- child->SetRelativePosition(7.5,12.0,z); child->SetRelativeOrientation(0,0,0); ! gameObj->AddChild(child); flight_deck.AddObject(child, LAUNCH); } *************** *** 143,167 **** } ! /******************************************************************************/ ! void tcFlightOpsObject::PrintToFile(tcFile& file) { ! tcSurfaceObject::PrintToFile(file); ! } ! /******************************************************************************/ ! void tcFlightOpsObject::SaveToFile(tcFile& file) { ! tcSurfaceObject::SaveToFile(file); ! } ! /******************************************************************************/ ! void tcFlightOpsObject::LoadFromFile(tcFile& file) { ! tcSurfaceObject::LoadFromFile(file); ! } ! /******************************************************************************/ ! void tcFlightOpsObject::Serialize(tcFile& file, bool mbLoad) { ! if (mbLoad) { ! LoadFromFile(file); ! } ! else { ! SaveToFile(file); ! } } /** * Set up default spots and capacities for carrier flightport. --- 147,159 ---- } ! /** ! * Print state info to text file for debug ! */ ! void tcFlightOpsObject::PrintToFile(tcFile& file) ! { ! } + + /** * Set up default spots and capacities for carrier flightport. *************** *** 170,174 **** { flight_deck.Clear(); ! flight_deck.SetParent(this); flight_deck.AddSpot(LAUNCH, -7.5, 16.0f, 18.8f, 0.03f); --- 162,166 ---- { flight_deck.Clear(); ! flight_deck.SetParent(gameObj); flight_deck.AddSpot(LAUNCH, -7.5, 16.0f, 18.8f, 0.03f); *************** *** 186,190 **** void tcFlightOpsObject::Update(double afStatusTime) { - tcSurfaceObject::Update(afStatusTime); flight_deck.Update(afStatusTime); UpdateLaunch(); --- 178,181 ---- *************** *** 200,208 **** int nLaunch = (int)flight_deck.toLaunch.size(); if (nLaunch==0) return; ! for(int n=0;n<nLaunch;n++) { tcGameObject *object_to_launch = flight_deck.toLaunch[n]; ! toLaunch.push_back(object_to_launch); ! RemoveChild(object_to_launch); } flight_deck.toLaunch.clear(); --- 191,199 ---- int nLaunch = (int)flight_deck.toLaunch.size(); if (nLaunch==0) return; ! for(int n=0; n < nLaunch; n++) { tcGameObject *object_to_launch = flight_deck.toLaunch[n]; ! gameObj->toLaunch.push_back(object_to_launch); ! gameObj->RemoveChild(object_to_launch); } flight_deck.toLaunch.clear(); *************** *** 215,221 **** //SetFlightportDefaults(); - - mpDBObject = NULL; - mnModelType = MTYPE_CARRIER; } /******************************************************************************/ --- 206,209 ---- *************** *** 233,256 **** * can hold. */ ! tcFlightOpsObject::tcFlightOpsObject(tcGenericDBObject *obj) ! : tcSurfaceObject(obj) { wxASSERT(database); ! mpDBObject = obj; ! ! tcFlightportDBObject* flightportDBObj = dynamic_cast<tcFlightportDBObject*> ! (database->GetObject(obj->flightportClass.mz)); ! wxASSERT(flightportDBObj); ! if (flightportDBObj == NULL) { ! std::cerr << "Flightport database obj not found for carrier obj: "; ! std::cerr << mzUnit.mz << "\n"; return; } ! flight_deck.InitFromDatabase(flightportDBObj); } /******************************************************************************/ ! tcFlightOpsObject::~tcFlightOpsObject() { } \ No newline at end of file --- 221,245 ---- * can hold. */ ! tcFlightOpsObject::tcFlightOpsObject(tcFlightportDBObject* dbObject, tcGameObject* gameObject) ! : gameObj(gameObject) { + wxASSERT(gameObj); + if (database == 0) + { + database = tcDatabase::Get(); + } wxASSERT(database); ! if (dbObject == NULL) { ! std::cerr << "Flightport database obj not found for flight ops obj: "; ! std::cerr << gameObj->mzUnit.mz << "\n"; return; } ! flight_deck.InitFromDatabase(dbObject); } /******************************************************************************/ ! tcFlightOpsObject::~tcFlightOpsObject() ! { } \ No newline at end of file Index: tcFlightPort.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcFlightPort.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** tcFlightPort.cpp 24 May 2004 00:14:47 -0000 1.7 --- tcFlightPort.cpp 18 Jul 2004 03:18:01 -0000 1.8 *************** *** 146,150 **** float dx = obj->rel_pos.dx - spot->x; float dy = obj->rel_pos.dy - spot->y; ! float dz = obj->rel_pos.dy - spot->z; if ((dx*dx + dz*dz <= 1600.0f)&&(dy < 25.0f)&&(dy > -25.0f)) { --- 146,150 ---- float dx = obj->rel_pos.dx - spot->x; float dy = obj->rel_pos.dy - spot->y; ! float dz = obj->rel_pos.dz - spot->z; if ((dx*dx + dz*dz <= 1600.0f)&&(dy < 25.0f)&&(dy > -25.0f)) { *************** *** 326,329 **** --- 326,367 ---- return &loc_vect->at(spot_idx); } + + /** + * This version returns info for the first runway spot only + * + * @return track with landing point coord and heading with orientation + */ + tcTrack tcFlightPort::GetLandingData(const tcGameObject* obj) + { + tcTrack data; + + int nRunways = (int)launch_spots.size(); + + if (nRunways > 0) + { + tsSpotInfo *spot = &launch_spots.at(0); + + wxASSERT(obj); + tsGeoPoint p = obj->RelPosToLatLonAlt(spot->x, spot->y, spot->z); + + data.mfLat_rad = p.mfLat_rad; + data.mfLon_rad = p.mfLon_rad; + data.mfAlt_m = p.mfAlt_m; + data.mfHeading_rad = spot->orientation + obj->mcKin.mfHeading_rad; + if (data.mfHeading_rad >= C_PI) data.mfHeading_rad -= C_TWOPI; + else if (data.mfHeading_rad < -C_PI) data.mfHeading_rad += C_TWOPI; + + data.mnID = obj->mnID; + + return data; + } + else + { + data.mnID = -1; + return data; + } + + } + //---------------------------------------------------------------------------- /** Index: Game.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/Game.cpp,v retrieving revision 1.86 retrieving revision 1.87 diff -C2 -d -r1.86 -r1.87 *** Game.cpp 24 Jun 2004 21:35:41 -0000 1.86 --- Game.cpp 18 Jul 2004 03:18:01 -0000 1.87 *************** *** 1,5 **** /** @file Game.cpp main application class ** ! ** Copyright (C) 2003 Dewitt "Cole" Colclough (de...@tw...) ** All rights reserved. ** --- 1,5 ---- /** @file Game.cpp main application class ** ! ** Copyright (C) 2003-2004 Dewitt Colclough (de...@tw...) ** All rights reserved. ** *************** *** 98,104 **** /** ! * The tcGame object constructor. ! * ! */ tcGame::tcGame(const wxPoint& pos, const wxSize& size) : wxFrame((wxFrame *)NULL, -1, "Global Conflict", pos, size, wxNO_FULL_REPAINT_ON_RESIZE), // | wxNO_FULL_REPAINT_ON_RESIZE | wxCLIP_CHILDREN --- 98,104 ---- /** ! * The tcGame object constructor. ! * ! */ tcGame::tcGame(const wxPoint& pos, const wxSize& size) : wxFrame((wxFrame *)NULL, -1, "Global Conflict", pos, size, wxNO_FULL_REPAINT_ON_RESIZE), // | wxNO_FULL_REPAINT_ON_RESIZE | wxCLIP_CHILDREN *************** *** 124,127 **** --- 124,128 ---- simState = tcSimState::Get(); + database = tcDatabase::Get(); glCanvas = new wxGLCanvas(this, -1, wxPoint(0,0), size, 0, "GLCanvas", 0, wxNullPalette); *************** *** 424,437 **** chatBox->MoveToTop(); ! mcDatabase.LoadDBCSV(); // uncomment the SaveDBCSV line to save copy of database to _out suffix, // warning, this erroneously puts a copy of air DB objects into the generic file // need to fix DB obj structure so that only leaf classes are used by game objects ! mcDatabase.SaveDBCSV("_out"); ! mcDatabase.SaveDBXml(""); ! tcGameObject::SetGameObjectDatabase(&mcDatabase); // added to allow objects to init themselves ! simState->AttachDB(&mcDatabase); simState->AttachMapData(&mcMapData); simState->AttachPythonInterface(pythonInterface); --- 425,438 ---- chatBox->MoveToTop(); ! database->LoadDBCSV(); // uncomment the SaveDBCSV line to save copy of database to _out suffix, // warning, this erroneously puts a copy of air DB objects into the generic file // need to fix DB obj structure so that only leaf classes are used by game objects ! database->SaveDBCSV("_out"); ! database->SaveDBXml(""); ! tcGameObject::SetGameObjectDatabase(database); // added to allow objects to init themselves ! simState->AttachDB(database); simState->AttachMapData(&mcMapData); simState->AttachPythonInterface(pythonInterface); *************** *** 441,445 **** pythonInterface->AttachSimState(simState); ! tcLauncherState::mpDatabase = &mcDatabase; /* ** Initialize mcMapData * **/ --- 442,446 ---- pythonInterface->AttachSimState(simState); ! tcLauncherState::mpDatabase = database; /* ** Initialize mcMapData * **/ *************** *** 2013,2018 **** if (s == "ShowFlightPanel") { ! popupControl->Track(wxPoint(mrectMap.left+20,mrectMap.top+70)); popupControl->SetMenu(MENUMODE_FLIGHTPANEL); } } --- 2014,2021 ---- if (s == "ShowFlightPanel") { ! // Freeze() to prevent flicker, not sure why this works ! popupControl->Freeze(); popupControl->SetMenu(MENUMODE_FLIGHTPANEL); + popupControl->Track(wxPoint(mrectMap.left+20,mrectMap.top+70)); } } Index: tcPlatformObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcPlatformObject.cpp,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** tcPlatformObject.cpp 4 Jun 2004 21:39:23 -0000 1.25 --- tcPlatformObject.cpp 18 Jul 2004 03:18:01 -0000 1.26 *************** *** 1,4 **** /** @file tcPlatformObject.cpp ! ** ** Copyright (C) 2003-2004 Dewitt Colclough (de...@tw...) ** All rights reserved. --- 1,5 ---- /** @file tcPlatformObject.cpp ! */ ! /* ** Copyright (C) 2003-2004 Dewitt Colclough (de...@tw...) ** All rights reserved. Index: tc3DViewer.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tc3DViewer.cpp,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** tc3DViewer.cpp 4 Jun 2004 21:39:22 -0000 1.31 --- tc3DViewer.cpp 18 Jul 2004 03:18:01 -0000 1.32 *************** *** 86,90 **** void tc3DViewer::OnChar(wxKeyEvent& event) { ! event.Skip(); } --- 86,121 ---- void tc3DViewer::OnChar(wxKeyEvent& event) { ! int nChar = event.GetKeyCode(); ! ! ! switch(nChar) ! { ! case 'l': ! if (moveWithTarget) ! { ! SetCameraMode(false, false); ! cameraLookAz = cameraAz + C_PI; ! cameraLookEl = -cameraEl; ! } ! else ! { ! SetCameraMode(true, true); ! } ! break; ! case WXK_UP: ! cameraTargetOffset._v[1] += 1.0f; ! break; ! case WXK_DOWN: ! cameraTargetOffset._v[1] -= 1.0f; ! break; ! case WXK_RIGHT: ! cameraTargetOffset._v[0] += 1.0f; ! break; ! case WXK_LEFT: ! cameraTargetOffset._v[0] -= 1.0f; ! break; ! default: ! event.Skip(); ! } } *************** *** 115,118 **** --- 146,152 ---- azStart = cameraAz; elStart = cameraEl; + + lookAzStart = cameraLookAz; + lookElStart = cameraLookEl; usePolarOffset = true; } *************** *** 139,142 **** --- 173,186 ---- if (cameraEl < -MAX_EL) {cameraEl = -MAX_EL;} else if (cameraEl > MAX_EL) {cameraEl = MAX_EL;} + + + // update mouselook scene panning + cameraLookAz = dAz + lookAzStart; + cameraLookEl = -dEl + lookElStart; + if ( cameraLookAz < 0) { cameraLookAz += C_TWOPI;} + else if ( cameraLookAz > C_TWOPI) {cameraLookAz -= C_TWOPI;} + if (cameraLookEl < -MAX_EL) {cameraLookEl = -MAX_EL;} + else if (cameraLookEl > MAX_EL) {cameraLookEl = MAX_EL;} + } } *************** *** 698,702 **** if (lookAtTarget) { ! cameraTarget = targetPosition; } else --- 742,746 ---- if (lookAtTarget) { ! cameraTarget = targetPosition + cameraTargetOffset; } else *************** *** 1034,1037 **** --- 1078,1084 ---- if (lastHook != hookID) { + SetCameraMode(true, true); + cameraTargetOffset.set(0, 0, 0); + lastHook = hookID; tcGameObject *obj = simState->GetObject(hookID); Index: tcGameObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcGameObject.cpp,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** tcGameObject.cpp 4 Jun 2004 21:39:23 -0000 1.16 --- tcGameObject.cpp 18 Jul 2004 03:18:01 -0000 1.17 *************** *** 151,154 **** --- 151,180 ---- } + tsGeoPoint tcGameObject::RelPosToLatLonAlt(const tsRelativePosition& rel_pos) const + { + return RelPosToLatLonAlt(rel_pos.dx, rel_pos.dy, rel_pos.dz); + } + + /** + * Looking forward from the object, dx is right, and dz is back + * TODO fix this system to use dx right, dy forward, dz up + */ + tsGeoPoint tcGameObject::RelPosToLatLonAlt(const float& dx, + const float& dy, const float& dz) const + { + tsGeoPoint p; + + float hdg = mcKin.mfHeading_rad; + float cos_hdg = cosf(hdg); + float sin_hdg = sinf(hdg); + + p.mfAlt_m = mcKin.mfAlt_m + dy; + p.mfLon_rad = (C_MTORAD / cosf((float)mcKin.mfLat_rad)) * + (cos_hdg * dx - sin_hdg * dz) + mcKin.mfLon_rad; + p.mfLat_rad = C_MTORAD * (-cos_hdg * dz - sin_hdg * dx) + mcKin.mfLat_rad; + + return p; + } + /** * Index: tcCarrierObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcCarrierObject.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** tcCarrierObject.cpp 13 Feb 2004 01:31:33 -0000 1.7 --- tcCarrierObject.cpp 18 Jul 2004 03:18:01 -0000 1.8 *************** *** 1,4 **** /* ! ** Copyright (C) 2003 Dewitt "Cole" Colclough (de...@tw...) ** All rights reserved. --- 1,4 ---- /* ! ** Copyright (C) 2003-2004 Dewitt Colclough (de...@tw...) ** All rights reserved. *************** *** 22,102 **** #include "tcAeroAirObject.h" #include "tcAirDBObject.h" ! #include "tcFlightportDBObject.h" - /******************************************************************************/ - /****************************** tcCarrierObject *******************************/ - /******************************************************************************/ - /** - * Determines if obj has landed on runway or crashed into flightport. - * Calls tcFlightPort method. - * If object successfully lands, it is added as a child. - * @param obj Object to attempt landing - * @return -1 if crash, 0 if not close enough for landing, 1 if landed - * @see tcFlightPort::CheckLanding - */ - int tcCarrierObject::CheckLanding(tcGameObject *obj) - { - GetRelPosOf(obj, obj->rel_pos); // set update rel_pos field of landing candidate - int result = flight_deck.CheckLanding(obj); - if (result == 1) - { - AddChild(obj); - } - return result; - } void tcCarrierObject::Clear() { tcSurfaceObject::Clear(); ! flight_deck.Clear(); } /** ! * Supports aero air model and air generic models. Adding other ! * model types will fail. ! * @return true if successful, false otherwise */ ! bool tcCarrierObject::AddChildToFlightDeck(std::string className, std::string unitName, ! teLocation loc) { - tcGameObject *child = NULL; // object to add to flight_deck - - tcDatabaseObject *dbObj = database->GetObject(className); - if (tcAirDBObject *airDBObj = dynamic_cast<tcAirDBObject*>(dbObj)) - { - - child = new tcAeroAirObject(airDBObj); - } - else if (tcGenericDBObject *genericDBObj = dynamic_cast<tcGenericDBObject*>(dbObj)) - { - if (genericDBObj->mnModelType == MTYPE_FIXEDWING) - { - child = new tcAirObject(genericDBObj); - } - else - { - std::cerr << "Attempted to add non-air generic object type to carrier: " << - className << "\n"; - return false; - } - } - else - { - std::cerr << "Attempted to add non-air object type to carrier: " << - className << "\n"; - return false; - } - - child->mzUnit = unitName.c_str(); - child->mnAlliance = mnAlliance; - child->SetRelativePosition(0,0,0); - child->SetRelativeOrientation(0,0,0); - AddChild(child); // add child to carrier object - flight_deck.AddObject(child, loc); // add child to flight_deck - return true; - } - /******************************************************************************/ - void tcCarrierObject::RandInitNear(float afLon_deg, float afLat_deg) { // tcGameObject::RandInitNear(afLon,afLat); // why can't we call base here ? virtual issue? if (mpDBObject == NULL) {return;} --- 22,40 ---- #include "tcAeroAirObject.h" #include "tcAirDBObject.h" ! #include "tcFlightOpsObject.h" void tcCarrierObject::Clear() { tcSurfaceObject::Clear(); ! tcFlightOpsObject::Clear(); } /** ! * Randomly initializes object */ ! void tcCarrierObject::RandInitNear(float afLon_deg, float afLat_deg) { // tcGameObject::RandInitNear(afLon,afLat); // why can't we call base here ? virtual issue? if (mpDBObject == NULL) {return;} *************** *** 116,218 **** mcGS.SetAltitude(mcKin.mfAlt_m); ! int nAircraft = flight_deck.GetHangarCapacity(); ! for(int i=0;i<nAircraft;i++) ! { ! // add FW air child for test ! tcDatabaseObject *dbObj = database->GetRandomOfType(MTYPE_FIXEDWINGX); ! tcAirDBObject *airDBObj = dynamic_cast<tcAirDBObject*>(dbObj); ! tcAeroAirObject *child = NULL; ! if (airDBObj) child = new tcAeroAirObject(airDBObj); ! wxASSERT(child); ! if (child != NULL) ! { ! child->mzUnit = "AIRX_"; ! child->mzUnit.AssignRandomSuffix(); ! float z = -20.0f + (float)i * 18.0f; ! child->SetRelativePosition(7.5,12.0,z); ! child->SetRelativeOrientation(0,0,0); ! AddChild(child); ! flight_deck.AddObject(child, LAUNCH); ! } ! } } /******************************************************************************/ ! void tcCarrierObject::PrintToFile(tcFile& file) { tcSurfaceObject::PrintToFile(file); } /******************************************************************************/ ! void tcCarrierObject::SaveToFile(tcFile& file) { tcSurfaceObject::SaveToFile(file); } /******************************************************************************/ ! void tcCarrierObject::LoadFromFile(tcFile& file) { tcSurfaceObject::LoadFromFile(file); } /******************************************************************************/ ! void tcCarrierObject::Serialize(tcFile& file, bool mbLoad) { ! if (mbLoad) { LoadFromFile(file); } ! else { SaveToFile(file); } } /** ! * Set up default spots and capacities for carrier flightport. */ - void tcCarrierObject::SetFlightportDefaults() - { - flight_deck.Clear(); - flight_deck.SetParent(this); - - flight_deck.AddSpot(LAUNCH, -7.5, 16.0f, 18.8f, 0.03f); - - flight_deck.AddSpot(READY, 5.0f, 16.0f, 36.25f, -0.5f); - flight_deck.AddSpot(READY, 1.25f, 16.0f, 45.0f, -0.5f); - flight_deck.AddSpot(READY, 7.5f, 16.0f, 60.0f, 0.4f); - flight_deck.AddSpot(READY, 7.5f, 16.0f, 72.5f, 0.4f); - flight_deck.AddSpot(READY, 7.5f, 16.0f, 85.0f, 0.4f); - flight_deck.AddSpot(READY, 7.5f, 16.0f, 97.5f, 0.4f); - - flight_deck.SetHangarCapacity(16); - } - /******************************************************************************/ void tcCarrierObject::Update(double afStatusTime) { tcSurfaceObject::Update(afStatusTime); ! flight_deck.Update(afStatusTime); ! UpdateLaunch(); ! } ! /******************************************************************************/ ! /* Check if flight_deck has an objects in the toLaunch vector. If so, move them ! ** to the tcGameObject::toLaunch vector and delete the matching pointer in the ! ** child list. This is a bit awkward because tcGameObject is holding an object ! ** in its child list that functionally belongs to the flight deck. ! */ ! void tcCarrierObject::UpdateLaunch() ! { ! int nLaunch = (int)flight_deck.toLaunch.size(); ! if (nLaunch==0) return; ! for(int n=0;n<nLaunch;n++) ! { ! tcGameObject *object_to_launch = flight_deck.toLaunch[n]; ! toLaunch.push_back(object_to_launch); ! RemoveChild(object_to_launch); ! } ! flight_deck.toLaunch.clear(); } ! /******************************************************************************/ tcCarrierObject::tcCarrierObject() { Clear(); - //SetFlightportDefaults(); - mpDBObject = NULL; mnModelType = MTYPE_CARRIER; } /******************************************************************************/ /* --- 54,113 ---- mcGS.SetAltitude(mcKin.mfAlt_m); ! tcFlightOpsObject::RandInitNear(afLon_deg, afLat_deg); } /******************************************************************************/ ! void tcCarrierObject::PrintToFile(tcFile& file) ! { tcSurfaceObject::PrintToFile(file); + tcFlightOpsObject::PrintToFile(file); } /******************************************************************************/ ! void tcCarrierObject::SaveToFile(tcFile& file) ! { tcSurfaceObject::SaveToFile(file); } /******************************************************************************/ ! void tcCarrierObject::LoadFromFile(tcFile& file) ! { tcSurfaceObject::LoadFromFile(file); } /******************************************************************************/ ! void tcCarrierObject::Serialize(tcFile& file, bool mbLoad) ! { ! if (mbLoad) ! { LoadFromFile(file); } ! else ! { SaveToFile(file); } } + /** ! * */ void tcCarrierObject::Update(double afStatusTime) { tcSurfaceObject::Update(afStatusTime); ! tcFlightOpsObject::Update(afStatusTime); } ! #pragma warning (disable : 4355) ! /** ! * ! */ tcCarrierObject::tcCarrierObject() + : tcFlightOpsObject(0, this) { Clear(); mpDBObject = NULL; mnModelType = MTYPE_CARRIER; } + + /******************************************************************************/ /* *************** *** 230,252 **** */ tcCarrierObject::tcCarrierObject(tcGenericDBObject *obj) ! : tcSurfaceObject(obj) { - wxASSERT(database); - mpDBObject = obj; - - tcFlightportDBObject* flightportDBObj = dynamic_cast<tcFlightportDBObject*> - (database->GetObject(obj->flightportClass.mz)); - wxASSERT(flightportDBObj); - if (flightportDBObj == NULL) - { - std::cerr << "Flightport database obj not found for carrier obj: "; - std::cerr << mzUnit.mz << "\n"; - return; - } - - flight_deck.InitFromDatabase(flightportDBObj); } ! /******************************************************************************/ ! tcCarrierObject::~tcCarrierObject() { } \ No newline at end of file --- 125,134 ---- */ tcCarrierObject::tcCarrierObject(tcGenericDBObject *obj) ! : tcSurfaceObject(obj), tcFlightOpsObject(obj->GetFlightport(), this) { mpDBObject = obj; } ! ! tcCarrierObject::~tcCarrierObject() ! { } \ No newline at end of file --- NEW FILE: tcAirfieldObject.cpp --- /* @file tcAirfieldObject.cpp */ /* ** Copyright (C) 2004 Dewitt Colclough (de...@tw...) ** All rights reserved. ** This file is part of the Global Conflict Blue (GCB) program. ** GCB is free software; you can redistribute it and/or modify ** it under the terms of version 2 of the GNU General Public License as ** published by the Free Software Foundation. ** GCB is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** You should have received a copy of the GNU General Public License ** along with GCB; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "tcAirfieldObject.h" #include "tcFlightOpsObject.h" #include "tcGenericDBObject.h" void tcAirfieldObject::Clear() { tcPlatformObject::Clear(); tcFlightOpsObject::Clear(); } /** * Randomly initializes object */ void tcAirfieldObject::RandInitNear(float afLon_deg, float afLat_deg) { if (mpDBObject == NULL) {return;} strcpy(mzClass.mz, mpDBObject->mzClass.mz); mzUnit = "AF_"; mzUnit.AssignRandomSuffix(); mnAlliance = 0; mfStatusTime = 0; mcKin.mfLon_rad = C_PIOVER180*(afLon_deg + randfc(1.1f)); mcKin.mfLat_rad = C_PIOVER180*(afLat_deg + randfc(1.1f)); mcKin.mfAlt_m = 0.0f; mcKin.mfHeading_rad = C_TWOPI*randf(); mcKin.mfSpeed_kts = 0; mfDamageLevel = 0; tcFlightOpsObject::RandInitNear(afLon_deg, afLat_deg); } /******************************************************************************/ void tcAirfieldObject::PrintToFile(tcFile& file) { tcPlatformObject::PrintToFile(file); tcFlightOpsObject::PrintToFile(file); } /******************************************************************************/ void tcAirfieldObject::SaveToFile(tcFile& file) { tcPlatformObject::SaveToFile(file); } /******************************************************************************/ void tcAirfieldObject::LoadFromFile(tcFile& file) { tcPlatformObject::LoadFromFile(file); } /******************************************************************************/ void tcAirfieldObject::Serialize(tcFile& file, bool mbLoad) { if (mbLoad) { LoadFromFile(file); } else { SaveToFile(file); } } /** * Update method calls flightops update and updates that are not * related to motion from tcPlatformObject. (tcAirfieldObject does * ot move. ) * TODO: extract sensor and launcher functionality from * tcPlatformObject and use as parent classes instead. Then any * class that needs sensors or launchers can derive from the * appropriate parent class. */ void tcAirfieldObject::Update(double afStatusTime) { const float min_update_s = 0.0f; float dt_s = (float)(afStatusTime - mfStatusTime); if (dt_s <= min_update_s) {return;} // added for pause case tcFlightOpsObject::Update(afStatusTime); UpdateEffects(); wxASSERT(mpDBObject); UpdateLauncherState(dt_s); UpdateSensors(afStatusTime); mfStatusTime = afStatusTime; } #pragma warning (disable : 4355) /** * */ tcAirfieldObject::tcAirfieldObject() : tcFlightOpsObject(0, this) { Clear(); mpDBObject = NULL; mnModelType = MTYPE_AIRFIELD; } /******************************************************************************/ /* tcAirfieldObject::tcAirfieldObject(tcAirfieldObject& o) : tcSurfaceObject(o) { } */ /** * Constructor that initializes using info from database entry. * This object will have its own database object eventually. The * DB object will have info on number and types of aircraft the carrier * can hold. */ tcAirfieldObject::tcAirfieldObject(tcGenericDBObject *obj) : tcPlatformObject(obj), tcFlightOpsObject(obj->GetFlightport(), this) { mpDBObject = obj; mcKin.mfSpeed_kts = 0; // make sure this doesn't move (shouldn't be necessary) } tcAirfieldObject::~tcAirfieldObject() { } |