1
0
Fork 0

find waypoints in the flight plan.

This commit is contained in:
James Turner 2014-11-28 22:00:38 +00:00
parent 71eba5e579
commit d806b68706
3 changed files with 34 additions and 0 deletions

View file

@ -358,6 +358,17 @@ int FlightPlan::findWayptIndex(const SGGeod& aPos) const
return -1;
}
int FlightPlan::findWayptIndex(const FGPositionedRef aPos) const
{
for (int i=0; i<numLegs(); ++i) {
if (_legs[i]->waypoint()->source() == aPos) {
return i;
}
}
return -1;
}
FlightPlan::Leg* FlightPlan::currentLeg() const
{

View file

@ -152,6 +152,7 @@ public:
int findLegIndex(const Leg* l) const;
int findWayptIndex(const SGGeod& aPos) const;
int findWayptIndex(const FGPositionedRef aPos) const;
bool load(const SGPath& p);
bool save(const SGPath& p);

View file

@ -2213,6 +2213,27 @@ static naRef f_flightplan_finish(naContext c, naRef me, int argc, naRef* args)
return naNil();
}
static naRef f_flightplan_indexOfWp(naContext c, naRef me, int argc, naRef* args)
{
FlightPlan* fp = flightplanGhost(me);
if (!fp) {
naRuntimeError(c, "flightplan.indexOfWP called on non-flightplan object");
}
FGPositioned* positioned = positionedGhost(args[0]);
if (positioned) {
return naNum(fp->findWayptIndex(positioned));
}
SGGeod pos;
int argOffset = geodFromArgs(args, 0, argc, pos);
if (argOffset > 0) {
return naNum(fp->findWayptIndex(pos));
}
return naNum(-1);
}
static naRef f_leg_setSpeed(naContext c, naRef me, int argc, naRef* args)
{
FlightPlan::Leg* leg = fpLegGhost(me);
@ -2479,6 +2500,7 @@ naRef initNasalPositioned(naRef globals, naContext c)
hashset(c, flightplanPrototype, "clone", naNewFunc(c, naNewCCode(c, f_flightplan_clone)));
hashset(c, flightplanPrototype, "pathGeod", naNewFunc(c, naNewCCode(c, f_flightplan_pathGeod)));
hashset(c, flightplanPrototype, "finish", naNewFunc(c, naNewCCode(c, f_flightplan_finish)));
hashset(c, flightplanPrototype, "indexOfWP", naNewFunc(c, naNewCCode(c, f_flightplan_indexOfWp)));
waypointPrototype = naNewHash(c);
naSave(c, waypointPrototype);