]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIWingman.cxx
Walk the AImodels property tree only once at init, rather than at update. Should...
[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     //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));
56 }
57
58 void FGAIWingman::bind() {
59     FGAIBallistic::bind();
60
61     props->tie("id", SGRawValueMethods<FGAIBase,int>(*this,
62         &FGAIBase::getID));
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));
77
78     props->tie("controls/formate-to-ac",
79         SGRawValueMethods<FGAIBallistic,bool>
80         (*this, &FGAIBallistic::getFormate, &FGAIBallistic::setFormate));
81
82
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));
86
87     props->tie("submodels/serviceable", SGRawValuePointer<bool>(&serviceable));
88
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));
95
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));
104
105
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));
118 }
119
120 void FGAIWingman::unbind() {
121     FGAIBallistic::unbind();
122
123     props->untie("id");
124     props->untie("SubID");
125
126     props->untie("orientation/pitch-deg");
127     props->untie("orientation/roll-deg");
128     props->untie("orientation/true-heading-deg");
129
130     props->untie("controls/formate-to-ac");
131
132     props->untie("submodels/serviceable");
133
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");
138
139     props->untie("load/rel-brg-to-user-deg");
140     props->untie("load/elev-to-user-deg");
141
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");
151 }
152
153 bool FGAIWingman::init(bool search_in_AI_path) {
154     if (!FGAIBallistic::init(search_in_AI_path))
155         return false;
156
157     invisible = false;
158
159     _tgt_x_offset = _x_offset;
160     _tgt_y_offset = _y_offset;
161     _tgt_z_offset = _z_offset;
162
163     hdg = _azimuth;
164     pitch = _elevation;
165     roll = _rotation;
166     _ht_agl_ft = 1e10;
167
168     props->setStringValue("submodels/path", _path.c_str());
169     return true;
170 }
171
172 void FGAIWingman::update(double dt) {
173     FGAIBallistic::update(dt);
174 //    cout << FGAIBase::_getName() << " update speed " << FGAIBase::_getSpeed() << endl;
175 }
176
177 // end AIWingman