1
0
Fork 0
flightgear/src/AIModel/AIScenario.cxx

124 lines
4.3 KiB
C++
Raw Normal View History

// FGAIScenario.cxx - class for loading an AI scenario
// Written by David Culp, started May 2004
// - davidculp2@comcast.net
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include <simgear/misc/sg_path.hxx>
#include <simgear/debug/logstream.hxx>
#include <simgear/structure/exception.hxx>
#include <simgear/constants.h>
#ifdef __BORLANDC__
# define exception c_exception
#endif
#include <simgear/props/props.hxx>
#include <Main/globals.hxx>
#include <Main/fg_props.hxx>
#include "AIScenario.hxx"
#include "AIFlightPlan.hxx"
FGAIScenario::FGAIScenario(string &filename)
{
int i;
SGPath path( globals->get_fg_root() );
path.append( ("/Data/AI/" + filename + ".xml").c_str() );
SGPropertyNode root;
try {
readProperties(path.str(), &root);
} catch (const sg_exception &e) {
SG_LOG(SG_GENERAL, SG_ALERT,
"Incorrect path specified for AI scenario: ");
cout << path.str() << endl;
return;
}
entries.clear();
2004-05-15 12:46:25 +00:00
SGPropertyNode * node = root.getNode("scenario");
for (i = 0; i < node->nChildren(); i++) {
//cout << "Reading entry " << i << endl;
SGPropertyNode * entry_node = node->getChild(i);
2004-09-22 11:24:45 +00:00
FGAIModelEntity* en = new FGAIModelEntity;
2004-05-15 12:46:25 +00:00
en->callsign = entry_node->getStringValue("callsign", "none");
en->m_type = entry_node->getStringValue("type", "aircraft");
en->m_class = entry_node->getStringValue("class", "jet_transport");
en->path = entry_node->getStringValue("model", "Models/Geometry/glider.ac");
2004-05-15 12:46:25 +00:00
en->flightplan = entry_node->getStringValue("flightplan", "");
en->repeat = entry_node->getDoubleValue("repeat", 0.0);
en->latitude = entry_node->getDoubleValue("latitude", 0.0);
en->longitude = entry_node->getDoubleValue("longitude", 0.0);
en->altitude = entry_node->getDoubleValue("altitude", 0.0);
en->speed = entry_node->getDoubleValue("speed", 0.0);
en->heading = entry_node->getDoubleValue("heading", 0.0);
en->roll = entry_node->getDoubleValue("roll", 0.0);
en->azimuth = entry_node->getDoubleValue("azimuth", 0.0);
en->elevation = entry_node->getDoubleValue("elevation", 0.0);
en->rudder = entry_node->getDoubleValue("rudder", 0.0);
en->strength = entry_node->getDoubleValue("strength-fps", 0.0);
en->diameter = entry_node->getDoubleValue("diameter-ft", 0.0);
en->height_msl = entry_node->getDoubleValue("height-msl", 5000.0);
David Culp: Silly me. I was starting the timer at zero, so the first tracer didn't fly until 0.25 seconds after pulling the trigger. Now the timer starts at the same value as "delay", so the first round comes out immediately. Also, I've added an optional configuration attribute that allows you to change the ballistics of the submodel. This allows parachutes, or anything else that has ballistics different from a bullet. The attribute is called "eda", which is the equivalent drag area. Default value is 0.007, which gives the same ballistics as the current tracers. Increasing this value gives more drag. A value of 2.0 looks good for a parachute. math stuff ######################################################################## The deceleration of the ballictic object is now given by: [ (rho) (Cd) ] / [ (1/2) (m) ] * A * (V * V) where rho is sea-level air density, and Cd and m are fixed, bullet-like values. So the calculation is: 0.0116918 * A * (V * V) The value "A" is what I'm calling the "eda" (equivalent drag area). ######################################################################## A parachute model will have to be built so that the parachutist's feet are in the forward x-direction. Here is the submodel.xml config I use for "parachutes": <submodel> <name>flares</name> <model>Models/Geometry/flare.ac</model> <trigger>systems/submodels/submodel[0]/trigger</trigger> <speed>0.0</speed> <repeat>true</repeat> <delay>0.85</delay> <count>4</count> <x-offset>0.0</x-offset> <y-offset>0.0</y-offset> <z-offset>-4.0</z-offset> <yaw-offset>0.0</yaw-offset> <pitch-offset>0.0</pitch-offset> <eda>2.0</eda> </submodel>
2004-08-26 16:25:54 +00:00
en->eda = entry_node->getDoubleValue("eda", 0.007);
en->life = entry_node->getDoubleValue("life", 900.0);
en->buoyancy = entry_node->getDoubleValue("buoyancy", 0);
en->wind_from_east = entry_node->getDoubleValue("wind_from_east", 0);
en->wind_from_north = entry_node->getDoubleValue("wind_from_north", 0);
en->wind = entry_node->getBoolValue("wind", false);
en->cd = entry_node->getDoubleValue ("cd", 0.029);
en->mass = entry_node->getDoubleValue ("mass", 0.007);
en->fp = NULL;
if (en->flightplan != ""){
en->fp = new FGAIFlightPlan( en->flightplan );
}
2004-09-22 11:24:45 +00:00
entries.push_back( en );
}
entry_iterator = entries.begin();
//cout << entries.size() << " entries read." << endl;
}
FGAIScenario::~FGAIScenario()
{
entries.clear();
}
FGAIModelEntity*
FGAIScenario::getNextEntry( void )
{
if (entries.size() == 0) return 0;
if (entry_iterator != entries.end()) {
return *entry_iterator++;
} else {
return 0;
}
}
int FGAIScenario::nEntries( void )
{
return entries.size();
}
// end scenario.cxx