]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIManager.hxx
Mathias Froehlich:
[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., 675 Mass Ave, Cambridge, MA 02139, USA.
22
23 #ifndef _FG_AIMANAGER_HXX
24 #define _FG_AIMANAGER_HXX
25
26 #include <list>
27
28 #include <simgear/structure/subsystem_mgr.hxx>
29 #include <simgear/structure/ssgSharedPtr.hxx>
30 #include <simgear/structure/SGSharedPtr.hxx>
31
32 #include <Main/fg_props.hxx>
33
34 #include <AIModel/AIBase.hxx>
35 #include <AIModel/AIFlightPlan.hxx>
36
37 #include <Traffic/SchedFlight.hxx>
38 #include <Traffic/Schedule.hxx>
39
40 SG_USING_STD(list);
41 SG_USING_STD(vector);
42
43 class FGModelID
44 {
45 private:
46   ssgSharedPtr<ssgBranch> model;
47   string path;
48 public:
49   FGModelID(const string& pth, ssgBranch * mdl) { path =pth; model=mdl;};
50   ssgBranch * const getModelId() const { return model;};
51   const string & getPath() const { return path;};
52 };
53
54 typedef vector<FGModelID> ModelVec;
55 typedef vector<FGModelID>::const_iterator ModelVecIterator;
56
57 class FGAIThermal;
58
59
60 class FGAIManager : public SGSubsystem
61 {
62
63 private:
64
65     // A list of pointers to AI objects
66     typedef list <SGSharedPtr<FGAIBase> > ai_list_type;
67     typedef ai_list_type::iterator ai_list_iterator;
68     typedef ai_list_type::const_iterator ai_list_const_iterator;
69
70     ai_list_type ai_list;
71   ModelVec loadedModels;
72
73 public:
74
75     FGAIManager();
76     ~FGAIManager();
77
78     void init();
79     void reinit();
80     void bind();
81     void unbind();
82     void update(double dt);
83
84     void attach(SGSharedPtr<FGAIBase> model);
85
86     void destroyObject( int ID );
87
88     inline double get_user_latitude() const { return user_latitude; }
89     inline double get_user_longitude() const { return user_longitude; }
90     inline double get_user_altitude() const { return user_altitude; }
91     inline double get_user_heading() const { return user_heading; }
92     inline double get_user_pitch() const { return user_pitch; }
93     inline double get_user_yaw() const { return user_yaw; }
94     inline double get_user_speed() const {return user_speed; }
95     inline double get_wind_from_east() const {return wind_from_east; }
96     inline double get_wind_from_north() const {return wind_from_north; }
97
98     inline int getNum( FGAIBase::object_type ot ) const {
99       return (0 < ot && ot < FGAIBase::MAX_OBJECTS) ? numObjects[ot] : numObjects[0];
100     }
101
102     void processScenario( const string &filename );
103
104   ssgBranch * getModel(const string& path) const;
105   void setModel(const string& path, ssgBranch *model);
106
107   static SGPropertyNode_ptr loadScenarioFile(const std::string& filename);
108
109   static bool getStartPosition(const string& id, const string& pid,
110                                Point3D& geodPos, double& hdng, sgdVec3 uvw);
111
112 private:
113
114     bool enabled;
115     int numObjects[FGAIBase::MAX_OBJECTS];
116     SGPropertyNode* root;
117     SGPropertyNode* wind_from_down_node;
118     SGPropertyNode* user_latitude_node;
119     SGPropertyNode* user_longitude_node;
120     SGPropertyNode* user_altitude_node;
121     SGPropertyNode* user_heading_node;
122     SGPropertyNode* user_pitch_node;
123     SGPropertyNode* user_yaw_node;
124     SGPropertyNode* user_speed_node;
125     SGPropertyNode* wind_from_east_node ;
126     SGPropertyNode* wind_from_north_node ;
127
128     string scenario_filename;
129
130     double user_latitude;
131     double user_longitude;
132     double user_altitude;
133     double user_heading;
134     double user_pitch;
135     double user_yaw;
136     double user_speed;
137     double wind_from_east;
138     double wind_from_north;
139     double _dt;
140     void fetchUserState( void );
141
142     // used by thermals
143     double range_nearest;
144     double strength;
145     void processThermal( FGAIThermal* thermal ); 
146
147 };
148
149 #endif  // _FG_AIMANAGER_HXX