1
0
Fork 0

Code cleanup of AIModels (mainly AIAircraft), by Thomas Foerster

This commit is contained in:
durk 2007-06-09 11:49:16 +00:00
parent dbdfc9012b
commit ba8ed137cf
9 changed files with 1073 additions and 822 deletions

File diff suppressed because it is too large Load diff

View file

@ -62,7 +62,7 @@ public:
virtual void readFromScenario(SGPropertyNode* scFileNode);
virtual bool init(bool search_in_AI_path=false);
// virtual bool init(bool search_in_AI_path=false);
virtual void bind();
virtual void unbind();
virtual void update(double dt);
@ -81,7 +81,6 @@ public:
void TurnTo(double heading);
void ProcessFlightPlan( double dt, time_t now );
void setCallSign(const string& );
void setTACANChannelID(const string& );
void getGroundElev(double dt);
void doGroundAltitude();
@ -93,9 +92,11 @@ public:
void announcePositionToController();
void processATC(FGATCInstruction instruction);
inline void SetTanker(bool setting) { isTanker = setting; };
virtual const char* getTypeString(void) const { return "aircraft"; }
protected:
void Run(double dt);
private:
FGAISchedule *trafficRef;
FGATCController *controller, *prevController;
@ -112,9 +113,25 @@ private:
const PERF_STRUCT *performance;
bool use_perf_vs;
SGPropertyNode_ptr refuel_node;
bool isTanker;
void Run(double dt);
// helpers for Run
bool fpExecutable(time_t now);
void handleFirstWaypoint(void);
bool leadPointReached(FGAIFlightPlan::waypoint* curr);
bool handleAirportEndPoints(FGAIFlightPlan::waypoint* prev, time_t now);
bool aiTrafficVisible(void);
void controlHeading(FGAIFlightPlan::waypoint* curr);
void controlSpeed(FGAIFlightPlan::waypoint* curr,
FGAIFlightPlan::waypoint* next);
bool updateTargetValues();
void adjustSpeed(double tgt_speed);
void updatePosition();
void updateHeading();
void updateBankAngles();
void updateAltitudes();
void updateVerticalSpeed();
void matchPitchAngle();
double sign(double x);
string acType;
@ -124,13 +141,11 @@ private:
double prevSpeed;
double prev_dist_to_go;
bool holdPos;
bool holdPos;
bool _getGearDown() const;
bool reachedWaypoint;
string callsign; // The callsign of this tanker.
string TACAN_channel_id; // The TACAN channel of this tanker
bool contact; // set if this tanker is within fuelling range
};

View file

@ -349,6 +349,7 @@ void FGAIFlightPlan::IncrementWaypoint(bool eraseWaypoints )
}
else
wpt_iterator++;
}
// gives distance in feet from a position to a waypoint

View file

@ -102,7 +102,7 @@ public:
FGTaxiRoute *getTaxiRoute() { return taxiRoute; };
void deleteTaxiRoute();
string getRunway() { return activeRunway; };
bool isActive(time_t time) {return time >= this->getStartTime();};
private:
FGRunway rwy;

View file

@ -32,6 +32,7 @@
#include "AICarrier.hxx"
#include "AIStatic.hxx"
#include "AIMultiplayer.hxx"
#include "AITanker.hxx"
#include <simgear/math/sg_geodesy.hxx>
@ -262,7 +263,11 @@ FGAIManager::processScenario( const string &filename ) {
continue;
std::string type = scEntry->getStringValue("type", "aircraft");
if (type == "aircraft") {
if (type == "tanker") { // refueling scenarios
FGAITanker* aircraft = new FGAITanker;
aircraft->readFromScenario(scEntry);
attach(aircraft);
} else if (type == "aircraft") {
FGAIAircraft* aircraft = new FGAIAircraft;
aircraft->readFromScenario(scEntry);
attach(aircraft);

72
src/AIModel/AITanker.cxx Normal file
View file

@ -0,0 +1,72 @@
// AITanker.cxx Based on David Culp's AIModel code
// - Tanker specific code isolated from AI Aircraft code
// by Thomas Foerster, started June 2007
//
//
// Original code written by David Culp, started October 2003.
// - 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "AITanker.hxx"
FGAITanker::FGAITanker(FGAISchedule* ref): FGAIAircraft(ref){
}
FGAITanker::~FGAITanker() {}
void FGAITanker::readFromScenario(SGPropertyNode* scFileNode) {
if (!scFileNode)
return;
FGAIAircraft::readFromScenario(scFileNode);
setTACANChannelID(scFileNode->getStringValue("TACAN-channel-ID"));
}
void FGAITanker::bind() {
FGAIAircraft::bind();
props->tie("refuel/contact", SGRawValuePointer<bool>(&contact));
props->setStringValue("navaids/tacan/channel-ID", TACAN_channel_id.c_str());
props->setBoolValue("tanker", true);
}
void FGAITanker::unbind() {
FGAIAircraft::unbind();
props->untie("refuel/contact");
}
void FGAITanker::setTACANChannelID(const string& id) {
TACAN_channel_id = id;
}
void FGAITanker::Run(double dt) {
FGAIAircraft::Run(dt);
//###########################//
// do calculations for radar //
//###########################//
double range_ft2 = UpdateRadar(manager);
// check if radar contact
if ( (range_ft2 < 250.0 * 250.0) && (y_shift > 0.0)
&& (elevation > 0.0) ) {
//refuel_node->setBoolValue(true);
contact = true;
} else {
//refuel_node->setBoolValue(false);
contact = false;
}
}

58
src/AIModel/AITanker.hxx Normal file
View file

@ -0,0 +1,58 @@
// AITanker.hxx Based on David Culp's AIModel code
// - Tanker specific code isolated from AI Aircraft code
// by Thomas Foerster, started June 2007
//
//
// Original code written by David Culp, started October 2003.
// - 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#ifndef FGAITANKER_HXX
#define FGAITANKER_HXX
#include <AIAircraft.hxx>
/**
* An AI tanker for air-air refueling.
*
* This class is just a refactoring of the AA refueling related code in FGAIAircraft. The idea
* is to have a clean generic AIAircraft class without any special functionality. In your
* scenario specification use 'tanker' as the scenario type to use this class.
*
* @author Thomas Förster <t.foerster@biologie.hu-berlin.de>
*/
class FGAITanker : public FGAIAircraft {
public:
FGAITanker(FGAISchedule* ref = 0);
~FGAITanker();
virtual void readFromScenario(SGPropertyNode* scFileNode);
virtual void bind();
virtual void unbind();
virtual const char* getTypeString(void) const { return "tanker"; }
void setTACANChannelID(const string& id);
private:
string TACAN_channel_id; // The TACAN channel of this tanker
bool contact; // set if this tanker is within fuelling range
virtual void Run(double dt);
};
#endif

View file

@ -1,18 +1,19 @@
noinst_LIBRARIES = libAIModel.a
libAIModel_a_SOURCES = \
submodel.cxx submodel.hxx \
libAIModel_a_SOURCES = submodel.cxx submodel.hxx \
AIManager.hxx AIManager.cxx \
AIBase.hxx AIBase.cxx \
AIAircraft.hxx AIAircraft.cxx \
AIMultiplayer.hxx AIMultiplayer.cxx \
AIAircraft.hxx AIAircraft.cxx AIMultiplayer.hxx \
AIMultiplayer.cxx \
AIShip.hxx AIShip.cxx \
AIBallistic.hxx AIBallistic.cxx \
AIStorm.hxx AIStorm.cxx \
AIThermal.hxx AIThermal.cxx \
AIFlightPlan.hxx AIFlightPlan.cxx \
AIFlightPlanCreate.cxx AIFlightPlanCreateCruise.cxx \
AICarrier.hxx AICarrier.cxx \
AIStatic.hxx AIStatic.cxx
AIFlightPlanCreate.cxx \
AIFlightPlanCreateCruise.cxx \
AICarrier.hxx AICarrier.cxx \
AIStatic.hxx AIStatic.cxx \
AITanker.cxx AITanker.hxx
INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src

View file

@ -1,8 +1,5 @@
/* Special single config.h for MSVC8 build */
#define ENABLE_OSGVIEWER
#define PU_USE_NATIVE
/* Special single config.h for MSVC6 build - Geoff McLane - 23 July, 2003 */
/* Define to enable plib joystick support */
#ifndef ENABLE_PLIB_JOYSTICK