city-generation/Game/Assets/Scripts/Generator/PopulationCentersGenerator.cs

40 lines
1.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TransportGame.Model;
using TransportGame.Noise;
namespace TransportGame.Generator
{
public class PopulationCentersGenerator
{
System.Random random = new System.Random();
public void Generate(Map map)
{
// Generate range
float mp = (float)(map.Width * map.Height) / (1024 * 1024); // For 4k x 4k range should be around 900
map.PopulationCenterRange = mp * 155f / 5f + 1490f / 3f; // For 2k x 2k range should be around 600
// Generate a number of points
int maxPoints = 16 * (int) Math.Sqrt(mp);
int points = random.Next(maxPoints / 2, maxPoints);
for (int i = 0; i < points; ++i)
{
int px, py;
do
{
px = random.Next(map.Width / 6, 5 * map.Width / 6);
py = random.Next(map.Height / 6, 5 * map.Height / 6);
}
while (map.IsWater(px, py));
map.PopulationCenters.Add(new Vector2(px, py));
}
}
}
}