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