]> git.mxchange.org Git - flightgear.git/blob - src/Airports/groundnetwork.hxx
Fix for refueling and radar calculations.
[flightgear.git] / src / Airports / groundnetwork.hxx
1 // groundnet.hxx - A number of classes to handle taxiway
2 // assignments by the AI code
3 //
4 // Written by Durk Talsma, started June 2005.
5 //
6 // Copyright (C) 2004 Durk Talsma.
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 //
22 // $Id$
23
24 #ifndef _GROUNDNETWORK_HXX_
25 #define _GROUNDNETWORK_HXX_
26
27 #include <simgear/compiler.h>
28 #include <simgear/route/waypoint.hxx>
29
30
31 #include STL_STRING
32 #include <vector>
33
34 SG_USING_STD(string);
35 SG_USING_STD(vector);
36
37 #include "parking.hxx"
38 #include "trafficcontrol.hxx"
39
40
41
42 class FGTaxiSegment; // forward reference
43 class FGAIFlightPlan; // forward reference
44 class FGAirport;      // forward reference
45
46 typedef vector<FGTaxiSegment*>  FGTaxiSegmentVector;
47 typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentVectorIterator;
48
49 //typedef vector<FGTaxiSegment*> FGTaxiSegmentPointerVector;
50 //typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentPointerVectorIterator;
51
52 /**************************************************************************************
53  * class FGTaxiNode
54  *************************************************************************************/
55 class FGTaxiNode 
56 {
57 private:
58   double lat;
59   double lon;
60   int index;
61   FGTaxiSegmentVector next; // a vector of pointers to all the segments leaving from this node
62   
63 public:
64   FGTaxiNode();
65   FGTaxiNode(double, double, int);
66
67   void setIndex(int idx)                  { index = idx;};
68   void setLatitude (double val)           { lat = val;};
69   void setLongitude(double val)           { lon = val;};
70   void setLatitude (const string& val)           { lat = processPosition(val);  };
71   void setLongitude(const string& val)           { lon = processPosition(val);  };
72   void addSegment(FGTaxiSegment *segment) { next.push_back(segment); };
73   
74   double getLatitude() { return lat;};
75   double getLongitude(){ return lon;};
76
77   int getIndex() { return index; };
78   FGTaxiNode *getAddress() { return this;};
79   FGTaxiSegmentVectorIterator getBeginRoute() { return next.begin(); };
80   FGTaxiSegmentVectorIterator getEndRoute()   { return next.end();   }; 
81   bool operator<(const FGTaxiNode &other) const { return index < other.index; };
82
83   void sortEndSegments(bool);
84 };
85
86 typedef vector<FGTaxiNode*> FGTaxiNodeVector;
87 typedef vector<FGTaxiNode*>::iterator FGTaxiNodeVectorIterator;
88
89 /***************************************************************************************
90  * class FGTaxiSegment
91  **************************************************************************************/
92 class FGTaxiSegment
93 {
94 private:
95   int startNode;
96   int endNode;
97   double length;
98   double course;
99   double headingDiff;
100   bool isActive;
101   FGTaxiNode *start;
102   FGTaxiNode *end;
103   int index;
104   FGTaxiSegment *oppositeDirection;
105
106  
107
108 public:
109   FGTaxiSegment();
110   //FGTaxiSegment(FGTaxiNode *, FGTaxiNode *, int);
111
112   void setIndex        (int val) { index     = val; };
113   void setStartNodeRef (int val) { startNode = val; };
114   void setEndNodeRef   (int val) { endNode   = val; };
115
116   void setOpposite(FGTaxiSegment *opp) { oppositeDirection = opp; };
117
118   void setStart(FGTaxiNodeVector *nodes);
119   void setEnd  (FGTaxiNodeVector *nodes);
120   void setTrackDistance();
121
122   FGTaxiNode * getEnd() { return end;};
123   FGTaxiNode * getStart() { return start; };
124   double getLength() { return length; };
125   int getIndex() { return index; };
126
127  FGTaxiSegment *getAddress() { return this;};
128
129   bool operator<(const FGTaxiSegment &other) const { return index < other.index; };
130   bool hasSmallerHeadingDiff (const FGTaxiSegment &other) const { return headingDiff < other.headingDiff; };
131   FGTaxiSegment *opposite() { return oppositeDirection; };
132   void setCourseDiff(double crse);
133
134
135   
136 };
137
138
139
140
141 typedef vector<int> intVec;
142 typedef vector<int>::iterator intVecIterator;
143
144
145
146 /***************************************************************************************
147  * class FGTaxiRoute
148  **************************************************************************************/
149 class FGTaxiRoute
150 {
151 private:
152   intVec nodes;
153   intVec routes;
154   double distance;
155   int depth;
156   intVecIterator currNode;
157   intVecIterator currRoute;
158
159 public:
160   FGTaxiRoute() { distance = 0; currNode = nodes.begin(); currRoute = routes.begin();};
161   FGTaxiRoute(intVec nds, intVec rts, double dist, int dpth) { 
162     nodes = nds; 
163     routes = rts;
164     distance = dist; 
165     currNode = nodes.begin();
166     depth = dpth;
167   };
168   bool operator< (const FGTaxiRoute &other) const {return distance < other.distance; };
169   bool empty () { return nodes.begin() == nodes.end(); };
170   bool next(int *nde); 
171   bool next(int *nde, int *rte);
172   void rewind(int legNr);
173   
174   void first() { currNode = nodes.begin(); currRoute = routes.begin(); };
175   int size() { return nodes.size(); };
176   int getDepth() { return depth; };
177 };
178
179 typedef vector<FGTaxiRoute> TaxiRouteVector;
180 typedef vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
181
182 bool sortByHeadingDiff(FGTaxiSegment *a, FGTaxiSegment *b);
183 bool sortByLength     (FGTaxiSegment *a, FGTaxiSegment *b);
184
185
186 /**************************************************************************************
187  * class FGGroundNetWork
188  *************************************************************************************/
189 class FGGroundNetwork : public FGATCController
190 {
191 private:
192   bool hasNetwork;
193   int maxDepth;
194   int count;
195   FGTaxiNodeVector    nodes;
196   FGTaxiSegmentVector segments;
197   //intVec route;
198   intVec nodesStack;
199   intVec routesStack;
200   TaxiRouteVector routes;
201   TrafficVector activeTraffic;
202   TrafficVectorIterator currTraffic;
203   SGWayPoint destination;
204   
205   bool foundRoute;
206   double totalDistance, maxDistance;
207   FGTowerController *towerController;
208   FGAirport *parent;
209   
210
211   void printRoutingError(string);
212
213   void checkSpeedAdjustment(int id, double lat, double lon, 
214                             double heading, double speed, double alt);
215   void checkHoldPosition(int id, double lat, double lon, 
216                          double heading, double speed, double alt);
217   
218 public:
219   FGGroundNetwork();
220   ~FGGroundNetwork();
221
222   void addNode   (const FGTaxiNode& node);
223   void addNodes  (FGParkingVec *parkings);
224   void addSegment(const FGTaxiSegment& seg); 
225
226   void init();
227   bool exists() { return hasNetwork; };
228   void setTowerController(FGTowerController *twrCtrlr) { towerController = twrCtrlr; };
229   int findNearestNode(double lat, double lon);
230   FGTaxiNode *findNode(int idx);
231   FGTaxiSegment *findSegment(int idx);
232   FGTaxiRoute findShortestRoute(int start, int end);
233   void trace(FGTaxiNode *, int, int, double dist);
234
235   void setParent(FGAirport *par) { parent = par; };
236
237   virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute, 
238                                 double lat, double lon, double hdg, double spd, double alt, 
239                                 double radius, int leg, string callsign);
240   virtual void signOff(int id);
241   virtual void update(int id, double lat, double lon, double heading, double speed, double alt, double dt);
242   virtual bool hasInstruction(int id);
243   virtual FGATCInstruction getInstruction(int id);
244 };
245
246
247 #endif