diff --git a/Subsurface/Characters/AI/PathFinder.cs b/Subsurface/Characters/AI/PathFinder.cs index 1ba662db4..0e4c8dfd4 100644 --- a/Subsurface/Characters/AI/PathFinder.cs +++ b/Subsurface/Characters/AI/PathFinder.cs @@ -116,7 +116,7 @@ namespace Subsurface if (startNode == null || endNode == null) { DebugConsole.ThrowError("Pathfinding error, couldn't find pathnodes"); - return null; + return new SteeringPath(); } return FindPath(startNode,endNode); @@ -141,7 +141,7 @@ namespace Subsurface if (startNode==null || endNode==null) { DebugConsole.ThrowError("Pathfinding error, couldn't find matching pathnodes to waypoints"); - return null; + return new SteeringPath();; } } diff --git a/Subsurface/Characters/Jobs/Job.cs b/Subsurface/Characters/Jobs/Job.cs index c90ab4ad0..2e97c48de 100644 --- a/Subsurface/Characters/Jobs/Job.cs +++ b/Subsurface/Characters/Jobs/Job.cs @@ -86,9 +86,12 @@ namespace Subsurface foreach (XElement subElement in element.Elements()) { + if (subElement.Name.ToString().ToLower() != "skill") continue; + string skillName = ToolBox.GetAttributeString(subElement, "name", ""); + if (string.IsNullOrEmpty(name)) continue; skills.Add( - subElement.Name.ToString(), - new Skill(subElement.Name.ToString(), ToolBox.GetAttributeInt(subElement, "level", 0))); + skillName, + new Skill(skillName, ToolBox.GetAttributeInt(subElement, "level", 0))); } } @@ -115,7 +118,7 @@ namespace Subsurface foreach (KeyValuePair skill in skills) { - jobElement.Add(new XElement(skill.Key, new XAttribute("level", skill.Value.Level))); + jobElement.Add(new XElement("skill", new XAttribute("name", skill.Value.Name), new XAttribute("level", skill.Value.Level))); } parentElement.Add(jobElement); diff --git a/Subsurface/Characters/Ragdoll.cs b/Subsurface/Characters/Ragdoll.cs index dd00ad5c4..937e7649d 100644 --- a/Subsurface/Characters/Ragdoll.cs +++ b/Subsurface/Characters/Ragdoll.cs @@ -609,7 +609,7 @@ namespace Subsurface float dist = Vector2.Distance(limbPos, gapPos); - force += Vector2.Normalize(gap.FlowForce)*(Math.Max(gap.FlowForce.Length() - dist, 0.0f)/500.0f); + force += Vector2.Normalize(gap.FlowForce)*(Math.Max(gap.FlowForce.Length() - dist, 0.0f)/1000.0f); } if (force.Length() > 20.0f) return force; diff --git a/Subsurface/Content/Items/Engine/engine.xml b/Subsurface/Content/Items/Engine/engine.xml index 856d8462b..cb3318286 100644 --- a/Subsurface/Content/Items/Engine/engine.xml +++ b/Subsurface/Content/Items/Engine/engine.xml @@ -31,6 +31,7 @@ + diff --git a/Subsurface/Content/Items/Engine/radarPing.ogg b/Subsurface/Content/Items/Engine/radarPing.ogg new file mode 100644 index 000000000..41284f48b Binary files /dev/null and b/Subsurface/Content/Items/Engine/radarPing.ogg differ diff --git a/Subsurface/Content/Items/Weapons/railgun.xml b/Subsurface/Content/Items/Weapons/railgun.xml index e2803a3d6..f7df33e46 100644 --- a/Subsurface/Content/Items/Weapons/railgun.xml +++ b/Subsurface/Content/Items/Weapons/railgun.xml @@ -3,7 +3,8 @@ name="Railgun" focusonselected="true" offsetonselected="500" - linkable="true"> + linkable="true" + pickdistance="150"> @@ -12,6 +13,13 @@ powerconsumption="500.0"> + + + + + + + - + + + + + + + - + + + diff --git a/Subsurface/Content/Items/Weapons/railgunbase.png b/Subsurface/Content/Items/Weapons/railgunbase.png index 7e1492d39..bf2ef92f7 100644 Binary files a/Subsurface/Content/Items/Weapons/railgunbase.png and b/Subsurface/Content/Items/Weapons/railgunbase.png differ diff --git a/Subsurface/Content/randomevents.xml b/Subsurface/Content/randomevents.xml index beb43f35c..027a43ca1 100644 --- a/Subsurface/Content/randomevents.xml +++ b/Subsurface/Content/randomevents.xml @@ -3,7 +3,7 @@ @@ -14,4 +14,19 @@ difficulty="50" starttimemin="15" starttimemax="20" musictype="monster"/> + + + + \ No newline at end of file diff --git a/Subsurface/GUI/GUI.cs b/Subsurface/GUI/GUI.cs index f31ba8eaf..bcb251288 100644 --- a/Subsurface/GUI/GUI.cs +++ b/Subsurface/GUI/GUI.cs @@ -265,20 +265,18 @@ namespace Subsurface public static void Draw(float deltaTime, SpriteBatch spriteBatch, Camera cam) { spriteBatch.DrawString(font, - "FPS: " + (int)Game1.frameCounter.AverageFramesPerSecond, + "FPS: " + (int)Game1.frameCounter.AverageFramesPerSecond + + " - Physics: " + Game1.World.UpdateTime + + " - bodies: " + Game1.World.BodyList.Count, new Vector2(10, 10), Color.White); - spriteBatch.DrawString(font, - "Physics: " + Game1.World.UpdateTime - + " - bodies: " + Game1.World.BodyList.Count, - new Vector2(10, 30), Color.White); spriteBatch.DrawString(font, "Camera pos: " + Game1.GameScreen.Cam.Position, - new Vector2(10, 50), Color.White); - - + new Vector2(10, 30), Color.White); + if (Character.Controlled != null && cam!=null) Character.Controlled.DrawHud(spriteBatch, cam); + if (Game1.NetworkMember != null) Game1.NetworkMember.Draw(spriteBatch); DrawMessages(spriteBatch, (float)deltaTime); diff --git a/Subsurface/GUI/GUIListBox.cs b/Subsurface/GUI/GUIListBox.cs index 43d0d4b83..09f6f0a43 100644 --- a/Subsurface/GUI/GUIListBox.cs +++ b/Subsurface/GUI/GUIListBox.cs @@ -44,6 +44,17 @@ namespace Subsurface } } + public float BarScroll + { + get { return scrollBar.BarScroll; } + set { scrollBar.BarScroll = value; } + } + + public float BarSize + { + get { return scrollBar.BarSize; } + } + public int Spacing { get { return spacing; } @@ -173,14 +184,16 @@ namespace Subsurface { base.AddChild(child); - float oldScroll = scrollBar.BarScroll; - float oldSize = scrollBar.BarSize; + //float oldScroll = scrollBar.BarScroll; + //float oldSize = scrollBar.BarSize; UpdateScrollBarSize(); - if (scrollBar.BarSize < 1.0f && oldScroll == 1.0f) - { - scrollBar.BarScroll = 1.0f; - } + //if (oldSize == 1.0f && scrollBar.BarScroll == 0.0f) scrollBar.BarScroll = 1.0f; + + //if (scrollBar.BarSize < 1.0f && oldScroll == 1.0f) + //{ + // scrollBar.BarScroll = 1.0f; + //} } diff --git a/Subsurface/GUI/GUIScrollBar.cs b/Subsurface/GUI/GUIScrollBar.cs index fa7568518..0ab9663d7 100644 --- a/Subsurface/GUI/GUIScrollBar.cs +++ b/Subsurface/GUI/GUIScrollBar.cs @@ -107,9 +107,10 @@ namespace Subsurface private void UpdateRect() { + bar.Rect = new Rectangle( - frame.Rect.X, - frame.Rect.Y, + bar.Rect.X, + bar.Rect.Y, isHorizontal ? (int)(frame.Rect.Width * barSize) : frame.Rect.Width, isHorizontal ? frame.Rect.Height : (int)(frame.Rect.Height * barSize)); diff --git a/Subsurface/GameSession/GameMode.cs b/Subsurface/GameSession/GameMode.cs index bdd7acd68..ce89ffbe2 100644 --- a/Subsurface/GameSession/GameMode.cs +++ b/Subsurface/GameSession/GameMode.cs @@ -120,7 +120,7 @@ namespace Subsurface { if (!isRunning) return; - if (duration!=TimeSpan.Zero) + if (duration != TimeSpan.Zero) { double elapsedTime = (DateTime.Now - startTime).TotalSeconds; timerBar.BarSize = (float)(elapsedTime / duration.TotalSeconds); diff --git a/Subsurface/GameSession/GameSession.cs b/Subsurface/GameSession/GameSession.cs index c9fd04fc5..25477bd55 100644 --- a/Subsurface/GameSession/GameSession.cs +++ b/Subsurface/GameSession/GameSession.cs @@ -134,14 +134,6 @@ namespace Subsurface submarine.SetPosition(level.StartPosition - new Vector2(0.0f, 2000.0f)); } - foreach (Item item in Item.itemList) - { - foreach (ItemComponent ic in item.components) - { - ic.OnMapLoaded(); - } - } - taskManager.StartShift(level); } @@ -227,7 +219,7 @@ namespace Subsurface //double elapsedTime = (DateTime.Now-startTime).TotalSeconds; //timerBar.BarSize = (float)(elapsedTime / Math.Max(duration, 1.0)); - if (PlayerInput.KeyHit(Keys.Tab)) + if (PlayerInput.KeyHit(Keys.Tab) && textBox!=null) { if (textBox.Selected) { diff --git a/Subsurface/Items/CharacterInventory.cs b/Subsurface/Items/CharacterInventory.cs index 5606c124f..e924accb7 100644 --- a/Subsurface/Items/CharacterInventory.cs +++ b/Subsurface/Items/CharacterInventory.cs @@ -25,6 +25,12 @@ namespace Subsurface this.character = character; } + protected override void DropItem(Item item) + { + item.Drop(character); + item.body.SetTransform(character.SimPosition, 0.0f); + } + public int FindLimbSlot(LimbSlot limbSlot) { for (int i = 0; i < items.Length; i++) @@ -232,7 +238,7 @@ namespace Subsurface else { draggingItem.body.SetTransform(character.SimPosition, 0.0f); - draggingItem.Drop(character); + DropItem(draggingItem); //draggingItem = null; } } diff --git a/Subsurface/Items/Components/Holdable/RepairTool.cs b/Subsurface/Items/Components/Holdable/RepairTool.cs index dce55bfde..7cd21e7e8 100644 --- a/Subsurface/Items/Components/Holdable/RepairTool.cs +++ b/Subsurface/Items/Components/Holdable/RepairTool.cs @@ -129,7 +129,7 @@ namespace Subsurface.Items.Components targetStructure.HighLightSection(sectionIndex); - + targetStructure.AddDamage(sectionIndex, -structureFixAmount); } else if ((targetLimb = (targetBody.UserData as Limb)) != null) diff --git a/Subsurface/Items/Components/ItemComponent.cs b/Subsurface/Items/Components/ItemComponent.cs index 1b644c05a..d500b0498 100644 --- a/Subsurface/Items/Components/ItemComponent.cs +++ b/Subsurface/Items/Components/ItemComponent.cs @@ -284,6 +284,11 @@ namespace Subsurface { return false; } + + public virtual bool Select(Character character) + { + return CanBeSelected; + } /// a character has dropped the item public virtual void Drop(Character dropper) { } @@ -395,40 +400,31 @@ namespace Subsurface return true; } - public bool HasRequiredEquippedItems(Character character, bool addMessage) + public bool HasRequiredItems(Character character, bool addMessage) { if (!requiredItems.Any()) return true; + + foreach (RelatedItem ri in requiredItems) { + if (!ri.Type.HasFlag(RelatedItem.RelationType.Equipped) && !ri.Type.HasFlag(RelatedItem.RelationType.Picked)) continue; + + bool hasItem = false; if (ri.Type.HasFlag(RelatedItem.RelationType.Equipped)) { - for (int i = 0; i < character.SelectedItems.Length; i++ ) - { - Item selectedItem = character.SelectedItems[i]; - if (selectedItem !=null && selectedItem.Condition>0.0f && ri.MatchesItem(selectedItem )) - { - return true; - } - } - - //if (addMessage && !String.IsNullOrEmpty(ri.Msg)) GUI.AddMessage(ri.Msg, Color.Red); - return false; + if (character.SelectedItems.FirstOrDefault(it => it != null && it.Condition > 0.0f && ri.MatchesItem(it)) != null) hasItem = true; } - else if (ri.Type.HasFlag(RelatedItem.RelationType.Picked)) + if (!hasItem && ri.Type.HasFlag(RelatedItem.RelationType.Picked)) { - Item pickedItem = character.Inventory.items.FirstOrDefault(x => x!=null && x.Condition>0.0f && ri.MatchesItem(x)); - if (pickedItem == null) - { - //if (addMessage && !String.IsNullOrEmpty(ri.Msg)) GUI.AddMessage(ri.Msg, Color.Red); - return false; - } + if (character.Inventory.items.FirstOrDefault(x => x!=null && x.Condition>0.0f && ri.MatchesItem(x))!=null) hasItem = true; } + if (!hasItem) return false; } return true; } - + public void ApplyStatusEffects(ActionType type, float deltaTime, Character character = null) { foreach (StatusEffect effect in statusEffects) diff --git a/Subsurface/Items/Components/Ladder.cs b/Subsurface/Items/Components/Ladder.cs index 89f97803e..9323bf328 100644 --- a/Subsurface/Items/Components/Ladder.cs +++ b/Subsurface/Items/Components/Ladder.cs @@ -10,11 +10,11 @@ namespace Subsurface.Items.Components { } - public override bool Pick(Character picker = null) + public override bool Select(Character character = null) { - if (picker == null) return false; + if (character == null) return false; - picker.AnimController.Anim = AnimController.Animation.Climbing; + character.AnimController.Anim = AnimController.Animation.Climbing; //picker.SelectedConstruction = item; return true; diff --git a/Subsurface/Items/Components/Machines/Controller.cs b/Subsurface/Items/Components/Machines/Controller.cs index 2c5067435..a968e8ed9 100644 --- a/Subsurface/Items/Components/Machines/Controller.cs +++ b/Subsurface/Items/Components/Machines/Controller.cs @@ -23,6 +23,8 @@ namespace Subsurface.Items.Components //the x-position where the user walks to when using the controller float userPos; + Camera cam; + Character character; [HasDefaultValue(1.0f,false)] @@ -38,19 +40,6 @@ namespace Subsurface.Items.Components dir = (Direction)Enum.Parse(typeof(Direction), ToolBox.GetAttributeString(element, "direction", "None"), true); - //userPos = ToolBox.GetAttributeInt(element, "userpos", 1); - - //string allowedIdString = ToolBox.GetAttributeString(element, "allowedids", ""); - //if (allowedIdString!="") - //{ - // string[] splitIds = allowedIdString.Split(','); - // allowedIDs = new string[splitIds.Length]; - // for (int i = 0; i1.0f) + { + item.Use(deltaTime,null); + pingState = 0.0f; + } - angle = (angle + deltaTime) % MathHelper.TwoPi; + //angle = (angle + deltaTime) % MathHelper.TwoPi; + } + + public override bool Use(float deltaTime, Character character = null) + { + return true; } public override void DrawHUD(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, Character character) diff --git a/Subsurface/Items/Components/Machines/Steering.cs b/Subsurface/Items/Components/Machines/Steering.cs index 991be701a..305bbd46d 100644 --- a/Subsurface/Items/Components/Machines/Steering.cs +++ b/Subsurface/Items/Components/Machines/Steering.cs @@ -34,45 +34,37 @@ namespace Subsurface.Items.Components { isActive = true; } - - public override void OnMapLoaded() - { - PathFinder pathFinder = new PathFinder(WayPoint.WayPointList, false); - steeringPath = pathFinder.FindPath( - ConvertUnits.ToSimUnits(Level.Loaded.StartPosition), - ConvertUnits.ToSimUnits(Level.Loaded.EndPosition)); - } - + public override void Update(float deltaTime, Camera cam) { base.Update(deltaTime, cam); - if (autoPilot || true) + + + if (autoPilot) { - steeringPath.GetNode(Vector2.Zero, 5.0f); + if (steeringPath==null) + { + PathFinder pathFinder = new PathFinder(WayPoint.WayPointList, false); + steeringPath = pathFinder.FindPath( + ConvertUnits.ToSimUnits(Level.Loaded.StartPosition), + ConvertUnits.ToSimUnits(Level.Loaded.EndPosition)); + } + + steeringPath.GetNode(Vector2.Zero, 20.0f); if (steeringPath.CurrentNode!=null) { - Vector2 targetSpeed = steeringPath.CurrentNode.Position; + float prediction = 10.0f; - float dist = targetSpeed.Length(); + Vector2 futurePosition = Submarine.Loaded.Speed * prediction; + + Vector2 targetSpeed = (steeringPath.CurrentNode.Position - futurePosition); + + //float dist = targetSpeed.Length(); targetSpeed = Vector2.Normalize(targetSpeed); - if (dist<2000.0f) - { - targetSpeed = targetSpeed * Math.Max(dist / 2000.0f, 0.5f); - - } - - - Vector2 currSpeed = (Submarine.Loaded.Speed == Vector2.Zero) ? Vector2.Zero : Vector2.Normalize(Submarine.Loaded.Speed); - - //targetSpeed.X = (targetSpeed.X - currSpeed.X); - //targetSpeed.Y = (targetSpeed.Y - currSpeed.Y); - - //TargetVelocity += targetSpeed; - - TargetVelocity += (targetSpeed-currSpeed); + TargetVelocity = targetSpeed*100.0f; } } @@ -91,6 +83,13 @@ namespace Subsurface.Items.Components Rectangle velRect = new Rectangle(x + 20, y + 20, width - 40, height - 40); GUI.DrawRectangle(spriteBatch, velRect, Color.White, false); + if (GUI.DrawButton(spriteBatch, new Rectangle(x + width - 150, y + height - 30, 150, 30), "Autopilot")) + { + autoPilot = !autoPilot; + + item.NewComponentEvent(this, true); + } + GUI.DrawLine(spriteBatch, new Vector2(velRect.Center.X,velRect.Center.Y), new Vector2(velRect.Center.X + currVelocity.X, velRect.Center.Y - currVelocity.Y), @@ -113,10 +112,10 @@ namespace Subsurface.Items.Components { targetVelocity = PlayerInput.MousePosition - new Vector2(velRect.Center.X, velRect.Center.Y); targetVelocity.Y = -targetVelocity.Y; + + item.NewComponentEvent(this, true); } } - - item.NewComponentEvent(this, true); } public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f) @@ -131,14 +130,19 @@ namespace Subsurface.Items.Components { message.Write(targetVelocity.X); message.Write(targetVelocity.Y); + + message.Write(autoPilot); } public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message) { - Vector2 newTargetVelocity = Vector2.Zero; + Vector2 newTargetVelocity = Vector2.Zero; + bool newAutoPilot = false; + try { newTargetVelocity = new Vector2(message.ReadFloat(), message.ReadFloat()); + newAutoPilot = message.ReadBoolean(); } catch @@ -147,6 +151,7 @@ namespace Subsurface.Items.Components } TargetVelocity = newTargetVelocity; + autoPilot = newAutoPilot; } } } diff --git a/Subsurface/Items/Components/Signal/ConnectionPanel.cs b/Subsurface/Items/Components/Signal/ConnectionPanel.cs index 4b48bea80..50cbd499f 100644 --- a/Subsurface/Items/Components/Signal/ConnectionPanel.cs +++ b/Subsurface/Items/Components/Signal/ConnectionPanel.cs @@ -1,5 +1,6 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using System; using System.Collections.Generic; using System.Xml.Linq; @@ -28,26 +29,13 @@ namespace Subsurface.Items.Components break; } } + + isActive = true; } - //public override void Move(Vector2 amount) - //{ - // base.Move(amount); - - // foreach (Connection c in connections) - // { - // foreach (Wire w in c.wires) - // { - // if (w == null) continue; - - // w.Move - // } - // } - //} - public override void DrawHUD(SpriteBatch spriteBatch, Character character) { - if (user!=character) return; + if (character != Character.Controlled || character != user) return; Connection.DrawConnections(spriteBatch, this, character); } @@ -76,7 +64,7 @@ namespace Subsurface.Items.Components if (user != null && user.SelectedConstruction != item) user = null; } - public override bool Pick(Character picker) + public override bool Select(Character picker) { user = picker; isActive = true; @@ -107,10 +95,12 @@ namespace Subsurface.Items.Components { foreach (Connection c in connections) { - int wireCount = c.Wires.Length; - for (int i = 0 ; i < wireCount; i++) + Wire[] wires = Array.FindAll(c.Wires, w => w != null); + message.Write((byte)wires.Length); + for (int i = 0 ; i < c.Wires.Length; i++) { - message.Write(c.Wires[i]==null ? -1 : c.Wires[i].Item.ID); + if (c.Wires[i] == null) continue; + message.Write(c.Wires[i].Item.ID); } } } @@ -120,23 +110,28 @@ namespace Subsurface.Items.Components System.Diagnostics.Debug.WriteLine("connectionpanel update"); foreach (Connection c in connections) { - int wireCount = c.Wires.Length; + //int wireCount = c.Wires.Length; c.ClearConnections(); - - for (int i = 0; i < wireCount; i++) + try { - int wireId = message.ReadInt32(); - if (wireId == -1) continue; + byte wireCount = message.ReadByte(); - Item wireItem = MapEntity.FindEntityByID(wireId) as Item; - if (wireItem == null) continue; + for (int i = 0; i < wireCount; i++) + { + int wireId = message.ReadInt32(); + + Item wireItem = MapEntity.FindEntityByID(wireId) as Item; + if (wireItem == null) continue; - Wire wireComponent = wireItem.GetComponent(); - if (wireComponent == null) continue; + Wire wireComponent = wireItem.GetComponent(); + if (wireComponent == null) continue; - c.Wires[i] = wireComponent; - wireComponent.Connect(c, false); + c.Wires[i] = wireComponent; + wireComponent.Connect(c, false); + } } + + catch { } } } } diff --git a/Subsurface/Items/Components/Signal/Wire.cs b/Subsurface/Items/Components/Signal/Wire.cs index 240d474ae..c50649956 100644 --- a/Subsurface/Items/Components/Signal/Wire.cs +++ b/Subsurface/Items/Components/Signal/Wire.cs @@ -15,12 +15,12 @@ namespace Subsurface.Items.Components static Sprite wireSprite; - List nodes; + public List Nodes; Connection[] connections; private Vector2 newNodePos; - + public Wire(Item item, XElement element) : base(item, element) { @@ -30,7 +30,7 @@ namespace Subsurface.Items.Components wireSprite.Depth = 0.85f; } - nodes = new List(); + Nodes = new List(); connections = new Connection[2]; } @@ -38,9 +38,9 @@ namespace Subsurface.Items.Components public override void Move(Vector2 amount) { amount = FarseerPhysics.ConvertUnits.ToDisplayUnits(amount); - for (int i = 0; i0 && Vector2.Distance(newNodePos, nodes[nodes.Count - 1]) > nodeDistance) + if (newNodePos!= Vector2.Zero && Nodes.Count>0 && Vector2.Distance(newNodePos, Nodes[Nodes.Count - 1]) > nodeDistance) { - nodes.Add(newNodePos); + Nodes.Add(newNodePos); newNodePos = Vector2.Zero; } @@ -166,9 +165,9 @@ namespace Subsurface.Items.Components public override void SecondaryUse(float deltaTime, Character character = null) { - if (nodes.Count > 1) + if (Nodes.Count > 1) { - nodes.RemoveAt(nodes.Count - 1); + Nodes.RemoveAt(Nodes.Count - 1); item.NewComponentEvent(this, true); } } @@ -182,7 +181,7 @@ namespace Subsurface.Items.Components private void ClearConnections() { - nodes.Clear(); + Nodes.Clear(); for (int i = 0; i < 2; i++) { @@ -198,14 +197,14 @@ namespace Subsurface.Items.Components private void CleanNodes() { - for (int i = nodes.Count - 2; i > 0; i--) + for (int i = Nodes.Count - 2; i > 0; i--) { - if ((nodes[i - 1].X == nodes[i].X || nodes[i - 1].Y == nodes[i].Y) && - (nodes[i + 1].X == nodes[i].X || nodes[i + 1].Y == nodes[i].Y)) + if ((Nodes[i - 1].X == Nodes[i].X || Nodes[i - 1].Y == Nodes[i].Y) && + (Nodes[i + 1].X == Nodes[i].X || Nodes[i + 1].Y == Nodes[i].Y)) { - if (Vector2.Distance(nodes[i - 1], nodes[i]) == Vector2.Distance(nodes[i + 1], nodes[i])) + if (Vector2.Distance(Nodes[i - 1], Nodes[i]) == Vector2.Distance(Nodes[i + 1], Nodes[i])) { - nodes.RemoveAt(i); + Nodes.RemoveAt(i); } } } @@ -214,12 +213,12 @@ namespace Subsurface.Items.Components do { removed = false; - for (int i = nodes.Count - 2; i > 0; i--) + for (int i = Nodes.Count - 2; i > 0; i--) { - if ((nodes[i - 1].X == nodes[i].X && nodes[i + 1].X == nodes[i].X) - || (nodes[i - 1].Y == nodes[i].Y && nodes[i + 1].Y == nodes[i].Y)) + if ((Nodes[i - 1].X == Nodes[i].X && Nodes[i + 1].X == Nodes[i].X) + || (Nodes[i - 1].Y == Nodes[i].Y && Nodes[i + 1].Y == Nodes[i].Y)) { - nodes.RemoveAt(i); + Nodes.RemoveAt(i); removed = true; } } @@ -231,21 +230,21 @@ namespace Subsurface.Items.Components public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch) { - if (nodes.Count == 0) return; + if (Nodes.Count == 0) return; //for (int i = 0; i < nodes.Count; i++) //{ // GUI.DrawRectangle(spriteBatch, new Rectangle((int)nodes[i].X, (int)-nodes[i].Y, 5, 5), Color.DarkGray, true, wireSprite.Depth - 0.01f); //} - for (int i = 1; i < nodes.Count; i++) + for (int i = 1; i < Nodes.Count; i++) { - DrawSection(spriteBatch, nodes[i], nodes[i - 1], i, Color.White); + DrawSection(spriteBatch, Nodes[i], Nodes[i - 1], i, Color.White); } - if (isActive && Vector2.Distance(newNodePos, nodes[nodes.Count - 1]) > nodeDistance) + if (isActive && Vector2.Distance(newNodePos, Nodes[Nodes.Count - 1]) > nodeDistance) { - DrawSection(spriteBatch, nodes[nodes.Count - 1], newNodePos, nodes.Count, Color.White * 0.5f); + DrawSection(spriteBatch, Nodes[Nodes.Count - 1], newNodePos, Nodes.Count, Color.White * 0.5f); //nodes.Add(newNodePos); } @@ -269,13 +268,13 @@ namespace Subsurface.Items.Components { XElement componentElement = base.Save(parentElement); - if (nodes == null || nodes.Count == 0) return componentElement; + if (Nodes == null || Nodes.Count == 0) return componentElement; - string[] nodeCoords = new string[nodes.Count() * 2]; - for (int i = 0; i < nodes.Count(); i++) + string[] nodeCoords = new string[Nodes.Count() * 2]; + for (int i = 0; i < Nodes.Count(); i++) { - nodeCoords[i * 2] = nodes[i].X.ToString(CultureInfo.InvariantCulture); - nodeCoords[i * 2 + 1] = nodes[i].Y.ToString(CultureInfo.InvariantCulture); + nodeCoords[i * 2] = Nodes[i].X.ToString(CultureInfo.InvariantCulture); + nodeCoords[i * 2 + 1] = Nodes[i].Y.ToString(CultureInfo.InvariantCulture); } componentElement.Add(new XAttribute("nodes", string.Join(";", nodeCoords))); @@ -307,28 +306,28 @@ namespace Subsurface.Items.Components } catch { y = 0.0f; } - nodes.Add(new Vector2(x, y)); + Nodes.Add(new Vector2(x, y)); } } public override void FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetOutgoingMessage message) { - message.Write(nodes.Count); - for (int i = 0; i < nodes.Count; i++) + message.Write(Nodes.Count); + for (int i = 0; i < Nodes.Count; i++) { - message.Write(nodes[i].X); - message.Write(nodes[i].Y); + message.Write(Nodes[i].X); + message.Write(Nodes[i].Y); } } public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message) { - nodes.Clear(); + Nodes.Clear(); int nodeCount = message.ReadInt32(); for (int i = 0; i < nodeCount; i++) { - nodes.Add(new Vector2(message.ReadFloat(), message.ReadFloat())); + Nodes.Add(new Vector2(message.ReadFloat(), message.ReadFloat())); } } } diff --git a/Subsurface/Items/Components/Turret.cs b/Subsurface/Items/Components/Turret.cs index fcd4ec371..81da94d8a 100644 --- a/Subsurface/Items/Components/Turret.cs +++ b/Subsurface/Items/Components/Turret.cs @@ -4,6 +4,7 @@ using System.IO; using System.Xml.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using FarseerPhysics; namespace Subsurface.Items.Components { @@ -13,14 +14,11 @@ namespace Subsurface.Items.Components Vector2 barrelPos; - float targetRotation; - float rotation; + float rotation, targetRotation; - float reload; - float reloadTime; + float reload, reloadTime; - float minRotation; - float maxRotation; + float minRotation, maxRotation; float launchImpulse; @@ -53,12 +51,16 @@ namespace Subsurface.Items.Components set { reloadTime = value; } } - [HasDefaultValue("0.0,0.0", false)] + [HasDefaultValue("0.0,0.0", true)] public string RotationLimits { get { - return ToolBox.Vector2ToString(barrelPos); + Vector2 limits = new Vector2(minRotation, maxRotation); + limits.X = MathHelper.ToDegrees(limits.X); + limits.Y = MathHelper.ToDegrees(limits.Y); + + return ToolBox.Vector2ToString(limits); } set { @@ -75,35 +77,15 @@ namespace Subsurface.Items.Components barrelSprite = new Sprite(Path.GetDirectoryName(item.Prefab.ConfigFile) + "\\" +element.Attribute("barrelsprite").Value, ToolBox.GetAttributeVector2(element, "origin", Vector2.Zero)); - - //barrelPos = ToolBox.GetAttributeVector2(element, "BarrelPos", Vector2.Zero); - - //launchImpulse = ToolBox.GetAttributeFloat(element, "launchimpulse", 0.0f); - - //minRotation = ToolBox.GetAttributeFloat(element, "MinimumRotation", 0.0f); - //maxRotation = ToolBox.GetAttributeFloat(element, "MaximumRotation", MathHelper.TwoPi); - - //reloadTime = ToolBox.GetAttributeFloat(element, "reload", 5.0f); } public override void Draw(SpriteBatch spriteBatch) { barrelSprite.Draw(spriteBatch, new Vector2(item.Rect.X, -item.Rect.Y) + barrelPos, rotation + MathHelper.PiOver2, 1.0f); - - //GUI.DrawRectangle(spriteBatch, - // new Rectangle((int)(rect.X + barrelPos.X), (int)(-rect.Y + barrelPos.Y), 10, 10), - // Color.White, true); } public override void Update(float deltaTime, Camera cam) { - //if (character == null || character.SelectedConstruction != item) - //{ - // character = null; - // isActive = false; - // return; - //} - this.cam = cam; if (reload>0.0f) reload -= deltaTime; @@ -117,30 +99,22 @@ namespace Subsurface.Items.Components } rotation = MathUtils.CurveAngle(rotation, targetRotation, 0.05f); - - //if (!prefab.FocusOnSelected) return; - //cam.OffsetAmount = prefab.OffsetOnSelected; + } - public override void SecondaryUse(float deltaTime, Character character = null) - { - if (character == null) return; - Vector2 centerPos = new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y); + //public override void SecondaryUse(float deltaTime, Character character = null) + //{ + // if (character == null) return; + + // Vector2 centerPos = new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y); - Vector2 offset = character.CursorPosition - centerPos; - offset.Y = -offset.Y; - - targetRotation = MathUtils.WrapAngleTwoPi(MathUtils.VectorToAngle(offset)); - - isActive = true; - - if (character == Character.Controlled && cam!=null) - { - Lights.LightManager.ViewPos = centerPos; - cam.TargetPos = new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y); - } - } + // if (character == Character.Controlled && cam!=null) + // { + // Lights.LightManager.ViewPos = centerPos; + // cam.TargetPos = new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y); + // } + //} public override bool Use(float deltaTime, Character character = null) { @@ -148,23 +122,25 @@ namespace Subsurface.Items.Components Projectile projectileComponent = null; - currPowerConsumption = powerConsumption; + //currPowerConsumption = powerConsumption; float availablePower = 0.0f; //List batteries = new List(); - foreach (MapEntity e in item.linkedTo) + foreach (Connection c in item.Connections) { - Item battery = e as Item; - if (battery == null) continue; + foreach (Connection c2 in c.Recipients) + { + if (c2 == null || c2.Item == null) continue; - PowerContainer batteryComponent = battery.GetComponent(); - if (batteryComponent == null) continue; + PowerContainer batteryComponent = c2.Item.GetComponent(); + if (batteryComponent == null) continue; - float batteryPower = Math.Min(batteryComponent.Charge, batteryComponent.MaxOutPut); - float takePower = Math.Min(currPowerConsumption - availablePower, batteryPower); + float batteryPower = Math.Min(batteryComponent.Charge, batteryComponent.MaxOutPut); + float takePower = Math.Min(currPowerConsumption - availablePower, batteryPower); - batteryComponent.Charge -= takePower; - availablePower += takePower; + batteryComponent.Charge -= takePower; + availablePower += takePower; + } } reload = reloadTime; @@ -198,7 +174,7 @@ namespace Subsurface.Items.Components projectile.body.ResetDynamics(); projectile.body.Enabled = true; - projectile.SetTransform(item.SimPosition, rotation); + projectile.SetTransform(ConvertUnits.ToSimUnits(new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y)), -rotation); //if (useSounds.Count() > 0) useSounds[Game1.localRandom.Next(useSounds.Count())].Play(1.0f, 800.0f, item.body.FarseerBody); @@ -207,6 +183,29 @@ namespace Subsurface.Items.Components return true; } + + public override void ReceiveSignal(string signal, Connection connection, Item sender, float power) + { + switch (connection.Name) + { + case "position_in": + Vector2 receivedPos = ToolBox.ParseToVector2(signal, false); + + Vector2 centerPos = new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y); + + Vector2 offset = receivedPos - centerPos; + offset.Y = -offset.Y; + + targetRotation = MathUtils.WrapAngleTwoPi(MathUtils.VectorToAngle(offset)); + + isActive = true; + + break; + case "trigger_in": + item.Use((float)Physics.step, null); + break; + } + } } } diff --git a/Subsurface/Items/Inventory.cs b/Subsurface/Items/Inventory.cs index 2e802cccb..55f5ece09 100644 --- a/Subsurface/Items/Inventory.cs +++ b/Subsurface/Items/Inventory.cs @@ -134,20 +134,17 @@ namespace Subsurface } } - //protected virtual void DropItem(Item item) - //{ - // for (int i = 0; i < capacity; i++) - // { - // if (items[i] == item) items[i] = null; - // } - // item.Drop(); - // return; - //} - //public void DropItem(int i) - //{ - // items[i].Drop(); - // items[i] = null; - //} + protected virtual void DropItem(Item item) + { + + item.Drop(null, false); + return; + } + public void DropItem(int i) + { + items[i].Drop(); + items[i] = null; + } public virtual void Draw(SpriteBatch spriteBatch) { @@ -188,12 +185,10 @@ namespace Subsurface } else { - draggingItem.Drop(null, false); - int[] data = { draggingItem.ID, -1 }; new NetworkEvent(NetworkEventType.InventoryUpdate, ID, true, data); - - //draggingItem = null; + + DropItem(draggingItem); } } } diff --git a/Subsurface/Items/Item.cs b/Subsurface/Items/Item.cs index d428d2044..787fc378a 100644 --- a/Subsurface/Items/Item.cs +++ b/Subsurface/Items/Item.cs @@ -734,9 +734,8 @@ namespace Subsurface foreach (ItemComponent ic in components) { if (!ic.HasRequiredSkills(picker)) hasRequiredSkills = false; - if ((ic.CanBePicked || ic.CanBeSelected) - && (ic.HasRequiredEquippedItems(picker, picker == Character.Controlled) || forcePick) - && ic.Pick(picker)) + if (!ic.HasRequiredItems(picker, picker == Character.Controlled) && !forcePick) continue; + if ((ic.CanBePicked && ic.Pick(picker)) || (ic.CanBeSelected && ic.Select(picker))) { picked = true; ic.ApplyStatusEffects(ActionType.OnPicked, 1.0f, picker); diff --git a/Subsurface/Items/ItemInventory.cs b/Subsurface/Items/ItemInventory.cs index fe2840ab9..b3f2ed9fb 100644 --- a/Subsurface/Items/ItemInventory.cs +++ b/Subsurface/Items/ItemInventory.cs @@ -13,6 +13,13 @@ namespace Subsurface this.container = container; } + protected override void DropItem(Item item) + { + item.Drop(); + item.body.Enabled = true; + item.body.SetTransform(container.Item.SimPosition, 0.0f); + } + public override int FindAllowedSlot(Item item) { for (int i = 0; i < capacity; i++) diff --git a/Subsurface/Items/RelatedItem.cs b/Subsurface/Items/RelatedItem.cs index 5ee8c0c54..41bac1a0c 100644 --- a/Subsurface/Items/RelatedItem.cs +++ b/Subsurface/Items/RelatedItem.cs @@ -13,7 +13,7 @@ namespace Subsurface None = 0, Contained = 1, Equipped = 2, - Picked = 3 + Picked = 4 } string[] names; diff --git a/Subsurface/Map/Levels/Level.cs b/Subsurface/Map/Levels/Level.cs index 567bfb627..d153f73a5 100644 --- a/Subsurface/Map/Levels/Level.cs +++ b/Subsurface/Map/Levels/Level.cs @@ -74,7 +74,7 @@ namespace Subsurface public Vector2 Position { - get { return ConvertUnits.ToDisplayUnits(cells[1].body.Position); } + get { return ConvertUnits.ToDisplayUnits(cells[0].body.Position); } } public string Seed @@ -546,11 +546,10 @@ int currentTargetIndex = 1; List tempVertices = new List(); List bodyPoints = new List(); - int n = 0; - foreach (VoronoiCell cell in cells) + for (int n = cells.Count - 1; n >= 0; n-- ) { - n = (n + 30) % 255; - + VoronoiCell cell = cells[n]; + bodyPoints.Clear(); tempVertices.Clear(); foreach (GraphEdge ge in cell.edges) @@ -568,14 +567,18 @@ int currentTargetIndex = 1; if (!bodyPoints.Contains(ge.point2)) bodyPoints.Add(ge.point2); } - if (tempVertices.Count < 3) continue; + if (tempVertices.Count < 3 || bodyPoints.Count < 2) + { + cells.RemoveAt(n); + continue; + } var triangles = MathUtils.TriangulateConvexHull(tempVertices, cell.Center); - for (int i = 0; i < triangles.Count; i++ ) + for (int i = 0; i < triangles.Count; i++) { foreach (Vector2 vertex in triangles[i]) { - verticeList.Add(new VertexPositionColor(new Vector3(vertex, 0.0f), new Color(n,(n*2)%255,(n*3)%255)*0.5f)); + verticeList.Add(new VertexPositionColor(new Vector3(vertex, 0.0f), new Color(n*30, (n * 60) % 255, (n * 90) % 255) * 0.5f)); } } @@ -584,7 +587,7 @@ int currentTargetIndex = 1; if (bodyPoints.Count < 3) { - foreach(Vector2 vertex in tempVertices) + foreach (Vector2 vertex in tempVertices) { if (bodyPoints.Contains(vertex)) continue; bodyPoints.Add(vertex); @@ -608,7 +611,7 @@ int currentTargetIndex = 1; if (triangles[i][0].X == triangles[i][1].X && triangles[i][0].X == triangles[i][2].X) continue; Vertices bodyVertices = new Vertices(triangles[i]); - FixtureFactory.AttachPolygon(bodyVertices, 5.0f, edgeBody); + FixtureFactory.AttachPolygon(bodyVertices, 5.0f, edgeBody); } edgeBody.UserData = cell; @@ -655,8 +658,8 @@ int currentTargetIndex = 1; Item item = mapEntity as Item; if (item == null) { - if (!mapEntity.MoveWithLevel) continue; - mapEntity.Move(amount); + //if (!mapEntity.MoveWithLevel) continue; + //mapEntity.Move(amount); } else if (item.body != null) { @@ -692,8 +695,8 @@ int currentTargetIndex = 1; Item item = mapEntity as Item; if (item == null) { - if (!mapEntity.MoveWithLevel) continue; - mapEntity.Move(velocity); + //if (!mapEntity.MoveWithLevel) continue; + //mapEntity.Move(velocity); } else if (item.body!=null) { diff --git a/Subsurface/Map/MapEntity.cs b/Subsurface/Map/MapEntity.cs index 62f369eed..33e751983 100644 --- a/Subsurface/Map/MapEntity.cs +++ b/Subsurface/Map/MapEntity.cs @@ -61,13 +61,16 @@ namespace Subsurface get { return false; } } - public Vector2 Position + public virtual Vector2 Position { get { - return new Vector2( + Vector2 rectPos = new Vector2( rect.X + rect.Width / 2.0f, rect.Y - rect.Height / 2.0f); + + if (MoveWithLevel) rectPos += Level.Loaded.Position; + return rectPos; } } diff --git a/Subsurface/Map/Submarine.cs b/Subsurface/Map/Submarine.cs index 9fd35bf31..22813b215 100644 --- a/Subsurface/Map/Submarine.cs +++ b/Subsurface/Map/Submarine.cs @@ -40,7 +40,6 @@ namespace Subsurface Vector2 speed; Vector2 targetPosition; - Vector2 targetSpeed; private Rectangle borders; @@ -417,7 +416,7 @@ namespace Subsurface if (targetPosition != Vector2.Zero && Vector2.Distance(targetPosition, Position) > 5.0f) { - translateAmount += (targetPosition - Position) * 0.05f; + translateAmount += (targetPosition - Position) * 0.01f; } else { @@ -583,6 +582,7 @@ namespace Subsurface return; } + newTargetPosition = newTargetPosition + newSpeed * (float)(NetTime.Now - sendingTime); targetPosition = newTargetPosition; speed = newSpeed; @@ -818,20 +818,16 @@ namespace Subsurface hullBody.GravityScale = 0.0f; hullBody.OnCollision += OnCollision; hullBody.OnSeparation += OnSeparation; - //body.IsSensor = true; - - //body.SetTransform(); - - //HullBody hullBody = new HullBody(); - //hullBody.body = body; - ////hullBody.shapeTexture = GUI.CreateRectangle(borders.Width, borders.Height); - - //hullBodies = new List(); - //hullBodies.Add(hullBody); - + MapEntity.LinkAll(); - - + + foreach (Item item in Item.itemList) + { + foreach (ItemComponent ic in item.components) + { + ic.OnMapLoaded(); + } + } ID = int.MaxValue-10; diff --git a/Subsurface/Map/WayPoint.cs b/Subsurface/Map/WayPoint.cs index b2c8de052..5027876c3 100644 --- a/Subsurface/Map/WayPoint.cs +++ b/Subsurface/Map/WayPoint.cs @@ -42,11 +42,6 @@ namespace Subsurface } } - public override Vector2 SimPosition - { - get { return ConvertUnits.ToSimUnits(new Vector2(rect.X, rect.Y)); } - } - public WayPoint(Rectangle newRect) { rect = newRect; @@ -61,14 +56,16 @@ namespace Subsurface { //if (!editing) return; + Point pos = new Point((int)Position.X, (int)Position.Y); + Color clr = (isSelected) ? Color.Red : Color.LightGreen; - GUI.DrawRectangle(spriteBatch, new Rectangle(rect.X, -rect.Y, rect.Width, rect.Height), clr, true); + GUI.DrawRectangle(spriteBatch, new Rectangle(pos.X, -pos.Y, rect.Width, rect.Height), clr, true); foreach (MapEntity e in linkedTo) { GUI.DrawLine(spriteBatch, - new Vector2(rect.X + rect.Width / 2, -rect.Y + rect.Height / 2), - new Vector2(e.Rect.X + e.Rect.Width / 2, -e.Rect.Y + e.Rect.Height / 2), + new Vector2(pos.X, -pos.Y), + new Vector2(e.Position.X + e.Rect.Width / 2, -e.Position.Y + e.Rect.Height / 2), Color.Green); } } diff --git a/Subsurface/Networking/GameClient.cs b/Subsurface/Networking/GameClient.cs index bbbf508c6..ade53d4c7 100644 --- a/Subsurface/Networking/GameClient.cs +++ b/Subsurface/Networking/GameClient.cs @@ -132,7 +132,8 @@ namespace Subsurface.Networking { // All manually sent messages are type of "Data" case NetIncomingMessageType.Data: - if (inc.ReadByte() == (byte)PacketTypes.LoggedIn) + byte packetType = inc.ReadByte(); + if (packetType == (byte)PacketTypes.LoggedIn) { myID = inc.ReadInt32(); @@ -152,7 +153,7 @@ namespace Subsurface.Networking CanStart = true; } - else if (inc.ReadByte() == (byte)PacketTypes.KickedOut) + else if (packetType == (byte)PacketTypes.KickedOut) { string msg = inc.ReadString(); DebugConsole.ThrowError(msg); @@ -199,6 +200,7 @@ namespace Subsurface.Networking SendRandomData(); } + if (gameStarted) inGameHUD.Update((float)Physics.step); if (!connected || updateTimer > DateTime.Now) return; diff --git a/Subsurface/Networking/GameServer.cs b/Subsurface/Networking/GameServer.cs index 79a244cc2..8207cbf78 100644 --- a/Subsurface/Networking/GameServer.cs +++ b/Subsurface/Networking/GameServer.cs @@ -21,6 +21,9 @@ namespace Subsurface.Networking public GameServer() { + var endRoundButton = new GUIButton(new Rectangle(Game1.GraphicsWidth - 170-120, 20, 150, 25), "End round", Alignment.TopLeft, GUI.style, inGameHUD); + endRoundButton.OnClicked = EndButtonHit; + name = "Server"; Config = new NetPeerConfiguration("subsurface"); @@ -49,13 +52,11 @@ namespace Subsurface.Networking updateInterval = new TimeSpan(0, 0, 0, 0, 30); DebugConsole.NewMessage("Server started", Color.Green); - } public override void Update() { - // Server.ReadMessage() Returns new messages, that have not yet been read. - // If "inc" is null -> ReadMessage returned null -> Its null, so dont do this :) + if (gameStarted) inGameHUD.Update((float)Physics.step); NetIncomingMessage inc = Server.ReadMessage(); if (inc != null) @@ -84,6 +85,30 @@ namespace Subsurface.Networking } } + private void SparseUpdate() + { + foreach (Character c in Character.CharacterList) + { + bool isClient = false; + foreach (Client client in connectedClients) + { + if (client.character != c) continue; + isClient = true; + break; + } + + if (!isClient) + { + c.LargeUpdateTimer = 0; + new NetworkEvent(c.ID, false); + } + } + + new NetworkEvent(Submarine.Loaded.ID, false); + + sparseUpdateTimer = DateTime.Now + SparseUpdateInterval; + } + private void ReadMessage(NetIncomingMessage inc) { NetOutgoingMessage outmsg; @@ -224,30 +249,6 @@ namespace Subsurface.Networking } } - private void SparseUpdate() - { - foreach (Character c in Character.CharacterList) - { - bool isClient = false; - foreach (Client client in connectedClients) - { - if (client.character != c) continue; - isClient = true; - break; - } - - if (!isClient) - { - c.LargeUpdateTimer = 0; - new NetworkEvent(c.ID, false); - } - } - - new NetworkEvent(Submarine.Loaded.ID, false); - - sparseUpdateTimer = DateTime.Now + SparseUpdateInterval; - } - private void SendMessage(NetOutgoingMessage msg, NetDeliveryMethod deliveryMethod, NetConnection excludedConnection) { List recipients = new List(); @@ -296,7 +297,6 @@ namespace Subsurface.Networking Submarine selectedMap = Game1.NetLobbyScreen.SelectedMap as Submarine; - //selectedMap.Load(); Game1.GameSession = new GameSession(selectedMap, Game1.NetLobbyScreen.SelectedMode); @@ -378,6 +378,13 @@ namespace Subsurface.Networking return true; } + private bool EndButtonHit(GUIButton button, object obj) + { + Game1.GameSession.gameMode.End("The round has ended"); + + return true; + } + public void EndGame(string endMessage) { Submarine.Unload(); diff --git a/Subsurface/Networking/NetworkMember.cs b/Subsurface/Networking/NetworkMember.cs index 57571f877..d191307d0 100644 --- a/Subsurface/Networking/NetworkMember.cs +++ b/Subsurface/Networking/NetworkMember.cs @@ -1,5 +1,6 @@ using System; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; namespace Subsurface.Networking { @@ -93,12 +94,17 @@ namespace Subsurface.Networking Alignment.Left, null, null, true); msg.Padding = new Vector4(20.0f, 0, 0, 0); - chatBox.AddChild(msg); - while (chatBox.CountChildren > 20) - { - chatBox.RemoveChild(chatBox.children[0]); - } + //float prevScroll = chatBox.BarScroll; + + //chatBox.AddChild(msg); + + //while (chatBox.CountChildren > 20) + //{ + // chatBox.RemoveChild(chatBox.children[0]); + //} + + //if (prevScroll == 1.0f) chatBox.BarScroll = 1.0f; GUI.PlayMessageSound(); } @@ -107,6 +113,13 @@ namespace Subsurface.Networking public virtual void Update() { } + public virtual void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch) + { + if (!gameStarted) return; + + inGameHUD.Draw(spriteBatch); + } + public virtual void Disconnect() { } } diff --git a/Subsurface/Properties.cs b/Subsurface/Properties.cs index caa2ea365..3b4d10fef 100644 --- a/Subsurface/Properties.cs +++ b/Subsurface/Properties.cs @@ -30,16 +30,7 @@ namespace Subsurface this.isSaveable = isSaveable; } } - - //[AttributeUsage(AttributeTargets.Property)] - //public class Saveable : Initable - //{ - // public Saveable(object defaultValue) - // :base(defaultValue) - // { - // } - //} - + class ObjectProperty { readonly PropertyDescriptor property; diff --git a/Subsurface/Screens/NetLobbyScreen.cs b/Subsurface/Screens/NetLobbyScreen.cs index 9d68dfe97..02afdcfc4 100644 --- a/Subsurface/Screens/NetLobbyScreen.cs +++ b/Subsurface/Screens/NetLobbyScreen.cs @@ -31,9 +31,6 @@ namespace Subsurface private float camAngle; - //private Body previewPlatform; - //private Hull previewHull; - public bool IsServer; public Submarine SelectedMap @@ -112,7 +109,7 @@ namespace Subsurface GUI.style, menu); chatBox = new GUIListBox(new Rectangle(0,0,0,chatFrame.Rect.Height-80), Color.White, GUI.style, chatFrame); - textBox = new GUITextBox(new Rectangle(0, 0, 0, 25), Alignment.Bottom, GUI.style, chatFrame); + textBox = new GUITextBox(new Rectangle(0, 25, 0, 25), Alignment.Bottom, GUI.style, chatFrame); textBox.OnEnter = EnterChatMessage; //player info panel ------------------------------------------------------------ @@ -135,18 +132,6 @@ namespace Subsurface public override void Deselect() { textBox.Deselect(); - - //if (previewPlatform!=null) - //{ - // Game1.World.RemoveBody(previewPlatform); - // previewPlatform = null; - //} - - //if (previewHull!=null) - //{ - // previewHull.Remove(); - // previewHull = null; - //} } public override void Select() @@ -186,7 +171,6 @@ namespace Subsurface new GUITextBlock(new Rectangle(220, 30, 0, 30), "Selected game mode: ", GUI.style, infoFrame); modeList = new GUIListBox(new Rectangle(220, 60, 200, 200), GUI.style, infoFrame); modeList.Enabled = (Game1.Server != null); - //modeList.OnSelected = new GUIListBox.OnSelectedHandler(SelectEvent); foreach (GameModePreset mode in GameModePreset.list) { @@ -324,7 +308,8 @@ namespace Subsurface public override void Update(double deltaTime) { base.Update(deltaTime); - + + Game1.GameScreen.Cam.TargetPos = Vector2.Zero; Game1.GameScreen.Cam.MoveCamera((float)deltaTime); Vector2 pos = new Vector2( @@ -342,7 +327,7 @@ namespace Subsurface menu.Update((float)deltaTime); - durationBar.BarScroll = Math.Max(durationBar.BarScroll, 1.0f / 60.0f); + //durationBar.BarScroll = Math.Max(durationBar.BarScroll, 1.0f / 60.0f); } public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch) @@ -361,31 +346,13 @@ namespace Subsurface spriteBatch.End(); - - //if (Game1.Client != null) - //{ - // if (Game1.Client.Character != null) - // { - // Vector2 position = new Vector2(playerFrame.Rect.X + playerFrame.Rect.Width * 0.25f, playerFrame.Rect.Y + 25.0f); - - // Vector2 pos = Game1.Client.Character.Position; - // pos.Y = -pos.Y; - // Matrix transform = Matrix.CreateTranslation(new Vector3(-pos + position, 0.0f)); - - // spriteBatch.Begin(SpriteSortMode.BackToFront, null, null, null, null, null, transform); - // Game1.Client.Character.Draw(spriteBatch); - // spriteBatch.End(); - // } - // else - // { - // CreatePreviewCharacter(); - // } - //} - } public void NewChatMessage(string message, Color color) { + float prevSize = chatBox.BarSize; + float oldScroll = chatBox.BarScroll; + GUITextBlock msg = new GUITextBlock(new Rectangle(0, 0, 0, 20), message, ((chatBox.CountChildren % 2) == 0) ? Color.Transparent : Color.Black*0.1f, color, @@ -393,6 +360,8 @@ namespace Subsurface msg.Padding = new Vector4(20, 0, 0, 0); chatBox.AddChild(msg); + + if ((prevSize == 1.0f && chatBox.BarScroll == 0.0f) || (prevSize < 1.0f && chatBox.BarScroll == 1.0f)) chatBox.BarScroll = 1.0f; } diff --git a/Subsurface/Subsurface.csproj b/Subsurface/Subsurface.csproj index 71f9a4b30..268807c0d 100644 --- a/Subsurface/Subsurface.csproj +++ b/Subsurface/Subsurface.csproj @@ -659,6 +659,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/Subsurface/Subsurface.csproj.user b/Subsurface/Subsurface.csproj.user index 693505ea4..505c3a0bf 100644 --- a/Subsurface/Subsurface.csproj.user +++ b/Subsurface/Subsurface.csproj.user @@ -9,6 +9,6 @@ en-US false - ShowAllFiles + ProjectFiles \ No newline at end of file diff --git a/Subsurface_Solution.v12.suo b/Subsurface_Solution.v12.suo index d0c3c4db5..a8a0ae7a1 100644 Binary files a/Subsurface_Solution.v12.suo and b/Subsurface_Solution.v12.suo differ