private void AddToCenterList(List <Graph.Center> centers, Graph.Center center) { if (center != null && centers.IndexOf(center) < 0) { centers.Add(center); } }
// Assign a biome type to each polygon. If it has // ocean/coast/water, then that's the biome; otherwise it depends // on low/high elevation and low/medium/high moisture. This is // roughly based on the Whittaker diagram but adapted to fit the // needs of the island map generator. private static string GetBiome(Graph.Center p) { if (p.ocean) { return("OCEAN"); } else if (p.water) { if (p.elevation < 0.1f) { return("MARSH"); } if (p.elevation > 0.8f) { return("ICE"); } return("LAKE"); } else if (p.coast) { return("BEACH"); } else if (p.elevation > 0.8f) { if (p.moisture > 0.50f) { return("SNOW"); } else if (p.moisture > 0.33f) { return("TUNDRA"); } else if (p.moisture > 0.16f) { return("BARE"); } else { return("SCORCHED"); } } else if (p.elevation > 0.6f) { if (p.moisture > 0.66f) { return("TAIGA"); } else if (p.moisture > 0.33f) { return("SHRUBLAND"); } else { return("TEMPERATE_DESERT"); } } else if (p.elevation > 0.3f) { if (p.moisture > 0.83f) { return("TEMPERATE_RAIN_FOREST"); } else if (p.moisture > 0.50f) { return("TEMPERATE_DECIDUOUS_FOREST"); } else if (p.moisture > 0.16f) { return("GRASSLAND"); } else { return("TEMPERATE_DESERT"); } } else { if (p.moisture > 0.66f) { return("TROPICAL_RAIN_FOREST"); } else if (p.moisture > 0.33f) { return("TROPICAL_SEASONAL_FOREST"); } else if (p.moisture > 0.16f) { return("GRASSLAND"); } else { return("SUBTROPICAL_DESERT"); } } }
private void Build(Polygon polygon, VoronoiBase voronoi) { Dictionary <Point, Graph.Center> centerLoopup = new Dictionary <Point, Graph.Center>(); foreach (var point in polygon.Points) { Graph.Center center = new Graph.Center { id = data.centers.Count, pos = point.ToVector(), neighbours = new List <Graph.Center>(), borders = new List <Graph.Edge>(), corners = new List <Graph.Corner>() }; data.centers.Add(center); centerLoopup[point] = center; } foreach (var face in voronoi.Faces) { face.LoopEdges(halfEdge => { Point voronoiEdge1 = halfEdge.Origin; Point voronoiEdge2 = halfEdge.Twin.Origin; Point delaunayEdge1 = polygon.Points[halfEdge.Face.ID]; Point delaunayEdge2 = polygon.Points[halfEdge.Twin.Face.ID]; Graph.Edge edge = new Graph.Edge { id = data.edges.Count, midPoint = new Vector2((float)(voronoiEdge1.X + voronoiEdge2.X) / 2, (float)(voronoiEdge1.Y + voronoiEdge2.Y) / 2), v0 = MakeCorner(voronoiEdge1), v1 = MakeCorner(voronoiEdge2), d0 = centerLoopup[delaunayEdge1], d1 = centerLoopup[delaunayEdge2] }; if (edge.d0 != null) { edge.d0.borders.Add(edge); } if (edge.d1 != null) { edge.d1.borders.Add(edge); } if (edge.v0 != null) { edge.v0.protrudes.Add(edge); } if (edge.v1 != null) { edge.v1.protrudes.Add(edge); } data.edges.Add(edge); // Centers point to centers. if (edge.d0 != null && edge.d1 != null) { AddToCenterList(edge.d0.neighbours, edge.d1); AddToCenterList(edge.d1.neighbours, edge.d0); } // Corners point to corners if (edge.v0 != null && edge.v1 != null) { AddToCornerList(edge.v0.adjacent, edge.v1); AddToCornerList(edge.v1.adjacent, edge.v0); } // Centers point to corners if (edge.d0 != null) { AddToCornerList(edge.d0.corners, edge.v0); AddToCornerList(edge.d0.corners, edge.v1); } if (edge.d1 != null) { AddToCornerList(edge.d1.corners, edge.v0); AddToCornerList(edge.d1.corners, edge.v1); } // Corners point to centers if (edge.v0 != null) { AddToCenterList(edge.v0.touches, edge.d0); AddToCenterList(edge.v0.touches, edge.d1); } if (edge.v1 != null) { AddToCenterList(edge.v1.touches, edge.d0); AddToCenterList(edge.v1.touches, edge.d1); } }); } }