Ruin and seafloor mirroring works now

This commit is contained in:
Joonas Rikkonen
2018-07-27 13:01:04 +03:00
parent aa5b2a973e
commit 3b4a6c0081
2 changed files with 50 additions and 23 deletions
@@ -397,10 +397,12 @@ namespace Barotrauma
// remove unnecessary cells and create some holes at the bottom of the level // remove unnecessary cells and create some holes at the bottom of the level
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
System.Diagnostics.Debug.WriteLine("cellcount before cleaning: " + cells.Count);
cells = CleanCells(pathCells); cells = CleanCells(pathCells);
pathCells.AddRange(CreateBottomHoles(generationParams.BottomHoleProbability, new Rectangle( pathCells.AddRange(CreateBottomHoles(generationParams.BottomHoleProbability, new Rectangle(
(int)(borders.Width * 0.2f), 0, (int)(borders.Width * 0.2f), 0,
(int)(borders.Width * 0.6f), (int)(borders.Height * 0.8f)))); (int)(borders.Width * 0.6f), (int)(borders.Height * 0.8f))));
System.Diagnostics.Debug.WriteLine("cellcount after bottom holes: " + cells.Count);
foreach (VoronoiCell cell in cells) foreach (VoronoiCell cell in cells)
{ {
@@ -412,6 +414,7 @@ namespace Barotrauma
// initialize the cells that are still left and insert them into the cell grid // initialize the cells that are still left and insert them into the cell grid
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
System.Diagnostics.Debug.WriteLine("pathcells before init: " + cells.Count);
foreach (VoronoiCell cell in pathCells) foreach (VoronoiCell cell in pathCells)
{ {
cell.edges.ForEach(e => e.OutsideLevel = false); cell.edges.ForEach(e => e.OutsideLevel = false);
@@ -432,11 +435,15 @@ namespace Barotrauma
// mirror if needed // mirror if needed
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
System.Diagnostics.Debug.WriteLine("cellcount: "+cells.Count);
System.Diagnostics.Debug.WriteLine("pathcellcount: " + pathCells.Count);
if (mirror) if (mirror)
{ {
HashSet<GraphEdge> mirroredEdges = new HashSet<GraphEdge>(); HashSet<GraphEdge> mirroredEdges = new HashSet<GraphEdge>();
HashSet<Site> mirroredSites = new HashSet<Site>(); HashSet<Site> mirroredSites = new HashSet<Site>();
foreach (VoronoiCell cell in cells) List<VoronoiCell> allCells = new List<VoronoiCell>(cells);
allCells.AddRange(pathCells);
foreach (VoronoiCell cell in allCells)
{ {
foreach (GraphEdge edge in cell.edges) foreach (GraphEdge edge in cell.edges)
{ {
@@ -500,7 +507,7 @@ namespace Barotrauma
} }
int testSync = Rand.Int(1000, Rand.RandSync.Server); int testSync = Rand.Int(1000, Rand.RandSync.Server);
DebugConsole.NewMessage("TESTSYNC: " + testSync + " ---------------------------------------------",Color.White); System.Diagnostics.Debug.WriteLine("TESTSYNC: " + testSync + " ---------------------------------------------",Color.White);
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// generate the bodies and rendered triangles of the cells // generate the bodies and rendered triangles of the cells
@@ -529,7 +536,7 @@ namespace Barotrauma
bodies.Add(TopBarrier); bodies.Add(TopBarrier);
GenerateSeaFloor(); GenerateSeaFloor(mirror);
backgroundSpriteManager.PlaceSprites(this, generationParams.BackgroundSpriteAmount); backgroundSpriteManager.PlaceSprites(this, generationParams.BackgroundSpriteAmount);
#if CLIENT #if CLIENT
@@ -728,7 +735,7 @@ namespace Barotrauma
return newCells; return newCells;
} }
private void GenerateSeaFloor() private void GenerateSeaFloor(bool mirror)
{ {
BottomPos = generationParams.SeaFloorDepth; BottomPos = generationParams.SeaFloorDepth;
SeaFloorTopPos = BottomPos; SeaFloorTopPos = BottomPos;
@@ -751,7 +758,7 @@ namespace Barotrauma
{ {
for (int i = 0; i < bottomPositions.Count - 1; i++) for (int i = 0; i < bottomPositions.Count - 1; i++)
{ {
bottomPositions.Insert(i+1, bottomPositions.Insert(i + 1,
(bottomPositions[i] + bottomPositions[i + 1]) / 2.0f + (bottomPositions[i] + bottomPositions[i + 1]) / 2.0f +
Vector2.UnitY * Rand.Range(0.0f, generationParams.SeaFloorVariance, Rand.RandSync.Server)); Vector2.UnitY * Rand.Range(0.0f, generationParams.SeaFloorVariance, Rand.RandSync.Server));
@@ -761,6 +768,14 @@ namespace Barotrauma
currInverval /= 2.0f; currInverval /= 2.0f;
} }
if (mirror)
{
for (int i = 0; i < bottomPositions.Count; i++)
{
bottomPositions[i] = new Vector2(borders.Size.X - bottomPositions[i].X, bottomPositions[i].Y);
}
}
SeaFloorTopPos = bottomPositions.Max(p => p.Y); SeaFloorTopPos = bottomPositions.Max(p => p.Y);
extraWalls = new LevelWall[] { new LevelWall(bottomPositions, new Vector2(0.0f, -2000.0f), backgroundColor, this) }; extraWalls = new LevelWall[] { new LevelWall(bottomPositions, new Vector2(0.0f, -2000.0f), backgroundColor, this) };
@@ -878,6 +893,10 @@ namespace Barotrauma
float ruinRadius = Math.Max(ruinSize.X, ruinSize.Y) * 0.5f; float ruinRadius = Math.Max(ruinSize.X, ruinSize.Y) * 0.5f;
System.Diagnostics.Debug.WriteLine("Cell count " + cells.Count); System.Diagnostics.Debug.WriteLine("Cell count " + cells.Count);
for (int i = 0; i<cells.Count && i < 100; i++)
{
System.Diagnostics.Debug.WriteLine(" " + i + ": " + cells[i].Center);
}
int cellIndex = Rand.Int(cells.Count, Rand.RandSync.Server); int cellIndex = Rand.Int(cells.Count, Rand.RandSync.Server);
System.Diagnostics.Debug.WriteLine("Cell index " + cellIndex); System.Diagnostics.Debug.WriteLine("Cell index " + cellIndex);
Vector2 ruinPos = cells[cellIndex].Center; Vector2 ruinPos = cells[cellIndex].Center;
@@ -939,9 +958,14 @@ namespace Barotrauma
} }
System.Diagnostics.Debug.WriteLine("Final ruin pos: " + ruinPos); System.Diagnostics.Debug.WriteLine("Final ruin pos: " + ruinPos);
int testSync = Rand.Int(1000, Rand.RandSync.Server);
System.Diagnostics.Debug.WriteLine("TESTSYNC2: " + testSync + " ---------------------------------------------", Color.White);
var ruin = new Ruin(closestPathCell, cells, new Rectangle(MathUtils.ToPoint(ruinPos - ruinSize * 0.5f), MathUtils.ToPoint(ruinSize)), mirror); var ruin = new Ruin(closestPathCell, cells, new Rectangle(MathUtils.ToPoint(ruinPos - ruinSize * 0.5f), MathUtils.ToPoint(ruinSize)), mirror);
ruins.Add(ruin); ruins.Add(ruin);
testSync = Rand.Int(1000, Rand.RandSync.Server);
System.Diagnostics.Debug.WriteLine("TESTSYNC3: " + testSync + " ---------------------------------------------", Color.White);
ruin.RuinShapes.Sort((shape1, shape2) => shape2.DistanceFromEntrance.CompareTo(shape1.DistanceFromEntrance)); ruin.RuinShapes.Sort((shape1, shape2) => shape2.DistanceFromEntrance.CompareTo(shape1.DistanceFromEntrance));
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
@@ -1091,14 +1115,11 @@ namespace Barotrauma
List<VoronoiCell> cells = new List<VoronoiCell>(); List<VoronoiCell> cells = new List<VoronoiCell>();
for (int x = startX; x <= endX; x++) for (int y = startY; y <= endY; y++)
{ {
for (int y = startY; y <= endY; y++) for (int x = startX; x <= endX; x++)
{ {
foreach (VoronoiCell cell in cellGrid[x, y]) foreach (VoronoiCell cell in cellGrid[x, y]) cells.Add(cell);
{
cells.Add(cell);
}
} }
} }
@@ -1,6 +1,7 @@
using FarseerPhysics; using FarseerPhysics;
using FarseerPhysics.Factories; using FarseerPhysics.Factories;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
@@ -35,7 +36,7 @@ namespace Barotrauma.RuinGeneration
public Alignment GetLineAlignment(Line line) public Alignment GetLineAlignment(Line line)
{ {
if (line.A.Y == line.B.Y) if (line.IsHorizontal)
{ {
if (line.A.Y > rect.Center.Y && line.B.Y > rect.Center.Y) if (line.A.Y > rect.Center.Y && line.B.Y > rect.Center.Y)
{ {
@@ -70,7 +71,7 @@ namespace Barotrauma.RuinGeneration
foreach (Line line in Walls) foreach (Line line in Walls)
{ {
if (line.A.X == line.B.X) //vertical line if (!line.IsHorizontal) //vertical line
{ {
//line doesn't intersect the rectangle //line doesn't intersect the rectangle
if (rectangle.X > line.A.X || rectangle.Right < line.A.X || if (rectangle.X > line.A.X || rectangle.Right < line.A.X ||
@@ -100,7 +101,7 @@ namespace Barotrauma.RuinGeneration
newLines.Add(new Line(new Vector2(line.A.X, rectangle.Bottom), line.B, line.Type)); newLines.Add(new Line(new Vector2(line.A.X, rectangle.Bottom), line.B, line.Type));
} }
} }
else if (line.A.Y == line.B.Y) //horizontal line else
{ {
//line doesn't intersect the rectangle //line doesn't intersect the rectangle
if (rectangle.X > line.B.X || rectangle.Right < line.A.X || if (rectangle.X > line.B.X || rectangle.Right < line.A.X ||
@@ -130,11 +131,6 @@ namespace Barotrauma.RuinGeneration
newLines.Add(new Line(new Vector2(rectangle.Right, line.A.Y), line.B, line.Type)); newLines.Add(new Line(new Vector2(rectangle.Right, line.A.Y), line.B, line.Type));
} }
} }
else
{
DebugConsole.ThrowError("Error in StructureGenerator.SplitLines - lines must be axis aligned");
}
} }
Walls = newLines; Walls = newLines;
@@ -164,6 +160,11 @@ namespace Barotrauma.RuinGeneration
public readonly RuinStructureType Type; public readonly RuinStructureType Type;
public bool IsHorizontal
{
get { return Math.Abs(A.Y - B.Y) < Math.Abs(A.X - B.X); }
}
public Line(Vector2 a, Vector2 b, RuinStructureType type) public Line(Vector2 a, Vector2 b, RuinStructureType type)
{ {
Debug.Assert(a.X <= b.X); Debug.Assert(a.X <= b.X);
@@ -260,7 +261,12 @@ namespace Barotrauma.RuinGeneration
float shortestDistance = 0.0f; float shortestDistance = 0.0f;
foreach (BTRoom leaf in rooms) foreach (BTRoom leaf in rooms)
{ {
float distance = Vector2.Distance(leaf.Rect.Center.ToVector2(), closestPathCell.Center); Vector2 leafPos = leaf.Rect.Center.ToVector2();
if (mirror)
{
leafPos.X = area.Center.X + (area.Center.X - leafPos.X);
}
float distance = Vector2.Distance(leafPos, closestPathCell.Center);
if (entranceRoom == null || distance < shortestDistance) if (entranceRoom == null || distance < shortestDistance)
{ {
entranceRoom = leaf; entranceRoom = leaf;