예제 #1
0
        /// <summary>
        /// Must be called after changing one cell geometry.
        /// </summary>
        void UpdateProvinceGeometry(MapProvince prov, WorldMapStrategyKit.MapGenerator.Geom.Polygon poly)
        {
            // Copy new polygon definition
            prov.region.polygon = poly;
            // Update segments list
            prov.region.segments.Clear();
            List <Segment> segmentCache = new List <Segment>(cellNeighbourHit.Keys);

            WorldMapStrategyKit.MapGenerator.Geom.Contour contour0 = poly.contours[0];
            int pointCount        = contour0.points.Count;
            int segmentCacheCount = segmentCache.Count;

            for (int k = 0; k < pointCount; k++)
            {
                Segment s     = contour0.GetSegment(k);
                bool    found = false;
                // Search this segment in the segment cache
                for (int j = 0; j < segmentCacheCount; j++)
                {
                    Segment o = segmentCache[j];
                    if ((Point.EqualsBoth(o.start, s.start) && Point.EqualsBoth(o.end, s.end)) || (Point.EqualsBoth(o.end, s.start) && Point.EqualsBoth(o.start, s.end)))
                    {
                        prov.region.segments.Add(o);
                        o.territoryIndex = prov.countryIndex;
                        found            = true;
                        break;
                    }
                }
                if (!found)
                {
                    prov.region.segments.Add(s);
                }
            }
            // Refresh neighbours
            ProvincesUpdateNeighbours();
            // Refresh rect2D
            ProvincesUpdateBounds(prov);

            // Refresh territories
            FindCountryFrontiers();
            UpdateCountryBoundaries();
        }