Ejemplo n.º 1
0
        /// <summary>
        /// Determine the positions of any potential battles where the number of fleets
        /// is more than one (this scan could be more efficient but this is easier to
        /// read).
        /// </summary>
        /// <returns>A list of all lists of co-located fleets.</returns>
        public List <List <Fleet> > DetermineCoLocatedFleets()
        {
            List <List <Fleet> >    allColocatedFleets = new List <List <Fleet> >();
            Dictionary <long, bool> fleetDone          = new Dictionary <long, bool>();

            foreach (Fleet fleetA in serverState.IterateAllFleets())
            {
                if (fleetDone.ContainsKey(fleetA.Key))
                {
                    continue;
                }

                List <Fleet> coLocatedFleets = new List <Fleet>();

                foreach (Fleet fleetB in serverState.IterateAllFleets())
                {
                    if (fleetB.Position != fleetA.Position)
                    {
                        continue;
                    }

                    coLocatedFleets.Add(fleetB);
                    fleetDone[fleetB.Key] = true;
                }

                if (coLocatedFleets.Count > 1)
                {
                    allColocatedFleets.Add(coLocatedFleets);
                }
            }

            return(allColocatedFleets);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Generate a new turn by reading in the player turn files to update the master
        /// copy of stars, ships, etc. Then do the processing required to take in the
        /// passage of one year of time and, finally, write out the new turn file.
        /// </summary>
        public void Generate()
        {
            BackupTurn();

            // For now, just copy the command stacks right away.
            // TODO (priority 6): Integrity check the new turn before
            // updating the state (cheats, errors).
            ReadOrders();

            // for all commands of all empires: command.ApplyToState(empire);
            // for WaypointCommand: Add Waypoints to Fleets.
            ParseCommands();

            // Do all fleet movement and actions
            // TODO (priority 4) - split this up into waypoint zero and waypoint 1 actions

            // ToDo: Step 1 --> Scrap Fleet if waypoint 0 order; here, and only here.
            // ToDo: ScrapFleetStep / foreach ITurnStep for waypoint 0. Own TurnStep-List for Waypoint 0?
            new ScrapFleetStep().Process(serverState);

            foreach (Fleet fleet in serverState.IterateAllFleets())
            {
                ProcessFleet(fleet); // ToDo: don't scrap fleets here at waypoint 1
            }
            serverState.CleanupFleets();

            // remove battle from old turns
            foreach (EmpireData empire in serverState.AllEmpires.Values)
            {
                empire.BattleReports.Clear();
            }

            battleEngine.Run();

            serverState.CleanupFleets();

            victoryCheck.Victor();

            serverState.TurnYear++;

            foreach (EmpireData empire in serverState.AllEmpires.Values)
            {
                empire.TurnYear      = serverState.TurnYear;
                empire.TurnSubmitted = false;
            }

            foreach (ITurnStep turnStep in turnSteps.Values)
            {
                turnStep.Process(serverState);
            }

            WriteIntel();

            // remove old messages, do this last so that the 1st turn intro message is not removed before it is delivered.
            serverState.AllMessages = new List <Message>();

            CleanupOrders();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Build a <see cref="ScoreRecord"/> for a given race.
        /// </summary>
        /// <param name="raceName">The name fo the race to build a <see cref="ScoreRecord"/> for.</param>
        /// <returns>A <see cref="ScoreRecord"/> for the given race.</returns>
        private ScoreRecord GetScoreRecord(int empireId)
        {
            double      totalScore = 0;
            ScoreRecord score      = new ScoreRecord();

            // ----------------------------------------------------------------------------
            // Count star-specific values
            // ----------------------------------------------------------------------------

            int starBases = 0;
            int resources = 0;

            foreach (Star star in serverState.AllStars.Values)
            {
                if (star.Owner == empireId)
                {
                    score.Planets++;
                    resources += (int)star.ResourcesOnHand.Energy;

                    if (star.Starbase != null)
                    {
                        starBases++;
                        totalScore += 3;
                    }

                    totalScore += star.Colonists / 100000;
                }
            }

            score.Starbases = starBases;
            score.Resources = resources;
            totalScore     += resources / 30;

            // ----------------------------------------------------------------------------
            // Count ship specific values.
            // ----------------------------------------------------------------------------

            int unarmedShips = 0;
            int escortShips  = 0;
            int capitalShips = 0;


            foreach (Fleet fleet in serverState.IterateAllFleets())
            {
                if (fleet.Owner == empireId)
                {
                    foreach (ShipToken token in fleet.Composition.Values)
                    {
                        if (token.Design.HasWeapons == false)
                        {
                            unarmedShips++;
                            totalScore += 0.5;
                        }
                        else
                        {
                            if (token.Design.PowerRating < 2000)
                            {
                                escortShips++;
                                totalScore += 2;
                            }
                            else
                            {
                                capitalShips++;
                            }
                        }
                    }
                }
            }

            score.UnarmedShips = unarmedShips;
            score.EscortShips  = escortShips;
            score.CapitalShips = capitalShips;

            if (capitalShips != 0)
            {
                int stars = score.Planets;
                totalScore += (8 * capitalShips * stars) / (capitalShips + stars);
            }

            // ----------------------------------------------------------------------------
            // Single instance values.
            // ----------------------------------------------------------------------------

            score.EmpireId = empireId;
            if (serverState.AllTechLevels.ContainsKey(empireId))
            {
                score.TechLevel = serverState.AllTechLevels[empireId];

                if (score.TechLevel < 4)
                {
                    totalScore += 1;
                }
                if (score.TechLevel > 9)
                {
                    totalScore += 4;
                }
                if (score.TechLevel > 3 && score.TechLevel < 7)
                {
                    totalScore += 2;
                }
                if (score.TechLevel > 6 && score.TechLevel < 10)
                {
                    totalScore += 3;
                }
            }

            score.Score = (int)totalScore;

            return(score);
        }