/// <Summary>
        /// Display a planet Summary
        /// </Summary>
        /// <param name="Item"></param>
        private void DisplayPlanet(StarIntel report)
        {
            if (empireState.StarReports[report.Name].Year == Global.Unset)
            {
                this.summaryFrame.Text = report.Name + " is unexplored";
                summaryItem            = null;
                PlanetSummary.Hide();
                FleetSummary.Hide();
                Invalidate();
                return;
            }

            // If we are displaying a fleet clear it out and add the planet
            // Summary display.

            if (summaryItem is FleetIntel || summaryItem == null)
            {
                PlanetSummary.Show();
                FleetSummary.Hide();
                Invalidate();
            }

            summaryItem = report;

            this.summaryFrame.Text = "Summary of " + report.Name;
            PlanetSummary.Location = new Point(5, 15);
            PlanetSummary.Value    = report;
        }
Exemple #2
0
        /// <Summary>
        /// Add an indication of a starbase (circle) or orbiting fleets (smaller
        /// circle) or both.
        /// </Summary>
        /// <param name="Star">The Star being drawn.</param>
        private void DrawOrbitingFleets(Graphics g, StarIntel report)
        {
            NovaPoint position = LogicalToDevice(report.Position);

            if (report == null)
            {
                return;
            }

            if (report.Starbase != null)
            {
                g.FillEllipse(
                    Brushes.Yellow,
                    position.X + 6,
                    position.Y - 6,
                    4,
                    4);
            }

            if (report.HasFleetsInOrbit)
            {
                int size = 12;
                g.DrawEllipse(
                    Pens.White,
                    position.X - (size / 2),
                    position.Y - (size / 2),
                    size,
                    size);
            }
        }
Exemple #3
0
        private void HandleScouting()
        {
            List <Fleet> scoutFleets = new List <Fleet>();

            foreach (Fleet fleet in clientState.EmpireState.OwnedFleets.Values)
            {
                if (fleet.Name.Contains("Scout") == true)
                {
                    scoutFleets.Add(fleet);
                }
            }

            // Find the stars we do not need to scout (eg home world)
            List <StarIntel> excludedStars = new List <StarIntel>();

            foreach (StarIntel report in turnData.EmpireState.StarReports.Values)
            {
                if (report.Year != Global.Unset)
                {
                    excludedStars.Add(report);
                }
            }

            if (scoutFleets.Count > 0)
            {
                foreach (Fleet fleet in scoutFleets)
                {
                    StarIntel starToScout = fleetAIs[fleet.Id].Scout(excludedStars);
                    if (starToScout != null)
                    {
                        excludedStars.Add(starToScout);
                    }
                }
            }
        }
Exemple #4
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);
            }
        }
Exemple #5
0
        /// <summary>
        /// Send the fleet to colonise a planet.
        /// </summary>
        /// <param name="targetStar">The <see cref="StarIntel"/> for the target star to colonise.</param>
        public void Colonise(StarIntel targetStar)
        {
            // ensure we take some colonists, maybe some Germainium
            if (this.fleet.Cargo.ColonistsInKilotons < 1)
            {
                if (this.fleet.InOrbit != null && this.fleet.InOrbit.Owner == this.fleet.Owner)
                {
                    // there is one of our planets here, so try to beam up colonists
                    Star ourStar = (Star)this.fleet.InOrbit;

                    // How much germanium to load to seed factory production?
                    // 1/4 of cargo capacity, so long as we can load 100 kT of colonists
                    int germaniumToLoad = System.Math.Min(this.fleet.TotalCargoCapacity / 4, this.fleet.TotalCargoCapacity - 100);
                    // but leave at least 50 G behind
                    germaniumToLoad = System.Math.Min(germaniumToLoad, ourStar.ResourcesOnHand.Germanium - 50);
                    // do not try to load a negative number of G
                    germaniumToLoad = System.Math.Max(germaniumToLoad, 0);

                    // How many colonists to load?
                    // fill up space left after G
                    int colonistsToLoadKt = this.fleet.TotalCargoCapacity - germaniumToLoad;
                    // but do not take the Star below 250,000 (max % growth)
                    colonistsToLoadKt = System.Math.Min(colonistsToLoadKt, (ourStar.Colonists - 250000) / Nova.Common.Global.ColonistsPerKiloton);
                    // ensure we load at least 1 kT of colonists
                    colonistsToLoadKt = System.Math.Max(colonistsToLoadKt, 1);

                    // load up
                    CargoTask wpTask = new CargoTask();
                    wpTask.Mode = CargoMode.Load;
                    wpTask.Amount.ColonistsInKilotons = colonistsToLoadKt;
                    wpTask.Amount.Germanium           = germaniumToLoad;

                    Waypoint wp = new Waypoint();
                    wp.Task        = wpTask;
                    wp.Position    = ourStar.Position;
                    wp.WarpFactor  = this.fleet.FreeWarpSpeed;
                    wp.Destination = ourStar.Name;

                    WaypointCommand loadCommand = new WaypointCommand(CommandMode.Add, wp, this.fleet.Key);
                    loadCommand.ApplyToState(clientState.EmpireState);
                    clientState.Commands.Push(loadCommand);

                    SendFleet(targetStar, this.fleet, new ColoniseTask());
                }
                else
                {
                    // TODO (priority 5) - go get some colonists
                }
            }
            else
            {
                // Already has colonists
                SendFleet(targetStar, this.fleet, new ColoniseTask());
            }
        }
Exemple #6
0
        private void SendFleet(StarIntel star, Fleet fleet, IWaypointTask task)
        {
            Waypoint w = new Waypoint();

            w.Position = star.Position;

            w.Destination = star.Name;
            w.Task        = task;

            WaypointCommand command = new WaypointCommand(CommandMode.Add, w, fleet.Key);

            command.ApplyToState(clientState.EmpireState);
            clientState.Commands.Push(command);
        }
Exemple #7
0
        /// <summary>
        /// Return closest star to current fleet.
        /// </summary>
        /// <param name="fleet"></param>
        /// <returns></returns>
        private StarIntel CloesestStar(Fleet fleet, List <StarIntel> excludedStars)
        {
            StarIntel target   = null;
            double    distance = double.MaxValue;

            foreach (StarIntel report in clientState.EmpireState.StarReports.Values)
            {
                if (excludedStars.Contains(report) != true)
                {
                    if (distance > Math.Sqrt(Math.Pow(fleet.Position.X - report.Position.X, 2) + Math.Pow(fleet.Position.Y - report.Position.Y, 2)))
                    {
                        target   = report;
                        distance = Math.Sqrt(Math.Pow(fleet.Position.X - target.Position.X, 2) + Math.Pow(fleet.Position.Y - target.Position.Y, 2));
                    }
                }
            }
            return(target);
        }
Exemple #8
0
        /// <Summary>
        /// Draw a Star. The Star is just a small circle which is a bit bigger if we've
        /// explored it.
        /// </Summary>
        /// <remarks>
        /// The color of the Star symbol is based on its Star report (reports for stars
        /// owned by the current player are always up-to-date). Unoccupied stars are
        /// white. Stars colonised by the player are green. Stars owned by other races
        /// are red.
        /// </remarks>
        /// <param name="Star">The Star sytem to draw.</param>
        private void DrawStar(Graphics g, StarIntel report)
        {
            NovaPoint position  = LogicalToDevice(report.Position);
            int       size      = 2;
            Brush     starBrush = Brushes.White;

            // Bigger symbol for explored stars.

            if (report.Year > Global.Unset)
            {
                size = 4;
            }

            // Our stars are greenish, other's are red, unknown or uncolonised
            // stars are white.

            if (report.Owner == clientState.EmpireState.Id)
            {
                starBrush = Brushes.GreenYellow;
            }
            else
            {
                if (report.Owner != Global.Nobody)
                {
                    starBrush = Brushes.Red;
                }
            }

            FillCircle(g, starBrush, (Point)position, size);

            // If the Star name display is turned on then add the name

            if (this.displayStarNames && zoomFactor > 0.5)
            {
                StringFormat format = new StringFormat();
                format.Alignment = StringAlignment.Center;
                g.DrawString(report.Name, this.nameFont, Brushes.White, position.X, position.Y + 5, format);
            }
        }
Exemple #9
0
 public void Update(Star star)
 {
     this.Value = star.GenerateReport(ScanLevel.Owned, empireState.TurnYear);
 }