Infinite wall fixes, pressure damage to sub, sub/mode voting & randomization working now, better ui scaling

This commit is contained in:
Regalis
2015-10-31 00:29:51 +02:00
parent dc4b502248
commit bcc96cee97
33 changed files with 1068 additions and 151 deletions

View File

@@ -65,6 +65,11 @@ namespace Barotrauma
private set;
}
public Vector2 Size
{
get { return new Vector2(borders.Width, borders.Height); }
}
public Vector2 EndPosition
{
get { return endPosition; }
@@ -277,7 +282,7 @@ namespace Barotrauma
var newPathCells = GeneratePath(new List<Vector2> { start, end }, cells, pathBorders, 0.0f, 0.8f, mirror);
for (int n = 0; n < newPathCells.Count-5; n += 3)
for (int n = 0; n < newPathCells.Count; n += 5)
{
positionsOfInterest.Add(newPathCells[n].Center);
}
@@ -297,9 +302,13 @@ namespace Barotrauma
// GeneratePath(rand, tunnelStart, new Vector2(tunnelStart.X, borders.Height), cells, pathBorders, minWidth, 0.1f, mirror)
// );
//}
cells = CleanCells(pathCells);
cells = CleanCells(pathCells);
pathCells.AddRange(CreateBottomHoles(1.0f, new Rectangle(
(int)(borders.Width * 0.2f), 0,
(int)(borders.Width * 0.6f), (int)(borders.Height * 0.3f))));
foreach (VoronoiCell cell in pathCells)
{
cells.Remove(cell);
@@ -344,6 +353,17 @@ namespace Barotrauma
}
}
for (int i = 0; i < 2; i++)
{
Body shaftBody = BodyFactory.CreateRectangle(GameMain.World, 100.0f, 10.0f, 5.0f);
shaftBody.BodyType = BodyType.Kinematic;
shaftBody.CollisionCategories = Physics.CollisionLevel;
shaftBody.SetTransform(ConvertUnits.ToSimUnits((i == 0) ? startPosition : endPosition), 0.0f);
shaftBody.SleepingAllowed = false;
bodies.Add(shaftBody);
}
foreach (VoronoiCell cell in cells)
{
foreach (GraphEdge edge in cell.edges)
@@ -381,6 +401,7 @@ namespace Barotrauma
//lower values will cause the path to "wander" more, higher will make it head straight to the end
wanderAmount = MathHelper.Clamp(wanderAmount, 0.0f, 1.0f);
List<GraphEdge> allowedEdges = new List<GraphEdge>();
List<VoronoiCell> pathCells = new List<VoronoiCell>();
VoronoiCell[] targetCells = new VoronoiCell[points.Count];
@@ -398,12 +419,21 @@ namespace Barotrauma
{
int edgeIndex = 0;
allowedEdges.Clear();
foreach (GraphEdge edge in currentCell.edges)
{
if (!limits.Contains(edge.AdjacentCell(currentCell).Center)) continue;
allowedEdges.Add(edge);
}
//steer towards target
if (Rand.Range(0.0f, 1.0f, false) > wanderAmount)
if (Rand.Range(0.0f, 1.0f, false) > wanderAmount || allowedEdges.Count == 0)
{
for (int i = 0; i < currentCell.edges.Count; i++)
{
if (!MathUtils.LinesIntersect(currentCell.Center, targetCells[currentTargetIndex].Center, currentCell.edges[i].point1, currentCell.edges[i].point2)) continue;
if (!MathUtils.LinesIntersect(currentCell.Center, targetCells[currentTargetIndex].Center,
currentCell.edges[i].point1, currentCell.edges[i].point2)) continue;
edgeIndex = i;
break;
}
@@ -411,24 +441,18 @@ namespace Barotrauma
//choose random edge (ignoring ones where the adjacent cell is outside limits)
else
{
List<GraphEdge> allowedEdges = new List<GraphEdge>();
foreach (GraphEdge edge in currentCell.edges)
{
if (!limits.Contains(edge.AdjacentCell(currentCell).Center)) continue;
allowedEdges.Add(edge);
}
if (allowedEdges.Count==0)
{
edgeIndex = Rand.Int(currentCell.edges.Count, false);
}
else
{
//if (allowedEdges.Count==0)
//{
// edgeIndex = Rand.Int(currentCell.edges.Count, false);
//}
//else
//{
edgeIndex = Rand.Int(allowedEdges.Count, false);
if (mirror && edgeIndex > 0) edgeIndex = allowedEdges.Count - edgeIndex;
edgeIndex = currentCell.edges.IndexOf(allowedEdges[edgeIndex]);
}
//}
}
currentCell = currentCell.edges[edgeIndex].AdjacentCell(currentCell);
@@ -495,6 +519,26 @@ namespace Barotrauma
return pathCells;
}
private List<VoronoiCell> CreateBottomHoles(float holeProbability, Rectangle limits)
{
List<VoronoiCell> toBeRemoved = new List<VoronoiCell>();
foreach (VoronoiCell cell in cells)
{
if (Rand.Range(0.0f, 1.0f, false) > holeProbability) continue;
if (!limits.Contains(cell.Center)) continue;
toBeRemoved.Add(cell);
}
return toBeRemoved;
//foreach (VoronoiCell cell in toBeRemoved)
//{
// cells.Remove(cell);
//}
}
private List<VoronoiCell> GetTooCloseCells(List<VoronoiCell> emptyCells, float minDistance)
{
List<VoronoiCell> tooCloseCells = new List<VoronoiCell>();
@@ -671,17 +715,7 @@ namespace Barotrauma
bodies.Add(edgeBody);
}
for (int i = 0; i < 2; i++ )
{
Body shaftBody = BodyFactory.CreateRectangle(GameMain.World, 100.0f, 10.0f, 5.0f);
shaftBody.BodyType = BodyType.Kinematic;
shaftBody.CollisionCategories = Physics.CollisionLevel;
shaftBody.SetTransform(ConvertUnits.ToSimUnits((i==0) ? startPosition : endPosition), 0.0f);
shaftBody.SleepingAllowed = false;
bodies.Add(shaftBody);
}
return verticeList.ToArray();
return verticeList.ToArray();
}
public void SetPosition(Vector2 pos)
@@ -918,7 +952,7 @@ namespace Barotrauma
for (int i = 0; i < 2; i++)
{
basicEffect.World = Matrix.CreateTranslation(new Vector3(Position + wrappingWalls[side, i].Offset, 0.0f)) * cam.ShaderTransform
* Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 1) * 0.5f;
* Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 1) * 0.5f;
basicEffect.CurrentTechnique.Passes[0].Apply();

View File

@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using FarseerPhysics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
@@ -12,7 +13,7 @@ namespace Barotrauma
class WrappingWall
{
const float wallWidth = 10000.0f;
const float wallWidth = 20000.0f;
public VertexPositionTexture[] Vertices;
@@ -60,7 +61,7 @@ namespace Barotrauma
}
}
Vector2 wallSectionSize = new Vector2(2000.0f, 2000.0f);
Vector2 wallSectionSize = new Vector2(2300.0f, 2300.0f);
Vector2 startPos = (dir < 0) ?
edgeCell.Center + Vector2.UnitX * wallWidth * dir :
edgeCell.Center + wallWidth * Vector2.UnitX * (dir - 1);
@@ -77,7 +78,7 @@ namespace Barotrauma
float normalizedDist = distFromEdge / (wallWidth / 2);
float variance = 1000.0f * normalizedDist;
bottomVertices.Add(center + new Vector2(Rand.Range(-variance, variance, false), Rand.Range(-variance, variance, false)*5.0f));
bottomVertices.Add(center + new Vector2(Rand.Range(-variance, variance, false), Rand.Range(-variance, variance, false)*2.0f));
}
for (int i = 1; i < bottomVertices.Count; i++)
@@ -127,6 +128,22 @@ namespace Barotrauma
walls[0, 0] = walls[0, 1];
walls[0, 1] = temp;
}
else if (pos.X > walls[1, 1].midPos.X && walls[1,0].midPos.X < pos.X)
{
walls[1, 0].Shift(2);
var temp = walls[1, 0];
walls[1, 0] = walls[1, 1];
walls[1, 1] = temp;
}
else if (pos.X < walls[1, 0].midPos.X && walls[1, 1].midPos.X > pos.X && walls[1, 1].slot > 0)
{
walls[1, 1].Shift(-2);
var temp = walls[0, 0];
walls[1, 0] = walls[1, 1];
walls[1, 1] = temp;
}
}
public void Shift(int amount)
@@ -134,9 +151,11 @@ namespace Barotrauma
slot += amount;
Vector2 moveAmount = Vector2.UnitX * wallWidth * amount;
Vector2 simMoveAmount = ConvertUnits.ToSimUnits(moveAmount);
foreach (VoronoiCell cell in cells)
{
cell.body.SetTransform(cell.body.Position + moveAmount, 0.0f);
cell.body.SetTransform(cell.body.Position + simMoveAmount, 0.0f);
}
midPos += moveAmount;

View File

@@ -16,6 +16,9 @@ namespace Barotrauma
{
class SubmarineBody
{
const float DamageDepth = 0.0f;
const float PressureDamageMultiplier = 0.001f;
//structure damage = impact * damageMultiplier
const float DamageMultiplier = 50.0f;
@@ -27,6 +30,8 @@ namespace Barotrauma
private set;
}
private float depthDamageTimer;
private Submarine sub;
private Body body;
@@ -207,6 +212,8 @@ namespace Barotrauma
ApplyForce(totalForce);
UpdateDepthDamage(deltaTime);
//hullBodies[0].body.LinearVelocity = -hullBodies[0].body.Position;
//hullBody.SetTransform(Vector2.Zero , 0.0f);
@@ -240,6 +247,48 @@ namespace Barotrauma
Speed += force / mass;
}
private void UpdateDepthDamage(float deltaTime)
{
if (sub.Position.Y > DamageDepth) return;
float depth = DamageDepth - sub.Position.Y;
depth = Math.Max(depth, -40000.0f);
// float prevTimer = depthDamageTimer;
depthDamageTimer -= deltaTime*depth*PressureDamageMultiplier;
//if (prevTimer>5.0f && depthDamageTimer<=5.0f)
//{
// SoundPlayer.PlayDamageSound(DamageSoundType.Pressure, 50.0f,);
//}
if (depthDamageTimer > 0.0f) return;
Vector2 damagePos = Vector2.Zero;
if (Rand.Int(2)==0)
{
damagePos = new Vector2(
(Rand.Int(2) == 0) ? Borders.X : Borders.X+Borders.Width,
Rand.Range(Borders.Y - Borders.Height, Borders.Y));
}
else
{
damagePos = new Vector2(
Rand.Range(Borders.X, Borders.X + Borders.Width),
(Rand.Int(2) == 0) ? Borders.Y : Borders.Y - Borders.Height);
}
SoundPlayer.PlayDamageSound(DamageSoundType.Pressure, 50.0f, damagePos, 5000.0f);
GameMain.GameScreen.Cam.Shake = depth * PressureDamageMultiplier * 0.1f;
Explosion.RangedStructureDamage(damagePos, depth * PressureDamageMultiplier * 50.0f, depth * PressureDamageMultiplier);
//SoundPlayer.PlayDamageSound(DamageSoundType.StructureBlunt, Rand.Range(0.0f, 100.0f), damagePos, 5000.0f);
depthDamageTimer = 10.0f;
}
private void UpdateColliding()
{
if (body.Position.LengthSquared()<0.00001f) return;

View File

@@ -226,7 +226,6 @@ namespace Barotrauma
//try to give the crew member a spawnpoint that hasn't been assigned to anyone and matches their job
for (int n = 0; n < unassignedWayPoints.Count; n++)
{
if (crew[i].Job.Prefab != unassignedWayPoints[n].assignedJob) continue;
assignedWayPoints[i] = unassignedWayPoints[n];
unassignedWayPoints.RemoveAt(n);