diff --git a/Subsurface/Content/Items/Clothes/clothes.xml b/Subsurface/Content/Items/Clothes/clothes.xml index edeadde3a..e5cc154a9 100644 --- a/Subsurface/Content/Items/Clothes/clothes.xml +++ b/Subsurface/Content/Items/Clothes/clothes.xml @@ -18,12 +18,12 @@ pickdistance="150" tags="smallitem"> - + - + - - + + @@ -38,11 +38,11 @@ pickdistance="150" tags="smallitem"> - + - + - + diff --git a/Subsurface/Content/Items/Diving/divinggear.xml b/Subsurface/Content/Items/Diving/divinggear.xml index 61308838c..de9b788c9 100644 --- a/Subsurface/Content/Items/Diving/divinggear.xml +++ b/Subsurface/Content/Items/Diving/divinggear.xml @@ -20,7 +20,7 @@ pickdistance="200" price="50"> - + @@ -42,7 +42,7 @@ pickdistance="200" price="200"> - + diff --git a/Subsurface/Content/Items/Tools/tools.xml b/Subsurface/Content/Items/Tools/tools.xml index b3dc02f3c..1e6441e34 100644 --- a/Subsurface/Content/Items/Tools/tools.xml +++ b/Subsurface/Content/Items/Tools/tools.xml @@ -77,7 +77,7 @@ - + diff --git a/Subsurface/Content/Items/Weapons/explosives.xml b/Subsurface/Content/Items/Weapons/explosives.xml index 498457a59..bcf007454 100644 --- a/Subsurface/Content/Items/Weapons/explosives.xml +++ b/Subsurface/Content/Items/Weapons/explosives.xml @@ -11,8 +11,8 @@ - - + + diff --git a/Subsurface/Content/Items/Weapons/railgun.xml b/Subsurface/Content/Items/Weapons/railgun.xml index 4284d886e..3431add15 100644 --- a/Subsurface/Content/Items/Weapons/railgun.xml +++ b/Subsurface/Content/Items/Weapons/railgun.xml @@ -51,7 +51,7 @@ - + @@ -63,14 +63,17 @@ - + - + + + + diff --git a/Subsurface/Content/Items/idcard.xml b/Subsurface/Content/Items/idcard.xml index 7446e6d77..045bd351d 100644 --- a/Subsurface/Content/Items/idcard.xml +++ b/Subsurface/Content/Items/idcard.xml @@ -5,7 +5,7 @@ Tags="smallitem" pickdistance="150"> - + diff --git a/Subsurface/Content/Particles/ParticlePrefabs.xml b/Subsurface/Content/Particles/ParticlePrefabs.xml index 578505a2c..368ffdcf3 100644 --- a/Subsurface/Content/Particles/ParticlePrefabs.xml +++ b/Subsurface/Content/Particles/ParticlePrefabs.xml @@ -87,10 +87,10 @@ @@ -98,10 +98,10 @@ diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index 39f86d427..34cb71ed4 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -34,7 +34,7 @@ namespace Subsurface public readonly bool IsNetworkPlayer; - private Inventory inventory; + private CharacterInventory inventory; public double LastNetworkUpdate; @@ -66,6 +66,7 @@ namespace Subsurface protected float maxHealth; protected Item closestItem; + private Character closestCharacter, selectedCharacter; protected bool isDead; @@ -93,7 +94,6 @@ namespace Subsurface protected float soundInterval; private float bleeding; - //private float blood; private Sound[] sounds; private float[] soundRange; @@ -113,7 +113,7 @@ namespace Subsurface get { return AnimController.Mass; } } - public Inventory Inventory + public CharacterInventory Inventory { get { return inventory; } } @@ -301,11 +301,11 @@ namespace Subsurface public Character(string file, Vector2 position, CharacterInfo characterInfo = null, bool isNetworkPlayer = false) { - selectKeyHit = new Key(false); - actionKeyDown = new Key(true); - actionKeyHit = new Key(false); - secondaryKeyHit = new Key(false); - secondaryKeyDown = new Key(true); + selectKeyHit = new Key(false); + actionKeyDown = new Key(true); + actionKeyHit = new Key(false); + secondaryKeyHit = new Key(false); + secondaryKeyDown = new Key(true); selectedItems = new Item[2]; @@ -330,7 +330,7 @@ namespace Subsurface { AnimController = new HumanoidAnimController(this, doc.Root.Element("ragdoll")); AnimController.TargetDir = Direction.Right; - inventory = new CharacterInventory(10, this); + inventory = new CharacterInventory(15, this); } else { @@ -432,11 +432,15 @@ namespace Subsurface } Item item = new Item(itemPrefab, Position); - inventory.TryPutItem(item, item.AllowedSlots, false); if (info.Job.EquipSpawnItem[i]) { - item.Equip(this); + inventory.TryPutItem(item, + item.AllowedSlots.HasFlag(LimbSlot.Any) ? item.AllowedSlots & ~LimbSlot.Any : item.AllowedSlots, false); + } + else + { + inventory.TryPutItem(item, item.AllowedSlots, false); } if (item.Prefab.Name == "ID Card" && spawnPoint != null) @@ -460,8 +464,7 @@ namespace Subsurface //find the closest item if selectkey has been hit, or if the character is being //controlled by the player (in order to highlight it) - //closestItem = null; - if (controlled==this) + if (controlled == this) { Vector2 mouseSimPos = ConvertUnits.ToSimUnits(cam.ScreenToWorld(PlayerInput.MousePosition)); closestItem = FindClosestItem(mouseSimPos); @@ -474,6 +477,13 @@ namespace Subsurface new NetworkEvent(NetworkEventType.PickItem, ID, true, closestItem.ID); } } + + closestCharacter = FindClosestCharacter(mouseSimPos); + if (closestCharacter != selectedCharacter) selectedCharacter = null; + if (closestCharacter!=null) + { + if (selectKeyHit.State) selectedCharacter = (selectedCharacter==null) ? closestCharacter : null; + } } for (int i = 0; i < selectedItems.Length; i++ ) @@ -509,6 +519,31 @@ namespace Subsurface return Item.FindPickable(pos, selectedConstruction == null ? mouseSimPos : selectedConstruction.SimPosition, null, selectedItems); } + private Character FindClosestCharacter(Vector2 mouseSimPos, float maxDist = 150.0f) + { + Character closestCharacter = null; + float closestDist = 0.0f; + + maxDist = ConvertUnits.ToSimUnits(maxDist); + + foreach (Character c in Character.CharacterList) + { + if (c == this) continue; + + if (Vector2.Distance(SimPosition, c.SimPosition) > maxDist) continue; + + float dist = Vector2.Distance(mouseSimPos, c.SimPosition); + if (dist < maxDist && closestCharacter==null || dist /// Control the character according to player input /// @@ -743,10 +778,10 @@ namespace Subsurface private static GUIProgressBar drowningBar, healthBar; public void DrawHud(SpriteBatch spriteBatch, Camera cam) { - if (drowningBar==null) + if (drowningBar == null) { int width = 100, height = 20; - drowningBar = new GUIProgressBar(new Rectangle(20, Game1.GraphicsHeight/2, width, height), Color.Blue, 1.0f); + drowningBar = new GUIProgressBar(new Rectangle(20, Game1.GraphicsHeight / 2, width, height), Color.Blue, 1.0f); healthBar = new GUIProgressBar(new Rectangle(20, Game1.GraphicsHeight / 2 + 30, width, height), Color.Red, 1.0f); } @@ -757,11 +792,26 @@ namespace Subsurface healthBar.BarSize = health / maxHealth; if (healthBar.BarSize < 1.0f) healthBar.Draw(spriteBatch); - if (Controlled.Inventory != null) Controlled.Inventory.Draw(spriteBatch); + if (Controlled.Inventory != null) Controlled.Inventory.DrawOwn(spriteBatch); - if (closestItem != null && selectedConstruction==null) + Color color = Color.Orange; + + if (closestCharacter != null && closestCharacter.isDead) + { + Vector2 startPos = Position + (closestCharacter.Position - Position) * 0.7f; + startPos = cam.WorldToScreen(startPos); + + Vector2 textPos = startPos; + + float stringWidth = GUI.Font.MeasureString(closestCharacter.Info.Name).X; + textPos -= new Vector2(stringWidth / 2, 20); + spriteBatch.DrawString(GUI.Font, closestCharacter.Info.Name, textPos, Color.Black); + spriteBatch.DrawString(GUI.Font, closestCharacter.Info.Name, textPos + new Vector2(1, -1), Color.Orange); + + if (selectedCharacter==closestCharacter) closestCharacter.inventory.Draw(spriteBatch); + } + else if (closestItem != null && selectedConstruction==null) { - Color color = Color.Orange; Vector2 startPos = Position + (closestItem.Position - Position) * 0.7f; startPos = cam.WorldToScreen(startPos); @@ -782,7 +832,7 @@ namespace Subsurface spriteBatch.DrawString(GUI.Font, coloredText.text, textPos + new Vector2(1, -1), coloredText.color); textPos.Y += 25; - } + } } } diff --git a/Subsurface/Source/Items/CharacterInventory.cs b/Subsurface/Source/Items/CharacterInventory.cs index 2469ad150..cab256dc1 100644 --- a/Subsurface/Source/Items/CharacterInventory.cs +++ b/Subsurface/Source/Items/CharacterInventory.cs @@ -19,7 +19,8 @@ namespace Subsurface private static LimbSlot[] limbSlots = new LimbSlot[] { LimbSlot.Head, LimbSlot.Torso, LimbSlot.Legs, LimbSlot.LeftHand, LimbSlot.RightHand, - LimbSlot.Any, LimbSlot.Any, LimbSlot.Any, LimbSlot.Any, LimbSlot.Any }; + LimbSlot.Any, LimbSlot.Any, LimbSlot.Any, LimbSlot.Any, LimbSlot.Any, + LimbSlot.Any, LimbSlot.Any, LimbSlot.Any, LimbSlot.Any, LimbSlot.Any}; private Vector2[] slotPositions; @@ -52,12 +53,12 @@ namespace Subsurface case 4: slotPositions[i] = new Vector2( spacing * 2 + rectWidth + (spacing + rectWidth) * (i - 3), - Game1.GraphicsHeight - (spacing + rectHeight)); + Game1.GraphicsHeight - (spacing + rectHeight)*3); break; default: slotPositions[i] = new Vector2( - spacing * (4 + (i - 5)) + rectWidth * (3 + (i - 5)), - Game1.GraphicsHeight - (spacing + rectHeight)); + spacing * 2 + rectWidth + (spacing + rectWidth) * ((i - 3)%5), + Game1.GraphicsHeight - (spacing + rectHeight) * ((i>9) ? 2 : 1)); break; } } @@ -212,7 +213,7 @@ namespace Subsurface } - public override void Draw(SpriteBatch spriteBatch) + public void DrawOwn(SpriteBatch spriteBatch) { if (doubleClickedItem!=null && doubleClickedItem.inventory!=this) { @@ -251,7 +252,7 @@ namespace Subsurface slotRect.Y = (int)slotPositions[i].Y; - UpdateSlot(spriteBatch, slotRect, i, items[i], false); + UpdateSlot(spriteBatch, slotRect, i, items[i], i>4); if (draggingItem!=null && draggingItem == items[i]) draggingItemSlot = slotRect; } diff --git a/Subsurface/Source/Items/Components/Container.cs b/Subsurface/Source/Items/Components/Container.cs index b30ac86be..cd5ea359f 100644 --- a/Subsurface/Source/Items/Components/Container.cs +++ b/Subsurface/Source/Items/Components/Container.cs @@ -58,8 +58,8 @@ namespace Subsurface.Items.Components [HasDefaultValue(0.0f, false)] public float ItemRotation { - get { return itemRotation; } - set { itemRotation = value; } + get { return MathHelper.ToDegrees(itemRotation); } + set { itemRotation = MathHelper.ToRadians(value); } } private float itemRotation; diff --git a/Subsurface/Source/Items/Components/Holdable/Holdable.cs b/Subsurface/Source/Items/Components/Holdable/Holdable.cs index a13eb2748..fb285428d 100644 --- a/Subsurface/Source/Items/Components/Holdable/Holdable.cs +++ b/Subsurface/Source/Items/Components/Holdable/Holdable.cs @@ -183,6 +183,17 @@ namespace Subsurface.Items.Components if (!attachable || item.body==null) return true; item.Drop(); + + var containedItems = item.ContainedItems; + if (containedItems!=null) + { + foreach (Item contained in containedItems) + { + if (contained.body == null) continue; + contained.SetTransform(item.SimPosition, contained.body.Rotation); + } + } + item.body.Enabled = false; item.body = null; diff --git a/Subsurface/Source/Items/Components/Holdable/RepairTool.cs b/Subsurface/Source/Items/Components/Holdable/RepairTool.cs index da2662189..7063d955e 100644 --- a/Subsurface/Source/Items/Components/Holdable/RepairTool.cs +++ b/Subsurface/Source/Items/Components/Holdable/RepairTool.cs @@ -124,7 +124,7 @@ namespace Subsurface.Items.Components Body targetBody = Submarine.PickBody(TransformedBarrelPos, targetPosition, ignoredBodies); pickedPosition = Submarine.LastPickedPosition; - if (targetBody==null || targetBody.UserData==null) return true; + if (targetBody == null || targetBody.UserData == null) return true; //ApplyStatusEffects(ActionType.OnUse, 1.0f, character); diff --git a/Subsurface/Source/Items/Components/ItemComponent.cs b/Subsurface/Source/Items/Components/ItemComponent.cs index 2f8688e00..5bd69c663 100644 --- a/Subsurface/Source/Items/Components/ItemComponent.cs +++ b/Subsurface/Source/Items/Components/ItemComponent.cs @@ -550,9 +550,7 @@ namespace Subsurface.Items.Components public virtual void Load(XElement componentElement) { - if (componentElement == null) return; - - + if (componentElement == null) return; foreach (XAttribute attribute in componentElement.Attributes()) { diff --git a/Subsurface/Source/Items/Components/Projectile.cs b/Subsurface/Source/Items/Components/Projectile.cs index 6643d3cf1..0e44f3468 100644 --- a/Subsurface/Source/Items/Components/Projectile.cs +++ b/Subsurface/Source/Items/Components/Projectile.cs @@ -179,6 +179,10 @@ namespace Subsurface.Items.Components foreach (Item contained in item.ContainedItems) { contained.Condition = 0.0f; + if (contained.body!=null) + { + contained.body.SetTransform(item.SimPosition, contained.body.Rotation); + } } return true; diff --git a/Subsurface/Source/Items/Components/Signal/Connection.cs b/Subsurface/Source/Items/Components/Signal/Connection.cs index 9e3734ccd..c790acd00 100644 --- a/Subsurface/Source/Items/Components/Signal/Connection.cs +++ b/Subsurface/Source/Items/Components/Signal/Connection.cs @@ -28,7 +28,7 @@ namespace Subsurface.Items.Components private List effects; - int[] wireId; + public readonly int[] wireId; public List Recipients { @@ -463,7 +463,7 @@ namespace Subsurface.Items.Components } } - wireId = null; + //wireId = null; } } diff --git a/Subsurface/Source/Items/Components/Signal/ConnectionPanel.cs b/Subsurface/Source/Items/Components/Signal/ConnectionPanel.cs index 18b743e89..6bdbb62c6 100644 --- a/Subsurface/Source/Items/Components/Signal/ConnectionPanel.cs +++ b/Subsurface/Source/Items/Components/Signal/ConnectionPanel.cs @@ -74,21 +74,26 @@ namespace Subsurface.Items.Components public override void Load(XElement element) { base.Load(element); - - connections.Clear(); + + List loadedConnections = new List(); foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString()) { case "input": - connections.Add(new Connection(subElement, item)); + loadedConnections.Add(new Connection(subElement, item)); break; case "output": - connections.Add(new Connection(subElement, item)); + loadedConnections.Add(new Connection(subElement, item)); break; } } + + for (int i = 0; i nodeDistance) { - DrawSection(spriteBatch, Nodes[Nodes.Count - 1], newNodePos, Nodes.Count, item.Color * 0.5f); + DrawSection(spriteBatch, Nodes[Nodes.Count - 1], newNodePos, item.Color * 0.5f); //nodes.Add(newNodePos); } @@ -333,7 +333,7 @@ selectedNodeIndex = null; } - private void DrawSection(SpriteBatch spriteBatch, Vector2 start, Vector2 end, int i, Color color) + private void DrawSection(SpriteBatch spriteBatch, Vector2 start, Vector2 end, Color color) { start.Y = -start.Y; end.Y = -end.Y; @@ -344,7 +344,7 @@ selectedNodeIndex = null; new Vector2(0.0f, wireSprite.size.Y / 2.0f), new Vector2((Vector2.Distance(start, end)) / wireSprite.Texture.Width, 0.3f), SpriteEffects.None, - wireSprite.Depth + 0.1f + i * 0.00001f); + wireSprite.Depth + ((item.ID % 100) * 0.00001f)); } public override XElement Save(XElement parentElement) diff --git a/Subsurface/Source/Items/Item.cs b/Subsurface/Source/Items/Item.cs index 70070dbe6..f84d5bc4d 100644 --- a/Subsurface/Source/Items/Item.cs +++ b/Subsurface/Source/Items/Item.cs @@ -450,13 +450,21 @@ namespace Subsurface { if (ic.Parent != null) ic.IsActive = ic.Parent.IsActive; - if (!ic.WasUsed) ic.StopSounds(ActionType.OnUse); - ic.WasUsed = false; + //if (!ic.WasUsed) + //{ + // if (ic.Name == "RepairTool" && ic.IsActive) + // { + // System.Diagnostics.Debug.WriteLine("stop sounds"); + // } + // ic.StopSounds(ActionType.OnUse); + //} + //ic.WasUsed = false; if (!ic.IsActive) { ic.StopSounds(ActionType.OnActive); + ic.StopSounds(ActionType.OnUse); continue; } if (condition > 0.0f) diff --git a/Subsurface/Source/Map/Submarine.cs b/Subsurface/Source/Map/Submarine.cs index 3b42ba5c3..260ee1d2f 100644 --- a/Subsurface/Source/Map/Submarine.cs +++ b/Subsurface/Source/Map/Submarine.cs @@ -436,7 +436,7 @@ namespace Subsurface float dragCoefficient = 0.00001f; - float speedLength = speed.Length(); + float speedLength = (speed == Vector2.Zero) ? 0.0f : speed.Length(); float drag = speedLength * speedLength * dragCoefficient * mass; if (speed != Vector2.Zero) diff --git a/Subsurface/Source/Map/WayPoint.cs b/Subsurface/Source/Map/WayPoint.cs index 07f98d4b1..da17484b7 100644 --- a/Subsurface/Source/Map/WayPoint.cs +++ b/Subsurface/Source/Map/WayPoint.cs @@ -73,7 +73,7 @@ namespace Subsurface public override void DrawEditing(SpriteBatch spriteBatch, Camera cam) { - if (editingHUD==null) + if (editingHUD == null || editingHUD.UserData != this) { editingHUD = CreateEditingHUD(); } diff --git a/Subsurface/Source/Networking/GameClient.cs b/Subsurface/Source/Networking/GameClient.cs index adb5c3250..638399375 100644 --- a/Subsurface/Source/Networking/GameClient.cs +++ b/Subsurface/Source/Networking/GameClient.cs @@ -258,7 +258,6 @@ namespace Subsurface.Networking { Character.Controlled = null; Game1.GameScreen.Cam.TargetPos = Vector2.Zero; - Game1.GameScreen.Cam.Zoom = 1.0f; } else { diff --git a/Subsurface/Source/Particles/Particle.cs b/Subsurface/Source/Particles/Particle.cs index 686011341..6fa547c85 100644 --- a/Subsurface/Source/Particles/Particle.cs +++ b/Subsurface/Source/Particles/Particle.cs @@ -161,9 +161,8 @@ namespace Subsurface.Particles float drawRotation = Physics.Interpolate(prevRotation, rotation); drawPosition = ConvertUnits.ToDisplayUnits(drawPosition); - - - prefab.sprite.Draw(spriteBatch, drawPosition, color*alpha, drawRotation, size.X, SpriteEffects.None, prefab.sprite.Depth); + + prefab.sprite.Draw(spriteBatch, drawPosition, color*alpha, prefab.sprite.origin, drawRotation, size, SpriteEffects.None, prefab.sprite.Depth); //spriteBatch.Draw( // prefab.sprite.Texture, diff --git a/Subsurface/Source/Sprite.cs b/Subsurface/Source/Sprite.cs index 71c731ed8..5bce899f1 100644 --- a/Subsurface/Source/Sprite.cs +++ b/Subsurface/Source/Sprite.cs @@ -194,6 +194,11 @@ namespace Subsurface { spriteBatch.Draw(texture, pos + offset, sourceRect, color, rotation + rotate, origin, scale, spriteEffect, depth == null ? this.depth : (float)depth); } + + public void Draw(SpriteBatch spriteBatch, Vector2 pos, Color color, Vector2 origin, float rotate, Vector2 scale, SpriteEffects spriteEffect = SpriteEffects.None, float? depth = null) + { + spriteBatch.Draw(texture, pos + offset, sourceRect, color, rotation + rotate, origin, scale, spriteEffect, depth == null ? this.depth : (float)depth); + } public void DrawTiled(SpriteBatch spriteBatch, Vector2 pos, Vector2 targetSize, Color color) { diff --git a/Subsurface_Solution.v12.suo b/Subsurface_Solution.v12.suo index 5ee2b4a44..8f04bc374 100644 Binary files a/Subsurface_Solution.v12.suo and b/Subsurface_Solution.v12.suo differ