Exemple #1
0
 public void SetHomeSystem(StarSystem homeSystem, Planet homePlanet)
 {
     selectedSystem = homeSystem;
     lastSelectedSystem = homeSystem;
     PlanetManager.AddOwnedPlanet(homePlanet);
     FleetManager.SetupStarterFleet(homeSystem);
     homePlanet.ShipBeingBuilt = FleetManager.CurrentDesigns[0];
     homePlanet.SetCleanup();
     homePlanet.UpdateOutputs();
 }
Exemple #2
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);
         }
     }
 }
Exemple #3
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();
 }
Exemple #4
0
 public bool Load(XElement root, GameMain gameMain)
 {
     var galaxyElement = root.Element("Galaxy");
     if (galaxyElement == null)
     {
         return false;
     }
     GalaxySize = int.Parse(galaxyElement.Attribute("Width").Value);
     starSystems = new List<StarSystem>();
     _quickLookupSystem = new Dictionary<int, StarSystem>();
     var starsElement = galaxyElement.Element("Stars");
     foreach (var star in starsElement.Elements())
     {
         string name = star.Attribute("Name").Value;
         string description = star.Attribute("Description").Value;
         int id = int.Parse(star.Attribute("ID").Value);
         int xPos = int.Parse(star.Attribute("XPos").Value);
         int yPos = int.Parse(star.Attribute("YPos").Value);
         string[] color = star.Attribute("Color").Value.Split(new[] {','});
         float[] starColor = new float[4];
         for (int i = 0; i < 4; i++)
         {
             starColor[i] = float.Parse(color[i]);
         }
         StarSystem newStar = new StarSystem(name, id, xPos, yPos, Color.FromArgb((int)(255 * starColor[3]), (int)(255 * starColor[0]), (int)(255 * starColor[1]), (int)(255 * starColor[2])), description, gameMain.Random);
         newStar.ExploredByIDs = star.Attribute("ExploredBy").Value;
         foreach (var planetElement in star.Elements())
         {
             string planetName = planetElement.Attribute("Name").Value;
             string type = planetElement.Attribute("Type").Value;
             int owner = -1;
             if (!string.IsNullOrEmpty(planetElement.Attribute("Owner").Value))
             {
                 owner = int.Parse(planetElement.Attribute("Owner").Value);
             }
             int populationMax = int.Parse(planetElement.Attribute("MaxPopulation").Value);
             var newPlanet = new Planet(planetName, type, populationMax, null, newStar, gameMain.Random);
             newPlanet.OwnerID = owner;
             newPlanet.Factories = float.Parse(planetElement.Attribute("Buildings").Value);
             newPlanet.EnvironmentAmount = int.Parse(planetElement.Attribute("EnvironmentPercentage").Value);
             newPlanet.InfrastructureAmount = int.Parse(planetElement.Attribute("InfrastructurePercentage").Value);
             newPlanet.DefenseAmount = int.Parse(planetElement.Attribute("DefensePercentage").Value);
             newPlanet.ConstructionAmount = int.Parse(planetElement.Attribute("ConstructionPercentage").Value);
             newPlanet.ResearchAmount = int.Parse(planetElement.Attribute("ResearchPercentage").Value);
             newPlanet.EnvironmentLocked = bool.Parse(planetElement.Attribute("EnvironmentLocked").Value);
             newPlanet.InfrastructureLocked = bool.Parse(planetElement.Attribute("InfrastructureLocked").Value);
             newPlanet.DefenseLocked = bool.Parse(planetElement.Attribute("DefenseLocked").Value);
             newPlanet.ConstructionLocked = bool.Parse(planetElement.Attribute("ConstructionLocked").Value);
             newPlanet.ResearchLocked = bool.Parse(planetElement.Attribute("ResearchLocked").Value);
             newPlanet.ShipBeingBuiltID = int.Parse(planetElement.Attribute("ShipBuilding").Value);
             newPlanet.ShipConstructionAmount = float.Parse(planetElement.Attribute("AmountBuilt").Value);
             newPlanet.RelocateToSystemID = int.Parse(planetElement.Attribute("RelocatingTo").Value);
             var transferTo = planetElement.Element("TransferTo");
             if (transferTo != null)
             {
                 newPlanet.TransferSystemID = new KeyValuePair<int, int>(int.Parse(transferTo.Attribute("StarSystem").Value), int.Parse(transferTo.Attribute("Amount").Value));
             }
             var races = planetElement.Element("Races");
             foreach (var race in races.Elements())
             {
                 newPlanet.AddRacePopulation(gameMain.RaceManager.GetRace(race.Attribute("RaceName").Value), float.Parse(race.Attribute("Amount").Value));
             }
             newStar.Planets.Add(newPlanet);
         }
         starSystems.Add(newStar);
         _quickLookupSystem.Add(newStar.ID, newStar);
     }
     //Now match up IDs to actual classes
     foreach (var starSystem in starSystems)
     {
         foreach (var planet in starSystem.Planets)
         {
             if (planet.RelocateToSystemID != -1)
             {
                 planet.RelocateToSystem = new TravelNode {StarSystem = _quickLookupSystem[planet.RelocateToSystemID]};
                 planet.RelocateToSystemID = -1;
             }
             if (!planet.TransferSystemID.Equals(new KeyValuePair<int, int>()))
             {
                 planet.TransferSystem = new KeyValuePair<TravelNode, int>(new TravelNode { StarSystem = _quickLookupSystem[planet.TransferSystemID.Key] }, planet.TransferSystemID.Value);
             }
         }
     }
     return true;
 }
 public void AddOwnedPlanet(Planet planet)
 {
     _planets.Add(planet);
 }