47 lines
1.2 KiB
C#
47 lines
1.2 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Assets.Common;
|
|
using Assets.Voronoi;
|
|
|
|
namespace Assets.Cities
|
|
{
|
|
public class City
|
|
{
|
|
public Graph<MapSite> startGraph;
|
|
public List<MapSite> sites;
|
|
|
|
public Graph<Point> roads = new Graph<Point>();
|
|
public Graph<Point> fieldBoundaries = new Graph<Point>();
|
|
|
|
public List<CityField> fields = new List<CityField>();
|
|
|
|
public List<(int, int)> edges;
|
|
|
|
public City(Graph<MapSite> startGraph)
|
|
{
|
|
this.startGraph = startGraph;
|
|
|
|
this.sites = new List<MapSite>();
|
|
this.edges = new List<(int, int)>();
|
|
}
|
|
|
|
public City(Graph<MapSite> startGraph, List<MapSite> sitesList) : this(startGraph)
|
|
{
|
|
this.sites = sitesList;
|
|
}
|
|
|
|
public void AddSite(MapSite site)
|
|
{
|
|
sites.Add(site);
|
|
FixBoundaryEdges(site);
|
|
}
|
|
|
|
private void FixBoundaryEdges(MapSite site)
|
|
{
|
|
var a = edges;
|
|
var b = site.Edges.Select(x => x.Item1 < x.Item2 ? x : (x.Item2, x.Item1));
|
|
|
|
edges = a.Union(b).Except(a.Intersect(b)).ToList();
|
|
}
|
|
}
|
|
} |