Exemplo n.º 1
0
        private void FlyToStationPointAndWaitForAelphs()
        {
            Log("FlyToStationPointAndWaitForAelphs");

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

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

            // 1/3 of 360 degrees in radians.
            double oneThirdAngle = Math.PI * 2 / 3;

            // Move to a new point 1/3 or 2/3 of the total angle and the same distance as the entry aleph.
            double newAngle = startingAngleInRadians + (oneThirdAngle * _random.Next(1, 3));

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

            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);

            List <int> consideredWarpObjectIDs = new List <int>();

            // Wait for Aelphs to appear.
            Task.Run(() =>
            {
                try
                {
                    _runningTasks++;

                    bool foundNewWarp = false;
                    bool updatedUnexploredClusterListAfterMove = false;
                    for (int i = 0; i < 120 * 100 && _cancellationTokenSource.IsCancellationRequested == false; i++)
                    {
                        var otherScoutShips         = ship.GetCluster().GetShips().Where(p => p.GetObjectID() != ship.GetObjectID() && p.GetBaseHullType().GetName().Contains("Scout") == true);
                        var otherSweepingScoutShips = otherScoutShips.Where(p => p.GetCommandTarget((sbyte)CommandType.c_cmdCurrent)?.GetObjectType() == (short)ObjectType.OT_buoy);

                        if (i % 500 == 0)
                        {
                            Log($"Waiting for Alephs to be found: {i}.");

                            // Once we get within 400 of the waypoint, update the unexplored clusters list in case we happen to have found a new unexplored cluster.
                            if (updatedUnexploredClusterListAfterMove == false && (nextPoint - ship.GetPosition()).LengthSquared() < Math.Pow(400, 2))
                            {
                                Log("Updating unexplored cluster list after ship move.");
                                UpdateUnexploredWarpsList();
                                updatedUnexploredClusterListAfterMove = true;
                            }
                        }

                        var newWarps = ship.GetCluster().GetWarps().Where(p => GameInfo.UnexploredClustersByObjectID.ContainsKey(p.GetDestination().GetCluster().GetObjectID()) == true && consideredWarpObjectIDs.Contains(p.GetObjectID()) == false);
                        if (newWarps.Count() > 0)
                        {
                            foreach (var newWarp in newWarps)
                            {
                                // If there are other non-sweeping ships in the sector, then only 33% of those ships should go to the newly visible aelph.
                                if (otherScoutShips.Count() - otherSweepingScoutShips.Count() > 0)
                                {
                                    if (_random.Next(0, 100) < 33)
                                    {
                                        Log($"Warp found, 33% chance success, heading to {newWarp.GetName()}");

                                        ship.SetCommand((sbyte)CommandType.c_cmdCurrent, newWarp, (sbyte)CommandID.c_cidGoto);
                                        ship.SetAutopilot(true);
                                        foundNewWarp = true;
                                        break;
                                    }
                                }
                                else // We are the only non-sweeping scout in the cluster, go to the new warp.
                                {
                                    Log($"Warp found, heading to {newWarp.GetName()}");

                                    ship.SetCommand((sbyte)CommandType.c_cmdCurrent, newWarp, (sbyte)CommandID.c_cidGoto);
                                    ship.SetAutopilot(true);
                                    foundNewWarp = true;
                                    break;
                                }
                            }
                        }

                        Thread.Sleep(100);
                    }

                    if (foundNewWarp == false)
                    {
                        Log("No aelph was found, heading to next available warp.");
                        SelectNextAelphTarget();
                    }
                }
                finally
                {
                    _runningTasks--;
                }
            });
        }
Exemplo n.º 2
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();
            //}
        }
Exemplo n.º 3
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();
            //}
        }