Added lot allocation.

This commit is contained in:
2015-06-03 23:54:22 +03:00
parent f9b20b0226
commit 352f212ae9
28 changed files with 488 additions and 65 deletions

View 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;
}
}
}

View 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;
}
}
}

View 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;
}
}
}

View 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:

View File

@ -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;
}
}
}

View File

@ -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