]> git.mxchange.org Git - flightgear.git/blob - src/ATC/tower.hxx
More efficient rotation matrix calc from Norm Vine.
[flightgear.git] / src / ATC / tower.hxx
1 // FGTower - a class to provide tower control at towered airports.
2 //
3 // Written by David Luff, started March 2002.
4 //
5 // Copyright (C) 2002  David C. Luff - david.luff@nottingham.ac.uk
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 #ifndef _FG_TOWER_HXX
22 #define _FG_TOWER_HXX
23
24 #include <simgear/compiler.h>
25 #include <simgear/math/point3d.hxx>
26 #include <simgear/misc/sgstream.hxx>
27 #include <simgear/math/sg_geodesy.hxx>
28 #include <plib/sg.h>
29
30 #include STL_IOSTREAM
31 #include STL_STRING
32
33 SG_USING_STD(string);
34 #ifndef SG_HAVE_NATIVE_SGI_COMPILERS
35 SG_USING_STD(ios);
36 #endif
37
38 #include "ATC.hxx"
39
40 //DCL - a complete guess for now.
41 #define FG_TOWER_DEFAULT_RANGE 30
42
43 // somewhere in the ATC/AI system we are going to have defined something like
44 // struct plane_rec
45 // list <PlaneRec> plane_rec_list_type
46
47 class FGTower : public FGATC {
48
49 private:
50
51     // Need a data structure to hold details of the various active planes
52     // or possibly another data structure with the positions of the inactive planes.
53     // Need a data structure to hold outstanding communications from aircraft.
54
55
56 public:
57
58     FGTower();
59     ~FGTower();
60
61     void Init();
62
63     void Update();
64
65     inline void SetDisplay() {display = true;}
66     inline void SetNoDisplay() {display = false;}
67
68     inline char get_type() const { return type; }
69     inline double get_lon() const { return lon; }
70     inline double get_lat() const { return lat; }
71     inline double get_elev() const { return elev; }
72     inline double get_x() const { return x; }
73     inline double get_y() const { return y; }
74     inline double get_z() const { return z; }
75     inline int get_freq() const { return freq; }
76     inline int get_range() const { return range; }
77     inline const char* GetIdent() { return ident.c_str(); }
78     inline string get_trans_ident() { return trans_ident; }
79     inline atc_type GetType() { return TOWER; }
80
81     // Make a request of tower control
82     //void Request(tower_request request);
83
84 private:
85
86     char type;
87     double lon, lat;
88     double elev;
89     double x, y, z;
90     int freq;
91     int range;
92     bool display;               // Flag to indicate whether we should be outputting to the ATC display.
93     bool displaying;            // Flag to indicate whether we are outputting to the ATC display.
94     string ident;               // Code of the airport its at.
95     string name;                // Name generally used in transmissions.
96
97     // for failure modeling
98     string trans_ident;         // transmitted ident
99     bool tower_failed;          // tower failed?
100
101     friend istream& operator>> ( istream&, FGTower& );
102 };
103
104
105 inline istream&
106 operator >> ( istream& in, FGTower& t )
107 {
108     double f;
109     char ch;
110
111     in >> t.type;
112     
113     if ( t.type == '[' )
114       return in >> skipeol;
115
116     in >> t.lat >> t.lon >> t.elev >> f >> t.range 
117        >> t.ident;
118
119     t.name = "";
120     in >> ch;
121     t.name += ch;
122     while(1) {
123         //in >> noskipws
124         in.unsetf(ios::skipws);
125         in >> ch;
126         t.name += ch;
127         if((ch == '"') || (ch == 0x0A)) {
128             break;
129         }   // we shouldn't need the 0x0A but it makes a nice safely in case someone leaves off the "
130     }
131     in.setf(ios::skipws);
132     //cout << "tower.name = " << t.name << '\n';
133
134     t.freq = (int)(f*100.0 + 0.5);
135
136     // cout << t.ident << endl;
137
138     // generate cartesian coordinates
139     Point3D geod( t.lon * SGD_DEGREES_TO_RADIANS, t.lat * SGD_DEGREES_TO_RADIANS, t.elev );
140     Point3D cart = sgGeodToCart( geod );
141     t.x = cart.x();
142     t.y = cart.y();
143     t.z = cart.z();
144
145     t.trans_ident = t.ident;
146     t.tower_failed = false;
147
148     return in >> skipeol;
149 }
150
151
152 #endif  //_FG_TOWER_HXX