-FGTrafficRecord::FGTrafficRecord() :
- id(0), waitsForId(0),
- currentPos(0),
- leg(0),
- state(0),
- latitude(0),
- longitude(0),
- heading(0),
- speed(0),
- altitude(0),
- radius(0),
- frequencyId(0),
- allowTransmission(true) {
-}
-
-void FGTrafficRecord::setPositionAndIntentions(int pos, FGAIFlightPlan *route)
-{
-
- currentPos = pos;
- if (intentions.size()) {
- intVecIterator i = intentions.begin();
- if ((*i) != pos) {
- SG_LOG(SG_GENERAL, SG_ALERT, "Error in FGTrafficRecord::setPositionAndIntentions");
- //cerr << "Pos : " << pos << " Curr " << *(intentions.begin()) << endl;
- for (intVecIterator i = intentions.begin(); i != intentions.end() ; i++) {
- //cerr << (*i) << " ";
- }
- //cerr << endl;
- }
- intentions.erase(i);
- } else {
- //int legNr, routeNr;
- //FGAIFlightPlan::waypoint* const wpt= route->getCurrentWaypoint();
- int size = route->getNrOfWayPoints();
- //cerr << "Setting pos" << pos << " ";
- //cerr << "setting intentions ";
- for (int i = 0; i < size; i++) {
- int val = route->getRouteIndex(i);
- //cerr << val<< " ";
- if ((val) && (val != pos))
- {
- intentions.push_back(val);
- //cerr << "[set] ";
- }
- }
- //cerr << endl;
- //while (route->next(&legNr, &routeNr)) {
- //intentions.push_back(routeNr);
- //}
- //route->rewind(currentPos);
- }
- //exit(1);
-}
-
-bool FGTrafficRecord::checkPositionAndIntentions(FGTrafficRecord &other)
-{
- bool result = false;
- //cerr << "Start check 1" << endl;
- if (currentPos == other.currentPos)
- {
- //cerr << callsign << ": Check Position and intentions: we are on the same taxiway" << other.callsign << "Index = " << currentPos << endl;
- result = true;
- }
- // else if (other.intentions.size())
- // {
- // cerr << "Start check 2" << endl;
- // intVecIterator i = other.intentions.begin();
- // while (!((i == other.intentions.end()) || ((*i) == currentPos)))
- // i++;
- // if (i != other.intentions.end()) {
- // cerr << "Check Position and intentions: current matches other.intentions" << endl;
- // result = true;
- // }
- else if (intentions.size()) {
- //cerr << "Start check 3" << endl;
- intVecIterator i = intentions.begin();
- //while (!((i == intentions.end()) || ((*i) == other.currentPos)))
- while (i != intentions.end()) {
- if ((*i) == other.currentPos) {
- break;
- }
- i++;
- }
- if (i != intentions.end()) {
- //cerr << callsign << ": Check Position and intentions: .other.current matches" << other.callsign << "Index = " << (*i) << endl;
- result = true;
- }
- }
- //cerr << "Done !!" << endl;
- return result;
-}
-
-void FGTrafficRecord::setPositionAndHeading(double lat, double lon, double hdg,
- double spd, double alt)
-{
- latitude = lat;
- longitude = lon;
- heading = hdg;
- speed = spd;
- altitude = alt;
-}
-
-int FGTrafficRecord::crosses(FGGroundNetwork *net, FGTrafficRecord &other)
-{
- if (checkPositionAndIntentions(other) || (other.checkPositionAndIntentions(*this)))
- return -1;
- intVecIterator i, j;
- int currentTargetNode = 0, otherTargetNode = 0;
- if (currentPos > 0)
- currentTargetNode = net->findSegment(currentPos )->getEnd()->getIndex(); // OKAY,...
- if (other.currentPos > 0)
- otherTargetNode = net->findSegment(other.currentPos)->getEnd()->getIndex(); // OKAY,...
- if ((currentTargetNode == otherTargetNode) && currentTargetNode > 0)
- return currentTargetNode;
- if (intentions.size())
- {
- for (i = intentions.begin(); i != intentions.end(); i++)
- {
- if ((*i) > 0) {
- if ((currentTargetNode == net->findSegment(*i)->getEnd()->getIndex()))
- {
- //cerr << "Current crosses at " << currentTargetNode <<endl;
- return currentTargetNode;
- }
- }
- }
- }
- if (other.intentions.size())
- {
- for (i = other.intentions.begin(); i != other.intentions.end(); i++)
- {
- if ((*i) > 0) {
- if (otherTargetNode == net->findSegment(*i)->getEnd()->getIndex())
- {
- //cerr << "Other crosses at " << currentTargetNode <<endl;
- return otherTargetNode;
- }
- }
- }
- }
- if (intentions.size() && other.intentions.size())
- {
- for (i = intentions.begin(); i != intentions.end(); i++)
- {
- for (j = other.intentions.begin(); j != other.intentions.end(); j++)
- {
- //cerr << "finding segment " << *i << " and " << *j << endl;
- if (((*i) > 0) && ((*j) > 0)) {
- currentTargetNode = net->findSegment(*i)->getEnd()->getIndex();
- otherTargetNode = net->findSegment(*j)->getEnd()->getIndex();
- if (currentTargetNode == otherTargetNode)
- {
- //cerr << "Routes will cross at " << currentTargetNode << endl;
- return currentTargetNode;
- }
- }
- }
- }
- }
- return -1;
-}
-
-bool FGTrafficRecord::onRoute(FGGroundNetwork *net, FGTrafficRecord &other)
-{
- int node = -1, othernode = -1;
- if (currentPos >0)
- node = net->findSegment(currentPos)->getEnd()->getIndex();
- if (other.currentPos > 0)
- othernode = net->findSegment(other.currentPos)->getEnd()->getIndex();
- if ((node == othernode) && (node != -1))
- return true;
- if (other.intentions.size())
- {
- for (intVecIterator i = other.intentions.begin(); i != other.intentions.end(); i++)
- {
- if (*i > 0)
- {
- othernode = net->findSegment(*i)->getEnd()->getIndex();
- if ((node == othernode) && (node > -1))
- return true;
- }
- }
- }
- //if (other.currentPos > 0)
- // othernode = net->findSegment(other.currentPos)->getEnd()->getIndex();
- //if (intentions.size())
- // {
- // for (intVecIterator i = intentions.begin(); i != intentions.end(); i++)
- // {
- // if (*i > 0)
- // {
- // node = net->findSegment(*i)->getEnd()->getIndex();
- // if ((node == othernode) && (node > -1))
- // return true;
- // }
- // }
- // }
- return false;
-}
-
-
-bool FGTrafficRecord::isOpposing (FGGroundNetwork *net, FGTrafficRecord &other, int node)
-{
- // Check if current segment is the reverse segment for the other aircraft
- FGTaxiSegment *opp;
- //cerr << "Current segment " << currentPos << endl;
- if ((currentPos > 0) && (other.currentPos > 0))
- {
- opp = net->findSegment(currentPos)->opposite();
- if (opp) {
- if (opp->getIndex() == other.currentPos)
- return true;
- }
-
- for (intVecIterator i = intentions.begin(); i != intentions.end(); i++)
- {
- if ((opp = net->findSegment(other.currentPos)->opposite()))
- {
- if ((*i) > 0)
- if (opp->getIndex() == net->findSegment(*i)->getIndex())
- {
- if (net->findSegment(*i)->getStart()->getIndex() == node) {
- {
- //cerr << "Found the node " << node << endl;
- return true;
- }
- }
- }
- }
- if (other.intentions.size())
- {
- for (intVecIterator j = other.intentions.begin(); j != other.intentions.end(); j++)
- {
- // cerr << "Current segment 1 " << (*i) << endl;
- if ((*i) > 0) {
- if ((opp = net->findSegment(*i)->opposite()))
- {
- if (opp->getIndex() ==
- net->findSegment(*j)->getIndex())
- {
- //cerr << "Nodes " << net->findSegment(*i)->getIndex()
- // << " and " << net->findSegment(*j)->getIndex()
- // << " are opposites " << endl;
- if (net->findSegment(*i)->getStart()->getIndex() == node) {
- {
- //cerr << "Found the node " << node << endl;
- return true;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- return false;
-}
-
-void FGTrafficRecord::setSpeedAdjustment(double spd)
-{
- instruction.setChangeSpeed(true);
- instruction.setSpeed(spd);
-}
-
-void FGTrafficRecord::setHeadingAdjustment(double heading)
-{
- instruction.setChangeHeading(true);
- instruction.setHeading(heading);
-}
-
-bool FGTrafficRecord::pushBackAllowed() {
- double course, az2,dist;
- SGGeod curr(SGGeod::fromDegM(getLongitude(),
- getLatitude(),
- getAltitude()));
-
- double userLatitude = fgGetDouble("/position/latitude-deg");
- double userLongitude = fgGetDouble("/position/longitude-deg");
- SGGeod user(SGGeod::fromDeg(userLongitude,userLatitude));
- SGGeodesy::inverse(curr, user, course, az2, dist);
- //cerr << "Distance to user : " << dist << endl;
- return (dist > 250);
+FGTrafficRecord::FGTrafficRecord():
+id(0), waitsForId(0),
+currentPos(0),
+leg(0),
+frequencyId(0),
+state(0),
+allowTransmission(true),
+latitude(0), longitude(0), heading(0), speed(0), altitude(0), radius(0)
+{
+}
+
+void FGTrafficRecord::setPositionAndIntentions(int pos,
+ FGAIFlightPlan * route)
+{
+
+ currentPos = pos;
+ if (intentions.size()) {
+ intVecIterator i = intentions.begin();
+ if ((*i) != pos) {
+ SG_LOG(SG_GENERAL, SG_ALERT,
+ "Error in FGTrafficRecord::setPositionAndIntentions");
+ //cerr << "Pos : " << pos << " Curr " << *(intentions.begin()) << endl;
+ for (intVecIterator i = intentions.begin();
+ i != intentions.end(); i++) {
+ //cerr << (*i) << " ";
+ }
+ //cerr << endl;
+ }
+ intentions.erase(i);
+ } else {
+ //FGAIFlightPlan::waypoint* const wpt= route->getCurrentWaypoint();
+ int size = route->getNrOfWayPoints();
+ //cerr << "Setting pos" << pos << " ";
+ //cerr << "setting intentions ";
+ for (int i = 0; i < size; i++) {
+ int val = route->getRouteIndex(i);
+ //cerr << val<< " ";
+ if ((val) && (val != pos)) {
+ intentions.push_back(val);
+ //cerr << "[set] ";
+ }
+ }
+ //cerr << endl;
+ //while (route->next(&legNr, &routeNr)) {
+ //intentions.push_back(routeNr);
+ //}
+ //route->rewind(currentPos);
+ }
+ //exit(1);
+}
+
+bool FGTrafficRecord::checkPositionAndIntentions(FGTrafficRecord & other)
+{
+ bool result = false;
+ //cerr << "Start check 1" << endl;
+ if (currentPos == other.currentPos) {
+ //cerr << callsign << ": Check Position and intentions: we are on the same taxiway" << other.callsign << "Index = " << currentPos << endl;
+ result = true;
+ }
+ // else if (other.intentions.size())
+ // {
+ // cerr << "Start check 2" << endl;
+ // intVecIterator i = other.intentions.begin();
+ // while (!((i == other.intentions.end()) || ((*i) == currentPos)))
+ // i++;
+ // if (i != other.intentions.end()) {
+ // cerr << "Check Position and intentions: current matches other.intentions" << endl;
+ // result = true;
+ // }
+ else if (intentions.size()) {
+ //cerr << "Start check 3" << endl;
+ intVecIterator i = intentions.begin();
+ //while (!((i == intentions.end()) || ((*i) == other.currentPos)))
+ while (i != intentions.end()) {
+ if ((*i) == other.currentPos) {
+ break;
+ }
+ i++;
+ }
+ if (i != intentions.end()) {
+ //cerr << callsign << ": Check Position and intentions: .other.current matches" << other.callsign << "Index = " << (*i) << endl;
+ result = true;
+ }
+ }
+ //cerr << "Done !!" << endl;
+ return result;
+}
+
+void FGTrafficRecord::setPositionAndHeading(double lat, double lon,
+ double hdg, double spd,
+ double alt)
+{
+ latitude = lat;
+ longitude = lon;
+ heading = hdg;
+ speed = spd;
+ altitude = alt;
+}
+
+int FGTrafficRecord::crosses(FGGroundNetwork * net,
+ FGTrafficRecord & other)
+{
+ if (checkPositionAndIntentions(other)
+ || (other.checkPositionAndIntentions(*this)))
+ return -1;
+ intVecIterator i, j;
+ int currentTargetNode = 0, otherTargetNode = 0;
+ if (currentPos > 0)
+ currentTargetNode = net->findSegment(currentPos)->getEnd()->getIndex(); // OKAY,...
+ if (other.currentPos > 0)
+ otherTargetNode = net->findSegment(other.currentPos)->getEnd()->getIndex(); // OKAY,...
+ if ((currentTargetNode == otherTargetNode) && currentTargetNode > 0)
+ return currentTargetNode;
+ if (intentions.size()) {
+ for (i = intentions.begin(); i != intentions.end(); i++) {
+ if ((*i) > 0) {
+ if ((currentTargetNode ==
+ net->findSegment(*i)->getEnd()->getIndex())) {
+ //cerr << "Current crosses at " << currentTargetNode <<endl;
+ return currentTargetNode;
+ }
+ }
+ }
+ }
+ if (other.intentions.size()) {
+ for (i = other.intentions.begin(); i != other.intentions.end();
+ i++) {
+ if ((*i) > 0) {
+ if (otherTargetNode ==
+ net->findSegment(*i)->getEnd()->getIndex()) {
+ //cerr << "Other crosses at " << currentTargetNode <<endl;
+ return otherTargetNode;
+ }
+ }
+ }
+ }
+ if (intentions.size() && other.intentions.size()) {
+ for (i = intentions.begin(); i != intentions.end(); i++) {
+ for (j = other.intentions.begin(); j != other.intentions.end();
+ j++) {
+ //cerr << "finding segment " << *i << " and " << *j << endl;
+ if (((*i) > 0) && ((*j) > 0)) {
+ currentTargetNode =
+ net->findSegment(*i)->getEnd()->getIndex();
+ otherTargetNode =
+ net->findSegment(*j)->getEnd()->getIndex();
+ if (currentTargetNode == otherTargetNode) {
+ //cerr << "Routes will cross at " << currentTargetNode << endl;
+ return currentTargetNode;
+ }
+ }
+ }
+ }
+ }
+ return -1;
+}
+
+bool FGTrafficRecord::onRoute(FGGroundNetwork * net,
+ FGTrafficRecord & other)
+{
+ int node = -1, othernode = -1;
+ if (currentPos > 0)
+ node = net->findSegment(currentPos)->getEnd()->getIndex();
+ if (other.currentPos > 0)
+ othernode =
+ net->findSegment(other.currentPos)->getEnd()->getIndex();
+ if ((node == othernode) && (node != -1))
+ return true;
+ if (other.intentions.size()) {
+ for (intVecIterator i = other.intentions.begin();
+ i != other.intentions.end(); i++) {
+ if (*i > 0) {
+ othernode = net->findSegment(*i)->getEnd()->getIndex();
+ if ((node == othernode) && (node > -1))
+ return true;
+ }
+ }
+ }
+ //if (other.currentPos > 0)
+ // othernode = net->findSegment(other.currentPos)->getEnd()->getIndex();
+ //if (intentions.size())
+ // {
+ // for (intVecIterator i = intentions.begin(); i != intentions.end(); i++)
+ // {
+ // if (*i > 0)
+ // {
+ // node = net->findSegment(*i)->getEnd()->getIndex();
+ // if ((node == othernode) && (node > -1))
+ // return true;
+ // }
+ // }
+ // }
+ return false;
+}
+
+
+bool FGTrafficRecord::isOpposing(FGGroundNetwork * net,
+ FGTrafficRecord & other, int node)
+{
+ // Check if current segment is the reverse segment for the other aircraft
+ FGTaxiSegment *opp;
+ //cerr << "Current segment " << currentPos << endl;
+ if ((currentPos > 0) && (other.currentPos > 0)) {
+ opp = net->findSegment(currentPos)->opposite();
+ if (opp) {
+ if (opp->getIndex() == other.currentPos)
+ return true;
+ }
+
+ for (intVecIterator i = intentions.begin(); i != intentions.end();
+ i++) {
+ if ((opp = net->findSegment(other.currentPos)->opposite())) {
+ if ((*i) > 0)
+ if (opp->getIndex() ==
+ net->findSegment(*i)->getIndex()) {
+ if (net->findSegment(*i)->getStart()->getIndex() ==
+ node) {
+ {
+ //cerr << "Found the node " << node << endl;
+ return true;
+ }
+ }
+ }
+ }
+ if (other.intentions.size()) {
+ for (intVecIterator j = other.intentions.begin();
+ j != other.intentions.end(); j++) {
+ // cerr << "Current segment 1 " << (*i) << endl;
+ if ((*i) > 0) {
+ if ((opp = net->findSegment(*i)->opposite())) {
+ if (opp->getIndex() ==
+ net->findSegment(*j)->getIndex()) {
+ //cerr << "Nodes " << net->findSegment(*i)->getIndex()
+ // << " and " << net->findSegment(*j)->getIndex()
+ // << " are opposites " << endl;
+ if (net->findSegment(*i)->getStart()->
+ getIndex() == node) {
+ {
+ //cerr << "Found the node " << node << endl;
+ return true;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return false;
+}
+
+void FGTrafficRecord::setSpeedAdjustment(double spd)
+{
+ instruction.setChangeSpeed(true);
+ instruction.setSpeed(spd);
+}
+
+void FGTrafficRecord::setHeadingAdjustment(double heading)
+{
+ instruction.setChangeHeading(true);
+ instruction.setHeading(heading);
+}
+
+bool FGTrafficRecord::pushBackAllowed()
+{
+ double course, az2, dist;
+ SGGeod curr(SGGeod::fromDegM(getLongitude(),
+ getLatitude(), getAltitude()));
+
+ double userLatitude = fgGetDouble("/position/latitude-deg");
+ double userLongitude = fgGetDouble("/position/longitude-deg");
+ SGGeod user(SGGeod::fromDeg(userLongitude, userLatitude));
+ SGGeodesy::inverse(curr, user, course, az2, dist);
+ //cerr << "Distance to user : " << dist << endl;
+ return (dist > 250);