#include "AIStorm.hxx"
#include "AIThermal.hxx"
#include "AICarrier.hxx"
+#include "AIStatic.hxx"
SG_USING_STD(list);
return;
wind_from_down_node = fgGetNode("/environment/wind-from-down-fps", true);
-
- scenario_filename = root->getNode("scenario", true)->getStringValue();
- if (scenario_filename != "") processScenario( scenario_filename );
-
+ wind_from_east_node = fgGetNode("/environment/wind-from-east-fps",true);
+ wind_from_north_node = fgGetNode("/environment/wind-from-north-fps",true);
+
+ user_latitude_node = fgGetNode("/position/latitude-deg", true);
+ user_longitude_node = fgGetNode("/position/longitude-deg", true);
+ user_altitude_node = fgGetNode("/position/altitude-ft", true);
+ user_heading_node = fgGetNode("/orientation/heading-deg", true);
+ user_pitch_node = fgGetNode("/orientation/pitch-deg", true);
+ user_yaw_node = fgGetNode("/orientation/side-slip-deg", true);
+ user_speed_node = fgGetNode("/velocities/uBody-fps", true);
+
+ for(int i = 0 ; i < root->nChildren() ; i++) {
+ SGPropertyNode *aiEntry = root->getChild( i );
+ if( !strcmp( aiEntry->getName(), "scenario" ) ) {
+ scenario_filename = aiEntry->getStringValue();
+ if (scenario_filename != "") processScenario( scenario_filename );
+ }
+ }
initDone = true;
}
+void FGAIManager::reinit() {
+ update(0.0);
+}
+
+
void FGAIManager::bind() {
root = globals->get_props()->getNode("ai/models", true);
root->tie("count", SGRawValuePointer<int>(&numObjects[0]));
}
++ai_list_itr;
}
- wind_from_down_node->setDoubleValue( strength );
+ wind_from_down_node->setDoubleValue( strength ); // for thermals
}
} else {
ai_plane->SetPerformance(&FGAIAircraft::settings[FGAIAircraft::JET_TRANSPORT]);
}
- ai_plane->setAcType(entity->acType);
- ai_plane->setCompany(entity->company);
+ ai_plane->setAcType(entity->acType);
+ ai_plane->setCompany(entity->company);
ai_plane->setHeading(entity->heading);
ai_plane->setSpeed(entity->speed);
ai_plane->setPath(entity->path.c_str());
if ( entity->fp ) {
ai_plane->SetFlightPlan(entity->fp);
}
-
+ if (entity->repeat) {
+ ai_plane->GetFlightPlan()->setRepeat(true);
+ }
ai_plane->init();
ai_plane->bind();
return ai_plane;
ai_ship->setAltitude(entity->altitude);
ai_ship->setLongitude(entity->longitude);
ai_ship->setLatitude(entity->latitude);
- ai_ship->setBank(entity->rudder);
+ ai_ship->setRudder(entity->rudder);
ai_ship->setName(entity->name);
if ( entity->fp ) {
ai_carrier->setAltitude(entity->altitude);
ai_carrier->setLongitude(entity->longitude);
ai_carrier->setLatitude(entity->latitude);
- ai_carrier->setBank(entity->rudder);
+ ai_carrier->setRudder(entity->rudder);
ai_carrier->setSolidObjects(entity->solid_objects);
ai_carrier->setWireObjects(entity->wire_objects);
ai_carrier->setCatapultObjects(entity->catapult_objects);
ai_carrier->setSign(entity->pennant_number);
ai_carrier->setName(entity->name);
ai_carrier->setFlolsOffset(entity->flols_offset);
+ ai_carrier->setWind_from_east(entity->wind_from_east);
+ ai_carrier->setWind_from_north(entity->wind_from_north);
+ ai_carrier->setTACANChannelID(entity->TACAN_channel_ID);
+ ai_carrier->setMaxLat(entity->max_lat);
+ ai_carrier->setMinLat(entity->min_lat);
+ ai_carrier->setMaxLong(entity->max_long);
+ ai_carrier->setMinLong(entity->min_long);
+
if ( entity->fp ) {
ai_carrier->setFlightPlan(entity->fp);
ai_storm->setHeading(entity->heading);
ai_storm->setSpeed(entity->speed);
ai_storm->setPath(entity->path.c_str());
- ai_storm->setAltitude(entity->altitude);
+ ai_storm->setAltitude(entity->altitude);
+ ai_storm->setDiameter(entity->diameter / 6076.11549);
+ ai_storm->setHeight(entity->height_msl);
+ ai_storm->setStrengthNorm(entity->strength);
ai_storm->setLongitude(entity->longitude);
ai_storm->setLatitude(entity->latitude);
ai_storm->init();
ai_thermal->setLatitude(entity->latitude);
ai_thermal->setMaxStrength(entity->strength);
ai_thermal->setDiameter(entity->diameter / 6076.11549);
+ ai_thermal->setHeight(entity->height_msl);
ai_thermal->init();
ai_thermal->bind();
ai_list.push_back(ai_thermal);
return ai_thermal;
}
+void*
+FGAIManager::createStatic( FGAIModelEntity *entity ) {
+
+ // cout << "creating static object" << endl;
+
+ FGAIStatic* ai_static = new FGAIStatic(this);
+ ai_list.push_back(ai_static);
+ ++numObjects[0];
+ ++numObjects[FGAIBase::otStatic];
+ ai_static->setHeading(entity->heading);
+ ai_static->setPath(entity->path.c_str());
+ ai_static->setAltitude(entity->altitude);
+ ai_static->setLongitude(entity->longitude);
+ ai_static->setLatitude(entity->latitude);
+ ai_static->init();
+ ai_static->bind();
+ return ai_static;
+}
+
void FGAIManager::destroyObject( void* ID ) {
ai_list_iterator ai_list_itr = ai_list.begin();
while(ai_list_itr != ai_list.end()) {
}
}
-// fetch the user's state every 10 sim cycles
+
void FGAIManager::fetchUserState( void ) {
- ++dt_count;
- if (dt_count == 10) {
- user_latitude = fgGetDouble("/position/latitude-deg");
- user_longitude = fgGetDouble("/position/longitude-deg");
- user_altitude = fgGetDouble("/position/altitude-ft");
- user_heading = fgGetDouble("/orientation/heading-deg");
- user_pitch = fgGetDouble("/orientation/pitch-deg");
- user_yaw = fgGetDouble("/orientation/side-slip-deg");
- user_speed = fgGetDouble("/velocities/uBody-fps") * 0.592484;
- dt_count = 0;
- }
+ user_latitude = user_latitude_node->getDoubleValue();
+ user_longitude = user_longitude_node->getDoubleValue();
+ user_altitude = user_altitude_node->getDoubleValue();
+ user_heading = user_heading_node->getDoubleValue();
+ user_pitch = user_pitch_node->getDoubleValue();
+ user_yaw = user_yaw_node->getDoubleValue();
+ user_speed = user_speed_node->getDoubleValue() * 0.592484;
+ wind_from_east = wind_from_east_node->getDoubleValue();
+ wind_from_north = wind_from_north_node->getDoubleValue();
+
+
}
}
-void FGAIManager::processScenario( string &filename ) {
+void FGAIManager::processScenario( const string &filename ) {
FGAIScenario* s = new FGAIScenario( filename );
for (int i=0;i<s->nEntries();i++) {
FGAIModelEntity* en = s->getNextEntry();
} else if ( en->m_type == "ballistic") {
createBallistic( en );
- }
+
+ } else if ( en->m_type == "static") {
+ createStatic( en );
+ }
}
}
loadedModels.push_back(FGModelID(path,model));
}
+bool FGAIManager::getStartPosition(const string& id, const string& pid,
+ Point3D& geodPos, double& heading,
+ sgdVec3 uvw)
+{
+ SGPropertyNode* root = fgGetNode("sim/ai", true);
+ if (!root->getNode("enabled", true)->getBoolValue())
+ return 0;
+
+ bool found = false;
+ for(int i = 0 ; (!found) && i < root->nChildren() ; i++) {
+ SGPropertyNode *aiEntry = root->getChild( i );
+ if( !strcmp( aiEntry->getName(), "scenario" ) ) {
+ string filename = aiEntry->getStringValue();
+ FGAIScenario* s = new FGAIScenario( filename );
+ for (int i=0; i<s->nEntries(); i++) {
+ FGAIModelEntity* en = s->getNextEntry();
+ if (en && en->m_type == "carrier" &&
+ (en->pennant_number == id || en->name == id)) {
+ FGAICarrier* ai_carrier = new FGAICarrier(0);
+ ai_carrier->setHeading(en->heading);
+ ai_carrier->setSpeed(en->speed);
+ ai_carrier->setAltitude(en->altitude);
+ ai_carrier->setLongitude(en->longitude);
+ ai_carrier->setLatitude(en->latitude);
+ ai_carrier->setBank(en->rudder);
+ ai_carrier->setParkingPositions(en->ppositions);
+ ai_carrier->setWind_from_east(en->wind_from_east);
+ ai_carrier->setWind_from_north(en->wind_from_north);
+ //ai_carrier->setTACANFreq(en->TACAN_freq);
+
+ if (ai_carrier->getParkPosition(pid, geodPos, heading, uvw)) {
+ delete ai_carrier;
+ found = true;
+ break;
+ }
+
+ delete ai_carrier;
+ }
+ }
+ delete s;
+ }
+ }
+ return found;
+}
//end AIManager.cxx