Beyond_Beyaan.Planet.AddRacePopulation C# (CSharp) Метод

AddRacePopulation() публичный Метод

public AddRacePopulation ( Race whichRace, float amount ) : void
whichRace Beyond_Beyaan.Data_Modules.Race
amount float
Результат void
        public void AddRacePopulation(Race whichRace, float amount)
        {
            if (_racePopulations.ContainsKey(whichRace))
            {
                _racePopulations[whichRace] += amount;
            }
            else
            {
                //Add it
                if (!_races.Contains(whichRace))
                {
                    _races.Add(whichRace);
                }
                _racePopulations[whichRace] = amount;
            }
        }

Usage Example

Пример #1
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;
 }