]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIManager.hxx
Commands to control scenarios / AI-objects.
[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
50     // A list of pointers to AI objects
51     typedef std::list <FGAIBasePtr> ai_list_type;
52     typedef ai_list_type::iterator ai_list_iterator;
53     typedef ai_list_type::const_iterator ai_list_const_iterator;
54
55     const ai_list_type& get_ai_list() const {
56         return ai_list;
57     }
58
59     FGAIManager();
60     virtual ~FGAIManager();
61
62     void init();
63     void postinit();
64     void reinit();
65     void bind();
66     void unbind();
67     void update(double dt);
68     void updateLOD(SGPropertyNode* node);
69     void attach(FGAIBase *model);
70
71     const FGAIBase *calcCollision(double alt, double lat, double lon, double fuse_range);
72
73     inline double get_user_heading() const { return user_heading; }
74     inline double get_user_pitch() const { return user_pitch; }
75     inline double get_user_yaw() const { return user_yaw; }
76     inline double get_user_speed() const {return user_speed; }
77     inline double get_wind_from_east() const {return wind_from_east; }
78     inline double get_wind_from_north() const {return wind_from_north; }
79     inline double get_user_roll() const { return user_roll; }
80     inline double get_user_agl() const { return user_altitude_agl; }
81
82     int getNumAiObjects(void) const;
83
84     bool loadScenario( const string &filename );
85
86     static SGPropertyNode_ptr loadScenarioFile(const std::string& filename);
87
88     static bool getStartPosition(const string& id, const string& pid,
89         SGGeod& geodPos, double& hdng, SGVec3d& uvw);
90
91     FGAIBasePtr addObject(const SGPropertyNode* definition);
92     
93 private:
94     void removeDeadItem(FGAIBase* base);
95   
96     double calcRange(const SGVec3d& aCartPos, FGAIBase* aObject) const;
97
98     bool loadScenarioCommand(const SGPropertyNode* args);
99     bool unloadScenarioCommand(const SGPropertyNode* args);
100     bool addObjectCommand(const SGPropertyNode* definition);
101     
102     bool removeObject(const SGPropertyNode* args);
103     void unloadScenario( const string &filename );
104     
105     SGPropertyNode_ptr root;
106     SGPropertyNode_ptr enabled;
107     SGPropertyNode_ptr thermal_lift_node;
108     SGPropertyNode_ptr user_altitude_agl_node;
109     SGPropertyNode_ptr user_yaw_node;
110     SGPropertyNode_ptr user_speed_node;
111     SGPropertyNode_ptr wind_from_east_node;
112     SGPropertyNode_ptr wind_from_north_node;
113
114
115     ai_list_type ai_list;
116     
117     double user_altitude_agl;
118     double user_heading;
119     double user_pitch;
120     double user_yaw;
121     double user_roll;
122     double user_speed;
123     double user_agl;
124     double wind_from_east;
125     double wind_from_north;
126
127     void fetchUserState( void );
128
129     // used by thermals
130     double range_nearest;
131     double strength;
132     void processThermal( double dt, FGAIThermal* thermal );
133
134     SGPropertyChangeCallback<FGAIManager> cb_ai_bare;
135     SGPropertyChangeCallback<FGAIManager> cb_ai_detailed;
136     
137     class Scenario;
138     typedef std::map<std::string, Scenario*> ScenarioDict;
139     ScenarioDict _scenarios;
140 };
141
142 #endif  // _FG_AIMANAGER_HXX