1
0
Fork 0

Fix problem where AI planes are placed on top of user aircraft when user either selects a specific spot or user selects parking to be an available spot.

This commit is contained in:
Dan Wickstrom 2019-04-08 23:21:51 -04:00 committed by James Turner
parent 6261b71774
commit 1948304157
4 changed files with 50 additions and 56 deletions

View file

@ -100,7 +100,31 @@ void FGATCManager::postinit()
FGAirportDynamicsRef dcs(flightgear::AirportDynamicsManager::find(airport));
if (dcs && onGround) {// && !runway.empty()) {
ParkingAssignment pk(dcs->getParkingByName(parking));
ParkingAssignment pk;
if (parking == "AVAILABLE") {
double radius = fgGetDouble("/sim/dimensions/radius-m");
if (radius > 0) {
pk = dcs->getAvailableParking(radius, string(), string(), string());
if (pk.isValid()) {
fgGetString("/sim/presets/parkpos");
fgSetString("/sim/presets/parkpos", pk.parking()->getName());
}
}
if (!pk.isValid()) {
FGParkingList pkl(dcs->getParkings(true, "gate"));
if (!pkl.empty()) {
std::sort(pkl.begin(), pkl.end(), [](const FGParkingRef& a, const FGParkingRef& b) {
return a->getRadius() > b->getRadius();
});
pk = ParkingAssignment(pkl.front(), dcs);
fgSetString("/sim/presets/parkpos", pkl.front()->getName());
}
}
} else {
pk = dcs->getParkingByName(parking);
}
if (pk.isValid()) {
dcs->setParkingAvailable(pk.parking(), false);

View file

@ -326,6 +326,17 @@ ParkingAssignment FGAirportDynamics::getParkingByName(const std::string& name) c
return ParkingAssignment();
}
FGParkingRef FGAirportDynamics::getOccupiedParkingByName(const std::string& name) const
{
auto it = std::find_if(occupiedParkings.begin(), occupiedParkings.end(),
[name](const FGParkingRef& pk) { return pk->name() == name; });
if (it != occupiedParkings.end()) {
return *it;
}
return {};
}
void FGAirportDynamics::setParkingAvailable(FGParking* park, bool available)
{
if (available) {

View file

@ -140,6 +140,8 @@ public:
*/
ParkingAssignment getParkingByName(const std::string& name) const;
FGParkingRef getOccupiedParkingByName(const std::string& name) const;
// ATC related functions.
FGStartupController *getStartupController() {
return &startupController;

View file

@ -254,62 +254,19 @@ static bool fgSetPosFromAirportIDandParkpos( const string& id, const string& par
return true;
}
ParkingAssignment pka;
double radius = fgGetDouble("/sim/dimensions/radius-m");
if ((parkpos == "AVAILABLE") && (radius > 0)) {
try {
acData = globals->get_fg_home();
acData.append("aircraft-data");
string acfile = fgGetString("/sim/aircraft") + string(".xml");
acData.append(acfile);
SGPropertyNode root;
readProperties(acData, &root);
SGPropertyNode * node = root.getNode("sim");
fltType = node->getStringValue("aircraft-class", "NONE" );
acOperator = node->getStringValue("aircraft-operator", "NONE" );
} catch (const sg_exception &) {
SG_LOG(SG_GENERAL, SG_INFO,
"Could not load aircraft aircrat type and operator information from: " << acData << ". Using defaults");
// cout << path.str() << endl;
}
if (fltType.empty() || fltType == "NONE") {
SG_LOG(SG_GENERAL, SG_INFO,
"Aircraft type information not found in: " << acData << ". Using default value");
fltType = fgGetString("/sim/aircraft-class" );
}
if (acOperator.empty() || fltType == "NONE") {
SG_LOG(SG_GENERAL, SG_INFO,
"Aircraft operator information not found in: " << acData << ". Using default value");
acOperator = fgGetString("/sim/aircraft-operator" );
}
pka = dcs->getAvailableParking(radius, fltType, acType, acOperator);
if (pka.isValid()) {
// why is the following line necessary?
fgGetString("/sim/presets/parkpos");
fgSetString("/sim/presets/parkpos", pka.parking()->getName());
} else {
SG_LOG( SG_GENERAL, SG_ALERT,
"Failed to find a suitable parking at airport " << id );
return false;
}
} else {
pka = dcs->getParkingByName(parkpos);
if (!pka.isValid()) {
SG_LOG( SG_GENERAL, SG_ALERT,
"Failed to find a parking at airport " << id << ":" << parkpos);
return false;
}
// this works because the second time we run this function, in finalizePosition,
// the ATC-manager has run its postinit which reads/sets /sim/presets/parkpos
// it will hold the parking assignment so AI acft don't occupy the same
// parking spot. We simply need to use the same parking it already found
FGParkingRef pkr = dcs->getOccupiedParkingByName(parkpos);
if (!pkr.valid()) {
SG_LOG( SG_GENERAL, SG_ALERT,
"Failed to find a parking at airport " << id << ":" << parkpos);
return false;
}
// Why is the following line necessary?
fgGetString("/sim/presets/parkpos");
fgSetString("/sim/presets/parkpos", pka.parking()->getName());
fgApplyStartOffset(pka.parking()->geod(), pka.parking()->getHeading());
fgSetString("/sim/presets/parkpos", pkr->getName());
fgApplyStartOffset(pkr->geod(), pkr->getHeading());
return true;
}