public FleetManager(Empire empire)
 {
     this._empire = empire;
     _currentShipDesignID = 0;
     _fleets = new List<Fleet>();
     CurrentDesigns = new List<Ship>();
     //ObsoleteDesigns = new List<Ship>();
 }
Beispiel #2
0
        public void SplitFleet(Empire empire)
        {
            Fleet fleet = new Fleet();
            fleet.Empire = FleetToSplit.Empire;
            fleet.GalaxyX = FleetToSplit.GalaxyX;
            fleet.GalaxyY = FleetToSplit.GalaxyY;
            fleet.AdjacentSystem = FleetToSplit.AdjacentSystem;

            foreach (KeyValuePair<Ship, int> ship in FleetToSplit.Ships)
            {
                if (ship.Value > 0)
                {
                    SelectedFleet.SubtractShips(ship.Key, ship.Value);
                    fleet.AddShips(ship.Key, ship.Value);
                }
            }
            foreach (var transport in FleetToSplit.TransportShips)
            {
                if (transport.amount > 0)
                {
                    SelectedFleet.SubtractTransport(transport.raceOnShip, transport.amount);
                    fleet.AddTransport(transport.raceOnShip, transport.amount);
                }
            }
            SelectedFleet.ClearEmptyShips();
            fleet.ClearEmptyShips();
            fleet.TravelNodes = FleetToSplit.TravelNodes;
            if (SelectedFleet.Ships.Count == 0 && SelectedFleet.TransportShips.Count == 0)
            {
                Fleets.Remove(SelectedFleet);
                empire.FleetManager.RemoveFleet(SelectedFleet);
            }
            if (fleet.Ships.Count > 0 || fleet.TransportShips.Count > 0)
            {
                Fleets.Add(fleet);
                empire.FleetManager.AddFleet(fleet);
            }
            SelectedFleet = fleet;
        }
Beispiel #3
0
        private bool IsDestinationValid(StarSystem destination, bool hasExtended, Empire whichEmpire)
        {
            if (destination.Planets[0].Owner == whichEmpire)
            {
                //By default, always true if destination is owned
                return(true);
            }
            int fuelRange = (whichEmpire.TechnologyManager.FuelRange + (hasExtended ? 3 : 0)) * PARSEC_SIZE_IN_PIXELS;

            fuelRange *= fuelRange;             //To avoid square rooting
            foreach (StarSystem system in starSystems)
            {
                if (system.Planets[0].Owner == whichEmpire)
                {
                    float x = destination.X - system.X;
                    float y = destination.Y - system.Y;
                    if ((x * x) + (y * y) <= fuelRange)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Beispiel #4
0
        private void SetValues(string name, string type, int maxPop, StarSystem system, Empire empire, Random r)
        {
            _whichSystem = system;
            this._name = name;
            _races = new List<Race>();
            _racePopulations = new Dictionary<Race, float>();
            TransferSystem = new KeyValuePair<TravelNode, int>(new TravelNode(), 0);
            TransferSystemID = new KeyValuePair<int, int>();
            RelocateToSystem = null;
            Owner = empire;
            _populationMax = maxPop;

            switch (type)
            {
                case ARCTIC:
                    {
                        _planetType = PLANET_TYPE.ARCTIC;
                        SmallSprite = SpriteManager.GetSprite("ArcticPlanetSmall", r);
                        GroundSprite = SpriteManager.GetSprite("ArcticGround", r);
                    } break;
                case BADLANDS:
                    {
                        _planetType = PLANET_TYPE.BADLAND;
                        SmallSprite = SpriteManager.GetSprite("BadlandsPlanetSmall", r);
                        GroundSprite = SpriteManager.GetSprite("BadlandsGround", r);
                    } break;
                case BARREN:
                    {
                        _planetType = PLANET_TYPE.BARREN;
                        SmallSprite = SpriteManager.GetSprite("BarrenPlanetSmall", r);
                        GroundSprite = SpriteManager.GetSprite("BarrenGround", r);
                    } break;
                case DEAD:
                    {
                        _planetType = PLANET_TYPE.DEAD;
                        SmallSprite = SpriteManager.GetSprite("DeadPlanetSmall", r);
                        GroundSprite = SpriteManager.GetSprite("DeadGround", r);
                    } break;
                case DESERT:
                    {
                        _planetType = PLANET_TYPE.DESERT;
                        SmallSprite = SpriteManager.GetSprite("DesertPlanetSmall", r);
                        GroundSprite = SpriteManager.GetSprite("DesertGround", r);
                    } break;
                case JUNGLE:
                    {
                        _planetType = PLANET_TYPE.JUNGLE;
                        SmallSprite = SpriteManager.GetSprite("JunglePlanetSmall", r);
                        GroundSprite = SpriteManager.GetSprite("JungleGround", r);
                    } break;
                case NONE:
                    {
                        _planetType = PLANET_TYPE.NONE;
                        SmallSprite = SpriteManager.GetSprite("AsteroidsPlanetSmall", r);
                    } break;
                case OCEANIC:
                    {
                        _planetType = PLANET_TYPE.OCEAN;
                        SmallSprite = SpriteManager.GetSprite("OceanicPlanetSmall", r);
                        GroundSprite = SpriteManager.GetSprite("OceanicGround", r);
                    } break;
                case RADIATED:
                    {
                        _planetType = PLANET_TYPE.RADIATED;
                        SmallSprite = SpriteManager.GetSprite("RadiatedPlanetSmall", r);
                        GroundSprite = SpriteManager.GetSprite("RadiatedGround", r);
                    } break;
                case STEPPE:
                    {
                        _planetType = PLANET_TYPE.STEPPE;
                        SmallSprite = SpriteManager.GetSprite("SteppePlanetSmall", r);
                        GroundSprite = SpriteManager.GetSprite("SteppeGround", r);
                    } break;
                case TERRAN:
                    {
                        _planetType = PLANET_TYPE.TERRAN;
                        SmallSprite = SpriteManager.GetSprite("TerranPlanetSmall", r);
                        GroundSprite = SpriteManager.GetSprite("TerranGround", r);
                    } break;
                case TOXIC:
                    {
                        _planetType = PLANET_TYPE.TOXIC;
                        SmallSprite = SpriteManager.GetSprite("ToxicPlanetSmall", r);
                        GroundSprite = SpriteManager.GetSprite("ToxicGround", r);
                    } break;
                case TUNDRA:
                    {
                        _planetType = PLANET_TYPE.TUNDRA;
                        SmallSprite = SpriteManager.GetSprite("TundraPlanetSmall", r);
                        GroundSprite = SpriteManager.GetSprite("TundraGround", r);
                    } break;
                case VOLCANIC:
                    {
                        _planetType = PLANET_TYPE.VOLCANIC;
                        SmallSprite = SpriteManager.GetSprite("VolcanicPlanetSmall", r);
                        GroundSprite = SpriteManager.GetSprite("VolcanicGround", r);
                    } break;
            }

            _planetTypeString = Utility.PlanetTypeToString(_planetType);
        }
 public void RemoveEmpire(Empire empire)
 {
     _empires.Remove(empire);
 }
Beispiel #6
0
 public StarSystem SetHomeworld(Empire empire, out Planet homePlanet)
 {
     lock (_lockGalaxy) //Won't modify anything, but ensures that galaxy is created and won't throw exceptions due to contents being modified
     {
         Random r = new Random();
         List<StarSystem> potentialSystems = new List<StarSystem>(starSystems);
         while (true)
         {
             if (potentialSystems.Count == 0)
             {
                 homePlanet = null;
                 return null;
             }
             var potentialSystem = potentialSystems[r.Next(potentialSystems.Count)];
             if (potentialSystem.EmpiresWithPlanetsInThisSystem.Count > 0)
             {
                 potentialSystems.Remove(potentialSystem);
                 continue;
             }
             //Validation checks
             bool FourParsecsSystem = false;
             bool SixParsecsSystem = false;
             bool AtLeastSixParsecsAwayFromOthers = true;
             foreach (StarSystem starSystem in starSystems)
             {
                 if (potentialSystem != starSystem)
                 {
                     int x = potentialSystem.X - starSystem.X;
                     int y = potentialSystem.Y - starSystem.Y;
                     double distance = Math.Sqrt((x * x) + (y * y));
                     if (distance <= PARSEC_SIZE_IN_PIXELS * 4)
                     {
                         if (!FourParsecsSystem)
                         {
                             FourParsecsSystem = true;
                         }
                         else
                         {
                             //Already have another star system that's within 4 parsecs
                             SixParsecsSystem = true;
                         }
                         if (starSystem.EmpiresWithPlanetsInThisSystem.Count > 0)
                         {
                             AtLeastSixParsecsAwayFromOthers = false;
                             break;
                         }
                     }
                     else if (distance <= PARSEC_SIZE_IN_PIXELS * 6)
                     {
                         SixParsecsSystem = true;
                         if (starSystem.EmpiresWithPlanetsInThisSystem.Count > 0)
                         {
                             AtLeastSixParsecsAwayFromOthers = false;
                             break;
                         }
                     }
                 }
             }
             if (FourParsecsSystem && SixParsecsSystem && AtLeastSixParsecsAwayFromOthers)
             {
                 potentialSystem.SetHomeworld(empire, out homePlanet, r);
                 return potentialSystem;
             }
             potentialSystems.Remove(potentialSystem);
         }
     }
 }
Beispiel #7
0
 public StarSystem SetHomeworld(Empire empire, out Planet homePlanet)
 {
     lock (_lockGalaxy)             //Won't modify anything, but ensures that galaxy is created and won't throw exceptions due to contents being modified
     {
         Random            r = new Random();
         List <StarSystem> potentialSystems = new List <StarSystem>(starSystems);
         while (true)
         {
             if (potentialSystems.Count == 0)
             {
                 homePlanet = null;
                 return(null);
             }
             var potentialSystem = potentialSystems[r.Next(potentialSystems.Count)];
             if (potentialSystem.EmpiresWithPlanetsInThisSystem.Count > 0)
             {
                 potentialSystems.Remove(potentialSystem);
                 continue;
             }
             //Validation checks
             bool FourParsecsSystem = false;
             bool SixParsecsSystem  = false;
             bool AtLeastSixParsecsAwayFromOthers = true;
             foreach (StarSystem starSystem in starSystems)
             {
                 if (potentialSystem != starSystem)
                 {
                     int    x        = potentialSystem.X - starSystem.X;
                     int    y        = potentialSystem.Y - starSystem.Y;
                     double distance = Math.Sqrt((x * x) + (y * y));
                     if (distance <= PARSEC_SIZE_IN_PIXELS * 4)
                     {
                         if (!FourParsecsSystem)
                         {
                             FourParsecsSystem = true;
                         }
                         else
                         {
                             //Already have another star system that's within 4 parsecs
                             SixParsecsSystem = true;
                         }
                         if (starSystem.EmpiresWithPlanetsInThisSystem.Count > 0)
                         {
                             AtLeastSixParsecsAwayFromOthers = false;
                             break;
                         }
                     }
                     else if (distance <= PARSEC_SIZE_IN_PIXELS * 6)
                     {
                         SixParsecsSystem = true;
                         if (starSystem.EmpiresWithPlanetsInThisSystem.Count > 0)
                         {
                             AtLeastSixParsecsAwayFromOthers = false;
                             break;
                         }
                     }
                 }
             }
             if (FourParsecsSystem && SixParsecsSystem && AtLeastSixParsecsAwayFromOthers)
             {
                 potentialSystem.SetHomeworld(empire, out homePlanet, r);
                 return(potentialSystem);
             }
             potentialSystems.Remove(potentialSystem);
         }
     }
 }
Beispiel #8
0
 public bool SystemHavePlanetOwnedByEmpire(Empire empire)
 {
     return(EmpiresWithPlanetsInThisSystem.Contains(empire));
 }
Beispiel #9
0
 public void Load(XElement fleet, FleetManager fleetManager, Empire empire, GameMain gameMain)
 {
     _empire = empire;
     _galaxyX = float.Parse(fleet.Attribute("X").Value);
     _galaxyY = float.Parse(fleet.Attribute("Y").Value);
     _adjacentSystem = gameMain.Galaxy.GetStarWithID(int.Parse(fleet.Attribute("AdjacentSystem").Value));
     var travelNodes = fleet.Element("TravelNodes");
     if (travelNodes != null)
     {
         _travelNodes = new List<TravelNode>();
         StarSystem startingPlace = null;
         foreach (var travelNode in travelNodes.Elements())
         {
             var destination = gameMain.Galaxy.GetStarWithID(int.Parse(travelNode.Attribute("Destination").Value));
             if (startingPlace == null)
             {
                 _travelNodes.Add(gameMain.Galaxy.GenerateTravelNode(_galaxyX, _galaxyY, destination));
             }
             else
             {
                 _travelNodes.Add(gameMain.Galaxy.GenerateTravelNode(startingPlace, destination));
             }
             startingPlace = destination;
         }
     }
     foreach (var ship in fleet.Elements("Ship"))
     {
         AddShips(fleetManager.GetShipWithDesignID(int.Parse(ship.Attribute("ShipDesign").Value)), int.Parse(ship.Attribute("NumberOfShips").Value));
     }
     foreach (var transport in fleet.Elements("Transport"))
     {
         AddTransport(gameMain.RaceManager.GetRace(transport.Attribute("Race").Value), int.Parse(transport.Attribute("Count").Value));
     }
 }
 public void AddEmpire(Empire empire)
 {
     _empires.Add(empire);
 }
 public void SetInitialEmpireTurn()
 {
     foreach (Empire empire in _empires)
     {
         //Reset fleet movement and stuff
         empire.FleetManager.ResetFleetMovements();
     }
     empireIter = 0;
     //If first player isn't human, find the next one
     for (int i = 0; i < _empires.Count; i++)
     {
         if (_empires[i].Type != PlayerType.HUMAN)
         {
             _empires[i].HandleAIEmpire();
         }
         else
         {
             currentEmpire = _empires[i];
             empireIter = i;
             break;
         }
     }
 }
 public void RemoveEmpire(Empire empire)
 {
     _empires.Remove(empire);
 }
 public bool ProcessNextEmpire()
 {
     if (empireIter + 1 == _empires.Count)
     {
         //It've reached the end
         return true;
     }
     //This will update each empire if they're AI.  If an empire is human-controlled, it stops and waits for the player to press end of turn
     for (int i = empireIter + 1; i < _empires.Count; i++)
     {
         empireIter = i;
         if (_empires[i].Type != PlayerType.HUMAN)
         {
             _empires[i].HandleAIEmpire();
             if (i + 1 == _empires.Count)
             {
                 //reached end of list with CPU player as last player
                 return true;
             }
         }
         else
         {
             currentEmpire = _empires[i];
             break;
         }
     }
     return false;
 }
 public bool Load(XElement root)
 {
     _empires = new List<Empire>();
     var empires = root.Element("Empires");
     foreach (var empire in empires.Elements())
     {
         var newEmpire = new Empire();
         newEmpire.Load(empire, _gameMain);
         _empires.Add(newEmpire);
     }
     foreach (var empire in _empires)
     {
         empire.SetUpContacts(_empires);
         //TODO: Update all empires' contacts
     }
     SetInitialEmpireTurn();
     return true;
 }
Beispiel #15
0
 public Planet(string name, string type, int maxPop, Empire owner, StarSystem system, Random r)
 {
     SetValues(name, type, maxPop, system, owner, r);
 }
Beispiel #16
0
 public void AddEmpireExplored(Empire empire)
 {
     exploredBy.Add(empire);
 }
Beispiel #17
0
 public void Load(XElement empireDoc, Empire empire, GameMain gameMain)
 {
     var currentDesigns = empireDoc.Element("CurrentShipDesigns");
     foreach (var currentDesign in currentDesigns.Elements())
     {
         var currentShip = new Ship();
         currentShip.Load(currentDesign, gameMain);
         currentShip.Owner = empire;
         CurrentDesigns.Add(currentShip);
     }
     /*var obsoleteDesigns = empireDoc.Element("ObsoleteShipDesigns");
     foreach (var obsoleteDesign in obsoleteDesigns.Elements())
     {
         var obsoleteShip = new Ship();
         obsoleteShip.Load(obsoleteDesign, gameMain);
         obsoleteShip.Owner = empire;
         ObsoleteDesigns.Add(obsoleteShip);
     }*/
     var fleets = empireDoc.Element("Fleets");
     foreach (var fleet in fleets.Elements())
     {
         var newFleet = new Fleet();
         newFleet.Load(fleet, this, empire, gameMain);
         _fleets.Add(newFleet);
     }
 }
Beispiel #18
0
 public bool IsThisSystemExploredByEmpire(Empire empire)
 {
     return exploredBy.Contains(empire);
 }
Beispiel #19
0
 public bool IsThisSystemExploredByEmpire(Empire empire)
 {
     return(exploredBy.Contains(empire));
 }
Beispiel #20
0
 public void SetHomeworld(Empire empire, out Planet homePlanet, Random r)
 {
     if (planets.Count == 0)
     {
         planets.Add(new Planet(name, r, this)); //planets.Add(new Planet(name + " I", r, this));
         planets[0].SetHomeworld(empire, r);
         homePlanet = planets[0];
     }
     else
     {
         int whichPlanet = r.Next(planets.Count);
         planets[whichPlanet].SetHomeworld(empire, r);
         homePlanet = planets[whichPlanet];
     }
     Color = Color.Yellow; //Homeworlds always have yellow stars
     exploredBy.Add(empire);
     UpdateOwners();
 }
Beispiel #21
0
 public void AddEmpireExplored(Empire empire)
 {
     exploredBy.Add(empire);
 }
Beispiel #22
0
 public bool SystemHavePlanetOwnedByEmpire(Empire empire)
 {
     return EmpiresWithPlanetsInThisSystem.Contains(empire);
 }
Beispiel #23
0
        /// <summary>
        /// Pathfinding function
        /// </summary>
        /// <param name="currentX">Fleet's Galaxy X</param>
        /// <param name="currentY">Fleet's Galaxy Y</param>
        /// <param name="currentDestination">Fleet's current destination for when empire don't have hyperspace communications</param>
        /// <param name="newDestination">New destination</param>
        /// <param name="hasExtended"></param>
        /// <param name="whichEmpire">For fuel range and other info</param>
        /// <returns></returns>
        public List <TravelNode> GetPath(float currentX, float currentY, StarSystem currentDestination, StarSystem newDestination, bool hasExtended, Empire whichEmpire)
        {
            // TODO: When Hyperspace communication is implemented, add this

            /*
             * if (whichEmpire.HasHyperspaceCommunications())
             * {
             *
             * }
             * else
             * {
             * }
             */
            // TODO: When adding stargates and wormholes, add actual pathfinding
            List <TravelNode> nodes = new List <TravelNode>();

            if (currentDestination != null)
            {
                TravelNode newNode = GenerateTravelNode(currentX, currentY, currentDestination);
                newNode.IsValid = true;
                nodes.Add(newNode);
                newNode         = GenerateTravelNode(currentDestination, newDestination);
                newNode.IsValid = IsDestinationValid(newDestination, hasExtended, whichEmpire);
                nodes.Add(newNode);
            }
            else
            {
                TravelNode newNode = GenerateTravelNode(currentX, currentY, newDestination);
                newNode.IsValid = IsDestinationValid(newDestination, hasExtended, whichEmpire);
                nodes.Add(newNode);
            }

            return(nodes);
        }
Beispiel #24
0
 public void Colonize(Empire whichEmpire)
 {
     _owner = whichEmpire;
     whichEmpire.PlanetManager.AddOwnedPlanet(this);
     _racePopulations = new Dictionary<Race, float>();
     _racePopulations.Add(whichEmpire.EmpireRace, 2);
     _races.Add(whichEmpire.EmpireRace);
     SetOutputAmount(OUTPUT_TYPE.INFRASTRUCTURE, 100, true);
     _shipBeingBuilt = whichEmpire.FleetManager.CurrentDesigns[0];
     System.UpdateOwners();
 }
Beispiel #25
0
        /// <summary>
        /// Pathfinding function
        /// </summary>
        /// <param name="currentX">Fleet's Galaxy X</param>
        /// <param name="currentY">Fleet's Galaxy Y</param>
        /// <param name="currentDestination">Fleet's current destination for when empire don't have hyperspace communications</param>
        /// <param name="newDestination">New destination</param>
        /// <param name="hasExtended"></param>
        /// <param name="whichEmpire">For fuel range and other info</param>
        /// <returns></returns>
        public List<TravelNode> GetPath(float currentX, float currentY, StarSystem currentDestination, StarSystem newDestination, bool hasExtended, Empire whichEmpire)
        {
            // TODO: When Hyperspace communication is implemented, add this
            /*
            if (whichEmpire.HasHyperspaceCommunications())
            {

            }
            else
            {
            }
            */
            // TODO: When adding stargates and wormholes, add actual pathfinding
            List<TravelNode> nodes = new List<TravelNode>();
            if (currentDestination != null)
            {
                TravelNode newNode = GenerateTravelNode(currentX, currentY, currentDestination);
                newNode.IsValid = true;
                nodes.Add(newNode);
                newNode = GenerateTravelNode(currentDestination, newDestination);
                newNode.IsValid = IsDestinationValid(newDestination, hasExtended, whichEmpire);
                nodes.Add(newNode);
            }
            else
            {
                TravelNode newNode = GenerateTravelNode(currentX, currentY, newDestination);
                newNode.IsValid = IsDestinationValid(newDestination, hasExtended, whichEmpire);
                nodes.Add(newNode);
            }

            return nodes;
        }
Beispiel #26
0
 //Set this planet as homeworld
 public void SetHomeworld(Empire owner, Random r)
 {
     _owner = owner;
     _planetType = PLANET_TYPE.TERRAN;
     _planetTypeString = Utility.PlanetTypeToString(_planetType);
     SmallSprite = SpriteManager.GetSprite("TerranPlanetSmall", r);
     _populationMax = 100;
     _races.Add(owner.EmpireRace);
     _racePopulations.Add(owner.EmpireRace, 40);
     Factories = 30;
     _factoryInvestments = 300; //Start with 300 BCs invested in factories
     SetOutputAmount(OUTPUT_TYPE.INFRASTRUCTURE, 100, true);
     ResearchBonus = PLANET_RESEARCH_BONUS.AVERAGE;
     ConstructionBonus = PLANET_CONSTRUCTION_BONUS.AVERAGE;
     EnvironmentBonus = PLANET_ENVIRONMENT_BONUS.AVERAGE;
 }
Beispiel #27
0
 private bool IsDestinationValid(StarSystem destination, bool hasExtended, Empire whichEmpire)
 {
     if (destination.Planets[0].Owner == whichEmpire)
     {
         //By default, always true if destination is owned
         return true;
     }
     int fuelRange = (whichEmpire.TechnologyManager.FuelRange + (hasExtended ? 3 : 0)) * PARSEC_SIZE_IN_PIXELS;
     fuelRange *= fuelRange; //To avoid square rooting
     foreach (StarSystem system in starSystems)
     {
         if (system.Planets[0].Owner == whichEmpire)
         {
             float x = destination.X - system.X;
             float y = destination.Y - system.Y;
             if ((x * x) + (y * y) <= fuelRange)
             {
                 return true;
             }
         }
     }
     return false;
 }
 public void AddEmpire(Empire empire)
 {
     _empires.Add(empire);
 }