fixed railgun, fixed repairtools radar ping & improved rendering, waypoint bugfixes, inventory bugfixes, syncing wires between clients

This commit is contained in:
Regalis
2015-07-15 23:34:13 +03:00
parent 44b9a63c94
commit 237df18765
39 changed files with 461 additions and 405 deletions
@@ -1,5 +1,6 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Xml.Linq;
@@ -28,26 +29,13 @@ namespace Subsurface.Items.Components
break;
}
}
isActive = true;
}
//public override void Move(Vector2 amount)
//{
// base.Move(amount);
// foreach (Connection c in connections)
// {
// foreach (Wire w in c.wires)
// {
// if (w == null) continue;
// w.Move
// }
// }
//}
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
{
if (user!=character) return;
if (character != Character.Controlled || character != user) return;
Connection.DrawConnections(spriteBatch, this, character);
}
@@ -76,7 +64,7 @@ namespace Subsurface.Items.Components
if (user != null && user.SelectedConstruction != item) user = null;
}
public override bool Pick(Character picker)
public override bool Select(Character picker)
{
user = picker;
isActive = true;
@@ -107,10 +95,12 @@ namespace Subsurface.Items.Components
{
foreach (Connection c in connections)
{
int wireCount = c.Wires.Length;
for (int i = 0 ; i < wireCount; i++)
Wire[] wires = Array.FindAll(c.Wires, w => w != null);
message.Write((byte)wires.Length);
for (int i = 0 ; i < c.Wires.Length; i++)
{
message.Write(c.Wires[i]==null ? -1 : c.Wires[i].Item.ID);
if (c.Wires[i] == null) continue;
message.Write(c.Wires[i].Item.ID);
}
}
}
@@ -120,23 +110,28 @@ namespace Subsurface.Items.Components
System.Diagnostics.Debug.WriteLine("connectionpanel update");
foreach (Connection c in connections)
{
int wireCount = c.Wires.Length;
//int wireCount = c.Wires.Length;
c.ClearConnections();
for (int i = 0; i < wireCount; i++)
try
{
int wireId = message.ReadInt32();
if (wireId == -1) continue;
byte wireCount = message.ReadByte();
Item wireItem = MapEntity.FindEntityByID(wireId) as Item;
if (wireItem == null) continue;
for (int i = 0; i < wireCount; i++)
{
int wireId = message.ReadInt32();
Item wireItem = MapEntity.FindEntityByID(wireId) as Item;
if (wireItem == null) continue;
Wire wireComponent = wireItem.GetComponent<Wire>();
if (wireComponent == null) continue;
Wire wireComponent = wireItem.GetComponent<Wire>();
if (wireComponent == null) continue;
c.Wires[i] = wireComponent;
wireComponent.Connect(c, false);
c.Wires[i] = wireComponent;
wireComponent.Connect(c, false);
}
}
catch { }
}
}
}
+40 -41
View File
@@ -15,12 +15,12 @@ namespace Subsurface.Items.Components
static Sprite wireSprite;
List<Vector2> nodes;
public List<Vector2> Nodes;
Connection[] connections;
private Vector2 newNodePos;
public Wire(Item item, XElement element)
: base(item, element)
{
@@ -30,7 +30,7 @@ namespace Subsurface.Items.Components
wireSprite.Depth = 0.85f;
}
nodes = new List<Vector2>();
Nodes = new List<Vector2>();
connections = new Connection[2];
}
@@ -38,9 +38,9 @@ namespace Subsurface.Items.Components
public override void Move(Vector2 amount)
{
amount = FarseerPhysics.ConvertUnits.ToDisplayUnits(amount);
for (int i = 0; i<nodes.Count; i++)
for (int i = 0; i<Nodes.Count; i++)
{
nodes[i] += amount;
Nodes[i] += amount;
}
}
@@ -76,11 +76,11 @@ namespace Subsurface.Items.Components
if (i == 0)
{
nodes.Insert(0, newConnection.Item.Position);
Nodes.Insert(0, newConnection.Item.Position);
}
else
{
nodes.Add(newConnection.Item.Position);
Nodes.Add(newConnection.Item.Position);
}
@@ -97,8 +97,7 @@ namespace Subsurface.Items.Components
CleanNodes();
}
//new Networking.NetworkEvent(item.ID, true);
Item.NewComponentEvent(this, true);
}
public override void Equip(Character character)
@@ -117,7 +116,7 @@ namespace Subsurface.Items.Components
public override void Update(float deltaTime, Camera cam)
{
if (nodes.Count == 0) return;
if (Nodes.Count == 0) return;
item.FindHull();
@@ -153,9 +152,9 @@ namespace Subsurface.Items.Components
public override bool Use(float deltaTime, Character character = null)
{
if (newNodePos!= Vector2.Zero && nodes.Count>0 && Vector2.Distance(newNodePos, nodes[nodes.Count - 1]) > nodeDistance)
if (newNodePos!= Vector2.Zero && Nodes.Count>0 && Vector2.Distance(newNodePos, Nodes[Nodes.Count - 1]) > nodeDistance)
{
nodes.Add(newNodePos);
Nodes.Add(newNodePos);
newNodePos = Vector2.Zero;
}
@@ -166,9 +165,9 @@ namespace Subsurface.Items.Components
public override void SecondaryUse(float deltaTime, Character character = null)
{
if (nodes.Count > 1)
if (Nodes.Count > 1)
{
nodes.RemoveAt(nodes.Count - 1);
Nodes.RemoveAt(Nodes.Count - 1);
item.NewComponentEvent(this, true);
}
}
@@ -182,7 +181,7 @@ namespace Subsurface.Items.Components
private void ClearConnections()
{
nodes.Clear();
Nodes.Clear();
for (int i = 0; i < 2; i++)
{
@@ -198,14 +197,14 @@ namespace Subsurface.Items.Components
private void CleanNodes()
{
for (int i = nodes.Count - 2; i > 0; i--)
for (int i = Nodes.Count - 2; i > 0; i--)
{
if ((nodes[i - 1].X == nodes[i].X || nodes[i - 1].Y == nodes[i].Y) &&
(nodes[i + 1].X == nodes[i].X || nodes[i + 1].Y == nodes[i].Y))
if ((Nodes[i - 1].X == Nodes[i].X || Nodes[i - 1].Y == Nodes[i].Y) &&
(Nodes[i + 1].X == Nodes[i].X || Nodes[i + 1].Y == Nodes[i].Y))
{
if (Vector2.Distance(nodes[i - 1], nodes[i]) == Vector2.Distance(nodes[i + 1], nodes[i]))
if (Vector2.Distance(Nodes[i - 1], Nodes[i]) == Vector2.Distance(Nodes[i + 1], Nodes[i]))
{
nodes.RemoveAt(i);
Nodes.RemoveAt(i);
}
}
}
@@ -214,12 +213,12 @@ namespace Subsurface.Items.Components
do
{
removed = false;
for (int i = nodes.Count - 2; i > 0; i--)
for (int i = Nodes.Count - 2; i > 0; i--)
{
if ((nodes[i - 1].X == nodes[i].X && nodes[i + 1].X == nodes[i].X)
|| (nodes[i - 1].Y == nodes[i].Y && nodes[i + 1].Y == nodes[i].Y))
if ((Nodes[i - 1].X == Nodes[i].X && Nodes[i + 1].X == Nodes[i].X)
|| (Nodes[i - 1].Y == Nodes[i].Y && Nodes[i + 1].Y == Nodes[i].Y))
{
nodes.RemoveAt(i);
Nodes.RemoveAt(i);
removed = true;
}
}
@@ -231,21 +230,21 @@ namespace Subsurface.Items.Components
public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
{
if (nodes.Count == 0) return;
if (Nodes.Count == 0) return;
//for (int i = 0; i < nodes.Count; i++)
//{
// GUI.DrawRectangle(spriteBatch, new Rectangle((int)nodes[i].X, (int)-nodes[i].Y, 5, 5), Color.DarkGray, true, wireSprite.Depth - 0.01f);
//}
for (int i = 1; i < nodes.Count; i++)
for (int i = 1; i < Nodes.Count; i++)
{
DrawSection(spriteBatch, nodes[i], nodes[i - 1], i, Color.White);
DrawSection(spriteBatch, Nodes[i], Nodes[i - 1], i, Color.White);
}
if (isActive && Vector2.Distance(newNodePos, nodes[nodes.Count - 1]) > nodeDistance)
if (isActive && Vector2.Distance(newNodePos, Nodes[Nodes.Count - 1]) > nodeDistance)
{
DrawSection(spriteBatch, nodes[nodes.Count - 1], newNodePos, nodes.Count, Color.White * 0.5f);
DrawSection(spriteBatch, Nodes[Nodes.Count - 1], newNodePos, Nodes.Count, Color.White * 0.5f);
//nodes.Add(newNodePos);
}
@@ -269,13 +268,13 @@ namespace Subsurface.Items.Components
{
XElement componentElement = base.Save(parentElement);
if (nodes == null || nodes.Count == 0) return componentElement;
if (Nodes == null || Nodes.Count == 0) return componentElement;
string[] nodeCoords = new string[nodes.Count() * 2];
for (int i = 0; i < nodes.Count(); i++)
string[] nodeCoords = new string[Nodes.Count() * 2];
for (int i = 0; i < Nodes.Count(); i++)
{
nodeCoords[i * 2] = nodes[i].X.ToString(CultureInfo.InvariantCulture);
nodeCoords[i * 2 + 1] = nodes[i].Y.ToString(CultureInfo.InvariantCulture);
nodeCoords[i * 2] = Nodes[i].X.ToString(CultureInfo.InvariantCulture);
nodeCoords[i * 2 + 1] = Nodes[i].Y.ToString(CultureInfo.InvariantCulture);
}
componentElement.Add(new XAttribute("nodes", string.Join(";", nodeCoords)));
@@ -307,28 +306,28 @@ namespace Subsurface.Items.Components
}
catch { y = 0.0f; }
nodes.Add(new Vector2(x, y));
Nodes.Add(new Vector2(x, y));
}
}
public override void FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetOutgoingMessage message)
{
message.Write(nodes.Count);
for (int i = 0; i < nodes.Count; i++)
message.Write(Nodes.Count);
for (int i = 0; i < Nodes.Count; i++)
{
message.Write(nodes[i].X);
message.Write(nodes[i].Y);
message.Write(Nodes[i].X);
message.Write(Nodes[i].Y);
}
}
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message)
{
nodes.Clear();
Nodes.Clear();
int nodeCount = message.ReadInt32();
for (int i = 0; i < nodeCount; i++)
{
nodes.Add(new Vector2(message.ReadFloat(), message.ReadFloat()));
Nodes.Add(new Vector2(message.ReadFloat(), message.ReadFloat()));
}
}
}