/************************************************************ * Provádí instrukce autopilota při přiblížení na letiště * **********************************************************/ public void approach(Airport airport) { float distanceOnAxis = airport.GetDistanceOnAxis((float)this.X, (float)this.Y); if (distanceOnAxis < 2.0 && !isLanding) { cancelApproach(); } else { Vector2 navigationPoint = distanceOnAxis > 12 ? airport.GetPointOnAxis(10) : airport.GetPointOnAxis(distanceOnAxis - 2); navX = navigationPoint.X; navY = navigationPoint.Y; WantedDir = Main.getCourse((float)this.X, (float)this.Y, navigationPoint.X, navigationPoint.Y); // sestupová fáze if (distanceOnAxis <= 10.0) { if (airport.GetAngleFromAxis((float)this.X, (float)this.Y) <= 2.5) { IsDescendingToRunway = true; } if (IsDescendingToRunway) // Tento a ten horní IF musí zůstat oddělené, jinak nefunguje správně sestup na výšku 0 { int newWantedAlt = (int)MathHelper.Lerp(3000, 0, 1.0f - distanceOnAxis / 10.0f); wantedAlt = newWantedAlt < wantedAlt ? newWantedAlt : wantedAlt; if (wantedAlt < 0) { wantedAlt = 0; } } } if (distanceOnAxis <= 5.0) { if (airport.GetAngleFromAxis((float)this.X, (float)this.Y) <= 2.5 && CheckLandingAvailability(airport)) { IsLanding = true; } if (IsLanding) // Tento a ten horní IF musí zůstat oddělené! { int newWantedSpeed = (int)MathHelper.Lerp(200, 130, 1.0f - distanceOnAxis / 5.0f); wantedSpeed = newWantedSpeed < wantedSpeed ? newWantedSpeed : wantedSpeed; if (wantedSpeed < 130) { wantedSpeed = 130; } } } // Runway touch if (!this.falling && Alt == 0) { wantedSpeed = (int)MathHelper.Lerp(130, 100, distanceOnAxis == 0 ? 0 : -distanceOnAxis / (float)airport.Length); } // Landing finished if (-distanceOnAxis > 0.5 * airport.Length) { if (isLanding && Alt == 0) { landed = true; } else { cancelApproach(); } } } }