1
0
Fork 0

Maintenance: AIFlightPlan

shortenToFirst() 'name' parameter to const&.
use const functions when appropriate.
This commit is contained in:
scttgs0 2023-05-21 20:31:52 -05:00
parent 6284ab6268
commit 4413bcc7ed
2 changed files with 243 additions and 245 deletions

View file

@ -9,8 +9,8 @@
#include <config.h>
#endif
#include <iterator>
#include <algorithm>
#include <iterator>
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
@ -22,25 +22,26 @@
#include <simgear/structure/exception.hxx>
#include <simgear/timing/sg_time.hxx>
#include <Main/globals.hxx>
#include <Main/fg_props.hxx>
#include <Main/fg_init.hxx>
#include <Airports/airport.hxx>
#include <Airports/dynamics.hxx>
#include <Airports/runways.hxx>
#include <Airports/groundnetwork.hxx>
#include <Airports/runways.hxx>
#include <Main/fg_init.hxx>
#include <Main/fg_props.hxx>
#include <Main/globals.hxx>
#include <Environment/environment_mgr.hxx>
#include <Environment/environment.hxx>
#include <Environment/environment_mgr.hxx>
#include <Traffic/Schedule.hxx>
#include "AIFlightPlan.hxx"
#include "AIAircraft.hxx"
#include "AIFlightPlan.hxx"
using std::string;
FGAIWaypoint::FGAIWaypoint() {
FGAIWaypoint::FGAIWaypoint()
{
speed = 0;
crossat = 0;
finished = 0;
@ -52,7 +53,8 @@ FGAIWaypoint::FGAIWaypoint() {
trackLength = 0;
}
bool FGAIWaypoint::contains(const string& target) {
bool FGAIWaypoint::contains(const string& target)
{
size_t found = name.find(target);
if (found == string::npos)
return false;
@ -60,17 +62,17 @@ bool FGAIWaypoint::contains(const string& target) {
return true;
}
double FGAIWaypoint::getLatitude()
double FGAIWaypoint::getLatitude() const
{
return pos.getLatitudeDeg();
}
double FGAIWaypoint::getLongitude()
double FGAIWaypoint::getLongitude() const
{
return pos.getLongitudeDeg();
}
double FGAIWaypoint::getAltitude()
double FGAIWaypoint::getAltitude() const
{
return pos.getElevationFt();
}
@ -90,8 +92,7 @@ void FGAIWaypoint::setAltitude(double alt)
pos.setElevationFt(alt);
}
FGAIFlightPlan::FGAIFlightPlan() :
sid(NULL),
FGAIFlightPlan::FGAIFlightPlan() : sid(NULL),
repeat(false),
distance_to_go(0),
lead_distance_ft(0),
@ -105,8 +106,7 @@ FGAIFlightPlan::FGAIFlightPlan() :
wpt_iterator = waypoints.begin();
}
FGAIFlightPlan::FGAIFlightPlan(const string& filename) :
sid(NULL),
FGAIFlightPlan::FGAIFlightPlan(const string& filename) : sid(NULL),
repeat(false),
distance_to_go(0),
lead_distance_ft(0),
@ -143,8 +143,7 @@ FGAIFlightPlan::FGAIFlightPlan(FGAIAircraft *ac,
double speed,
const string& fltType,
const string& acType,
const string& airline) :
sid(NULL),
const string& airline) : sid(NULL),
repeat(false),
distance_to_go(0),
lead_distance_ft(0),
@ -203,8 +202,7 @@ void FGAIFlightPlan::createWaypoints(FGAIAircraft *ac,
}
}
SG_LOG(SG_AI, SG_DEBUG, ac->getTrafficRef()->getCallSign() << "|Route from " << dep->getId() << " to " << arr->getId() <<
". Set leg to : " << leg << " " << remainingTime);
SG_LOG(SG_AI, SG_DEBUG, ac->getTrafficRef()->getCallSign() << "|Route from " << dep->getId() << " to " << arr->getId() << ". Set leg to : " << leg << " " << remainingTime);
wpt_iterator = waypoints.begin();
bool dist = 0;
@ -307,7 +305,7 @@ bool FGAIFlightPlan::readFlightplan(std::istream& stream, const sg_location& loc
return true;
}
FGAIWaypoint* FGAIFlightPlan::getLastWaypoint()
FGAIWaypoint* FGAIFlightPlan::getLastWaypoint() const
{
if (waypoints.empty())
return nullptr;
@ -315,7 +313,7 @@ FGAIWaypoint* FGAIFlightPlan::getLastWaypoint()
return waypoints.back();
};
FGAIWaypoint* FGAIFlightPlan::getPreviousWaypoint( void ) const
FGAIWaypoint* FGAIFlightPlan::getPreviousWaypoint() const
{
if (empty())
return nullptr;
@ -328,14 +326,14 @@ FGAIWaypoint* FGAIFlightPlan::getPreviousWaypoint( void ) const
}
}
FGAIWaypoint* FGAIFlightPlan::getCurrentWaypoint( void ) const
FGAIWaypoint* FGAIFlightPlan::getCurrentWaypoint() const
{
if (wpt_iterator == waypoints.end())
return nullptr;
return *wpt_iterator;
}
FGAIWaypoint* FGAIFlightPlan::getNextWaypoint( void ) const
FGAIWaypoint* FGAIFlightPlan::getNextWaypoint() const
{
if (wpt_iterator == waypoints.end())
return nullptr;
@ -348,7 +346,7 @@ FGAIWaypoint* FGAIFlightPlan::getNextWaypoint( void ) const
}
}
int FGAIFlightPlan::getNextTurnAngle( void ) const
int FGAIFlightPlan::getNextTurnAngle() const
{
return nextTurnAngle;
}
@ -359,20 +357,16 @@ void FGAIFlightPlan::IncrementWaypoint(bool eraseWaypoints )
if (empty())
return;
if (eraseWaypoints)
{
if (eraseWaypoints) {
if (wpt_iterator == waypoints.begin())
++wpt_iterator;
else
if (!waypoints.empty())
{
else if (!waypoints.empty()) {
delete *(waypoints.begin());
waypoints.erase(waypoints.begin());
wpt_iterator = waypoints.begin();
++wpt_iterator;
}
}
else {
} else {
++wpt_iterator;
}
// Calculate the angle of the next turn.
@ -413,13 +407,14 @@ void FGAIFlightPlan::eraseLastWaypoint()
return;
delete (waypoints.back());
waypoints.pop_back();;
waypoints.pop_back();
wpt_iterator = waypoints.begin();
++wpt_iterator;
}
// gives distance in meters from a position to a waypoint
double FGAIFlightPlan::getDistanceToGo(double lat, double lon, FGAIWaypoint* wp) const{
double FGAIFlightPlan::getDistanceToGo(double lat, double lon, FGAIWaypoint* wp) const
{
return SGGeodesy::distanceM(SGGeod::fromDeg(lon, lat), wp->getPos());
}
@ -430,7 +425,8 @@ double FGAIFlightPlan::getDistanceToGo(double lat, double lon, FGAIWaypoint* wp)
void FGAIFlightPlan::setLeadDistance(double speed,
double bearing,
FGAIWaypoint* current,
FGAIWaypoint* next){
FGAIWaypoint* next)
{
double turn_radius_m;
// Handle Ground steering
// At a turn rate of 30 degrees per second, it takes 12 seconds to do a full 360 degree turn
@ -491,7 +487,8 @@ void FGAIFlightPlan::setLeadDistance(double speed,
}*/
}
void FGAIFlightPlan::setLeadDistance(double distance_ft){
void FGAIFlightPlan::setLeadDistance(double distance_ft)
{
lead_distance_ft = distance_ft;
if (lead_distance_ft > 10000) {
SG_LOG(SG_AI, SG_BULK, "Excessive Leaddistance " << distance_ft);
@ -582,15 +579,16 @@ void FGAIFlightPlan::restart()
wpt_iterator = waypoints.begin();
}
int FGAIFlightPlan::getRouteIndex(int i) {
int FGAIFlightPlan::getRouteIndex(int i) const
{
if ((i > 0) && (i < (int)waypoints.size())) {
return waypoints[i]->getRouteIndex();
}
else
} else
return 0;
}
double FGAIFlightPlan::checkTrackLength(const string& wptName) const {
double FGAIFlightPlan::checkTrackLength(const string& wptName) const
{
// skip the first two waypoints: first one is behind, second one is partially done;
double trackDistance = 0;
wpt_vector_iterator wptvec = waypoints.begin();
@ -609,7 +607,7 @@ double FGAIFlightPlan::checkTrackLength(const string& wptName) const {
return trackDistance;
}
void FGAIFlightPlan::shortenToFirst(unsigned int number, string name)
void FGAIFlightPlan::shortenToFirst(unsigned int number, const std::string& name)
{
while (waypoints.size() > number + 3) {
eraseLastWaypoint();
@ -622,7 +620,7 @@ void FGAIFlightPlan::setGate(const ParkingAssignment& pka)
gate = pka;
}
FGParking* FGAIFlightPlan::getParkingGate()
FGParking* FGAIFlightPlan::getParkingGate() const
{
return gate.parking();
}

View file

@ -93,9 +93,9 @@ public:
const std::string& getName() { return name; };
const SGGeod& getPos() { return pos; };
double getLatitude();
double getLongitude();
double getAltitude();
double getLatitude() const;
double getLongitude() const;
double getAltitude() const;
double getSpeed() { return speed; };
double getCrossat() { return crossat; };
@ -198,7 +198,7 @@ public:
void restart(void);
int getNrOfWayPoints() { return waypoints.size(); }
int getRouteIndex(int i); // returns the AI related index of this current routes.
int getRouteIndex(int i) const; // returns the AI related index of this current routes.
const std::string& getRunway() { return activeRunway; }
bool isActive(time_t time) { return time >= this->getStartTime(); }
@ -220,12 +220,12 @@ public:
void setSID(FGAIFlightPlan* fp) { sid = fp; };
FGAIFlightPlan* getSID() { return sid; };
FGAIWaypoint* getWayPoint(int i) { return waypoints[i]; };
FGAIWaypoint* getLastWaypoint();
FGAIWaypoint* getLastWaypoint() const;
void shortenToFirst(unsigned int number, std::string name);
void shortenToFirst(unsigned int number, const std::string& name);
void setGate(const ParkingAssignment& pka);
FGParking* getParkingGate();
FGParking* getParkingGate() const;
FGAirportRef departureAirport() const;
FGAirportRef arrivalAirport() const;