]> git.mxchange.org Git - flightgear.git/blob - src/Airports/groundnetwork.hxx
Initial checkin.
[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
29
30 #include STL_STRING
31 #include <vector>
32
33 SG_USING_STD(string);
34 SG_USING_STD(vector);
35
36
37 #include "parking.hxx"
38 #include "trafficcontrol.hxx"
39
40
41
42 class FGTaxiSegment; // forward reference
43 class FGAIFlightPlan; // forward reference
44
45 typedef vector<FGTaxiSegment*>  FGTaxiSegmentVector;
46 typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentVectorIterator;
47
48 //typedef vector<FGTaxiSegment*> FGTaxiSegmentPointerVector;
49 //typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentPointerVectorIterator;
50
51 /**************************************************************************************
52  * class FGTaxiNode
53  *************************************************************************************/
54 class FGTaxiNode 
55 {
56 private:
57   double lat;
58   double lon;
59   int index;
60   FGTaxiSegmentVector next; // a vector of pointers to all the segments leaving from this node
61   
62 public:
63   FGTaxiNode();
64   FGTaxiNode(double, double, int);
65
66   void setIndex(int idx)                  { index = idx;};
67   void setLatitude (double val)           { lat = val;};
68   void setLongitude(double val)           { lon = val;};
69   void setLatitude (const string& val)           { lat = processPosition(val);  };
70   void setLongitude(const string& val)           { lon = processPosition(val);  };
71   void addSegment(FGTaxiSegment *segment) { next.push_back(segment); };
72   
73   double getLatitude() { return lat;};
74   double getLongitude(){ return lon;};
75
76   int getIndex() { return index; };
77   FGTaxiNode *getAddress() { return this;};
78   FGTaxiSegmentVectorIterator getBeginRoute() { return next.begin(); };
79   FGTaxiSegmentVectorIterator getEndRoute()   { return next.end();   }; 
80   bool operator<(const FGTaxiNode &other) const { return index < other.index; };
81 };
82
83 typedef vector<FGTaxiNode*> FGTaxiNodeVector;
84 typedef vector<FGTaxiNode*>::iterator FGTaxiNodeVectorIterator;
85
86 /***************************************************************************************
87  * class FGTaxiSegment
88  **************************************************************************************/
89 class FGTaxiSegment
90 {
91 private:
92   int startNode;
93   int endNode;
94   double length;
95   FGTaxiNode *start;
96   FGTaxiNode *end;
97   int index;
98   FGTaxiSegment *oppositeDirection;
99
100 public:
101   FGTaxiSegment();
102   //FGTaxiSegment(FGTaxiNode *, FGTaxiNode *, int);
103
104   void setIndex        (int val) { index     = val; };
105   void setStartNodeRef (int val) { startNode = val; };
106   void setEndNodeRef   (int val) { endNode   = val; };
107
108   void setOpposite(FGTaxiSegment *opp) { oppositeDirection = opp; };
109
110   void setStart(FGTaxiNodeVector *nodes);
111   void setEnd  (FGTaxiNodeVector *nodes);
112   void setTrackDistance();
113
114   FGTaxiNode * getEnd() { return end;};
115   FGTaxiNode * getStart() { return start; };
116   double getLength() { return length; };
117   int getIndex() { return index; };
118
119  FGTaxiSegment *getAddress() { return this;};
120
121   bool operator<(const FGTaxiSegment &other) const { return index < other.index; };
122   FGTaxiSegment *opposite() { return oppositeDirection; };
123
124   
125 };
126
127
128 typedef vector<int> intVec;
129 typedef vector<int>::iterator intVecIterator;
130
131 /***************************************************************************************
132  * class FGTaxiRoute
133  **************************************************************************************/
134 class FGTaxiRoute
135 {
136 private:
137   intVec nodes;
138   intVec routes;
139   double distance;
140   intVecIterator currNode;
141   intVecIterator currRoute;
142
143 public:
144   FGTaxiRoute() { distance = 0; currNode = nodes.begin(); currRoute = routes.begin();};
145   FGTaxiRoute(intVec nds, intVec rts, double dist) { 
146     nodes = nds; 
147     routes = rts;
148     distance = dist; 
149     currNode = nodes.begin();
150   };
151   bool operator< (const FGTaxiRoute &other) const {return distance < other.distance; };
152   bool empty () { return nodes.begin() == nodes.end(); };
153   bool next(int *nde); 
154   bool next(int *nde, int *rte);
155   void rewind(int legNr);
156   
157   void first() { currNode = nodes.begin(); currRoute = routes.begin(); };
158   int size() { return nodes.size(); };
159 };
160
161 typedef vector<FGTaxiRoute> TaxiRouteVector;
162 typedef vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
163
164
165
166
167 /**************************************************************************************
168  * class FGGroundNetWork
169  *************************************************************************************/
170 class FGGroundNetwork : public FGATCController
171 {
172 private:
173   bool hasNetwork;
174   FGTaxiNodeVector    nodes;
175   FGTaxiSegmentVector segments;
176   //intVec route;
177   intVec nodesStack;
178   intVec routesStack;
179   TaxiRouteVector routes;
180   TrafficVector activeTraffic;
181   TrafficVectorIterator currTraffic;
182   
183   bool foundRoute;
184   double totalDistance, maxDistance;
185   FGTowerController *towerController;
186
187   void printRoutingError(string);
188
189   void checkSpeedAdjustment(int id, double lat, double lon, 
190                             double heading, double speed, double alt);
191   void checkHoldPosition(int id, double lat, double lon, 
192                          double heading, double speed, double alt);
193   
194 public:
195   FGGroundNetwork();
196   ~FGGroundNetwork();
197
198   void addNode   (const FGTaxiNode& node);
199   void addNodes  (FGParkingVec *parkings);
200   void addSegment(const FGTaxiSegment& seg); 
201
202   void init();
203   bool exists() { return hasNetwork; };
204   void setTowerController(FGTowerController *twrCtrlr) { towerController = twrCtrlr; };
205   int findNearestNode(double lat, double lon);
206   FGTaxiNode *findNode(int idx);
207   FGTaxiSegment *findSegment(int idx);
208   FGTaxiRoute findShortestRoute(int start, int end);
209   void trace(FGTaxiNode *, int, int, double dist);
210
211   virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute, 
212                                 double lat, double lon, double hdg, double spd, double alt, double radius, int leg);
213   virtual void signOff(int id);
214   virtual void update(int id, double lat, double lon, double heading, double speed, double alt, double dt);
215   virtual bool hasInstruction(int id);
216   virtual FGATCInstruction getInstruction(int id);
217 };
218
219
220 #endif