Esempio n. 1
0
        internal override void Plus(XDocument xdoc)
        {
            foreach (var element in xdoc.Root.Elements())
            {
                var val = element.Value;
                int valI;
                int.TryParse(val, out valI);

                switch (element.Name.LocalName)
                {
                case "id":
                case "type":
                    break;

                case "coords":
                    if (Coords == null)
                    {
                        Coords = new List <Point>();
                    }
                    foreach (var coordSplit in val.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Select(coord => coord.Split(',')).Where(coordSplit => coordSplit.Length == 2))
                    {
                        Coords.Add(new Point(Convert.ToInt32(coordSplit[0]), Convert.ToInt32(coordSplit[1])));
                    }
                    break;

                case "population":
                    if (Populations == null)
                    {
                        Populations = new Dictionary <Race, int>();
                    }
                    foreach (var popSplit in val.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Select(pop => pop.Split(',')).Where(popSplit => popSplit.Length == 3))
                    {
                        if (Populations.ContainsKey(World.Races[Convert.ToInt32(popSplit[0])]))
                        {
                            Populations[World.Races[Convert.ToInt32(popSplit[0])]] += Convert.ToInt32(popSplit[1]);
                        }
                        else
                        {
                            Populations.Add(World.Races[Convert.ToInt32(popSplit[0])], Convert.ToInt32(popSplit[1]));
                        }
                    }
                    break;

                default:
                    DFXMLParser.UnexpectedXmlElement(xdoc.Root.Name.LocalName + "\t" + "Region", element, xdoc.Root.ToString());
                    break;
                }
            }
        }
Esempio n. 2
0
 public Builder setPopulation(PopulationType populationType, int count)
 {
     if (count == 0)
     {
         Populations.Remove(populationType);
         return(this);
     }
     if (Populations.ContainsKey(populationType))
     {
         Populations[populationType] = count;
     }
     else
     {
         Populations.Add(populationType, count);
     }
     return(this);
 }