Beispiel #1
0
        public IBotTask GetStateActions(Bot bot)
        {
            var memory       = bot.MemoryMeasurementAtTime.Value;
            var ManeuverType = memory?.ShipUi?.Indication?.ManeuverType;

            if (ShipManeuverTypeEnum.Warp == ManeuverType ||
                ShipManeuverTypeEnum.Jump == ManeuverType)
            {
                return(null);                //	do nothing while warping or jumping.
            }
            var undockTask = new UndockTask(bot.MemoryMeasurementAtTime.Value);

            if (undockTask.ClientActions.Any())
            {
                return(undockTask);
            }

            if (memory?.Menu == null)
            {
                return(memory.InfoPanelCurrentSystem.ListSurroundingsButton.ClickTask());
            }

            if (memory.Menu.Count() > 1 && memory.Menu.Skip(1).FirstOrDefault().Entry.Any(e => e.Text == "Approach Location"))
            {
                arrived = true;
            }

            return(memory.InfoPanelCurrentSystem.ListSurroundingsButton.ClickMenuEntryByRegexPattern(bot, bookmarkName,
                                                                                                     "Warp to Location Within .*"));
        }
Beispiel #2
0
        public IBotTask GetStateActions(Bot bot)
        {
            var memory       = bot.MemoryMeasurementAtTime.Value;
            var ManeuverType = memory?.ShipUi?.Indication?.ManeuverType;

            if (ShipManeuverTypeEnum.Warp == ManeuverType ||
                ShipManeuverTypeEnum.Jump == ManeuverType)
            {
                return(null);                //	do nothing while warping or jumping.
            }
            if (bookmarkMissionsOnWay)
            {
                var bookmarkTask = GetBookmarkTask(bot);
                if (bookmarkTask != null)
                {
                    return(bookmarkTask);
                }
            }


            //	from the set of route element markers in the Info Panel pick the one that represents the next Waypoint/System.
            //	We assume this is the one which is nearest to the topleft corner of the Screen which is at (0,0)
            var RouteElementMarkerNext =
                memory?.InfoPanelRoute?.RouteElementMarker
                ?.OrderByCenterDistanceToPoint(new Vektor2DInt(0, 0))?.FirstOrDefault();

            if (RouteElementMarkerNext != null)
            {
                var undockTask = new UndockTask(bot.MemoryMeasurementAtTime.Value);
                if (undockTask.ClientActions.Any())
                {
                    return(undockTask);
                }
            }
            else
            {
                if ((memory?.IsDocked ?? false))
                {
                    arrived = true;
                }
                return(null);
            }

            var nextSystemLabel  = memory?.InfoPanelRoute?.NextLabel.Text;
            var nextSystemExists = nextSystemLabel.Contains("Next System in Route");

            if (nextSystemExists)
            {
                var ns1            = nextSystemLabel.Substring(nextSystemLabel.IndexOf("Next System"));
                var ns2            = ns1.Substring(ns1.IndexOf(">") + 1);
                var nextSystemName = ns2.Substring(0, ns2.IndexOf("<"));

                if (memory.WindowSelectedItemView.Single().Sprite != null &&
                    memory.WindowSelectedItemView.Single().Sprite
                    .Any(a => a.TexturePath.Equals("res:/UI/Texture/icons/44_32_39.png")) &&
                    memory.WindowSelectedItemView.Single().LabelText.Any(lt => lt.Text.Contains(nextSystemName)))
                {
                    return(memory.WindowSelectedItemView.Single().Sprite
                           .Single(a => a.TexturePath.Equals("res:/UI/Texture/icons/44_32_39.png")).ClickTask());
                }
            }

            return(RouteElementMarkerNext.ClickMenuEntryByRegexPattern(bot, "Dock|Jump.*"));
        }
        public void Do(Dictionary <MyTuple <IntelItemType, long>, IFleetIntelligence> IntelItems, TimeSpan canonicalTime, Profiler profiler)
        {
            if (canonicalTime == TimeSpan.Zero)
            {
                return;
            }
            if (MiningSystem.Recalling > 0 || currentPosition > 120)
            {
                Recalling = true;
            }
            if (Recalling && state < 3)
            {
                state = 3;
            }
            if (state == 1) // Diving to surface of asteroid
            {
                MineTask.Do(IntelItems, canonicalTime, profiler);
                MineTask.Destination.MaxSpeed = Autopilot.GetMaxSpeedFromBrakingDistance(kFarSensorDist);

                if (MineTask.Status == TaskStatus.Complete || !MiningSystem.SensorsFarClear())
                {
                    EntryPoint = Autopilot.Reference.WorldMatrix.Translation + MineTask.Destination.Direction * (kFarSensorDist - 10);
                    MineTask.Destination.MaxSpeed = 1f;
                    state = 2;
                }
            }
            else if (state == 2) // Boring tunnel
            {
                bool   sampleHome      = false;
                double distToMiningEnd = (Autopilot.Reference.WorldMatrix.Translation - MiningEnd).Length();
                if (MiningSystem.SensorsClear())
                {
                    MineTask.Destination.Position = MiningEnd;
                }
                else if (MiningSystem.SensorsBack())
                {
                    MineTask.Destination.Position = EntryPoint;
                }
                else
                {
                    MineTask.Destination.Position = Vector3D.Zero;
                    if (SampleCount <= 0)
                    {
                        SampleCount = kSampleFrequency;
                        var cargoPercentage = MonitorSubsystem.GetPercentage(MonitorOptions.Cargo);
                        if (LastSampleCargoPercentages.Count >= kMaxSampleCount)
                        {
                            LastSampleCargoPercentages.Enqueue(cargoPercentage);

                            var sampleGreater     = 0;
                            var sampleLesser      = 0;
                            var comparePercentage = LastSampleCargoPercentages.Dequeue() + 0.00001;
                            foreach (var percentage in LastSampleCargoPercentages)
                            {
                                if (percentage > comparePercentage)
                                {
                                    sampleGreater++;
                                }
                                else
                                {
                                    sampleLesser++;
                                }
                            }

                            if (sampleGreater > sampleLesser)
                            {
                                if (!HitOre)
                                {
                                    HitOre = true;
                                    var currentCoords = GetMiningPosition(currentPosition);
                                    miningMatrix[currentCoords.X + 5, currentCoords.Y + 5] = 1;
                                }
                                if (LowestExpectedOreDist == -1)
                                {
                                    LowestExpectedOreDist = (float)distToMiningEnd - 5;
                                }
                            }
                            else
                            {
                                if (HitOre || distToMiningEnd < LowestExpectedOreDist)
                                {
                                    sampleHome = true;

                                    if (!HitOre)
                                    {
                                        var currentCoords = GetMiningPosition(currentPosition);
                                        miningMatrix[currentCoords.X + 5, currentCoords.Y + 5] = 2;
                                    }
                                }
                            }
                        }
                        else
                        {
                            LastSampleCargoPercentages.Enqueue(cargoPercentage);
                        }
                    }
                    else
                    {
                        SampleCount--;
                    }
                }

                MiningSystem.Drill();
                MineTask.Do(IntelItems, canonicalTime, profiler);

                if (GoHomeCheck() || MiningSystem.SensorsFarClear() || distToMiningEnd < 4 || sampleHome)
                {
                    if (MiningSystem.SensorsFarClear() || distToMiningEnd < 4 || sampleHome)
                    {
                        UpdateMiningMatrix(currentPosition);
                        IncrementCurrentPosition();
                        HitOre = false;
                    }
                    state = 3;
                    MineTask.Destination.MaxSpeed = 2;
                    LastSampleCargoPercentages.Clear();
                }
            }
            else if (state == 3) // Exiting tunnel
            {
                MiningSystem.StopDrill();
                if (MineTask.Destination.Position != ExitPoint)
                {
                    MineTask.Destination.Position = EntryPoint;
                }
                MineTask.Do(IntelItems, canonicalTime, profiler);
                if (MineTask.Status == TaskStatus.Complete)
                {
                    if (MineTask.Destination.Position == EntryPoint)
                    {
                        MineTask.Destination.Position = ExitPoint;
                        MineTask.Destination.MaxSpeed = 100;
                    }
                    else
                    {
                        state = 10;
                    }
                }
            }
            else if (state == 10) // Resuming to approach point
            {
                if (GoHomeCheck() || Recalling)
                {
                    state = 4;
                }
                else
                {
                    LeadTask.Destination.Position = ApproachPoint;
                    LeadTask.Do(IntelItems, canonicalTime, profiler);
                    if (LeadTask.Status == TaskStatus.Complete)
                    {
                        var position = GetMiningPosition(currentPosition);
                        LeadTask.Destination.Position = ApproachPoint + (Perpendicular * position.X * MiningSystem.OffsetDist + Perpendicular.Cross(MineTask.Destination.Direction) * position.Y * MiningSystem.OffsetDist);
                        LeadTask.Destination.MaxSpeed = 10;
                        ExitPoint = LeadTask.Destination.Position;
                        state     = 11;
                    }
                }
            }
            else if (state == 11) // Search for the digging spot
            {
                if (GoHomeCheck() || Recalling)
                {
                    state = 4;
                }
                else
                {
                    LeadTask.Do(IntelItems, canonicalTime, profiler);
                    if (LeadTask.Status == TaskStatus.Complete)
                    {
                        state = 1;
                        MiningSystem.SensorsOn();
                        var position = GetMiningPosition(currentPosition);
                        MineTask.Destination.Position = SurfacePoint + (Perpendicular * position.X * MiningSystem.OffsetDist + Perpendicular.Cross(MineTask.Destination.Direction) * position.Y * MiningSystem.OffsetDist) - MineTask.Destination.Direction * MiningSystem.CloseDist;
                        MiningEnd = SurfacePoint + (Perpendicular * position.X * MiningSystem.OffsetDist + Perpendicular.Cross(MineTask.Destination.Direction) * position.Y * MiningSystem.OffsetDist) + MineTask.Destination.Direction * MiningDepth;
                    }
                }
            }
            else if (state == 4) // Going home
            {
                if (DockingSubsystem == null || DockingSubsystem.HomeID == -1 || DockTaskGenerator == null || UndockTaskGenerator == null)
                {
                    state = 9999;
                }
                else
                {
                    if (HomeTask == null)
                    {
                        HomeTask = DockTaskGenerator.GenerateMoveToAndDockTask(MyTuple.Create(IntelItemType.NONE, (long)0), IntelItems, 40);
                    }
                    HomeTask.Do(IntelItems, canonicalTime, profiler);
                    if (HomeTask.Status != TaskStatus.Incomplete)
                    {
                        HomeTask  = null;
                        homeCheck = false;
                        state     = 5;
                    }
                }
            }
            else if (state == 5) // Waiting for refuel/unload
            {
                if (Recalling)
                {
                    state = 9999;
                }
                if ((Program.Me.WorldMatrix.Translation - EntryPoint).LengthSquared() > MiningSystem.CancelDist * MiningSystem.CancelDist)
                {
                    state = 9999;
                }
                if (LeaveHomeCheck())
                {
                    state = 6;
                }
            }
            else if (state == 6) // Undocking
            {
                if (DockingSubsystem != null && DockingSubsystem.Connector.Status == MyShipConnectorStatus.Connected)
                {
                    if (UndockTask == null)
                    {
                        UndockTask = UndockTaskGenerator.GenerateUndockTask(canonicalTime);
                    }
                }

                if (UndockTask != null)
                {
                    UndockTask.Do(IntelItems, canonicalTime, profiler);
                    if (UndockTask.Status != TaskStatus.Incomplete)
                    {
                        UndockTask = null;
                        state      = 10;
                    }
                }
                else
                {
                    state = 10;
                }
            }
            else if (state == 9999)
            {
                Status = TaskStatus.Complete;
            }
        }