]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIWingman.cxx
Use AIBase method setParentNode() vice the local method.
[flightgear.git] / src / AIModel / AIWingman.cxx
1 // FGAIWingman - FGAIBllistic-derived class creates an AI Wingman
2 //
3 // Written by Vivian Meazza, started February 2008.
4 // - vivian.meazza at lineone.net 
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 #ifdef HAVE_CONFIG_H
21 #  include <config.h>
22 #endif
23
24 #include "AIWingman.hxx"
25
26 FGAIWingman::FGAIWingman() : FGAIBallistic(otWingman)
27 {
28     invisible = false;
29     _formate_to_ac = true;
30
31 }
32
33 FGAIWingman::~FGAIWingman() {}
34
35 void FGAIWingman::readFromScenario(SGPropertyNode* scFileNode) {
36     if (!scFileNode)
37         return;
38
39     FGAIBase::readFromScenario(scFileNode);
40
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     setParentName(scFileNode->getStringValue("parent", ""));
47     //setSMPath(scFileNode->getStringValue("submodel-path", ""));
48     setSubID(scFileNode->getIntValue("SubID", 0));
49     setXoffset(scFileNode->getDoubleValue("x-offset", 0.0));
50     setYoffset(scFileNode->getDoubleValue("y-offset", 0.0));
51     setZoffset(scFileNode->getDoubleValue("z-offset", 0.0));
52     setPitchoffset(scFileNode->getDoubleValue("pitch-offset", 0.0));
53     setRolloffset(scFileNode->getDoubleValue("roll-offset", 0.0));
54     setYawoffset(scFileNode->getDoubleValue("yaw-offset", 0.0));
55     setGroundOffset(scFileNode->getDoubleValue("ground-offset", 0.0));
56     setFormate(scFileNode->getBoolValue("formate", true));
57 }
58
59 void FGAIWingman::bind() {
60     FGAIBallistic::bind();
61
62     props->tie("id", SGRawValueMethods<FGAIBase,int>(*this,
63         &FGAIBase::getID));
64     props->tie("subID", SGRawValueMethods<FGAIBase,int>(*this,
65         &FGAIBase::_getSubID));
66     props->tie("position/altitude-ft",
67         SGRawValueMethods<FGAIBase,double>(*this,
68         &FGAIBase::_getElevationFt,
69         &FGAIBase::_setAltitude));
70     props->tie("position/latitude-deg",
71         SGRawValueMethods<FGAIBase,double>(*this,
72         &FGAIBase::_getLatitude,
73         &FGAIBase::_setLatitude));
74     props->tie("position/longitude-deg",
75         SGRawValueMethods<FGAIBase,double>(*this,
76         &FGAIBase::_getLongitude,
77         &FGAIBase::_setLongitude));
78
79     props->tie("controls/formate-to-ac",
80         SGRawValueMethods<FGAIBallistic,bool>
81         (*this, &FGAIBallistic::getFormate, &FGAIBallistic::setFormate));
82
83
84     props->tie("orientation/pitch-deg",   SGRawValuePointer<double>(&pitch));
85     props->tie("orientation/roll-deg",    SGRawValuePointer<double>(&roll));
86     props->tie("orientation/true-heading-deg", SGRawValuePointer<double>(&hdg));
87
88     props->tie("submodels/serviceable", SGRawValuePointer<bool>(&serviceable));
89
90     props->tie("load/rel-brg-to-user-deg",
91         SGRawValueMethods<FGAIBallistic,double>
92         (*this, &FGAIBallistic::getRelBrgHitchToUser));
93     props->tie("load/elev-to-user-deg",
94         SGRawValueMethods<FGAIBallistic,double>
95         (*this, &FGAIBallistic::getElevHitchToUser));
96
97     props->tie("velocities/vertical-speed-fps",
98         SGRawValuePointer<double>(&vs));
99     props->tie("velocities/true-airspeed-kt",
100         SGRawValuePointer<double>(&speed));
101     props->tie("velocities/speed-east-fps",
102         SGRawValuePointer<double>(&_speed_east_fps));
103     props->tie("velocities/speed-north-fps",
104         SGRawValuePointer<double>(&_speed_north_fps));
105
106
107     props->tie("position/x-offset", 
108         SGRawValueMethods<FGAIBase,double>(*this, &FGAIBase::_getXOffset, &FGAIBase::setXoffset));
109     props->tie("position/y-offset", 
110         SGRawValueMethods<FGAIBase,double>(*this, &FGAIBase::_getYOffset, &FGAIBase::setYoffset));
111     props->tie("position/z-offset", 
112         SGRawValueMethods<FGAIBase,double>(*this, &FGAIBase::_getZOffset, &FGAIBase::setZoffset));
113     props->tie("position/tgt-x-offset", 
114         SGRawValueMethods<FGAIBallistic,double>(*this, &FGAIBallistic::getTgtXOffset, &FGAIBallistic::setTgtXOffset));
115     props->tie("position/tgt-y-offset", 
116         SGRawValueMethods<FGAIBallistic,double>(*this, &FGAIBallistic::getTgtYOffset, &FGAIBallistic::setTgtYOffset));
117     props->tie("position/tgt-z-offset", 
118         SGRawValueMethods<FGAIBallistic,double>(*this, &FGAIBallistic::getTgtZOffset, &FGAIBallistic::setTgtZOffset));
119 }
120
121 void FGAIWingman::unbind() {
122     FGAIBallistic::unbind();
123
124     props->untie("id");
125     props->untie("SubID");
126
127     props->untie("orientation/pitch-deg");
128     props->untie("orientation/roll-deg");
129     props->untie("orientation/true-heading-deg");
130
131     props->untie("controls/formate-to-ac");
132
133     props->untie("submodels/serviceable");
134
135     props->untie("velocities/true-airspeed-kt");
136     props->untie("velocities/vertical-speed-fps");
137     props->untie("velocities/speed_east_fps");
138     props->untie("velocities/speed_north_fps");
139
140     props->untie("load/rel-brg-to-user-deg");
141     props->untie("load/elev-to-user-deg");
142
143     props->untie("position/altitude-ft");
144     props->untie("position/latitude-deg");
145     props->untie("position/longitude-deg");
146     props->untie("position/x-offset");
147     props->untie("position/y-offset");
148     props->untie("position/z-offset");
149     props->untie("position/tgt-x-offset");
150     props->untie("position/tgt-y-offset");
151     props->untie("position/tgt-z-offset");
152 }
153
154 bool FGAIWingman::init(bool search_in_AI_path) {
155     if (!FGAIBallistic::init(search_in_AI_path))
156         return false;
157
158     invisible = false;
159
160     _tgt_x_offset = _x_offset;
161     _tgt_y_offset = _y_offset;
162     _tgt_z_offset = _z_offset;
163
164     hdg = _azimuth;
165     pitch = _elevation;
166     roll = _rotation;
167     _ht_agl_ft = 1e10;
168
169     props->setStringValue("submodels/path", _path.c_str());
170     return true;
171 }
172
173 void FGAIWingman::update(double dt) {
174     FGAIBallistic::update(dt);
175 }
176
177 // end AIWingman