]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIManager.hxx
Optimise NavCache airport query
[flightgear.git] / src / AIModel / AIManager.hxx
1 // AIManager.hxx - David Culp - based on:
2 // AIMgr.hxx - definition of FGAIMgr 
3 // - a global management class for FlightGear generated AI traffic
4 //
5 // Written by David Luff, started March 2002.
6 //
7 // Copyright (C) 2002  David C Luff - david.luff@nottingham.ac.uk
8 //
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License as
11 // published by the Free Software Foundation; either version 2 of the
12 // License, or (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 // General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
22
23 #ifndef _FG_AIMANAGER_HXX
24 #define _FG_AIMANAGER_HXX
25
26 #include <list>
27 #include <map>
28
29 #include <simgear/structure/subsystem_mgr.hxx>
30 #include <simgear/structure/SGSharedPtr.hxx>
31 #include <simgear/props/props_io.hxx>
32
33 #include <Main/fg_props.hxx>
34
35 #include <AIModel/AIBase.hxx>
36 #include <AIModel/AIFlightPlan.hxx>
37
38 #include <Traffic/SchedFlight.hxx>
39 #include <Traffic/Schedule.hxx>
40
41 class FGAIThermal;
42
43 typedef SGSharedPtr<FGAIBase> FGAIBasePtr;
44
45 class FGAIManager : public SGSubsystem
46 {
47
48 public:
49     FGAIManager();
50     virtual ~FGAIManager();
51
52     void init();
53     virtual void shutdown();
54     void postinit();
55     void reinit();
56     void bind();
57     void unbind();
58     void update(double dt);
59     void updateLOD(SGPropertyNode* node);
60     void attach(FGAIBase *model);
61
62     const FGAIBase *calcCollision(double alt, double lat, double lon, double fuse_range);
63
64     inline double get_user_heading() const { return user_heading; }
65     inline double get_user_pitch() const { return user_pitch; }
66     inline double get_user_speed() const {return user_speed; }
67     inline double get_wind_from_east() const {return wind_from_east; }
68     inline double get_wind_from_north() const {return wind_from_north; }
69     inline double get_user_roll() const { return user_roll; }
70     inline double get_user_agl() const { return user_altitude_agl; }
71
72     bool loadScenario( const std::string &filename );
73
74     static SGPropertyNode_ptr loadScenarioFile(const std::string& filename);
75
76     static bool getStartPosition(const std::string& id, const std::string& pid,
77         SGGeod& geodPos, double& hdng, SGVec3d& uvw);
78
79     FGAIBasePtr addObject(const SGPropertyNode* definition);
80     bool isVisible(const SGGeod& pos) const;
81     
82     /**
83      * @brief given a reference to an /ai/models/<foo>[n] node, return the
84      * corresponding AIObject implementation, or NULL.
85      */
86     FGAIBasePtr getObjectFromProperty(const SGPropertyNode* aProp) const;
87 private:
88     // FGSubmodelMgr is a friend for access to the AI_list
89     friend class FGSubmodelMgr;
90     
91     // A list of pointers to AI objects
92     typedef std::list <FGAIBasePtr> ai_list_type;
93     typedef ai_list_type::iterator ai_list_iterator;
94     typedef ai_list_type::const_iterator ai_list_const_iterator;
95     
96     const ai_list_type& get_ai_list() const {
97         return ai_list;
98     }
99
100     int getNumAiObjects() const;
101     
102     void removeDeadItem(FGAIBase* base);
103   
104     double calcRangeFt(const SGVec3d& aCartPos, FGAIBase* aObject) const;
105
106     bool loadScenarioCommand(const SGPropertyNode* args);
107     bool unloadScenarioCommand(const SGPropertyNode* args);
108     bool addObjectCommand(const SGPropertyNode* definition);
109     
110     bool removeObject(const SGPropertyNode* args);
111     bool unloadScenario( const std::string &filename );
112     void unloadAllScenarios();
113     
114     SGPropertyNode_ptr root;
115     SGPropertyNode_ptr enabled;
116     SGPropertyNode_ptr thermal_lift_node;
117     SGPropertyNode_ptr user_altitude_agl_node;
118     SGPropertyNode_ptr user_speed_node;
119     SGPropertyNode_ptr wind_from_east_node;
120     SGPropertyNode_ptr wind_from_north_node;
121     SGPropertyNode_ptr _environmentVisiblity;
122
123
124     ai_list_type ai_list;
125     
126     double user_altitude_agl;
127     double user_heading;
128     double user_pitch;
129     double user_roll;
130     double user_speed;
131     double wind_from_east;
132     double wind_from_north;
133
134     void fetchUserState( void );
135
136     // used by thermals
137     double range_nearest;
138     double strength;
139     void processThermal( double dt, FGAIThermal* thermal );
140
141     SGPropertyChangeCallback<FGAIManager> cb_ai_bare;
142     SGPropertyChangeCallback<FGAIManager> cb_ai_detailed;
143     
144     class Scenario;
145     typedef std::map<std::string, Scenario*> ScenarioDict;
146     ScenarioDict _scenarios;
147 };
148
149 #endif  // _FG_AIMANAGER_HXX