1 // FGAIWingman - FGAIBllistic-derived class creates an AI Wingman
3 // Written by Vivian Meazza, started February 2008.
4 // - vivian.meazza at lineone.net
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.
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.
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.
24 #include "AIWingman.hxx"
26 FGAIWingman::FGAIWingman() : FGAIBallistic(otWingman)
29 _formate_to_ac = true;
33 FGAIWingman::~FGAIWingman() {}
35 void FGAIWingman::readFromScenario(SGPropertyNode* scFileNode) {
39 FGAIBase::readFromScenario(scFileNode);
41 setAzimuth(scFileNode->getDoubleValue("azimuth", 0.0));
42 setElevation(scFileNode->getDoubleValue("elevation", 0.0));
43 setLife(scFileNode->getDoubleValue("life", -1));
44 setNoRoll(scFileNode->getBoolValue("no-roll", false));
45 setName(scFileNode->getStringValue("name", "Wingman"));
46 //setSMPath(scFileNode->getStringValue("submodel-path", ""));
47 setSubID(scFileNode->getIntValue("SubID", 0));
48 setXoffset(scFileNode->getDoubleValue("x-offset", 0.0));
49 setYoffset(scFileNode->getDoubleValue("y-offset", 0.0));
50 setZoffset(scFileNode->getDoubleValue("z-offset", 0.0));
51 setPitchoffset(scFileNode->getDoubleValue("pitch-offset", 0.0));
52 setRolloffset(scFileNode->getDoubleValue("roll-offset", 0.0));
53 setYawoffset(scFileNode->getDoubleValue("yaw-offset", 0.0));
54 setGroundOffset(scFileNode->getDoubleValue("ground-offset", 0.0));
55 setFormate(scFileNode->getBoolValue("formate", true));
58 void FGAIWingman::bind() {
59 FGAIBallistic::bind();
61 props->tie("id", SGRawValueMethods<FGAIBase,int>(*this,
63 props->tie("subID", SGRawValueMethods<FGAIBase,int>(*this,
64 &FGAIBase::_getSubID));
65 props->tie("position/altitude-ft",
66 SGRawValueMethods<FGAIBase,double>(*this,
67 &FGAIBase::_getElevationFt,
68 &FGAIBase::_setAltitude));
69 props->tie("position/latitude-deg",
70 SGRawValueMethods<FGAIBase,double>(*this,
71 &FGAIBase::_getLatitude,
72 &FGAIBase::_setLatitude));
73 props->tie("position/longitude-deg",
74 SGRawValueMethods<FGAIBase,double>(*this,
75 &FGAIBase::_getLongitude,
76 &FGAIBase::_setLongitude));
78 props->tie("controls/formate-to-ac",
79 SGRawValueMethods<FGAIBallistic,bool>
80 (*this, &FGAIBallistic::getFormate, &FGAIBallistic::setFormate));
83 props->tie("orientation/pitch-deg", SGRawValuePointer<double>(&pitch));
84 props->tie("orientation/roll-deg", SGRawValuePointer<double>(&roll));
85 props->tie("orientation/true-heading-deg", SGRawValuePointer<double>(&hdg));
87 props->tie("submodels/serviceable", SGRawValuePointer<bool>(&serviceable));
89 props->tie("load/rel-brg-to-user-deg",
90 SGRawValueMethods<FGAIBallistic,double>
91 (*this, &FGAIBallistic::getRelBrgHitchToUser));
92 props->tie("load/elev-to-user-deg",
93 SGRawValueMethods<FGAIBallistic,double>
94 (*this, &FGAIBallistic::getElevHitchToUser));
96 props->tie("velocities/vertical-speed-fps",
97 SGRawValuePointer<double>(&vs));
98 props->tie("velocities/true-airspeed-kt",
99 SGRawValuePointer<double>(&speed));
100 props->tie("velocities/speed-east-fps",
101 SGRawValuePointer<double>(&_speed_east_fps));
102 props->tie("velocities/speed-north-fps",
103 SGRawValuePointer<double>(&_speed_north_fps));
106 props->tie("position/x-offset",
107 SGRawValueMethods<FGAIBase,double>(*this, &FGAIBase::_getXOffset, &FGAIBase::setXoffset));
108 props->tie("position/y-offset",
109 SGRawValueMethods<FGAIBase,double>(*this, &FGAIBase::_getYOffset, &FGAIBase::setYoffset));
110 props->tie("position/z-offset",
111 SGRawValueMethods<FGAIBase,double>(*this, &FGAIBase::_getZOffset, &FGAIBase::setZoffset));
112 props->tie("position/tgt-x-offset",
113 SGRawValueMethods<FGAIBallistic,double>(*this, &FGAIBallistic::getTgtXOffset, &FGAIBallistic::setTgtXOffset));
114 props->tie("position/tgt-y-offset",
115 SGRawValueMethods<FGAIBallistic,double>(*this, &FGAIBallistic::getTgtYOffset, &FGAIBallistic::setTgtYOffset));
116 props->tie("position/tgt-z-offset",
117 SGRawValueMethods<FGAIBallistic,double>(*this, &FGAIBallistic::getTgtZOffset, &FGAIBallistic::setTgtZOffset));
120 void FGAIWingman::unbind() {
121 FGAIBallistic::unbind();
124 props->untie("SubID");
126 props->untie("orientation/pitch-deg");
127 props->untie("orientation/roll-deg");
128 props->untie("orientation/true-heading-deg");
130 props->untie("controls/formate-to-ac");
132 props->untie("submodels/serviceable");
134 props->untie("velocities/true-airspeed-kt");
135 props->untie("velocities/vertical-speed-fps");
136 props->untie("velocities/speed_east_fps");
137 props->untie("velocities/speed_north_fps");
139 props->untie("load/rel-brg-to-user-deg");
140 props->untie("load/elev-to-user-deg");
142 props->untie("position/altitude-ft");
143 props->untie("position/latitude-deg");
144 props->untie("position/longitude-deg");
145 props->untie("position/x-offset");
146 props->untie("position/y-offset");
147 props->untie("position/z-offset");
148 props->untie("position/tgt-x-offset");
149 props->untie("position/tgt-y-offset");
150 props->untie("position/tgt-z-offset");
153 bool FGAIWingman::init(bool search_in_AI_path) {
154 if (!FGAIBallistic::init(search_in_AI_path))
159 _tgt_x_offset = _x_offset;
160 _tgt_y_offset = _y_offset;
161 _tgt_z_offset = _z_offset;
168 props->setStringValue("submodels/path", _path.c_str());
172 void FGAIWingman::update(double dt) {
173 FGAIBallistic::update(dt);
174 // cout << FGAIBase::_getName() << " update speed " << FGAIBase::_getSpeed() << endl;