]> git.mxchange.org Git - flightgear.git/blob - src/ATC/ATCmgr.hxx
Attached are a fairly extensive series of patches to the ATC
[flightgear.git] / src / ATC / ATCmgr.hxx
1 // ATCMgr.hxx - definition of FGATCMgr 
2 // - a global management class for FlightGear generated ATC
3 //
4 // Written by David Luff, started February 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 #ifndef _FG_ATCMGR_HXX
23 #define _FG_ATCMGR_HXX
24
25 #include <Main/fgfs.hxx>
26 #include <Main/fg_props.hxx>
27
28 #include <string>
29 #include <list>
30 #include <map>
31
32 #include "atis.hxx"
33 #include "tower.hxx"
34 #include "approach.hxx"
35 //#include "ground.hxx"
36 #include "ATC.hxx"
37
38 SG_USING_STD(string);
39 SG_USING_STD(list);
40 SG_USING_STD(map);
41
42 const int max_app = 20;
43
44 // Structure for holding details of the ATC frequencies at a given airport, and whether they are in the active list or not.
45 // These can then be cross referenced with the [atis][tower][etc]lists which are stored by frequency.
46 // Non-available services are denoted by a frequency of zero.
47 // Eventually the whole ATC data structures may have to be rethought if we turn out to be massive memory hogs!!
48 struct AirportATC {
49     float lon;
50     float lat;
51     float elev;
52     float atis_freq;
53     bool atis_active;
54     float tower_freq;
55     bool tower_active;
56     float ground_freq;
57     bool ground_active;
58     //float approach_freq;
59     //bool approach_active;
60     //float departure_freq;
61     //bool departure_active;
62
63     // Flags to ensure the stations don't get wrongly deactivated
64     bool set_by_AI;     // true when the AI manager has activated this station
65     bool set_by_comm_search;    // true when the comm_search has activated this station
66 };
67
68 class FGATCMgr : public FGSubsystem
69 {
70
71 private:
72
73     // A map of airport ID vs frequencies and ATC provision
74     typedef map < string, AirportATC* > airport_atc_map_type;
75     typedef airport_atc_map_type::iterator airport_atc_map_iterator;
76     typedef airport_atc_map_type::const_iterator airport_atc_map_const_iterator;
77
78     airport_atc_map_type airport_atc_map;
79     airport_atc_map_iterator airport_atc_map_itr;
80
81     // A list of pointers to all currently active ATC classes
82     typedef list <FGATC*> atc_list_type;
83     typedef atc_list_type::iterator atc_list_iterator;
84     typedef atc_list_type::const_iterator atc_list_const_iterator;
85
86     // Everything put in this list should be created dynamically
87     // on the heap and ***DELETED WHEN REMOVED!!!!!***
88     atc_list_type atc_list;
89     atc_list_iterator atc_list_itr;
90     // Any member function of FGATCMgr is permitted to leave this iterator pointing
91     // at any point in or at the end of the list.
92     // Hence any new access must explicitly first check for atc_list.end() before dereferencing.
93
94     // Position of the Users Aircraft
95     double lon;
96     double lat;
97     double elev;
98
99     // Type of ATC control that the user's radios are tuned to.
100     atc_type comm1_type;
101     atc_type comm2_type;
102
103     double comm1_freq;
104     double comm2_freq;
105
106     // Pointers to users current communication frequencies.
107     SGPropertyNode *comm1_node;
108     SGPropertyNode *comm2_node;
109
110     // Pointers to current users position
111     SGPropertyNode *lon_node;
112     SGPropertyNode *lat_node;
113     SGPropertyNode *elev_node;
114
115     // Position of the ATC that the comm radios are tuned to in order to decide whether transmission
116     // will be received
117     double comm1_x, comm1_y, comm1_z, comm1_elev;
118     double comm1_range, comm1_effective_range;
119     bool comm1_valid; 
120     bool comm1_atis_valid;
121     bool comm1_tower_valid;
122     bool comm1_approach_valid;
123     const char* comm1_ident;
124     const char* comm1_atis_ident;
125     const char* comm1_tower_ident;
126     const char* comm1_approach_ident;
127     const char* last_comm1_ident;
128     const char* last_comm1_atis_ident;
129     const char* last_comm1_tower_ident;
130     const char* last_comm1_approach_ident;
131     const char* approach_ident;
132     bool last_in_range;
133     double comm2_x, comm2_y, comm2_z, comm2_elev;
134     double comm2_range, comm2_effective_range;
135     bool comm2_valid;
136     const char* comm2_ident;
137     const char* last_comm2_ident;
138
139     FGATIS atis;
140     //FGGround ground;
141     FGTower tower;
142     FGApproach approaches[max_app];
143     FGApproach approach;
144     //FGDeparture departure;
145
146 public:
147
148     FGATCMgr();
149     ~FGATCMgr();
150
151     void init();
152
153     void bind();
154
155     void unbind();
156
157     void update(int dt);
158
159     // Returns true if the airport is found in the map
160     bool GetAirportATCDetails(string icao, AirportATC* a);
161
162     // Return a pointer to a given sort of ATC at a given airport and activate if necessary
163     FGATC* GetATCPointer(string icao, atc_type type);
164
165 private:
166
167     // Remove a class from the atc_list and delete it from memory
168     void RemoveFromList(const char* id, atc_type tp);
169
170     // Search a specified freq for matching stations
171     void Search();
172
173 };
174
175 #endif  // _FG_ATCMGR_HXX