Example #1
0
        public Color GetPolygonColor(Polygon polygon)
        {
            Color result;
            switch (polygon.Type)
            {
                case TerrainType.Grassland:
                    result = Color.FromArgb(196, 212, 170);
                    break;
                case TerrainType.Bare:
                    result = Color.FromArgb(187, 187, 187);
                    break;
                case TerrainType.Lake:
                    result = Color.CornflowerBlue;
                    break;
                case TerrainType.ShallowOcean:
                    result = Color.RoyalBlue; //Color.CornflowerBlue;
                    break;
                case TerrainType.DeepOcean:
                    result = Color.RoyalBlue;
                    break;
                case TerrainType.Scorched:
                    result = Color.FromArgb(153, 153, 153);
                    break;
                case TerrainType.Shrubland:
                    result = Color.FromArgb(196,204,187);
                    break;
                case TerrainType.Snow:
                    result = Color.White;// Color.FromArgb(248, 248, 248);
                    break;
                case TerrainType.SubtropicalDesert:
                    result = Color.FromArgb(233, 221, 199);
                    break;
                case TerrainType.Tundra:
                    result = Color.FromArgb(221, 221, 187);
                    break;
                case TerrainType.Taiga:
                    result = Color.FromArgb(204, 212, 187);
                    break;
                case TerrainType.TemperatureDesert:
                    result = Color.FromArgb(228, 232, 202);
                    break;
                case TerrainType.TemperateRainForest:
                    result = Color.FromArgb(164, 196, 168);
                    break;
                case TerrainType.TemperatureDeciduousForest:
                    result = Color.FromArgb(180, 201, 169);
                    break;
                case TerrainType.TropicalRainForest:
                    result = Color.FromArgb(156, 187, 169);
                    break;
                case TerrainType.TropicalSeasonalForest:
                    result = Color.FromArgb(169, 204, 164);
                    break;
                default:
                    result = Color.Red;
                    break;
            }

            return result;
        }
Example #2
0
        public void Add(Polygon polygon)
        {
            m_Polygons.Add(polygon);

            foreach (var corner in polygon.Corners.Where(c => c.IsLake))
            {
                m_Corners.Add(corner);
                corner.Lake = this;
            }
        }
Example #3
0
 private void Init()
 {
     Polygons = new Polygon[2];
     Corners = new Corner[2];
 }
Example #4
0
        public void Build(IMap map, MapSettings settings)
        {
            var pointsDict = new Dictionary<StructurePoint, MapPoint>();
            var trianglesDict = new Dictionary<Triangle, MapTriangle>();

            var points = new List<MapPoint>();
            foreach (var point in m_Structure.Points)
            {
                var mapPoint = new MapPoint(point);
                points.Add(mapPoint);

                var polygon = new Polygon(mapPoint);
                map.Polygons.Add(polygon);

                mapPoint.Polygon = polygon;
                pointsDict[point] = mapPoint;
            }

            var triangles = new List<MapTriangle>();
            foreach (var triangle in m_Structure.Triangles)
            {
                var mapTriangle = new MapTriangle(triangle.Id);
                triangles.Add(mapTriangle);

                var corner = new Corner(triangle.Center);
                map.Corners.Add(corner);

                mapTriangle.Corner = corner;
                trianglesDict[triangle] = mapTriangle;
            }

            foreach (var triangle in m_Structure.Triangles)
            {
                var mapTriangle = trianglesDict[triangle];

                for (int i = 0; i < 3; i++)
                {
                    var point = triangle.Points[i];
                    if (point != null)
                    {
                        mapTriangle.Points[i] = pointsDict[point];
                    }

                    var neighborTriangle = triangle.Triangles[i];
                    if (neighborTriangle != null)
                    {
                        mapTriangle.Triangles[i] = trianglesDict[neighborTriangle];
                    }
                }
            }

            foreach (var triangle in triangles)
            {
                for (int i = 0; i < 3; i++)
                {
                    triangle.Corner.Polygons[i] = triangle.Points[i].Polygon;
                    triangle.Points[i].Polygon.Corners.Add(triangle.Corner);
                }

                for (int i = 0; i < 3; i++)
                {
                    var edge = triangle.Edge(i);
                    var current = triangle.Triangles[i];

                    if (current != null)
                    {
                        triangle.Corner.Corners[i] = current.Corner;

                        // TODO: Remove check
                        if (triangle.Id == current.Id)
                        {
                            throw new InvalidDataException("Ids are equal");
                        }

                        if (triangle.Id < current.Id)
                        {
                            var border = new Border();
                            border.Corners[0] = current.Corner;
                            border.Corners[1] = triangle.Corner;
                            border.Polygons[0] = edge.First.Polygon;
                            border.Polygons[1] = edge.Second.Polygon;

                            border.BasePolygon = edge.Second.Polygon;

                            map.Borders.Add(border);

                            triangle.Corner.Borders.Add(border);
                            current.Corner.Borders.Add(border);

                            edge.First.Polygon.Borders.Add(border);
                            edge.Second.Polygon.Borders.Add(border);

                            edge.First.Polygon.Polygons.Add(edge.Second.Polygon);
                            edge.Second.Polygon.Polygons.Add(edge.First.Polygon);
                        }
                    }
                    else
                    {
                        edge.First.Polygon.Polygons.Add(edge.Second.Polygon);
                        edge.Second.Polygon.Polygons.Add(edge.First.Polygon);
                    }
                }
            }

            foreach (Polygon polygon in map.Polygons)
            {
                Point2D center = polygon.Center;
                polygon.Corners.QuickSort((a, b) => Geometry.Vect(center, a, b).CompareTo(0));
                polygon.Borders.QuickSort((a, b) => Geometry.Vect(center, a.Center, b.Center).CompareTo(0));
                polygon.IsInside = polygon.Corners.All(map.ContainsPointInside);
            }

            foreach (var polygon in map.Polygons)
            {
                foreach (var border in polygon.Borders.Where(b => !b.BorderToDrawCreated))
                {
                    var borderPoints = m_NoiseLineGenerator.Generate(border.Corners[0], border.Polygons[0].BasePoint,
                                                             border.Corners[1], border.Polygons[1].BasePoint, 2, true);
                    /*var points = new List<Point2D> { border.Corners[0], border.Corners[1] };*/
                    /*border.Polygons[0].CornersToDraw.AddRange(points);
                    border.Polygons[1].CornersToDraw.AddRange(points);*/
                    border.BorderToDraw = borderPoints;
                    border.BorderToDrawCreated = true;
                }
            }

            foreach (var polygon in map.Polygons)
            {
                foreach (var border in polygon.Borders)
                {
                    if (border.BasePolygon == polygon)
                    {
                        polygon.CornersToDraw.AddRange(border.BorderToDraw);
                    }
                    else
                    {
                        var borderPoints = new List<Point2D>(border.BorderToDraw);
                        borderPoints.Reverse();
                        polygon.CornersToDraw.AddRange(borderPoints);
                    }
                }
            }

            /*foreach (var polygon in map.Polygons)
            {
                var center = polygon.BasePoint;
                polygon.CornersToDraw.Sort((a, b) => Geometry.Vect(center, a, b).CompareTo(0));
            }*/
        }
Example #5
0
 public bool Contains(Polygon polygon)
 {
     return m_Polygons.Contains(polygon);
 }
        private void CreateSkeleton(int width, Point2D direction, Polygon current, int totalLength, Queue<Polygon> queue,
                                    bool addAtMiddle)
        {
            current.InSkeleton = true;
            current.DistanceFromSkeleton = 0;
            current.IsLand = true;

            Polygon middlePolygon = null;
            Point2D newBaseDirection = null;

            for (int i = 0; i < totalLength - 1; i++)
            {
                Polygon nextPolygon = null;
                double cos = 0;
                foreach (var polygon in current.Polygons)
                {
                    if (polygon.IsInside && !polygon.InSkeleton && polygon.DistanceFromEdge > width)
                    {
                        var newCos = Geometry.Cos(direction, polygon.Center - current.Center);
                        if (nextPolygon == null || cos < newCos)
                        {
                            nextPolygon = polygon;
                            cos = newCos;
                        }
                    }
                }
                if (nextPolygon != null)
                {
                    nextPolygon.InSkeleton = true;
                    nextPolygon.DistanceFromSkeleton = 0;
                    nextPolygon.IsLand = true;
                    queue.Enqueue(nextPolygon);
                    direction = nextPolygon.Center - current.Center;
                    current = nextPolygon;
                    if (i == totalLength / 2)
                    {
                        middlePolygon = current;
                        newBaseDirection = new Point2D(direction.Y, -direction.X);
                        if (m_Random.Next(2) == 0)
                        {
                            newBaseDirection = -newBaseDirection;
                        }
                    }
                }
                else
                {
                    break;
                }
            }

            if (addAtMiddle && middlePolygon != null)
            {
                CreateSkeleton(width, newBaseDirection, middlePolygon, totalLength / 2, queue, m_Random.Next(2) == 0);
            }
        }