]> git.mxchange.org Git - flightgear.git/blob - src/ATC/AIPlane.cxx
Return landing type. Simple AIPlane always returns full stop for now - more advanced...
[flightgear.git] / src / ATC / AIPlane.cxx
1 // FGAIPlane - abstract base class for an AI plane
2 //
3 // Written by David Luff, started 2002.
4 //
5 // Copyright (C) 2002  David C. Luff - david.luff@nottingham.ac.uk
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., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 #include <Main/globals.hxx>
22 #include <Main/fg_props.hxx>
23 #include <simgear/math/point3d.hxx>
24 #include <simgear/debug/logstream.hxx>
25 #include <math.h>
26 #include <string>
27 SG_USING_STD(string);
28
29
30 #include "AIPlane.hxx"
31 #include "ATCdisplay.hxx"
32
33 FGAIPlane::FGAIPlane() {
34         leg = LEG_UNKNOWN;
35 }
36
37 FGAIPlane::~FGAIPlane() {
38 }
39
40 void FGAIPlane::Update(double dt) {
41 }
42
43 void FGAIPlane::Bank(double angle) {
44         // This *should* bank us smoothly to any angle
45         if(fabs(roll - angle) > 0.6) {
46                 roll -= ((roll - angle)/fabs(roll - angle));  
47         }
48 }
49
50 // Duplication of Bank(0.0) really - should I cut this?
51 void FGAIPlane::LevelWings(void) {
52         // bring the plane back to level smoothly (this should work to come out of either bank)
53         if(fabs(roll) > 0.6) {
54                 roll -= (roll/fabs(roll));
55         }
56 }
57
58 void FGAIPlane::Transmit(string msg) {
59         SG_LOG(SG_ATC, SG_INFO, "Transmit called, msg = " << msg);
60         double user_freq0 = fgGetDouble("/radios/comm[0]/frequencies/selected-mhz");
61         //double user_freq0 = ("/radios/comm[0]/frequencies/selected-mhz");
62         //comm1 is not used yet.
63         
64         if(freq == user_freq0) {
65                 //cout << "Transmitting..." << endl;
66                 // we are on the same frequency, so check distance to the user plane
67                 if(1) {
68                         // For now (testing) assume in range !!!
69                         // TODO - implement range checking
70                         globals->get_ATC_display()->RegisterSingleMessage(msg, 0);
71                 }
72         }
73 }
74
75 void FGAIPlane::RegisterTransmission(int code) {
76 }
77
78
79 // Return what type of landing we're doing on this circuit
80 LandingType FGAIPlane::GetLandingOption() {
81         return(FULL_STOP);
82 }
83
84
85 ostream& operator << (ostream& os, PatternLeg pl) {
86         switch(pl) {
87         case(TAKEOFF_ROLL):   return(os << "TAKEOFF ROLL");
88         case(CLIMBOUT):       return(os << "CLIMBOUT");
89         case(TURN1):          return(os << "TURN1");
90         case(CROSSWIND):      return(os << "CROSSWIND");
91         case(TURN2):          return(os << "TURN2");
92         case(DOWNWIND):       return(os << "DOWNWIND");
93         case(TURN3):          return(os << "TURN3");
94         case(BASE):           return(os << "BASE");
95         case(TURN4):          return(os << "TURN4");
96         case(FINAL):          return(os << "FINAL");
97         case(LANDING_ROLL):   return(os << "LANDING ROLL");
98         case(LEG_UNKNOWN):    return(os << "UNKNOWN");
99         }
100         return(os << "ERROR - Unknown switch in PatternLeg operator << ");
101 }
102
103
104 ostream& operator << (ostream& os, LandingType lt) {
105         switch(lt) {
106         case(FULL_STOP):      return(os << "FULL STOP");
107         case(STOP_AND_GO):    return(os << "STOP AND GO");
108         case(TOUCH_AND_GO):   return(os << "TOUCH AND GO");
109         case(AIP_LT_UNKNOWN): return(os << "UNKNOWN");
110         }
111         return(os << "ERROR - Unknown switch in LandingType operator << ");
112 }
113