Giving crew members an ID card with clearances based on spawnpoint, level collision bugfixes, level exit/enter "shafts", moar entity ID bugfixes

This commit is contained in:
Regalis
2015-07-09 20:33:53 +03:00
parent 2254585dac
commit 257835e609
25 changed files with 279 additions and 204 deletions

View File

@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Xml.Linq;
using FarseerPhysics;
using FarseerPhysics;
using FarseerPhysics.Dynamics.Joints;
using Lidgren.Network;
using Microsoft.Xna.Framework;
@@ -11,6 +6,11 @@ using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Subsurface.Networking;
using Subsurface.Particles;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Xml.Linq;
namespace Subsurface
{
@@ -37,7 +37,7 @@ namespace Subsurface
public double LastNetworkUpdate;
public byte LargeUpdateTimer;
public float LargeUpdateTimer;
public readonly Dictionary<string, ObjectProperty> Properties;
public Dictionary<string, ObjectProperty> ObjectProperties
@@ -367,7 +367,7 @@ namespace Subsurface
CharacterList.Add(this);
}
public void GiveJobItems()
public void GiveJobItems(WayPoint spawnPoint)
{
if (Info == null || Info.Job == null) return;
@@ -382,6 +382,15 @@ namespace Subsurface
Item item = new Item(itemPrefab, Position);
inventory.TryPutItem(item, item.AllowedSlots, false);
if (item.Prefab.Name == "ID Card" && spawnPoint!=null)
{
foreach (string s in spawnPoint.IdCardTags)
{
item.AddTag(s);
}
}
}
}
@@ -893,10 +902,7 @@ namespace Subsurface
message.Write(cursorPosition.X);
message.Write(cursorPosition.Y);
message.Write(AnimController.limbs.Count());
message.Write(LargeUpdateTimer <= 0);
if (LargeUpdateTimer<=0)
@@ -904,7 +910,6 @@ namespace Subsurface
int i = 0;
foreach (Limb limb in AnimController.limbs)
{
message.Write(42.0f+i);
message.Write(limb.body.Position.X);
message.Write(limb.body.Position.Y);
@@ -926,7 +931,7 @@ namespace Subsurface
message.Write(torso.body.Position.X);
message.Write(torso.body.Position.Y);
LargeUpdateTimer = (byte)Math.Max(0, LargeUpdateTimer-1);
LargeUpdateTimer = Math.Max(0, LargeUpdateTimer-1);
}
@@ -964,11 +969,6 @@ namespace Subsurface
return;
}
//if (type == Networking.NetworkEventType.KeyHit)
//{
// selectKeyHit.State = message.ReadBoolean();
//}
actionKeyDown.State = message.ReadBoolean();
secondaryKeyDown.State = message.ReadBoolean();
@@ -987,14 +987,10 @@ namespace Subsurface
cursorPos.X = message.ReadFloat();
cursorPos.Y = message.ReadFloat();
int num1 = message.ReadInt32();
System.Diagnostics.Debug.WriteLine(num1);
if (sendingTime <= LastNetworkUpdate) return;
cursorPosition = cursorPos;
AnimController.TargetMovement= targetMovement;
AnimController.TargetDir = (targetDir) ? Direction.Right : Direction.Left;
@@ -1002,8 +998,6 @@ namespace Subsurface
{
foreach (Limb limb in AnimController.limbs)
{
float num = message.ReadFloat();
System.Diagnostics.Debug.WriteLine(num);
Vector2 pos = Vector2.Zero;
pos.X = message.ReadFloat();
pos.Y = message.ReadFloat();
@@ -1013,9 +1007,7 @@ namespace Subsurface
vel.Y = message.ReadFloat();
float rotation = message.ReadFloat();
float angularVel = message.ReadFloat();
float angularVel = message.ReadFloat();
if (vel != Vector2.Zero && vel.Length() > 100.0f) { }

View File

@@ -388,7 +388,7 @@ namespace Subsurface
}
public void Draw(SpriteBatch spriteBatch, bool debugDraw)
public void Draw(SpriteBatch spriteBatch)
{
Color color = Color.White;// new Color(1.0f, 1.0f - damage / maxHealth, 1.0f - damage / maxHealth);
@@ -405,7 +405,7 @@ namespace Subsurface
1.0f, spriteEffect);
}
if (!debugDraw) return;
if (!Game1.DebugDraw) return;
if (pullJoint!=null)
{

View File

@@ -15,8 +15,6 @@ namespace Subsurface
{
public static List<Ragdoll> list = new List<Ragdoll>();
public static bool DebugDraw = false;
protected Hull currentHull;
public Limb[] limbs;
@@ -308,10 +306,10 @@ namespace Subsurface
foreach (Limb limb in limbs)
{
limb.Draw(spriteBatch, DebugDraw);
limb.Draw(spriteBatch);
}
if (!DebugDraw) return;
if (!Game1.DebugDraw) return;
foreach (Limb limb in limbs)
{

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 KiB

View File

@@ -242,8 +242,9 @@ namespace Subsurface
new GUIMessageBox(commands[1], commands[2]);
break;
case "debugdraw":
Hull.DebugDraw = !Hull.DebugDraw;
Ragdoll.DebugDraw = !Ragdoll.DebugDraw;
//Hull.DebugDraw = !Hull.DebugDraw;
//Ragdoll.DebugDraw = !Ragdoll.DebugDraw;
Game1.DebugDraw = !Game1.DebugDraw;
break;
default:
NewMessage("Command not found", Color.Red);

View File

@@ -16,6 +16,8 @@ namespace Subsurface
static int graphicsWidth, graphicsHeight;
static SpriteBatch spriteBatch;
public static bool DebugDraw;
public static GraphicsDevice CurrGraphicsDevice;
public static FrameCounter frameCounter;

View File

@@ -121,15 +121,15 @@ namespace Subsurface
for (int i = 0; i < waypoints.Length; i++)
{
WayPoint randomWayPoint = WayPoint.GetRandom(SpawnType.Human);
Vector2 position = (randomWayPoint == null) ? Vector2.Zero : randomWayPoint.SimPosition;
//WayPoint randomWayPoint = WayPoint.GetRandom(SpawnType.Human);
//Vector2 position = (randomWayPoint == null) ? Vector2.Zero : randomWayPoint.SimPosition;
Character character = new Character(characterInfos[i], waypoints[i]);
Character.Controlled = character;
if (!character.Info.StartItemsGiven)
{
character.GiveJobItems();
character.GiveJobItems(waypoints[i]);
character.Info.StartItemsGiven = true;
}

View File

@@ -120,7 +120,7 @@ namespace Subsurface
public void StartShift(TimeSpan duration, Level level)
{
//if (crewManager.characterInfos.Count == 0) return;
Lights.LightManager.FowEnabled = (Game1.Server==null);
this.level = level;
@@ -131,10 +131,9 @@ namespace Subsurface
if (level != null)
{
level.Generate(submarine == null ? 100.0f : Math.Max(Submarine.Borders.Width, Submarine.Borders.Height));
submarine.SetPosition(level.StartPosition);
submarine.SetPosition(level.StartPosition - new Vector2(0.0f, 2000.0f));
}
//crewManager.StartShift();
taskManager.StartShift(level);
}

View File

@@ -56,8 +56,7 @@ namespace Subsurface.Items.Components
float scale = 0.01f;
List<Vector2[]> edges = Level.Loaded.GetCellEdges(-Level.Loaded.Position, 5);
Vector2 offset = Vector2.Zero; //Level.Loaded.position;
//offset.Y = -offset.Y;
Vector2 offset = Vector2.Zero;
for (int i = 0; i < edges.Count; i++)
{

View File

@@ -144,6 +144,11 @@ namespace Subsurface
get { return prefab.IsLinkable; }
}
public override string ToString()
{
return Name +"("+ID+")";
}
public List<IPropertyObject> AllPropertyObjects
{
get
@@ -322,6 +327,11 @@ namespace Subsurface
return CurrentHull;
}
public void AddTag(string tag)
{
if (tags.Contains(tag)) return;
tags.Add(tag);
}
public bool HasTag(string tag)
{

View File

@@ -7,7 +7,7 @@ namespace Subsurface
{
class Entity
{
public static Dictionary<int, Entity> dictionary = new Dictionary<int, Entity>();
private static Dictionary<int, Entity> dictionary = new Dictionary<int, Entity>();
private int id;
@@ -20,7 +20,11 @@ namespace Subsurface
get { return id; }
set
{
dictionary.Remove(id);
Entity thisEntity;
if (dictionary.TryGetValue(id, out thisEntity) && thisEntity == this)
{
dictionary.Remove(id);
}
//if there's already an entity with the same ID, give it the old ID of this one
Entity existingEntity;
if (dictionary.TryGetValue(value, out existingEntity))
@@ -76,6 +80,7 @@ namespace Subsurface
{
e.Remove();
}
dictionary.Clear();
}
public virtual void Remove()

View File

@@ -17,9 +17,7 @@ namespace Subsurface
public static bool EditWater;
public static WaterRenderer renderer;
public static bool DebugDraw;
public const float OxygenDistributionSpeed = 500.0f;
public const float OxygenDetoriationSpeed = 0.3f;
public const float OxygenConsumptionSpeed = 1000.0f;
@@ -277,7 +275,7 @@ namespace Subsurface
public override void Draw(SpriteBatch spriteBatch, bool editing)
{
if (!editing && !DebugDraw) return;
if (!editing && !Game1.DebugDraw) return;
GUI.DrawRectangle(spriteBatch,
new Vector2(rect.X, -rect.Y),

View File

@@ -21,6 +21,8 @@ namespace Subsurface
static Level loaded;
private static Texture2D shaftTexture;
private string seed;
private int siteInterval;
@@ -41,6 +43,8 @@ namespace Subsurface
private Rectangle borders;
private List<Body> bodies = new List<Body>();
public Vector2 StartPosition
{
get { return startPosition; }
@@ -58,6 +62,8 @@ namespace Subsurface
public Level(string seed, int width, int height, int siteInterval)
{
if (shaftTexture == null) shaftTexture = Game1.textureLoader.FromFile("Content/Map/shaft.png");
this.seed = seed;
this.siteInterval = siteInterval;
@@ -79,8 +85,6 @@ namespace Subsurface
Stopwatch sw = new Stopwatch();
sw.Start();
//Game1.random = new Random(ToolBox.SeedToInt(seed));
if (loaded != null)
{
loaded.Unload();
@@ -92,8 +96,6 @@ namespace Subsurface
List<Vector2> sites = new List<Vector2>();
int aa = seed.GetHashCode();
Random rand = new Random(seed.GetHashCode());
float siteVariance = siteInterval * 0.8f;
@@ -177,6 +179,8 @@ namespace Subsurface
wayPoint.SpawnType = SpawnType.Enemy;
}
startPosition = pathCells[0].Center;
endPosition = pathCells[pathCells.Count - 1].Center;
//generate a couple of random paths
for (int i = 0; i < rand.Next() % 3; i++)
@@ -200,11 +204,21 @@ namespace Subsurface
Debug.WriteLine("path: " + sw2.ElapsedMilliseconds + " ms");
sw2.Restart();
startPosition = pathCells[0].Center;
endPosition = pathCells[pathCells.Count - 1].Center;
for (int i = 0; i < 2; i++ )
{
Vector2 tunnelStart = (i == 0) ? startPosition : endPosition;
pathCells.AddRange
(
GeneratePath(rand, tunnelStart, new Vector2(tunnelStart.X, borders.Height), cells, pathBorders, minWidth, 0.1f)
);
}
cells = CleanCells(pathCells);
foreach (VoronoiCell cell in pathCells)
{
cells.Remove(cell);
@@ -223,6 +237,26 @@ namespace Subsurface
cellGrid[(int)Math.Floor(cell.Center.X / GridCellWidth), (int)Math.Floor(cell.Center.Y / GridCellWidth)].Add(cell);
}
startPosition.Y = borders.Height;
endPosition.Y = borders.Height;
for (int i = 0; i < 2; i++)
{
Vector2 tunnelStart = (i == 0) ? startPosition : endPosition;
for (int n = -1; n < 2; n += 2)
{
int cellIndex = FindCellIndex(new Vector2(tunnelStart.X + minWidth * 0.5f * n, tunnelStart.Y), 3);
foreach (GraphEdge ge in cells[cellIndex].edges)
{
if (ge.point1.Y > cells[cellIndex].Center.Y) ge.point1.Y = borders.Height + 5000.0f;
if (ge.point2.Y > cells[cellIndex].Center.Y) ge.point2.Y = borders.Height + 5000.0f;
}
}
}
startPosition.Y += 5000.0f;
endPosition.Y += 5000.0f;
GeneratePolygons(cells, pathCells);
foreach (VoronoiCell cell in cells)
@@ -394,23 +428,11 @@ namespace Subsurface
return (r >= 0 && r <= 1) && (s >= 0 && s <= 1);
}
//public Microsoft.Xna.Framework.Point GridCell(Vector2 position)
//{
// Microsoft.Xna.Framework.Point point = new Microsoft.Xna.Framework.Point(
// (int)Math.Floor(position.X / gridCellWidth),
// (int)Math.Floor(position.Y / gridCellWidth));
// point.X = MathHelper.Clamp(point.X, 0, cellGrid.GetLength(0) - 1);
// point.Y = MathHelper.Clamp(point.X, 0, cellGrid.GetLength(1) - 1);
// return point;
//}
/// <summary>
/// find the index of the cell which the point is inside
/// (actually finds the cell whose center is closest, but it's always the correct cell assuming the point is inside the borders of the diagram)
/// </summary>
private int FindCellIndex(Vector2 position)
private int FindCellIndex(Vector2 position, int searchDepth = 1)
{
float closestDist = 0.0f;
VoronoiCell closestCell = null;
@@ -418,11 +440,9 @@ namespace Subsurface
int gridPosX = (int)Math.Floor(position.X / GridCellWidth);
int gridPosY = (int)Math.Floor(position.Y / GridCellWidth);
int searchOffset = 1;
for (int x = Math.Max(gridPosX - searchOffset, 0); x <= Math.Min(gridPosX + searchOffset, cellGrid.GetLength(0) - 1); x++)
for (int x = Math.Max(gridPosX - searchDepth, 0); x <= Math.Min(gridPosX + searchDepth, cellGrid.GetLength(0) - 1); x++)
{
for (int y = Math.Max(gridPosY - searchOffset, 0); y <= Math.Min(gridPosY + searchOffset, cellGrid.GetLength(1) - 1); y++)
for (int y = Math.Max(gridPosY - searchDepth, 0); y <= Math.Min(gridPosY + searchDepth, cellGrid.GetLength(1) - 1); y++)
{
for (int i = 0; i < cellGrid[x, y].Count; i++)
{
@@ -472,45 +492,27 @@ namespace Subsurface
if (tempVertices.Count < 3) continue;
int triangleCount = tempVertices.Count - 2;
tempVertices.Sort(new CompareCCW(cell.Center));
int lastIndex = 1;
for (int i = 0; i < triangleCount; i++)
var triangles = TriangulateConvex(tempVertices, cell.Center);
for (int i = 0; i < triangles.Count; i++ )
{
//simple triangulation
List<Vector2> triangleVertices = new List<Vector2>();
triangleVertices.Add(tempVertices[0]);
for (int j = lastIndex; j <= lastIndex + 1; j++)
foreach (Vector2 vertex in triangles[i])
{
triangleVertices.Add(tempVertices[j]);
verticeList.Add(new VertexPositionColor(new Vector3(vertex, 0.0f), new Color(n,(n*2)%255,(n*3)%255)*0.5f));
}
lastIndex += 1;
foreach (Vector2 vertex in triangleVertices)
{
verticeList.Add(new VertexPositionColor(new Vector3(vertex, 0.0f), Color.LightGray * 0.8f));//new Color(n,(n*2)%255,(n*3)%255)*0.5f));
}
//bool isSame = false;
//if (triangleVertices[0].Y == triangleVertices[1].Y && triangleVertices[1].Y == triangleVertices[2].Y) isSame = true;
//if (triangleVertices[0].X == triangleVertices[1].X && triangleVertices[1].X == triangleVertices[2].X) isSame = true;
//if (isSame) continue;
//CreateBody(cell, triangleVertices);
}
if (bodyPoints.Count < 2) continue;
//todo: make sure the first point is the one where the edge should start from
bodyPoints.Sort(new CompareCCW(cell.Center));
//if (bodyPoints.Count == tempVertices.Count)
//{
//}
if (bodyPoints.Count < 3)
{
foreach(Vector2 vertex in tempVertices)
{
if (bodyPoints.Contains(vertex)) continue;
bodyPoints.Add(vertex);
break;
}
}
for (int i = 0; i < bodyPoints.Count; i++)
{
@@ -518,45 +520,81 @@ namespace Subsurface
bodyPoints[i] = ConvertUnits.ToSimUnits(bodyPoints[i]);
}
for (int i = bodyPoints.Count-1; i >0 ; i--)
triangles = TriangulateConvex(bodyPoints, cell.Center);
Body edgeBody = new Body(Game1.World);
for (int i = 0; i < triangles.Count; i++)
{
if (Vector2.Distance(bodyPoints[i], bodyPoints[i - 1]) < 0.1f) bodyPoints.RemoveAt(i);
Vertices bodyVertices = new Vertices(triangles[i]);
FixtureFactory.AttachPolygon(bodyVertices, 5.0f, edgeBody);
}
if (bodyPoints.Count < 2) continue;
Vertices bodyVertices = new Vertices(bodyPoints);
Body edgeBody = BodyFactory.CreateLoopShape(Game1.World, bodyVertices);
//Body edgeBody = (bodyVertices.Count == tempVertices.Count) ?
// BodyFactory.CreateLoopShape(Game1.world, bodyVertices) :
// BodyFactory.CreateChainShape(Game1.world, bodyVertices);
edgeBody.UserData = cell;
edgeBody.SleepingAllowed = false;
edgeBody.BodyType = BodyType.Kinematic;
edgeBody.CollisionCategories = Physics.CollisionWall | Physics.CollisionLevel;
cell.body = edgeBody;
bodies.Add(edgeBody);
}
vertices = verticeList.ToArray();
for (int i = 0; i < 2; i++ )
{
Body shaftBody = BodyFactory.CreateRectangle(Game1.World, 100.0f, 10.0f, 5.0f);
shaftBody.BodyType = BodyType.Kinematic;
shaftBody.CollisionCategories = Physics.CollisionWall | Physics.CollisionLevel;
shaftBody.SetTransform(ConvertUnits.ToSimUnits((i==0) ? startPosition : endPosition), 0.0f);
shaftBody.SleepingAllowed = false;
bodies.Add(shaftBody);
}
//return bodies;
vertices = verticeList.ToArray();
}
private List<Vector2[]> TriangulateConvex(List<Vector2> vertices, Vector2 center)
{
List<Vector2[]> triangles = new List<Vector2[]>();
int triangleCount = vertices.Count - 2;
vertices.Sort(new CompareCCW(center));
int lastIndex = 1;
for (int i = 0; i < triangleCount; i++)
{
Vector2[] triangleVertices = new Vector2[3];
triangleVertices[0] = vertices[0];
int k = 1;
for (int j = lastIndex; j <= lastIndex + 1; j++)
{
triangleVertices[k]=vertices[j];
k++;
}
lastIndex += 1;
triangles.Add(triangleVertices);
}
return triangles;
}
public void SetPosition(Vector2 pos)
{
Vector2 amount = pos - Position;
Vector2 simAmount = ConvertUnits.ToSimUnits(amount);
foreach (VoronoiCell cell in cells)
//foreach (VoronoiCell cell in cells)
//{
// if (cell.body == null) continue;
// cell.body.SleepingAllowed = false;
// cell.body.SetTransform(cell.body.Position + simAmount, cell.body.Rotation);
//}
foreach (Body body in bodies)
{
if (cell.body == null) continue;
cell.body.SleepingAllowed = false;
cell.body.SetTransform(cell.body.Position + simAmount, cell.body.Rotation);
body.SetTransform(body.Position + simAmount, body.Rotation);
}
foreach (MapEntity mapEntity in MapEntity.mapEntityList)
@@ -585,10 +623,15 @@ namespace Subsurface
//DebugCheckPos();
foreach (VoronoiCell cell in cells)
//foreach (VoronoiCell cell in cells)
//{
// if (cell.body == null) continue;
// cell.body.LinearVelocity = simVelocity;
//}
foreach (Body body in bodies)
{
if (cell.body == null) continue;
cell.body.LinearVelocity = simVelocity;
body.LinearVelocity = simVelocity;
}
foreach (Character character in Character.CharacterList)
@@ -703,64 +746,51 @@ namespace Subsurface
}
public void RenderLines(SpriteBatch spriteBatch)
public void Draw(SpriteBatch spriteBatch)
{
//GUI.DrawRectangle(spriteBatch, new Rectangle(borders.X, borders.Y-borders.Height, borders.Width, borders.Height), Color.Cyan);
Vector2 pos = endPosition;
pos.X += Position.X;
pos.Y = -pos.Y - Position.Y;
//for (int x = 0; x < cellGrid.GetLength(0); x++)
int shaftWidth = 10000;
spriteBatch.Draw(shaftTexture,
new Rectangle((int)(pos.X - shaftWidth / 2), (int)pos.Y, shaftWidth, 512),
new Rectangle(0, 0, shaftWidth, 256),
Color.White, 0.0f,
Vector2.Zero,
SpriteEffects.None, 0.0f);
pos = startPosition;
pos.X += Position.X;
pos.Y = -pos.Y - Position.Y;
spriteBatch.Draw(shaftTexture,
new Rectangle((int)(pos.X - shaftWidth/2), (int)pos.Y, shaftWidth, 512),
new Rectangle(0, 0, shaftWidth, 256),
Color.White, 0.0f,
Vector2.Zero,
SpriteEffects.None, 0.0f);
//List<Vector2[]> edges = GetCellEdges(observerPosition, 1, false);
//foreach (VoronoiCell cell in cells)
//{
// for (int y = 0; y < cellGrid.GetLength(1); y++)
// for (int i = 0; i < cell.bodyVertices.Count - 1; i++)
// {
// GUI.DrawRectangle(spriteBatch,
// new Rectangle(x * gridCellWidth + (int)position.X, borders.Y - borders.Height + y * gridCellWidth - (int)position.Y, gridCellWidth, gridCellWidth),
// Color.Cyan);
// Vector2 start = cell.bodyVertices[i];
// start.X += Position.X;
// start.Y = -start.Y - Position.Y;
// start.X += Rand.Range(-10.0f, 10.0f);
// Vector2 end = cell.bodyVertices[i + 1];
// end.X += Position.X;
// end.Y = -end.Y - Position.Y;
// end.X += Rand.Range(-10.0f, 10.0f);
// GUI.DrawLine(spriteBatch, start, end, (cell.body != null && cell.body.Enabled) ? Color.Red : Color.Red);
// }
//}
//int gridPosX = (int)Math.Floor(-observerPosition.X / gridCellWidth);
//int gridPosY = (int)Math.Floor(-observerPosition.Y / gridCellWidth);
//int searchOffset = 2;
//int startX = Math.Max(gridPosX - searchOffset, 0);
//int endX = Math.Min(gridPosX + searchOffset, cellGrid.GetLength(0) - 1);
//int startY = Math.Max(gridPosY - searchOffset, 0);
//int endY = Math.Min(gridPosY + searchOffset, cellGrid.GetLength(1) - 1);
//for (int x = startX; x < endX; x++)
//{
// for (int y = startY; y < endY; y++)
// {
// GUI.DrawRectangle(spriteBatch,
// new Rectangle(x * gridCellWidth + (int)position.X, borders.Y - borders.Height + y * gridCellWidth - (int)position.Y, gridCellWidth, gridCellWidth),
// Color.Cyan);
// }
//}
List<Vector2[]> edges = GetCellEdges(observerPosition, 1, false);
//for (int i = 0; i < edges.Count; i++)
//{
// GUI.DrawLine(spriteBatch, edges[i][0], edges[i][1], Color.Green);
//}
foreach (VoronoiCell cell in cells)
{
for (int i = 0; i < cell.bodyVertices.Count - 1; i++)
{
Vector2 start = cell.bodyVertices[i];
start.X += Position.X;
start.Y = -start.Y - Position.Y;
start.X += Rand.Range(-10.0f, 10.0f);
Vector2 end = cell.bodyVertices[i + 1];
end.X += Position.X;
end.Y = -end.Y - Position.Y;
end.X += Rand.Range(-10.0f, 10.0f);
GUI.DrawLine(spriteBatch, start, end, (cell.body != null && cell.body.Enabled) ? Color.Red : Color.Red);
}
}
}
public List<Vector2[]> GetCellEdges(Vector2 refPos, int searchDepth = 2, bool onlySolid = true)
@@ -814,7 +844,6 @@ namespace Subsurface
basicEffect.CurrentTechnique.Passes[0].Apply();
graphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, vertices, 0, (int)Math.Floor(vertices.Length / 3.0f));
}

View File

@@ -149,7 +149,7 @@ namespace Subsurface
}
base.Remove();
ID = -1;
}
private List<Vector2> GenerateConvexHull()
@@ -524,10 +524,17 @@ namespace Subsurface
Vector2 u = Vector2.Dot(simSpeed, normal)*normal;
Vector2 w = simSpeed - u;
speed = ConvertUnits.ToDisplayUnits(w*f2.Body.Friction - u*0.5f);
System.Diagnostics.Debug.WriteLine("IMPACT:"+impact);
if (impact < 5.0f) return true;
if (impact < 5.0f)
{
speed = ConvertUnits.ToDisplayUnits(w * 0.9f - u * 0.2f);
return true;
}
else
{
speed = ConvertUnits.ToDisplayUnits(w * 0.9f + u * 0.5f);
}
collisionRigidness = 0.8f;
@@ -820,18 +827,21 @@ namespace Subsurface
}
}
//ID = 1;
ID = int.MaxValue-10;
loaded = this;
}
public static Submarine Load(string file)
{
Unload();
Unload();
Submarine sub = new Submarine(file);
sub.Load();
//Entity.dictionary.Add(int.MaxValue, sub);
return sub;
}

View File

@@ -374,6 +374,7 @@ namespace Subsurface.Networking
msg.Write((byte)PacketTypes.PlayerLeft);
Client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered);
Client.Shutdown("");
}
public void SendCharacterData()
@@ -411,6 +412,11 @@ namespace Subsurface.Networking
string jobName = inc.ReadString();
JobPrefab jobPrefab = JobPrefab.List.Find(jp => jp.Name == jobName);
if (inc.Position > inc.LengthBits)
{
return null;
}
CharacterInfo ch = new CharacterInfo("Content/Characters/Human/human.xml", newName, isFemale ? Gender.Female : Gender.Male, jobPrefab);
ch.HeadSpriteId = headSpriteID;
@@ -433,7 +439,7 @@ namespace Subsurface.Networking
character.ID = ID;
character.Inventory.ID = inventoryID;
character.GiveJobItems();
character.GiveJobItems(closestWaypoint);
return character;
}

View File

@@ -285,6 +285,7 @@ namespace Subsurface.Networking
Rand.SetSyncedSeed(seed);
Submarine selectedMap = Game1.NetLobbyScreen.SelectedMap as Submarine;
//selectedMap.Load();
@@ -315,7 +316,7 @@ namespace Subsurface.Networking
{
connectedClients[i].character = new Character(
connectedClients[i].characterInfo, assignedWayPoints[i], true);
connectedClients[i].character.GiveJobItems();
connectedClients[i].character.GiveJobItems(assignedWayPoints[i]);
}
//todo: fix
@@ -627,6 +628,11 @@ namespace Subsurface.Networking
return preferredClient;
}
public override void Disconnect()
{
Server.Shutdown("");
}
}
class Client

View File

@@ -103,7 +103,7 @@ namespace Subsurface.Networking
DebugConsole.ThrowError("Received invalid network message");
return false;
}
//288=id, 280=char
Entity e = Entity.FindEntityByID(id);
if (e == null)
{

View File

@@ -39,7 +39,7 @@ namespace Subsurface
{
base.Select();
Ragdoll.DebugDraw = true;
Game1.DebugDraw = true;
cam = new Camera();

View File

@@ -161,21 +161,26 @@ namespace Subsurface
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.LinearWrap);
int x = (int)(cam.Position.X / 20.0f);
int y = (int)((-cam.Position.Y+5000) / 20.0f);
if (y<1024)
Vector2 backgroundPos = cam.Position;
if (Level.Loaded != null) backgroundPos -= Level.Loaded.Position;
backgroundPos.Y = -backgroundPos.Y;
backgroundPos /= 20.0f;
if (backgroundPos.Y < 1024)
{
if (y>-1024)
if (backgroundPos.Y > -1024)
{
background.SourceRect = new Rectangle(x, Math.Max(y,0), 1024, 1024);
background.DrawTiled(spriteBatch, (y<0) ? new Vector2(0.0f, -y) : Vector2.Zero, new Vector2(Game1.GraphicsWidth, 1024 - y),
background.SourceRect = new Rectangle((int)backgroundPos.X, (int)Math.Max(backgroundPos.Y, 0), 1024, 1024);
background.DrawTiled(spriteBatch,
(backgroundPos.Y < 0) ? new Vector2(0.0f, -backgroundPos.Y) : Vector2.Zero,
new Vector2(Game1.GraphicsWidth, 1024 - backgroundPos.Y),
Vector2.Zero, Color.White);
}
if (y<0)
if (backgroundPos.Y < 0)
{
backgroundTop.SourceRect = new Rectangle(x, y, 1024, Math.Min(-y,1024));
backgroundTop.DrawTiled(spriteBatch, Vector2.Zero, new Vector2(Game1.GraphicsWidth, Math.Min(-y, Game1.GraphicsHeight)),
backgroundTop.SourceRect = new Rectangle((int)backgroundPos.X, (int)backgroundPos.Y, 1024, (int)Math.Min(-backgroundPos.Y, 1024));
backgroundTop.DrawTiled(spriteBatch, Vector2.Zero, new Vector2(Game1.GraphicsWidth, Math.Min(-backgroundPos.Y, Game1.GraphicsHeight)),
Vector2.Zero, Color.White);
}
}
@@ -255,15 +260,15 @@ namespace Subsurface
//----------------------------------------------------------------------------------------
spriteBatch.Begin(SpriteSortMode.BackToFront,
BlendState.AlphaBlend,
null, null, null, null,
BlendState.AlphaBlend, SamplerState.LinearWrap,
null, null, null,
cam.Transform);
Submarine.DrawFront(spriteBatch);
if (Game1.GameSession != null && Game1.GameSession.Level != null)
{
Game1.GameSession.Level.RenderLines(spriteBatch);
Game1.GameSession.Level.Draw(spriteBatch);
//Game1.GameSession.Level.SetObserverPosition(cam.WorldViewCenter);
}

View File

@@ -151,6 +151,8 @@ namespace Subsurface
public override void Select()
{
Lights.LightManager.FowEnabled = false;
infoFrame.ClearChildren();
if (IsServer && Game1.Server == null) Game1.NetworkMember = new GameServer();

View File

@@ -372,6 +372,9 @@
<Content Include="Content\Map\iceSurface.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Map\shaft.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\UI\caret.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

View File

@@ -3,6 +3,7 @@ using System.Drawing.Imaging;
using System.IO;
using Microsoft.Xna.Framework.Graphics;
using Color = Microsoft.Xna.Framework.Color;
using System;
namespace Subsurface
{
@@ -41,8 +42,17 @@ namespace Subsurface
public Texture2D FromFile(string path, bool preMultiplyAlpha = true)
{
using (Stream fileStream = File.OpenRead(path))
return FromStream(fileStream, preMultiplyAlpha);
try
{
using (Stream fileStream = File.OpenRead(path))
return FromStream(fileStream, preMultiplyAlpha);
}
catch (Exception e)
{
DebugConsole.ThrowError("Loading texture ''"+path+"'' failed!", e);
return null;
}
}
public Texture2D FromStream(Stream stream, bool preMultiplyAlpha = true)

Binary file not shown.