FGAIBase::FGAIBase()
- : fp( NULL ),
+ : fp( NULL ),
model( NULL ),
props( NULL ),
- manager( NULL )
+ manager( NULL ),
+ _refID( _newAIModelID() )
{
_type_str = "model";
tgt_heading = tgt_altitude = tgt_speed = 0.0;
void FGAIBase::bind() {
props->tie("id", SGRawValueMethods<FGAIBase,int>(*this,
- &FGAIBase::_getID));
+ &FGAIBase::getID));
props->tie("velocities/true-airspeed-kt", SGRawValuePointer<double>(&speed));
props->tie("velocities/vertical-speed-fps",
SGRawValueMethods<FGAIBase,double>(*this,
return (fgGetFloat("/sim/time/sun-angle-rad") > 1.57);
}
-int FGAIBase::_getID() const {
- return (int)(this);
+int FGAIBase::getID() const {
+ return _refID;
}
void FGAIBase::CalculateMach() {
// cout << "Speed(ft/s) "<< speed <<" Altitude(ft) "<< altitude << " Mach " << Mach;
}
+int FGAIBase::_newAIModelID() {
+ static int id = 0;
+ if (!++id) id++; // id = 0 is not allowed.
+ return id;
+}
+
class FGAIManager;
class FGAIFlightPlan;
+
struct ParkPosition {
ParkPosition(const ParkPosition& pp)
: name(pp.name), offset(pp.offset), heading_deg(pp.heading_deg)
void setYoffset( double y_offset );
void setZoffset( double z_offset );
+ int getID() const;
- void* getID();
void setDie( bool die );
bool getDie();
object_type _otype;
int index;
+ static int _newAIModelID();
+
+private:
+ const int _refID;
+
public:
object_type getType();
static const double e;
static const double lbs_to_slugs;
- int _getID() const;
-
inline double _getRange() { return range; };
ssgBranch * load3DModel(const string& fg_root,
const string &path,
inline FGAIBase::object_type FGAIBase::getType() { return _otype; }
-inline void* FGAIBase::getID() { return this; }
-
#endif // _FG_AIBASE_HXX
return ai_static;
}
-void FGAIManager::destroyObject( void* ID ) {
+void FGAIManager::destroyObject( int ID ) {
ai_list_iterator ai_list_itr = ai_list.begin();
while(ai_list_itr != ai_list.end()) {
if ((*ai_list_itr)->getID() == ID) {
void* createCarrier( FGAIModelEntity *entity );
void* createStatic( FGAIModelEntity *entity );
- void destroyObject( void* ID );
+ void destroyObject( int ID );
inline double get_user_latitude() { return user_latitude; }
inline double get_user_longitude() { return user_longitude; }
// Fixme: A non-existent model path results in an
// abort, due to an unhandled exeption, in fg main loop.
- AIManagerRef = aimgr->createAircraft( &entity, this);
+ FGAIBase *aircraft = (FGAIBase*)aimgr->createAircraft( &entity, this);
+ AIManagerRef = aircraft->getID();
//cerr << "Class: " << m_class << ". acType: " << acType << ". Airline: " << airline << ". Speed = " << speed << ". From " << dep->getId() << " to " << arr->getId() << ". Time Fraction = " << (remainingTimeEnroute/(double) totalTimeEnroute) << endl;
//cerr << "Latitude : " << lat << ". Longitude : " << lon << endl;
//cerr << "Dep : " << dep->getLatitude()<< ", "<< dep->getLongitude() << endl;
double radius;
double groundOffset;
double distanceToUser;
- void* AIManagerRef;
+ int AIManagerRef;
bool firstRun;
currAircraft++;
}
-void FGTrafficManager::release(void *id)
+void FGTrafficManager::release(int id)
{
releaseList.push_back(id);
}
-bool FGTrafficManager::isReleased(void *id)
+bool FGTrafficManager::isReleased(int id)
{
IdListIterator i = releaseList.begin();
while (i != releaseList.end())
#include "Schedule.hxx"
-typedef vector<void *> IdList;
-typedef vector<void *>::iterator IdListIterator;
+typedef vector<int> IdList;
+typedef vector<int>::iterator IdListIterator;
class FGTrafficManager : public SGSubsystem, public XMLVisitor
void init();
void update(double time);
- void release(void *ref);
- bool isReleased(void *id);
+ void release(int ref);
+ bool isReleased(int id);
// Some overloaded virtual XMLVisitor members
virtual void startXML ();