53
54
FGAIManager::~FGAIManager() {
54
ai_list_itr = ai_list.begin();
55
ai_list_iterator ai_list_itr = ai_list.begin();
55
56
while(ai_list_itr != ai_list.end()) {
56
57
(*ai_list_itr)->unbind();
57
58
delete (*ai_list_itr);
76
77
wind_from_down_node = fgGetNode("/environment/wind-from-down-fps", true);
78
scenario_filename = root->getNode("scenario", true)->getStringValue();
79
if (scenario_filename != "") processScenario( scenario_filename );
78
wind_from_east_node = fgGetNode("/environment/wind-from-east-fps",true);
79
wind_from_north_node = fgGetNode("/environment/wind-from-north-fps",true);
81
user_latitude_node = fgGetNode("/position/latitude-deg", true);
82
user_longitude_node = fgGetNode("/position/longitude-deg", true);
83
user_altitude_node = fgGetNode("/position/altitude-ft", true);
84
user_heading_node = fgGetNode("/orientation/heading-deg", true);
85
user_pitch_node = fgGetNode("/orientation/pitch-deg", true);
86
user_yaw_node = fgGetNode("/orientation/side-slip-deg", true);
87
user_speed_node = fgGetNode("/velocities/uBody-fps", true);
89
for(int i = 0 ; i < root->nChildren() ; i++) {
90
SGPropertyNode *aiEntry = root->getChild( i );
91
if( !strcmp( aiEntry->getName(), "scenario" ) ) {
92
scenario_filename = aiEntry->getStringValue();
93
if (scenario_filename != "") processScenario( scenario_filename );
100
void FGAIManager::reinit() {
85
105
void FGAIManager::bind() {
86
106
root = globals->get_props()->getNode("ai/models", true);
87
107
root->tie("count", SGRawValuePointer<int>(&numObjects[0]));
108
ai_list_itr = ai_list.begin();
128
ai_list_iterator ai_list_itr = ai_list.begin();
109
129
while(ai_list_itr != ai_list.end()) {
110
130
if ((*ai_list_itr)->getDie()) {
111
131
tmgr->release((*ai_list_itr)->getID());
157
177
ai_plane->SetPerformance(&FGAIAircraft::settings[FGAIAircraft::JET_TRANSPORT]);
179
ai_plane->setAcType(entity->acType);
180
ai_plane->setCompany(entity->company);
159
181
ai_plane->setHeading(entity->heading);
160
182
ai_plane->setSpeed(entity->speed);
161
183
ai_plane->setPath(entity->path.c_str());
188
212
ai_ship->setAltitude(entity->altitude);
189
213
ai_ship->setLongitude(entity->longitude);
190
214
ai_ship->setLatitude(entity->latitude);
191
ai_ship->setBank(entity->rudder);
215
ai_ship->setRudder(entity->rudder);
216
ai_ship->setName(entity->name);
193
218
if ( entity->fp ) {
194
219
ai_ship->setFlightPlan(entity->fp);
207
232
FGAICarrier* ai_carrier = new FGAICarrier(this);
208
233
ai_list.push_back(ai_carrier);
210
++numObjects[FGAIBase::otShip];
235
++numObjects[FGAIBase::otCarrier];
211
236
ai_carrier->setHeading(entity->heading);
212
237
ai_carrier->setSpeed(entity->speed);
213
238
ai_carrier->setPath(entity->path.c_str());
214
239
ai_carrier->setAltitude(entity->altitude);
215
240
ai_carrier->setLongitude(entity->longitude);
216
241
ai_carrier->setLatitude(entity->latitude);
217
ai_carrier->setBank(entity->rudder);
242
ai_carrier->setRudder(entity->rudder);
218
243
ai_carrier->setSolidObjects(entity->solid_objects);
219
244
ai_carrier->setWireObjects(entity->wire_objects);
220
245
ai_carrier->setCatapultObjects(entity->catapult_objects);
246
ai_carrier->setParkingPositions(entity->ppositions);
221
247
ai_carrier->setRadius(entity->radius);
222
ai_carrier->setXoffset(entity->x_offset);
223
ai_carrier->setYoffset(entity->y_offset);
224
ai_carrier->setZoffset(entity->z_offset);
248
ai_carrier->setSign(entity->pennant_number);
249
ai_carrier->setName(entity->name);
250
ai_carrier->setFlolsOffset(entity->flols_offset);
251
ai_carrier->setWind_from_east(entity->wind_from_east);
252
ai_carrier->setWind_from_north(entity->wind_from_north);
253
ai_carrier->setTACANChannelID(entity->TACAN_channel_ID);
254
ai_carrier->setMaxLat(entity->max_lat);
255
ai_carrier->setMinLat(entity->min_lat);
256
ai_carrier->setMaxLong(entity->max_long);
257
ai_carrier->setMinLong(entity->min_long);
226
260
if ( entity->fp ) {
227
261
ai_carrier->setFlightPlan(entity->fp);
270
304
ai_storm->setHeading(entity->heading);
271
305
ai_storm->setSpeed(entity->speed);
272
306
ai_storm->setPath(entity->path.c_str());
273
ai_storm->setAltitude(entity->altitude);
307
ai_storm->setAltitude(entity->altitude);
308
ai_storm->setDiameter(entity->diameter / 6076.11549);
309
ai_storm->setHeight(entity->height_msl);
310
ai_storm->setStrengthNorm(entity->turb_strength);
274
311
ai_storm->setLongitude(entity->longitude);
275
312
ai_storm->setLatitude(entity->latitude);
276
313
ai_storm->init();
289
326
ai_thermal->setLatitude(entity->latitude);
290
327
ai_thermal->setMaxStrength(entity->strength);
291
328
ai_thermal->setDiameter(entity->diameter / 6076.11549);
329
ai_thermal->setHeight(entity->height_msl);
292
330
ai_thermal->init();
293
331
ai_thermal->bind();
294
332
ai_list.push_back(ai_thermal);
295
333
return ai_thermal;
298
void FGAIManager::destroyObject( void* ID ) {
299
ai_list_itr = ai_list.begin();
337
FGAIManager::createStatic( FGAIModelEntity *entity ) {
339
// cout << "creating static object" << endl;
341
FGAIStatic* ai_static = new FGAIStatic(this);
342
ai_list.push_back(ai_static);
344
++numObjects[FGAIBase::otStatic];
345
ai_static->setHeading(entity->heading);
346
ai_static->setPath(entity->path.c_str());
347
ai_static->setAltitude(entity->altitude);
348
ai_static->setLongitude(entity->longitude);
349
ai_static->setLatitude(entity->latitude);
355
void FGAIManager::destroyObject( int ID ) {
356
ai_list_iterator ai_list_itr = ai_list.begin();
300
357
while(ai_list_itr != ai_list.end()) {
301
358
if ((*ai_list_itr)->getID() == ID) {
314
// fetch the user's state every 10 sim cycles
315
372
void FGAIManager::fetchUserState( void ) {
317
if (dt_count == 10) {
318
user_latitude = fgGetDouble("/position/latitude-deg");
319
user_longitude = fgGetDouble("/position/longitude-deg");
320
user_altitude = fgGetDouble("/position/altitude-ft");
321
user_heading = fgGetDouble("/orientation/heading-deg");
322
user_pitch = fgGetDouble("/orientation/pitch-deg");
323
user_yaw = fgGetDouble("/orientation/side-slip-deg");
324
user_speed = fgGetDouble("/velocities/uBody-fps") * 0.592484;
373
user_latitude = user_latitude_node->getDoubleValue();
374
user_longitude = user_longitude_node->getDoubleValue();
375
user_altitude = user_altitude_node->getDoubleValue();
376
user_heading = user_heading_node->getDoubleValue();
377
user_pitch = user_pitch_node->getDoubleValue();
378
user_yaw = user_yaw_node->getDoubleValue();
379
user_speed = user_speed_node->getDoubleValue() * 0.592484;
380
wind_from_east = wind_from_east_node->getDoubleValue();
381
wind_from_north = wind_from_north_node->getDoubleValue();
340
void FGAIManager::processScenario( string &filename ) {
397
void FGAIManager::processScenario( const string &filename ) {
341
398
FGAIScenario* s = new FGAIScenario( filename );
342
399
for (int i=0;i<s->nEntries();i++) {
343
FGAIModelEntity* en = s->getNextEntry();
400
FGAIModelEntity* const en = s->getNextEntry();
346
403
if ( en->m_type == "aircraft") {
370
430
// This code keeps track of models that have already been loaded
371
431
// Eventually we'd prbably need to find a way to keep track of models
372
432
// that are unloaded again
373
ssgBranch * FGAIManager::getModel(const string& path)
433
ssgBranch * FGAIManager::getModel(const string& path) const
375
435
ModelVecIterator i = loadedModels.begin();
376
436
while (i != loadedModels.end())
385
445
void FGAIManager::setModel(const string& path, ssgBranch *model)
387
449
loadedModels.push_back(FGModelID(path,model));
452
bool FGAIManager::getStartPosition(const string& id, const string& pid,
453
Point3D& geodPos, double& heading,
456
SGPropertyNode* root = fgGetNode("sim/ai", true);
457
if (!root->getNode("enabled", true)->getBoolValue())
461
for(int i = 0 ; (!found) && i < root->nChildren() ; i++) {
462
SGPropertyNode *aiEntry = root->getChild( i );
463
if( !strcmp( aiEntry->getName(), "scenario" ) ) {
464
string filename = aiEntry->getStringValue();
465
FGAIScenario* s = new FGAIScenario( filename );
466
for (int i=0; i<s->nEntries(); i++) {
467
FGAIModelEntity* en = s->getNextEntry();
468
if (en && en->m_type == "carrier" &&
469
(en->pennant_number == id || en->name == id)) {
470
FGAICarrier* ai_carrier = new FGAICarrier(0);
471
ai_carrier->setHeading(en->heading);
472
ai_carrier->setSpeed(en->speed);
473
ai_carrier->setAltitude(en->altitude);
474
ai_carrier->setLongitude(en->longitude);
475
ai_carrier->setLatitude(en->latitude);
476
ai_carrier->setBank(en->rudder);
477
ai_carrier->setParkingPositions(en->ppositions);
478
ai_carrier->setWind_from_east(en->wind_from_east);
479
ai_carrier->setWind_from_north(en->wind_from_north);
480
//ai_carrier->setTACANFreq(en->TACAN_freq);
482
if (ai_carrier->getParkPosition(pid, geodPos, heading, uvw)) {
391
497
//end AIManager.cxx