Пример #1
0
        /// <summary>
        /// Calculate the fuel required for this fleet to reach a given destination.
        /// </summary>
        /// <param name="warpFactor">The warp speed to travel at.</param>
        /// <param name="race">The race operating the fleet.</param>
        /// <param name="dest">The destination as a <see cref="NovaPoint"/>.</param>
        /// <returns>The estimated fuel consumption.</returns>
        /// <remarks>
        /// FIXME (priority 4) - probably has rounding errors.
        /// FIXME (priority 3) - should this account for final year slow down?.
        /// </remarks>
        public int GetFuelRequired(int warpFactor, Race race, NovaPoint dest)
        {
            double fuelConsumption = FuelConsumption(warpFactor, race);
            double time            = PointUtilities.DistanceSquare(this.Position, dest) / (warpFactor * warpFactor * warpFactor * warpFactor);

            return((int)(time * fuelConsumption));
        }
Пример #2
0
        /// <summary>
        /// Move the fleet towards the waypoint at the top of the list. Fuel is consumed
        /// at the rate of the sum of each of the individual ships (i.e. available fuel
        /// is automatically "pooled" between the ships).
        /// </summary>
        /// <param name="availableTime">The portion of a year left for travel.</param>
        /// <param name="race">The race this fleet belongs to.</param>
        /// <returns>A TravelStatus indicating arrival or in-transit.</returns>
        public TravelStatus Move(ref double availableTime, Race race)
        {
            if (GetTravelStatus() == TravelStatus.Arrived)
            {
                return(TravelStatus.Arrived);
            }

            Waypoint target = Waypoints[0];

            InOrbit = null;

            double legDistance = PointUtilities.Distance(Position, target.Position);

            int    warpFactor          = target.WarpFactor;
            int    speed               = warpFactor * warpFactor;
            double targetTime          = legDistance / speed;
            double fuelConsumptionRate = FuelConsumption(warpFactor, race);
            double fuelTime            = FuelAvailable / fuelConsumptionRate;
            double travelTime          = targetTime;

            // Determine just how long we have available to travel towards the
            // waypoint target. This will be the smaller of target time (the ideal
            // case, we get there) available time (didn't get there but still can
            // move towards there next turn) and fuel time.

            TravelStatus arrived = TravelStatus.Arrived;

            if (travelTime > availableTime)
            {
                travelTime = availableTime;
                arrived    = TravelStatus.InTransit;
            }

            if (travelTime >= fuelTime)
            {
                travelTime = fuelTime;
                arrived    = TravelStatus.InTransit;
            }

            // If we have arrived then the new fleet position is the waypoint
            // target. Otherwise the position is determined by how far we got
            // in the time or fuel available.

            if (arrived == TravelStatus.Arrived)
            {
                Position          = target.Position;
                target.WarpFactor = 0;
            }
            else
            {
                double travelled = speed * travelTime;
                Position = PointUtilities.MoveTo(Position, target.Position, travelled);
            }

            // Update the travel time left for this year and the total fuel we
            // now have available.

            availableTime -= travelTime;
            int fuelUsed = (int)(fuelConsumptionRate * travelTime);

            FuelAvailable -= fuelUsed;

            // Added check if fleet run out of full it's speed will be changed
            // to free warp speed.
            if (arrived == TravelStatus.InTransit && fuelConsumptionRate > this.FuelAvailable)
            {
                target.WarpFactor = this.FreeWarpSpeed;
            }
            return(arrived);
        }