1 // FGAILocalTraffic - AIEntity derived class with enough logic to
2 // fly and interact with the traffic pattern.
4 // Written by David Luff, started March 2002.
6 // Copyright (C) 2002 David C. Luff - david.luff@nottingham.ac.uk
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 /*****************************************************************
24 * WARNING - Curt has some ideas about AI traffic so anything in here
25 * may get rewritten or scrapped. Contact Curt curt@flightgear.org
26 * before spending any time or effort on this code!!!
28 ******************************************************************/
30 #include <Main/globals.hxx>
31 #include <Model/loader.hxx>
32 //#include <simgear/constants.h>
33 #include <simgear/math/point3d.hxx>
34 #include <simgear/math/sg_geodesy.hxx>
35 #include <simgear/misc/sg_path.hxx>
41 #include "AILocalTraffic.hxx"
43 FGAILocalTraffic::FGAILocalTraffic() {
46 FGAILocalTraffic::~FGAILocalTraffic() {
49 void FGAILocalTraffic::Init() {
50 // Hack alert - Hardwired path!!
51 string planepath = "Aircraft/c172/Models/c172-dpm.ac";
52 model = globals->get_model_loader()->load_model(planepath);
55 globals->get_model_loader()
56 ->load_model("Models/Geometry/glider.ac");
58 cout << "Failed to load an aircraft model in AILocalTraffic\n";
60 cout << "AILocal Traffic Model loaded successfully\n";
62 position = new ssgTransform;
63 position->addKid(model);
69 elev = (287.0 + 0.5) * SG_FEET_TO_METER; // Ground is 296 so this should be above it
75 // Activate the tower - this is dependent on the ATC system being initialised before the AI system
77 if(globals->get_ATC_mgr()->GetAirportATCDetails((string)"KEMT", &a)) {
78 if(a.tower_freq) { // Has a tower
79 tower = (FGTower*)globals->get_ATC_mgr()->GetATCPointer((string)"KEMT", TOWER); // Maybe need some error checking here
81 // Check CTAF, unicom etc
84 cout << "Unable to find airport details in FGAILocalTraffic::Init()\n";
90 // Run the internal calculations
91 void FGAILocalTraffic::Update() {
92 hdg = mag_hdg + mag_var;
94 // This should become if(the plane has moved) then Transform()