]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AICarrier.hxx
Merge branch 'maint2' into next
[flightgear.git] / src / AIModel / AICarrier.hxx
1 // FGAICarrier - AIShip-derived class creates an AI aircraft carrier
2 //
3 // Written by David Culp, started October 2004.
4 //
5 // Copyright (C) 2004  David P. Culp - davidculp2@comcast.net
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
21 #ifndef _FG_AICARRIER_HXX
22 #define _FG_AICARRIER_HXX
23
24 #include <string>
25 #include <list>
26
27 #include <osg/Referenced>
28 #include <osg/Node>
29
30 #include <simgear/compiler.h>
31
32 using std::string;
33 using std::list;
34
35 #include "AIShip.hxx"
36
37 #include "AIManager.hxx"
38 #include "AIBase.hxx"
39
40 class FGAIManager;
41 class FGAICarrier;
42
43 class FGAICarrierHardware : public osg::Referenced {
44 public:
45
46     enum Type { Catapult, Wire, Solid };
47
48     FGAICarrier *carrier;
49     int id;
50     Type type;
51
52     static FGAICarrierHardware* newCatapult(FGAICarrier *c) {
53         FGAICarrierHardware* ch = new FGAICarrierHardware;
54         ch->carrier = c;
55         ch->type = Catapult;
56         ch->id = unique_id++;
57         return ch;
58     }
59     static FGAICarrierHardware* newWire(FGAICarrier *c) {
60         FGAICarrierHardware* ch = new FGAICarrierHardware;
61         ch->carrier = c;
62         ch->type = Wire;
63         ch->id = unique_id++;
64         return ch;
65     }
66     static FGAICarrierHardware* newSolid(FGAICarrier *c) {
67         FGAICarrierHardware* ch = new FGAICarrierHardware;
68         ch->carrier = c;
69         ch->type = Solid;
70         ch->id = unique_id++;
71         return ch;
72     }
73
74 private:
75     static int unique_id;
76 };
77
78
79 class FGAICarrier  : public FGAIShip {
80 public:
81
82     FGAICarrier();
83     virtual ~FGAICarrier();
84
85     virtual void readFromScenario(SGPropertyNode* scFileNode);
86
87     void setSign(const string& );
88     void setTACANChannelID(const string &);
89
90     void getVelocityWrtEarth(SGVec3d& v, SGVec3d& omega, SGVec3d& pivot);
91     virtual void bind();
92     virtual void unbind();
93     void UpdateWind ( double dt );
94     void setWind_from_east( double fps );
95     void setWind_from_north( double fps );
96     void setMaxLat( double deg );
97     void setMinLat( double deg );
98     void setMaxLong( double deg );
99     void setMinLong( double deg );
100     void TurnToLaunch();
101     void TurnToBase();
102     void ReturnToBox();
103     bool OutsideBox();
104
105     bool init(bool search_in_AI_path=false);
106     void initModel(osg::Node *node);
107
108     virtual const char* getTypeString(void) const { return "carrier"; }
109
110     bool getParkPosition(const string& id, SGGeod& geodPos,
111                          double& hdng, SGVec3d& uvw);
112
113 private:
114   /// Is sufficient to be private, stores a possible position to place an
115   /// aircraft on start
116   struct ParkPosition {
117     ParkPosition(const ParkPosition& pp)
118       : name(pp.name), offset(pp.offset), heading_deg(pp.heading_deg)
119     {}
120     ParkPosition(const string& n, const SGVec3d& off = SGVec3d(), double heading = 0)
121       : name(n), offset(off), heading_deg(heading)
122     {}
123     string name;
124     SGVec3d offset;
125     double heading_deg;
126   };
127
128
129     void update(double dt);
130     double wind_from_east;  // fps
131     double wind_from_north; // fps
132     double rel_wind_speed_kts;
133     double rel_wind_from_deg;
134
135
136     list<string> solid_objects;       // List of solid object names
137     list<string> wire_objects;        // List of wire object names
138     list<string> catapult_objects;    // List of catapult object names
139     list<ParkPosition> ppositions;    // List of positions where an aircraft can start.
140     string sign;                      // The sign of this carrier.
141
142     // Velocity wrt earth.
143     SGVec3d vel_wrt_earth;
144     SGVec3d rot_wrt_earth;
145     SGVec3d rot_pivot_wrt_earth;
146
147     // these describe the flols
148     SGVec3d flols_off;
149
150     double dist;            // the distance of the eyepoint from the flols
151     double angle;
152     int source;             // the flols light which is visible at the moment
153     bool wave_off_lights;
154
155     // these are for maneuvering the carrier
156     SGGeod mOpBoxPos;
157
158     double wind_speed_from_north_kts ;
159     double wind_speed_from_east_kts  ;
160     double wind_speed_kts;  //true wind speed
161     double wind_from_deg;   //true wind direction
162     double rel_wind;
163     double max_lat, min_lat, max_long, min_long;
164     double base_course, base_speed;
165
166     bool turn_to_launch_hdg;
167     bool returning;      // set if the carrier is returning to an operating box
168     bool InToWind();     // set if the carrier is in to wind
169
170
171     SGPropertyNode_ptr _longitude_node;
172     SGPropertyNode_ptr _latitude_node;
173     SGPropertyNode_ptr _altitude_node;
174     SGPropertyNode_ptr _surface_wind_from_deg_node;
175     SGPropertyNode_ptr _surface_wind_speed_node;
176     SGPropertyNode_ptr _launchbar_state_node;
177     // this is for tacan
178
179     string TACAN_channel_id;
180
181     // these are for moving the elevators
182     void UpdateElevator( double dt, double transition_time);
183     double pos_norm, raw_pos_norm;
184     double transition_time, time_constant;
185     bool elevators;
186
187     // these are for moving the jet blast deflectors
188     void UpdateJBD( double dt, double jbd_transition_time);
189     double jbd_pos_norm, raw_jbd_pos_norm;
190     double jbd_transition_time, jbd_time_constant;
191     bool jbd;
192 };
193
194 #endif  // _FG_AICARRIER_HXX