]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIManager.hxx
Fix stray back-button in Qt launcher
[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
32 class FGAIBase;
33 class FGAIThermal;
34
35 typedef SGSharedPtr<FGAIBase> FGAIBasePtr;
36
37 class FGAIManager : public SGSubsystem
38 {
39
40 public:
41     FGAIManager();
42     virtual ~FGAIManager();
43
44     void init();
45     virtual void shutdown();
46     void postinit();
47     void reinit();
48     void bind();
49     void unbind();
50     void update(double dt);
51     void updateLOD(SGPropertyNode* node);
52     void attach(FGAIBase *model);
53
54     const FGAIBase *calcCollision(double alt, double lat, double lon, double fuse_range);
55
56     inline double get_user_heading() const { return user_heading; }
57     inline double get_user_pitch() const { return user_pitch; }
58     inline double get_user_speed() const {return user_speed; }
59     inline double get_wind_from_east() const {return wind_from_east; }
60     inline double get_wind_from_north() const {return wind_from_north; }
61     inline double get_user_roll() const { return user_roll; }
62     inline double get_user_agl() const { return user_altitude_agl; }
63
64     bool loadScenario( const std::string &filename );
65
66     static SGPropertyNode_ptr loadScenarioFile(const std::string& filename);
67
68     static bool getStartPosition(const std::string& id, const std::string& pid,
69         SGGeod& geodPos, double& hdng, SGVec3d& uvw);
70
71     FGAIBasePtr addObject(const SGPropertyNode* definition);
72     bool isVisible(const SGGeod& pos) const;
73     
74     /**
75      * @brief given a reference to an /ai/models/<foo>[n] node, return the
76      * corresponding AIObject implementation, or NULL.
77      */
78     FGAIBasePtr getObjectFromProperty(const SGPropertyNode* aProp) const;
79
80     static const char* subsystemName() { return "ai-model"; }
81 private:
82     // FGSubmodelMgr is a friend for access to the AI_list
83     friend class FGSubmodelMgr;
84     
85     // A list of pointers to AI objects
86     typedef std::list <FGAIBasePtr> ai_list_type;
87     typedef ai_list_type::iterator ai_list_iterator;
88     typedef ai_list_type::const_iterator ai_list_const_iterator;
89     
90     const ai_list_type& get_ai_list() const {
91         return ai_list;
92     }
93
94     int getNumAiObjects() const;
95     
96     void removeDeadItem(FGAIBase* base);
97   
98     double calcRangeFt(const SGVec3d& aCartPos, FGAIBase* aObject) const;
99
100     bool loadScenarioCommand(const SGPropertyNode* args);
101     bool unloadScenarioCommand(const SGPropertyNode* args);
102     bool addObjectCommand(const SGPropertyNode* definition);
103     
104     bool removeObject(const SGPropertyNode* args);
105     bool unloadScenario( const std::string &filename );
106     void unloadAllScenarios();
107     
108     SGPropertyNode_ptr root;
109     SGPropertyNode_ptr enabled;
110     SGPropertyNode_ptr thermal_lift_node;
111     SGPropertyNode_ptr user_altitude_agl_node;
112     SGPropertyNode_ptr user_speed_node;
113     SGPropertyNode_ptr wind_from_east_node;
114     SGPropertyNode_ptr wind_from_north_node;
115     SGPropertyNode_ptr _environmentVisiblity;
116
117
118     ai_list_type ai_list;
119     
120     double user_altitude_agl;
121     double user_heading;
122     double user_pitch;
123     double user_roll;
124     double user_speed;
125     double wind_from_east;
126     double wind_from_north;
127
128     void fetchUserState( void );
129
130     // used by thermals
131     double range_nearest;
132     double strength;
133     void processThermal( double dt, FGAIThermal* thermal );
134
135     SGPropertyChangeCallback<FGAIManager> cb_ai_bare;
136     SGPropertyChangeCallback<FGAIManager> cb_ai_detailed;
137     
138     class Scenario;
139     typedef std::map<std::string, Scenario*> ScenarioDict;
140     ScenarioDict _scenarios;
141 };
142
143 #endif  // _FG_AIMANAGER_HXX