2015-05-22 08:26:29 +00:00
|
|
|
|
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();
|
|
|
|
|
|
2015-06-17 09:07:02 +00:00
|
|
|
|
public void Generate(CityMap map)
|
2015-05-22 08:26:29 +00:00
|
|
|
|
{
|
2015-05-29 16:03:08 +00:00
|
|
|
|
// Generate range
|
|
|
|
|
float mp = (float)(map.Width * map.Height) / (1024 * 1024); // For 4k x 4k range should be around 900
|
2015-06-13 18:36:32 +00:00
|
|
|
|
map.PopulationCenterRange = mp * 31f + 496.66f; // For 2k x 2k range should be around 600
|
2015-05-29 16:03:08 +00:00
|
|
|
|
|
2015-05-22 08:26:29 +00:00
|
|
|
|
// Generate a number of points
|
2015-05-29 16:03:08 +00:00
|
|
|
|
int maxPoints = 16 * (int) Math.Sqrt(mp);
|
|
|
|
|
int points = random.Next(maxPoints / 2, maxPoints);
|
2015-05-22 08:26:29 +00:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < points; ++i)
|
|
|
|
|
{
|
|
|
|
|
int px, py;
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
2015-06-13 18:36:32 +00:00
|
|
|
|
px = random.Next(map.Width / 8, 7 * map.Width / 8);
|
|
|
|
|
py = random.Next(map.Height / 8, 7 * map.Height / 8);
|
2015-05-22 08:26:29 +00:00
|
|
|
|
}
|
|
|
|
|
while (map.IsWater(px, py));
|
|
|
|
|
|
2015-05-29 16:03:08 +00:00
|
|
|
|
map.PopulationCenters.Add(new Vector2(px, py));
|
2015-05-22 08:26:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|