[Gcblue-commits] gcb_wx/src/sim tcFlightOpsObject.cpp,NONE,1.1
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2004-07-13 23:28:11
|
Update of /cvsroot/gcblue/gcb_wx/src/sim In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15364/src/sim Added Files: tcFlightOpsObject.cpp Log Message: --- NEW FILE: tcFlightOpsObject.cpp --- /** ** @file tcFlightOpsObject.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 "tcFlightOpsObject.h" #include "tcAirObject.h" #include "tcAeroAirObject.h" #include "tcAirDBObject.h" #include "tcFlightportDBObject.h" /******************************************************************************/ /****************************** tcFlightOpsObject *******************************/ /******************************************************************************/ /** * 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 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; } void tcFlightOpsObject::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 tcFlightOpsObject::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 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(); 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 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. */ void tcFlightOpsObject::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 tcFlightOpsObject::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 tcFlightOpsObject::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(); } /******************************************************************************/ tcFlightOpsObject::tcFlightOpsObject() { Clear(); //SetFlightportDefaults(); mpDBObject = NULL; mnModelType = MTYPE_CARRIER; } /******************************************************************************/ /* tcFlightOpsObject::tcFlightOpsObject(tcFlightOpsObject& 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. */ 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() { } |