]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AITanker.cxx
std:: namespace fixes, AIBase cleanup.
[flightgear.git] / src / AIModel / AITanker.cxx
1 // AITanker.cxx  Based on David Culp's AIModel code
2 // - Tanker specific code isolated from AI Aircraft code
3 // by Thomas Foerster, started June 2007
4 //
5 // 
6 // Original code written by David Culp, started October 2003.
7 // - davidculp2@comcast.net/
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 #ifdef HAVE_CONFIG_H
23 #  include <config.h>
24 #endif
25
26 #include "AITanker.hxx"
27
28 using std::string;
29
30 FGAITanker::FGAITanker(FGAISchedule* ref): FGAIAircraft(ref){
31 }
32
33 FGAITanker::~FGAITanker() {}
34
35 void FGAITanker::readFromScenario(SGPropertyNode* scFileNode) {
36     if (!scFileNode)
37         return;
38
39     FGAIAircraft::readFromScenario(scFileNode);
40     setTACANChannelID(scFileNode->getStringValue("TACAN-channel-ID",""));
41     setName(scFileNode->getStringValue("name", "Tanker"));
42
43 }
44
45 void FGAITanker::bind() {
46     FGAIAircraft::bind();
47
48     tie("refuel/contact", SGRawValuePointer<bool>(&contact));
49     tie("position/altitude-agl-ft",SGRawValuePointer<double>(&altitude_agl_ft));
50
51     props->setStringValue("navaids/tacan/channel-ID", TACAN_channel_id.c_str());
52     props->setStringValue("name", _name.c_str());
53     props->setBoolValue("tanker", true);
54 }
55
56 void FGAITanker::setTACANChannelID(const string& id) {
57     TACAN_channel_id = id;
58 }
59
60 void FGAITanker::Run(double dt) {
61     //FGAIAircraft::Run(dt);
62
63     double start = pos.getElevationFt() + 1000;
64     altitude_agl_ft = _getAltitudeAGL(pos, start);
65
66     //###########################//
67     // do calculations for radar //
68     //###########################//
69     double range_ft2 = UpdateRadar(manager);
70
71     // check if radar contact
72     if ( (range_ft2 < 250.0 * 250.0) && (y_shift > 0.0)
73               && (elevation > 0.0) ) {
74         //refuel_node->setBoolValue(true);
75         contact = true;
76     } else {
77         //refuel_node->setBoolValue(false);
78         contact = false;
79     }
80 }
81
82
83 void FGAITanker::update(double dt) {
84      FGAIAircraft::update(dt);
85      Run(dt);
86      Transform();
87 }