Map generation tweaking: some biomes are placed at the center of the map, some at the center and some randomly.
This commit is contained in:
@@ -112,7 +112,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public void GenerateMap(string seed)
|
public void GenerateMap(string seed)
|
||||||
{
|
{
|
||||||
Map = new Map(seed, 500);
|
Map = new Map(seed, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Start()
|
public override void Start()
|
||||||
|
|||||||
@@ -114,13 +114,11 @@ namespace Barotrauma
|
|||||||
new Rectangle((int)start.X, (int)start.Y, (int)dist + 2, width),
|
new Rectangle((int)start.X, (int)start.Y, (int)dist + 2, width),
|
||||||
new Rectangle(0, 0, iceCrack.Width, 60), crackColor, MathUtils.VectorToAngle(end - start),
|
new Rectangle(0, 0, iceCrack.Width, 60), crackColor, MathUtils.VectorToAngle(end - start),
|
||||||
new Vector2(0, 30), SpriteEffects.None, 0.01f);
|
new Vector2(0, 30), SpriteEffects.None, 0.01f);
|
||||||
|
|
||||||
if (i == 0)
|
|
||||||
{
|
|
||||||
|
|
||||||
GUI.DrawString(spriteBatch, start, connection.Biome.Name, Color.White);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: remove
|
||||||
|
Vector2 center = rectCenter + (connection.CenterPos + offset) * scale;
|
||||||
|
GUI.DrawString(spriteBatch, center, connection.Biome.Name, Color.White);
|
||||||
}
|
}
|
||||||
|
|
||||||
rect.Inflate(8, 8);
|
rect.Inflate(8, 8);
|
||||||
|
|||||||
@@ -4,24 +4,29 @@
|
|||||||
<Biomes>
|
<Biomes>
|
||||||
<Biome
|
<Biome
|
||||||
name = "Cold Caverns"
|
name = "Cold Caverns"
|
||||||
description= "asdgfdfg"/>
|
description= "asdgfdfg"
|
||||||
|
MapPlacement="Center, Random"/>
|
||||||
|
|
||||||
<Biome
|
<Biome
|
||||||
name = "Volcanic Ridge"
|
name = "Volcanic Ridge"
|
||||||
description= "asdgfdfg"/>
|
description= "asdgfdfg"
|
||||||
|
MapPlacement="Random"/>
|
||||||
|
|
||||||
<Biome
|
<Biome
|
||||||
name = "Hydrothermal Wastes"
|
name = "Hydrothermal Wastes"
|
||||||
description= "asdgfdfg"/>
|
description= "asdgfdfg"
|
||||||
|
MapPlacement="Random"/>
|
||||||
|
|
||||||
<Biome
|
<Biome
|
||||||
name = "Great Sea"
|
name = "Great Sea"
|
||||||
description= "asdgfdfg"/>
|
description= "asdgfdfg"
|
||||||
|
MapPlacement="Edge"/>
|
||||||
</Biomes>
|
</Biomes>
|
||||||
|
|
||||||
<Default
|
<Default
|
||||||
biomes="Cold Caverns"
|
biomes="Cold Caverns"
|
||||||
width="150000"
|
width="150000"
|
||||||
height="60000"
|
height="60000"
|
||||||
VoronoiSiteInterval="2000,2000"
|
VoronoiSiteInterval="2000,2000"
|
||||||
VoronoiSiteVariance="800,800"
|
VoronoiSiteVariance="800,800"
|
||||||
MainPathNodeIntervalRange="10000,30000"
|
MainPathNodeIntervalRange="10000,30000"
|
||||||
|
|||||||
@@ -8,9 +8,18 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
class Biome
|
class Biome
|
||||||
{
|
{
|
||||||
|
public enum MapPlacement
|
||||||
|
{
|
||||||
|
Random = 1,
|
||||||
|
Center = 2,
|
||||||
|
Edge = 4
|
||||||
|
}
|
||||||
|
|
||||||
public readonly string Name;
|
public readonly string Name;
|
||||||
public readonly string Description;
|
public readonly string Description;
|
||||||
|
|
||||||
|
public readonly MapPlacement Placement;
|
||||||
|
|
||||||
public Biome(string name, string description)
|
public Biome(string name, string description)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
@@ -21,6 +30,17 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
Name = ToolBox.GetAttributeString(element, "name", "Biome");
|
Name = ToolBox.GetAttributeString(element, "name", "Biome");
|
||||||
Description = ToolBox.GetAttributeString(element, "description", "");
|
Description = ToolBox.GetAttributeString(element, "description", "");
|
||||||
|
|
||||||
|
string[] placementsStrs = ToolBox.GetAttributeString(element, "MapPlacement", "Default").Split(',');
|
||||||
|
foreach (string placementStr in placementsStrs)
|
||||||
|
{
|
||||||
|
MapPlacement parsedPlacement;
|
||||||
|
if (Enum.TryParse(placementStr.Trim(), out parsedPlacement))
|
||||||
|
{
|
||||||
|
Placement |= parsedPlacement;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
string mapSeed = ToolBox.GetAttributeString(element, "seed", "a");
|
string mapSeed = ToolBox.GetAttributeString(element, "seed", "a");
|
||||||
|
|
||||||
int size = ToolBox.GetAttributeInt(element, "size", 500);
|
int size = ToolBox.GetAttributeInt(element, "size", 1000);
|
||||||
Map map = new Map(mapSeed, size);
|
Map map = new Map(mapSeed, size);
|
||||||
|
|
||||||
map.SetLocation(ToolBox.GetAttributeInt(element, "currentlocation", 0));
|
map.SetLocation(ToolBox.GetAttributeInt(element, "currentlocation", 0));
|
||||||
@@ -119,7 +119,7 @@ namespace Barotrauma
|
|||||||
Voronoi voronoi = new Voronoi(0.5f);
|
Voronoi voronoi = new Voronoi(0.5f);
|
||||||
|
|
||||||
List<Vector2> sites = new List<Vector2>();
|
List<Vector2> sites = new List<Vector2>();
|
||||||
for (int i = 0; i < 50; i++)
|
for (int i = 0; i < 100; i++)
|
||||||
{
|
{
|
||||||
sites.Add(new Vector2(Rand.Range(0.0f, size, Rand.RandSync.Server), Rand.Range(0.0f, size, Rand.RandSync.Server)));
|
sites.Add(new Vector2(Rand.Range(0.0f, size, Rand.RandSync.Server), Rand.Range(0.0f, size, Rand.RandSync.Server)));
|
||||||
}
|
}
|
||||||
@@ -159,6 +159,7 @@ namespace Barotrauma
|
|||||||
connections.Add(new LocationConnection(newLocations[0], newLocations[1]));
|
connections.Add(new LocationConnection(newLocations[0], newLocations[1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//remove connections that are too short
|
||||||
float minDistance = 50.0f;
|
float minDistance = 50.0f;
|
||||||
for (int i = connections.Count - 1; i >= 0; i--)
|
for (int i = connections.Count - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
@@ -201,6 +202,7 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
foreach (LocationConnection connection in connections)
|
foreach (LocationConnection connection in connections)
|
||||||
{
|
{
|
||||||
Vector2 start = connection.Locations[0].MapPosition;
|
Vector2 start = connection.Locations[0].MapPosition;
|
||||||
@@ -208,12 +210,54 @@ namespace Barotrauma
|
|||||||
int generations = (int)(Math.Sqrt(Vector2.Distance(start, end) / 10.0f));
|
int generations = (int)(Math.Sqrt(Vector2.Distance(start, end) / 10.0f));
|
||||||
connection.CrackSegments = MathUtils.GenerateJaggedLine(start, end, generations, 5.0f);
|
connection.CrackSegments = MathUtils.GenerateJaggedLine(start, end, generations, 5.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AssignBiomes();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AssignBiomes()
|
||||||
|
{
|
||||||
List<LocationConnection> biomeSeeds = new List<LocationConnection>();
|
List<LocationConnection> biomeSeeds = new List<LocationConnection>();
|
||||||
foreach (Biome biome in LevelGenerationParams.GetBiomes())
|
|
||||||
|
List<Biome> centerBiomes = LevelGenerationParams.GetBiomes().FindAll(b => b.Placement.HasFlag(Biome.MapPlacement.Center));
|
||||||
|
if (centerBiomes.Count > 0)
|
||||||
|
{
|
||||||
|
Vector2 mapCenter = new Vector2(locations.Sum(l => l.MapPosition.X), locations.Sum(l => l.MapPosition.Y)) / locations.Count;
|
||||||
|
foreach (Biome centerBiome in centerBiomes)
|
||||||
|
{
|
||||||
|
LocationConnection closestConnection = null;
|
||||||
|
float closestDist = float.PositiveInfinity;
|
||||||
|
foreach (LocationConnection connection in connections)
|
||||||
|
{
|
||||||
|
if (connection.Biome != null) continue;
|
||||||
|
|
||||||
|
float dist = Vector2.Distance(connection.CenterPos, mapCenter);
|
||||||
|
if (closestConnection == null || dist < closestDist)
|
||||||
|
{
|
||||||
|
closestConnection = connection;
|
||||||
|
closestDist = dist;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
closestConnection.Biome = centerBiome;
|
||||||
|
biomeSeeds.Add(closestConnection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Biome> edgeBiomes = LevelGenerationParams.GetBiomes().FindAll(b => b.Placement.HasFlag(Biome.MapPlacement.Edge));
|
||||||
|
if (edgeBiomes.Count > 0)
|
||||||
|
{
|
||||||
|
List<LocationConnection> edges = GetMapEdges();
|
||||||
|
foreach (LocationConnection edge in edges)
|
||||||
|
{
|
||||||
|
edge.Biome = edgeBiomes[Rand.Range(0, edgeBiomes.Count, Rand.RandSync.Server)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Biome> randomBiomes = LevelGenerationParams.GetBiomes().FindAll(b => b.Placement.HasFlag(Biome.MapPlacement.Random));
|
||||||
|
foreach (Biome biome in randomBiomes)
|
||||||
{
|
{
|
||||||
LocationConnection seed = connections[0];
|
LocationConnection seed = connections[0];
|
||||||
while (biomeSeeds.Contains(seed))
|
while (seed.Biome != null)
|
||||||
{
|
{
|
||||||
seed = connections[Rand.Range(0, connections.Count, Rand.RandSync.Server)];
|
seed = connections[Rand.Range(0, connections.Count, Rand.RandSync.Server)];
|
||||||
}
|
}
|
||||||
@@ -247,6 +291,25 @@ namespace Barotrauma
|
|||||||
ExpandBiomes(nextSeeds);
|
ExpandBiomes(nextSeeds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<LocationConnection> GetMapEdges()
|
||||||
|
{
|
||||||
|
List<Vector2> verts = locations.Select(l => l.MapPosition).ToList();
|
||||||
|
|
||||||
|
List<Vector2> giftWrappedVerts = MathUtils.GiftWrap(verts);
|
||||||
|
|
||||||
|
List<LocationConnection> edges = new List<LocationConnection>();
|
||||||
|
foreach (LocationConnection connection in connections)
|
||||||
|
{
|
||||||
|
if (giftWrappedVerts.Contains(connection.Locations[0].MapPosition) ||
|
||||||
|
giftWrappedVerts.Contains(connection.Locations[1].MapPosition))
|
||||||
|
{
|
||||||
|
edges.Add(connection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return edges;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void GenerateDifficulties(Location start, List<LocationConnection> locations, float currDifficulty)
|
private void GenerateDifficulties(Location start, List<LocationConnection> locations, float currDifficulty)
|
||||||
@@ -339,6 +402,14 @@ namespace Barotrauma
|
|||||||
get { return level; }
|
get { return level; }
|
||||||
set { level = value; }
|
set { level = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vector2 CenterPos
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return (locations[0].MapPosition + locations[1].MapPosition) / 2.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public LocationConnection(Location location1, Location location2)
|
public LocationConnection(Location location1, Location location2)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user