]> git.mxchange.org Git - flightgear.git/blob - src/ATC/tower.hxx
Attached are a fairly extensive series of patches to the ATC
[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 <string>
31
32 SG_USING_STD(string);
33
34 #include "ATC.hxx"
35
36 //DCL - a complete guess for now.
37 #define FG_TOWER_DEFAULT_RANGE 30
38
39 // somewhere in the ATC/AI system we are going to have defined something like
40 // struct plane_rec
41 // list <PlaneRec> plane_rec_list_type
42
43 class FGTower : public FGATC {
44
45 private:
46
47     // Need a data structure to hold details of the various active planes
48     // or possibly another data structure with the positions of the inactive planes.
49     // Need a data structure to hold outstanding communications from aircraft.
50
51
52 public:
53
54     FGTower();
55     ~FGTower();
56
57     void Init();
58
59     void Update();
60
61     inline void SetDisplay() {display = true;}
62     inline void SetNoDisplay() {display = false;}
63
64     inline char get_type() const { return type; }
65     inline double get_lon() const { return lon; }
66     inline double get_lat() const { return lat; }
67     inline double get_elev() const { return elev; }
68     inline double get_x() const { return x; }
69     inline double get_y() const { return y; }
70     inline double get_z() const { return z; }
71     inline int get_freq() const { return freq; }
72     inline int get_range() const { return range; }
73     inline const char* GetIdent() { return ident.c_str(); }
74     inline string get_trans_ident() { return trans_ident; }
75     inline atc_type GetType() { return TOWER; }
76
77     // Make a request of tower control
78     //void Request(tower_request request);
79
80 private:
81
82     char type;
83     double lon, lat;
84     double elev;
85     double x, y, z;
86     int freq;
87     int range;
88     bool display;               // Flag to indicate whether we should be outputting to the ATC display.
89     bool displaying;            // Flag to indicate whether we are outputting to the ATC display.
90     string ident;               // Code of the airport its at.
91     string name;                // Name generally used in transmissions.
92
93     // for failure modeling
94     string trans_ident;         // transmitted ident
95     bool tower_failed;          // tower failed?
96
97     friend istream& operator>> ( istream&, FGTower& );
98 };
99
100
101 inline istream&
102 operator >> ( istream& in, FGTower& t )
103 {
104     double f;
105     char ch;
106
107     in >> t.type;
108     
109     if ( t.type == '[' )
110       return in >> skipeol;
111
112     in >> t.lat >> t.lon >> t.elev >> f >> t.range 
113        >> t.ident;
114
115     t.name = "";
116     in >> ch;
117     t.name += ch;
118     while(1) {
119         //in >> noskipws
120         in.unsetf(ios::skipws);
121         in >> ch;
122         t.name += ch;
123         if((ch == '"') || (ch == 0x0A)) {
124             break;
125         }   // we shouldn't need the 0x0A but it makes a nice safely in case someone leaves off the "
126     }
127     in.setf(ios::skipws);
128     //cout << "tower.name = " << t.name << '\n';
129
130     t.freq = (int)(f*100.0 + 0.5);
131
132     // cout << t.ident << endl;
133
134     // generate cartesian coordinates
135     Point3D geod( t.lon * SGD_DEGREES_TO_RADIANS, t.lat * SGD_DEGREES_TO_RADIANS, t.elev );
136     Point3D cart = sgGeodToCart( geod );
137     t.x = cart.x();
138     t.y = cart.y();
139     t.z = cart.z();
140
141     t.trans_ident = t.ident;
142     t.tower_failed = false;
143
144     return in >> skipeol;
145 }
146
147
148 #endif  //_FG_TOWER_HXX