1 // AIMgr.hxx - definition of FGAIMgr
2 // - a global management class for FlightGear generated AI traffic
4 // Written by David Luff, started March 2002.
6 // Copyright (C) 2002 David C Luff - david.luff@nottingham.ac.uk
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.
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.
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.
25 #include <simgear/structure/subsystem_mgr.hxx>
26 #include <simgear/structure/ssgSharedPtr.hxx>
28 #include <Main/fg_props.hxx>
33 #include "AIEntity.hxx"
38 class FGAIMgr : public SGSubsystem
43 // This is purely for synactic convienience to avoid writing globals->get_ATC_mgr()-> all through the code!
45 // A list of pointers to all currently active AI stuff
46 typedef list <FGAIEntity*> ai_list_type;
47 typedef ai_list_type::iterator ai_list_iterator;
48 typedef ai_list_type::const_iterator ai_list_const_iterator;
50 // Everything put in this list should be created dynamically
51 // on the heap and ***DELETED WHEN REMOVED!!!!!***
53 ai_list_iterator ai_list_itr;
54 // Any member function of FGATCMgr is permitted to leave this iterator pointing
55 // at any point in or at the end of the list.
56 // Hence any new access must explicitly first check for atc_list.end() before dereferencing.
58 // A list of airport or airplane ID's
59 typedef list < string > ID_list_type;
60 typedef ID_list_type::iterator ID_list_iterator;
62 // Temporary storage of ID of planes scheduled for removeal
63 ID_list_type removalList;
65 // A map of airport-IDs that have taxiway network files against bucket number
66 typedef map < int, ID_list_type* > ai_apt_map_type;
67 typedef ai_apt_map_type::iterator ai_apt_map_iterator;
68 ai_apt_map_type facilities;
70 // A map of airport ID's that we've activated AI traffic at
71 typedef map < string, int > ai_activated_map_type;
72 typedef ai_activated_map_type::iterator ai_activated_map_iterator;
73 ai_activated_map_type activated;
75 // AI traffic lists mapped by airport
76 typedef map < string, ai_list_type > ai_traffic_map_type;
77 typedef ai_traffic_map_type::iterator ai_traffic_map_iterator;
78 ai_traffic_map_type traffic;
80 // A map of callsigns that we have used (eg CFGFS or N0546D - the code will generate Cessna-four-six-delta from this later)
81 typedef map < string, int > ai_callsigns_map_type;
82 typedef ai_callsigns_map_type::iterator ai_callsigns_map_iterator;
83 ai_callsigns_map_type ai_callsigns_used;
85 // Position of the Users Aircraft
89 // Pointers to current users position
90 SGPropertyNode *lon_node;
91 SGPropertyNode *lat_node;
92 SGPropertyNode *elev_node;
105 void update(double dt);
107 // Signal that it is OK to remove a plane of callsign s
108 // (To be called by the plane itself).
109 void ScheduleRemoval(const string& s);
113 ssgSharedPtr<ssgBranch> _defaultModel; // Cessna 172!
114 ssgSharedPtr<ssgBranch> _piperModel; // pa28-161
116 bool initDone; // Hack - guard against update getting called before init
118 // Remove a class from the ai_list and delete it from memory
119 //void RemoveFromList(const char* id, atc_type tp);
121 // Activate AI traffic at an airport
122 void ActivateAirport(const string& ident);
124 // Hack - Generate AI traffic at an airport with no facilities file, with the first plane being at least min_dist out.
125 void GenerateSimpleAirportTraffic(const string& ident, double min_dist = 0.0);
127 // Search for valid airports in the vicinity of the user and activate them if necessary
128 void SearchByPos(double range);
130 string GenerateCallsign();
132 string GenerateUniqueCallsign();
134 string GenerateShortForm(const string& callsign, const string& plane_str = "Cessna-", bool local = false);
136 // TODO - implement a proper robust system for registering and loading AI GA aircraft models
137 bool _havePiperModel;
140 #endif // _FG_AIMGR_HXX