-Prevent crashing the sim when starting at a gate that is not connected to the ground network. For now, just silently shut down the ATC system.
This commit is contained in:
parent
b175d8f1ac
commit
1e4b17595a
3 changed files with 150 additions and 141 deletions
|
@ -1,22 +1,22 @@
|
|||
/****************************************************************************
|
||||
* AIFlightPlanCreatePushBack.cxx
|
||||
* Written by Durk Talsma, started August 1, 2007.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
**************************************************************************/
|
||||
* AIFlightPlanCreatePushBack.cxx
|
||||
* Written by Durk Talsma, started August 1, 2007.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
|
@ -38,13 +38,13 @@
|
|||
|
||||
// TODO: Use James Turner's createOnGround functions.
|
||||
bool FGAIFlightPlan::createPushBack(FGAIAircraft *ac,
|
||||
bool firstFlight, FGAirport *dep,
|
||||
double latitude,
|
||||
double longitude,
|
||||
double radius,
|
||||
const string& fltType,
|
||||
const string& aircraftType,
|
||||
const string& airline)
|
||||
bool firstFlight, FGAirport *dep,
|
||||
double latitude,
|
||||
double longitude,
|
||||
double radius,
|
||||
const string& fltType,
|
||||
const string& aircraftType,
|
||||
const string& airline)
|
||||
{
|
||||
double lat, lon, heading;
|
||||
double vTaxi = ac->getPerformance()->vTaxi();
|
||||
|
@ -57,72 +57,72 @@ bool FGAIFlightPlan::createPushBack(FGAIAircraft *ac,
|
|||
|
||||
if (!(dep->getDynamics()->getGroundNetwork()->exists())) {
|
||||
//cerr << "Push Back fallback" << endl;
|
||||
createPushBackFallBack(ac, firstFlight, dep, latitude, longitude,
|
||||
radius, fltType, aircraftType, airline);
|
||||
createPushBackFallBack(ac, firstFlight, dep, latitude, longitude,
|
||||
radius, fltType, aircraftType, airline);
|
||||
} else {
|
||||
if (firstFlight) {
|
||||
|
||||
if (!(dep->getDynamics()->getAvailableParking(&lat, &lon,
|
||||
&heading, &gateId,
|
||||
radius, fltType,
|
||||
aircraftType, airline))) {
|
||||
SG_LOG(SG_INPUT, SG_WARN, "Warning: Could not find parking for a " <<
|
||||
aircraftType <<
|
||||
" of flight type " << fltType <<
|
||||
" of airline " << airline <<
|
||||
" at airport " << dep->getId());
|
||||
return false;
|
||||
char buffer[10];
|
||||
snprintf (buffer, 10, "%d", gateId);
|
||||
SGGeod coord = coord.fromDeg(lon, lat);
|
||||
//FGTaxiNode *tn = dep->getDynamics()->getGroundNetwork()->findNode(node);
|
||||
FGAIWaypoint *wpt = createOnGround(ac, string(buffer), coord, dep->getElevation(), vTaxiBackward);
|
||||
wpt->setRouteIndex(-1);
|
||||
waypoints.push_back(wpt);
|
||||
}
|
||||
//cerr << "Success : GateId = " << gateId << endl;
|
||||
SG_LOG(SG_INPUT, SG_WARN, "Warning: Succesfully found a parking for a " <<
|
||||
aircraftType <<
|
||||
" of flight type " << fltType <<
|
||||
" of airline " << airline <<
|
||||
" at airport " << dep->getId());
|
||||
} else {
|
||||
if (firstFlight) {
|
||||
|
||||
if (!(dep->getDynamics()->getAvailableParking(&lat, &lon,
|
||||
&heading, &gateId,
|
||||
radius, fltType,
|
||||
aircraftType, airline))) {
|
||||
SG_LOG(SG_INPUT, SG_WARN, "Warning: Could not find parking for a " <<
|
||||
aircraftType <<
|
||||
" of flight type " << fltType <<
|
||||
" of airline " << airline <<
|
||||
" at airport " << dep->getId());
|
||||
return false;
|
||||
char buffer[10];
|
||||
snprintf (buffer, 10, "%d", gateId);
|
||||
SGGeod coord = coord.fromDeg(lon, lat);
|
||||
//FGTaxiNode *tn = dep->getDynamics()->getGroundNetwork()->findNode(node);
|
||||
FGAIWaypoint *wpt = createOnGround(ac, string(buffer), coord, dep->getElevation(), vTaxiBackward);
|
||||
wpt->setRouteIndex(-1);
|
||||
waypoints.push_back(wpt);
|
||||
}
|
||||
//cerr << "Success : GateId = " << gateId << endl;
|
||||
SG_LOG(SG_INPUT, SG_WARN, "Warning: Succesfully found a parking for a " <<
|
||||
aircraftType <<
|
||||
" of flight type " << fltType <<
|
||||
" of airline " << airline <<
|
||||
" at airport " << dep->getId());
|
||||
} else {
|
||||
//cerr << "Push Back follow-up Flight" << endl;
|
||||
dep->getDynamics()->getParking(gateId, &lat, &lon, &heading);
|
||||
}
|
||||
if (gateId < 0) {
|
||||
createPushBackFallBack(ac, firstFlight, dep, latitude, longitude,
|
||||
radius, fltType, aircraftType, airline);
|
||||
return true;
|
||||
dep->getDynamics()->getParking(gateId, &lat, &lon, &heading);
|
||||
}
|
||||
if (gateId < 0) {
|
||||
createPushBackFallBack(ac, firstFlight, dep, latitude, longitude,
|
||||
radius, fltType, aircraftType, airline);
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
//cerr << "getting parking " << gateId;
|
||||
//cerr << " for a " <<
|
||||
// aircraftType <<
|
||||
// " of flight type " << fltType <<
|
||||
// " of airline " << airline <<
|
||||
// " at airport " << dep->getId() << endl;
|
||||
//cerr << " for a " <<
|
||||
// aircraftType <<
|
||||
// " of flight type " << fltType <<
|
||||
// " of airline " << airline <<
|
||||
// " at airport " << dep->getId() << endl;
|
||||
FGParking *parking = dep->getDynamics()->getParking(gateId);
|
||||
int pushBackNode = parking->getPushBackPoint();
|
||||
int pushBackNode = parking->getPushBackPoint();
|
||||
|
||||
|
||||
pushBackRoute = parking->getPushBackRoute();
|
||||
if ((pushBackNode > 0) && (pushBackRoute == 0)) { // Load the already established route for this gate
|
||||
int node, rte;
|
||||
FGTaxiRoute route;
|
||||
//cerr << "Creating push-back for " << gateId << " (" << parking->getName() << ") using push-back point " << pushBackNode << endl;
|
||||
route = dep->getDynamics()->getGroundNetwork()->findShortestRoute(gateId, pushBackNode, false);
|
||||
parking->setPushBackRoute(new FGTaxiRoute(route));
|
||||
|
||||
pushBackRoute = parking->getPushBackRoute();
|
||||
if ((pushBackNode > 0) && (pushBackRoute == 0)) { // Load the already established route for this gate
|
||||
int node, rte;
|
||||
FGTaxiRoute route;
|
||||
//cerr << "Creating push-back for " << gateId << " (" << parking->getName() << ") using push-back point " << pushBackNode << endl;
|
||||
route = dep->getDynamics()->getGroundNetwork()->findShortestRoute(gateId, pushBackNode, false);
|
||||
parking->setPushBackRoute(new FGTaxiRoute(route));
|
||||
|
||||
|
||||
pushBackRoute = parking->getPushBackRoute();
|
||||
int size = pushBackRoute->size();
|
||||
if (size < 2) {
|
||||
pushBackRoute = parking->getPushBackRoute();
|
||||
int size = pushBackRoute->size();
|
||||
if (size < 2) {
|
||||
SG_LOG(SG_GENERAL, SG_WARN, "Push back route from gate " << gateId << " has only " << size << " nodes.");
|
||||
SG_LOG(SG_GENERAL, SG_WARN, "Using " << pushBackNode);
|
||||
}
|
||||
pushBackRoute->first();
|
||||
while(pushBackRoute->next(&node, &rte))
|
||||
SG_LOG(SG_GENERAL, SG_WARN, "Using " << pushBackNode);
|
||||
}
|
||||
pushBackRoute->first();
|
||||
while(pushBackRoute->next(&node, &rte))
|
||||
{
|
||||
//FGTaxiNode *tn = apt->getDynamics()->getGroundNetwork()->findSegment(node)->getEnd();
|
||||
char buffer[10];
|
||||
|
@ -130,70 +130,73 @@ bool FGAIFlightPlan::createPushBack(FGAIAircraft *ac,
|
|||
FGTaxiNode *tn = dep->getDynamics()->getGroundNetwork()->findNode(node);
|
||||
//ids.pop_back();
|
||||
//wpt = new waypoint;
|
||||
SGGeod coord = coord.fromDeg(tn->getLongitude(), tn->getLatitude());
|
||||
FGAIWaypoint *wpt = createOnGround(ac, string(buffer), coord, dep->getElevation(), vTaxiBackward);
|
||||
SGGeod coord = coord.fromDeg(tn->getLongitude(), tn->getLatitude());
|
||||
FGAIWaypoint *wpt = createOnGround(ac, string(buffer), coord, dep->getElevation(), vTaxiBackward);
|
||||
|
||||
wpt->setRouteIndex(rte);
|
||||
waypoints.push_back(wpt);
|
||||
}
|
||||
// some special considerations for the last point:
|
||||
waypoints.back()->setName(string("PushBackPoint"));
|
||||
waypoints.back()->setSpeed(vTaxi);
|
||||
ac->setTaxiClearanceRequest(true);
|
||||
} else { // In case of a push forward departure...
|
||||
ac->setTaxiClearanceRequest(false);
|
||||
double lat2 = 0.0, lon2 = 0.0, az2 = 0.0;
|
||||
// some special considerations for the last point:
|
||||
waypoints.back()->setName(string("PushBackPoint"));
|
||||
waypoints.back()->setSpeed(vTaxi);
|
||||
ac->setTaxiClearanceRequest(true);
|
||||
} else { // In case of a push forward departure...
|
||||
ac->setTaxiClearanceRequest(false);
|
||||
double lat2 = 0.0, lon2 = 0.0, az2 = 0.0;
|
||||
|
||||
//cerr << "Creating final push forward point for gate " << gateId << endl;
|
||||
FGTaxiNode *tn = dep->getDynamics()->getGroundNetwork()->findNode(gateId);
|
||||
FGTaxiSegmentVectorIterator ts = tn->getBeginRoute();
|
||||
FGTaxiSegmentVectorIterator te = tn->getEndRoute();
|
||||
if (ts == te) {
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, "Gate " << gateId << "doesn't seem to have routes associated with it.");
|
||||
//exit(1);
|
||||
}
|
||||
tn = (*ts)->getEnd();
|
||||
lastNodeVisited = tn->getIndex();
|
||||
if (tn == NULL) {
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, "No valid taxinode found");
|
||||
exit(1);
|
||||
}
|
||||
double distance = (*ts)->getLength();
|
||||
//cerr << "Length of push forward route = " << distance << " and heading is " << heading << endl;
|
||||
lat2 = tn->getLatitude();
|
||||
lon2 = tn->getLongitude();
|
||||
//cerr << "Creating final push forward point for gate " << gateId << endl;
|
||||
FGTaxiNode *tn = dep->getDynamics()->getGroundNetwork()->findNode(gateId);
|
||||
FGTaxiSegmentVectorIterator ts = tn->getBeginRoute();
|
||||
FGTaxiSegmentVectorIterator te = tn->getEndRoute();
|
||||
// if the starting node equals the ending node, then there aren't any routes for this parking.
|
||||
// in cases like these we should flag the gate as being inoperative and return false
|
||||
if (ts == te) {
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, "Gate " << gateId << "doesn't seem to have routes associated with it.");
|
||||
parking->setAvailable(false);
|
||||
return false;
|
||||
}
|
||||
tn = (*ts)->getEnd();
|
||||
lastNodeVisited = tn->getIndex();
|
||||
if (tn == NULL) {
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, "No valid taxinode found");
|
||||
exit(1);
|
||||
}
|
||||
double distance = (*ts)->getLength();
|
||||
//cerr << "Length of push forward route = " << distance << " and heading is " << heading << endl;
|
||||
lat2 = tn->getLatitude();
|
||||
lon2 = tn->getLongitude();
|
||||
|
||||
for (int i = 1; i < 10; i++) {
|
||||
geo_direct_wgs_84 ( 0, lat, lon, heading,
|
||||
((i / 10.0) * distance), &lat2, &lon2, &az2 );
|
||||
char buffer[16];
|
||||
snprintf(buffer, 16, "pushback-%02d", i);
|
||||
SGGeod coord = coord.fromDeg(lon2, lat2);
|
||||
//cerr << i << endl;
|
||||
FGAIWaypoint *wpt = createOnGround(ac, string(buffer), coord, dep->getElevation(), vTaxiReduced);
|
||||
for (int i = 1; i < 10; i++) {
|
||||
geo_direct_wgs_84 ( 0, lat, lon, heading,
|
||||
((i / 10.0) * distance), &lat2, &lon2, &az2 );
|
||||
char buffer[16];
|
||||
snprintf(buffer, 16, "pushback-%02d", i);
|
||||
SGGeod coord = coord.fromDeg(lon2, lat2);
|
||||
//cerr << i << endl;
|
||||
FGAIWaypoint *wpt = createOnGround(ac, string(buffer), coord, dep->getElevation(), vTaxiReduced);
|
||||
|
||||
wpt->setRouteIndex((*ts)->getIndex());
|
||||
waypoints.push_back(wpt);
|
||||
}
|
||||
// cerr << "Done " << endl;
|
||||
waypoints.back()->setName(string("PushBackPoint"));
|
||||
// cerr << "Done assinging new name" << endl;
|
||||
}
|
||||
wpt->setRouteIndex((*ts)->getIndex());
|
||||
waypoints.push_back(wpt);
|
||||
}
|
||||
// cerr << "Done " << endl;
|
||||
waypoints.back()->setName(string("PushBackPoint"));
|
||||
// cerr << "Done assinging new name" << endl;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/*******************************************************************
|
||||
* createPushBackFallBack
|
||||
* This is the backup function for airports that don't have a
|
||||
* network yet.
|
||||
******************************************************************/
|
||||
* createPushBackFallBack
|
||||
* This is the backup function for airports that don't have a
|
||||
* network yet.
|
||||
******************************************************************/
|
||||
void FGAIFlightPlan::createPushBackFallBack(FGAIAircraft *ac, bool firstFlight, FGAirport *dep,
|
||||
double latitude,
|
||||
double longitude,
|
||||
double radius,
|
||||
const string& fltType,
|
||||
const string& aircraftType,
|
||||
const string& airline)
|
||||
double latitude,
|
||||
double longitude,
|
||||
double radius,
|
||||
const string& fltType,
|
||||
const string& aircraftType,
|
||||
const string& airline)
|
||||
{
|
||||
double heading;
|
||||
double lat;
|
||||
|
@ -212,7 +215,7 @@ void FGAIFlightPlan::createPushBackFallBack(FGAIAircraft *ac, bool firstFlight,
|
|||
|
||||
heading += 180.0;
|
||||
if (heading > 360)
|
||||
heading -= 360;
|
||||
heading -= 360;
|
||||
|
||||
SGGeod coord = coord.fromDeg(lon, lat);
|
||||
FGAIWaypoint *wpt = createOnGround(ac, string("park"), coord, dep->getElevation(), vTaxiBackward);
|
||||
|
@ -220,16 +223,16 @@ void FGAIFlightPlan::createPushBackFallBack(FGAIAircraft *ac, bool firstFlight,
|
|||
waypoints.push_back(wpt);
|
||||
|
||||
geo_direct_wgs_84 ( 0, lat, lon, heading,
|
||||
10,
|
||||
&lat2, &lon2, &az2 );
|
||||
10,
|
||||
&lat2, &lon2, &az2 );
|
||||
coord = coord.fromDeg(lon2, lat2);
|
||||
wpt = createOnGround(ac, string("park2"), coord, dep->getElevation(), vTaxiBackward);
|
||||
|
||||
waypoints.push_back(wpt);
|
||||
|
||||
geo_direct_wgs_84 ( 0, lat, lon, heading,
|
||||
2.2*radius,
|
||||
&lat2, &lon2, &az2 );
|
||||
2.2*radius,
|
||||
&lat2, &lon2, &az2 );
|
||||
coord = coord.fromDeg(lon2, lat2);
|
||||
wpt = createOnGround(ac, string("taxiStart"), coord, dep->getElevation(), vTaxiReduced);
|
||||
waypoints.push_back(wpt);
|
||||
|
|
|
@ -37,6 +37,7 @@ FGATCManager::FGATCManager() {
|
|||
controller = 0;
|
||||
prevController = 0;
|
||||
networkVisible = false;
|
||||
initSucceeded = false;
|
||||
}
|
||||
|
||||
FGATCManager::~FGATCManager() {
|
||||
|
@ -136,7 +137,7 @@ void FGATCManager::init() {
|
|||
string aircraftType; // Unused.
|
||||
string airline; // Currently used for gate selection, but a fallback mechanism will apply when not specified.
|
||||
fp->setGate(park_index);
|
||||
fp->createPushBack(&ai_ac,
|
||||
if (!(fp->createPushBack(&ai_ac,
|
||||
false,
|
||||
apt,
|
||||
latitude,
|
||||
|
@ -144,7 +145,10 @@ void FGATCManager::init() {
|
|||
aircraftRadius,
|
||||
fltType,
|
||||
aircraftType,
|
||||
airline);
|
||||
airline))) {
|
||||
controller = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
fp->getLastWaypoint()->setName( fp->getLastWaypoint()->getName() + string("legend"));
|
||||
|
@ -170,6 +174,7 @@ void FGATCManager::init() {
|
|||
//cerr << "Adding groundnetWork to the scenegraph::init" << endl;
|
||||
//globals->get_scenery()->get_scene_graph()->addChild(node);
|
||||
}
|
||||
initSucceeded = true;
|
||||
}
|
||||
|
||||
void FGATCManager::addController(FGATCController *controller) {
|
||||
|
|
|
@ -52,6 +52,7 @@ private:
|
|||
FGATCController *controller, *prevController; // The ATC controller that is responsible for the user's aircraft.
|
||||
//FGATCDialogNew dialog; // note that this variable should really replace the ugly global "currentATCDialog();
|
||||
bool networkVisible;
|
||||
bool initSucceeded;
|
||||
|
||||
public:
|
||||
FGATCManager();
|
||||
|
|
Loading…
Reference in a new issue