Beispiel #1
0
        IEnumerable <string> ReachTargetArea()
        {
            Runtime.UpdateFrequency = UpdateFrequency.Update10;
            Waypoint wp = new Waypoint(TargetLocation.CurrentPosition, TargetLocation.Velocity, TargetLocation.Name);

            wp.TargetDistance = ScanningDistance;
            if ((TargetLocation.CurrentPosition - Pilot.Controller.GetPosition()).LengthSquared() < (wp.TargetDistance * wp.TargetDistance))
            {
                yield return("FindTarget");
            }
            Message("Proceeding to target area.");

            double rotangle     = 0;
            double scandistance = 190.0;
            MyDetectedEntityInfo obstacle;

            var task = new AimedFlightStrategy(wp, Pilot.Controller);

            task.MaxLinearSpeed = MaxSpeed;
            Pilot.Tasks.Add(task);
            while (!Pilot.Update(Runtime.TimeSinceLastRun.TotalSeconds))
            {
                if (HasToAbort())
                {
                    yield return("ReturnHome");
                }
                else
                {
                    Vector3D scanvector =
                        Clamp.GetPosition() +
                        Clamp.WorldMatrix.Forward * 1.5 * Me.CubeGrid.WorldVolume.Radius * Math.Sin(rotangle) +
                        Clamp.WorldMatrix.Left * 1.5 * Me.CubeGrid.WorldVolume.Radius * Math.Cos(rotangle) +
                        Clamp.WorldMatrix.Down * scandistance;
                    foreach (var cam in Cameras)
                    {
                        if (cam.CanScan(scanvector))
                        {
                            rotangle += 0.8;
                            if (rotangle > 2 * Math.PI)
                            {
                                rotangle -= 2 * Math.PI;
                            }
                            obstacle = cam.Raycast(scanvector);
                            if (!obstacle.IsEmpty() && (!TargetSelector(obstacle) || (obstacle.HitPosition.Value - TargetLocation.CurrentPosition).LengthSquared() > ScanningDistance * ScanningDistance))
                            {
                                Message($"Obstacle detected, aborting. {obstacle.Name} @ {obstacle.Position}");
                                yield return("FullStop");
                            }
                        }
                    }
                }
                yield return(null);
            }
            yield return("FindTarget");
        }