Voting for round to end, level generation improvements
This commit is contained in:
@@ -150,18 +150,21 @@ namespace Barotrauma
|
||||
|
||||
float minWidth = Submarine.Loaded == null ? 3000.0f : Math.Max(Submarine.Borders.Width, Submarine.Borders.Height);
|
||||
|
||||
startPosition = new Vector2(minWidth * 2, borders.Height);
|
||||
endPosition = new Vector2(borders.Width - minWidth * 2, borders.Height);
|
||||
startPosition = new Vector2((int)minWidth * 2, Rand.Range((int)minWidth * 2, borders.Height - (int)minWidth * 2, false));
|
||||
endPosition = new Vector2(borders.Width - (int)minWidth * 2, Rand.Range((int)minWidth * 2, borders.Height - (int)minWidth * 2, false));
|
||||
|
||||
|
||||
|
||||
List<Vector2> pathNodes = new List<Vector2>();
|
||||
Rectangle pathBorders = borders;// new Rectangle((int)minWidth, (int)minWidth, borders.Width - (int)minWidth * 2, borders.Height - (int)minWidth);
|
||||
pathBorders.Inflate(-minWidth*2, -minWidth*2);
|
||||
|
||||
pathNodes.Add(startPosition);
|
||||
//pathNodes.Add(new Vector2(minWidth * 3, Rand.Range(minWidth * 2, borders.Height - minWidth * 2, false)));
|
||||
|
||||
for (float x = startPosition.X; x < endPosition.X; x += Rand.Range(2000.0f, 10000.0f, false))
|
||||
pathNodes.Add(new Vector2(startPosition.X, borders.Height));
|
||||
pathNodes.Add(startPosition);
|
||||
|
||||
|
||||
for (float x = startPosition.X; x < endPosition.X; x += Rand.Range(5000.0f, 10000.0f, false))
|
||||
{
|
||||
pathNodes.Add(new Vector2(x, Rand.Range(pathBorders.Y, pathBorders.Bottom, false)));
|
||||
|
||||
@@ -171,8 +174,8 @@ namespace Barotrauma
|
||||
//}
|
||||
}
|
||||
|
||||
//pathNodes.Add(new Vector2(borders.Width - minWidth * 3, borders.Height / 2));
|
||||
pathNodes.Add(endPosition);
|
||||
pathNodes.Add(new Vector2(endPosition.X, borders.Height));
|
||||
|
||||
int smallTunnelCount = 5;
|
||||
|
||||
@@ -283,7 +286,8 @@ namespace Barotrauma
|
||||
// pathNodes.Reverse();
|
||||
//}
|
||||
|
||||
List<VoronoiCell> pathCells = GeneratePath(pathNodes, cells, pathBorders, minWidth, 0.3f, mirror, true);
|
||||
List<VoronoiCell> pathCells = GeneratePath(pathNodes, cells,
|
||||
new Rectangle(pathBorders.X, pathBorders.Y, pathBorders.Width, borders.Height), minWidth, 0.3f, mirror, true);
|
||||
|
||||
foreach (InterestingPosition positionOfInterest in positionsOfInterest)
|
||||
{
|
||||
@@ -291,8 +295,8 @@ namespace Barotrauma
|
||||
wayPoint.MoveWithLevel = true;
|
||||
}
|
||||
|
||||
startPosition = pathCells[0].Center;
|
||||
endPosition = pathCells[pathCells.Count - 1].Center;
|
||||
//startPosition = pathCells[0].Center;
|
||||
//endPosition = pathCells[pathCells.Count - 1].Center;
|
||||
|
||||
foreach (List<Vector2> tunnel in smallTunnels)
|
||||
{
|
||||
@@ -475,9 +479,7 @@ namespace Barotrauma
|
||||
pathCells.Add(currentCell);
|
||||
|
||||
int currentTargetIndex = 1;
|
||||
|
||||
wanderAmount = 0.0f;
|
||||
|
||||
|
||||
do
|
||||
{
|
||||
int edgeIndex = 0;
|
||||
@@ -617,30 +619,41 @@ namespace Barotrauma
|
||||
minDistance *= 0.5f;
|
||||
do
|
||||
{
|
||||
var closeCells = GetCells(position, 2);
|
||||
var closeCells = GetCells(position, 1);
|
||||
|
||||
foreach (VoronoiCell cell in closeCells)
|
||||
{
|
||||
if (!cell.edges.Any(e => Vector2.Distance(position, e.point1) < minDistance || Vector2.Distance(position, e.point2) < minDistance)) continue;
|
||||
bool tooClose = false;
|
||||
foreach (GraphEdge edge in cell.edges)
|
||||
{
|
||||
if (Math.Abs(position.X - edge.point1.X) < minDistance ||
|
||||
Math.Abs(position.Y - edge.point1.Y) < minDistance ||
|
||||
Math.Abs(position.X - edge.point2.X) < minDistance ||
|
||||
Math.Abs(position.Y - edge.point2.Y) < minDistance)
|
||||
{
|
||||
tooClose = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!tooCloseCells.Contains(cell)) tooCloseCells.Add(cell);
|
||||
if (tooClose && !tooCloseCells.Contains(cell)) tooCloseCells.Add(cell);
|
||||
}
|
||||
|
||||
//for (int x = -1; x <= 1; x++)
|
||||
//{
|
||||
// for (int y = -1; y <= 1; y++)
|
||||
// {
|
||||
// if (x == 0 && y == 0) continue;
|
||||
// Vector2 cornerPos = position + new Vector2(x * minDistance, y * minDistance);
|
||||
for (int x = -1; x <= 1; x++)
|
||||
{
|
||||
for (int y = -1; y <= 1; y++)
|
||||
{
|
||||
if (x == 0 && y == 0) continue;
|
||||
Vector2 cornerPos = position + new Vector2(x * minDistance, y * minDistance);
|
||||
|
||||
// int cellIndex = FindCellIndex(cornerPos);
|
||||
// if (cellIndex == -1) continue;
|
||||
// if (!tooCloseCells.Contains(cells[cellIndex]))
|
||||
// {
|
||||
// tooCloseCells.Add(cells[cellIndex]);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
int cellIndex = FindCellIndex(cornerPos);
|
||||
if (cellIndex == -1) continue;
|
||||
if (!tooCloseCells.Contains(cells[cellIndex]))
|
||||
{
|
||||
tooCloseCells.Add(cells[cellIndex]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
position += Vector2.Normalize(emptyCells[targetCellIndex].Center - position) * step;
|
||||
|
||||
@@ -664,7 +677,7 @@ namespace Barotrauma
|
||||
foreach (GraphEdge edge in cell.edges)
|
||||
{
|
||||
VoronoiCell adjacent = edge.AdjacentCell(cell);
|
||||
if (!newCells.Contains(adjacent)) newCells.Add(adjacent);
|
||||
if (adjacent!=null && !newCells.Contains(adjacent)) newCells.Add(adjacent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -964,7 +977,7 @@ namespace Barotrauma
|
||||
int tries = 0;
|
||||
do
|
||||
{
|
||||
Vector2 startPos = ConvertUnits.ToSimUnits(positionsOfInterest[Rand.Int(positionsOfInterest.Count, false)].Position);
|
||||
Vector2 startPos = ConvertUnits.ToSimUnits(Level.Loaded.GetRandomInterestingPosition(true, false));
|
||||
|
||||
Vector2 endPos = startPos - ConvertUnits.ToSimUnits(Vector2.UnitY * Size.Y);
|
||||
|
||||
@@ -989,20 +1002,21 @@ namespace Barotrauma
|
||||
return position;
|
||||
}
|
||||
|
||||
public Vector2 GetRandomInterestingPosition(bool requireSpace, bool useSyncedRand)
|
||||
public Vector2 GetRandomInterestingPosition(bool useSyncedRand, bool? preferLarge)
|
||||
{
|
||||
if (!positionsOfInterest.Any()) return Size * 0.5f;
|
||||
|
||||
if (requireSpace)
|
||||
if (preferLarge==null)
|
||||
{
|
||||
var positionsWithSpace = positionsOfInterest.FindAll(p => p.IsLarge);
|
||||
if (!positionsWithSpace.Any()) return Size * 0.5f;
|
||||
return positionsOfInterest[Rand.Int(positionsOfInterest.Count, !useSyncedRand)].Position;
|
||||
|
||||
return positionsWithSpace[Rand.Int(positionsOfInterest.Count, !useSyncedRand)].Position;
|
||||
}
|
||||
else
|
||||
{
|
||||
return positionsOfInterest[Rand.Int(positionsOfInterest.Count, !useSyncedRand)].Position;
|
||||
var positionsWithSpace = positionsOfInterest.FindAll(p => (bool)preferLarge == p.IsLarge);
|
||||
if (!positionsWithSpace.Any()) return Size * 0.5f;
|
||||
|
||||
return positionsWithSpace[Rand.Int(positionsOfInterest.Count, !useSyncedRand)].Position;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -524,6 +524,34 @@ namespace Barotrauma
|
||||
return loaded.SaveAs(SavePath+System.IO.Path.DirectorySeparatorChar+fileName);
|
||||
}
|
||||
|
||||
public void CheckForErrors()
|
||||
{
|
||||
if (!Hull.hullList.Any())
|
||||
{
|
||||
DebugConsole.ThrowError("No hulls found in the submarine. Hulls determine the ''borders'' of an individual room and are required for water and air distribution to work correctly.");
|
||||
}
|
||||
|
||||
foreach (Item item in Item.ItemList)
|
||||
{
|
||||
if (item.GetComponent<Barotrauma.Items.Components.Vent>() == null) continue;
|
||||
|
||||
if (!item.linkedTo.Any())
|
||||
{
|
||||
DebugConsole.ThrowError("The submarine contains vents which haven't been linked to an oxygen generator. Select a vent and click an oxygen generator while holding space to link them.");
|
||||
}
|
||||
}
|
||||
|
||||
if (WayPoint.WayPointList.Find(wp => !wp.MoveWithLevel && wp.SpawnType == SpawnType.Path) == null)
|
||||
{
|
||||
DebugConsole.ThrowError("No waypoints found in the submarine. AI controlled crew members won't be able to navigate without waypoints.");
|
||||
}
|
||||
|
||||
if (WayPoint.WayPointList.Find(wp => wp.SpawnType == SpawnType.Cargo) == null)
|
||||
{
|
||||
DebugConsole.ThrowError("The submarine doesn't have a waypoint marked as ''Cargo'', which are used for determining where to place bought items.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void Preload()
|
||||
{
|
||||
|
||||
@@ -669,7 +697,6 @@ namespace Barotrauma
|
||||
{
|
||||
DebugConsole.ThrowError("Could not find the method ''Load'' in " + t + ".", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
subBody = new SubmarineBody(this);
|
||||
|
||||
@@ -87,57 +87,67 @@ namespace Barotrauma
|
||||
{
|
||||
this.submarine = sub;
|
||||
|
||||
|
||||
List<Vector2> convexHull = GenerateConvexHull();
|
||||
HullVertices = convexHull;
|
||||
|
||||
for (int i = 0; i < convexHull.Count; i++)
|
||||
if (!Hull.hullList.Any())
|
||||
{
|
||||
convexHull[i] = ConvertUnits.ToSimUnits(convexHull[i]);
|
||||
|
||||
body = BodyFactory.CreateRectangle(GameMain.World, 1.0f, 1.0f, 1.0f);
|
||||
DebugConsole.ThrowError("WARNING: no hulls found, generating a physics body for the submarine failed.");
|
||||
}
|
||||
|
||||
convexHull.Reverse();
|
||||
|
||||
//get farseer 'vertices' from vectors
|
||||
Vertices shapevertices = new Vertices(convexHull);
|
||||
|
||||
AABB hullAABB = shapevertices.GetAABB();
|
||||
|
||||
Borders = new Rectangle(
|
||||
(int)ConvertUnits.ToDisplayUnits(hullAABB.LowerBound.X),
|
||||
(int)ConvertUnits.ToDisplayUnits(hullAABB.UpperBound.Y),
|
||||
(int)ConvertUnits.ToDisplayUnits(hullAABB.Extents.X * 2.0f),
|
||||
(int)ConvertUnits.ToDisplayUnits(hullAABB.Extents.Y * 2.0f));
|
||||
|
||||
//var triangulatedVertices = Triangulate.ConvexPartition(shapevertices, TriangulationAlgorithm.Bayazit);
|
||||
|
||||
body = BodyFactory.CreateBody(GameMain.World, this);
|
||||
|
||||
foreach (Hull hull in Hull.hullList)
|
||||
else
|
||||
{
|
||||
Rectangle rect = hull.Rect;
|
||||
foreach (Structure wall in Structure.WallList)
|
||||
List<Vector2> convexHull = GenerateConvexHull();
|
||||
HullVertices = convexHull;
|
||||
|
||||
for (int i = 0; i < convexHull.Count; i++)
|
||||
{
|
||||
if (!Submarine.RectsOverlap(wall.Rect, hull.Rect)) continue;
|
||||
|
||||
Rectangle wallRect = wall.IsHorizontal ?
|
||||
new Rectangle(hull.Rect.X, wall.Rect.Y, hull.Rect.Width, wall.Rect.Height) :
|
||||
new Rectangle(wall.Rect.X, hull.Rect.Y, wall.Rect.Width, hull.Rect.Height);
|
||||
|
||||
rect = Rectangle.Union(
|
||||
new Rectangle(wallRect.X, wallRect.Y-wallRect.Height, wallRect.Width, wallRect.Height),
|
||||
new Rectangle(rect.X, rect.Y - rect.Height, rect.Width, rect.Height));
|
||||
rect.Y = rect.Y + rect.Height;
|
||||
convexHull[i] = ConvertUnits.ToSimUnits(convexHull[i]);
|
||||
}
|
||||
|
||||
FixtureFactory.AttachRectangle(
|
||||
ConvertUnits.ToSimUnits(rect.Width),
|
||||
ConvertUnits.ToSimUnits(rect.Height),
|
||||
5.0f,
|
||||
ConvertUnits.ToSimUnits(new Vector2(rect.X + rect.Width/2, rect.Y - rect.Height/2)),
|
||||
body, this);
|
||||
convexHull.Reverse();
|
||||
|
||||
//get farseer 'vertices' from vectors
|
||||
Vertices shapevertices = new Vertices(convexHull);
|
||||
|
||||
AABB hullAABB = shapevertices.GetAABB();
|
||||
|
||||
Borders = new Rectangle(
|
||||
(int)ConvertUnits.ToDisplayUnits(hullAABB.LowerBound.X),
|
||||
(int)ConvertUnits.ToDisplayUnits(hullAABB.UpperBound.Y),
|
||||
(int)ConvertUnits.ToDisplayUnits(hullAABB.Extents.X * 2.0f),
|
||||
(int)ConvertUnits.ToDisplayUnits(hullAABB.Extents.Y * 2.0f));
|
||||
|
||||
//var triangulatedVertices = Triangulate.ConvexPartition(shapevertices, TriangulationAlgorithm.Bayazit);
|
||||
|
||||
body = BodyFactory.CreateBody(GameMain.World, this);
|
||||
|
||||
foreach (Hull hull in Hull.hullList)
|
||||
{
|
||||
Rectangle rect = hull.Rect;
|
||||
foreach (Structure wall in Structure.WallList)
|
||||
{
|
||||
if (!Submarine.RectsOverlap(wall.Rect, hull.Rect)) continue;
|
||||
|
||||
Rectangle wallRect = wall.IsHorizontal ?
|
||||
new Rectangle(hull.Rect.X, wall.Rect.Y, hull.Rect.Width, wall.Rect.Height) :
|
||||
new Rectangle(wall.Rect.X, hull.Rect.Y, wall.Rect.Width, hull.Rect.Height);
|
||||
|
||||
rect = Rectangle.Union(
|
||||
new Rectangle(wallRect.X, wallRect.Y - wallRect.Height, wallRect.Width, wallRect.Height),
|
||||
new Rectangle(rect.X, rect.Y - rect.Height, rect.Width, rect.Height));
|
||||
rect.Y = rect.Y + rect.Height;
|
||||
}
|
||||
|
||||
FixtureFactory.AttachRectangle(
|
||||
ConvertUnits.ToSimUnits(rect.Width),
|
||||
ConvertUnits.ToSimUnits(rect.Height),
|
||||
5.0f,
|
||||
ConvertUnits.ToSimUnits(new Vector2(rect.X + rect.Width / 2, rect.Y - rect.Height / 2)),
|
||||
body, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
body.BodyType = BodyType.Dynamic;
|
||||
body.CollisionCategories = Physics.CollisionMisc | Physics.CollisionWall;
|
||||
body.CollidesWith = Physics.CollisionLevel | Physics.CollisionCharacter;
|
||||
@@ -275,7 +285,7 @@ namespace Barotrauma
|
||||
volume += hull.FullVolume;
|
||||
}
|
||||
|
||||
float waterPercentage = waterVolume / volume;
|
||||
float waterPercentage = volume==0.0f ? 0.0f : waterVolume / volume;
|
||||
|
||||
float neutralPercentage = 0.07f;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user