public override bool Tick(Actor self) { // Refuse to take off if it would land immediately again. if (aircraft.ForceLanding) { Cancel(self); return(true); } var dat = self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition); if (dat < aircraft.Info.CruiseAltitude) { // If we're a VTOL, rise before flying forward if (aircraft.Info.VTOL) { Fly.VerticalTakeOffOrLandTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude); return(false); } Fly.FlyTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude); return(false); } return(true); }
public override bool Tick(Actor self) { // Refuse to take off if it would land immediately again. if (aircraft.ForceLanding) { Cancel(self); return(true); } var dat = self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition); if (dat < aircraft.Info.CruiseAltitude) { // If we're a VTOL, rise before flying forward if (aircraft.Info.VTOL) { Fly.VerticalTakeOffOrLandTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude); return(false); } Fly.FlyTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude); return(false); } // Only move to the fallback target if we don't have anything better to do if (NextActivity == null && fallbackTarget.IsValidFor(self) && !movedToTarget) { QueueChild(new AttackMoveActivity(self, () => move.MoveToTarget(self, fallbackTarget, targetLineColor: Color.OrangeRed))); movedToTarget = true; return(false); } return(true); }
public override Activity Tick(Actor self) { if (ChildActivity != null) { ChildActivity = ActivityUtils.RunActivity(self, ChildActivity); if (ChildActivity != null) { return(this); } } // Refuse to take off if it would land immediately again. if (aircraft.ForceLanding) { Cancel(self); return(NextActivity); } var dat = self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition); if (dat < aircraft.Info.CruiseAltitude) { // If we're a VTOL, rise before flying forward if (aircraft.Info.VTOL) { Fly.VerticalTakeOffOrLandTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude); return(this); } else { Fly.FlyTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude); return(this); } } // Checking for NextActivity == null again in case another activity was queued while taking off if (moveToRallyPoint && NextActivity == null) { QueueChild(self, new AttackMoveActivity(self, () => move.MoveToTarget(self, target)), true); moveToRallyPoint = false; return(this); } return(NextActivity); }
public override bool Tick(Actor self) { // Refuse to take off if it would land immediately again. if (aircraft.ForceLanding) { Cancel(self); } var dat = self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition); var isLanded = dat <= aircraft.LandAltitude; // HACK: Prevent paused (for example, EMP'd) aircraft from taking off. // This is necessary until the TODOs in the IsCanceling block below are adressed. if (isLanded && aircraft.IsTraitPaused) { return(false); } if (IsCanceling) { // We must return the actor to a sensible height before continuing. // If the aircraft is on the ground we queue TakeOff to manage the influence reservation and takeoff sounds etc. // TODO: It would be better to not take off at all, but we lack the plumbing to detect current airborne/landed state. // If the aircraft lands when idle and is idle, we let the default idle handler manage this. // TODO: Remove this after fixing all activities to work properly with arbitrary starting altitudes. var landWhenIdle = aircraft.Info.IdleBehavior == IdleBehaviorType.Land; var skipHeightAdjustment = landWhenIdle && self.CurrentActivity.IsCanceling && self.CurrentActivity.NextActivity == null; if (aircraft.Info.CanHover && !skipHeightAdjustment && dat != aircraft.Info.CruiseAltitude) { if (isLanded) { QueueChild(new TakeOff(self)); } else { VerticalTakeOffOrLandTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude); } return(false); } return(true); } else if (isLanded) { QueueChild(new TakeOff(self)); return(false); } bool targetIsHiddenActor; target = target.Recalculate(self.Owner, out targetIsHiddenActor); if (!targetIsHiddenActor && target.Type == TargetType.Actor) { lastVisibleTarget = Target.FromTargetPositions(target); } useLastVisibleTarget = targetIsHiddenActor || !target.IsValidFor(self); // Target is hidden or dead, and we don't have a fallback position to move towards if (useLastVisibleTarget && !lastVisibleTarget.IsValidFor(self)) { return(true); } var checkTarget = useLastVisibleTarget ? lastVisibleTarget : target; var pos = aircraft.GetPosition(); var delta = checkTarget.CenterPosition - pos; // Inside the target annulus, so we're done var insideMaxRange = maxRange.Length > 0 && checkTarget.IsInRange(pos, maxRange); var insideMinRange = minRange.Length > 0 && checkTarget.IsInRange(pos, minRange); if (insideMaxRange && !insideMinRange) { return(true); } var isSlider = aircraft.Info.CanSlide; var desiredFacing = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : aircraft.Facing; var move = isSlider ? aircraft.FlyStep(desiredFacing) : aircraft.FlyStep(aircraft.Facing); // Inside the minimum range, so reverse if we CanSlide, otherwise face away from the target. if (insideMinRange) { if (isSlider) { FlyTick(self, aircraft, desiredFacing, aircraft.Info.CruiseAltitude, -move); } else { desiredFacing = Util.NormalizeFacing(desiredFacing + 128); FlyTick(self, aircraft, desiredFacing, aircraft.Info.CruiseAltitude, move); } return(false); } // HACK: Consider ourselves blocked if we have moved by less than 64 WDist in the last five ticks // Stop if we are blocked and close enough if (positionBuffer.Count >= 5 && (positionBuffer.Last() - positionBuffer[0]).LengthSquared < 4096 && delta.HorizontalLengthSquared <= nearEnough.LengthSquared) { return(true); } // The next move would overshoot, so consider it close enough or set final position if we CanSlide if (delta.HorizontalLengthSquared < move.HorizontalLengthSquared) { // For VTOL landing to succeed, it must reach the exact target position, // so for the final move it needs to behave as if it had CanSlide. if (isSlider || aircraft.Info.VTOL) { // Set final (horizontal) position if (delta.HorizontalLengthSquared != 0) { // Ensure we don't include a non-zero vertical component here that would move us away from CruiseAltitude var deltaMove = new WVec(delta.X, delta.Y, 0); FlyTick(self, aircraft, desiredFacing, dat, deltaMove); } // Move to CruiseAltitude, if not already there if (dat != aircraft.Info.CruiseAltitude) { Fly.VerticalTakeOffOrLandTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude); return(false); } } return(true); } if (!isSlider) { // Using the turn rate, compute a hypothetical circle traced by a continuous turn. // If it contains the destination point, it's unreachable without more complex manuvering. var turnRadius = CalculateTurnRadius(aircraft.MovementSpeed, aircraft.TurnSpeed); // The current facing is a tangent of the minimal turn circle. // Make a perpendicular vector, and use it to locate the turn's center. var turnCenterFacing = aircraft.Facing; turnCenterFacing += Util.GetNearestFacing(aircraft.Facing, desiredFacing) > 0 ? 64 : -64; var turnCenterDir = new WVec(0, -1024, 0).Rotate(WRot.FromFacing(turnCenterFacing)); turnCenterDir *= turnRadius; turnCenterDir /= 1024; // Compare with the target point, and keep flying away if it's inside the circle. var turnCenter = aircraft.CenterPosition + turnCenterDir; if ((checkTarget.CenterPosition - turnCenter).HorizontalLengthSquared < turnRadius * turnRadius) { desiredFacing = aircraft.Facing; } } positionBuffer.Add(self.CenterPosition); if (positionBuffer.Count > 5) { positionBuffer.RemoveAt(0); } FlyTick(self, aircraft, desiredFacing, aircraft.Info.CruiseAltitude); return(false); }
public override bool Tick(Actor self) { if (IsCanceling || target.Type == TargetType.Invalid) { if (landingInitiated) { // We must return the actor to a sensible height before continuing. // If the aircraft lands when idle and is idle, continue landing, // otherwise climb back to CruiseAltitude. // TODO: Remove this after fixing all activities to work properly with arbitrary starting altitudes. var shouldLand = aircraft.Info.IdleBehavior == IdleBehaviorType.Land; var continueLanding = shouldLand && self.CurrentActivity.IsCanceling && self.CurrentActivity.NextActivity == null; if (!continueLanding) { var dat = self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition); if (dat > aircraft.LandAltitude && dat < aircraft.Info.CruiseAltitude) { QueueChild(new TakeOff(self)); return(false); } aircraft.RemoveInfluence(); return(true); } } else { return(true); } } var pos = aircraft.GetPosition(); // Reevaluate target position in case the target has moved. targetPosition = target.CenterPosition + offset; landingCell = self.World.Map.CellContaining(targetPosition); // We are already at the landing location. if ((targetPosition - pos).LengthSquared == 0) { return(true); } // Look for free landing cell if (target.Type == TargetType.Terrain && !landingInitiated) { var newLocation = aircraft.FindLandingLocation(landingCell, landRange); // Cannot land so fly towards the last target location instead. if (!newLocation.HasValue) { QueueChild(aircraft.MoveTo(landingCell, 0)); return(true); } if (newLocation.Value != landingCell) { target = Target.FromCell(self.World, newLocation.Value); targetPosition = target.CenterPosition + offset; landingCell = self.World.Map.CellContaining(targetPosition); } } // Move towards landing location/facing if (aircraft.Info.VTOL) { if ((pos - targetPosition).HorizontalLengthSquared != 0) { QueueChild(new Fly(self, Target.FromPos(targetPosition))); return(false); } else if (desiredFacing != -1 && desiredFacing != aircraft.Facing) { QueueChild(new Turn(self, desiredFacing)); return(false); } } if (!aircraft.Info.VTOL && !finishedApproach) { // Calculate approach trajectory var altitude = aircraft.Info.CruiseAltitude.Length; // Distance required for descent. var landDistance = altitude * 1024 / aircraft.Info.MaximumPitch.Tan(); // Approach landing from the opposite direction of the desired facing // TODO: Calculate sensible trajectory without preferred facing. var rotation = WRot.Zero; if (desiredFacing != -1) { rotation = WRot.FromFacing(desiredFacing); } var approachStart = targetPosition + new WVec(0, landDistance, altitude).Rotate(rotation); // Add 10% to the turning radius to ensure we have enough room var speed = aircraft.MovementSpeed * 32 / 35; var turnRadius = Fly.CalculateTurnRadius(speed, aircraft.Info.TurnSpeed); // Find the center of the turning circles for clockwise and counterclockwise turns var angle = WAngle.FromFacing(aircraft.Facing); var fwd = -new WVec(angle.Sin(), angle.Cos(), 0); // Work out whether we should turn clockwise or counter-clockwise for approach var side = new WVec(-fwd.Y, fwd.X, fwd.Z); var approachDelta = self.CenterPosition - approachStart; var sideTowardBase = new[] { side, -side } .MinBy(a => WVec.Dot(a, approachDelta)); // Calculate the tangent line that joins the turning circles at the current and approach positions var cp = self.CenterPosition + turnRadius * sideTowardBase / 1024; var posCenter = new WPos(cp.X, cp.Y, altitude); var approachCenter = approachStart + new WVec(0, turnRadius * Math.Sign(self.CenterPosition.Y - approachStart.Y), 0); var tangentDirection = approachCenter - posCenter; var tangentLength = tangentDirection.Length; var tangentOffset = WVec.Zero; if (tangentLength != 0) { tangentOffset = new WVec(-tangentDirection.Y, tangentDirection.X, 0) * turnRadius / tangentLength; } // TODO: correctly handle CCW <-> CW turns if (tangentOffset.X > 0) { tangentOffset = -tangentOffset; } var w1 = posCenter + tangentOffset; var w2 = approachCenter + tangentOffset; var w3 = approachStart; turnRadius = Fly.CalculateTurnRadius(aircraft.Info.Speed, aircraft.Info.TurnSpeed); // Move along approach trajectory. QueueChild(new Fly(self, Target.FromPos(w1), WDist.Zero, new WDist(turnRadius * 3))); QueueChild(new Fly(self, Target.FromPos(w2))); // Fix a problem when the airplane is sent to land near the landing cell QueueChild(new Fly(self, Target.FromPos(w3), WDist.Zero, new WDist(turnRadius / 2))); finishedApproach = true; return(false); } if (!landingInitiated) { var blockingCells = clearCells.Append(landingCell); if (!aircraft.CanLand(blockingCells, target.Actor)) { // Maintain holding pattern. QueueChild(new FlyIdle(self, 25)); self.NotifyBlocker(blockingCells); finishedApproach = false; return(false); } if (aircraft.Info.LandingSounds.Length > 0) { Game.Sound.Play(SoundType.World, aircraft.Info.LandingSounds, self.World, aircraft.CenterPosition); } aircraft.AddInfluence(landingCell); aircraft.EnteringCell(self); landingInitiated = true; } // Final descent. if (aircraft.Info.VTOL) { var landAltitude = self.World.Map.DistanceAboveTerrain(targetPosition) + aircraft.LandAltitude; if (Fly.VerticalTakeOffOrLandTick(self, aircraft, aircraft.Facing, landAltitude)) { return(false); } return(true); } var d = targetPosition - pos; // The next move would overshoot, so just set the final position var move = aircraft.FlyStep(aircraft.Facing); if (d.HorizontalLengthSquared < move.HorizontalLengthSquared) { var landingAltVec = new WVec(WDist.Zero, WDist.Zero, aircraft.LandAltitude); aircraft.SetPosition(self, targetPosition + landingAltVec); return(true); } var landingAlt = self.World.Map.DistanceAboveTerrain(targetPosition) + aircraft.LandAltitude; Fly.FlyTick(self, aircraft, d.Yaw.Facing, landingAlt); return(false); }
public override Activity Tick(Actor self) { if (ChildActivity != null) { ChildActivity = ActivityUtils.RunActivity(self, ChildActivity); if (ChildActivity != null) { return(this); } } if (IsCanceling || target.Type == TargetType.Invalid) { // We must return the actor to a sensible height before continuing. // If the aircraft lands when idle and is idle, continue landing, // otherwise climb back to CruiseAltitude. // TODO: Remove this after fixing all activities to work properly with arbitrary starting altitudes. var continueLanding = aircraft.Info.LandWhenIdle && self.CurrentActivity.IsCanceling && self.CurrentActivity.NextActivity == null; if (!continueLanding) { var dat = self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition); if (dat > aircraft.LandAltitude && dat < aircraft.Info.CruiseAltitude) { QueueChild(self, new TakeOff(self), true); return(this); } aircraft.RemoveInfluence(); return(NextActivity); } } if (!landingInitiated) { var landingCell = !aircraft.Info.VTOL ? self.World.Map.CellContaining(target.CenterPosition + offset) : self.Location; if (!aircraft.CanLand(landingCell, target.Actor)) { // Maintain holding pattern. if (!aircraft.Info.CanHover) { QueueChild(self, new FlyCircle(self, 25), true); } self.NotifyBlocker(landingCell); return(this); } aircraft.AddInfluence(landingCell); aircraft.EnteringCell(self); landingInitiated = true; } var altitude = self.World.Map.DistanceAboveTerrain(self.CenterPosition); var landAltitude = self.World.Map.DistanceAboveTerrain(target.CenterPosition + offset) + aircraft.LandAltitude; if (!soundPlayed && aircraft.Info.LandingSounds.Length > 0 && altitude != landAltitude) { Game.Sound.Play(SoundType.World, aircraft.Info.LandingSounds, self.World, aircraft.CenterPosition); soundPlayed = true; } // For VTOLs we assume we've already arrived at the target location and just need to move downward if (aircraft.Info.VTOL) { if (Fly.VerticalTakeOffOrLandTick(self, aircraft, aircraft.Facing, landAltitude)) { return(this); } return(NextActivity); } var d = (target.CenterPosition + offset) - self.CenterPosition; // The next move would overshoot, so just set the final position var move = aircraft.FlyStep(aircraft.Facing); if (d.HorizontalLengthSquared < move.HorizontalLengthSquared) { var landingAltVec = new WVec(WDist.Zero, WDist.Zero, aircraft.LandAltitude); aircraft.SetPosition(self, target.CenterPosition + offset + landingAltVec); return(NextActivity); } var landingAlt = self.World.Map.DistanceAboveTerrain(target.CenterPosition + offset) + aircraft.LandAltitude; Fly.FlyTick(self, aircraft, d.Yaw.Facing, landingAlt); return(this); }
public override Activity Tick(Actor self) { if (ChildActivity != null) { ChildActivity = ActivityUtils.RunActivity(self, ChildActivity); if (ChildActivity != null) { return(this); } } // Refuse to take off if it would land immediately again. if (aircraft.ForceLanding) { Cancel(self); } var dat = self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition); if (IsCanceling) { // We must return the actor to a sensible height before continuing. // If the aircraft is on the ground we queue TakeOff to manage the influence reservation and takeoff sounds etc. // TODO: It would be better to not take off at all, but we lack the plumbing to detect current airborne/landed state. // If the aircraft lands when idle and is idle, we let the default idle handler manage this. // TODO: Remove this after fixing all activities to work properly with arbitrary starting altitudes. var skipHeightAdjustment = aircraft.Info.LandWhenIdle && self.CurrentActivity.IsCanceling && self.CurrentActivity.NextActivity == null; if (aircraft.Info.CanHover && !skipHeightAdjustment && dat != aircraft.Info.CruiseAltitude) { if (dat <= aircraft.LandAltitude) { QueueChild(self, new TakeOff(self, target), true); } else { VerticalTakeOffOrLandTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude); } return(this); } return(NextActivity); } else if (dat <= aircraft.LandAltitude) { QueueChild(self, new TakeOff(self, target), true); return(this); } bool targetIsHiddenActor; target = target.Recalculate(self.Owner, out targetIsHiddenActor); if (!targetIsHiddenActor && target.Type == TargetType.Actor) { lastVisibleTarget = Target.FromTargetPositions(target); } var oldUseLastVisibleTarget = useLastVisibleTarget; useLastVisibleTarget = targetIsHiddenActor || !target.IsValidFor(self); // Update target lines if required if (useLastVisibleTarget != oldUseLastVisibleTarget && targetLineColor.HasValue) { self.SetTargetLine(useLastVisibleTarget ? lastVisibleTarget : target, targetLineColor.Value, false); } // Target is hidden or dead, and we don't have a fallback position to move towards if (useLastVisibleTarget && !lastVisibleTarget.IsValidFor(self)) { return(NextActivity); } var checkTarget = useLastVisibleTarget ? lastVisibleTarget : target; var delta = checkTarget.CenterPosition - self.CenterPosition; var desiredFacing = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : aircraft.Facing; // Inside the target annulus, so we're done var insideMaxRange = maxRange.Length > 0 && checkTarget.IsInRange(aircraft.CenterPosition, maxRange); var insideMinRange = minRange.Length > 0 && checkTarget.IsInRange(aircraft.CenterPosition, minRange); if (insideMaxRange && !insideMinRange) { return(NextActivity); } var move = aircraft.Info.CanHover ? aircraft.FlyStep(desiredFacing) : aircraft.FlyStep(aircraft.Facing); // Inside the minimum range, so reverse if CanHover if (aircraft.Info.CanHover && insideMinRange) { FlyTick(self, aircraft, desiredFacing, aircraft.Info.CruiseAltitude, -move); return(this); } // The next move would overshoot, so consider it close enough or set final position if CanHover if (delta.HorizontalLengthSquared < move.HorizontalLengthSquared) { if (aircraft.Info.CanHover) { // Set final (horizontal) position if (delta.HorizontalLengthSquared != 0) { // Ensure we don't include a non-zero vertical component here that would move us away from CruiseAltitude var deltaMove = new WVec(delta.X, delta.Y, 0); FlyTick(self, aircraft, desiredFacing, dat, deltaMove); } // Move to CruiseAltitude, if not already there if (dat != aircraft.Info.CruiseAltitude) { Fly.VerticalTakeOffOrLandTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude); return(this); } } return(NextActivity); } if (!aircraft.Info.CanHover) { // Using the turn rate, compute a hypothetical circle traced by a continuous turn. // If it contains the destination point, it's unreachable without more complex manuvering. var turnRadius = CalculateTurnRadius(aircraft.MovementSpeed, aircraft.TurnSpeed); // The current facing is a tangent of the minimal turn circle. // Make a perpendicular vector, and use it to locate the turn's center. var turnCenterFacing = aircraft.Facing; turnCenterFacing += Util.GetNearestFacing(aircraft.Facing, desiredFacing) > 0 ? 64 : -64; var turnCenterDir = new WVec(0, -1024, 0).Rotate(WRot.FromFacing(turnCenterFacing)); turnCenterDir *= turnRadius; turnCenterDir /= 1024; // Compare with the target point, and keep flying away if it's inside the circle. var turnCenter = aircraft.CenterPosition + turnCenterDir; if ((checkTarget.CenterPosition - turnCenter).HorizontalLengthSquared < turnRadius * turnRadius) { desiredFacing = aircraft.Facing; } } FlyTick(self, aircraft, desiredFacing, aircraft.Info.CruiseAltitude); return(this); }
public override Activity Tick(Actor self) { if (ChildActivity != null) { ChildActivity = ActivityUtils.RunActivity(self, ChildActivity); if (ChildActivity != null) { return(this); } } // Refuse to take off if it would land immediately again. if (aircraft.ForceLanding) { Cancel(self); } if (IsCanceling) { // Cancel the requested target, but keep firing on it while in range if (attackAircraft.Info.PersistentTargeting) { attackAircraft.OpportunityTarget = attackAircraft.RequestedTarget; attackAircraft.OpportunityForceAttack = attackAircraft.RequestedForceAttack; attackAircraft.OpportunityTargetIsPersistentTarget = true; } attackAircraft.RequestedTarget = Target.Invalid; return(NextActivity); } // Check that AttackFollow hasn't cancelled the target by modifying attack.Target // Having both this and AttackFollow modify that field is a horrible hack. if (hasTicked && attackAircraft.RequestedTarget.Type == TargetType.Invalid) { return(NextActivity); } if (attackAircraft.IsTraitPaused) { return(this); } bool targetIsHiddenActor; attackAircraft.RequestedTarget = target = target.Recalculate(self.Owner, out targetIsHiddenActor); attackAircraft.RequestedTargetLastTick = self.World.WorldTick; hasTicked = true; if (!targetIsHiddenActor && target.Type == TargetType.Actor) { lastVisibleTarget = Target.FromTargetPositions(target); lastVisibleMaximumRange = attackAircraft.GetMaximumRangeVersusTarget(target); lastVisibleOwner = target.Actor.Owner; lastVisibleTargetTypes = target.Actor.GetEnabledTargetTypes(); } var oldUseLastVisibleTarget = useLastVisibleTarget; useLastVisibleTarget = targetIsHiddenActor || !target.IsValidFor(self); // Update target lines if required if (useLastVisibleTarget != oldUseLastVisibleTarget) { self.SetTargetLine(useLastVisibleTarget ? lastVisibleTarget : target, Color.Red, false); } // Target is hidden or dead, and we don't have a fallback position to move towards if (useLastVisibleTarget && !lastVisibleTarget.IsValidFor(self)) { attackAircraft.RequestedTarget = Target.Invalid; return(NextActivity); } // If all valid weapons have depleted their ammo and Rearmable trait exists, return to RearmActor to reload and then resume the activity if (rearmable != null && !useLastVisibleTarget && attackAircraft.Armaments.All(x => x.IsTraitPaused || !x.Weapon.IsValidAgainst(target, self.World, self))) { QueueChild(self, new ReturnToBase(self, aircraft.Info.AbortOnResupply), true); return(this); } var pos = self.CenterPosition; var checkTarget = useLastVisibleTarget ? lastVisibleTarget : target; // We don't know where the target actually is, so move to where we last saw it if (useLastVisibleTarget) { // We've reached the assumed position but it is not there - give up if (checkTarget.IsInRange(pos, lastVisibleMaximumRange)) { attackAircraft.RequestedTarget = Target.Invalid; return(NextActivity); } // Fly towards the last known position QueueChild(self, new Fly(self, target, WDist.Zero, lastVisibleMaximumRange, checkTarget.CenterPosition, Color.Red), true); return(this); } var delta = attackAircraft.GetTargetPosition(pos, target) - pos; var desiredFacing = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : aircraft.Facing; var isAirborne = self.World.Map.DistanceAboveTerrain(pos).Length >= aircraft.Info.MinAirborneAltitude; if (!isAirborne) { QueueChild(self, new TakeOff(self), true); } if (attackAircraft.Info.AttackType == AirAttackType.Strafe) { if (target.IsInRange(pos, attackAircraft.GetMinimumRange())) { QueueChild(self, new FlyTimed(ticksUntilTurn, self), true); } QueueChild(self, new Fly(self, target, target.CenterPosition, Color.Red), true); QueueChild(self, new FlyTimed(ticksUntilTurn, self)); } else { var minimumRange = attackAircraft.GetMinimumRangeVersusTarget(target); if (!target.IsInRange(pos, lastVisibleMaximumRange) || target.IsInRange(pos, minimumRange)) { QueueChild(self, new Fly(self, target, minimumRange, lastVisibleMaximumRange, target.CenterPosition, Color.Red), true); } else if (isAirborne) // Don't use 'else' to avoid conflict with TakeOff { Fly.VerticalTakeOffOrLandTick(self, aircraft, desiredFacing, aircraft.Info.CruiseAltitude); } } return(this); }