public Town(TownOptions options) { Options = options; Random = new Random(options.Seed); var ok = false; while (!ok) { NumPatches = options.Patches; Roads = new List <List <Vector2> > (); Streets = new List <List <Vector2> > (); Gates = new List <Vector2> (); Center = new Vector2(Width / 2f * (1f + 0.1f * Random.value - 0.1f * Random.value), Height / 2f * (1f + 0.1f * Random.value - 0.1f * Random.value)); Patches = new List <Patch> (); WaterBorder = new List <Vector2> (); try { BuildPatches(); OptimizePatches(); BuildWalls(); BuildRoads(); PopulateTown(); ok = Roads.Count > 1; } catch (Exception exception) { Console.WriteLine(exception); } } }
public TownMeshRenderer(Town town, TownOptions options, TownMeshRendererOptions rendererOptions) { this.town = town; this.options = options; root = rendererOptions.Root; this.rendererOptions = rendererOptions; }
public GameObject GenerateOverlay() { if (TownGlobalObject.townsData[town.coord].TownGameObject == null) { TownGlobalObject.townsData[town.coord].TownGameObject = new GameObject(town.name); } var go = TownGlobalObject.townsData[town.coord].TownGameObject; go.transform.parent = root; child = go.transform; child.transform.localPosition = Vector3.zero; // var bounds = town.GetCityWallsBounds().Expand(100); TownOptions skeletonOptions = options; skeletonOptions.IOC = false; skeletonOptions.Farm = false; skeletonOptions.Roads = true; skeletonOptions.Walls = false; skeletonOptions.CityDetail = false; var geometry = town.GetTownGeometry(skeletonOptions); UnityEngine.Random.InitState(options.Seed.GetHashCode()); DrawOverlay(geometry, null); return(go); }
public static void RunIt() { TownRendererProxy proxy = GameObject.FindObjectOfType <TownRendererProxy>(); TownOptions townOptions = new TownOptions { Overlay = true, // options.Overlay, Patches = 32, //options.Patches, Walls = true, //options.Walls, Water = true, //options.Water, Seed = /*options.Seed ?? */ new System.Random().Next() }; Town town = new Town(townOptions); // var img = new TownRenderer(town, townOptions).DrawTown(); TownRenderer Trenderer = new TownRenderer(town, townOptions); proxy.townRenderer = Trenderer; proxy.DoShit(); // File.WriteAllText(@"C:\temp\town.svg", img); }
static void Main(string[] args) { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); var options = new Options(); var valid = Parser.Default.ParseArgumentsStrict(args, options); if (!valid) { throw new ArgumentException("Invalid application arguments"); } var townOptions = new TownOptions { Overlay = options.Overlay, Patches = options.Patches, Walls = options.Walls, Water = options.Water, Seed = options.Seed ?? new Random().Next() }; var town = new Town(townOptions); var img = new TownRenderer(town, townOptions).DrawTown(); File.WriteAllText(@"C:\temp\town.svg", img); }
public TownMeshRenderer(Town town, TownOptions options = null) { if (options == null) { options = TownOptions.Default; } _town = town; _options = options; }
public Town(TownOptions options) { Options = options; // Random = new Random (options.Seed); SplinesToRender = new List <Dictionary <Den.Tools.Coord, List <UnityEngine.Vector3> > >(); Random = new Random(options.Seed + RandomGen.Next()); mapOffset = options.mapOffset; townOffset = options.townOffset; var ok = false; while (!ok) { NumPatches = options.Patches; name = TownGlobalObjectService.NamesQueue.Dequeue(); //var addendum = // ((Options.coord.z > 0) ? "N" : "S") // + // ((Options.coord.x > 0) ? "E" : "W"); //name += "_" + addendum; //name = TownGlobalObjectService.namegenref.GeneratePlace(); // name = "cityWith"+ NumPatches+"Patches"; // TownGlobalObjectService.namegenref.GeneratePlace(); Roads = new List <List <Vector2> > (); Streets = new List <List <Vector2> > (); Gates = new List <Vector2> (); Center = new Vector2(Width / 2f * (1f + 0.1f * Random.value - 0.1f * Random.value), Height / 2f * (1f + 0.1f * Random.value - 0.1f * Random.value)); Patches = new List <Patch> (); WaterBorder = new List <Vector2> (); try { BuildPatches(); OptimizePatches(); BuildWalls(); BuildRoads(); PopulateTown(); ok = Roads.Count > 1; } catch (Exception exception) { Console.WriteLine(exception); } } }
public static Town.Town MakeTown( Coord index, int townOffsetX = 0, // WE USE THESE <---- TO DO THE SUB-TILE RENDER OFFSETS FROM TOWN INFO int townOffsetZ = 0, int seed = 0, int patches = 0) { // Debug.Log("*** REALLY * MAKING A TOWN ***********"); Town.TownOptions opt = new Town.TownOptions(); // TODO. make global Tile size from Terrain opt.mapOffset = new Town.Geom.Vector2(index.x * 1000, index.z * 1000); opt.townOffset = new Town.Geom.Vector2(townOffsetX * 1000, townOffsetZ * 1000); opt.Patches = (patches == 0)? RandomGen.NextValidRandomPatchAmountFromTGOSRange() : patches; opt.Overlay = TownGlobalObjectService.ProduceOverlay; opt.Water = false; // ( RandomGen.Next() % 2 == 0)?true:false; opt.CityDetail = true; opt.Walls = true; opt.Towers = true; // Debug.Log(opt.Patches + " patches requested"); opt.Seed = (seed == 0) ? opt.Seed : seed; opt.coord = index; Town.Town town = new Town.Town(opt); // town.coord = index; // town.Options.coord = index; MeshRenderer = new TownMeshRenderer(town, opt, TownGlobalObjectService.rendererOptions); TownGlobalObject.TownsWaitingToRender.Enqueue(MeshRenderer); TownGlobalObject.TownWaitingToRender = true; //Debug.LogFormat("{0} is {1} for location with {2} of {3} and {4} of {5} for {6} of size {7} ", // nameof(index), // index, // nameof(opt.mapOffset), // opt.mapOffset, // nameof(opt.townOffset), // opt.townOffset, // town.name, // opt.Patches // ); return(town); }
public TownGeometry GetTownGeometry(TownOptions options) { var geometry = new TownGeometry(); var buildingShapes = new List <Polygon> (); foreach (var patch in Patches.Where(p => p.Area != null)) { buildingShapes.AddRange(patch.Area.GetGeometry()); } var buildingPlacer = new BuildingPlacer(buildingShapes); var buildings = buildingPlacer.PopulateBuildings(); geometry.Buildings.AddRange(buildings); if (options.Walls) { geometry.Walls.AddRange(CityWall.GetEdges().Union(Castle.Wall.GetEdges()).Distinct()); geometry.Towers.AddRange(CityWall.Towers.Union(Castle.Wall.Towers)); geometry.Gates.AddRange(CityWall.Gates.Union(Castle.Wall.Gates)); } else { var castleWall = CityWall.GetEdges().Union(Castle.Wall.GetEdges()).Distinct().SelectMany(e => new [] { e.A, e.B }).Where(w => Castle.Patch.Shape.Vertices.Contains(w)).ToList(); var towers = CityWall.Towers.Union(Castle.Wall.Towers).Intersect(castleWall); var gates = CityWall.Gates.Union(Castle.Wall.Gates).Intersect(castleWall); geometry.Walls.AddRange(Edge.FromPointList(castleWall)); geometry.Towers.AddRange(towers); geometry.Gates.AddRange(gates); } geometry.Roads.AddRange(Roads); geometry.Roads.AddRange(Streets); geometry.Overlay.AddRange(Patches); geometry.Water.AddRange(Patches.Where(p => p.Water).Select(p => p.Shape)); geometry.WaterBorder = new Polygon(WaterBorder); return(geometry); }