#include <simgear/scene/material/EffectGeode.hxx>
#include <simgear/scene/material/matlib.hxx>
#include <simgear/scene/material/mat.hxx>
+#include <simgear/scene/util/OsgMath.hxx>
#include <Scenery/scenery.hxx>
#include "trafficcontrol.hxx"
#include <Airports/groundnetwork.hxx>
#include <Airports/dynamics.hxx>
#include <Airports/simple.hxx>
+#include <Radio/radio.hxx>
+#include <signal.h>
using std::sort;
+using std::string;
/***************************************************************************
* ActiveRunway
if (intentions.size()) {
intVecIterator i = intentions.begin();
if ((*i) != pos) {
- SG_LOG(SG_GENERAL, SG_ALERT,
+ SG_LOG(SG_ATC, SG_ALERT,
"Error in FGTrafficRecord::setPositionAndIntentions at " << SG_ORIGIN);
- //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 size = route->getNrOfWayPoints();
//cerr << "Setting pos" << pos << " ";
//cerr << "setting intentions ";
- for (int i = 0; i < size; i++) {
+ for (int i = 2; i < size; i++) {
int val = route->getRouteIndex(i);
- //cerr << val<< " ";
- if ((val) && (val != pos)) {
- intentions.push_back(val);
- //cerr << "[set] ";
- }
+ intentions.push_back(val);
}
- //cerr << endl;
- //while (route->next(&legNr, &routeNr)) {
- //intentions.push_back(routeNr);
- //}
- //route->rewind(currentPos);
}
- //exit(1);
}
/**
* Check if another aircraft is ahead of the current one, and on the same
if (intentions.size()) {
for (i = intentions.begin(); i != intentions.end(); i++) {
if ((*i) > 0) {
- if ((currentTargetNode ==
- net->findSegment(*i)->getEnd()->getIndex())) {
+ if (currentTargetNode ==
+ net->findSegment(*i)->getEnd()->getIndex()) {
//cerr << "Current crosses at " << currentTargetNode <<endl;
return currentTargetNode;
}
return (ac->getCallSign() == fgGetString("/sim/multiplay/callsign")) ? true : false;
};
-void FGATCController::transmit(FGTrafficRecord * rec, AtcMsgId msgId,
+void FGATCController::transmit(FGTrafficRecord * rec, FGAirportDynamics *parent, AtcMsgId msgId,
AtcMsgDir msgDir, bool audible)
{
string sender, receiver;
FGAIFlightPlan *fp;
string fltRules;
string instructionText;
+ int ground_to_air=0;
//double commFreqD;
sender = rec->getAircraft()->getTrafficRef()->getCallSign();
string tmp = sender;
sender = receiver;
receiver = tmp;
+ ground_to_air=1;
}
switch (msgId) {
case MSG_ANNOUNCE_ENGINE_START:
getDynamics()->getActiveRunway(rwyClass, 1, activeRunway,
heading);
rec->getAircraft()->GetFlightPlan()->setRunway(activeRunway);
- fp = rec->getAircraft()->getTrafficRef()->getDepartureAirport()->
- getDynamics()->getSID(activeRunway, heading);
+ fp = NULL;
rec->getAircraft()->GetFlightPlan()->setSID(fp);
if (fp) {
SID = fp->getName() + " departure";
// Display ATC message only when one of the radios is tuned
// the relevant frequency.
// Note that distance attenuation is currently not yet implemented
- if ((onBoardRadioFreqI0 == stationFreq)
- || (onBoardRadioFreqI1 == stationFreq)) {
+
+ if ((stationFreq > 0)&&
+ ((onBoardRadioFreqI0 == stationFreq)||
+ (onBoardRadioFreqI1 == stationFreq))) {
if (rec->allowTransmissions()) {
- fgSetString("/sim/messages/atc", text.c_str());
+
+ if( fgGetBool( "/sim/radio/use-itm-attenuation", false ) ) {
+ //cerr << "Using ITM radio propagation" << endl;
+ FGRadioTransmission* radio = new FGRadioTransmission();
+ SGGeod sender_pos;
+ double sender_alt_ft, sender_alt;
+ if(ground_to_air) {
+ sender_pos = parent->parent()->geod();
+ }
+ else {
+ sender_alt_ft = rec->getAltitude();
+ sender_alt = sender_alt_ft * SG_FEET_TO_METER;
+ sender_pos= SGGeod::fromDegM( rec->getLongitude(),
+ rec->getLatitude(), sender_alt );
+ }
+ double frequency = ((double)stationFreq) / 100;
+ radio->receiveATC(sender_pos, frequency, text, ground_to_air);
+ delete radio;
+ }
+ else {
+ fgSetString("/sim/messages/atc", text.c_str());
+ }
}
}
} else {
}
}
+
string FGATCController::formatATCFrequency3_2(int freq)
{
char buffer[7];
// TODO: Set transponder codes according to real-world routes.
// The current version just returns a random string of four octal numbers.
-string FGATCController::genTransponderCode(string fltRules)
+string FGATCController::genTransponderCode(const string& fltRules)
{
if (fltRules == "VFR") {
return string("1200");
}
// // update position of the current aircraft
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
- SG_LOG(SG_GENERAL, SG_ALERT,
+ SG_LOG(SG_ATC, SG_ALERT,
"AI error: updating aircraft without traffic record at " << SG_ORIGIN);
} else {
i->setPositionAndHeading(lat, lon, heading, speed, alt);
// already exists here. So, we can simplify the current code.
ActiveRunwayVecIterator rwy = activeRunways.begin();
- if (parent->getId() == fgGetString("/sim/presets/airport-id")) {
- //for (rwy = activeRunways.begin(); rwy != activeRunways.end(); rwy++) {
- // rwy->printDepartureCue();
- //}
- }
+ //if (parent->getId() == fgGetString("/sim/presets/airport-id")) {
+ // for (rwy = activeRunways.begin(); rwy != activeRunways.end(); rwy++) {
+ // rwy->printDepartureCue();
+ // }
+ //}
rwy = activeRunways.begin();
while (rwy != activeRunways.end()) {
rwy->setCleared(0);
rwy->updateDepartureCue();
} else {
- SG_LOG(SG_GENERAL, SG_ALERT,
+ SG_LOG(SG_ATC, SG_ALERT,
"AI error: Attempting to erase non-existing runway clearance record in FGTowerController::signoff at " << SG_ORIGIN);
}
}
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
- SG_LOG(SG_GENERAL, SG_ALERT,
+ SG_LOG(SG_ATC, SG_ALERT,
"AI error: Aircraft without traffic record is signing off from tower at " << SG_ORIGIN);
} else {
i->getAircraft()->resetTakeOffStatus();
}
}
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
- SG_LOG(SG_GENERAL, SG_ALERT,
+ SG_LOG(SG_ATC, SG_ALERT,
"AI error: checking ATC instruction for aircraft without traffic record at " << SG_ORIGIN);
} else {
return i->hasInstruction();
}
}
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
- SG_LOG(SG_GENERAL, SG_ALERT,
+ SG_LOG(SG_ATC, SG_ALERT,
"AI error: requesting ATC instruction for aircraft without traffic record at " << SG_ORIGIN);
} else {
return i->getInstruction();
}
}
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
- SG_LOG(SG_GENERAL, SG_ALERT,
+ SG_LOG(SG_ATC, SG_ALERT,
"AI error: checking ATC instruction for aircraft without traffic record at " << SG_ORIGIN);
} else {
return i->hasInstruction();
}
}
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
- SG_LOG(SG_GENERAL, SG_ALERT,
+ SG_LOG(SG_ATC, SG_ALERT,
"AI error: requesting ATC instruction for aircraft without traffic record at " << SG_ORIGIN);
} else {
return i->getInstruction();
}
}
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
- SG_LOG(SG_GENERAL, SG_ALERT,
+ SG_LOG(SG_ATC, SG_ALERT,
"AI error: Aircraft without traffic record is signing off from tower at " << SG_ORIGIN);
} else {
//cerr << i->getAircraft()->getCallSign() << " signing off from startupcontroller" << endl;
FGATCDialogNew::instance()->removeEntry(1);
} else {
//cerr << "creading message for " << i->getAircraft()->getCallSign() << endl;
- transmit(&(*i), msgId, msgDir, false);
+ transmit(&(*i), &(*parent), msgId, msgDir, false);
return false;
}
}
if (now > startTime) {
//cerr << "Transmitting startup msg" << endl;
- transmit(&(*i), msgId, msgDir, true);
+ transmit(&(*i), &(*parent), msgId, msgDir, true);
i->updateState();
lastTransmission = now;
available = false;
// // update position of the current aircraft
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
- SG_LOG(SG_GENERAL, SG_ALERT,
+ SG_LOG(SG_ATC, SG_ALERT,
"AI error: updating aircraft without traffic record at " << SG_ORIGIN);
} else {
i->setPositionAndHeading(lat, lon, heading, speed, alt);
if (now > startTime + 200) {
if (i->pushBackAllowed()) {
i->allowRepeatedTransmissions();
- transmit(&(*i), MSG_PERMIT_PUSHBACK_CLEARANCE,
+ transmit(&(*i), &(*parent), MSG_PERMIT_PUSHBACK_CLEARANCE,
ATC_GROUND_TO_AIR, true);
i->updateState();
} else {
- transmit(&(*i), MSG_HOLD_PUSHBACK_CLEARANCE,
+ transmit(&(*i), &(*parent), MSG_HOLD_PUSHBACK_CLEARANCE,
ATC_GROUND_TO_AIR, true);
i->suppressRepeatedTransmissions();
}
double lon, double elev, double hdg, double slope)
{
SGGeod geod = SGGeod::fromDegM(lon, lat, elev);
- obj_pos = geod.makeZUpFrame();
+ obj_pos = makeZUpFrame(geod);
// hdg is not a compass heading, but a counter-clockwise rotation
// around the Z axis
obj_pos.preMult(osg::Matrix::rotate(hdg * SGD_DEGREES_TO_RADIANS,
if (visible) {
group = new osg::Group;
FGScenery * local_scenery = globals->get_scenery();
- double elevation_meters = 0.0;
- double elevation_feet = 0.0;
+ //double elevation_meters = 0.0;
+ //double elevation_feet = 0.0;
//for ( FGTaxiSegmentVectorIterator i = segments.begin(); i != segments.end(); i++) {
double dx = 0;
+ time_t now = time(NULL) + fgGetLong("/sim/time/warp");
for (TrafficVectorIterator i = activeTraffic.begin(); i != activeTraffic.end(); i++) {
if (i->isActive(300)) {
// Handle start point
if (pos > 0) {
FGTaxiSegment *segment = parent->getGroundNetwork()->findSegment(pos);
SGGeod start(SGGeod::fromDeg((i->getLongitude()), (i->getLatitude())));
- SGGeod end (SGGeod::fromDeg(segment->getEnd()->getLongitude(), segment->getEnd()->getLatitude()));
+ SGGeod end (segment->getEnd()->geod());
double length = SGGeodesy::distanceM(start, end);
- //heading = SGGeodesy::headingDeg(start->getGeod(), end->getGeod());
+ //heading = SGGeodesy::headingDeg(start->geod(), end->geod());
double az2, heading; //, distanceM;
SGGeodesy::inverse(start, end, heading, az2, length);
SGGeod center2 = end;
center2.setElevationM(SG_MAX_ELEVATION_M);
if (local_scenery->get_elevation_m( center2, elevationEnd, NULL )) {
- elevation_feet = elevationEnd * SG_METER_TO_FEET + 0.5;
+ //elevation_feet = elevationEnd * SG_METER_TO_FEET + 0.5;
//elevation_meters += 0.5;
}
else {
geode->addDrawable(geometry);
//osg::Node *custom_obj;
SGMaterial *mat;
- if (segment->hasBlock()) {
+ if (segment->hasBlock(now)) {
mat = matlib->find("UnidirectionalTaperRed");
} else {
mat = matlib->find("UnidirectionalTaperGreen");
double elevationStart = segment->getStart()->getElevationM(parent->getElevation()*SG_FEET_TO_METER);
double elevationEnd = segment->getEnd ()->getElevationM(parent->getElevation()*SG_FEET_TO_METER);
if ((elevationStart == 0) || (elevationStart == parent->getElevation())) {
- SGGeod center2 = segment->getStart()->getGeod();
+ SGGeod center2 = segment->getStart()->geod();
center2.setElevationM(SG_MAX_ELEVATION_M);
if (local_scenery->get_elevation_m( center2, elevationStart, NULL )) {
- elevation_feet = elevationStart * SG_METER_TO_FEET + 0.5;
+ //elevation_feet = elevationStart * SG_METER_TO_FEET + 0.5;
//elevation_meters += 0.5;
}
else {
segment->getStart()->setElevation(elevationStart);
}
if ((elevationEnd == 0) || (elevationEnd == parent->getElevation())) {
- SGGeod center2 = segment->getEnd()->getGeod();
+ SGGeod center2 = segment->getEnd()->geod();
center2.setElevationM(SG_MAX_ELEVATION_M);
if (local_scenery->get_elevation_m( center2, elevationEnd, NULL )) {
- elevation_feet = elevationEnd * SG_METER_TO_FEET + 0.5;
+ //elevation_feet = elevationEnd * SG_METER_TO_FEET + 0.5;
//elevation_meters += 0.5;
}
else {
//cerr << "2. Using mean elevation : " << elevationMean << " and " << slope << endl;
-
- WorldCoordinate( obj_pos, segment->getLatitude(), segment->getLongitude(), elevationMean + 0.5 + dx, -(segment->getHeading()), slope );
+ SGGeod segCenter(segment->getCenter());
+ WorldCoordinate( obj_pos, segCenter.getLatitudeDeg(),
+ segCenter.getLongitudeDeg(), elevationMean + 0.5 + dx, -(segment->getHeading()), slope );
//WorldCoordinate( obj_pos, segment->getLatitude(), segment->getLongitude(), parent->getElevation()+8+dx, -(segment->getHeading()) );
geode->addDrawable(geometry);
//osg::Node *custom_obj;
SGMaterial *mat;
- if (segment->hasBlock()) {
+ if (segment->hasBlock(now)) {
mat = matlib->find("UnidirectionalTaperRed");
} else {
mat = matlib->find("UnidirectionalTaperGreen");
}
// // update position of the current aircraft
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
- SG_LOG(SG_GENERAL, SG_ALERT,
+ SG_LOG(SG_ATC, SG_ALERT,
"AI error: updating aircraft without traffic record at " << SG_ORIGIN);
} else {
i->setPositionAndHeading(lat, lon, heading, speed, alt);
}
}
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
- SG_LOG(SG_GENERAL, SG_ALERT,
+ SG_LOG(SG_ATC, SG_ALERT,
"AI error: Aircraft without traffic record is signing off from approach at " << SG_ORIGIN);
} else {
i = activeTraffic.erase(i);
}
}
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
- SG_LOG(SG_GENERAL, SG_ALERT,
+ SG_LOG(SG_ATC, SG_ALERT,
"AI error: checking ATC instruction for aircraft without traffic record at " << SG_ORIGIN);
} else {
return i->hasInstruction();
}
}
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
- SG_LOG(SG_GENERAL, SG_ALERT,
+ SG_LOG(SG_ATC, SG_ALERT,
"AI error: requesting ATC instruction for aircraft without traffic record at " << SG_ORIGIN);
} else {
return i->getInstruction();
}
-ActiveRunway *FGApproachController::getRunway(string name)
+ActiveRunway *FGApproachController::getRunway(const string& name)
{
ActiveRunwayVecIterator rwy = activeRunways.begin();
if (activeRunways.size()) {