diff --git a/Farseer Physics Engine 3.5/Farseer Physics Engine.v12.suo b/Farseer Physics Engine 3.5/Farseer Physics Engine.v12.suo new file mode 100644 index 000000000..7d0e3e068 Binary files /dev/null and b/Farseer Physics Engine 3.5/Farseer Physics Engine.v12.suo differ diff --git a/Launcher/PackageManager.cs b/Launcher/PackageManager.cs index 61e9b7e2e..b1270721f 100644 --- a/Launcher/PackageManager.cs +++ b/Launcher/PackageManager.cs @@ -96,28 +96,25 @@ namespace Launcher fileButton.Enabled = (selectedPackage != null); } - if (selectedPackage == null) + + foreach (ListBox fileBox in fileBoxes) { - foreach (ListBox fileBox in fileBoxes) + fileBox.Items.Clear(); + } + + + foreach (ListBox fileBox in fileBoxes) + { + ContentType type = (fileBox.Tag is ContentType) ? (ContentType)fileBox.Tag : ContentType.None; + + foreach (ContentFile file in selectedPackage.files) { - fileBox.Items.Clear(); - } - } - else - { - - foreach (ListBox fileBox in fileBoxes) - { - ContentType type = (fileBox.Tag is ContentType) ? (ContentType)fileBox.Tag : ContentType.None; - - foreach (ContentFile file in selectedPackage.files) - { - if (file.type != type) continue; - - fileBox.Items.Add(file); - } + if (file.type != type) continue; + + fileBox.Items.Add(file); } } + } private void newPackage_Click(object sender, EventArgs e) diff --git a/Subsurface/Properties/AssemblyInfo.cs b/Subsurface/Properties/AssemblyInfo.cs index eaf2f38aa..511733048 100644 --- a/Subsurface/Properties/AssemblyInfo.cs +++ b/Subsurface/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.1.2.0")] -[assembly: AssemblyFileVersion("0.1.2.0")] +[assembly: AssemblyVersion("0.1.3.1")] +[assembly: AssemblyFileVersion("0.1.3.1")] diff --git a/Subsurface/Source/Characters/AI/EnemyAIController.cs b/Subsurface/Source/Characters/AI/EnemyAIController.cs index 80131efd7..ffdba403f 100644 --- a/Subsurface/Source/Characters/AI/EnemyAIController.cs +++ b/Subsurface/Source/Characters/AI/EnemyAIController.cs @@ -470,14 +470,21 @@ namespace Subsurface public override void FillNetworkData(NetOutgoingMessage message) { message.Write((byte)state); + + bool wallAttack = (wallAttackPos!=Vector2.Zero && state == AiState.Attack); - message.Write(wallAttackPos.X); - message.Write(wallAttackPos.Y); + message.Write(wallAttack); - message.Write(steeringManager.WanderAngle); - message.Write(updateTargetsTimer); - message.Write(raycastTimer); - message.Write(coolDownTimer); + if (wallAttack) + { + message.Write(wallAttackPos.X); + message.Write(wallAttackPos.Y); + } + + message.Write(MathUtils.AngleToByte(steeringManager.WanderAngle)); + message.WriteRangedSingle(Math.Max(updateTargetsTimer,0.0f), 0.0f, UpdateTargetsInterval, 8); + message.WriteRangedSingle(Math.Max(raycastTimer,0.0f), 0.0f, RaycastInterval, 8); + message.WriteRangedSingle(Math.Max(coolDownTimer, 0.0f), 0.0f, attackCoolDown*2.0f, 8); message.Write(targetEntity==null ? -1 : (targetEntity as Entity).ID); } @@ -485,7 +492,7 @@ namespace Subsurface public override void ReadNetworkData(NetIncomingMessage message) { AiState newState = AiState.None; - Vector2 newWallAttackPos; + Vector2 newWallAttackPos = Vector2.Zero; float wanderAngle; float updateTargetsTimer, raycastTimer, coolDownTimer; @@ -495,12 +502,18 @@ namespace Subsurface { newState = (AiState)(message.ReadByte()); - newWallAttackPos = new Vector2(message.ReadFloat(), message.ReadFloat()); - wanderAngle = MathUtils.WrapAngleTwoPi(message.ReadFloat()); - updateTargetsTimer = MathHelper.Clamp(message.ReadFloat(), 0.0f, UpdateTargetsInterval); - raycastTimer = MathHelper.Clamp(message.ReadFloat(), 0.0f, RaycastInterval); - coolDownTimer = MathHelper.Clamp(message.ReadFloat(), 0.0f, attackCoolDown); + bool wallAttack = message.ReadBoolean(); + + if (wallAttack) + { + newWallAttackPos = new Vector2(message.ReadFloat(), message.ReadFloat()); + } + + wanderAngle = MathUtils.ByteToAngle(message.ReadByte()); + updateTargetsTimer = message.ReadRangedSingle(0.0f, UpdateTargetsInterval, 8); + raycastTimer = message.ReadRangedSingle(0.0f, RaycastInterval, 8); + coolDownTimer = message.ReadRangedSingle(0.0f, attackCoolDown*2.0f, 8); targetID = message.ReadInt32(); } diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index 3d9009f48..85b126a30 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -426,6 +426,11 @@ namespace Subsurface } } + public override string ToString() + { + return (info != null && !string.IsNullOrWhiteSpace(info.Name)) ? info.Name : SpeciesName; + } + public void GiveJobItems(WayPoint spawnPoint) { if (info == null || info.Job == null) return; @@ -1032,14 +1037,17 @@ namespace Subsurface message.Write(NetTime.Now); // Write byte = move direction - message.Write(AnimController.TargetMovement.X); - message.Write(AnimController.TargetMovement.Y); + message.WriteRangedSingle(AnimController.TargetMovement.X, -10.0f, 10.0f, 8); + message.WriteRangedSingle(AnimController.TargetMovement.Y, -10.0f, 10.0f, 8); message.Write(AnimController.TargetDir==Direction.Right); - message.Write(cursorPosition.X); - message.Write(cursorPosition.Y); - + if (aiController!=null) + { + message.WriteRangedSingle(cursorPosition.X, -1000.0f, 1000.0f, 16); + message.WriteRangedSingle(cursorPosition.Y, -1000.0f, 1000.0f, 16); + } + message.Write(LargeUpdateTimer <= 0); if (LargeUpdateTimer<=0) @@ -1053,29 +1061,28 @@ namespace Subsurface message.Write(limb.body.LinearVelocity.X); message.Write(limb.body.LinearVelocity.Y); - message.Write(limb.body.Rotation); + message.Write(MathUtils.AngleToByte(limb.body.Rotation)); message.Write(limb.body.AngularVelocity); i++; } - message.Write(AnimController.StunTimer); + message.WriteRangedSingle(AnimController.StunTimer, 0.0f, 60.0f, 8); message.Write((byte)health); - LargeUpdateTimer = 5; + if (aiController != null) aiController.FillNetworkData(message); + + LargeUpdateTimer = 10; } else { Limb torso = AnimController.GetLimb(LimbType.Torso); + if (torso == null) torso = AnimController.GetLimb(LimbType.Head); + message.Write(torso.body.Position.X); message.Write(torso.body.Position.Y); LargeUpdateTimer = Math.Max(0, LargeUpdateTimer-1); - } - - - - if (aiController != null) aiController.FillNetworkData(message); - + } } public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message) @@ -1127,10 +1134,19 @@ namespace Subsurface sendingTime = message.ReadDouble(); - targetMovement = new Vector2 (message.ReadFloat(), message.ReadFloat()); + targetMovement = new Vector2(message.ReadRangedSingle(-10.0f, 10.0f, 8), message.ReadRangedSingle(-10.0f, 10.0f, 8)); + targetMovement.X = MathUtils.Round(targetMovement.X, 0.1f); + targetMovement.Y = MathUtils.Round(targetMovement.Y, 0.1f); + targetDir = message.ReadBoolean(); - cursorPos = new Vector2(message.ReadFloat(), message.ReadFloat()); + if (aiController!=null) + { + cursorPos = new Vector2( + message.ReadRangedSingle(-1000.0f, 1000.0f, 16), + message.ReadRangedSingle(-1000.0f, 1000.0f, 16)); + } + } catch @@ -1165,7 +1181,7 @@ namespace Subsurface vel.X = message.ReadFloat(); vel.Y = message.ReadFloat(); - rotation = message.ReadFloat(); + rotation = MathUtils.ByteToAngle(message.ReadByte()); angularVel = message.ReadFloat(); } catch @@ -1187,7 +1203,7 @@ namespace Subsurface try { - newStunTimer = message.ReadFloat(); + newStunTimer = message.ReadRangedSingle(0.0f, 60.0f, 8); newHealth = message.ReadByte(); } catch { return; } @@ -1196,6 +1212,8 @@ namespace Subsurface Health = newHealth; LargeUpdateTimer = 1; + + if (aiController != null) aiController.ReadNetworkData(message); } else { @@ -1210,13 +1228,12 @@ namespace Subsurface Limb torso = AnimController.GetLimb(LimbType.Torso); + if (torso == null) torso = AnimController.GetLimb(LimbType.Head); torso.body.TargetPosition = pos; LargeUpdateTimer = 0; } - if (aiController != null) aiController.ReadNetworkData(message); - LastNetworkUpdate = sendingTime; } diff --git a/Subsurface/Source/Characters/CharacterInfo.cs b/Subsurface/Source/Characters/CharacterInfo.cs index be1b2bf5a..b2d473d47 100644 --- a/Subsurface/Source/Characters/CharacterInfo.cs +++ b/Subsurface/Source/Characters/CharacterInfo.cs @@ -269,7 +269,7 @@ namespace Subsurface { UpdateCharacterItems(); } - + if (pickedItems.Count > 0) { charElement.Add(new XAttribute("items", string.Join(",", pickedItems))); diff --git a/Subsurface/Source/GameSession/GameModes/TraitorMode.cs b/Subsurface/Source/GameSession/GameModes/TraitorMode.cs index cd8d1c537..76d3bffb6 100644 --- a/Subsurface/Source/GameSession/GameModes/TraitorMode.cs +++ b/Subsurface/Source/GameSession/GameModes/TraitorMode.cs @@ -63,8 +63,10 @@ namespace Subsurface { string endMessage = traitor.character.Info.Name + " was a traitor! "; endMessage += (traitor.character.Info.Gender == Gender.Male) ? "His" : "Her"; - endMessage += " task was to assassinate " + target.character.Info.Name + ". "; - endMessage += "The task was unsuccessful - the has submarine reached its destination."; + endMessage += " task was to assassinate " + target.character.Info.Name + ", but "; + endMessage += (traitor.character.Info.Gender == Gender.Male) ? "he" : "she"; + endMessage += " got " + ((traitor.character.Info.Gender == Gender.Male) ? "himself" : "herself"); + endMessage += " killed before completing it."; End(endMessage); return; } @@ -72,10 +74,8 @@ namespace Subsurface { string endMessage = traitor.character.Info.Name + " was a traitor! "; endMessage += (traitor.character.Info.Gender == Gender.Male) ? "His" : "Her"; - endMessage += " task was to assassinate " + target.character.Info.Name + ", but "; - endMessage += (traitor.character.Info.Gender == Gender.Male) ? "he" : "she"; - endMessage += " got " + ((traitor.character.Info.Gender == Gender.Male) ? "himself" : "herself"); - endMessage += " killed before completing it."; + endMessage += " task was to assassinate " + target.character.Info.Name + ". "; + endMessage += "The task was unsuccessful - the has submarine reached its destination."; End(endMessage); return; } diff --git a/Subsurface/Source/GameSettings.cs b/Subsurface/Source/GameSettings.cs index 088b0489f..a1831609a 100644 --- a/Subsurface/Source/GameSettings.cs +++ b/Subsurface/Source/GameSettings.cs @@ -52,6 +52,21 @@ namespace Subsurface GraphicsHeight = int.Parse(graphicsMode.Attribute("height").Value); FullScreenEnabled = graphicsMode.Attribute("fullscreen").Value == "true"; + + MasterServerUrl = ToolBox.GetAttributeString(doc.Root, "masterserverurl", ""); + + foreach (XElement subElement in doc.Root.Elements()) + { + switch (subElement.Name.ToString().ToLower()) + { + case "contentpackage": + string path = ToolBox.GetAttributeString(subElement, "path", ""); + SelectedContentPackage = ContentPackage.list.Find(cp => cp.Path == path); + + if (SelectedContentPackage == null) SelectedContentPackage = new ContentPackage(path); + break; + } + } } catch { @@ -60,20 +75,7 @@ namespace Subsurface } - MasterServerUrl = ToolBox.GetAttributeString(doc.Root, "masterserverurl", ""); - foreach (XElement subElement in doc.Root.Elements()) - { - switch (subElement.Name.ToString().ToLower()) - { - case "contentpackage": - string path = ToolBox.GetAttributeString(subElement, "path", ""); - SelectedContentPackage = ContentPackage.list.Find(cp => cp.Path == path); - - if (SelectedContentPackage == null) SelectedContentPackage = new ContentPackage(path); - break; - } - } } @@ -86,6 +88,8 @@ namespace Subsurface doc.Add(new XElement("config")); } + doc.Root.Add(new XAttribute("masterserverurl", MasterServerUrl)); + XElement gMode = doc.Root.Element("graphicsmode"); if (gMode == null) { diff --git a/Subsurface/Source/Items/CharacterInventory.cs b/Subsurface/Source/Items/CharacterInventory.cs index 25db5d641..d705153bb 100644 --- a/Subsurface/Source/Items/CharacterInventory.cs +++ b/Subsurface/Source/Items/CharacterInventory.cs @@ -139,16 +139,17 @@ namespace Subsurface if (items[i] != null) { bool combined = false; - if (item.Combine(items[i])) - { - //PutItem(item, i, false, false); - combined = true; - } - //else if (items[i].Combine(item)) + //if (item.Combine(items[i])) //{ - // //PutItem(items[i], i, false, false); + // //PutItem(item, i, false, false); // combined = true; //} + //else + if (items[i].Combine(item)) + { + //PutItem(items[i], i, false, false); + combined = true; + } if (!combined) return false; diff --git a/Subsurface/Source/Items/Components/Machines/Controller.cs b/Subsurface/Source/Items/Components/Machines/Controller.cs index a968e8ed9..9bd231f5a 100644 --- a/Subsurface/Source/Items/Components/Machines/Controller.cs +++ b/Subsurface/Source/Items/Components/Machines/Controller.cs @@ -66,7 +66,9 @@ namespace Subsurface.Items.Components { this.cam = cam; - if (character == null || character.SelectedConstruction != item) + if (character == null + || character.SelectedConstruction != item + || Vector2.Distance(character.SimPosition, item.SimPosition) > item.PickDistance * 1.5f) { if (character != null) { diff --git a/Subsurface/Source/Items/Components/Machines/Reactor.cs b/Subsurface/Source/Items/Components/Machines/Reactor.cs index afe8c36d5..a2351be9d 100644 --- a/Subsurface/Source/Items/Components/Machines/Reactor.cs +++ b/Subsurface/Source/Items/Components/Machines/Reactor.cs @@ -239,24 +239,15 @@ namespace Subsurface.Items.Components new RepairTask(item, 60.0f, "Reactor meltdown!"); item.Condition = 0.0f; - //fissionRate = 0.0f; - //coolingRate = 0.0f; - //PlaySound(ActionType.OnFailure, item.Position); - //item.ApplyStatusEffects(ActionType.OnFailure, 1.0f, null); - - //new Explosion(item.SimPosition, 6.0f, 500.0f, 600.0f, 10.0f, 2.0f).Explode(); + var containedItems = item.ContainedItems; + if (containedItems == null) return; - if (item.ContainedItems!=null) + foreach (Item containedItem in item.ContainedItems) { - foreach (Item containedItem in item.ContainedItems) - { - if (containedItem == null) continue; - containedItem.Condition = 0.0f; - } + if (containedItem == null) continue; + containedItem.Condition = 0.0f; } - - } public override bool Pick(Character picker) diff --git a/Subsurface/Source/Items/Components/Projectile.cs b/Subsurface/Source/Items/Components/Projectile.cs index 122574f22..8deae4633 100644 --- a/Subsurface/Source/Items/Components/Projectile.cs +++ b/Subsurface/Source/Items/Components/Projectile.cs @@ -173,16 +173,19 @@ namespace Subsurface.Items.Components (float)Math.Cos(item.body.Rotation), (float)Math.Sin(item.body.Rotation)); - if (Vector2.Dot(f1.Body.LinearVelocity, normal)<0 ) return StickToTarget(f2.Body, dir); + if (Vector2.Dot(f1.Body.LinearVelocity, normal) < 0.0f) return StickToTarget(f2.Body, dir); } - foreach (Item contained in item.ContainedItems) + + var containedItems = item.ContainedItems; + if (containedItems == null) return true; + foreach (Item contained in containedItems) { - contained.Condition = 0.0f; if (contained.body != null) { - contained.body.SetTransform(item.SimPosition, contained.body.Rotation); + contained.SetTransform(item.SimPosition, contained.body.Rotation); } + contained.Condition = 0.0f; } return true; diff --git a/Subsurface/Source/Items/Item.cs b/Subsurface/Source/Items/Item.cs index a6b4e95be..cf030ec47 100644 --- a/Subsurface/Source/Items/Item.cs +++ b/Subsurface/Source/Items/Item.cs @@ -61,6 +61,11 @@ namespace Subsurface get { return prefab.sprite; } } + public float PickDistance + { + get { return prefab.PickDistance; } + } + public float Condition { get { return condition; } diff --git a/Subsurface/Source/Map/Submarine.cs b/Subsurface/Source/Map/Submarine.cs index 260ee1d2f..4d09ddcb1 100644 --- a/Subsurface/Source/Map/Submarine.cs +++ b/Subsurface/Source/Map/Submarine.cs @@ -505,7 +505,7 @@ namespace Subsurface private void Translate(Vector2 amount) { - if (amount == Vector2.Zero) return; + if (amount == Vector2.Zero || ! amount.IsValid()) return; Level.Loaded.Move(-amount); } @@ -516,11 +516,6 @@ namespace Subsurface speed += force/mass; } - //public void Move(Vector2 amount) - //{ - // speed = Vector2.Lerp(speed, amount, 0.05f); - //} - VoronoiCell collidingCell; public bool OnCollision(Fixture f1, Fixture f2, Contact contact) { @@ -597,6 +592,8 @@ namespace Subsurface return; } + if (!speed.IsValid() || targetPosition.IsValid()) return; + //newTargetPosition = newTargetPosition + newSpeed * (float)(NetTime.Now - sendingTime); targetPosition = newTargetPosition; diff --git a/Subsurface/Source/Networking/GameClient.cs b/Subsurface/Source/Networking/GameClient.cs index 57a8dbd23..47fcbd36a 100644 --- a/Subsurface/Source/Networking/GameClient.cs +++ b/Subsurface/Source/Networking/GameClient.cs @@ -74,8 +74,8 @@ namespace Subsurface.Networking // Create new instance of configs. Parameter is "application Id". It has to be same on client and server. NetPeerConfiguration Config = new NetPeerConfiguration("subsurface"); - //Config.SimulatedLoss = 0.2f; - //Config.SimulatedMinimumLatency = 0.25f; + Config.SimulatedLoss = 0.2f; + Config.SimulatedMinimumLatency = 0.5f; // Create new client, with previously created configs client = new NetClient(Config); @@ -141,7 +141,7 @@ namespace Subsurface.Networking // When this is set to true, we are approved and ready to go bool CanStart = false; - DateTime timeOut = DateTime.Now + new TimeSpan(0,0,5); + DateTime timeOut = DateTime.Now + new TimeSpan(0,0,15); // Loop untill we are approved while (!CanStart) @@ -421,6 +421,26 @@ namespace Subsurface.Networking gameStarted = false; } + public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch) + { + base.Draw(spriteBatch); + + if (!Game1.DebugDraw) return; + + int width = 200, height = 300; + int x = Game1.GraphicsWidth - width, y = (int)(Game1.GraphicsHeight * 0.3f); + + GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black * 0.7f, true); + spriteBatch.DrawString(GUI.Font, "Network statistics:", new Vector2(x + 10, y + 10), Color.White); + + spriteBatch.DrawString(GUI.SmallFont, "Received bytes: " + client.Statistics.ReceivedBytes, new Vector2(x + 10, y + 45), Color.White); + spriteBatch.DrawString(GUI.SmallFont, "Received packets: " + client.Statistics.ReceivedPackets, new Vector2(x + 10, y + 60), Color.White); + + spriteBatch.DrawString(GUI.SmallFont, "Sent bytes: " + client.Statistics.SentBytes, new Vector2(x + 10, y + 75), Color.White); + spriteBatch.DrawString(GUI.SmallFont, "Sent packets: " + client.Statistics.SentPackets, new Vector2(x + 10, y + 90), Color.White); + + } + public override void Disconnect() { NetOutgoingMessage msg = client.CreateMessage(); @@ -514,7 +534,7 @@ namespace Subsurface.Networking msg.Write((byte)type); msg.Write(message); - client.SendMessage(msg, NetDeliveryMethod.Unreliable); + client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered); } /// diff --git a/Subsurface/Source/Networking/GameServer.cs b/Subsurface/Source/Networking/GameServer.cs index a1d961eb4..95ba6e8ad 100644 --- a/Subsurface/Source/Networking/GameServer.cs +++ b/Subsurface/Source/Networking/GameServer.cs @@ -38,12 +38,12 @@ namespace Subsurface.Networking this.name = name; this.password = password; - + config = new NetPeerConfiguration("subsurface"); - //config.SimulatedLoss = 0.2f; - //config.SimulatedMinimumLatency = 0.25f; - + config.SimulatedLoss = 0.2f; + config.SimulatedMinimumLatency = 0.5f; + config.Port = port; Port = port; @@ -222,7 +222,7 @@ namespace Subsurface.Networking if (!isClient) { - c.LargeUpdateTimer = 0; + //c.LargeUpdateTimer = 0; new NetworkEvent(c.ID, false); } } @@ -259,32 +259,38 @@ namespace Subsurface.Networking catch { inc.SenderConnection.Deny("Connection error - server failed to read your ConnectionApproval message"); + DebugConsole.NewMessage("Connection error - server failed to read the ConnectionApproval message", Color.Red); break; } if (userPassword != password) { inc.SenderConnection.Deny("Wrong password!"); + break; } else if (version != Game1.Version.ToString()) { inc.SenderConnection.Deny("Subsurface version " + Game1.Version + " required to connect to the server (Your version: " + version + ")"); + DebugConsole.NewMessage("Connection error - wrong game version", Color.Red); break; } else if (packageName != Game1.SelectedPackage.Name) { inc.SenderConnection.Deny("Your content package ("+packageName+") doesn't match the server's version (" + Game1.SelectedPackage.Name + ")"); + DebugConsole.NewMessage("Connection error - wrong content package name", Color.Red); break; } else if (packageHash != Game1.SelectedPackage.MD5hash.Hash) { inc.SenderConnection.Deny("Your content package (MD5: " + packageHash + ") doesn't match the server's version (MD5: " + Game1.SelectedPackage.MD5hash.Hash + ")"); + DebugConsole.NewMessage("Connection error - wrong content package hash", Color.Red); break; } else if (connectedClients.Find(c => c.name.ToLower() == name.ToLower())!=null) { inc.SenderConnection.Deny("The name ''" + name + "'' is already in use. Please choose another name."); + DebugConsole.NewMessage("Connection error - name already in use", Color.Red); break; } @@ -397,7 +403,9 @@ namespace Subsurface.Networking } if (recipients.Count == 0) break; - server.SendMessage(outmsg, recipients, inc.DeliveryMethod, 0); + server.SendMessage(outmsg, recipients, inc.DeliveryMethod, 0); + + System.Diagnostics.Debug.WriteLine("Sending networkevent (" + outmsg.LengthBytes+" bytes)"); break; case (byte)PacketTypes.Chatmessage: @@ -451,6 +459,8 @@ namespace Subsurface.Networking networkEvent.FillData(message); + System.Diagnostics.Debug.WriteLine("Sending networkevent " + Entity.FindEntityByID(networkEvent.ID).ToString() + " (" + message.LengthBytes + " bytes)"); + if (server.ConnectionsCount>0) { server.SendMessage(message, server.Connections, @@ -464,13 +474,19 @@ namespace Subsurface.Networking public bool StartGame(GUIButton button, object obj) { + Submarine selectedMap = Game1.NetLobbyScreen.SelectedMap as Submarine; + + if (selectedMap == null) + { + Game1.NetLobbyScreen.SubList.Flash(); + return false; + } + int seed = DateTime.Now.Millisecond; Rand.SetSyncedSeed(seed); - AssignJobs(); - - Submarine selectedMap = Game1.NetLobbyScreen.SelectedMap as Submarine; - + AssignJobs(); + //selectedMap.Load(); Game1.GameSession = new GameSession(selectedMap, "", Game1.NetLobbyScreen.SelectedMode); @@ -654,7 +670,7 @@ namespace Subsurface.Networking public void NewTraitor(Client traitor, Client target) { - new GUIMessageBox("New traitor", traitor.name + " is the traitor and the target is " + target+"."); + new GUIMessageBox("New traitor", traitor.name + " is the traitor and the target is " + target.name+"."); NetOutgoingMessage msg = server.CreateMessage(); msg.Write((byte)PacketTypes.Traitor); @@ -665,6 +681,38 @@ namespace Subsurface.Networking } } + public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch) + { + base.Draw(spriteBatch); + + if (!Game1.DebugDraw) return; + + int width = 200, height = 300; + int x = Game1.GraphicsWidth - width, y = (int)(Game1.GraphicsHeight*0.3f); + + GUI.DrawRectangle(spriteBatch, new Rectangle(x,y,width,height), Color.Black*0.7f, true); + spriteBatch.DrawString(GUI.Font, "Network statistics:", new Vector2(x+10, y+10), Color.White); + + spriteBatch.DrawString(GUI.SmallFont, "Connections: "+server.ConnectionsCount, new Vector2(x + 10, y + 30), Color.White); + spriteBatch.DrawString(GUI.SmallFont, "Received bytes: " + server.Statistics.ReceivedBytes, new Vector2(x + 10, y + 45), Color.White); + spriteBatch.DrawString(GUI.SmallFont, "Received packets: " + server.Statistics.ReceivedPackets, new Vector2(x + 10, y + 60), Color.White); + + spriteBatch.DrawString(GUI.SmallFont, "Sent bytes: " + server.Statistics.SentBytes, new Vector2(x + 10, y + 75), Color.White); + spriteBatch.DrawString(GUI.SmallFont, "Sent packets: " + server.Statistics.SentPackets, new Vector2(x + 10, y + 90), Color.White); + + + y += 110; + foreach (Client c in connectedClients) + { + spriteBatch.DrawString(GUI.SmallFont, c.name + ":", new Vector2(x + 10, y), Color.White); + spriteBatch.DrawString(GUI.SmallFont, "- avg roundtrip " + c.Connection.AverageRoundtripTime+" s", new Vector2(x + 20, y + 15), Color.White); + spriteBatch.DrawString(GUI.SmallFont, "- current MTU " + c.Connection.CurrentMTU, new Vector2(x + 20, y + 30), Color.White); + y += 50; + + } + + } + public bool UpdateNetLobby(object obj) { NetOutgoingMessage msg = server.CreateMessage(); @@ -699,12 +747,12 @@ namespace Subsurface.Networking } if (recipients.Count>0) { - server.SendMessage(msg, recipients, NetDeliveryMethod.Unreliable, 0); + server.SendMessage(msg, recipients, NetDeliveryMethod.ReliableUnordered, 0); } } else { - server.SendMessage(msg, server.Connections, NetDeliveryMethod.Unreliable, 0); + server.SendMessage(msg, server.Connections, NetDeliveryMethod.ReliableUnordered, 0); } } diff --git a/Subsurface/Source/Networking/NetworkEvent.cs b/Subsurface/Source/Networking/NetworkEvent.cs index e2d699ffc..47daaed52 100644 --- a/Subsurface/Source/Networking/NetworkEvent.cs +++ b/Subsurface/Source/Networking/NetworkEvent.cs @@ -113,6 +113,8 @@ namespace Subsurface.Networking return false; } + System.Diagnostics.Debug.WriteLine("Networkevent entity: "+e.ToString()); + //System.Diagnostics.Debug.WriteLine("new message: " + eventType +" - "+e); e.ReadNetworkData(eventType, message); diff --git a/Subsurface/Source/Screens/LobbyScreen.cs b/Subsurface/Source/Screens/LobbyScreen.cs index 04160fa25..266740951 100644 --- a/Subsurface/Source/Screens/LobbyScreen.cs +++ b/Subsurface/Source/Screens/LobbyScreen.cs @@ -428,7 +428,7 @@ namespace Subsurface private bool StartShift(GUIButton button, object selection) { - Game1.GameSession.StartShift(TimeSpan.Zero, selectedLevel); + Game1.GameSession.StartShift(TimeSpan.Zero, selectedLevel, false); Game1.GameScreen.Select(); return true; diff --git a/Subsurface/Source/Screens/NetLobbyScreen.cs b/Subsurface/Source/Screens/NetLobbyScreen.cs index 993e285c7..9cbcae64f 100644 --- a/Subsurface/Source/Screens/NetLobbyScreen.cs +++ b/Subsurface/Source/Screens/NetLobbyScreen.cs @@ -23,8 +23,6 @@ namespace Subsurface private GUITextBox textBox, seedBox; - //GUIFrame previewPlayer; - private GUIScrollBar durationBar; private GUIFrame playerFrame; @@ -36,6 +34,11 @@ namespace Subsurface private GUITextBox serverMessage; + public GUIListBox SubList + { + get { return subList; } + } + public Submarine SelectedMap { get { return subList.SelectedData as Submarine; } @@ -275,7 +278,7 @@ namespace Subsurface modeList.OnSelected += Game1.Server.UpdateNetLobby; durationBar.OnMoved = Game1.Server.UpdateNetLobby; - if (subList.CountChildren > 0) subList.Select(0); + if (subList.CountChildren > 0) subList.Select(-1); if (GameModePreset.list.Count > 0) modeList.Select(0); } else if (playerFrame.children.Count==0) @@ -443,6 +446,7 @@ namespace Subsurface ((chatBox.CountChildren % 2) == 0) ? Color.Transparent : Color.Black*0.1f, color, Alignment.Left, GUI.style, null, true); msg.Font = GUI.SmallFont; + msg.CanBeFocused = false; msg.Padding = new Vector4(20, 0, 0, 0); chatBox.AddChild(msg); @@ -658,57 +662,13 @@ namespace Subsurface return; } - TrySelectMap(mapName, md5Hash); + if (!string.IsNullOrWhiteSpace(mapName)) TrySelectMap(mapName, md5Hash); modeList.Select(modeIndex); durationBar.BarScroll = durationScroll; LevelSeed = levelSeed; - - //try - //{ - // int playerCount = msg.ReadInt32(); - - // for (int i = 0; i < playerCount; i++) - // { - // int clientID = msg.ReadInt32(); - // string jobName = msg.ReadString(); - - // Client client = null; - // GUITextBlock textBlock = null; - // foreach (GUIComponent child in playerList.children) - // { - // Client tempClient = child.UserData as Client; - // if (tempClient == null || tempClient.ID != clientID) continue; - - // client = tempClient; - // textBlock = child as GUITextBlock; - // break; - // } - // if (client == null) continue; - - // client.assignedJob = JobPrefab.List.Find(jp => jp.Name == jobName); - - // textBlock.Text = client.name + ((client.assignedJob==null) ? "" : " (" + client.assignedJob.Name + ")"); - - // if (client.assignedJob==null || jobName != client.assignedJob.Name) - // { - // if (clientID == Game1.Client.ID) - // { - // Game1.Client.CharacterInfo.Job = new Job(client.assignedJob); - // Game1.Client.CharacterInfo.Name = client.name; - // UpdatePreviewPlayer(Game1.Client.CharacterInfo); - // } - // } - // } - //} - - //catch - //{ - // return; - //} - } } diff --git a/Subsurface/Source/Screens/ServerListScreen.cs b/Subsurface/Source/Screens/ServerListScreen.cs index 6534975bd..00dd70f84 100644 --- a/Subsurface/Source/Screens/ServerListScreen.cs +++ b/Subsurface/Source/Screens/ServerListScreen.cs @@ -51,11 +51,6 @@ namespace Subsurface new GUITextBlock(new Rectangle(0, 100, 0, 30), "Server IP:", GUI.style, menu); ipBox = new GUITextBox(new Rectangle(0, 130, 200, 30), GUI.style, menu); - - - - - int middleX = (int)(width * 0.4f); serverList = new GUIListBox(new Rectangle(middleX,60,0,(int)(height*0.7f)), GUI.style, menu); @@ -80,6 +75,10 @@ namespace Subsurface joinButton = new GUIButton(new Rectangle(0,0,150,30), "Join", Alignment.BottomRight, GUI.style, menu); joinButton.OnClicked = JoinServer; + + GUIButton button = new GUIButton(new Rectangle(-20, -20, 100, 30), "Back", Alignment.TopLeft, GUI.style, menu); + button.UserData = 0; + button.OnClicked = Game1.MainMenuScreen.SelectTab; refreshDisableTimer = DateTime.Now; @@ -286,7 +285,7 @@ namespace Subsurface { string selectedPassword = ""; - if ((serverList.Selected.GetChild("password") as GUITickBox).Selected) + if (serverList.Selected!=null && (serverList.Selected.GetChild("password") as GUITickBox).Selected) { var msgBox = new GUIMessageBox("Password required", ""); var passwordBox = new GUITextBox(new Rectangle(0,0,150,20), Alignment.BottomCenter, GUI.style, msgBox); diff --git a/Subsurface/Source/Utils/MathUtils.cs b/Subsurface/Source/Utils/MathUtils.cs index 02ae459b5..1a0d088e5 100644 --- a/Subsurface/Source/Utils/MathUtils.cs +++ b/Subsurface/Source/Utils/MathUtils.cs @@ -17,7 +17,9 @@ namespace Subsurface public static float Round(float value, float div) { - return (float)Math.Floor(value / div) * div; + return (value < 0.0f) ? + (float)Math.Ceiling(value / div) * div : + (float)Math.Floor(value / div) * div; } public static float VectorToAngle(Vector2 vector) diff --git a/Subsurface/Source/Utils/SaveUtil.cs b/Subsurface/Source/Utils/SaveUtil.cs index b9111f1ad..5836779c1 100644 --- a/Subsurface/Source/Utils/SaveUtil.cs +++ b/Subsurface/Source/Utils/SaveUtil.cs @@ -55,11 +55,16 @@ namespace Subsurface { DebugConsole.ThrowError("Error saving gamesession", e); } - //Game1.GameSession.crewManager.Save(directory+"\\crew.xml"); + + try + { + CompressDirectory(tempPath, fileName+".save", null); + } - CompressDirectory(tempPath, fileName+".save", null); - - //Directory.Delete(tempPath, true); + catch (Exception e) + { + DebugConsole.ThrowError("Error compressing save file", e); + } } public static void LoadGame(string fileName) diff --git a/Subsurface/changelog.txt b/Subsurface/changelog.txt index 49db66232..e4c559a3a 100644 --- a/Subsurface/changelog.txt +++ b/Subsurface/changelog.txt @@ -1,3 +1,27 @@ + +--------------------------------------------------------------------------------------------------------- +v0.1.3.1 +--------------------------------------------------------------------------------------------------------- + +Multiplayer: + - chat messages are sent reliably + +--------------------------------------------------------------------------------------------------------- +v0.1.3 +--------------------------------------------------------------------------------------------------------- + +Multiplayer: + - fixed master server connection errors in server list screen + - fixed a bug that caused other characters to get "stuck" to the railgun controller, causing them + to fly back to it as they try to move away + +Items: + - putting items inside other items works properly now (i.e. by pulling a spear to the same slot as + a harpoon, not the other way around) + - C4 blocks loaded inside a railgun shell won't explode inside the submarine when firing the railgun + - fixed another game-crashing railgun bug + - fixed a bug that caused characters to spawn with an incorrect number of items + --------------------------------------------------------------------------------------------------------- v0.1.2 --------------------------------------------------------------------------------------------------------- diff --git a/Subsurface_Solution.v12.suo b/Subsurface_Solution.v12.suo index fd62b5402..081fd5b1c 100644 Binary files a/Subsurface_Solution.v12.suo and b/Subsurface_Solution.v12.suo differ diff --git a/Subsurface_content/Subsurface_content/Subsurface_content.csproj.PSM.cachefile b/Subsurface_content/Subsurface_content/Subsurface_content.csproj.PSM.cachefile index 1c77f5a53..2a3436749 100644 --- a/Subsurface_content/Subsurface_content/Subsurface_content.csproj.PSM.cachefile +++ b/Subsurface_content/Subsurface_content/Subsurface_content.csproj.PSM.cachefile @@ -1,4 +1,6 @@ Content\SpriteFont1.xnb Content\SmallFont.xnb +Content\LargeFont.xnb Content\SpriteFont1.spritefont Content\SmallFont.spritefont +Content\LargeFont.spritefont diff --git a/Subsurface_content/Subsurface_content/Subsurface_content.csproj.Windows.cachefile b/Subsurface_content/Subsurface_content/Subsurface_content.csproj.Windows.cachefile new file mode 100644 index 000000000..2a3436749 --- /dev/null +++ b/Subsurface_content/Subsurface_content/Subsurface_content.csproj.Windows.cachefile @@ -0,0 +1,6 @@ +Content\SpriteFont1.xnb +Content\SmallFont.xnb +Content\LargeFont.xnb +Content\SpriteFont1.spritefont +Content\SmallFont.spritefont +Content\LargeFont.spritefont diff --git a/Subsurface_content/Subsurface_content/bin/Windows/Content/SpriteFont1.xnb b/Subsurface_content/Subsurface_content/bin/Windows/Content/SpriteFont1.xnb index 51c4abd74..37d6342fc 100644 Binary files a/Subsurface_content/Subsurface_content/bin/Windows/Content/SpriteFont1.xnb and b/Subsurface_content/Subsurface_content/bin/Windows/Content/SpriteFont1.xnb differ diff --git a/Subsurface_content/Subsurface_content/bin/Windows/IgnoreMe.dll b/Subsurface_content/Subsurface_content/bin/Windows/IgnoreMe.dll index 56f61cc36..5c634cfcf 100644 Binary files a/Subsurface_content/Subsurface_content/bin/Windows/IgnoreMe.dll and b/Subsurface_content/Subsurface_content/bin/Windows/IgnoreMe.dll differ diff --git a/Subsurface_content/Subsurface_content/obj/PSM/cachefile-{8C1D2051-F0F3-457B-AAAE-4E155FC7C75C}-targetpath.txt b/Subsurface_content/Subsurface_content/obj/PSM/cachefile-{8C1D2051-F0F3-457B-AAAE-4E155FC7C75C}-targetpath.txt index 1c77f5a53..2a3436749 100644 --- a/Subsurface_content/Subsurface_content/obj/PSM/cachefile-{8C1D2051-F0F3-457B-AAAE-4E155FC7C75C}-targetpath.txt +++ b/Subsurface_content/Subsurface_content/obj/PSM/cachefile-{8C1D2051-F0F3-457B-AAAE-4E155FC7C75C}-targetpath.txt @@ -1,4 +1,6 @@ Content\SpriteFont1.xnb Content\SmallFont.xnb +Content\LargeFont.xnb Content\SpriteFont1.spritefont Content\SmallFont.spritefont +Content\LargeFont.spritefont diff --git a/Subsurface_content/Subsurface_content/obj/Windows/ContentPipeline-{8C1D2051-F0F3-457B-AAAE-4E155FC7C75C}.xml b/Subsurface_content/Subsurface_content/obj/Windows/ContentPipeline-{8C1D2051-F0F3-457B-AAAE-4E155FC7C75C}.xml index f51a9df04..d4c649161 100644 --- a/Subsurface_content/Subsurface_content/obj/Windows/ContentPipeline-{8C1D2051-F0F3-457B-AAAE-4E155FC7C75C}.xml +++ b/Subsurface_content/Subsurface_content/obj/Windows/ContentPipeline-{8C1D2051-F0F3-457B-AAAE-4E155FC7C75C}.xml @@ -7,8 +7,26 @@ FontDescriptionImporter FontDescriptionProcessor None - C:\Users\Joonas\Desktop\SBMR_3011\Sbmr_content\Sbmr_content\bin\Windows\Content\SpriteFont1.xnb - + E:\Subsurface\Subsurface_content\Subsurface_content\bin\Windows\Content\SpriteFont1.xnb + + + + SmallFont.spritefont + SmallFont + FontDescriptionImporter + FontDescriptionProcessor + None + E:\Subsurface\Subsurface_content\Subsurface_content\bin\Windows\Content\SmallFont.xnb + + + + LargeFont.spritefont + LargeFont + FontDescriptionImporter + FontDescriptionProcessor + None + E:\Subsurface\Subsurface_content\Subsurface_content\bin\Windows\Content\LargeFont.xnb + true @@ -17,15 +35,15 @@ HiDef Windows false - C:\Users\Joonas\Desktop\SBMR_3011\Sbmr_content\Sbmr_contentContent\ - C:\Users\Joonas\Desktop\SBMR_3011\Sbmr_content\Sbmr_content\ - C:\Users\Joonas\Desktop\SBMR_3011\Sbmr_content\Sbmr_content\obj\Windows\ - C:\Users\Joonas\Desktop\SBMR_3011\Sbmr_content\Sbmr_content\bin\Windows\Content\ + E:\Subsurface\Subsurface_content\Subsurface_contentContent\ + E:\Subsurface\Subsurface_content\Subsurface_content\ + E:\Subsurface\Subsurface_content\Subsurface_content\obj\Windows\ + E:\Subsurface\Subsurface_content\Subsurface_content\bin\Windows\Content\ C:\Program Files (x86)\MSBuild\MonoGame\v3.0\MonoGameContentProcessors.dll - 2014-04-06T00:56:18+03:00 + 2015-02-12T06:10:24+02:00 C:\Program Files (x86)\Microsoft XNA\XNA Game Studio\v4.0\References\Windows\x86\Microsoft.Xna.Framework.Content.Pipeline.XImporter.dll diff --git a/Subsurface_content/Subsurface_content/obj/Windows/DesignTimeResolveAssemblyReferencesInput.cache b/Subsurface_content/Subsurface_content/obj/Windows/DesignTimeResolveAssemblyReferencesInput.cache index 8237fb523..c28b17377 100644 Binary files a/Subsurface_content/Subsurface_content/obj/Windows/DesignTimeResolveAssemblyReferencesInput.cache and b/Subsurface_content/Subsurface_content/obj/Windows/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/Subsurface_content/Subsurface_content/obj/Windows/IgnoreMe.dll b/Subsurface_content/Subsurface_content/obj/Windows/IgnoreMe.dll index 56f61cc36..5c634cfcf 100644 Binary files a/Subsurface_content/Subsurface_content/obj/Windows/IgnoreMe.dll and b/Subsurface_content/Subsurface_content/obj/Windows/IgnoreMe.dll differ diff --git a/Subsurface_content/Subsurface_content/obj/Windows/cachefile-{8C1D2051-F0F3-457B-AAAE-4E155FC7C75C}-targetpath.txt b/Subsurface_content/Subsurface_content/obj/Windows/cachefile-{8C1D2051-F0F3-457B-AAAE-4E155FC7C75C}-targetpath.txt index b1ac40206..2a3436749 100644 --- a/Subsurface_content/Subsurface_content/obj/Windows/cachefile-{8C1D2051-F0F3-457B-AAAE-4E155FC7C75C}-targetpath.txt +++ b/Subsurface_content/Subsurface_content/obj/Windows/cachefile-{8C1D2051-F0F3-457B-AAAE-4E155FC7C75C}-targetpath.txt @@ -1 +1,6 @@ Content\SpriteFont1.xnb +Content\SmallFont.xnb +Content\LargeFont.xnb +Content\SpriteFont1.spritefont +Content\SmallFont.spritefont +Content\LargeFont.spritefont diff --git a/Subsurface_content/Subsurface_contentContent/Subsurface_contentContent.contentproj b/Subsurface_content/Subsurface_contentContent/Subsurface_contentContent.contentproj index 91d4cea64..14690175f 100644 --- a/Subsurface_content/Subsurface_contentContent/Subsurface_contentContent.contentproj +++ b/Subsurface_content/Subsurface_contentContent/Subsurface_contentContent.contentproj @@ -65,6 +65,15 @@ FontDescriptionProcessor + + + Designer + Always + LargeFont + FontDescriptionImporter + FontDescriptionProcessor + +