2004-03-03 20:26:06 +00:00
|
|
|
// FGAIThermal - FGAIBase-derived class creates an AI thermal
|
|
|
|
//
|
|
|
|
// Written by David Culp, started Feb 2004.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2004 David P. Culp - 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
|
2006-02-21 01:16:04 +00:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2004-03-03 20:26:06 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <Main/fg_props.hxx>
|
|
|
|
#include <Main/globals.hxx>
|
|
|
|
#include <Scenery/scenery.hxx>
|
|
|
|
#include <string>
|
|
|
|
#include <math.h>
|
|
|
|
|
2008-07-27 16:25:13 +00:00
|
|
|
using std::string;
|
2004-03-03 20:26:06 +00:00
|
|
|
|
|
|
|
#include "AIThermal.hxx"
|
|
|
|
|
|
|
|
|
2006-02-11 13:16:56 +00:00
|
|
|
FGAIThermal::FGAIThermal() : FGAIBase(otThermal) {
|
David Culp:
I added some things to the AI stuff to improve the AIThermal processing.
Before, all the thermals were processed in order, and the last one overwrote
the prior one. Now, only the data from the nearest thermal is kept. This
way a tile can be populated with many thermals, and (as long as they have the
same diameter) the one nearest the airplane correctly takes effect. This
will make us ready for the next step, "auto-thermaling", where FlightGear's
tile manager can cover a tile with thermals, and set the thermal strength
based on land-use type.
I moved the enumerated object_type to the base class. When an AI object is
created it now sets the _otype variable in the base class. This lets the AI
manager find out what kind of AI object it is dealing with, using the base
pointer. I also added a function isa() to the base class, so the manager can
process objects differently based on their type.
The AI manager now sends AIThermal processing to a different function, where
only the data from the nearest thermal is kept. After the manager processes
all the AI objects, then the results from the nearest thermal are applied to
wind-from-down.
2004-03-07 12:08:46 +00:00
|
|
|
max_strength = 6.0;
|
2004-03-03 20:26:06 +00:00
|
|
|
diameter = 0.5;
|
David Culp:
I added some things to the AI stuff to improve the AIThermal processing.
Before, all the thermals were processed in order, and the last one overwrote
the prior one. Now, only the data from the nearest thermal is kept. This
way a tile can be populated with many thermals, and (as long as they have the
same diameter) the one nearest the airplane correctly takes effect. This
will make us ready for the next step, "auto-thermaling", where FlightGear's
tile manager can cover a tile with thermals, and set the thermal strength
based on land-use type.
I moved the enumerated object_type to the base class. When an AI object is
created it now sets the _otype variable in the base class. This lets the AI
manager find out what kind of AI object it is dealing with, using the base
pointer. I also added a function isa() to the base class, so the manager can
process objects differently based on their type.
The AI manager now sends AIThermal processing to a different function, where
only the data from the nearest thermal is kept. After the manager processes
all the AI objects, then the results from the nearest thermal are applied to
wind-from-down.
2004-03-07 12:08:46 +00:00
|
|
|
strength = factor = 0.0;
|
2004-03-03 20:26:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FGAIThermal::~FGAIThermal() {
|
|
|
|
}
|
|
|
|
|
2006-02-11 13:16:56 +00:00
|
|
|
void FGAIThermal::readFromScenario(SGPropertyNode* scFileNode) {
|
|
|
|
if (!scFileNode)
|
|
|
|
return;
|
|
|
|
|
|
|
|
FGAIBase::readFromScenario(scFileNode);
|
|
|
|
|
|
|
|
setMaxStrength(scFileNode->getDoubleValue("strength-fps", 8.0));
|
|
|
|
setDiameter(scFileNode->getDoubleValue("diameter-ft", 0.0)/6076.11549);
|
|
|
|
setHeight(scFileNode->getDoubleValue("height-msl", 5000.0));
|
|
|
|
}
|
2004-03-03 20:26:06 +00:00
|
|
|
|
2007-01-13 16:04:28 +00:00
|
|
|
bool FGAIThermal::init(bool search_in_AI_path) {
|
David Culp:
I added some things to the AI stuff to improve the AIThermal processing.
Before, all the thermals were processed in order, and the last one overwrote
the prior one. Now, only the data from the nearest thermal is kept. This
way a tile can be populated with many thermals, and (as long as they have the
same diameter) the one nearest the airplane correctly takes effect. This
will make us ready for the next step, "auto-thermaling", where FlightGear's
tile manager can cover a tile with thermals, and set the thermal strength
based on land-use type.
I moved the enumerated object_type to the base class. When an AI object is
created it now sets the _otype variable in the base class. This lets the AI
manager find out what kind of AI object it is dealing with, using the base
pointer. I also added a function isa() to the base class, so the manager can
process objects differently based on their type.
The AI manager now sends AIThermal processing to a different function, where
only the data from the nearest thermal is kept. After the manager processes
all the AI objects, then the results from the nearest thermal are applied to
wind-from-down.
2004-03-07 12:08:46 +00:00
|
|
|
factor = 8.0 * max_strength / (diameter * diameter * diameter);
|
2006-05-02 01:19:02 +00:00
|
|
|
setAltitude( height );
|
2007-01-13 16:04:28 +00:00
|
|
|
return FGAIBase::init(search_in_AI_path);
|
2004-03-03 20:26:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FGAIThermal::bind() {
|
|
|
|
FGAIBase::bind();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FGAIThermal::unbind() {
|
|
|
|
FGAIBase::unbind();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FGAIThermal::update(double dt) {
|
2004-06-11 13:49:07 +00:00
|
|
|
FGAIBase::update(dt);
|
2004-03-03 20:26:06 +00:00
|
|
|
Run(dt);
|
|
|
|
Transform();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FGAIThermal::Run(double dt) {
|
|
|
|
|
|
|
|
//###########################//
|
|
|
|
// do calculations for range //
|
|
|
|
//###########################//
|
|
|
|
|
|
|
|
// copy values from the AIManager
|
|
|
|
double user_latitude = manager->get_user_latitude();
|
|
|
|
double user_longitude = manager->get_user_longitude();
|
2004-11-07 14:46:21 +00:00
|
|
|
double user_altitude = manager->get_user_altitude();
|
2004-03-03 20:26:06 +00:00
|
|
|
|
|
|
|
// calculate range to target in feet and nautical miles
|
2006-06-15 08:29:43 +00:00
|
|
|
double lat_range = fabs(pos.getLatitudeDeg() - user_latitude) * ft_per_deg_lat;
|
|
|
|
double lon_range = fabs(pos.getLongitudeDeg() - user_longitude) * ft_per_deg_lon;
|
2004-06-12 11:37:47 +00:00
|
|
|
double range_ft = sqrt(lat_range*lat_range + lon_range*lon_range);
|
2004-03-03 20:26:06 +00:00
|
|
|
range = range_ft / 6076.11549;
|
|
|
|
|
David Culp:
I added some things to the AI stuff to improve the AIThermal processing.
Before, all the thermals were processed in order, and the last one overwrote
the prior one. Now, only the data from the nearest thermal is kept. This
way a tile can be populated with many thermals, and (as long as they have the
same diameter) the one nearest the airplane correctly takes effect. This
will make us ready for the next step, "auto-thermaling", where FlightGear's
tile manager can cover a tile with thermals, and set the thermal strength
based on land-use type.
I moved the enumerated object_type to the base class. When an AI object is
created it now sets the _otype variable in the base class. This lets the AI
manager find out what kind of AI object it is dealing with, using the base
pointer. I also added a function isa() to the base class, so the manager can
process objects differently based on their type.
The AI manager now sends AIThermal processing to a different function, where
only the data from the nearest thermal is kept. After the manager processes
all the AI objects, then the results from the nearest thermal are applied to
wind-from-down.
2004-03-07 12:08:46 +00:00
|
|
|
// Calculate speed of rising air if within range.
|
2004-03-03 20:26:06 +00:00
|
|
|
// Air vertical speed is maximum at center of thermal,
|
|
|
|
// and decreases to zero at the edge (as distance cubed).
|
|
|
|
if (range < (diameter * 0.5)) {
|
David Culp:
I added some things to the AI stuff to improve the AIThermal processing.
Before, all the thermals were processed in order, and the last one overwrote
the prior one. Now, only the data from the nearest thermal is kept. This
way a tile can be populated with many thermals, and (as long as they have the
same diameter) the one nearest the airplane correctly takes effect. This
will make us ready for the next step, "auto-thermaling", where FlightGear's
tile manager can cover a tile with thermals, and set the thermal strength
based on land-use type.
I moved the enumerated object_type to the base class. When an AI object is
created it now sets the _otype variable in the base class. This lets the AI
manager find out what kind of AI object it is dealing with, using the base
pointer. I also added a function isa() to the base class, so the manager can
process objects differently based on their type.
The AI manager now sends AIThermal processing to a different function, where
only the data from the nearest thermal is kept. After the manager processes
all the AI objects, then the results from the nearest thermal are applied to
wind-from-down.
2004-03-07 12:08:46 +00:00
|
|
|
strength = max_strength - ( range * range * range * factor );
|
2004-03-03 20:26:06 +00:00
|
|
|
} else {
|
David Culp:
I added some things to the AI stuff to improve the AIThermal processing.
Before, all the thermals were processed in order, and the last one overwrote
the prior one. Now, only the data from the nearest thermal is kept. This
way a tile can be populated with many thermals, and (as long as they have the
same diameter) the one nearest the airplane correctly takes effect. This
will make us ready for the next step, "auto-thermaling", where FlightGear's
tile manager can cover a tile with thermals, and set the thermal strength
based on land-use type.
I moved the enumerated object_type to the base class. When an AI object is
created it now sets the _otype variable in the base class. This lets the AI
manager find out what kind of AI object it is dealing with, using the base
pointer. I also added a function isa() to the base class, so the manager can
process objects differently based on their type.
The AI manager now sends AIThermal processing to a different function, where
only the data from the nearest thermal is kept. After the manager processes
all the AI objects, then the results from the nearest thermal are applied to
wind-from-down.
2004-03-07 12:08:46 +00:00
|
|
|
strength = 0.0;
|
2004-03-03 20:26:06 +00:00
|
|
|
}
|
2004-11-07 14:46:21 +00:00
|
|
|
|
|
|
|
// Stop lift at the top of the thermal (smoothly)
|
|
|
|
if (user_altitude > (height + 100.0)) {
|
|
|
|
strength = 0.0;
|
|
|
|
}
|
|
|
|
else if (user_altitude < height) {
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
strength -= (strength * (user_altitude - height) * 0.01);
|
|
|
|
}
|
2004-03-03 20:26:06 +00:00
|
|
|
}
|
|
|
|
|