Assigned an ATC controller to the user's Aircraft and change the comm1 radio frequency according to the frequency relevant to the current scenario.
This commit is contained in:
parent
3455079060
commit
e04d2f8ba9
8 changed files with 92 additions and 4 deletions
|
@ -27,6 +27,9 @@
|
|||
#include <iostream>
|
||||
|
||||
#include <simgear/math/SGMath.hxx>
|
||||
#include <Airports/dynamics.hxx>
|
||||
#include <Airports/simple.hxx>
|
||||
|
||||
#include "atc_mgr.hxx"
|
||||
|
||||
|
||||
|
@ -43,6 +46,37 @@ void FGATCManager::init() {
|
|||
currentATCDialog = new FGATCDialogNew;
|
||||
currentATCDialog->init();
|
||||
|
||||
// find a reasonable controller for our user's aircraft..
|
||||
// Let's start by working out the following three scenarios:
|
||||
// Starting on ground at a parking position
|
||||
// Starting on ground at the runway.
|
||||
// Starting in the Air
|
||||
bool onGround = fgGetBool("/sim/presets/onground");
|
||||
string runway = fgGetString("/sim/atc/runway");
|
||||
string airport = fgGetString("/sim/presets/airport-id");
|
||||
string parking = fgGetString("/sim/presets/parkpos");
|
||||
|
||||
FGAirport *apt = FGAirport::findByIdent(airport);
|
||||
cerr << "found information: " << runway << " " << airport << ": parking = " << parking << endl;
|
||||
if (onGround) {
|
||||
if (parking.empty()) {
|
||||
controller = apt->getDynamics()->getTowerController();
|
||||
int stationFreq = apt->getDynamics()->getTowerFrequency(2);
|
||||
cerr << "Setting radio frequency to in airfrequency: " << stationFreq << endl;
|
||||
fgSetDouble("/instrumentation/comm[0]/frequencies/selected-mhz", ((double) stationFreq / 100.0));
|
||||
|
||||
} else {
|
||||
controller = apt->getDynamics()->getGroundNetwork();
|
||||
int stationFreq = apt->getDynamics()->getGroundFrequency(2);
|
||||
cerr << "Setting radio frequency to : " << stationFreq << endl;
|
||||
fgSetDouble("/instrumentation/comm[0]/frequencies/selected-mhz", ((double) stationFreq / 100.0));
|
||||
|
||||
}
|
||||
} else {
|
||||
controller = 0;
|
||||
}
|
||||
//controller =
|
||||
|
||||
//dialog.init();
|
||||
}
|
||||
|
||||
|
@ -52,4 +86,5 @@ void FGATCManager::addController(FGATCController *controller) {
|
|||
|
||||
void FGATCManager::update ( double time ) {
|
||||
//cerr << "ATC update code is running at time: " << time << endl;
|
||||
currentATCDialog->update(time);
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ class FGATCManager : public SGSubsystem
|
|||
{
|
||||
private:
|
||||
AtcVec activeStations;
|
||||
FGATCController *controller; // The ATC controller that is responsible for the user's aircraft.
|
||||
//FGATCDialogNew dialog; // note that this variable should really replace the ugly global "currentATCDialog();
|
||||
|
||||
public:
|
||||
|
|
|
@ -132,3 +132,13 @@ void FGATCDialogNew::PopupDialog() {
|
|||
dialogVisible = !dialogVisible;
|
||||
return;
|
||||
}
|
||||
|
||||
void FGATCDialogNew::update(double dt) {
|
||||
static SGPropertyNode_ptr trans_num = globals->get_props()->getNode("/sim/atc/transmission-num", true);
|
||||
int n = trans_num->getIntValue();
|
||||
if (n >= 0) {
|
||||
trans_num->setIntValue(-1);
|
||||
// PopupCallback(n);
|
||||
cerr << "Selected transmission message" << n << endl;
|
||||
}
|
||||
}
|
|
@ -452,8 +452,7 @@ FGATCController::FGATCController()
|
|||
dt_count = 0;
|
||||
available = true;
|
||||
lastTransmission = 0;
|
||||
FGATCManager *mgr = (FGATCManager*) globals->get_subsystem("ATC");
|
||||
mgr->addController(this);
|
||||
initialized = false;
|
||||
}
|
||||
|
||||
FGATCController::~FGATCController()
|
||||
|
@ -672,6 +671,15 @@ string FGATCController::genTransponderCode(string fltRules)
|
|||
}
|
||||
}
|
||||
|
||||
void FGATCController::init()
|
||||
{
|
||||
if (!initialized) {
|
||||
FGATCManager *mgr = (FGATCManager*) globals->get_subsystem("ATC");
|
||||
mgr->addController(this);
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
* class FGTowerController
|
||||
*
|
||||
|
@ -690,6 +698,7 @@ void FGTowerController::announcePosition(int id,
|
|||
double radius, int leg,
|
||||
FGAIAircraft * ref)
|
||||
{
|
||||
init();
|
||||
TrafficVectorIterator i = activeTraffic.begin();
|
||||
// Search whether the current id alread has an entry
|
||||
// This might be faster using a map instead of a vector, but let's start by taking a safe route
|
||||
|
@ -882,6 +891,7 @@ void FGStartupController::announcePosition(int id,
|
|||
double radius, int leg,
|
||||
FGAIAircraft * ref)
|
||||
{
|
||||
init();
|
||||
TrafficVectorIterator i = activeTraffic.begin();
|
||||
// Search whether the current id alread has an entry
|
||||
// This might be faster using a map instead of a vector, but let's start by taking a safe route
|
||||
|
@ -1141,6 +1151,7 @@ void FGApproachController::announcePosition(int id,
|
|||
double alt, double radius,
|
||||
int leg, FGAIAircraft * ref)
|
||||
{
|
||||
init();
|
||||
TrafficVectorIterator i = activeTraffic.begin();
|
||||
// Search whether the current id alread has an entry
|
||||
// This might be faster using a map instead of a vector, but let's start by taking a safe route
|
||||
|
|
|
@ -225,6 +225,8 @@ typedef vector<ActiveRunway>::iterator ActiveRunwayVecIterator;
|
|||
*************************************************************************************/
|
||||
class FGATCController
|
||||
{
|
||||
private:
|
||||
bool initialized;
|
||||
protected:
|
||||
bool available;
|
||||
time_t lastTransmission;
|
||||
|
@ -260,6 +262,8 @@ public:
|
|||
ATC_GROUND_TO_AIR } AtcMsgDir;
|
||||
FGATCController();
|
||||
virtual ~FGATCController();
|
||||
void init();
|
||||
|
||||
virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
|
||||
double lat, double lon,
|
||||
double hdg, double spd, double alt, double radius, int leg,
|
||||
|
|
|
@ -535,6 +535,32 @@ int FGAirportDynamics::getGroundFrequency(unsigned leg)
|
|||
return groundFreq;
|
||||
}
|
||||
|
||||
int FGAirportDynamics::getTowerFrequency(unsigned nr)
|
||||
{
|
||||
int towerFreq = 0;
|
||||
if (nr < 2) {
|
||||
SG_LOG(SG_ATC, SG_ALERT,
|
||||
"Leg value is smaller than two at " << SG_ORIGIN);
|
||||
}
|
||||
if (freqTower.size() == 0) {
|
||||
return 0;
|
||||
}
|
||||
if ((freqTower.size() > nr - 1) && (nr > 1)) {
|
||||
towerFreq = freqTower[nr - 1];
|
||||
}
|
||||
if ((freqTower.size() < nr - 1) && (nr > 1)) {
|
||||
towerFreq =
|
||||
(freqTower.size() <
|
||||
(nr - 1)) ? freqTower[freqTower.size() -
|
||||
1] : freqTower[nr - 2];
|
||||
}
|
||||
if ((freqTower.size() >= nr - 1) && (nr > 1)) {
|
||||
towerFreq = freqTower[nr - 2];
|
||||
}
|
||||
return towerFreq;
|
||||
}
|
||||
|
||||
|
||||
FGAIFlightPlan *FGAirportDynamics::getSID(string activeRunway,
|
||||
double heading)
|
||||
{
|
||||
|
|
|
@ -119,8 +119,8 @@ public:
|
|||
FGApproachController *getApproachController() { return &approachController; };
|
||||
|
||||
const string& getAtisInformation() { return atisInformation; };
|
||||
int getGroundFrequency(unsigned leg); //{ return freqGround.size() ? freqGround[0] : 0; };
|
||||
|
||||
int getGroundFrequency (unsigned leg); //{ return freqGround.size() ? freqGround[0] : 0; };
|
||||
int getTowerFrequency (unsigned nr);
|
||||
void setRwyUse(const FGRunwayPreference& ref);
|
||||
};
|
||||
|
||||
|
|
|
@ -460,6 +460,7 @@ void FGGroundNetwork::announcePosition(int id,
|
|||
double radius, int leg,
|
||||
FGAIAircraft * aircraft)
|
||||
{
|
||||
init();
|
||||
TrafficVectorIterator i = activeTraffic.begin();
|
||||
// Search search if the current id alread has an entry
|
||||
// This might be faster using a map instead of a vector, but let's start by taking a safe route
|
||||
|
|
Loading…
Reference in a new issue