예제 #1
0
        public StarIntel Scout(List <StarIntel> excludedStars)
        {
            bool missionAccepted = false;

            // Find a star to scout
            StarIntel starToScout = CloesestStar(this.fleet, excludedStars);

            if (starToScout != null)
            {
                // Do we need fuel first?
                double fuelRequired = 0.0;
                Fleet  nearestFuel  = ClosestFuel(fleet);
                if (!fleet.CanRefuel)
                {
                    // Can not make fuel, so how much fuel is required to scout and then refuel?
                    if (nearestFuel != null)
                    {
                        int    bestWarp        = 6; // FIXME (priority 4) - what speed to scout at?
                        double bestSpeed       = bestWarp * bestWarp;
                        double speedSquared    = bestSpeed * bestSpeed;
                        double fuelConsumption = fleet.FuelConsumption(bestWarp, clientState.EmpireState.Race);
                        double distanceSquared = PointUtilities.DistanceSquare(fleet.Position, starToScout.Position); // to the stars
                        distanceSquared += PointUtilities.DistanceSquare(starToScout.Position, nearestFuel.Position); // and back to fuel (minimum)
                        double time = Math.Sqrt(distanceSquared / speedSquared);
                        fuelRequired = time * fuelConsumption;
                    }
                    else
                    {
                        // OMG there is no fuel! - just keep scouting then?
                    }
                }


                if (fleet.FuelAvailable > fuelRequired)
                {
                    // Fuel is no problem
                    SendFleet(starToScout, fleet, new NoTask());
                    missionAccepted = true;
                }
                else
                {
                    // Refuel before scouting further
                    SendFleet(nearestFuel, fleet, new NoTask());
                }
            }

            if (missionAccepted)
            {
                return(starToScout);
            }
            else
            {
                return(null);
            }
        }
예제 #2
0
        /// <summary>
        /// Return the closest refuelling point.
        /// </summary>
        /// <param name="fleet">The fleet looking for fuel.</param>
        /// <returns>The closest fleet that can refuel (normally a star base).</returns>
        private Fleet ClosestFuel(Fleet customer)
        {
            if (customer == null)
            {
                return(null);
            }

            // initialise the list of fuel stations, if null.
            if (FuelStations == null)
            {
                FuelStations = new FleetList();
                foreach (Fleet pump in clientState.EmpireState.OwnedFleets.Values)
                {
                    if (pump.CanRefuel)
                    {
                        FuelStations.Add(pump);
                    }
                }
            }

            // if there are still no fuel stations, bug out
            if (FuelStations.Count == 0)
            {
                return(null);
            }

            Fleet  closestFuelSoFar   = null;
            double minRefulerDistance = double.MaxValue;

            foreach (Fleet pump in FuelStations.Values)
            {
                double distSquare = PointUtilities.DistanceSquare(pump.Position, customer.Position);
                if (distSquare < minRefulerDistance)
                {
                    minRefulerDistance = distSquare;
                    closestFuelSoFar   = pump;
                }
            }

            return(closestFuelSoFar);
        }