]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIWingman.cxx
39c20bbc6aaa49f2e1ca6acd1c8218e326e13455
[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("orientation/pitch-deg",   SGRawValuePointer<double>(&pitch));
79     props->tie("orientation/roll-deg",    SGRawValuePointer<double>(&roll));
80     props->tie("orientation/true-heading-deg", SGRawValuePointer<double>(&hdg));
81
82     props->tie("submodels/serviceable", SGRawValuePointer<bool>(&serviceable));
83
84     props->tie("load/rel-brg-to-user-deg",
85         SGRawValueMethods<FGAIBallistic,double>
86         (*this, &FGAIBallistic::getRelBrgHitchToUser));
87     props->tie("load/elev-to-user-deg",
88         SGRawValueMethods<FGAIBallistic,double>
89         (*this, &FGAIBallistic::getElevHitchToUser));
90
91     props->tie("velocities/vertical-speed-fps",
92         SGRawValuePointer<double>(&vs));
93     props->tie("velocities/true-airspeed-kt",
94         SGRawValuePointer<double>(&speed));
95     props->tie("velocities/speed-east-fps",
96         SGRawValuePointer<double>(&_speed_east_fps));
97     props->tie("velocities/speed-north-fps",
98         SGRawValuePointer<double>(&_speed_north_fps));
99
100
101     props->tie("position/x-offset", 
102         SGRawValueMethods<FGAIBase,double>(*this, &FGAIBase::_getXOffset, &FGAIBase::setXoffset));
103     props->tie("position/y-offset", 
104         SGRawValueMethods<FGAIBase,double>(*this, &FGAIBase::_getYOffset, &FGAIBase::setYoffset));
105     props->tie("position/z-offset", 
106         SGRawValueMethods<FGAIBase,double>(*this, &FGAIBase::_getZOffset, &FGAIBase::setZoffset));
107     props->tie("position/tgt-x-offset", 
108         SGRawValueMethods<FGAIBallistic,double>(*this, &FGAIBallistic::getTgtXOffset, &FGAIBallistic::setTgtXOffset));
109     props->tie("position/tgt-y-offset", 
110         SGRawValueMethods<FGAIBallistic,double>(*this, &FGAIBallistic::getTgtYOffset, &FGAIBallistic::setTgtYOffset));
111     props->tie("position/tgt-z-offset", 
112         SGRawValueMethods<FGAIBallistic,double>(*this, &FGAIBallistic::getTgtZOffset, &FGAIBallistic::setTgtZOffset));
113 }
114
115 void FGAIWingman::unbind() {
116     FGAIBallistic::unbind();
117
118     props->untie("id");
119     props->untie("SubID");
120
121     props->untie("orientation/pitch-deg");
122     props->untie("orientation/roll-deg");
123     props->untie("orientation/true-heading-deg");
124
125     props->untie("submodels/serviceable");
126
127     props->untie("velocities/true-airspeed-kt");
128     props->untie("velocities/vertical-speed-fps");
129     props->untie("velocities/speed_east_fps");
130     props->untie("velocities/speed_north_fps");
131
132     props->untie("load/rel-brg-to-user-deg");
133     props->untie("load/elev-to-user-deg");
134
135     props->untie("position/altitude-ft");
136     props->untie("position/latitude-deg");
137     props->untie("position/longitude-deg");
138     props->untie("position/x-offset");
139     props->untie("position/y-offset");
140     props->untie("position/z-offset");
141     props->untie("position/tgt-x-offset");
142     props->untie("position/tgt-y-offset");
143     props->untie("position/tgt-z-offset");
144 }
145
146 bool FGAIWingman::init(bool search_in_AI_path) {
147     if (!FGAIBallistic::init(search_in_AI_path))
148         return false;
149
150     invisible = false;
151
152     _tgt_x_offset = _x_offset;
153     _tgt_y_offset = _y_offset;
154     _tgt_z_offset = _z_offset;
155
156     hdg = _azimuth;
157     pitch = _elevation;
158     roll = _rotation;
159     _ht_agl_ft = 1e10;
160
161     props->setStringValue("submodels/path", _path.c_str());
162     return true;
163 }
164
165 void FGAIWingman::update(double dt) {
166     FGAIBallistic::update(dt);
167 //    cout << FGAIBase::_getName() << " update speed " << FGAIBase::_getSpeed() << endl;
168 }
169
170 // end AIWingman