Пример #1
0
        private void SweepCluster()
        {
            Log("SweepCluster()");

            _isSweeping = true;

            var ship            = _client.GetShip();
            var otherScoutShips = ship.GetCluster().GetShips().Where(p => p.GetObjectID() != ship.GetObjectID() && p.GetBaseHullType().GetName().Contains("Scout") == true);

            var centerPoint  = new VectorWrapper(0, 0, 0);
            var shipPosition = ship.GetPosition();

            var startingPoint          = shipPosition;
            var startingAngleInRadians = shipPosition.AngleInRadians(centerPoint);

            double nextSliceWidth        = (Math.PI * 2 / SweepHopCount);
            double currentAngleInRadians = startingAngleInRadians;

            bool sweepLeft = otherScoutShips.Count() > 0;

            Task.Run(() =>
            {
                try
                {
                    _runningTasks++;

                    bool sweepComplete = true;

                    // Skip the first hop and the last 2 hops, aelphs won't be that close together.
                    for (int i = 1; i < SweepHopCount - 2 && _cancellationTokenSource.IsCancellationRequested == false; i++)
                    {
                        if (sweepLeft == true)
                        {
                            currentAngleInRadians += nextSliceWidth;
                        }
                        else
                        {
                            currentAngleInRadians -= nextSliceWidth;
                        }

                        VectorWrapper nextPoint = new VectorWrapper((startingPoint - centerPoint).Length() * (float)Math.Cos(currentAngleInRadians), (startingPoint - centerPoint).Length() * (float)Math.Sin(currentAngleInRadians), 0);

                        Log($"nextPoint: {nextPoint.GetString()}, currentAngleInRadians: {currentAngleInRadians}, sweepHop: {i}");

                        var buoy    = _client.CreateBuoy((sbyte)BuoyType.c_buoyWaypoint, nextPoint.X(), nextPoint.Y(), nextPoint.Z(), ship.GetCluster().GetObjectID(), true);
                        var command = ship.GetDefaultOrder(buoy);
                        ship.SetCommand((sbyte)CommandType.c_cmdCurrent, buoy, command);
                        ship.SetAutopilot(true);

                        bool reachedWaypoint = false;
                        for (int j = 0; j < 120 * 100 && _cancellationTokenSource.IsCancellationRequested == false; j++)
                        {
                            VectorWrapper difference = nextPoint - ship.GetPosition();

                            if (j % 500 == 0)
                            {
                                Log($"Current distance: {Math.Abs(difference.Length())}, iterations: {j}, {nextPoint.GetString()}");
                            }

                            if ((nextPoint - ship.GetPosition()).LengthSquared() < Math.Pow(400, 2))
                            {
                                Log($"Reached waypoint: {nextPoint.GetString()}");
                                reachedWaypoint = true;
                                break;
                            }

                            Thread.Sleep(100);
                        }

                        // We didn't reach the waypoint in two minutes. Something went wrong, let's just move on.
                        if (reachedWaypoint == false)
                        {
                            sweepComplete = false;
                            Log("No waypoint was found in 120 seconds.");
                            break;
                        }
                    }

                    if (sweepComplete == true)
                    {
                        Log($"Cluster exploration complete for ship.GetCluster().GetName(), removing from GameInfo.UnexploredClustersByObjectID");
                        GameInfo.UnexploredClustersByObjectID.Remove(ship.GetCluster().GetObjectID());
                        UpdateUnexploredWarpsList();
                    }

                    SelectNextAelphTarget();
                }
                finally
                {
                    _runningTasks--;
                    _isSweeping = false;
                }
            });

            //_startingPoint = shipPosition;
            //_startingAngleInRadians = shipPosition.AngleInRadians(centerPoint);



            //if (_startingAngleInRadians < 0)
            //    _startingAngleInRadians = _startingAngleInRadians + 2 * Math.PI;

            //_currentAngleInRadians = _startingAngleInRadians;

            //// If there are no scouts, sweep left, otherwise if there is already a scount, then sweep right, otherwise, locate a new aleph and go there!
            //if (otherScoutShips.Count() == 0)
            //{
            //    _sweepLeft = true;
            //    NavigateToNextSweepPoint();
            //}
            //else if (otherScoutShips.Count() == 1)
            //{
            //    _sweepRight = true;
            //    NavigateToNextSweepPoint();
            //}
            //else
            //{
            //    _sweepRight = false;
            //    _sweepLeft = false;
            //    SelectNextAelphTarget();
            //}
        }
Пример #2
0
        private void SweepCluster()
        {
            Log("\tSweepCluster()");

            _isSweeping = true;

            var ship            = ClientConnection.GetShip();
            var otherScoutShips = ship.GetCluster().GetShips().Where(p => p.GetObjectID() != ship.GetObjectID() && p.GetBaseHullType().GetName().Contains("Scout") == true);

            var centerPoint  = new VectorWrapper(0, 0, 0);
            var shipPosition = ship.GetPosition();

            var startingPoint          = shipPosition;
            var startingAngleInRadians = shipPosition.AngleInRadians(centerPoint);

            double nextSliceWidth        = (Math.PI * 2 / SweepHopCount);
            double currentAngleInRadians = startingAngleInRadians;

            Task.Run(() =>
            {
                try
                {
                    int currentSweepingScoutCount = GameInfo.IncrementSweepingScoutCount(ship.GetCluster());

                    //bool sweepLeft = currentSweepingScoutCount > 0;

                    _runningTasks++;

                    bool sweepComplete = true;

                    int hopCount            = SweepHopCount;
                    bool hopCountReduced    = false; // Changes to true when a second scout starts sweeping.
                    bool firstSweepingScout = currentSweepingScoutCount == 1;

                    // This is somewhat specific to hihigher, but we will assume that any cluster has an average of 3 warps and a station cluster has 4.
                    // This lets a scout stop sweeping early if all clusters are assumed to be found.
                    int targetWarpCount = 3 + ship.GetCluster().GetStations().Count;

                    for (int i = 1;
                         i < hopCount - 2 &&  // Skip the first hop and the last 2 hops, aelphs won't be that close together.
                         _cancellationTokenSource.IsCancellationRequested == false &&
                         ship.GetCluster().GetWarps().Count < targetWarpCount;        // If we find enough warps, we will consider this cluster scanned. If there are more warp clusters will be covered when the other cluster is discovered from the other side. Otherwise, it's up to the humans!
                         i++)
                    {
                        // If another scout starts sweeping, then reduce the hop count by half so that we get done quicker. The other scout will start sweeping from the other direction.
                        if (hopCountReduced == false && GameInfo.GetSweepingScoutCount(ship.GetCluster()) >= 2)
                        {
                            Log($"\t\tA second scout is also sweeping, reducing the hop count to half.");
                            hopCount = (SweepHopCount / 2) + 3;     // Go a little farther so that the paths overlap. It's the classic pincer manuver!!
                        }

                        if (firstSweepingScout == true)
                        {
                            currentAngleInRadians += nextSliceWidth;
                        }
                        else
                        {
                            currentAngleInRadians -= nextSliceWidth;
                        }

                        VectorWrapper nextPoint = new VectorWrapper((startingPoint - centerPoint).Length() * (float)Math.Cos(currentAngleInRadians), (startingPoint - centerPoint).Length() * (float)Math.Sin(currentAngleInRadians), 0);

                        Log($"\t\tnextPoint: {nextPoint.GetString()}, currentAngleInRadians: {currentAngleInRadians}, sweepHop: {i}, firstSweepingScout: {firstSweepingScout}, target hopCount: {hopCount - 2}");

                        var buoy    = ClientConnection.CreateBuoy((sbyte)BuoyType.c_buoyWaypoint, nextPoint.X(), nextPoint.Y(), nextPoint.Z(), ship.GetCluster().GetObjectID(), true);
                        var command = ship.GetDefaultOrder(buoy);
                        ship.SetCommand((sbyte)CommandType.c_cmdCurrent, buoy, command);
                        ship.SetAutopilot(true);

                        bool reachedWaypoint = false;
                        for (int j = 0; j < 60 * 100 && _cancellationTokenSource.IsCancellationRequested == false; j++)
                        {
                            VectorWrapper difference = nextPoint - ship.GetPosition();

                            if (j % 500 == 0)
                            {
                                Log($"\t\tCurrent distance: {Math.Abs(difference.Length())}, iterations: {j}, {nextPoint.GetString()}, ship velocity: {ship.GetVelocity().Length()}");
                            }

                            if ((nextPoint - ship.GetPosition()).LengthSquared() < Math.Pow(600, 2))
                            {
                                Log($"\t\tReached waypoint: {nextPoint.GetString()}, ship velocity: {ship.GetVelocity().Length()}");
                                reachedWaypoint = true;
                                break;
                            }

                            Thread.Sleep(100);
                        }

                        // We didn't reach the waypoint in one minute. Something went wrong, let's just move on.
                        if (reachedWaypoint == false)
                        {
                            sweepComplete = false;
                            Log("\t\tNo waypoint was found in 120 seconds.");
                            break;
                        }
                    }

                    if (sweepComplete == true)
                    {
                        currentSweepingScoutCount = GameInfo.GetSweepingScoutCount(ship.GetCluster());

                        // If there is more than one sweeping scout, then the second scout will perform the removal of the scanned cluster.
                        if (firstSweepingScout == false || currentSweepingScoutCount == 1)
                        {
                            var currentUnexploredClusters = GameInfo.GetUnexploredClusters(ClientConnection.GetCore());

                            if (currentUnexploredClusters.ContainsKey(ship.GetCluster().GetObjectID()) == true)
                            {
                                Log("Initial sweep complete, but we didn't find everything. TODO: take a closer look?");
                                DoTargetedSweep(ship);
                            }
                            else
                            {
                                Log($"\t\tCluster exploration complete for {ship.GetCluster().GetName()}, this cluster is no longer in the unexplored list.");
                                //GameInfo.UnexploredClustersByObjectID.Remove(ship.GetCluster().GetObjectID());
                                //UpdateUnexploredWarpsList();
                            }
                        }
                        else
                        {
                            Log($"\t\tCluster exploration complete for {ship.GetCluster().GetName()} for first sweeping scout.");
                        }
                    }

                    SelectNextAelphTarget();
                }
                finally
                {
                    _runningTasks--;
                    _isSweeping = false;
                    GameInfo.DecrementSweepingScoutCount(ship.GetCluster());
                }
            });

            //_startingPoint = shipPosition;
            //_startingAngleInRadians = shipPosition.AngleInRadians(centerPoint);



            //if (_startingAngleInRadians < 0)
            //    _startingAngleInRadians = _startingAngleInRadians + 2 * Math.PI;

            //_currentAngleInRadians = _startingAngleInRadians;

            //// If there are no scouts, sweep left, otherwise if there is already a scount, then sweep right, otherwise, locate a new aleph and go there!
            //if (otherScoutShips.Count() == 0)
            //{
            //    _sweepLeft = true;
            //    NavigateToNextSweepPoint();
            //}
            //else if (otherScoutShips.Count() == 1)
            //{
            //    _sweepRight = true;
            //    NavigateToNextSweepPoint();
            //}
            //else
            //{
            //    _sweepRight = false;
            //    _sweepLeft = false;
            //    SelectNextAelphTarget();
            //}
        }