示例#1
0
int
FindNearestWayPoint(const WayPointList &way_points,
                    MapWindowProjection &map_projection,
                    const GEOPOINT &loc,
                    double MaxRange,
                    bool exhaustive)
{
  int NearestIndex = -1;
  double NearestDistance, Dist;

  NearestDistance = MaxRange;
  for (unsigned i = 0; way_points.verify_index(i); ++i) {

    if (way_points.get_calc(i).Visible) {

      if (map_projection.WaypointInScaleFilter(i)) {

        // only look for visible waypoints
        // feature added by Samuel Gisiger
        Dist = Distance(loc, way_points.get(i).Location);
        if(Dist < NearestDistance) {
          NearestIndex = i;
          NearestDistance = Dist;
        }
      }
    }
  }

  // JMW allow exhaustive check for when looking up in status dialog
  if (exhaustive && (NearestIndex == -1)) {
    for (unsigned i = 0; way_points.verify_index(i); ++i) {
      Dist = Distance(loc, way_points.get(i).Location);
      if(Dist < NearestDistance) {
        NearestIndex = i;
        NearestDistance = Dist;
      }
    }
  }

  if(NearestDistance < MaxRange)
    return NearestIndex;
  else
    return -1;
}
示例#2
0
int
FindMatchingWaypoint(const WayPointList &way_points, WAYPOINT *waypoint)
{
  // first scan, lookup by name
  for (unsigned i = 0; way_points.verify_index(i); ++i) {
    if (_tcscmp(waypoint->Name, way_points.get(i).Name)==0) {
      return i;
    }
  }
  // second scan, lookup by location
  for (unsigned i = 0; way_points.verify_index(i); ++i) {
    const WAYPOINT &wpi = way_points.get(i);

    if ((fabs(waypoint->Location.Latitude - wpi.Location.Latitude)<1.0e-6)
        && (fabs(waypoint->Location.Longitude - wpi.Location.Longitude)<1.0e-6)) {
      return i;
    }
  }

  return -1;
}
示例#3
0
void
SetHome(const WayPointList &way_points, RasterTerrain &terrain,
        SETTINGS_COMPUTER &settings,
        const bool reset, const bool set_location)
{
  StartupStore(TEXT("SetHome\n"));

  // check invalid home waypoint or forced reset due to file change
  // VENTA3
  if (reset || !way_points.verify_index(0) ||
      !way_points.verify_index(settings.HomeWaypoint)) {
    settings.HomeWaypoint = -1;
  }
  // VENTA3 -- reset Alternates
  if (reset
      || !way_points.verify_index(settings.Alternate1)
      || !way_points.verify_index(settings.Alternate2)) {
    settings.Alternate1= -1;
    settings.Alternate2= -1;
  }
  // check invalid task ref waypoint or forced reset due to file change
  if (reset || !way_points.verify_index(settings.TeamCodeRefWaypoint)) {
    settings.TeamCodeRefWaypoint = -1;
  }

  if (!way_points.verify_index(settings.HomeWaypoint)) {
    // search for home in waypoint list, if we don't have a home
    settings.HomeWaypoint = -1;
    for (unsigned i = 0; way_points.verify_index(i); ++i)
      {
        if ((way_points.get(i).Flags & HOME) == HOME)
          {
            if (settings.HomeWaypoint== -1) {
              settings.HomeWaypoint = i;
	      break; // only search for one
            }
          }
      }
  }
  // set team code reference waypoint if we don't have one
  if (settings.TeamCodeRefWaypoint== -1) {
    settings.TeamCodeRefWaypoint =
      settings.HomeWaypoint;
  }

  if (set_location) {
    if (way_points.verify_index(settings.HomeWaypoint)) {
      // OK, passed all checks now
      StartupStore(TEXT("Start at home waypoint\n"));
      const WAYPOINT &home = way_points.get(settings.HomeWaypoint);
      device_blackboard.SetStartupLocation(home.Location, home.Altitude);
    } else {

      // no home at all, so set it from center of terrain if available
      GEOPOINT loc;
      if (terrain.GetTerrainCenter(&loc)) {
	StartupStore(TEXT("Start at terrain center\n"));
	device_blackboard.SetStartupLocation(loc, 0);
      }
    }
  }

  //
  // Save the home waypoint number in the resgistry
  //
  // VENTA3> this is probably useless, since HomeWayPoint &c were currently
  //         just loaded from registry.
  SetToRegistry(szRegistryHomeWaypoint,settings.HomeWaypoint);
  SetToRegistry(szRegistryAlternate1,settings.Alternate1);
  SetToRegistry(szRegistryAlternate2,settings.Alternate2);
  SetToRegistry(szRegistryTeamcodeRefWaypoint,settings.TeamCodeRefWaypoint);
}