]> git.mxchange.org Git - flightgear.git/blob - src/ATC/AILocalTraffic.cxx
A bunch of reorg and clean up of the KR 87 (adf) code including some
[flightgear.git] / src / ATC / AILocalTraffic.cxx
1 // FGAILocalTraffic - AIEntity derived class with enough logic to
2 // fly and interact with the traffic pattern.
3 //
4 // Written by David Luff, started March 2002.
5 //
6 // Copyright (C) 2002  David C. Luff - david.luff@nottingham.ac.uk
7 //
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.
12 //
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.
17 //
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.
21
22 /*****************************************************************
23 *
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!!!
27 *
28 ******************************************************************/
29
30 #include <Main/globals.hxx>
31 //#include <simgear/constants.h>
32 #include <simgear/math/point3d.hxx>
33 #include <simgear/math/sg_geodesy.hxx>
34 #include <simgear/misc/sg_path.hxx>
35 #include <string>
36
37 SG_USING_STD(string);
38
39 #include "ATCmgr.hxx"
40 #include "AILocalTraffic.hxx"
41
42 FGAILocalTraffic::FGAILocalTraffic() {
43 }
44
45 FGAILocalTraffic::~FGAILocalTraffic() {
46 }
47
48 void FGAILocalTraffic::Init() {
49     // Hack alert - Hardwired path!!
50     string planepath = "Aircraft/c172/Models/c172-dpm.ac";
51     SGPath path = globals->get_fg_root();
52     path.append(planepath);
53     ssgTexturePath((char*)path.dir().c_str());
54     model = ssgLoad((char*)planepath.c_str());
55     if (model == 0) {
56         model = ssgLoad((char*)"Models/Geometry/glider.ac");
57         if (model == 0)
58             cout << "Failed to load an aircraft model in AILocalTraffic\n";
59     } else {
60         cout << "AILocal Traffic Model loaded successfully\n";
61     }
62     position = new ssgTransform;
63     position->addKid(model);
64
65     // Hardwire to KEMT
66     lat = 34.081358;
67     lon = -118.037483;
68     hdg = 0.0;
69     elev = (287.0 + 0.5) * SG_FEET_TO_METER;  // Ground is 296 so this should be above it
70     mag_hdg = -10.0;
71     pitch = 0.0;
72     roll = 0.0;
73     mag_var = -14.0;
74
75     // Activate the tower - this is dependent on the ATC system being initialised before the AI system
76     AirportATC a;
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
80         } else {
81             // Check CTAF, unicom etc
82         }
83     } else {
84         cout << "Unable to find airport details in FGAILocalTraffic::Init()\n";
85     }
86
87     Transform();
88 }
89
90 // Run the internal calculations
91 void FGAILocalTraffic::Update() {
92     hdg = mag_hdg + mag_var;
93     
94     // This should become if(the plane has moved) then Transform()
95     static int i = 0;
96     if(i == 60) {
97         Transform();
98         i = 0;
99     }
100     i++; 
101 }