Пример #1
0
 public TravelNode GenerateTravelNode(float xPos, float yPos, StarSystem destination)
 {
     TravelNode newNode = new TravelNode();
     newNode.StarSystem = destination;
     float x = destination.X - xPos;
     float y = destination.Y - yPos;
     newNode.Length = (float)Math.Sqrt((x * x) + (y * y));
     newNode.Angle = (float)(Math.Atan2(y, x) * (180 / Math.PI));
     return newNode;
 }
Пример #2
0
        private void FillGalaxyWithStars(int numberOfStars, int minPlanets, int maxPlanets, bool[][] grid, Random r)
        {
            starSystems = new List<StarSystem>();
            _quickLookupSystem = new Dictionary<int, StarSystem>();

            StarNode starTree = new StarNode(0, 0, grid.Length - 1, grid.Length - 1);

            //Set area where stars can be placed (circle, random, star, etc shaped galaxy)
            for (int i = 0; i < grid.Length; i++)
            {
                for (int j = 0; j < grid[i].Length; j++)
                {
                    if (!grid[i][j])
                    {
                        starTree.RemoveNodeAtPosition(i, j);
                    }
                }
            }

            int starId = 0;
            while (starTree.nodes.Count > 0 && numberOfStars > 0)
            {
                int x;
                int y;

                starTree.GetRandomStarPosition(r, out x, out y);

                //int newSize = r.Next(3) + 2;

                Color starColor = Color.White;
                string description = string.Empty;

                int randNum = r.Next(100);

                if (randNum < 30)
                {
                    starColor = Color.Red;
                }
                else if (randNum < 55)
                {
                    starColor = Color.Green;
                }
                else if (randNum < 70)
                {
                    starColor = Color.Yellow;
                }
                else if (randNum < 85)
                {
                    starColor = Color.Blue;
                }
                else if (randNum < 95)
                {
                    starColor = Color.White;
                }
                else
                {
                    starColor = Color.Purple;
                }

                var newStarsystem = new StarSystem(NameGenerator.GetStarName(r), starId, x * PARSEC_SIZE_IN_PIXELS + (r.Next(PARSEC_SIZE_IN_PIXELS)), y * PARSEC_SIZE_IN_PIXELS + (r.Next(PARSEC_SIZE_IN_PIXELS)), starColor, description, minPlanets, maxPlanets, r);
                starSystems.Add(newStarsystem);
                _quickLookupSystem.Add(newStarsystem.ID, newStarsystem);

                bool[][] invalidatedArea = Utility.CalculateDisc(2, 1);

                for (int i = 0; i < invalidatedArea.Length; i++)
                {
                    for (int j = 0; j < invalidatedArea.Length; j++)
                    {
                        int xToInvalidate = (x - 2) + i;
                        int yToInvalidate = (y - 2) + j;

                        starTree.RemoveNodeAtPosition(xToInvalidate, yToInvalidate);
                    }
                }

                numberOfStars--;
                starId++;
            }
        }
Пример #3
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;
 }
Пример #4
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;
        }
Пример #5
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);
        }
Пример #6
0
        public void SetupStarterFleet(StarSystem homeSystem)
        {
            Technology retroEngine    = null;
            Technology titaniumArmor  = null;
            Technology laser          = null;
            Technology nuclearMissile = null;
            Technology nuclearBomb    = null;

            foreach (var tech in _empire.TechnologyManager.ResearchedPropulsionTechs)
            {
                if (tech.Speed == 1)
                {
                    retroEngine = tech;
                    break;
                }
            }
            foreach (var tech in _empire.TechnologyManager.ResearchedConstructionTechs)
            {
                if (tech.Armor == Technology.TITANIUM_ARMOR)
                {
                    titaniumArmor = tech;
                    break;
                }
            }
            foreach (var tech in _empire.TechnologyManager.ResearchedWeaponTechs)
            {
                if (tech.TechName == "Laser")
                {
                    laser = tech;
                }
                else if (tech.TechName == "Nuclear Missile")
                {
                    nuclearMissile = tech;
                }
                else if (tech.TechName == "Nuclear Bomb")
                {
                    nuclearBomb = tech;
                }
            }
            Ship scout = new Ship();

            scout.Name       = "Scout";
            scout.Owner      = _empire;
            scout.Size       = Ship.SMALL;
            scout.WhichStyle = 0;
            scout.Armor      = new Equipment(titaniumArmor, false);
            foreach (var tech in _empire.TechnologyManager.ResearchedConstructionTechs)
            {
                if (tech.ReserveFuelTanks)
                {
                    scout.Specials[0] = new Equipment(tech, false);
                    break;
                }
            }
            scout.Engine   = new KeyValuePair <Equipment, float>(new Equipment(retroEngine, false), scout.PowerUsed / (retroEngine.Speed * 10));
            scout.DesignID = _currentShipDesignID;
            CurrentDesigns.Add(scout);
            _currentShipDesignID++;

            Ship fighter = new Ship();

            fighter.Name       = "Fighter";
            fighter.Owner      = _empire;
            fighter.Size       = Ship.SMALL;
            fighter.WhichStyle = 1;
            fighter.Weapons[0] = new KeyValuePair <Equipment, int>(new Equipment(laser, false), 1);
            fighter.Armor      = new Equipment(titaniumArmor, false);
            fighter.Engine     = new KeyValuePair <Equipment, float>(new Equipment(retroEngine, false), fighter.PowerUsed / (retroEngine.Speed * 10));
            CurrentDesigns.Add(fighter);
            _currentShipDesignID++;

            Ship destroyer = new Ship();

            destroyer.Name       = "Destroyer";
            destroyer.Owner      = _empire;
            destroyer.Size       = Ship.MEDIUM;
            destroyer.WhichStyle = 0;
            destroyer.Weapons[0] = new KeyValuePair <Equipment, int>(new Equipment(nuclearMissile, false), 1);
            destroyer.Weapons[1] = new KeyValuePair <Equipment, int>(new Equipment(laser, false), 3);
            destroyer.Armor      = new Equipment(titaniumArmor, false);
            destroyer.Engine     = new KeyValuePair <Equipment, float>(new Equipment(retroEngine, false), destroyer.PowerUsed / (retroEngine.Speed * 10));
            CurrentDesigns.Add(destroyer);
            _currentShipDesignID++;

            Ship bomber = new Ship();

            bomber.Name       = "Bomber";
            bomber.Owner      = _empire;
            bomber.Size       = Ship.MEDIUM;
            bomber.WhichStyle = 1;
            bomber.Weapons[0] = new KeyValuePair <Equipment, int>(new Equipment(nuclearBomb, false), 2);
            bomber.Weapons[1] = new KeyValuePair <Equipment, int>(new Equipment(laser, false), 2);
            bomber.Armor      = new Equipment(titaniumArmor, false);
            bomber.Engine     = new KeyValuePair <Equipment, float>(new Equipment(retroEngine, false), bomber.PowerUsed / (retroEngine.Speed * 10));
            CurrentDesigns.Add(bomber);
            _currentShipDesignID++;

            Ship colonyShip = new Ship();

            colonyShip.Name       = "Colony Ship";
            colonyShip.Owner      = _empire;
            colonyShip.Size       = Ship.LARGE;
            colonyShip.WhichStyle = 0;
            colonyShip.Armor      = new Equipment(titaniumArmor, false);
            foreach (var tech in _empire.TechnologyManager.ResearchedPlanetologyTechs)
            {
                if (tech.Colony == Technology.STANDARD_COLONY)
                {
                    colonyShip.Specials[0] = new Equipment(tech, false);
                    break;
                }
            }
            colonyShip.Engine   = new KeyValuePair <Equipment, float>(new Equipment(retroEngine, false), colonyShip.PowerUsed / (retroEngine.Speed * 10));
            colonyShip.DesignID = _currentShipDesignID;
            CurrentDesigns.Add(colonyShip);
            _currentShipDesignID++;

            LastShipDesign = new Ship(scout);             //Make a copy so we don't accidentally modify the original ship

            Fleet starterFleet = new Fleet();

            starterFleet.GalaxyX        = homeSystem.X;
            starterFleet.GalaxyY        = homeSystem.Y;
            starterFleet.AdjacentSystem = homeSystem;
            starterFleet.Empire         = _empire;
            starterFleet.AddShips(CurrentDesigns[0], 2);
            starterFleet.AddShips(CurrentDesigns[4], 1);
            _fleets.Add(starterFleet);
        }
Пример #7
0
 public void Load(XElement empireToLoad, GameMain gameMain)
 {
     empireID = int.Parse(empireToLoad.Attribute("ID").Value);
     empireName = empireToLoad.Attribute("Name").Value;
     EmpireColor = Color.FromArgb(int.Parse(empireToLoad.Attribute("Color").Value));
     EmpireRace = gameMain.RaceManager.GetRace(empireToLoad.Attribute("Race").Value);
     type = bool.Parse(empireToLoad.Attribute("IsHumanPlayer").Value) ? PlayerType.HUMAN : PlayerType.CPU;
     lastSelectedSystem = gameMain.Galaxy.GetStarWithID(int.Parse(empireToLoad.Attribute("SelectedSystem").Value));
     TechnologyManager.Load(empireToLoad, gameMain.MasterTechnologyManager);
     FleetManager.Load(empireToLoad, this, gameMain);
 }
Пример #8
0
        public Planet(string name, Random r, StarSystem system)
        {
            _populationMax = r.Next(0, 150) - 25;

            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.AVERAGE;
            EnvironmentBonus = PLANET_ENVIRONMENT_BONUS.AVERAGE;
            ResearchBonus = PLANET_RESEARCH_BONUS.AVERAGE;

            int randomNum = r.Next(100);
            var color = system.Color;

            string type = string.Empty;
            if (color == Color.Red)
            {
                //TODO: Handle nebula generation
                if (randomNum < 5)
                {
                    type = NONE;
                }
                else if (randomNum < 10)
                {
                    type = RADIATED;
                }
                else if (randomNum < 15)
                {
                    type = TOXIC;
                }
                else if (randomNum < 20)
                {
                    type = VOLCANIC;
                }
                else if (randomNum < 25)
                {
                    type = DEAD;
                }
                else if (randomNum < 30)
                {
                    type = TUNDRA;
                }
                else if (randomNum < 35)
                {
                    type = BARREN;
                }
                else if (randomNum < 40)
                {
                    type = ARCTIC;
                }
                else if (randomNum < 50)
                {
                    type = DESERT;
                }
                else if (randomNum < 60)
                {
                    type = STEPPE;
                }
                else if (randomNum < 75)
                {
                    type = BADLANDS;
                }
                else if (randomNum < 85)
                {
                    type = OCEANIC;
                }
                else if (randomNum < 95)
                {
                    type = JUNGLE;
                }
                else
                {
                    type = TERRAN;
                }
            }
            else if (color == Color.Green)
            {
                //TODO: Handle nebula generation
                if (randomNum < 5)
                {
                    type = NONE;
                }
                else if (randomNum < 10)
                {
                    type = RADIATED;
                }
                else if (randomNum < 15)
                {
                    type = TOXIC;
                }
                else if (randomNum < 20)
                {
                    type = VOLCANIC;
                }
                else if (randomNum < 25)
                {
                    type = DEAD;
                }
                else if (randomNum < 30)
                {
                    type = TUNDRA;
                }
                else if (randomNum < 35)
                {
                    type = BARREN;
                }
                else if (randomNum < 40)
                {
                    type = ARCTIC;
                }
                else if (randomNum < 45)
                {
                    type = DESERT;
                }
                else if (randomNum < 55)
                {
                    type = STEPPE;
                }
                else if (randomNum < 65)
                {
                    type = BADLANDS;
                }
                else if (randomNum < 75)
                {
                    type = OCEANIC;
                }
                else if (randomNum < 85)
                {
                    type = JUNGLE;
                }
                else
                {
                    type = TERRAN;
                }
            }
            else if (color == Color.Yellow)
            {
                //TODO: Handle nebula generation
                if (randomNum < 5)
                {
                    type = VOLCANIC;
                }
                else if (randomNum < 10)
                {
                    type = TUNDRA;
                }
                else if (randomNum < 15)
                {
                    type = BARREN;
                }
                else if (randomNum < 20)
                {
                    type = ARCTIC;
                }
                else if (randomNum < 25)
                {
                    type = DESERT;
                }
                else if (randomNum < 30)
                {
                    type = STEPPE;
                }
                else if (randomNum < 40)
                {
                    type = BADLANDS;
                }
                else if (randomNum < 50)
                {
                    type = OCEANIC;
                }
                else if (randomNum < 60)
                {
                    type = JUNGLE;
                }
                else
                {
                    type = TERRAN;
                }
            }
            else if (color == Color.Blue)
            {
                //TODO: Handle nebula generation
                if (randomNum < 15)
                {
                    type = NONE;
                }
                else if (randomNum < 25)
                {
                    type = RADIATED;
                }
                else if (randomNum < 35)
                {
                    type = TOXIC;
                }
                else if (randomNum < 45)
                {
                    type = VOLCANIC;
                }
                else if (randomNum < 55)
                {
                    type = DEAD;
                }
                else if (randomNum < 65)
                {
                    type = TUNDRA;
                }
                else if (randomNum < 75)
                {
                    type = BARREN;
                }
                else if (randomNum < 85)
                {
                    type = ARCTIC;
                }
                else if (randomNum < 90)
                {
                    type = DESERT;
                }
                else if (randomNum < 95)
                {
                    type = STEPPE;
                }
                else
                {
                    type = BADLANDS;
                }
            }
            else if (color == Color.White)
            {
                //TODO: Handle nebula generation
                if (randomNum < 10)
                {
                    type = NONE;
                }
                else if (randomNum < 20)
                {
                    type = RADIATED;
                }
                else if (randomNum < 30)
                {
                    type = TOXIC;
                }
                else if (randomNum < 40)
                {
                    type = VOLCANIC;
                }
                else if (randomNum < 50)
                {
                    type = DEAD;
                }
                else if (randomNum < 60)
                {
                    type = TUNDRA;
                }
                else if (randomNum < 70)
                {
                    type = BARREN;
                }
                else if (randomNum < 80)
                {
                    type = ARCTIC;
                }
                else if (randomNum < 85)
                {
                    type = DESERT;
                }
                else if (randomNum < 90)
                {
                    type = STEPPE;
                }
                else if (randomNum < 95)
                {
                    type = BADLANDS;
                }
                else
                {
                    type = OCEANIC;
                }
            }
            else
            {
                //TODO: Handle nebula generation
                if (randomNum < 20)
                {
                    type = NONE;
                }
                else if (randomNum < 45)
                {
                    type = RADIATED;
                }
                else if (randomNum < 60)
                {
                    type = TOXIC;
                }
                else if (randomNum < 75)
                {
                    type = VOLCANIC;
                }
                else if (randomNum < 85)
                {
                    type = DEAD;
                }
                else if (randomNum < 90)
                {
                    type = TUNDRA;
                }
                else if (randomNum < 95)
                {
                    type = BARREN;
                }
                else
                {
                    type = ARCTIC;
                }
            }

            switch (type)
            {
                case NONE:
                    _populationMax = 0;
                    break;
                case RADIATED:
                case TOXIC:
                case VOLCANIC:
                    _populationMax = r.Next(2, 9) * 5;
                    break;
                case DEAD:
                case TUNDRA:
                    _populationMax = r.Next(4, 11) * 5;
                    break;
                case BARREN:
                case ARCTIC:
                    _populationMax = r.Next(6, 11) * 5;
                    break;
                case DESERT:
                    _populationMax = r.Next(7, 11) * 5;
                    break;
                case STEPPE:
                    _populationMax = r.Next(9, 13) * 5;
                    break;
                case BADLANDS:
                    _populationMax = r.Next(11, 15) * 5;
                    break;
                case OCEANIC:
                    _populationMax = r.Next(13, 17) * 5;
                    break;
                case JUNGLE:
                    _populationMax = r.Next(15, 19) * 5;
                    break;
                case TERRAN:
                    _populationMax = r.Next(17, 21) * 5;
                    break;
            }

            //Add some variety to the population size
            while (r.Next(100) < 20)
            {
                if (r.Next(100) < 50)
                {
                    //decrease the population by 20
                    _populationMax -= 20;
                    if (_populationMax < 10)
                    {
                        _populationMax = 10;
                    }
                }
                else
                {
                    //increase the population by 20
                    _populationMax += 20;
                    if (_populationMax > 140)
                    {
                        _populationMax = 140;
                    }
                }
            }

            //Now roll for poor/ultra poor if the planet is steppe, badlands, oceanic, jungle, or terran
            if (type == STEPPE || type == BADLANDS || type == OCEANIC || type == JUNGLE || type == TERRAN)
            {
                randomNum = r.Next(1000);
                if (system.Color == Color.Blue || system.Color == Color.White || system.Color == Color.Yellow)
                {
                    if (randomNum < 25) //2.5% chance of ultrapoor
                    {
                        ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRAPOOR;
                    }
                    else if (randomNum < 100) //7.5% chance of poor
                    {
                        ConstructionBonus = PLANET_CONSTRUCTION_BONUS.POOR;
                    }
                }
                else if (system.Color == Color.Red)
                {
                    if (randomNum < 60) //6% chance of ultrapoor
                    {
                        ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRAPOOR;
                    }
                    else if (randomNum < 200) //14% chance of poor
                    {
                        ConstructionBonus = PLANET_CONSTRUCTION_BONUS.POOR;
                    }
                }
                else if (system.Color == Color.Green)
                {
                    if (randomNum < 135) //13.5% chance of ultrapoor
                    {
                        ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRAPOOR;
                    }
                    else if (randomNum < 300) //16.5% chance of poor
                    {
                        ConstructionBonus = PLANET_CONSTRUCTION_BONUS.POOR;
                    }
                }
            }

            //roll for rich/ultrarich only if the planet is not poor already
            if (ConstructionBonus == PLANET_CONSTRUCTION_BONUS.AVERAGE)
            {
                //todo: handle nebula generation
                randomNum = r.Next(10000);
                if (type == RADIATED)
                {
                    if (system.Color == Color.Red || system.Color == Color.Yellow || system.Color == Color.Green || system.Color == Color.White)
                    {
                        if (randomNum < 875)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
                        }
                        else if (randomNum < 3500)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
                        }
                    }
                    else if (system.Color == Color.Blue)
                    {
                        if (randomNum < 1575)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
                        }
                        else if (randomNum < 4500)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
                        }
                    }
                    else //neutron star
                    {
                        if (randomNum < 3000)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
                        }
                        else if (randomNum < 6000)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
                        }
                    }
                }
                else if (type == TOXIC)
                {
                    if (system.Color == Color.Red || system.Color == Color.Yellow || system.Color == Color.Green || system.Color == Color.White)
                    {
                        if (randomNum < 750)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
                        }
                        else if (randomNum < 3000)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
                        }
                    }
                    else if (system.Color == Color.Blue)
                    {
                        if (randomNum < 1400)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
                        }
                        else if (randomNum < 4000)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
                        }
                    }
                    else //neutron star
                    {
                        if (randomNum < 2750)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
                        }
                        else if (randomNum < 5500)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
                        }
                    }
                }
                else if (type == VOLCANIC)
                {
                    if (system.Color == Color.Red || system.Color == Color.Yellow || system.Color == Color.Green || system.Color == Color.White)
                    {
                        if (randomNum < 625)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
                        }
                        else if (randomNum < 2500)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
                        }
                    }
                    else if (system.Color == Color.Blue)
                    {
                        if (randomNum < 1225)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
                        }
                        else if (randomNum < 3500)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
                        }
                    }
                    else //neutron star
                    {
                        if (randomNum < 2500)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
                        }
                        else if (randomNum < 5000)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
                        }
                    }
                }
                else if (type == DEAD)
                {
                    if (system.Color == Color.Red || system.Color == Color.Yellow || system.Color == Color.Green || system.Color == Color.White)
                    {
                        if (randomNum < 500)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
                        }
                        else if (randomNum < 2000)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
                        }
                    }
                    else if (system.Color == Color.Blue)
                    {
                        if (randomNum < 1050)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
                        }
                        else if (randomNum < 3000)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
                        }
                    }
                    else //neutron star
                    {
                        if (randomNum < 2250)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
                        }
                        else if (randomNum < 4500)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
                        }
                    }
                }
                else if (type == TUNDRA)
                {
                    if (system.Color == Color.Red || system.Color == Color.Yellow || system.Color == Color.Green || system.Color == Color.White)
                    {
                        if (randomNum < 375)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
                        }
                        else if (randomNum < 1500)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
                        }
                    }
                    else if (system.Color == Color.Blue)
                    {
                        if (randomNum < 875)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
                        }
                        else if (randomNum < 2500)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
                        }
                    }
                    else //neutron star
                    {
                        if (randomNum < 2000)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
                        }
                        else if (randomNum < 4000)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
                        }
                    }
                }
                else if (type == BARREN)
                {
                    if (system.Color == Color.Red || system.Color == Color.Yellow || system.Color == Color.Green || system.Color == Color.White)
                    {
                        if (randomNum < 250)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
                        }
                        else if (randomNum < 1000)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
                        }
                    }
                    else if (system.Color == Color.Blue)
                    {
                        if (randomNum < 700)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
                        }
                        else if (randomNum < 2000)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
                        }
                    }
                    else //neutron star
                    {
                        if (randomNum < 1750)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
                        }
                        else if (randomNum < 3500)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
                        }
                    }
                }
                else if (type == ARCTIC)
                {
                    if (system.Color == Color.Red || system.Color == Color.Yellow || system.Color == Color.Green || system.Color == Color.White)
                    {
                        if (randomNum < 125)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
                        }
                        else if (randomNum < 500)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
                        }
                    }
                    else if (system.Color == Color.Blue)
                    {
                        if (randomNum < 525)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
                        }
                        else if (randomNum < 1500)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
                        }
                    }
                    else //neutron star
                    {
                        if (randomNum < 1500)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
                        }
                        else if (randomNum < 3000)
                        {
                            ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
                        }
                    }
                }
                else if (type == DESERT && system.Color == Color.Blue)
                {
                    if (randomNum < 350)
                    {
                        ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
                    }
                    else if (randomNum < 1000)
                    {
                        ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
                    }
                }
                else if (type == STEPPE && system.Color == Color.Blue)
                {
                    if (randomNum < 175)
                    {
                        ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
                    }
                    else if (randomNum < 500)
                    {
                        ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
                    }
                }
            }

            //Now determine asteroid density
            randomNum = r.Next(100);
            if (randomNum < 25) //Always 25% chance of low density, no matter what type/bonus the planet has
            {
                AsteroidDensity = PLANET_ASTEROID_DENSITY.LOW;
            }
            else
            {
                int extraValue = 0;
                switch (type)
                {
                    case RADIATED:
                        extraValue = 12;
                        break;
                    case TOXIC:
                        extraValue = 11;
                        break;
                    case VOLCANIC:
                        extraValue = 10;
                        break;
                    case DEAD:
                        extraValue = 9;
                        break;
                    case TUNDRA:
                        extraValue = 8;
                        break;
                    case BARREN:
                        extraValue = 7;
                        break;
                    case ARCTIC:
                        extraValue = 6;
                        break;
                    case DESERT:
                        extraValue = 5;
                        break;
                    case STEPPE:
                        extraValue = 4;
                        break;
                    case BADLANDS:
                        extraValue = 3;
                        break;
                    case OCEANIC:
                        extraValue = 2;
                        break;
                    case JUNGLE:
                        extraValue = 1;
                        break;
                }
                if (ConstructionBonus == PLANET_CONSTRUCTION_BONUS.ULTRARICH)
                {
                    if (randomNum < 62 + extraValue)
                    {
                        AsteroidDensity = PLANET_ASTEROID_DENSITY.HIGH;
                    }
                    else
                    {
                        AsteroidDensity = PLANET_ASTEROID_DENSITY.NONE;
                    }
                }
                else if (ConstructionBonus == PLANET_CONSTRUCTION_BONUS.RICH)
                {
                    if (randomNum < 52 + extraValue)
                    {
                        AsteroidDensity = PLANET_ASTEROID_DENSITY.HIGH;
                    }
                    else
                    {
                        AsteroidDensity = PLANET_ASTEROID_DENSITY.NONE;
                    }
                }
                else
                {
                    if (randomNum < 42 + extraValue)
                    {
                        AsteroidDensity = PLANET_ASTEROID_DENSITY.HIGH;
                    }
                    else
                    {
                        AsteroidDensity = PLANET_ASTEROID_DENSITY.NONE;
                    }
                }
            }

            //Now roll for fertility
            if (type == DESERT || type == STEPPE || type == BADLANDS || type == OCEANIC || type == JUNGLE || type == TERRAN)
            {
                randomNum = r.Next(100);
                if (randomNum < 9) //original is 1 / 12th, so this is close enough
                {
                    EnvironmentBonus = PLANET_ENVIRONMENT_BONUS.FERTILE;
                    float value = _populationMax / 5;
                    value *= 1.25f;
                    _populationMax = ((int) value) * 5;
                    if (_populationMax > 140)
                    {
                        _populationMax = 140;
                    }
                }
            }
            else if (type == RADIATED || type == TOXIC || type == VOLCANIC || type == DEAD || type == TUNDRA || type == BARREN)
            {
                EnvironmentBonus = PLANET_ENVIRONMENT_BONUS.HOSTILE;
            }

            //Finally, roll for artifacts
            if (ConstructionBonus == PLANET_CONSTRUCTION_BONUS.AVERAGE)
            {
                randomNum = r.Next(100);
                if (randomNum < 10) //10% chance of having artifacts
                {
                    ResearchBonus = PLANET_RESEARCH_BONUS.ARTIFACTS;
                }
            }

            SetValues(name, type, _populationMax, system, null, r);
        }
Пример #9
0
        public void SetupStarterFleet(StarSystem homeSystem)
        {
            Technology retroEngine = null;
            Technology titaniumArmor = null;
            Technology laser = null;
            Technology nuclearMissile = null;
            Technology nuclearBomb = null;

            foreach (var tech in _empire.TechnologyManager.ResearchedPropulsionTechs)
            {
                if (tech.Speed == 1)
                {
                    retroEngine = tech;
                    break;
                }
            }
            foreach (var tech in _empire.TechnologyManager.ResearchedConstructionTechs)
            {
                if (tech.Armor == Technology.TITANIUM_ARMOR)
                {
                    titaniumArmor = tech;
                    break;
                }
            }
            foreach (var tech in _empire.TechnologyManager.ResearchedWeaponTechs)
            {
                if (tech.TechName == "Laser")
                {
                    laser = tech;
                }
                else if (tech.TechName == "Nuclear Missile")
                {
                    nuclearMissile = tech;
                }
                else if (tech.TechName == "Nuclear Bomb")
                {
                    nuclearBomb = tech;
                }
            }
            Ship scout = new Ship();
            scout.Name = "Scout";
            scout.Owner = _empire;
            scout.Size = Ship.SMALL;
            scout.WhichStyle = 0;
            scout.Armor = new Equipment(titaniumArmor, false);
            foreach (var tech in _empire.TechnologyManager.ResearchedConstructionTechs)
            {
                if (tech.ReserveFuelTanks)
                {
                    scout.Specials[0] = new Equipment(tech, false);
                    break;
                }
            }
            scout.Engine = new KeyValuePair<Equipment, float>(new Equipment(retroEngine, false), scout.PowerUsed / (retroEngine.Speed * 10));
            scout.DesignID = _currentShipDesignID;
            CurrentDesigns.Add(scout);
            _currentShipDesignID++;

            Ship fighter = new Ship();
            fighter.Name = "Fighter";
            fighter.Owner = _empire;
            fighter.Size = Ship.SMALL;
            fighter.WhichStyle = 1;
            fighter.Weapons[0] = new KeyValuePair<Equipment, int>(new Equipment(laser, false), 1);
            fighter.Armor = new Equipment(titaniumArmor, false);
            fighter.Engine = new KeyValuePair<Equipment, float>(new Equipment(retroEngine, false), fighter.PowerUsed / (retroEngine.Speed * 10));
            CurrentDesigns.Add(fighter);
            _currentShipDesignID++;

            Ship destroyer = new Ship();
            destroyer.Name = "Destroyer";
            destroyer.Owner = _empire;
            destroyer.Size = Ship.MEDIUM;
            destroyer.WhichStyle = 0;
            destroyer.Weapons[0] = new KeyValuePair<Equipment, int>(new Equipment(nuclearMissile, false), 1);
            destroyer.Weapons[1] = new KeyValuePair<Equipment, int>(new Equipment(laser, false), 3);
            destroyer.Armor = new Equipment(titaniumArmor, false);
            destroyer.Engine = new KeyValuePair<Equipment, float>(new Equipment(retroEngine, false), destroyer.PowerUsed / (retroEngine.Speed * 10));
            CurrentDesigns.Add(destroyer);
            _currentShipDesignID++;

            Ship bomber = new Ship();
            bomber.Name = "Bomber";
            bomber.Owner = _empire;
            bomber.Size = Ship.MEDIUM;
            bomber.WhichStyle = 1;
            bomber.Weapons[0] = new KeyValuePair<Equipment, int>(new Equipment(nuclearBomb, false), 2);
            bomber.Weapons[1] = new KeyValuePair<Equipment, int>(new Equipment(laser, false), 2);
            bomber.Armor = new Equipment(titaniumArmor, false);
            bomber.Engine = new KeyValuePair<Equipment, float>(new Equipment(retroEngine, false), bomber.PowerUsed / (retroEngine.Speed * 10));
            CurrentDesigns.Add(bomber);
            _currentShipDesignID++;

            Ship colonyShip = new Ship();
            colonyShip.Name = "Colony Ship";
            colonyShip.Owner = _empire;
            colonyShip.Size = Ship.LARGE;
            colonyShip.WhichStyle = 0;
            colonyShip.Armor = new Equipment(titaniumArmor, false);
            foreach (var tech in _empire.TechnologyManager.ResearchedPlanetologyTechs)
            {
                if (tech.Colony == Technology.STANDARD_COLONY)
                {
                    colonyShip.Specials[0] = new Equipment(tech, false);
                    break;
                }
            }
            colonyShip.Engine = new KeyValuePair<Equipment, float>(new Equipment(retroEngine, false), colonyShip.PowerUsed / (retroEngine.Speed * 10));
            colonyShip.DesignID = _currentShipDesignID;
            CurrentDesigns.Add(colonyShip);
            _currentShipDesignID++;

            LastShipDesign = new Ship(scout); //Make a copy so we don't accidentally modify the original ship

            Fleet starterFleet = new Fleet();
            starterFleet.GalaxyX = homeSystem.X;
            starterFleet.GalaxyY = homeSystem.Y;
            starterFleet.AdjacentSystem = homeSystem;
            starterFleet.Empire = _empire;
            starterFleet.AddShips(CurrentDesigns[0], 2);
            starterFleet.AddShips(CurrentDesigns[4], 1);
            _fleets.Add(starterFleet);
        }
Пример #10
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);
        }
Пример #11
0
 public Planet(string name, string type, int maxPop, Empire owner, StarSystem system, Random r)
 {
     SetValues(name, type, maxPop, system, owner, r);
 }
Пример #12
0
        public void SetTentativePath(StarSystem destination, bool hasExtendedFuelTanks, Galaxy galaxy)
        {
            if (destination == null || destination == _adjacentSystem)
            {
                //if destination is same as origin, or nowhere, clear the tentative path
                TentativeNodes = null;
                return;
            }
            if (_travelNodes != null && _travelNodes[_travelNodes.Count - 1].StarSystem == destination)
            {
                //Same path as current path
                TentativeNodes = null;
                return;
            }
            if (TentativeNodes != null && TentativeNodes[_tentativeNodes.Count - 1].StarSystem == destination)
            {
                // Existing tentative path
                return;
            }

            StarSystem currentDestination = null;
            if (_adjacentSystem == null) //Has left a system
            {
                currentDestination = _travelNodes[0].StarSystem;
            }
            List<TravelNode> path = galaxy.GetPath(_galaxyX, _galaxyY, currentDestination, destination, hasExtendedFuelTanks, _empire);
            if (path == null)
            {
                TentativeNodes = null;
                return;
            }

            TentativeNodes = path;
            if (TentativeNodes.Count == 0)
            {
                TentativeNodes = null;
            }
        }
Пример #13
0
        public bool Move(float frameDeltaTime)
        {
            if (_travelNodes == null)
            {
                return false;
            }
            if (_remainingMoves > 0)
            {
                _adjacentSystem = null; //Left the system
                float amountToMove = frameDeltaTime * _maxSpeed * Galaxy.PARSEC_SIZE_IN_PIXELS;
                if (amountToMove > _remainingMoves)
                {
                    amountToMove = _remainingMoves;
                }
                _remainingMoves -= amountToMove;

                float xMov = (float)(Math.Cos(_travelNodes[0].Angle * (Math.PI / 180)) * amountToMove);
                float yMov = (float)(Math.Sin(_travelNodes[0].Angle * (Math.PI / 180)) * amountToMove);

                bool isLeftOfNode = _galaxyX <= _travelNodes[0].StarSystem.X;
                bool isTopOfNode = _galaxyY <= _travelNodes[0].StarSystem.Y;

                _galaxyX += xMov;
                _galaxyY += yMov;

                if ((_galaxyX > _travelNodes[0].StarSystem.X && isLeftOfNode) ||
                    (_galaxyX <= _travelNodes[0].StarSystem.X && !isLeftOfNode) ||
                    (_galaxyY > _travelNodes[0].StarSystem.Y && isTopOfNode) ||
                    (_galaxyY <= _travelNodes[0].StarSystem.Y && !isTopOfNode))
                {
                    //TODO: Carry over excess movement to next node

                    //It has arrived at destination
                    _galaxyX = _travelNodes[0].StarSystem.X;
                    _galaxyY = _travelNodes[0].StarSystem.Y;
                    _adjacentSystem = _travelNodes[0].StarSystem;
                    _travelNodes.RemoveAt(0);
                    if (_travelNodes.Count == 0)
                    {
                        _travelNodes = null;
                        _remainingMoves = 0;
                    }
                }
                else
                {
                    float x = _travelNodes[0].StarSystem.X - _galaxyX;
                    float y = _travelNodes[0].StarSystem.Y - _galaxyY;
                    _travelNodes[0].Length = (float)Math.Sqrt((x * x) + (y * y));
                    _travelNodes[0].Angle = (float)(Math.Atan2(y, x) * (180 / Math.PI));
                }
            }
            return _remainingMoves > 0;
        }
Пример #14
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));
     }
 }
Пример #15
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;
 }
Пример #16
0
        /*
         * private bool[][] GenerateCluster(int size)
         * {
         *      //Size is actually a diameter, change to radius
         *      return Utility.CalculateDisc(size / 2, 1);
         * }
         *
         * private bool[][] GenerateRing(int size)
         * {
         *      //Size is actually a diameter, change to radius
         *      bool[][] grid = Utility.CalculateDisc(size / 2, 1);
         *
         *      int quarterSize = size / 4;
         *
         *      bool[][] discToSubtract = Utility.CalculateDisc(quarterSize, 1);
         *
         *      for (int i = 0; i < discToSubtract.Length; i++)
         *      {
         *              for (int j = 0; j < discToSubtract[i].Length; j++)
         *              {
         *                      if (discToSubtract[i][j])
         *                      {
         *                              grid[quarterSize + i][quarterSize + j] = false;
         *                      }
         *              }
         *      }
         *
         *      return grid;
         * }
         *
         * private bool[][] GenerateRandom(int size)
         * {
         *      bool[][] grid = new bool[size][];
         *      for (int i = 0; i < grid.Length; i++)
         *      {
         *              grid[i] = new bool[size];
         *      }
         *
         *      for (int i = 0; i < size; i++)
         *      {
         *              for (int j = 0; j < size; j++)
         *              {
         *                      grid[i][j] = true;
         *              }
         *      }
         *
         *      return grid;
         * }
         *
         * private bool[][] GenerateStar(int size)
         * {
         *      bool[][] grid = new bool[size][];
         *      for (int i = 0; i < grid.Length; i++)
         *      {
         *              grid[i] = new bool[size];
         *      }
         *      int halfSize = size / 2;
         *
         *      for (int i = 0; i < size; i++)
         *      {
         *              for (int j = 0; j < size; j++)
         *              {
         *                      int x = i - halfSize;
         *                      int y = halfSize - j;
         *                      if (x < 0)
         *                      {
         *                              x *= -1;
         *                      }
         *                      if (y < 0)
         *                      {
         *                              y *= -1;
         *                      }
         *                      if ((x * x) * (y * y) <= (size * size * (halfSize / 6)))
         *                      {
         *                              grid[i][j] = true;
         *                      }
         *              }
         *      }
         *
         *      return grid;
         * }
         *
         * private bool[][] GenerateDiamond(int size)
         * {
         *      bool[][] grid = new bool[size][];
         *      for (int i = 0; i < grid.Length; i++)
         *      {
         *              grid[i] = new bool[size];
         *      }
         *      int halfSize = size / 2;
         *
         *      for (int i = 0; i < size; i++)
         *      {
         *              for (int j = 0; j < size; j++)
         *              {
         *                      int x = i - halfSize;
         *                      int y = halfSize - j;
         *                      if (x < 0)
         *                      {
         *                              x *= -1;
         *                      }
         *                      if (y < 0)
         *                      {
         *                              y *= -1;
         *                      }
         *                      if (x + y <= halfSize)
         *                      {
         *                              grid[i][j] = true;
         *                      }
         *              }
         *      }
         *
         *      return grid;
         * }*/
        #endregion

        #region Galaxy Filling Functions
        private void FillGalaxyWithStars(int numberOfStars, int minPlanets, int maxPlanets, bool[][] grid, Random r)
        {
            starSystems        = new List <StarSystem>();
            _quickLookupSystem = new Dictionary <int, StarSystem>();

            StarNode starTree = new StarNode(0, 0, grid.Length - 1, grid.Length - 1);

            //Set area where stars can be placed (circle, random, star, etc shaped galaxy)
            for (int i = 0; i < grid.Length; i++)
            {
                for (int j = 0; j < grid[i].Length; j++)
                {
                    if (!grid[i][j])
                    {
                        starTree.RemoveNodeAtPosition(i, j);
                    }
                }
            }

            int starId = 0;

            while (starTree.nodes.Count > 0 && numberOfStars > 0)
            {
                int x;
                int y;

                starTree.GetRandomStarPosition(r, out x, out y);

                //int newSize = r.Next(3) + 2;

                Color  starColor   = Color.White;
                string description = string.Empty;

                int randNum = r.Next(100);


                if (randNum < 30)
                {
                    starColor = Color.Red;
                }
                else if (randNum < 55)
                {
                    starColor = Color.Green;
                }
                else if (randNum < 70)
                {
                    starColor = Color.Yellow;
                }
                else if (randNum < 85)
                {
                    starColor = Color.Blue;
                }
                else if (randNum < 95)
                {
                    starColor = Color.White;
                }
                else
                {
                    starColor = Color.Purple;
                }

                var newStarsystem = new StarSystem(NameGenerator.GetStarName(r), starId, x * PARSEC_SIZE_IN_PIXELS + (r.Next(PARSEC_SIZE_IN_PIXELS)), y * PARSEC_SIZE_IN_PIXELS + (r.Next(PARSEC_SIZE_IN_PIXELS)), starColor, description, minPlanets, maxPlanets, r);
                starSystems.Add(newStarsystem);
                _quickLookupSystem.Add(newStarsystem.ID, newStarsystem);

                bool[][] invalidatedArea = Utility.CalculateDisc(2, 1);

                for (int i = 0; i < invalidatedArea.Length; i++)
                {
                    for (int j = 0; j < invalidatedArea.Length; j++)
                    {
                        int xToInvalidate = (x - 2) + i;
                        int yToInvalidate = (y - 2) + j;

                        starTree.RemoveNodeAtPosition(xToInvalidate, yToInvalidate);
                    }
                }

                numberOfStars--;
                starId++;
            }
        }
Пример #17
0
 public TravelNode GenerateTravelNode(StarSystem origin, StarSystem destination)
 {
     return GenerateTravelNode(origin.X, origin.Y, destination);
 }
Пример #18
0
 public TravelNode GenerateTravelNode(StarSystem origin, StarSystem destination)
 {
     return(GenerateTravelNode(origin.X, origin.Y, destination));
 }
Пример #19
0
 public void ClearTurnData()
 {
     //Clears all current turn's temporary data to avoid issues
     selectedFleetGroup = null;
     selectedSystem = lastSelectedSystem;
 }
Пример #20
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);
        }
Пример #21
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();
 }
Пример #22
0
 public void ClearTurnData()
 {
     //Clears all current turn's temporary data to avoid issues
     selectedFleetGroup = null;
     selectedSystem     = lastSelectedSystem;
 }