return FGAIBase::init();
}
+void FGAIAircraft::bind() {
+ FGAIBase::bind();
+}
+
+void FGAIAircraft::unbind() {
+ FGAIBase::unbind();
+}
+
void FGAIAircraft::update(double dt) {
~FGAIAircraft();
bool init();
+ virtual void bind();
+ virtual void unbind();
void update(double dt);
void SetPerformance(const PERF_STRUCT *ps);
return true;
}
+void FGAIBallistic::bind() {
+ FGAIBase::bind();
+}
+
+void FGAIBallistic::unbind() {
+ FGAIBase::unbind();
+}
void FGAIBallistic::update(double dt) {
~FGAIBallistic();
bool init();
+ virtual void bind();
+ virtual void unbind();
void update(double dt);
void setAzimuth( double az );
# include <config.h>
#endif
+#include <simgear/compiler.h>
+
+#include STL_STRING
+
#include <plib/sg.h>
#include <plib/ssg.h>
-#include <Main/globals.hxx>
-#include <Scenery/scenery.hxx>
+
#include <simgear/math/point3d.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/scene/model/location.hxx>
#include <simgear/scene/model/model.hxx>
#include <simgear/debug/logstream.hxx>
-#include <string>
+#include <simgear/props/props.hxx>
+
+#include <Main/globals.hxx>
+#include <Scenery/scenery.hxx>
+
#include "AIBase.hxx"
bool FGAIBase::init() {
+
+ props = globals->get_props()->getNode("ai/model", true);
+
ssgBranch *model = sgLoad3DModel( globals->get_fg_root(),
model_path.c_str(),
- globals->get_props(),
+ props,
globals->get_sim_time_sec() );
if (model) {
aip.init( model );
setDie(false);
}
+void FGAIBase::bind() {
+ props->tie("velocities/airspeed-kt", SGRawValuePointer<double>(&speed));
+ props->tie("velocities/vertical-speed-fps", SGRawValuePointer<double>(&vs));
-void FGAIBase::setPath( const char* model ) {
- model_path.append(model);
-}
+ props->tie("position/altitude-ft", SGRawValuePointer<double>(&altitude));
+ props->tie("position/latitude-deg", SGRawValuePointer<double>(&lat));
+ props->tie("position/longitude-deg", SGRawValuePointer<double>(&lon));
-void FGAIBase::setSpeed( double speed_KTAS ) {
- speed = tgt_speed = speed_KTAS;
+ props->tie("orientation/pitch-deg", SGRawValuePointer<double>(&pitch));
+ props->tie("orientation/roll-deg", SGRawValuePointer<double>(&roll));
+ props->tie("orientation/heading-deg", SGRawValuePointer<double>(&hdg));
}
-void FGAIBase::setAltitude( double altitude_ft ) {
- altitude = tgt_altitude = altitude_ft;
- pos.setelev(altitude * 0.3048);
-}
+void FGAIBase::unbind() {
+ props->untie("velocities/airspeed-kt");
+ props->untie("velocities/vertical-speed-fps");
-void FGAIBase::setLongitude( double longitude ) {
- pos.setlon(longitude);
-}
+ props->untie("position/altitude-ft");
+ props->untie("position/latitude-deg");
+ props->untie("position/longitude-deg");
-void FGAIBase::setLatitude( double latitude ) {
- pos.setlat(latitude);
+ props->untie("orientation/pitch-deg");
+ props->untie("orientation/roll-deg");
+ props->untie("orientation/heading-deg");
}
-
-void FGAIBase::setHeading( double heading ) {
- hdg = tgt_heading = heading;
-}
-
-void FGAIBase::setDie( bool die ) {
- delete_me = die;
-}
-
#ifndef _FG_AIBASE_HXX
#define _FG_AIBASE_HXX
+#include <simgear/constants.h>
#include <simgear/math/point3d.hxx>
#include <simgear/scene/model/placement.hxx>
#include <string>
virtual ~FGAIBase();
virtual void update(double dt);
inline Point3D GetPos() { return(pos); }
+
virtual bool init();
+ virtual void bind();
+ virtual void unbind();
void setPath( const char* model );
void setSpeed( double speed_KTAS );
void setLongitude( double longitude );
void setLatitude( double latitude );
void setHeading( double heading );
+
void setDie( bool die );
- inline bool getDie() { return delete_me; }
+ bool getDie();
protected:
+ SGPropertyNode *props;
+
Point3D pos; // WGS84 lat & lon in degrees, elev above sea-level in meters
+ double lat, lon; // As above, this is needed for the property bindings
double hdg; // True heading in degrees
double roll; // degrees, left is negative
double pitch; // degrees, nose-down is negative
bool delete_me;
void Transform();
+
};
+
+inline void FGAIBase::setPath( const char* model ) {
+ model_path.append(model);
+}
+
+inline void FGAIBase::setSpeed( double speed_KTAS ) {
+ speed = tgt_speed = speed_KTAS;
+}
+
+inline void FGAIBase::setAltitude( double altitude_ft ) {
+ altitude = tgt_altitude = altitude_ft;
+ pos.setelev(altitude * SG_FEET_TO_METER);
+}
+
+
+inline void FGAIBase::setLongitude( double longitude ) {
+ lon = longitude;
+ pos.setlon(longitude);
+}
+
+inline void FGAIBase::setLatitude( double latitude ) {
+ lat = latitude;
+ pos.setlat(latitude);
+}
+
+inline void FGAIBase::setHeading( double heading ) {
+ hdg = tgt_heading = heading;
+}
+
+inline void FGAIBase::setDie( bool die ) { delete_me = die; }
+inline bool FGAIBase::getDie() { return delete_me; }
+
#endif // _FG_AIBASE_HXX
ai_plane->setLongitude(entry->getDoubleValue("longitude"));
ai_plane->setLatitude(entry->getDoubleValue("latitude"));
ai_plane->init();
+ ai_plane->bind();
} else if (!strcmp(entry->getStringValue("type", ""), "ship")) {
FGAIShip* ai_ship = new FGAIShip;
ai_ship->setLongitude(entry->getDoubleValue("longitude"));
ai_ship->setLatitude(entry->getDoubleValue("latitude"));
ai_ship->init();
+ ai_ship->bind();
} else if (!strcmp(entry->getStringValue("type", ""), "ballistic")) {
FGAIBallistic* ai_ballistic = new FGAIBallistic;
ai_ballistic->setLongitude(entry->getDoubleValue("longitude"));
ai_ballistic->setLatitude(entry->getDoubleValue("latitude"));
ai_ballistic->init();
+ ai_ballistic->bind();
}
}
}
void FGAIManager::unbind() {
+ ai_list_itr = ai_list.begin();
+ while(ai_list_itr != ai_list.end()) {
+ (*ai_list_itr)->unbind();
+ ++ai_list_itr;
+ }
}
return FGAIBase::init();
}
+void FGAIShip::bind() {
+ FGAIBase::bind();
+}
+void FGAIShip::unbind() {
+ FGAIBase::unbind();
+}
void FGAIShip::update(double dt) {
~FGAIShip();
bool init();
+ virtual void bind();
+ virtual void unbind();
void update(double dt);
void AccelTo(double speed);