]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIManager.hxx
1eb1bf179edff8a8835515659aaf30320f7d0aae
[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
30 #include <Main/fg_props.hxx>
31
32 #include <AIModel/AIBase.hxx>
33 #include <AIModel/AIScenario.hxx>
34 #include <AIModel/AIFlightPlan.hxx>
35
36 #include <Traffic/SchedFlight.hxx>
37 #include <Traffic/Schedule.hxx>
38
39 SG_USING_STD(list);
40 SG_USING_STD(vector);
41
42 class FGModelID
43 {
44 private:
45   ssgBranch * model;
46   string path;
47 public:
48   FGModelID(const string& pth, ssgBranch * mdl) { path =pth; model=mdl;};
49   ssgBranch *getModelId() { return model;};
50   const string & getPath() { return path;};
51 };
52
53 typedef vector<FGModelID> ModelVec;
54 typedef vector<FGModelID>::iterator ModelVecIterator;
55
56 class FGAIThermal;
57
58
59 class FGAIManager : public SGSubsystem
60 {
61
62 private:
63
64     // A list of pointers to AI objects
65     typedef list <FGAIBase*> ai_list_type;
66     typedef ai_list_type::iterator ai_list_iterator;
67     typedef ai_list_type::const_iterator ai_list_const_iterator;
68
69     // Everything put in this list should be created dynamically
70     // on the heap and ***DELETED WHEN REMOVED!!!!!***
71     ai_list_type ai_list;
72   ModelVec loadedModels;
73
74 public:
75
76     FGAIManager();
77     ~FGAIManager();
78
79     void init();
80     void bind();
81     void unbind();
82     void update(double dt);
83
84     void* createBallistic( FGAIModelEntity *entity );
85     void* createAircraft( FGAIModelEntity *entity,   FGAISchedule *ref=0 );
86     void* createThermal( FGAIModelEntity *entity );
87     void* createStorm( FGAIModelEntity *entity );
88     void* createShip( FGAIModelEntity *entity );
89     void* createCarrier( FGAIModelEntity *entity );
90     void* createStatic( FGAIModelEntity *entity );
91
92     void destroyObject( void* ID );
93
94     inline double get_user_latitude() { return user_latitude; }
95     inline double get_user_longitude() { return user_longitude; }
96     inline double get_user_altitude() { return user_altitude; }
97     inline double get_user_heading() { return user_heading; }
98     inline double get_user_pitch() { return user_pitch; }
99     inline double get_user_yaw() { return user_yaw; }
100     inline double get_user_speed() {return user_speed; }
101
102     inline int getNum( FGAIBase::object_type ot ) {
103       return (0 < ot && ot < FGAIBase::MAX_OBJECTS) ? numObjects[ot] : numObjects[0];
104     }
105
106     void processScenario( const string &filename );
107
108   ssgBranch * getModel(const string& path);
109   void setModel(const string& path, ssgBranch *model);
110
111   static bool getStartPosition(const string& id, const string& pid,
112                                Point3D& geodPos, double& hdng, sgdVec3 uvw);
113
114 private:
115
116     bool initDone;
117     bool enabled;
118     int numObjects[FGAIBase::MAX_OBJECTS];
119     SGPropertyNode* root;
120     SGPropertyNode* wind_from_down_node;
121     SGPropertyNode* user_latitude_node;
122     SGPropertyNode* user_longitude_node;
123     SGPropertyNode* user_altitude_node;
124     SGPropertyNode* user_heading_node;
125     SGPropertyNode* user_pitch_node;
126     SGPropertyNode* user_yaw_node;
127     SGPropertyNode* user_speed_node;
128
129     string scenario_filename;
130
131     double user_latitude;
132     double user_longitude;
133     double user_altitude;
134     double user_heading;
135     double user_pitch;
136     double user_yaw;
137     double user_speed;
138     double _dt;
139     int dt_count;
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