private void CreateNewRegion(HexPos hexe)
        {
            Tile tile = base.Context.Settings.TmxMap.GetTile(this.tmxRegionLayer.Data[hexe.Row, hexe.Column]);

            if (tile == null)
            {
                base.ReportTmx(string.Concat(new object[]
                {
                    "?MissingTile&$Coordinate=",
                    hexe.Column,
                    ",",
                    hexe.Row - base.Context.Grid.Rows + 1,
                    "&$LayerName=Regions"
                }));
                this.anyErrorCatched = true;
                return;
            }
            short  regionTileValue = (short)tile.Id;
            Region region          = new Region(base.Context.Grid);

            region.Id = ImportTmxRegionLayer.id;
            ImportTmxRegionLayer.id += 1;
            string tileProperty = base.Context.Settings.TmxMap.GetTileProperty(this.tmxRegionLayer.Data[hexe.Row, hexe.Column], ImportTmxRegionLayer.regionNameProperty);

            if (!string.IsNullOrEmpty(tileProperty))
            {
                region.Name = tileProperty;
                if (this.regionsGivenNames.Contains(tileProperty))
                {
                    base.ReportTmx("?RegionNameDuplication&$RegionName=" + tileProperty);
                }
                else
                {
                    this.regionsGivenNames.Add(tileProperty);
                }
            }
            District district = new District();

            district.MotherRegion = region;
            district.Id           = (int)region.Id;
            district.Add(hexe);
            region.Districts.Add(district);
            this.treatedHexes[hexe.Row, hexe.Column]         = true;
            base.Context.RegionData[hexe.Row, hexe.Column]   = region.Id;
            base.Context.DistrictData[hexe.Row, hexe.Column] = district.Id;
            this.ExpandRegion(ref region, (int)regionTileValue);
            Diagnostics.Log(string.Format("[WorldGenerator] [ImportTmxRegionLayer] Region id is {0} it is composed of {1} hexe.", region.Id, district.Count));
            base.Context.Regions.Add(region.Id, region);
            base.Context.Districts.Add(district.Id, district);
        }
Esempio n. 2
0
        protected void CutCoastline()
        {
            List <District> list = new List <District>(from d in base.Context.Districts.Values
                                                       where d.CoastalSkeletonValue == 0
                                                       select d);
            List <District> list2 = new List <District>(from d in base.Context.Districts.Values
                                                        where d.CoastalSkeletonValue != 0
                                                        select d);
            List <District> list3 = new List <District>();

            foreach (District district in list)
            {
                foreach (HexPos hexPos in district)
                {
                    District district2 = new District();
                    district2.Add(hexPos);
                    if (base.Context.Grid.Adjacents(hexPos).Any((HexPos h) => base.Context.Districts[base.Context.DistrictData[h.Row, h.Column]].Content == District.Contents.Land))
                    {
                        district2.Content = District.Contents.Coastal;
                    }
                    else
                    {
                        district2.Content = District.Contents.Ocean;
                    }
                    list3.Add(district2);
                }
            }
            base.Context.Districts.Clear();
            int num = 0;

            foreach (District district3 in list2)
            {
                district3.Id = num++;
                base.Context.Districts.Add(district3.Id, district3);
            }
            foreach (District district4 in list3)
            {
                district4.Id = num++;
                base.Context.Districts.Add(district4.Id, district4);
            }
            base.ExecuteSubTask(new ComputeDistrictNeighbourhood());
        }
Esempio n. 3
0
        public District Create(string districtPath, string filePattern)
        {
            List <string> pathes     = new FileList(districtPath, filePattern).GetList();
            var           tikCreator = new TikCreator();

            if (pathes.Count == 0)
            {
                return(null);
            }

            var district = new District {
                Tiks = new List <Tik>(), Name = StringUtils.GetDistrictName(pathes[0])
            };

            foreach (var tikPath in pathes)
            {
                district.Add(tikCreator.Create(tikPath));
            }

            return(district);
        }