diff --git a/Subsurface/Content/Items/Door/doors.xml b/Subsurface/Content/Items/Door/doors.xml index 3b709c5e1..f4326c5ed 100644 --- a/Subsurface/Content/Items/Door/doors.xml +++ b/Subsurface/Content/Items/Door/doors.xml @@ -96,6 +96,9 @@ + + + @@ -105,6 +108,7 @@ + @@ -123,6 +127,15 @@ + + + + + + + + + @@ -132,6 +145,7 @@ + diff --git a/Subsurface/Content/Items/Tools/tools.xml b/Subsurface/Content/Items/Tools/tools.xml index f5a77a507..e51dfcc6d 100644 --- a/Subsurface/Content/Items/Tools/tools.xml +++ b/Subsurface/Content/Items/Tools/tools.xml @@ -268,7 +268,7 @@ - + diff --git a/Subsurface/Source/GameSession/GameModes/Tutorials/BasicTutorial.cs b/Subsurface/Source/GameSession/GameModes/Tutorials/BasicTutorial.cs index 47075b53f..d84c9f8ce 100644 --- a/Subsurface/Source/GameSession/GameModes/Tutorials/BasicTutorial.cs +++ b/Subsurface/Source/GameSession/GameModes/Tutorials/BasicTutorial.cs @@ -18,12 +18,19 @@ namespace Barotrauma.Tutorials public override IEnumerable UpdateState() { - //Submarine.Loaded.SetPosition(new Vector2(Submarine.Loaded.Position.X, 38500.0f)); - //spawn some fish next to the player GameMain.GameScreen.BackgroundCreatureManager.SpawnSprites(2, Submarine.MainSub.Position + Character.Controlled.Position); + foreach (Item item in Item.ItemList) + { + var wire = item.GetComponent(); + if (wire != null && wire.Connections.Any(c => c != null)) + { + wire.Locked = true; + } + } + yield return new WaitForSeconds(4.0f); infoBox = CreateInfoFrame("Use WASD to move and the mouse to look around"); diff --git a/Subsurface/Source/Items/Components/DockingPort.cs b/Subsurface/Source/Items/Components/DockingPort.cs index ac6d9847c..e67c8725f 100644 --- a/Subsurface/Source/Items/Components/DockingPort.cs +++ b/Subsurface/Source/Items/Components/DockingPort.cs @@ -105,7 +105,7 @@ namespace Barotrauma.Items.Components break; } } - + IsActive = true; hullIds = new ushort?[2]; @@ -131,18 +131,25 @@ namespace Barotrauma.Items.Components private void AttemptDock() { var adjacentPort = FindAdjacentPort(); + if (adjacentPort != null) Dock(adjacentPort); } public void Dock(DockingPort target) { if (item.Submarine.DockedTo.Contains(target.item.Submarine)) return; - + if (dockingTarget != null) { Undock(); } + if (target.item.Submarine == item.Submarine) + { + DebugConsole.ThrowError("Error - tried to a submarine to itself"); + return; + } + PlaySound(ActionType.OnUse, item.WorldPosition); if (!item.linkedTo.Contains(target.item)) item.linkedTo.Add(target.item); @@ -225,6 +232,32 @@ namespace Barotrauma.Items.Components joint.CollideConnected = true; } + private void ConnectWireBetweenPorts() + { + Wire wire = item.GetComponent(); + if (wire == null) return; + + wire.Hidden = true; + wire.Locked = true; + + if (Item.Connections == null) return; + + var powerConnection = Item.Connections.Find(c => c.IsPower); + if (powerConnection == null) return; + + if (dockingTarget == null || dockingTarget.item.Connections == null) return; + var recipient = dockingTarget.item.Connections.Find(c => c.IsPower); + if (recipient == null) return; + + wire.RemoveConnection(item); + wire.RemoveConnection(dockingTarget.item); + + powerConnection.AddLink(4, wire); + wire.Connect(powerConnection, false); + recipient.AddLink(4, wire); + wire.Connect(recipient, false); + } + private void CreateHull() { var hullRects = new Rectangle[] { item.WorldRect, dockingTarget.item.WorldRect }; @@ -374,6 +407,12 @@ namespace Barotrauma.Items.Components dockingTarget.Undock(); dockingTarget = null; + var wire = item.GetComponent(); + if (wire != null) + { + wire.Drop(null); + } + if (joint != null) { GameMain.World.RemoveJoint(joint); @@ -427,17 +466,6 @@ namespace Barotrauma.Items.Components if (!docked) { Dock(dockingTarget); - - //if (joint.BodyA.Mass < joint.BodyB.Mass) - //{ - // joint.BodyA.SetTransform(joint.BodyA.Position + (joint.WorldAnchorB - joint.WorldAnchorA), 0.0f); - //} - //else - //{ - // joint.BodyB.SetTransform(joint.BodyB.Position + (joint.WorldAnchorA - joint.WorldAnchorB), 0.0f); - //} - - } if (joint is DistanceJoint) @@ -450,6 +478,9 @@ namespace Barotrauma.Items.Components PlaySound(ActionType.OnSecondaryUse, item.WorldPosition); + ConnectWireBetweenPorts(); + + CreateJoint(true); if (!item.linkedTo.Any(e => e is Hull) && !dockingTarget.item.linkedTo.Any(e => e is Hull)) diff --git a/Subsurface/Source/Items/Components/Power/PowerTransfer.cs b/Subsurface/Source/Items/Components/Power/PowerTransfer.cs index 3dbf0d3e4..4b3366829 100644 --- a/Subsurface/Source/Items/Components/Power/PowerTransfer.cs +++ b/Subsurface/Source/Items/Components/Power/PowerTransfer.cs @@ -175,6 +175,8 @@ namespace Barotrauma.Items.Components public override void DrawHUD(SpriteBatch spriteBatch, Character character) { + if (!canBeSelected) return; + int x = GuiFrame.Rect.X; int y = GuiFrame.Rect.Y; diff --git a/Subsurface/Source/Items/Components/Signal/Connection.cs b/Subsurface/Source/Items/Components/Signal/Connection.cs index 323dd6f99..8325a5b8b 100644 --- a/Subsurface/Source/Items/Components/Signal/Connection.cs +++ b/Subsurface/Source/Items/Components/Signal/Connection.cs @@ -25,7 +25,7 @@ namespace Barotrauma.Items.Components public readonly bool IsOutput; - private static Item draggingConnected; + private static Wire draggingConnected; private List effects; @@ -240,7 +240,7 @@ namespace Barotrauma.Items.Components //dropped or dragged from the panel to the players inventory if (draggingConnected != null) { - int linkIndex = c.FindWireIndex(draggingConnected); + int linkIndex = c.FindWireIndex(draggingConnected.Item); if (linkIndex>-1) { Inventory.draggingItem = c.Wires[linkIndex].Item; @@ -279,11 +279,11 @@ namespace Barotrauma.Items.Components { if (panel.Connections.Find(c => c.Wires.Contains(equippedWire)) == null) { - DrawWire(spriteBatch, equippedWire.Item, equippedWire.Item, + DrawWire(spriteBatch, equippedWire, equippedWire.Item, new Vector2(x + width / 2, y + height - 100), new Vector2(x + width / 2, y + height), mouseInRect, false); - if (draggingConnected == equippedWire.Item) Inventory.draggingItem = equippedWire.Item; + if (draggingConnected == equippedWire) Inventory.draggingItem = equippedWire.Item; //break; } @@ -294,7 +294,7 @@ namespace Barotrauma.Items.Components if (draggingConnected != null) { - DrawWire(spriteBatch, draggingConnected, draggingConnected, PlayerInput.MousePosition, new Vector2(x + width / 2, y + height), mouseInRect, false); + DrawWire(spriteBatch, draggingConnected, draggingConnected.Item, PlayerInput.MousePosition, new Vector2(x + width / 2, y + height), mouseInRect, false); if (!PlayerInput.LeftButtonHeld()) { @@ -318,11 +318,11 @@ namespace Barotrauma.Items.Components for (int i = 0; i(); - - if (index > -1 && wireComponent != null && !Wires.Contains(wireComponent)) + if (index > -1 && !Wires.Contains(draggingConnected)) { - bool alreadyConnected = wireComponent.IsConnectedTo(item); + bool alreadyConnected = draggingConnected.IsConnectedTo(item); - wireComponent.RemoveConnection(item); + draggingConnected.RemoveConnection(item); - if (wireComponent.Connect(this, !alreadyConnected)) Wires[index] = wireComponent; + if (draggingConnected.Connect(this, !alreadyConnected)) Wires[index] = draggingConnected; } } } int screwIndex = (position.Y % 60 < 30) ? 0 : 1; - if (Wires.Any(w => w != null && w.Item != draggingConnected)) + if (Wires.Any(w => w != null && w != draggingConnected)) { spriteBatch.Draw(panelTexture, position - new Vector2(16.0f, 16.0f), new Rectangle(screwIndex*32, 256, 32, 32), Color.White); } } - private static void DrawWire(SpriteBatch spriteBatch, Item wireItem, Item item, Vector2 end, Vector2 start, bool mouseIn, bool wireEquipped) + private static void DrawWire(SpriteBatch spriteBatch, Wire wire, Item item, Vector2 end, Vector2 start, bool mouseIn, bool wireEquipped) { - if (draggingConnected == wireItem) + if (draggingConnected == wire) { if (!mouseIn) return; end = PlayerInput.MousePosition; @@ -377,16 +375,18 @@ namespace Barotrauma.Items.Components bool mouseOn = !wireEquipped && - (PlayerInput.MousePosition.X > Math.Min(start.X, end.X) && + ((PlayerInput.MousePosition.X > Math.Min(start.X, end.X) && PlayerInput.MousePosition.X < Math.Max(start.X, end.X) && MathUtils.LineToPointDistance(start, end, PlayerInput.MousePosition) < 6) || Vector2.Distance(end, PlayerInput.MousePosition)<20.0f || - new Rectangle((start.X < end.X) ? textX-100 : textX, (int)start.Y-5, 100, 14).Contains(PlayerInput.MousePosition); + new Rectangle((start.X < end.X) ? textX-100 : textX, (int)start.Y-5, 100, 14).Contains(PlayerInput.MousePosition)); + + string label = wire.Locked ? item.Name +"\n(Locked)" : item.Name; GUI.DrawString(spriteBatch, - new Vector2(start.X < end.X ? textX-GUI.SmallFont.MeasureString(item.Name).X : textX,start.Y -5.0f), - item.Name, - mouseOn ? Color.Gold : Color.White, Color.Black * 0.8f, + new Vector2(start.X < end.X ? textX-GUI.SmallFont.MeasureString(label).X : textX,start.Y -5.0f), + label, + (mouseOn ? Color.Gold : Color.White) * (wire.Locked ? 0.6f : 1.0f), Color.Black * 0.8f, 3, GUI.SmallFont); var wireEnd = end + Vector2.Normalize(start - end) * 30.0f; @@ -403,7 +403,7 @@ namespace Barotrauma.Items.Components 0.0f); } spriteBatch.Draw(wireVertical.Texture, new Rectangle(wireEnd.ToPoint(), new Point(12, (int)dist)), wireVertical.SourceRect, - wireItem.Color * alpha, + wire.Item.Color * alpha, MathUtils.VectorToAngle(end - start) + MathHelper.PiOver2, //angle of line (calulated above) new Vector2(6, 0), // point in line about which to rotate SpriteEffects.None, @@ -416,10 +416,14 @@ namespace Barotrauma.Items.Components if (mouseOn) { item.IsHighlighted = true; - wireItem.IsHighlighted = true; + wire.Item.IsHighlighted = true; - //start dragging the wire - if (PlayerInput.LeftButtonHeld()) draggingConnected = wireItem; + if (!wire.Locked) + { + //start dragging the wire + if (PlayerInput.LeftButtonHeld()) draggingConnected = wire; + } + } } } @@ -466,7 +470,7 @@ namespace Barotrauma.Items.Components if (Wires[i]!=null) { - Wires[i].Item.body.Enabled = false; + if (Wires[i].Item.body != null) Wires[i].Item.body.Enabled = false; Wires[i].Connect(this, false, true); } } diff --git a/Subsurface/Source/Items/Components/Signal/Wire.cs b/Subsurface/Source/Items/Components/Signal/Wire.cs index c61250113..50d8b968c 100644 --- a/Subsurface/Source/Items/Components/Signal/Wire.cs +++ b/Subsurface/Source/Items/Components/Signal/Wire.cs @@ -24,6 +24,8 @@ namespace Barotrauma.Items.Components private static Wire draggingWire; private static int? selectedNodeIndex; + public bool Hidden, Locked; + public Connection[] Connections { get { return connections; } @@ -109,7 +111,7 @@ namespace Barotrauma.Items.Components } } - item.Submarine = newConnection.Item.Submarine; + if (item.body != null) item.Submarine = newConnection.Item.Submarine; for (int i = 0; i < 2; i++) { @@ -149,7 +151,7 @@ namespace Barotrauma.Items.Components } if (item.Container != null) item.Container.RemoveContained(this.item); - item.body.Enabled = false; + if (item.body != null) item.body.Enabled = false; IsActive = false; diff --git a/Subsurface/Source/Networking/RespawnManager.cs b/Subsurface/Source/Networking/RespawnManager.cs index 00d6e6062..74f9e0931 100644 --- a/Subsurface/Source/Networking/RespawnManager.cs +++ b/Subsurface/Source/Networking/RespawnManager.cs @@ -82,13 +82,23 @@ namespace Barotrauma.Networking var door = item.GetComponent(); if (door != null) shuttleDoors.Add(door); + + //lock all wires to prevent the players from messing up the electronics + var connectionPanel = item.GetComponent(); + if (connectionPanel != null) + { + foreach (Connection connection in connectionPanel.Connections) + { + Array.ForEach(connection.Wires, w => { if (w != null) w.Locked = true; }); + } + } } if (shuttleSteering != null) { shuttleSteering.TargetPosition = ConvertUnits.ToSimUnits(Level.Loaded.StartPosition); } - + var server = networkMember as GameServer; if (server != null) {