1 // AIManager.cxx Based on David Luff's AIMgr:
2 // - a global management class for AI objects
4 // Written by David Culp, started October 2003.
5 // - davidculp2@comcast.net
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <simgear/misc/sg_path.hxx>
22 #include <Main/fg_props.hxx>
23 #include <Main/globals.hxx>
27 #include "AIManager.hxx"
28 #include "AIAircraft.hxx"
30 #include "AIBallistic.hxx"
35 FGAIManager::FGAIManager() {
39 FGAIManager::~FGAIManager() {
43 void FGAIManager::init() {
44 SGPropertyNode * node = fgGetNode("sim/ai", true);
45 for (int i = 0; i < node->nChildren(); i++) {
46 const SGPropertyNode * entry = node->getChild(i);
47 if (!strcmp(entry->getName(), "entry")) {
48 if (!strcmp(entry->getStringValue("type", ""), "aircraft")) {
49 FGAIAircraft* ai_plane = new FGAIAircraft;
50 ai_list.push_back(ai_plane);
51 if (!strcmp(entry->getStringValue("class", ""), "light")) {
52 PERF_STRUCT ps = {2.0, 2.0, 450.0, 1000.0, 70.0, 80.0, 100.0, 80.0, 60.0};
53 ai_plane->SetPerformance(ps);
54 } else if (!strcmp(entry->getStringValue("class", ""), "ww2_fighter")) {
55 PERF_STRUCT ps = {4.0, 2.0, 3000.0, 1500.0, 110.0, 180.0, 250.0, 200.0, 100.0};
56 ai_plane->SetPerformance(ps);
57 } else if (!strcmp(entry->getStringValue("class", ""), "jet_transport")) {
58 PERF_STRUCT ps = {5.0, 2.0, 3000.0, 1500.0, 140.0, 300.0, 430.0, 300.0, 130.0};
59 ai_plane->SetPerformance(ps);
60 } else if (!strcmp(entry->getStringValue("class", ""), "jet_fighter")) {
61 PERF_STRUCT ps = {7.0, 3.0, 4000.0, 2000.0, 150.0, 350.0, 500.0, 350.0, 150.0};
62 ai_plane->SetPerformance(ps);
64 ai_plane->setHeading(entry->getDoubleValue("heading"));
65 ai_plane->setSpeed(entry->getDoubleValue("speed-KTAS"));
66 ai_plane->setPath(entry->getStringValue("path"));
67 ai_plane->setAltitude(entry->getDoubleValue("altitude-ft"));
68 ai_plane->setLongitude(entry->getDoubleValue("longitude"));
69 ai_plane->setLatitude(entry->getDoubleValue("latitude"));
72 } else if (!strcmp(entry->getStringValue("type", ""), "ship")) {
73 FGAIShip* ai_ship = new FGAIShip;
74 ai_list.push_back(ai_ship);
75 ai_ship->setHeading(entry->getDoubleValue("heading"));
76 ai_ship->setSpeed(entry->getDoubleValue("speed-KTAS"));
77 ai_ship->setPath(entry->getStringValue("path"));
78 ai_ship->setAltitude(entry->getDoubleValue("altitude-ft"));
79 ai_ship->setLongitude(entry->getDoubleValue("longitude"));
80 ai_ship->setLatitude(entry->getDoubleValue("latitude"));
83 } else if (!strcmp(entry->getStringValue("type", ""), "ballistic")) {
84 FGAIBallistic* ai_ballistic = new FGAIBallistic;
85 ai_list.push_back(ai_ballistic);
86 ai_ballistic->setAzimuth(entry->getDoubleValue("azimuth"));
87 ai_ballistic->setElevation(entry->getDoubleValue("elevation"));
88 ai_ballistic->setSpeed(entry->getDoubleValue("speed-fps"));
89 ai_ballistic->setPath(entry->getStringValue("path"));
90 ai_ballistic->setAltitude(entry->getDoubleValue("altitude-ft"));
91 ai_ballistic->setLongitude(entry->getDoubleValue("longitude"));
92 ai_ballistic->setLatitude(entry->getDoubleValue("latitude"));
102 void FGAIManager::bind() {
106 void FGAIManager::unbind() {
110 void FGAIManager::update(double dt) {
114 SG_LOG(SG_ATC, SG_WARN, "Warning - AIManager::update(...) called before AIManager::init()");
118 ai_list_itr = ai_list.begin();
119 while(ai_list_itr != ai_list.end()) {
120 if ((*ai_list_itr)->getDie()) {
121 ai_list.erase(ai_list_itr, ai_list_itr);
123 (*ai_list_itr)->update(dt);