diff --git a/Subsurface/Content/Characters/Charybdis/charybdis.xml b/Subsurface/Content/Characters/Charybdis/charybdis.xml index 86ef15d62..9029f90f7 100644 --- a/Subsurface/Content/Characters/Charybdis/charybdis.xml +++ b/Subsurface/Content/Characters/Charybdis/charybdis.xml @@ -15,7 +15,7 @@ - + diff --git a/Subsurface/Content/Characters/Coelanth/coelanth.xml b/Subsurface/Content/Characters/Coelanth/coelanth.xml index ce223ad49..369627839 100644 --- a/Subsurface/Content/Characters/Coelanth/coelanth.xml +++ b/Subsurface/Content/Characters/Coelanth/coelanth.xml @@ -7,7 +7,7 @@ - + diff --git a/Subsurface/Content/Characters/Human/humanhusk.xml b/Subsurface/Content/Characters/Human/humanhusk.xml index fc593f3ad..73b9e9e13 100644 --- a/Subsurface/Content/Characters/Human/humanhusk.xml +++ b/Subsurface/Content/Characters/Human/humanhusk.xml @@ -9,8 +9,11 @@ movementlerp="0.4" legtorque="15.0" thightorque="-5.0" - walkspeed="2.0" - swimspeed="2.0"> + walkspeed="1.5" + swimspeed="2.5" + impacttolerance="7.5"> + + diff --git a/Subsurface/Data/ContentPackages/Vanilla 0.3.xml b/Subsurface/Data/ContentPackages/Vanilla 0.3.xml index 7f65c3b88..d2954ca1f 100644 --- a/Subsurface/Data/ContentPackages/Vanilla 0.3.xml +++ b/Subsurface/Data/ContentPackages/Vanilla 0.3.xml @@ -39,7 +39,7 @@ - + diff --git a/Subsurface/Source/Characters/Animation/FishAnimController.cs b/Subsurface/Source/Characters/Animation/FishAnimController.cs index fa1ef8eed..cb6a1c7ed 100644 --- a/Subsurface/Source/Characters/Animation/FishAnimController.cs +++ b/Subsurface/Source/Characters/Animation/FishAnimController.cs @@ -51,10 +51,20 @@ namespace Barotrauma if (character.IsDead || character.IsUnconscious || stunTimer > 0.0f) { - collider.PhysEnabled = false; - collider.SetTransform(MainLimb.SimPosition, 0.0f); + collider.FarseerBody.FixedRotation = false; - if (stunTimer > 0.0f) + if (character.IsRemotePlayer) + { + MainLimb.pullJoint.WorldAnchorB = collider.SimPosition; + MainLimb.pullJoint.Enabled = true; + } + else + { + collider.LinearVelocity = (MainLimb.SimPosition - collider.SimPosition) * 60.0f; + collider.SmoothRotate(MainLimb.Rotation); + } + + if (stunTimer > 0) { stunTimer -= deltaTime; } diff --git a/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs b/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs index eba834401..838c86aec 100644 --- a/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs +++ b/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs @@ -57,8 +57,18 @@ namespace Barotrauma if (character.IsDead || character.IsUnconscious || stunTimer > 0.0f) { - collider.PhysEnabled = false; - collider.SetTransform(GetLimb(LimbType.Torso).SimPosition, 0.0f); + collider.FarseerBody.FixedRotation = false; + + if (character.IsRemotePlayer) + { + MainLimb.pullJoint.WorldAnchorB = collider.SimPosition; + MainLimb.pullJoint.Enabled = true; + } + else + { + collider.LinearVelocity = (GetLimb(LimbType.Waist).SimPosition - collider.SimPosition) * 20.0f; + collider.SmoothRotate(GetLimb(LimbType.Torso).Rotation); + } if (stunTimer > 0) { @@ -87,21 +97,21 @@ namespace Barotrauma collider.SetTransform(new Vector2( collider.SimPosition.X, Math.Max(lowestLimb.SimPosition.Y + (collider.radius + collider.height / 2), collider.SimPosition.Y)), - 0.0f); + collider.Rotation); collider.FarseerBody.Enabled = true; } if (swimming) { - collider.FarseerBody.FixedRotation = false; + collider.FarseerBody.FixedRotation = false; } else if (!collider.FarseerBody.FixedRotation) { if (Math.Abs(MathUtils.GetShortestAngle(collider.Rotation, 0.0f)) > 0.001f) { //rotate collider back upright - collider.AngularVelocity = MathUtils.GetShortestAngle(collider.Rotation, 0.0f) * 60.0f; + collider.AngularVelocity = MathUtils.GetShortestAngle(collider.Rotation, 0.0f) * 10.0f; collider.FarseerBody.FixedRotation = false; } else @@ -297,8 +307,11 @@ namespace Barotrauma if (onGround && (!character.IsRemotePlayer || GameMain.Server != null)) { + //move slower if collider isn't upright + float rotationFactor = (float)Math.Abs(Math.Cos(collider.Rotation)); + collider.LinearVelocity = new Vector2( - movement.X, + movement.X * rotationFactor, collider.LinearVelocity.Y > 0.0f ? collider.LinearVelocity.Y * 0.5f : collider.LinearVelocity.Y); } @@ -502,7 +515,8 @@ namespace Barotrauma float colliderBottomY = GetColliderBottom().Y; //the contact point should be higher than the bottom of the collider - if (((Vector2)handle).Y < colliderBottomY + 0.01f) return; + if (((Vector2)handle).Y < colliderBottomY + 0.01f || + ((Vector2)handle).Y > collider.SimPosition.Y) return; //find the height of the floor below the torso //(if moving towards towards an obstacle that's low enough to climb over, the torso should be above it) @@ -511,7 +525,7 @@ namespace Barotrauma if (obstacleY > colliderBottomY) { //higher vertical velocity for taller obstacles - collider.LinearVelocity += Vector2.UnitY * (((Vector2)handle).Y - colliderBottomY + 0.01f) * 10; + collider.LinearVelocity += Vector2.UnitY * (((Vector2)handle).Y - colliderBottomY + 0.01f) * 50; onGround = true; } } @@ -888,13 +902,22 @@ namespace Barotrauma targetLimb.pullJoint.Enabled = true; targetLimb.pullJoint.WorldAnchorB = targetLimb.SimPosition - diff; targetLimb.pullJoint.MaxForce = 10000.0f; + + target.AnimController.movement -= diff; } } + float dist = Vector2.Distance(target.SimPosition, collider.SimPosition); + + //limit movement if moving away from the target + if (Vector2.Dot(target.SimPosition - collider.SimPosition, targetMovement)<0) + { + targetMovement *= MathHelper.Clamp(2.0f - dist, 0.0f, 1.0f); + } target.AnimController.IgnorePlatforms = IgnorePlatforms; - if (target.Stun > 0.0f || target.IsDead) + if (target.Stun > 0.0f || target.IsUnconscious || target.IsDead) { target.AnimController.TargetMovement = TargetMovement; } diff --git a/Subsurface/Source/Characters/Animation/Ragdoll.cs b/Subsurface/Source/Characters/Animation/Ragdoll.cs index 11fddad95..cf5c0f741 100644 --- a/Subsurface/Source/Characters/Animation/Ragdoll.cs +++ b/Subsurface/Source/Characters/Animation/Ragdoll.cs @@ -1140,7 +1140,10 @@ namespace Barotrauma public Vector2 GetColliderBottom() { - return collider.SimPosition - Vector2.UnitY * (collider.height / 2 + collider.radius); + float halfHeight = collider.height / 2 + collider.radius; + + return collider.SimPosition + + new Vector2((float)Math.Sin(collider.Rotation), -(float)Math.Cos(collider.Rotation)) * halfHeight; } public Limb FindLowestLimb() diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index c229090cf..7c4f171c3 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -1123,17 +1123,18 @@ namespace Barotrauma } } - if (moveCam) + if (moveCam && needsAir) { - float pressureEffect = 0.0f; - - if (pressureProtection < 80.0f && AnimController.CurrentHull != null && AnimController.CurrentHull.LethalPressure > 50.0f) + if (pressureProtection < 80.0f && + (AnimController.CurrentHull == null || AnimController.CurrentHull.LethalPressure > 50.0f)) { + float pressure = AnimController.CurrentHull == null ? 100.0f : AnimController.CurrentHull.LethalPressure; + cam.Zoom = MathHelper.Lerp(cam.Zoom, - (AnimController.CurrentHull.LethalPressure / 50.0f) * Rand.Range(1.0f, 1.05f), - (AnimController.CurrentHull.LethalPressure - 50.0f) / 50.0f); + (pressure / 50.0f) * Rand.Range(1.0f, 1.05f), + (pressure - 50.0f) / 50.0f); } - cam.OffsetAmount = MathHelper.Lerp(cam.OffsetAmount, (Submarine == null ? 400.0f : 250.0f)+pressureEffect, 0.05f); + cam.OffsetAmount = MathHelper.Lerp(cam.OffsetAmount, 250.0f, 0.05f); } cursorPosition = cam.ScreenToWorld(PlayerInput.MousePosition); diff --git a/Subsurface/Source/Characters/StatusEffect.cs b/Subsurface/Source/Characters/StatusEffect.cs index 7518fa4e7..1ff504b28 100644 --- a/Subsurface/Source/Characters/StatusEffect.cs +++ b/Subsurface/Source/Characters/StatusEffect.cs @@ -16,7 +16,7 @@ namespace Barotrauma } private TargetType targetTypes; - private string[] targetNames; + private HashSet targetNames; private List requiredItems; @@ -26,8 +26,8 @@ namespace Barotrauma private bool setValue; private bool disableDeltaTime; - - private string[] onContainingNames; + + private HashSet onContainingNames; private readonly float duration; @@ -48,12 +48,12 @@ namespace Barotrauma get { return targetTypes; } } - public string[] TargetNames + public HashSet TargetNames { get { return targetNames; } } - public string[] OnContainingNames + public HashSet OnContainingNames { get { return onContainingNames; } } @@ -92,10 +92,10 @@ namespace Barotrauma type = (ActionType)Enum.Parse(typeof(ActionType), split[0], true); string[] containingNames = split[1].Split(','); - onContainingNames = new string[containingNames.Length]; - for (int i =0; i < containingNames.Length; i++) + onContainingNames = new HashSet(); + for (int i = 0; i < containingNames.Length; i++) { - onContainingNames[i] = containingNames[i].Trim(); + onContainingNames.Add(containingNames[i].Trim()); } } @@ -116,10 +116,10 @@ namespace Barotrauma break; case "targetnames": string[] names = attribute.Value.Split(','); - targetNames = new string[names.Length]; + targetNames = new HashSet(); for (int i=0; i < names.Length; i++ ) { - targetNames[i] = names[i].Trim(); + targetNames.Add(names[i].Trim()); } break; case "sound": diff --git a/Subsurface/Source/DebugConsole.cs b/Subsurface/Source/DebugConsole.cs index 913a05290..c21c4158b 100644 --- a/Subsurface/Source/DebugConsole.cs +++ b/Subsurface/Source/DebugConsole.cs @@ -27,7 +27,7 @@ namespace Barotrauma static class DebugConsole { - const int MaxMessages = 100; + const int MaxMessages = 200; public static List Messages = new List(); @@ -757,6 +757,11 @@ namespace Barotrauma //listbox not created yet, don't attempt to add if (listBox == null) return; + if (listBox.children.Count > MaxMessages) + { + listBox.children.RemoveRange(0, listBox.children.Count - MaxMessages); + } + try { var textBlock = new GUITextBlock(new Rectangle(0, 0, listBox.Rect.Width, 0), msg, GUI.Style, Alignment.TopLeft, Alignment.Left, null, true, GUI.SmallFont); diff --git a/Subsurface/Source/Events/Missions/CombatMission.cs b/Subsurface/Source/Events/Missions/CombatMission.cs index 87809baf0..cc2335880 100644 --- a/Subsurface/Source/Events/Missions/CombatMission.cs +++ b/Subsurface/Source/Events/Missions/CombatMission.cs @@ -17,7 +17,12 @@ namespace Barotrauma private string[] descriptions; - private static string[] teamNames; + private static string[] teamNames = { "Team A", "Team B" }; + + public override bool AllowRespawn + { + get { return false; } + } public override string Description { @@ -126,11 +131,6 @@ namespace Barotrauma public override void Start(Level level) { - if (GameMain.Server != null) - { - GameMain.Server.AllowRespawn = false; - } - if (GameMain.NetworkMember == null) { DebugConsole.ThrowError("Combat missions cannot be played in the single player mode."); @@ -154,11 +154,6 @@ namespace Barotrauma { if (crews[0].Count == 0 && crews[1].Count == 0) { - if (GameMain.Server != null) - { - GameMain.Server.AllowRespawn = false; - } - foreach (Character character in Character.CharacterList) { if (character.TeamID == 1) diff --git a/Subsurface/Source/Events/Missions/Mission.cs b/Subsurface/Source/Events/Missions/Mission.cs index 1dd37f692..c6088203a 100644 --- a/Subsurface/Source/Events/Missions/Mission.cs +++ b/Subsurface/Source/Events/Missions/Mission.cs @@ -48,6 +48,11 @@ namespace Barotrauma set { completed = value; } } + public virtual bool AllowRespawn + { + get { return true; } + } + public virtual string RadarLabel { get { return radarLabel; } diff --git a/Subsurface/Source/Items/Components/ItemComponent.cs b/Subsurface/Source/Items/Components/ItemComponent.cs index 2717b54dd..d052621a3 100644 --- a/Subsurface/Source/Items/Components/ItemComponent.cs +++ b/Subsurface/Source/Items/Components/ItemComponent.cs @@ -380,7 +380,7 @@ namespace Barotrauma.Items.Components return; } - List matchingSounds = null; + List matchingSounds; if (!sounds.TryGetValue(type, out matchingSounds)) return; ItemSound itemSound = null; diff --git a/Subsurface/Source/Items/Components/ItemContainer.cs b/Subsurface/Source/Items/Components/ItemContainer.cs index 2d4077476..8846f70c6 100644 --- a/Subsurface/Source/Items/Components/ItemContainer.cs +++ b/Subsurface/Source/Items/Components/ItemContainer.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Xml.Linq; using FarseerPhysics; using Microsoft.Xna.Framework; @@ -14,7 +15,7 @@ namespace Barotrauma.Items.Components List containableItems; public ItemInventory Inventory; - private bool hasStatusEffects; + private List> itemsWithStatusEffects; //how many items can be contained [HasDefaultValue(5, false)] @@ -110,24 +111,39 @@ namespace Barotrauma.Items.Components case "containable": RelatedItem containable = RelatedItem.Load(subElement); if (containable == null) continue; - - foreach (StatusEffect effect in containable.statusEffects) - { - if (effect.type == ActionType.OnContaining) hasStatusEffects = true; - } - + containableItems.Add(containable); break; } } - IsActive = true; + itemsWithStatusEffects = new List>(); } - public void RemoveContained(Item item) + public void OnItemContained(Item item) { - Inventory.RemoveItem(item); + item.SetContainedItemPositions(); + + RelatedItem ri = containableItems.Find(x => x.MatchesItem(item)); + if (ri != null) + { + foreach (StatusEffect effect in ri.statusEffects) + { + itemsWithStatusEffects.Add(Pair.Create(item, effect)); + } + } + + //no need to Update() if this item has no statuseffects and no physics body + IsActive = itemsWithStatusEffects.Count > 0 || item.body != null; + } + + public void OnItemRemoved(Item item) + { + itemsWithStatusEffects.RemoveAll(i => i.First == item); + + //deactivate if the inventory is empty + IsActive = itemsWithStatusEffects.Count > 0 || item.body != null; } public bool CanBeContained(Item item) @@ -138,31 +154,24 @@ namespace Barotrauma.Items.Components public override void Update(float deltaTime, Camera cam) { - if (item.body != null && item.body.FarseerBody.Awake) + if (item.body != null && + item.body.Enabled && + item.body.FarseerBody.Awake) { - foreach (Item contained in Inventory.Items) - { - if (contained == null) continue; - contained.SetTransform(item.SimPosition, 0.0f); - } + item.SetContainedItemPositions(); } - if (!hasStatusEffects) return; - - foreach (Item contained in Inventory.Items) + foreach (Pair itemAndEffect in itemsWithStatusEffects) { - if (contained == null || contained.Condition <= 0.0f) continue; + Item contained = itemAndEffect.First; + if (contained.Condition < 0.0f) continue; - RelatedItem ri = containableItems.Find(x => x.MatchesItem(contained)); - if (ri == null) continue; + StatusEffect effect = itemAndEffect.Second; - foreach (StatusEffect effect in ri.statusEffects) - { - if (effect.Targets.HasFlag(StatusEffect.TargetType.This)) effect.Apply(ActionType.OnContaining, deltaTime, item, item.AllPropertyObjects); - if (effect.Targets.HasFlag(StatusEffect.TargetType.Contained)) effect.Apply(ActionType.OnContaining, deltaTime, item, contained.AllPropertyObjects); - } - - //contained.ApplyStatusEffects(ActionType.OnContained, deltaTime); + if (effect.Targets.HasFlag(StatusEffect.TargetType.This)) + effect.Apply(ActionType.OnContaining, deltaTime, item, item.AllPropertyObjects); + if (effect.Targets.HasFlag(StatusEffect.TargetType.Contained)) + effect.Apply(ActionType.OnContaining, deltaTime, item, contained.AllPropertyObjects); } } @@ -232,15 +241,13 @@ namespace Barotrauma.Items.Components public override bool Combine(Item item) { - if (containableItems.Find(x => x.MatchesItem(item)) == null) return false; + if (!containableItems.Any(x => x.MatchesItem(item))) return false; if (Inventory.TryPutItem(item)) { IsActive = true; - if (hideItems || (item.body!=null && !item.body.Enabled)) item.body.Enabled = false; - - //item.Container = this.item; - + if (hideItems && item.body != null) item.body.Enabled = false; + return true; } diff --git a/Subsurface/Source/Items/Components/Power/PowerTransfer.cs b/Subsurface/Source/Items/Components/Power/PowerTransfer.cs index 4fe57217a..d7257c601 100644 --- a/Subsurface/Source/Items/Components/Power/PowerTransfer.cs +++ b/Subsurface/Source/Items/Components/Power/PowerTransfer.cs @@ -22,7 +22,9 @@ namespace Barotrauma.Items.Components //affects how fast changes in power/load are carried over the grid static float inertia = 5.0f; - static List connectedList = new List(); + static HashSet connectedList = new HashSet(); + + private List powerConnections; private float powerLoad; @@ -35,24 +37,27 @@ namespace Barotrauma.Items.Components : base(item, element) { IsActive = true; + + powerConnections = new List(); } public override void Update(float deltaTime, Camera cam) { - //reset and recalculate the power generated/consumed - //by the constructions connected to the grid - fullPower = 0.0f; - fullLoad = 0.0f; - connectedList.Clear(); - if (updateTimer > 0) { + //this junction box has already been updated this frame updateTimer--; return; } - + + //reset and recalculate the power generated/consumed + //by the constructions connected to the grid + fullPower = 0.0f; + fullLoad = 0.0f; + updateTimer = 0; + connectedList.Clear(); + CheckJunctions(deltaTime); - updateTimer = 0; foreach (Powered p in connectedList) { @@ -68,8 +73,7 @@ namespace Barotrauma.Items.Components //(except if running as a client) if (GameMain.Client != null) continue; if (-pt.currPowerConsumption < Math.Max(pt.powerLoad * Rand.Range(1.9f,2.1f), 200.0f)) continue; - - + float prevCondition = pt.item.Condition; pt.item.Condition -= deltaTime * 10.0f; @@ -109,37 +113,31 @@ namespace Barotrauma.Items.Components ApplyStatusEffects(ActionType.OnActive, deltaTime, null); - List connections = item.Connections; - if (connections == null) return; - - foreach (Connection c in connections) + foreach (Connection c in powerConnections) { - if (!c.IsPower) continue; - var recipients = c.Recipients; foreach (Connection recipient in recipients) { - if (recipient == null || !c.IsPower) continue; + if (recipient == null) continue; Item it = recipient.Item; if (it == null) continue; - //if (it.Updated) continue; - Powered powered = it.GetComponent(); if (powered == null || !powered.IsActive) continue; if (connectedList.Contains(powered)) continue; PowerTransfer powerTransfer = powered as PowerTransfer; - PowerContainer powerContainer = powered as PowerContainer; if (powerTransfer != null) { - //if (powerTransfer.updateTimer>0) continue; powerTransfer.CheckJunctions(deltaTime); + continue; } - else if (powerContainer != null) + + PowerContainer powerContainer = powered as PowerContainer; + if (powerContainer != null) { if (recipient.Name == "power_in") { @@ -187,6 +185,19 @@ namespace Barotrauma.Items.Components GuiFrame.Update(1.0f / 60.0f); } + public override void OnMapLoaded() + { + var connections = item.Connections; + if (connections == null) + { + IsActive = false; + return; + } + + powerConnections = connections.FindAll(c => c.IsPower); + if (powerConnections.Count == 0) IsActive = false; + } + public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item sender, float power) { base.ReceiveSignal(stepsTaken, signal, connection, sender, power); diff --git a/Subsurface/Source/Items/Components/Signal/Wire.cs b/Subsurface/Source/Items/Components/Signal/Wire.cs index 70236b762..0240050dc 100644 --- a/Subsurface/Source/Items/Components/Signal/Wire.cs +++ b/Subsurface/Source/Items/Components/Signal/Wire.cs @@ -10,6 +10,47 @@ namespace Barotrauma.Items.Components { class Wire : ItemComponent, IDrawableComponent { + class WireSection + { + private Vector2 start; + + private float angle; + private float length; + + public WireSection(Vector2 start, Vector2 end) + { + this.start = start; + + angle = MathUtils.VectorToAngle(end - start); + length = Vector2.Distance(start, end); + } + + public void Draw(SpriteBatch spriteBatch, Color color, Vector2 offset, float depth, float width = 0.3f) + { + spriteBatch.Draw(wireSprite.Texture, + new Vector2(start.X+offset.X, -(start.Y+offset.Y)), null, color, + -angle, + new Vector2(0.0f, wireSprite.size.Y / 2.0f), + new Vector2(length / wireSprite.Texture.Width, width), + SpriteEffects.None, + depth); + } + + public static void Draw(SpriteBatch spriteBatch, Vector2 start, Vector2 end, Color color, float depth, float width = 0.3f) + { + start.Y = -start.Y; + end.Y = -end.Y; + + spriteBatch.Draw(wireSprite.Texture, + start, null, color, + MathUtils.VectorToAngle(end - start), + new Vector2(0.0f, wireSprite.size.Y / 2.0f), + new Vector2((Vector2.Distance(start, end)) / wireSprite.Texture.Width, width), + SpriteEffects.None, + depth); + } + } + const float nodeDistance = 32.0f; const float heightFromFloor = 128.0f; @@ -17,6 +58,8 @@ namespace Barotrauma.Items.Components public List Nodes; + private List sections; + Connection[] connections; private Vector2 newNodePos; @@ -39,22 +82,15 @@ namespace Barotrauma.Items.Components wireSprite = new Sprite("Content/Items/wireHorizontal.png", new Vector2(0.5f, 0.5f)); wireSprite.Depth = 0.85f; } - + Nodes = new List(); + sections = new List(); connections = new Connection[2]; - + IsActive = false; } - public override void Move(Vector2 amount) - { - //for (int i = 0; i < Nodes.Count; i++) - //{ - // Nodes[i] += amount; - //} - } - public Connection OtherConnection(Connection connection) { if (connection == null) return null; @@ -125,25 +161,23 @@ namespace Barotrauma.Items.Components if (Nodes.Count > 0 && Nodes[0] == newConnection.Item.Position - newConnection.Item.Submarine.HiddenSubPosition) break; if (Nodes.Count > 1 && Nodes[Nodes.Count-1] == newConnection.Item.Position - newConnection.Item.Submarine.HiddenSubPosition) break; - - + if (i == 0) { - Nodes.Insert(0, newConnection.Item.Position - newConnection.Item.Submarine.HiddenSubPosition); + Nodes.Insert(0, newConnection.Item.Position - newConnection.Item.Submarine.HiddenSubPosition); } else { Nodes.Add(newConnection.Item.Position - newConnection.Item.Submarine.HiddenSubPosition); } - + break; } if (connections[0] != null && connections[1] != null) { - //List prevNodes = new List(Nodes); foreach (ItemComponent ic in item.components) { if (ic == this) continue; @@ -155,12 +189,12 @@ namespace Barotrauma.Items.Components IsActive = false; - //Nodes = prevNodes; CleanNodes(); } Drawable = Nodes.Any(); - + + UpdateSections(); return true; } @@ -190,28 +224,11 @@ namespace Barotrauma.Items.Components { if (Nodes.Count == 0) return; - //item.FindHull(); - - //Vector2 position = item.Position; - - //position.X = MathUtils.Round(item.Position.X, nodeDistance); - //if (item.CurrentHull == null) - //{ - // position.Y = MathUtils.Round(item.Position.Y, nodeDistance); - //} - //else - //{ - // position.Y -= item.CurrentHull.Rect.Y - item.CurrentHull.Rect.Height; - // position.Y = Math.Max(MathUtils.Round(position.Y, nodeDistance), heightFromFloor); - // position.Y += item.CurrentHull.Rect.Y - item.CurrentHull.Rect.Height; - //} - - Submarine sub = null; if (connections[0] != null && connections[0].Item.Submarine != null) sub = connections[0].Item.Submarine; if (connections[1] != null && connections[1].Item.Submarine != null) sub = connections[1].Item.Submarine; - if (item.Submarine != sub) + if (item.Submarine != sub && Screen.Selected != GameMain.EditMapScreen) { ClearConnections(); Nodes.Clear(); @@ -219,20 +236,6 @@ namespace Barotrauma.Items.Components } newNodePos = RoundNode(item.Position, item.CurrentHull) - sub.HiddenSubPosition; - - //if (Vector2.Distance(position, nodes[nodes.Count - 1]) > nodeDistance*10) - //{ - // nodes.Add(position); - - // item.NewComponentEvent(this, true); - //} - //else if (Math.Abs(position.Y - nodes[nodes.Count - 1].Y) > nodeDistance) - //{ - // nodes.Add(new Vector2(nodes[nodes.Count - 1].X, - // position.Y)); - - // item.NewComponentEvent(this, true); - //} } public override bool Use(float deltaTime, Character character = null) @@ -242,6 +245,8 @@ namespace Barotrauma.Items.Components if (newNodePos!= Vector2.Zero && Nodes.Count>0 && Vector2.Distance(newNodePos, Nodes[Nodes.Count - 1]) > nodeDistance) { Nodes.Add(newNodePos); + UpdateSections(); + Drawable = true; newNodePos = Vector2.Zero; @@ -254,6 +259,7 @@ namespace Barotrauma.Items.Components if (Nodes.Count > 1) { Nodes.RemoveAt(Nodes.Count - 1); + UpdateSections(); } Drawable = Nodes.Any(); @@ -266,9 +272,20 @@ namespace Barotrauma.Items.Components return true; } + public void UpdateSections() + { + sections.Clear(); + + for (int i = 0; i < Nodes.Count-1; i++) + { + sections.Add(new WireSection(Nodes[i], Nodes[i + 1])); + } + } + private void ClearConnections() { Nodes.Clear(); + sections.Clear(); for (int i = 0; i < 2; i++) { @@ -288,8 +305,6 @@ namespace Barotrauma.Items.Components { if (Screen.Selected == GameMain.EditMapScreen) { - //position = GameMain.EditMapScreen.Cam.ScreenToWorld(PlayerInput.MousePosition) - Submarine.Loaded.Position;// Nodes[(int)selectedNodeIndex]; - position.X = MathUtils.Round(position.X, Submarine.GridSize.X / 2.0f); position.Y = MathUtils.Round(position.Y, Submarine.GridSize.Y / 2.0f); } @@ -345,35 +360,42 @@ namespace Barotrauma.Items.Components public void Draw(SpriteBatch spriteBatch, bool editing) { - //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); - //} - if (!Nodes.Any()) { Drawable = false; return; } + Vector2 drawOffset = Vector2.Zero; + if (item.Submarine != null) + { + drawOffset = item.Submarine.DrawPosition + item.Submarine.HiddenSubPosition; + } + + float depth = wireSprite.Depth + ((item.ID % 100) * 0.00001f); + if (item.IsHighlighted) { - for (int i = 1; i < Nodes.Count; i++) + foreach (WireSection section in sections) { - DrawSection(spriteBatch, Nodes[i], Nodes[i - 1], Color.Gold, 0.5f); + section.Draw(spriteBatch, Color.Gold, drawOffset, depth, 0.5f); } } - for (int i = 1; i < Nodes.Count; i++) + foreach (WireSection section in sections) { - DrawSection(spriteBatch, Nodes[i], Nodes[i - 1], item.Color); + section.Draw(spriteBatch, item.Color, drawOffset, depth, 0.3f); } - - + if (IsActive && Vector2.Distance(newNodePos, Nodes[Nodes.Count - 1]) > nodeDistance) { - DrawSection(spriteBatch, Nodes[Nodes.Count - 1], newNodePos, item.Color * 0.5f); - //nodes.Add(newNodePos); + WireSection.Draw( + spriteBatch, + new Vector2(Nodes[Nodes.Count - 1].X, Nodes[Nodes.Count - 1].Y) + drawOffset, + new Vector2(newNodePos.X, newNodePos.Y) + drawOffset, + item.Color * 0.5f, + depth, + 0.3f); } if (!editing || !PlayerInput.MouseInsideWindow || !GameMain.EditMapScreen.WiringMode) return; @@ -395,7 +417,6 @@ namespace Barotrauma.Items.Components continue; } - GUI.DrawRectangle(spriteBatch, worldPos + new Vector2(-10, -10), new Vector2(20, 20), Color.Red, false, 0.0f); if (selectedNodeIndex == null && draggingWire == null)// && !MapEntity.SelectedAny) @@ -447,26 +468,6 @@ namespace Barotrauma.Items.Components } } - private void DrawSection(SpriteBatch spriteBatch, Vector2 start, Vector2 end, Color color, float width = 0.3f) - { - if (item.Submarine != null) - { - start += item.Submarine.DrawPosition + item.Submarine.HiddenSubPosition; - end += item.Submarine.DrawPosition + item.Submarine.HiddenSubPosition; - } - - start.Y = -start.Y; - end.Y = -end.Y; - - spriteBatch.Draw(wireSprite.Texture, - start, null, color, - MathUtils.VectorToAngle(end - start), - new Vector2(0.0f, wireSprite.size.Y / 2.0f), - new Vector2((Vector2.Distance(start, end)) / wireSprite.Texture.Width, width), - SpriteEffects.None, - wireSprite.Depth + ((item.ID % 100) * 0.00001f)); - } - public override void FlipX() { for (int i = 0; i < Nodes.Count; i++) diff --git a/Subsurface/Source/Items/Components/Wearable.cs b/Subsurface/Source/Items/Components/Wearable.cs index adb195e10..0c828a61c 100644 --- a/Subsurface/Source/Items/Components/Wearable.cs +++ b/Subsurface/Source/Items/Components/Wearable.cs @@ -168,9 +168,8 @@ namespace Barotrauma.Items.Components public override void Update(float deltaTime, Camera cam) { - base.Update(deltaTime, cam); - item.SetTransform(picker.SimPosition, 0.0f); + item.SetContainedItemPositions(); ApplyStatusEffects(ActionType.OnWearing, deltaTime, picker); diff --git a/Subsurface/Source/Items/Item.cs b/Subsurface/Source/Items/Item.cs index 856681e8a..d1f52bcdf 100644 --- a/Subsurface/Source/Items/Item.cs +++ b/Subsurface/Source/Items/Item.cs @@ -32,8 +32,8 @@ namespace Barotrauma private ItemPrefab prefab; public static bool ShowLinks = true; - - private List tags; + + private HashSet tags; public Hull CurrentHull; @@ -52,6 +52,9 @@ namespace Barotrauma private bool inWater; private Inventory parentInventory; + private Inventory ownInventory; + + private Dictionary connections; //a dictionary containing lists of the status effects in all the components of the item private Dictionary> statusEffectLists; @@ -276,8 +279,7 @@ namespace Barotrauma { get { - ItemContainer c = GetComponent(); - return (c == null) ? null : Array.FindAll(c.Inventory.Items, i=>i!=null); + return (ownInventory == null) ? null : Array.FindAll(ownInventory.Items, i => i != null); } } @@ -327,7 +329,7 @@ namespace Barotrauma components = new List(); drawableComponents = new List(); FixRequirements = new List(); - tags = new List(); + tags = new HashSet(); rect = newRect; @@ -402,6 +404,12 @@ namespace Barotrauma if (body != null) body.FarseerBody.OnCollision += OnCollision; } + var itemContainer = GetComponent(); + if (itemContainer!=null) + { + ownInventory = itemContainer.Inventory; + } + InsertToList(); ItemList.Add(this); } @@ -429,15 +437,16 @@ namespace Barotrauma public void RemoveContained(Item contained) { - ItemContainer c = GetComponent(); - if (c == null) return; - - c.RemoveContained(contained); + if (ownInventory != null) + { + ownInventory.RemoveItem(contained); + } + contained.Container = null; } - public void SetTransform(Vector2 simPosition, float rotation) + public void SetTransform(Vector2 simPosition, float rotation, bool findNewHull = true) { if (body != null) { @@ -458,7 +467,7 @@ namespace Barotrauma rect.X = (int)(displayPos.X - rect.Width / 2.0f); rect.Y = (int)(displayPos.Y + rect.Height / 2.0f); - FindHull(); + if (findNewHull) FindHull(); } public override void Move(Vector2 amount) @@ -545,6 +554,33 @@ namespace Barotrauma return rootContainer; } + + public void SetContainedItemPositions() + { + if (ownInventory == null) return; + + Vector2 simPos = SimPosition; + Vector2 displayPos = Position; + + foreach (Item contained in ownInventory.Items) + { + if (contained == null) continue; + + if (contained.body != null) + { + contained.body.FarseerBody.SetTransformIgnoreContacts(ref simPos, 0.0f); + } + + contained.Rect = + new Rectangle( + (int)(displayPos.X - contained.Rect.Width / 2.0f), + (int)(displayPos.Y + contained.Rect.Height / 2.0f), + contained.Rect.Width, contained.Rect.Height); + + contained.Submarine = Submarine; + contained.CurrentHull = CurrentHull; + } + } public void AddTag(string tag) { @@ -572,7 +608,7 @@ namespace Barotrauma ApplyStatusEffect(effect, type, deltaTime, character); } } - + public void ApplyStatusEffect(StatusEffect effect, ActionType type, float deltaTime, Character character = null) { if (condition == 0.0f && effect.type != ActionType.OnBroken) return; @@ -581,16 +617,15 @@ namespace Barotrauma bool hasTargets = (effect.TargetNames == null); Item[] containedItems = ContainedItems; - if (effect.OnContainingNames!=null) + if (effect.OnContainingNames != null) { foreach (string s in effect.OnContainingNames) { - if (containedItems.FirstOrDefault(x => x!=null && x.Name==s && x.Condition>0.0f) == null) return; + if (!containedItems.Any(x => x!=null && x.Name==s && x.Condition > 0.0f)) return; } } List targets = new List(); - if (containedItems != null) { if (effect.Targets.HasFlag(StatusEffect.TargetType.Contained)) @@ -692,8 +727,7 @@ namespace Barotrauma { ic.Update(deltaTime, cam); - if (ic.IsActive) ic.PlaySound(ActionType.OnActive, WorldPosition); - //ic.ApplyStatusEffects(ActionType.OnActive, deltaTime, null); + if (ic.IsActive) ic.PlaySound(ActionType.OnActive, WorldPosition); } else { @@ -704,8 +738,8 @@ namespace Barotrauma inWater = IsInWater(); if (inWater) ApplyStatusEffects(ActionType.InWater, deltaTime); - isHighlighted = false; - + isHighlighted = false; + if (body == null || !body.Enabled) return; if (Math.Abs(body.LinearVelocity.X) > 0.01f || Math.Abs(body.LinearVelocity.Y) > 0.01f) @@ -723,11 +757,11 @@ namespace Barotrauma body.SetTransform(body.SimPosition - Submarine.SimPosition, body.Rotation); } - Vector2 moveAmount = body.SimPosition - body.LastSentPosition; - if (parentInventory == null && moveAmount != Vector2.Zero && moveAmount.Length() > NetConfig.ItemPosUpdateDistance) - { - - } + //Vector2 moveAmount = body.SimPosition - body.LastSentPosition; + //if (parentInventory == null && moveAmount != Vector2.Zero && moveAmount.Length() > NetConfig.ItemPosUpdateDistance) + //{ + // new NetworkEvent(NetworkEventType.PhysicsBodyPosition, ID, false); + //} Vector2 displayPos = ConvertUnits.ToDisplayUnits(body.SimPosition); rect.X = (int)(displayPos.X - rect.Width / 2.0f); @@ -1152,25 +1186,23 @@ namespace Barotrauma public void SendSignal(int stepsTaken, string signal, string connectionName, float power = 0.0f) { + if (connections == null) return; + stepsTaken++; - ConnectionPanel panel = GetComponent(); - if (panel == null) return; - foreach (Connection c in panel.Connections) + Connection c = null; + if (!connections.TryGetValue(connectionName, out c)) return; + + if (stepsTaken > 10) { - if (c.Name != connectionName) continue; - - if (stepsTaken > 10) - { - //use a coroutine to prevent infinite loops by creating a one - //frame delay if the "signal chain" gets too long - CoroutineManager.StartCoroutine(SendSignal(signal, c, power)); - } - else - { - c.SendSignal(stepsTaken, signal, this, power); - } + //use a coroutine to prevent infinite loops by creating a one + //frame delay if the "signal chain" gets too long + CoroutineManager.StartCoroutine(SendSignal(signal, c, power)); } + else + { + c.SendSignal(stepsTaken, signal, this, power); + } } private IEnumerable SendSignal(string signal, Connection connection, float power = 0.0f) @@ -1178,9 +1210,6 @@ namespace Barotrauma //wait one frame yield return CoroutineStatus.Running; - ConnectionPanel panel = GetComponent(); - if (panel == null) yield return CoroutineStatus.Success; - connection.SendSignal(0, signal, this, power); yield return CoroutineStatus.Success; @@ -1760,7 +1789,18 @@ namespace Barotrauma foreach (ItemComponent ic in components) { ic.OnMapLoaded(); - } + } + + //cache connections into a dictionary for faster lookups + var connectionPanel = GetComponent(); + connections = new Dictionary(); + + if (connectionPanel == null) return; + foreach (Connection c in connectionPanel.Connections) + { + if (!connections.ContainsKey(c.Name)) + connections.Add(c.Name, c); + } } diff --git a/Subsurface/Source/Items/ItemInventory.cs b/Subsurface/Source/Items/ItemInventory.cs index d2fd5c567..18e8a1cde 100644 --- a/Subsurface/Source/Items/ItemInventory.cs +++ b/Subsurface/Source/Items/ItemInventory.cs @@ -44,6 +44,28 @@ namespace Barotrauma return (item!=null && Items[i]==null && container.CanBeContained(item)); } + + public override bool TryPutItem(Item item, System.Collections.Generic.List allowedSlots = null) + { + bool wasPut = base.TryPutItem(item, allowedSlots); + + if (wasPut) + { + foreach (Character c in Character.CharacterList) + { + if (!c.HasSelectedItem(item)) continue; + + item.Unequip(c); + break; + } + + container.IsActive = true; + container.OnItemContained(item); + } + + return wasPut; + } + public override bool TryPutItem(Item item, int i, bool allowSwapping) { bool wasPut = base.TryPutItem(item, i, allowSwapping); @@ -57,11 +79,18 @@ namespace Barotrauma item.Unequip(c); break; } - //item.Container = container.Item; + container.IsActive = true; + container.OnItemContained(item); } + return wasPut; } + public override void RemoveItem(Item item) + { + base.RemoveItem(item); + container.OnItemRemoved(item); + } } } diff --git a/Subsurface/Source/Map/Submarine.cs b/Subsurface/Source/Map/Submarine.cs index ddb735ad9..8f08fbb4f 100644 --- a/Subsurface/Source/Map/Submarine.cs +++ b/Subsurface/Source/Map/Submarine.cs @@ -60,6 +60,8 @@ namespace Barotrauma } private static List loaded = new List(); + private static List visibleEntities; + private SubmarineBody subBody; public readonly List DockedTo; @@ -297,34 +299,71 @@ namespace Barotrauma } //drawing ---------------------------------------------------- + + public static void CullEntities(Camera cam) + { + List visibleSubs = new List(); + foreach (Submarine sub in Submarine.Loaded) + { + Rectangle worldBorders = new Rectangle( + sub.Borders.X + (int)sub.WorldPosition.X - 500, + sub.Borders.Y + (int)sub.WorldPosition.Y + 500, + sub.Borders.Width + 1000, + sub.Borders.Height + 1000); + + + if (Submarine.RectsOverlap(worldBorders, cam.WorldView)) + { + visibleSubs.Add(sub); + } + } + + visibleEntities = new List(); + foreach (MapEntity me in MapEntity.mapEntityList) + { + if (me.Submarine == null || visibleSubs.Contains(me.Submarine)) + { + visibleEntities.Add(me); + } + } + } public static void Draw(SpriteBatch spriteBatch, bool editing = false) { - for (int i = 0; i < MapEntity.mapEntityList.Count; i++ ) + var entitiesToRender = !editing && visibleEntities != null ? visibleEntities : MapEntity.mapEntityList; + + foreach (MapEntity e in entitiesToRender) { - MapEntity.mapEntityList[i].Draw(spriteBatch, editing); + e.Draw(spriteBatch, editing); } } public static void DrawFront(SpriteBatch spriteBatch, bool editing = false, Predicate predicate = null) { - for (int i = 0; i < MapEntity.mapEntityList.Count; i++) + var entitiesToRender = !editing && visibleEntities != null ? visibleEntities : MapEntity.mapEntityList; + + foreach (MapEntity e in entitiesToRender) { - if (!MapEntity.mapEntityList[i].DrawOverWater) continue; - + if (!e.DrawOverWater) continue; if (predicate != null) { - if (!predicate(MapEntity.mapEntityList[i])) continue; + if (!predicate(e)) continue; } - MapEntity.mapEntityList[i].Draw(spriteBatch, editing, false); + e.Draw(spriteBatch, editing, false); } if (GameMain.DebugDraw) { foreach (Submarine sub in Submarine.Loaded) { + Rectangle worldBorders = sub.Borders; + worldBorders.Location += sub.WorldPosition.ToPoint(); + worldBorders.Y = -worldBorders.Y; + + GUI.DrawRectangle(spriteBatch, worldBorders, Color.White, 5); + if (sub.subBody.MemPos.Count < 2) continue; Vector2 prevPos = ConvertUnits.ToDisplayUnits(sub.subBody.MemPos[0].Position); @@ -346,10 +385,12 @@ namespace Barotrauma public static void DrawDamageable(SpriteBatch spriteBatch, Effect damageEffect, bool editing = false) { - for (int i = 0; i < MapEntity.mapEntityList.Count; i++) + var entitiesToRender = !editing && visibleEntities != null ? visibleEntities : MapEntity.mapEntityList; + + foreach (MapEntity e in entitiesToRender) { - if (MapEntity.mapEntityList[i].DrawDamageEffect) - MapEntity.mapEntityList[i].DrawDamage(spriteBatch, damageEffect); + if (e.DrawDamageEffect) + e.DrawDamage(spriteBatch, damageEffect); } if (damageEffect != null) { @@ -361,16 +402,18 @@ namespace Barotrauma public static void DrawBack(SpriteBatch spriteBatch, bool editing = false, Predicate predicate = null) { - for (int i = 0; i < MapEntity.mapEntityList.Count; i++) + var entitiesToRender = !editing && visibleEntities != null ? visibleEntities : MapEntity.mapEntityList; + + foreach (MapEntity e in entitiesToRender) { - if (!MapEntity.mapEntityList[i].DrawBelowWater) continue; + if (!e.DrawBelowWater) continue; if (predicate != null) { - if (!predicate(MapEntity.mapEntityList[i])) continue; + if (!predicate(e)) continue; } - MapEntity.mapEntityList[i].Draw(spriteBatch, editing, true); + e.Draw(spriteBatch, editing, true); } } @@ -622,7 +665,11 @@ namespace Barotrauma subBody.Update(deltaTime); - if (this != MainSub && MainSub.DockedTo.Contains(this)) return; + for (int i = 0; i < 2; i++ ) + { + if (Submarine.MainSubs[i] == null) continue; + if (this != Submarine.MainSubs[i] && Submarine.MainSubs[i].DockedTo.Contains(this)) return; + } //send updates more frequently if moving fast networkUpdateTimer -= MathHelper.Clamp(Velocity.Length()*10.0f, 0.1f, 5.0f) * deltaTime; @@ -994,6 +1041,7 @@ namespace Barotrauma { wire.Nodes[i] -= center; } + wire.UpdateSections(); } for (int i = 0; i < MapEntity.mapEntityList.Count; i++) @@ -1086,6 +1134,8 @@ namespace Barotrauma loaded.Clear(); + visibleEntities = null; + if (GameMain.GameScreen.Cam != null) GameMain.GameScreen.Cam.TargetPos = Vector2.Zero; Entity.RemoveAll(); @@ -1105,6 +1155,8 @@ namespace Barotrauma subBody = null; + visibleEntities = null; + if (MainSub == this) MainSub = null; if (MainSubs[1] == this) MainSubs[1] = null; diff --git a/Subsurface/Source/Networking/GameServer.cs b/Subsurface/Source/Networking/GameServer.cs index 7e74b1c8a..b6bbc6998 100644 --- a/Subsurface/Source/Networking/GameServer.cs +++ b/Subsurface/Source/Networking/GameServer.cs @@ -871,7 +871,11 @@ namespace Barotrauma.Networking GameServer.Log("Game mode: " + selectedMode.Name, Color.Cyan); GameServer.Log("Level seed: " + GameMain.NetLobbyScreen.LevelSeed, Color.Cyan); - if (AllowRespawn) respawnManager = new RespawnManager(this, selectedShuttle); + bool missionAllowRespawn = + !(GameMain.GameSession.gameMode is MissionMode) || + ((MissionMode)GameMain.GameSession.gameMode).Mission.AllowRespawn; + + if (AllowRespawn && missionAllowRespawn) respawnManager = new RespawnManager(this, selectedShuttle); AssignJobs(connectedClients, characterInfo != null); @@ -971,7 +975,11 @@ namespace Barotrauma.Networking msg.Write(selectedMode.Name); - msg.Write(AllowRespawn); + bool missionAllowRespawn = + !(GameMain.GameSession.gameMode is MissionMode) || + ((MissionMode)GameMain.GameSession.gameMode).Mission.AllowRespawn; + + msg.Write(AllowRespawn && missionAllowRespawn); msg.Write(Submarine.MainSubs[1] != null); //loadSecondSub msg.Write(client.Character.ID); diff --git a/Subsurface/Source/Physics/PhysicsBody.cs b/Subsurface/Source/Physics/PhysicsBody.cs index 6c739d1eb..dbde6a2db 100644 --- a/Subsurface/Source/Physics/PhysicsBody.cs +++ b/Subsurface/Source/Physics/PhysicsBody.cs @@ -333,6 +333,11 @@ namespace Barotrauma public void SetTransform(Vector2 position, float rotation) { + System.Diagnostics.Debug.Assert(MathUtils.IsValid(position)); + System.Diagnostics.Debug.Assert(Math.Abs(position.X) < 1000000.0f); + System.Diagnostics.Debug.Assert(Math.Abs(position.Y) < 1000000.0f); + + body.SetTransform(position, rotation); SetPrevTransform(position, rotation); } diff --git a/Subsurface/Source/Program.cs b/Subsurface/Source/Program.cs index 09448f029..ebda383c2 100644 --- a/Subsurface/Source/Program.cs +++ b/Subsurface/Source/Program.cs @@ -116,9 +116,7 @@ namespace Barotrauma { #if WINDOWS MessageBox.Show(message, "Oops! Barotrauma just crashed.", MessageBoxButtons.OK, MessageBoxIcon.Error); -#endif - - Sounds.SoundManager.Dispose(); +#endif } static void CrashDump(GameMain game, string filePath, Exception exception) diff --git a/Subsurface/Source/Screens/GameScreen.cs b/Subsurface/Source/Screens/GameScreen.cs index 4bcd50017..bd5068a03 100644 --- a/Subsurface/Source/Screens/GameScreen.cs +++ b/Subsurface/Source/Screens/GameScreen.cs @@ -5,6 +5,7 @@ using Microsoft.Xna.Framework.Input; using Barotrauma.Lights; using System.Diagnostics; using Microsoft.Xna.Framework.Content; +using System.Collections.Generic; namespace Barotrauma { @@ -115,6 +116,7 @@ namespace Barotrauma closestSub.ApplyForce(targetMovement * closestSub.SubBody.Body.Mass * 100.0f); } #endif + if (GameMain.GameSession != null) GameMain.GameSession.Update((float)deltaTime); if (Level.Loaded != null) Level.Loaded.Update((float)deltaTime); @@ -165,18 +167,17 @@ namespace Barotrauma GameMain.World.Step((float)deltaTime); - if (!PlayerInput.LeftButtonHeld()) { Inventory.draggingSlot = null; Inventory.draggingItem = null; } - } public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch) { cam.UpdateTransform(true); + Submarine.CullEntities(cam); DrawMap(graphics, spriteBatch); @@ -222,7 +223,22 @@ namespace Barotrauma { GameMain.LightManager.UpdateObstructVision(graphics, spriteBatch, cam, Character.Controlled.CursorWorldPosition); } - + + List visibleSubs = new List(); + foreach (Submarine sub in Submarine.Loaded) + { + Rectangle worldBorders = new Rectangle( + sub.Borders.X + (int)sub.WorldPosition.X - 500, + sub.Borders.Y + (int)sub.WorldPosition.Y + 500, + sub.Borders.Width + 1000, + sub.Borders.Height + 1000); + + + if (Submarine.RectsOverlap(worldBorders, cam.WorldView)) + { + visibleSubs.Add(sub); + } + } //---------------------------------------------------------------------------------------- //1. draw the background, characters and the parts of the submarine that are behind them @@ -341,7 +357,7 @@ namespace Barotrauma null, null, null, cam.Transform); - Submarine.DrawDamageable(spriteBatch, null); + Submarine.DrawDamageable(spriteBatch, null, false); Submarine.DrawFront(spriteBatch, false, s => s is Structure); spriteBatch.End(); @@ -375,7 +391,7 @@ namespace Barotrauma null, null, null, cam.Transform); - Submarine.DrawFront(spriteBatch); + Submarine.DrawFront(spriteBatch, false, null); spriteBatch.End(); @@ -385,7 +401,7 @@ namespace Barotrauma damageEffect, cam.Transform); - Submarine.DrawDamageable(spriteBatch, damageEffect); + Submarine.DrawDamageable(spriteBatch, damageEffect, false); spriteBatch.End(); diff --git a/Subsurface/changelog.txt b/Subsurface/changelog.txt index a751f2378..2493dfda0 100644 --- a/Subsurface/changelog.txt +++ b/Subsurface/changelog.txt @@ -1,6 +1,19 @@ +--------------------------------------------------------------------------------------------------------- +v0.5.3.2 +--------------------------------------------------------------------------------------------------------- + +- fixed character colliders occasionally getting stuck inside walls when switching from swimming to +walking or standing up after being unconscious +- wires can be dragged outside the sub in the editor without disconnecting them +- easier to climb over small obstacles +- combat missions don't reset the "allow respawn" setting +- submarines outside the camera view aren't rendered +- coelanth collider fix + --------------------------------------------------------------------------------------------------------- v0.5.3.1 --------------------------------------------------------------------------------------------------------- + - fixed monster movement! ---------------------------------------------------------------------------------------------------------