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