Added lot allocation.
This commit is contained in:
parent
f9b20b0226
commit
352f212ae9
@ -48,6 +48,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Assets\Standard Assets\Character Controllers\Sources\Scripts\MouseLook.cs" />
|
||||
<Compile Include="Assets\Standard Assets\Environment\Water (Basic)\Scripts\WaterBasic.cs" />
|
||||
<None Include="Assets\Data\Config\roadgen.xml" />
|
||||
<None Include="Assets\Data\Config\tergen.xml" />
|
||||
<None Include="Assets\Standard Assets\Environment\Water (Basic)\Shaders\FXWaterBasic.shader" />
|
||||
<None Include="Assets\Data\Biomes\Grassland.xml" />
|
||||
|
@ -48,6 +48,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Assets\Standard Assets\Character Controllers\Sources\Scripts\MouseLook.cs" />
|
||||
<Compile Include="Assets\Standard Assets\Environment\Water (Basic)\Scripts\WaterBasic.cs" />
|
||||
<None Include="Assets\Data\Config\roadgen.xml" />
|
||||
<None Include="Assets\Data\Config\tergen.xml" />
|
||||
<None Include="Assets\Standard Assets\Environment\Water (Basic)\Shaders\FXWaterBasic.shader" />
|
||||
<None Include="Assets\Data\Biomes\Grassland.xml" />
|
||||
|
@ -47,12 +47,14 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Assets\Scripts\Business\BiomeManager.cs" />
|
||||
<Compile Include="Assets\Scripts\Business\ConfigurationManager.cs" />
|
||||
<Compile Include="Assets\Scripts\Business\ConfigManager.cs" />
|
||||
<Compile Include="Assets\Scripts\Generator\BuildingGenerator.cs" />
|
||||
<Compile Include="Assets\Scripts\Generator\CityGenerator.cs" />
|
||||
<Compile Include="Assets\Scripts\Generator\PopulationCentersGenerator.cs" />
|
||||
<Compile Include="Assets\Scripts\Generator\RoadGenerator.cs" />
|
||||
<Compile Include="Assets\Scripts\Generator\TerrainGenerator.cs" />
|
||||
<Compile Include="Assets\Scripts\Model\Biome.cs" />
|
||||
<Compile Include="Assets\Scripts\Model\Config\RoadGeneratorConfig.cs" />
|
||||
<Compile Include="Assets\Scripts\Model\Config\TerrainGeneratorConfig.cs" />
|
||||
<Compile Include="Assets\Scripts\Model\IPositionable.cs" />
|
||||
<Compile Include="Assets\Scripts\Model\LineSegment.cs" />
|
||||
@ -79,6 +81,7 @@
|
||||
<Compile Include="Assets\Scripts\Utils\SerializationHelper.cs" />
|
||||
<Compile Include="Assets\Scripts\Utils\Task.cs" />
|
||||
<Compile Include="Assets\Scripts\Utils\Texture2DExtensions.cs" />
|
||||
<None Include="Assets\Data\Config\roadgen.xml" />
|
||||
<None Include="Assets\Data\Config\tergen.xml" />
|
||||
<None Include="Assets\Standard Assets\Environment\Water (Basic)\Shaders\FXWaterBasic.shader" />
|
||||
<None Include="Assets\Data\Biomes\Grassland.xml" />
|
||||
|
@ -47,12 +47,14 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Assets\Scripts\Business\BiomeManager.cs" />
|
||||
<Compile Include="Assets\Scripts\Business\ConfigurationManager.cs" />
|
||||
<Compile Include="Assets\Scripts\Business\ConfigManager.cs" />
|
||||
<Compile Include="Assets\Scripts\Generator\BuildingGenerator.cs" />
|
||||
<Compile Include="Assets\Scripts\Generator\CityGenerator.cs" />
|
||||
<Compile Include="Assets\Scripts\Generator\PopulationCentersGenerator.cs" />
|
||||
<Compile Include="Assets\Scripts\Generator\RoadGenerator.cs" />
|
||||
<Compile Include="Assets\Scripts\Generator\TerrainGenerator.cs" />
|
||||
<Compile Include="Assets\Scripts\Model\Biome.cs" />
|
||||
<Compile Include="Assets\Scripts\Model\Config\RoadGeneratorConfig.cs" />
|
||||
<Compile Include="Assets\Scripts\Model\Config\TerrainGeneratorConfig.cs" />
|
||||
<Compile Include="Assets\Scripts\Model\IPositionable.cs" />
|
||||
<Compile Include="Assets\Scripts\Model\LineSegment.cs" />
|
||||
@ -79,6 +81,7 @@
|
||||
<Compile Include="Assets\Scripts\Utils\SerializationHelper.cs" />
|
||||
<Compile Include="Assets\Scripts\Utils\Task.cs" />
|
||||
<Compile Include="Assets\Scripts\Utils\Texture2DExtensions.cs" />
|
||||
<None Include="Assets\Data\Config\roadgen.xml" />
|
||||
<None Include="Assets\Data\Config\tergen.xml" />
|
||||
<None Include="Assets\Standard Assets\Environment\Water (Basic)\Shaders\FXWaterBasic.shader" />
|
||||
<None Include="Assets\Data\Biomes\Grassland.xml" />
|
||||
|
@ -50,6 +50,7 @@
|
||||
<Compile Include="Assets\Standard Assets\Character Controllers\Sources\Scripts\FPSInputController.js" />
|
||||
<Compile Include="Assets\Standard Assets\Character Controllers\Sources\Scripts\FlyCam.js" />
|
||||
<Compile Include="Assets\Standard Assets\Character Controllers\Sources\Scripts\PlatformInputController.js" />
|
||||
<None Include="Assets\Data\Config\roadgen.xml" />
|
||||
<None Include="Assets\Data\Config\tergen.xml" />
|
||||
<None Include="Assets\Standard Assets\Environment\Water (Basic)\Shaders\FXWaterBasic.shader" />
|
||||
<None Include="Assets\Data\Biomes\Grassland.xml" />
|
||||
|
@ -50,6 +50,7 @@
|
||||
<Compile Include="Assets\Standard Assets\Character Controllers\Sources\Scripts\FPSInputController.js" />
|
||||
<Compile Include="Assets\Standard Assets\Character Controllers\Sources\Scripts\FlyCam.js" />
|
||||
<Compile Include="Assets\Standard Assets\Character Controllers\Sources\Scripts\PlatformInputController.js" />
|
||||
<None Include="Assets\Data\Config\roadgen.xml" />
|
||||
<None Include="Assets\Data\Config\tergen.xml" />
|
||||
<None Include="Assets\Standard Assets\Environment\Water (Basic)\Shaders\FXWaterBasic.shader" />
|
||||
<None Include="Assets\Data\Biomes\Grassland.xml" />
|
||||
|
23
Game/Assets/Data/Config/roadgen.xml
Normal file
23
Game/Assets/Data/Config/roadgen.xml
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RoadGeneratorConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||
<DefaultSegmentLength>24</DefaultSegmentLength>
|
||||
<HighwaySegmentLength>60</HighwaySegmentLength>
|
||||
<DefaultBranchProbability>0.2</DefaultBranchProbability>
|
||||
<DefaultBranchPopulationTreshold>0.12</DefaultBranchPopulationTreshold>
|
||||
<HighwayBranchProbability>0.01</HighwayBranchProbability>
|
||||
<HighwayBranchPopulationTreshold>0.4</HighwayBranchPopulationTreshold>
|
||||
<HighwayBranchDelay>3</HighwayBranchDelay>
|
||||
<SteepnessLimit>10</SteepnessLimit>
|
||||
<SlopeLimit>0.448798954</SlopeLimit>
|
||||
<RoadSegmentAngleLimit>0.7853982</RoadSegmentAngleLimit>
|
||||
<MinNodeDistance>12</MinNodeDistance>
|
||||
<RoadSnapDistance>19</RoadSnapDistance>
|
||||
<MaximumRandomStraightAngle>45</MaximumRandomStraightAngle>
|
||||
<MaximumBranchAngleVariation>12</MaximumBranchAngleVariation>
|
||||
<MaximumIntersectingRoads>5</MaximumIntersectingRoads>
|
||||
<SidewalkWidth>0.8</SidewalkWidth>
|
||||
<LaneWidth>1</LaneWidth>
|
||||
<RaiseOffset>0.8</RaiseOffset>
|
||||
<SidewalkHeight>0.1</SidewalkHeight>
|
||||
<SideCoverHeight>0.1</SideCoverHeight>
|
||||
</RoadGeneratorConfig>
|
8
Game/Assets/Data/Config/roadgen.xml.meta
Normal file
8
Game/Assets/Data/Config/roadgen.xml.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8b97fa810c6224244a5ec1c8d5b27493
|
||||
timeCreated: 1433342482
|
||||
licenseType: Free
|
||||
TextScriptImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -29,7 +29,7 @@ namespace TransportGame.Business
|
||||
/// </summary>
|
||||
public static void LoadBiomes()
|
||||
{
|
||||
foreach (var file in Directory.GetFiles(ConfigurationManager.BiomeDirectory, "*.xml", SearchOption.AllDirectories))
|
||||
foreach (var file in Directory.GetFiles(ConfigManager.BiomeDirectory, "*.xml", SearchOption.AllDirectories))
|
||||
{
|
||||
try
|
||||
{
|
||||
|
55
Game/Assets/Scripts/Business/ConfigManager.cs
Normal file
55
Game/Assets/Scripts/Business/ConfigManager.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
using TransportGame.Model.Config;
|
||||
using TransportGame.Utils;
|
||||
|
||||
namespace TransportGame.Business
|
||||
{
|
||||
public static class ConfigManager
|
||||
{
|
||||
public static readonly string BiomeDirectory = "Assets\\Data\\Biomes";
|
||||
public static readonly string ConfigurationDirectory = "Assets\\Data\\Config";
|
||||
|
||||
public static readonly string TerrGenConfigFile = "tergen.xml";
|
||||
public static readonly string RoadGenConfigFile = "roadgen.xml";
|
||||
|
||||
public static TerrainGeneratorConfig Tergen { get; private set; }
|
||||
public static RoadGeneratorConfig Roadgen { get; private set; }
|
||||
public static BuildingGeneratorConfig Buildgen { get; private set; }
|
||||
|
||||
public static void LoadConfiguration()
|
||||
{
|
||||
// Terrain generator
|
||||
string tergenPath = Path.Combine(ConfigurationDirectory, TerrGenConfigFile);
|
||||
if (File.Exists(tergenPath))
|
||||
{
|
||||
Tergen = SerializationHelper.DeserializeXml<TerrainGeneratorConfig>(Path.Combine(ConfigurationDirectory, TerrGenConfigFile));
|
||||
}
|
||||
else
|
||||
{
|
||||
Tergen = new TerrainGeneratorConfig();
|
||||
Tergen.SerializeXml(tergenPath);
|
||||
}
|
||||
|
||||
// Road generator
|
||||
string roadgenPath = Path.Combine(ConfigurationDirectory, RoadGenConfigFile);
|
||||
if (File.Exists(roadgenPath))
|
||||
{
|
||||
Roadgen = SerializationHelper.DeserializeXml<RoadGeneratorConfig>(Path.Combine(ConfigurationDirectory, RoadGenConfigFile));
|
||||
}
|
||||
else
|
||||
{
|
||||
Roadgen = new RoadGeneratorConfig();
|
||||
Roadgen.SerializeXml(roadgenPath);
|
||||
}
|
||||
|
||||
// Building generator
|
||||
Buildgen = new BuildingGeneratorConfig();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
using Assets.Scripts.Model.Config;
|
||||
using TransportGame.Utils;
|
||||
|
||||
namespace TransportGame.Business
|
||||
{
|
||||
public static class ConfigurationManager
|
||||
{
|
||||
public static readonly string BiomeDirectory = "Assets\\Data\\Biomes";
|
||||
public static readonly string ConfigurationDirectory = "Assets\\Data\\Config";
|
||||
|
||||
public static readonly string TerrGenConfigFile = "tergen.xml";
|
||||
|
||||
public static TerrainGeneratorConfig TerrGenConfig { get; private set; }
|
||||
|
||||
public static void LoadConfiguration()
|
||||
{
|
||||
// Load terrgen config
|
||||
TerrGenConfig = SerializationHelper.DeserializeXml<TerrainGeneratorConfig>(Path.Combine(ConfigurationDirectory, TerrGenConfigFile));
|
||||
}
|
||||
}
|
||||
}
|
118
Game/Assets/Scripts/Generator/BuildingGenerator.cs
Normal file
118
Game/Assets/Scripts/Generator/BuildingGenerator.cs
Normal file
@ -0,0 +1,118 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using TransportGame.Business;
|
||||
using TransportGame.Model;
|
||||
using TransportGame.Model.Road;
|
||||
using TransportGame.Utils;
|
||||
|
||||
namespace TransportGame.Generator
|
||||
{
|
||||
public class BuildingGenerator
|
||||
{
|
||||
private const float LotSquareSize = 1f;
|
||||
private const float LotSpacing = 0.1f;
|
||||
|
||||
private Map map;
|
||||
QuadTree<RoadNode> nodeTree;
|
||||
QuadTree<BuildingLot> lotTree;
|
||||
|
||||
private void AllocateLots()
|
||||
{
|
||||
float advance = LotSquareSize + LotSpacing;
|
||||
|
||||
// Generate lots for every segment
|
||||
foreach (var pair in map.RoadNetwork.ArticulationSegments)
|
||||
{
|
||||
var seg = pair.Value;
|
||||
var dir = seg.Direction;
|
||||
var perp = dir.RotateDeg(90);
|
||||
|
||||
float width0 = ConfigManager.Roadgen.SidewalkWidth + ConfigManager.Roadgen.LaneWidth * seg.LanesTo1;
|
||||
float width1 = ConfigManager.Roadgen.SidewalkWidth + ConfigManager.Roadgen.LaneWidth * seg.LanesTo2;
|
||||
|
||||
for (Vector2 pos = seg.Terminal1.Position; (pos - seg.Terminal2.Position).LengthSq > advance * advance; pos += dir * advance)
|
||||
{
|
||||
// Build lot squares
|
||||
Vector2[] left = new Vector2[4];
|
||||
left[0] = pos + perp * (width0 + LotSpacing + LotSquareSize);
|
||||
left[1] = pos + perp * (width0 + LotSpacing);
|
||||
left[2] = pos + dir * LotSquareSize + perp * (width0 + LotSpacing);
|
||||
left[3] = pos + dir * LotSquareSize + perp * (width0 + LotSpacing + LotSquareSize);
|
||||
|
||||
Vector2[] right = new Vector2[4];
|
||||
right[0] = pos - perp * (width0 + LotSpacing + LotSquareSize);
|
||||
right[1] = pos - perp * (width0 + LotSpacing);
|
||||
right[2] = pos + dir * LotSquareSize - perp * (width0 + LotSpacing);
|
||||
right[3] = pos + dir * LotSquareSize - perp * (width0 + LotSpacing + LotSquareSize);
|
||||
|
||||
BuildingLot lot0 = new BuildingLot(left);
|
||||
BuildingLot lot1 = new BuildingLot(right);
|
||||
|
||||
// Test for intersections
|
||||
if (CanAllocate(pos, lot0))
|
||||
lotTree.Add(lot0);
|
||||
|
||||
if (CanAllocate(pos, lot1))
|
||||
lotTree.Add(lot1);
|
||||
}
|
||||
}
|
||||
|
||||
// Done
|
||||
map.BuildingLots = lotTree.ToList();
|
||||
}
|
||||
|
||||
private bool CanAllocate(Vector2 pos, BuildingLot lot0)
|
||||
{
|
||||
// Test other lots
|
||||
Rectangle lotArea = new Rectangle(pos.X - 2 * LotSquareSize, pos.Y - 2 * LotSquareSize, pos.X + 2 * LotSquareSize, pos.Y + 2 * LotSquareSize);
|
||||
foreach (var lot in lotTree.Query(lotArea))
|
||||
{
|
||||
if (BuildingLot.Intersect(lot0, lot))
|
||||
return false;
|
||||
}
|
||||
|
||||
// Test nearby roads
|
||||
Rectangle roadArea = new Rectangle(
|
||||
pos.X - 2 * ConfigManager.Roadgen.HighwaySegmentLength,
|
||||
pos.Y - 2 * ConfigManager.Roadgen.HighwaySegmentLength,
|
||||
pos.X + 2 * ConfigManager.Roadgen.HighwaySegmentLength,
|
||||
pos.Y + 2 * ConfigManager.Roadgen.HighwaySegmentLength);
|
||||
|
||||
foreach (var node in nodeTree.Query(roadArea))
|
||||
{
|
||||
foreach (var segment in node.ArticulationSegments)
|
||||
{
|
||||
if (BuildingLot.Intersect(lot0, segment.AsLineSegment()))
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void GenerateBuildings()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Generate(Map map)
|
||||
{
|
||||
this.map = map;
|
||||
|
||||
// Construct node tree
|
||||
nodeTree = new QuadTree<RoadNode>(0, 0, map.Width, map.Height);
|
||||
foreach (var pair in map.RoadNetwork.Nodes)
|
||||
nodeTree.Add(pair.Value);
|
||||
|
||||
lotTree = new QuadTree<BuildingLot>(0, 0, map.Width, map.Height);
|
||||
|
||||
// Allocate lots
|
||||
AllocateLots();
|
||||
|
||||
GenerateBuildings();
|
||||
}
|
||||
}
|
||||
}
|
12
Game/Assets/Scripts/Generator/BuildingGenerator.cs.meta
Normal file
12
Game/Assets/Scripts/Generator/BuildingGenerator.cs.meta
Normal file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 387d471e5e9dff54b9cb832e01b969ec
|
||||
timeCreated: 1433340433
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using TransportGame.Business;
|
||||
using TransportGame.Model;
|
||||
using TransportGame.Model.Road;
|
||||
using TransportGame.Utils;
|
||||
@ -50,21 +51,21 @@ namespace TransportGame.Generator
|
||||
System.Random random = new System.Random();
|
||||
Map map;
|
||||
|
||||
const float HighwaySegmentLength = 60;
|
||||
const float DefaultBranchPopulationTreshold = 0.12f;
|
||||
const float DefaultBranchProbability = 0.2f;
|
||||
const float DefaultSegmentLength = 24;
|
||||
const float SteepnessLimit = 10;
|
||||
const float SlopeLimit = (float)Math.PI / 7;
|
||||
const float RoadSegmentAngleLimit = (float)Math.PI / 4;
|
||||
const float RoadSnapDistance = 19;
|
||||
const float MinNodeDistance = 12;
|
||||
const int MaximumRandomStraightAngle = 45; // in degrees
|
||||
const int MaximumBranchAngleVariation = 12; // in degrees
|
||||
const float HighwayBranchPopulationTreshold = .4f; // 0..1
|
||||
const float HighwayBranchProbability = .01f;
|
||||
const int HighwayBranchDelay = 3;
|
||||
const int MaximumIntersectingRoads = 5;
|
||||
private float HighwaySegmentLength { get { return ConfigManager.Roadgen.HighwaySegmentLength; } }
|
||||
private float DefaultBranchPopulationTreshold { get { return ConfigManager.Roadgen.DefaultBranchPopulationTreshold; } }
|
||||
private float DefaultBranchProbability { get { return ConfigManager.Roadgen.DefaultBranchProbability; } }
|
||||
private float DefaultSegmentLength { get { return ConfigManager.Roadgen.DefaultSegmentLength; } }
|
||||
private float SteepnessLimit { get { return ConfigManager.Roadgen.SteepnessLimit; } }
|
||||
private float SlopeLimit { get { return ConfigManager.Roadgen.SlopeLimit; } }
|
||||
private float RoadSegmentAngleLimit { get { return ConfigManager.Roadgen.RoadSegmentAngleLimit; } }
|
||||
private float RoadSnapDistance { get { return ConfigManager.Roadgen.RoadSnapDistance; } }
|
||||
private float MinNodeDistance { get { return ConfigManager.Roadgen.MinNodeDistance; } }
|
||||
private int MaximumRandomStraightAngle { get { return ConfigManager.Roadgen.MaximumRandomStraightAngle; } }
|
||||
private int MaximumBranchAngleVariation { get { return ConfigManager.Roadgen.MaximumBranchAngleVariation; } }
|
||||
private float HighwayBranchPopulationTreshold { get { return ConfigManager.Roadgen.HighwayBranchPopulationTreshold; } }
|
||||
private float HighwayBranchProbability { get { return ConfigManager.Roadgen.HighwayBranchProbability; } }
|
||||
private int HighwayBranchDelay { get { return ConfigManager.Roadgen.HighwayBranchDelay; } }
|
||||
private int MaximumIntersectingRoads { get { return ConfigManager.Roadgen.MaximumIntersectingRoads; } }
|
||||
|
||||
public RoadGenerator()
|
||||
{
|
||||
|
@ -26,12 +26,12 @@ namespace TransportGame.Generator
|
||||
{
|
||||
Noise = new PerlinNoiseGenerator();
|
||||
|
||||
if (ConfigurationManager.TerrGenConfig == null)
|
||||
if (ConfigManager.Tergen == null)
|
||||
throw new Exception("Not initialized!");
|
||||
|
||||
Noise.Octaves = ConfigurationManager.TerrGenConfig.NoiseOctaves;
|
||||
Noise.NonLinearPower = ConfigurationManager.TerrGenConfig.NoiseNonLinearPower;
|
||||
Noise.Scale = ConfigurationManager.TerrGenConfig.ElevationScale;
|
||||
Noise.Octaves = ConfigManager.Tergen.NoiseOctaves;
|
||||
Noise.NonLinearPower = ConfigManager.Tergen.NoiseNonLinearPower;
|
||||
Noise.Scale = ConfigManager.Tergen.ElevationScale;
|
||||
}
|
||||
|
||||
public Map Generate(int width, int height)
|
||||
@ -48,7 +48,7 @@ namespace TransportGame.Generator
|
||||
|
||||
// Generate water level
|
||||
float waterAmount = random.NextSingle(map.Biome.Moisture.Minimum, map.Biome.Moisture.Maximum);
|
||||
map.WaterLevel = Mathf.Pow(waterAmount, ConfigurationManager.TerrGenConfig.WaterNonLinearPower) * map.Biome.Height;
|
||||
map.WaterLevel = Mathf.Pow(waterAmount, ConfigManager.Tergen.WaterNonLinearPower) * map.Biome.Height;
|
||||
|
||||
return map;
|
||||
}
|
||||
|
67
Game/Assets/Scripts/Model/BuildingLot.cs
Normal file
67
Game/Assets/Scripts/Model/BuildingLot.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using TransportGame.Business;
|
||||
|
||||
namespace TransportGame.Model
|
||||
{
|
||||
public class BuildingLot : IPositionable
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the list of points
|
||||
/// </summary>
|
||||
public Vector2[] Points { get; set; }
|
||||
|
||||
public BuildingLot()
|
||||
{
|
||||
Points = new Vector2[4];
|
||||
}
|
||||
|
||||
public BuildingLot(params Vector2[] points)
|
||||
{
|
||||
Points = points;
|
||||
}
|
||||
|
||||
public BuildingLot(IEnumerable<Vector2> points)
|
||||
{
|
||||
Points = points.ToArray();
|
||||
}
|
||||
|
||||
public Vector2 Position
|
||||
{
|
||||
get { return Points.Aggregate((x, y) => x + y) / Points.Length; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests if two building lots intersect
|
||||
/// </summary>
|
||||
/// <param name="a">First lot</param>
|
||||
/// <param name="b">Second lot</param>
|
||||
/// <returns></returns>
|
||||
public static bool Intersect(BuildingLot a, BuildingLot b)
|
||||
{
|
||||
return (a.Position - b.Position).LengthSq <= ConfigManager.Buildgen.LotSquareSize + ConfigManager.Buildgen.LotSpacing;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests if a building lot intersects a line segment (such as a road segment)
|
||||
/// </summary>
|
||||
/// <param name="a"></param>
|
||||
/// <param name="b"></param>
|
||||
/// <returns></returns>
|
||||
public static bool Intersect(BuildingLot a, LineSegment b)
|
||||
{
|
||||
for (int i = 0; i < a.Points.Length; i++)
|
||||
{
|
||||
int j = (i + 1 >= a.Points.Length) ? 0 : i + 1;
|
||||
|
||||
LineSegment s = new LineSegment(a.Points[i], a.Points[j]);
|
||||
if (LineSegment.Intersect(s, b).HasValue)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
26
Game/Assets/Scripts/Model/Config/BuildingGeneratorConfig.cs
Normal file
26
Game/Assets/Scripts/Model/Config/BuildingGeneratorConfig.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TransportGame.Model.Config
|
||||
{
|
||||
public class BuildingGeneratorConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Lot size
|
||||
/// </summary>
|
||||
public float LotSquareSize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Space between lots
|
||||
/// </summary>
|
||||
public float LotSpacing { get; set; }
|
||||
|
||||
public BuildingGeneratorConfig()
|
||||
{
|
||||
LotSquareSize = 1f;
|
||||
LotSpacing = 0.1f;
|
||||
}
|
||||
}
|
||||
}
|
83
Game/Assets/Scripts/Model/Config/RoadGeneratorConfig.cs
Normal file
83
Game/Assets/Scripts/Model/Config/RoadGeneratorConfig.cs
Normal file
@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TransportGame.Model.Config
|
||||
{
|
||||
public class RoadGeneratorConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the default segment length
|
||||
/// </summary>
|
||||
public float DefaultSegmentLength { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the highway segment length
|
||||
/// </summary>
|
||||
public float HighwaySegmentLength { get; set; }
|
||||
|
||||
public float DefaultBranchProbability { get; set; }
|
||||
public float DefaultBranchPopulationTreshold { get; set; }
|
||||
public float HighwayBranchProbability { get; set; }
|
||||
public float HighwayBranchPopulationTreshold { get; set; }
|
||||
|
||||
public int HighwayBranchDelay { get; set; }
|
||||
|
||||
public float SteepnessLimit { get; set; }
|
||||
public float SlopeLimit { get; set; }
|
||||
public float RoadSegmentAngleLimit { get; set; }
|
||||
public float MinNodeDistance { get; set; }
|
||||
|
||||
public float RoadSnapDistance { get; set; }
|
||||
public int MaximumRandomStraightAngle { get; set; }
|
||||
public int MaximumBranchAngleVariation { get; set; }
|
||||
public int MaximumIntersectingRoads { get; set; }
|
||||
|
||||
public float SidewalkWidth { get; set; }
|
||||
public float LaneWidth { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Raises road above actual height of terrain
|
||||
/// </summary>
|
||||
public float RaiseOffset { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Height of sidewalk
|
||||
/// </summary>
|
||||
public float SidewalkHeight { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// On the sides of the roads, so that we can't see under the road
|
||||
/// </summary>
|
||||
public float SideCoverHeight { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes configuration with default values
|
||||
/// </summary>
|
||||
public RoadGeneratorConfig()
|
||||
{
|
||||
HighwaySegmentLength = 60;
|
||||
DefaultBranchPopulationTreshold = 0.12f;
|
||||
DefaultBranchProbability = 0.2f;
|
||||
DefaultSegmentLength = 24;
|
||||
SteepnessLimit = 10;
|
||||
SlopeLimit = (float)Math.PI / 7;
|
||||
RoadSegmentAngleLimit = (float)Math.PI / 4;
|
||||
RoadSnapDistance = 19;
|
||||
MinNodeDistance = 12;
|
||||
MaximumRandomStraightAngle = 45; // in degrees
|
||||
MaximumBranchAngleVariation = 12; // in degrees
|
||||
HighwayBranchPopulationTreshold = .4f; // 0..1
|
||||
HighwayBranchProbability = .01f;
|
||||
HighwayBranchDelay = 3;
|
||||
MaximumIntersectingRoads = 5;
|
||||
|
||||
SidewalkWidth = .8f;
|
||||
LaneWidth = 1f;
|
||||
RaiseOffset = 0.8f;
|
||||
SidewalkHeight = 0.1f;
|
||||
SideCoverHeight = 0.1f;
|
||||
}
|
||||
}
|
||||
}
|
12
Game/Assets/Scripts/Model/Config/RoadGeneratorConfig.cs.meta
Normal file
12
Game/Assets/Scripts/Model/Config/RoadGeneratorConfig.cs.meta
Normal file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 541bc5719bdd5fc4c84addebb8208869
|
||||
timeCreated: 1433340433
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace Assets.Scripts.Model.Config
|
||||
namespace TransportGame.Model.Config
|
||||
{
|
||||
[XmlRoot("terrgenConfig")]
|
||||
public class TerrainGeneratorConfig
|
||||
@ -29,5 +29,19 @@ namespace Assets.Scripts.Model.Config
|
||||
|
||||
[XmlElement("erodeAmountPercent")]
|
||||
public float ErodeAmountPercent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes with default values
|
||||
/// </summary>
|
||||
public TerrainGeneratorConfig()
|
||||
{
|
||||
NoiseOctaves = 9;
|
||||
NoiseNonLinearPower = 2.4f;
|
||||
WaterNonLinearPower = 1.9f;
|
||||
ElevationScale = 0.001f;
|
||||
ErodePoints = 100;
|
||||
ErodeIterations = 60;
|
||||
ErodeAmountPercent = 0.1f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -83,6 +83,12 @@ namespace TransportGame.Model
|
||||
[XmlElement("roadNetwork")]
|
||||
public RoadNetwork RoadNetwork { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the building lots
|
||||
/// </summary>
|
||||
[XmlElement("lots")]
|
||||
public List<BuildingLot> BuildingLots { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
@ -12,7 +12,7 @@ public class InitializeScript : MonoBehaviour
|
||||
{
|
||||
// Load configuration
|
||||
Logger.Info("Loading configuration...");
|
||||
ConfigurationManager.LoadConfiguration();
|
||||
ConfigManager.LoadConfiguration();
|
||||
|
||||
// Load biomes
|
||||
Logger.Info("Loading biomes...");
|
||||
|
@ -3,6 +3,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using TransportGame.Business;
|
||||
using TransportGame.Model;
|
||||
using TransportGame.Model.Road;
|
||||
using TransportGame.Utils;
|
||||
@ -17,12 +18,18 @@ namespace TransportGame.Unity
|
||||
{
|
||||
#region Constants
|
||||
|
||||
private const float SidewalkWidth = .8f;
|
||||
private const float LaneWidth = 1f;
|
||||
private float SidewalkWidth { get { return ConfigManager.Roadgen.SidewalkWidth; } }
|
||||
|
||||
private const float RaiseOffset = 0.8f; // Raises road above actual height of terrain
|
||||
private const float SidewalkHeight = 0.1f; // Height of sidewalk
|
||||
private const float SideCoverHeight = 0.1f; // On the sides of the roads, so that we can't see the road from the underside
|
||||
private float LaneWidth { get { return ConfigManager.Roadgen.LaneWidth; } }
|
||||
|
||||
// Raises road above actual height of terrain
|
||||
private float RaiseOffset { get { return ConfigManager.Roadgen.RaiseOffset; } }
|
||||
|
||||
// Height of sidewalk
|
||||
private float SidewalkHeight { get { return ConfigManager.Roadgen.SidewalkHeight; } }
|
||||
|
||||
// On the sides of the roads, so that we can't see the road from the underside
|
||||
private float SideCoverHeight { get { return ConfigManager.Roadgen.SideCoverHeight; } }
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -65,6 +65,7 @@
|
||||
<ItemGroup>
|
||||
<None Include="Assets\Data\Biomes\Grassland.xml" />
|
||||
<None Include="Assets\Data\Biomes\Mountain.xml" />
|
||||
<None Include="Assets\Data\Config\roadgen.xml" />
|
||||
<None Include="Assets\Data\Config\tergen.xml" />
|
||||
<None Include="Assets\Standard Assets\Environment\Water (Basic)\Shaders\FXWaterBasic.shader" />
|
||||
</ItemGroup>
|
||||
|
@ -7,14 +7,16 @@
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{02576F1D-BE9C-CFA7-763D-1EBF63B36977}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace></RootNamespace>
|
||||
<RootNamespace>
|
||||
</RootNamespace>
|
||||
<AssemblyName>Assembly-CSharp</AssemblyName>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile>Unity Subset v3.5</TargetFrameworkProfile>
|
||||
<CompilerResponseFile></CompilerResponseFile>
|
||||
<CompilerResponseFile>
|
||||
</CompilerResponseFile>
|
||||
<UnityProjectType>Game:1</UnityProjectType>
|
||||
<UnityBuildTarget>StandaloneWindows64:19</UnityBuildTarget>
|
||||
<UnityVersion>5.0.1f1</UnityVersion>
|
||||
@ -69,12 +71,16 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Assets\Scripts\Business\BiomeManager.cs" />
|
||||
<Compile Include="Assets\Scripts\Business\ConfigurationManager.cs" />
|
||||
<Compile Include="Assets\Scripts\Business\ConfigManager.cs" />
|
||||
<Compile Include="Assets\Scripts\Generator\BuildingGenerator.cs" />
|
||||
<Compile Include="Assets\Scripts\Generator\CityGenerator.cs" />
|
||||
<Compile Include="Assets\Scripts\Generator\PopulationCentersGenerator.cs" />
|
||||
<Compile Include="Assets\Scripts\Generator\RoadGenerator.cs" />
|
||||
<Compile Include="Assets\Scripts\Generator\TerrainGenerator.cs" />
|
||||
<Compile Include="Assets\Scripts\Model\Biome.cs" />
|
||||
<Compile Include="Assets\Scripts\Model\BuildingLot.cs" />
|
||||
<Compile Include="Assets\Scripts\Model\Config\BuildingGeneratorConfig.cs" />
|
||||
<Compile Include="Assets\Scripts\Model\Config\RoadGeneratorConfig.cs" />
|
||||
<Compile Include="Assets\Scripts\Model\Config\TerrainGeneratorConfig.cs" />
|
||||
<Compile Include="Assets\Scripts\Model\IPositionable.cs" />
|
||||
<Compile Include="Assets\Scripts\Model\LineSegment.cs" />
|
||||
@ -105,6 +111,7 @@
|
||||
<ItemGroup>
|
||||
<None Include="Assets\Data\Biomes\Grassland.xml" />
|
||||
<None Include="Assets\Data\Biomes\Mountain.xml" />
|
||||
<None Include="Assets\Data\Config\roadgen.xml" />
|
||||
<None Include="Assets\Data\Config\tergen.xml" />
|
||||
<None Include="Assets\Standard Assets\Environment\Water (Basic)\Shaders\FXWaterBasic.shader" />
|
||||
</ItemGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user