]> git.mxchange.org Git - flightgear.git/blob - src/ATCDCL/AIMgr.hxx
Tie samplegroup 'avionics' to the listener, just in case no other device is created...
[flightgear.git] / src / ATCDCL / AIMgr.hxx
1 // AIMgr.hxx - definition of FGAIMgr 
2 // - a global management class for FlightGear generated AI traffic
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21
22 #ifndef _FG_AIMGR_HXX
23 #define _FG_AIMGR_HXX
24
25 #include <simgear/structure/subsystem_mgr.hxx>
26
27 #include <Main/fg_props.hxx>
28
29 #include <list>
30
31 #include "ATCmgr.hxx"
32 #include "AIEntity.hxx"
33
34 using std::list;
35
36
37 class FGAIMgr : public SGSubsystem
38 {
39
40 private:
41         FGATCMgr* ATC;  
42         // This is purely for synactic convienience to avoid writing globals->get_ATC_mgr()-> all through the code!
43
44     // A list of pointers to all currently active AI stuff
45     typedef list <FGAIEntity*> ai_list_type;
46     typedef ai_list_type::iterator ai_list_iterator;
47     typedef ai_list_type::const_iterator ai_list_const_iterator;
48
49     // Everything put in this list should be created dynamically
50     // on the heap and ***DELETED WHEN REMOVED!!!!!***
51     ai_list_type ai_list;
52     ai_list_iterator ai_list_itr;
53     // Any member function of FGATCMgr is permitted to leave this iterator pointing
54     // at any point in or at the end of the list.
55     // Hence any new access must explicitly first check for atc_list.end() before dereferencing.
56         
57         // A list of airport or airplane ID's
58         typedef list < string > ID_list_type;
59         typedef ID_list_type::iterator ID_list_iterator;
60
61         // Temporary storage of ID of planes scheduled for removeal
62         ID_list_type removalList;
63         
64         // A map of airport-IDs that have taxiway network files against bucket number
65         typedef map < int, ID_list_type* > ai_apt_map_type;
66         typedef ai_apt_map_type::iterator ai_apt_map_iterator;
67         ai_apt_map_type facilities;
68         
69         // A map of airport ID's that we've activated AI traffic at
70         typedef map < string, int > ai_activated_map_type;
71         typedef ai_activated_map_type::iterator ai_activated_map_iterator;
72         ai_activated_map_type activated;
73         
74         // AI traffic lists mapped by airport
75         typedef map < string, ai_list_type > ai_traffic_map_type;
76         typedef ai_traffic_map_type::iterator ai_traffic_map_iterator;
77         ai_traffic_map_type traffic;
78         
79         // A map of callsigns that we have used (eg CFGFS or N0546D - the code will generate Cessna-four-six-delta from this later)
80         typedef map < string, int > ai_callsigns_map_type;
81         typedef ai_callsigns_map_type::iterator ai_callsigns_map_iterator;
82         ai_callsigns_map_type ai_callsigns_used;
83
84   SGGeod _userAircraftPos;
85
86   // Pointers to current users position
87   SGPropertyNode_ptr lon_node;
88   SGPropertyNode_ptr lat_node;
89   SGPropertyNode_ptr elev_node;
90 public:
91
92     FGAIMgr();
93     ~FGAIMgr();
94
95     void init();
96
97     void bind();
98
99     void unbind();
100
101     void update(double dt);
102         
103         // Signal that it is OK to remove a plane of callsign s
104         // (To be called by the plane itself).
105         void ScheduleRemoval(const string& s);
106
107 private:
108         
109         osg::ref_ptr<osg::Node> _defaultModel;  // Cessna 172!
110         osg::ref_ptr<osg::Node> _piperModel;    // pa28-161
111
112         bool initDone;  // Hack - guard against update getting called before init
113
114     // Remove a class from the ai_list and delete it from memory
115     //void RemoveFromList(const char* id, atc_type tp);
116         
117         // Activate AI traffic at an airport
118         void ActivateAirport(const string& ident);
119         
120         // Hack - Generate AI traffic at an airport with no facilities file, with the first plane being at least min_dist out.
121         void GenerateSimpleAirportTraffic(const string& ident, double min_dist = 0.0);
122         
123         // Search for valid airports in the vicinity of the user and activate them if necessary
124         void SearchByPos(double range);
125         
126         string GenerateCallsign();
127         
128         string GenerateUniqueCallsign();
129         
130         string GenerateShortForm(const string& callsign, const string& plane_str = "Cessna-", bool local = false);
131         
132         // TODO - implement a proper robust system for registering and loading AI GA aircraft models
133         bool _havePiperModel;
134 };
135
136 #endif  // _FG_AIMGR_HXX