]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AITanker.cxx
de9adbb26052aaf22b30a67b54135503c74c6f92
[flightgear.git] / src / AIModel / AITanker.cxx
1 // AITanker.cxx  Based on David Culp's AIModel code\r
2 // - Tanker specific code isolated from AI Aircraft code\r
3 // by Thomas Foerster, started June 2007\r
4 //\r
5 // \r
6 // Original code written by David Culp, started October 2003.\r
7 // - davidculp2@comcast.net/\r
8 // This program is free software; you can redistribute it and/or\r
9 // modify it under the terms of the GNU General Public License as\r
10 // published by the Free Software Foundation; either version 2 of the\r
11 // License, or (at your option) any later version.\r
12 //\r
13 // This program is distributed in the hope that it will be useful, but\r
14 // WITHOUT ANY WARRANTY; without even the implied warranty of\r
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
16 // General Public License for more details.\r
17 //\r
18 // You should have received a copy of the GNU General Public License\r
19 // along with this program; if not, write to the Free Software\r
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\r
21 \r
22 #ifdef HAVE_CONFIG_H\r
23 #  include <config.h>\r
24 #endif\r
25 \r
26 #include "AITanker.hxx"\r
27 \r
28 FGAITanker::FGAITanker(FGAISchedule* ref): FGAIAircraft(ref){\r
29 }\r
30 \r
31 FGAITanker::~FGAITanker() {}\r
32 \r
33 void FGAITanker::readFromScenario(SGPropertyNode* scFileNode) {\r
34     if (!scFileNode)\r
35         return;\r
36 \r
37     FGAIAircraft::readFromScenario(scFileNode);\r
38     setTACANChannelID(scFileNode->getStringValue("TACAN-channel-ID",""));\r
39     setName(scFileNode->getStringValue("name", "Tanker"));
40 \r
41 }\r
42 \r
43 void FGAITanker::bind() {\r
44     FGAIAircraft::bind();\r
45 \r
46     props->tie("refuel/contact", SGRawValuePointer<bool>(&contact));\r
47     props->tie("position/altitude-agl-ft",SGRawValuePointer<double>(&altitude_agl_ft));\r
48     props->setStringValue("navaids/tacan/channel-ID", TACAN_channel_id.c_str());\r
49     props->setStringValue("name", _name.c_str());\r
50     props->setBoolValue("tanker", true);\r
51 }\r
52 \r
53 void FGAITanker::unbind() {\r
54     FGAIAircraft::unbind();\r
55     props->untie("refuel/contact");\r
56     props->untie("position/altitude-agl-ft");\r
57 \r
58 }\r
59 \r
60 void FGAITanker::setTACANChannelID(const string& id) {\r
61     TACAN_channel_id = id;\r
62 }\r
63 \r
64 void FGAITanker::Run(double dt) {\r
65     //FGAIAircraft::Run(dt);\r
66 \r
67     double start = pos.getElevationFt() + 1000;\r
68     altitude_agl_ft = _getAltitudeAGL(pos, start);\r
69 \r
70     //###########################//\r
71     // do calculations for radar //\r
72     //###########################//\r
73     double range_ft2 = UpdateRadar(manager);\r
74 \r
75     // check if radar contact\r
76     if ( (range_ft2 < 250.0 * 250.0) && (y_shift > 0.0)\r
77               && (elevation > 0.0) ) {\r
78         //refuel_node->setBoolValue(true);\r
79         contact = true;\r
80     } else {\r
81         //refuel_node->setBoolValue(false);\r
82         contact = false;\r
83     }\r
84 }\r
85 \r
86 \r
87 void FGAITanker::update(double dt) {\r
88      FGAIAircraft::update(dt);\r
89      Run(dt);\r
90      Transform();\r
91 }\r