Debian Codegraph @

src/AIModel/AISwiftAircraft.cpp

raw symbols SCIP
1 // AISwiftAircraft.cpp - Derived AIBase class for swift aircraft
2 //
3 // Copyright (C) 2020 - swift Project Community / Contributors (http://swift-project.org/)
4 // Written by Lars Toenning <[email protected]> started on April 2020.
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License as
8 // published by the Free Software Foundation; either version 2 of the
9 // License, or (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 #include "AISwiftAircraft.h"
21 #include <Main/globals.hxx>
22
23
24 FGAISwiftAircraft::FGAISwiftAircraft(const std::string& callsign, const std::string& modelString) : FGAIBaseAircraft(object_type::otStatic)
25 {
26 std::size_t pos = modelString.find("/Aircraft/"); // Only supporting AI models from FGDATA/AI/Aircraft for now
27 if(pos != std::string::npos)
28 model_path.append(modelString.substr(pos));
29 else
30 model_path.append("INVALID_PATH");
31
32 setCallSign(callsign);
33 _searchOrder = ModelSearchOrder::PREFER_AI;
34 }
35
36 void FGAISwiftAircraft::updatePosition(const SGGeod &position, const SGVec3d &orientation, double groundspeed, bool initPos)
37 {
38 m_initPos = initPos;
39 _setLatitude(position.getLatitudeDeg());
40 _setLongitude(position.getLongitudeDeg());
41 _setAltitude(position.getElevationFt());
42 setPitch(orientation.x());
43 setBank(orientation.y());
44 setHeading(orientation.z());
45 setSpeed(groundspeed);
46
47 }
48
49 void FGAISwiftAircraft::update(double dt)
50 {
51 FGAIBase::update(dt);
52 Transform();
53 }
54
55 double FGAISwiftAircraft::getGroundElevation(const SGGeod& pos) const
56 {
57 if(!m_initPos) { return std::numeric_limits<double>::quiet_NaN(); }
58 double alt = 0;
59 SGGeod posReq;
60 posReq.setElevationFt(30000);
61 posReq.setLatitudeDeg(pos.getLatitudeDeg());
62 posReq.setLongitudeDeg(pos.getLongitudeDeg());
63 if(this->getGroundElevationM(posReq, alt, nullptr))
64 return alt;
65 return std::numeric_limits<double>::quiet_NaN();
66 }
67
68 void FGAISwiftAircraft::setPlaneSurface(const AircraftSurfaces& surfaces)
69 {
70 GearPos(surfaces.gear);
71 FlapsPos(surfaces.flaps);
72 SpoilerPos(surfaces.spoilers);
73 SpeedBrakePos(surfaces.spoilers);
74 BeaconLight(surfaces.beaconLight);
75 LandingLight(surfaces.landingLight);
76 NavLight(surfaces.navLight);
77 StrobeLight(surfaces.strobeLight);
78 TaxiLight(surfaces.taxiLight);
79 }
80
81 void FGAISwiftAircraft::setPlaneTransponder(const AircraftTransponder& transponder)
82 {
83 m_transponderCodeNode->setIntValue(transponder.code);
84 m_transponderCModeNode->setBoolValue(transponder.modeC);
85 m_transponderIdentNode->setBoolValue(transponder.ident);
86 }
87
88 void FGAISwiftAircraft::initProps()
89 {
90 // Setup node properties
91 m_transponderCodeNode = _getProps()->getNode("swift/transponder/code", true);
92 m_transponderCModeNode = _getProps()->getNode("swift/transponder/c-mode", true);
93 m_transponderIdentNode = _getProps()->getNode("swift/transponder/ident", true);
94 }