From fac31b489269fe47b646e4d940a3822469d379e4 Mon Sep 17 00:00:00 2001 From: Regalis Date: Mon, 10 Apr 2017 20:13:33 +0300 Subject: [PATCH] - Fixed railgun sounds not playing at the clients' end - Server sends updates for batteries when their charge changes (not strictly necessary assuming the rest of the electrical grid stays in sync, but just in case) - Reactor state is synced with clients if modified through the debug console - Increased maximum item velocity to 64 units/s, all item are clamped to the max vel --- Subsurface/Source/Characters/Character.cs | 4 +- Subsurface/Source/DebugConsole.cs | 5 +++ .../Items/Components/Machines/Reactor.cs | 4 +- .../Items/Components/Power/PowerContainer.cs | 22 ++++++---- Subsurface/Source/Items/Components/Turret.cs | 1 + Subsurface/Source/Items/Item.cs | 42 ++++++++++--------- 6 files changed, 45 insertions(+), 33 deletions(-) diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index d3a5d172d..9d3acbeeb 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -1617,7 +1617,7 @@ namespace Barotrauma //GUI.DrawLine(spriteBatch, remoteVec, localVec, Color.Yellow, 0, 10); if (localPos1 != null) GUI.DrawLine(spriteBatch, remoteVec, localVec1, Color.Lime, 0, 2); if (localPos2 != null) GUI.DrawLine(spriteBatch, remoteVec + Vector2.One, localVec2 + Vector2.One, Color.Red, 0, 2); - }*/ + } Vector2 mouseDrawPos = CursorWorldPosition; mouseDrawPos.Y = -mouseDrawPos.Y; @@ -1625,7 +1625,7 @@ namespace Barotrauma Vector2 closestItemPos = closestItem != null ? closestItem.DrawPosition : Vector2.Zero; closestItemPos.Y = -closestItemPos.Y; - GUI.DrawLine(spriteBatch, closestItemPos - new Vector2(0, 5), closestItemPos + new Vector2(0, 5), Color.Lime, 0, 10); + GUI.DrawLine(spriteBatch, closestItemPos - new Vector2(0, 5), closestItemPos + new Vector2(0, 5), Color.Lime, 0, 10);*/ if (this == controlled || GUI.DisableHUD) return; diff --git a/Subsurface/Source/DebugConsole.cs b/Subsurface/Source/DebugConsole.cs index 4d5b7ad40..9deb14d8c 100644 --- a/Subsurface/Source/DebugConsole.cs +++ b/Subsurface/Source/DebugConsole.cs @@ -581,6 +581,11 @@ namespace Barotrauma reactor.ShutDownTemp = power == 0 ? 0 : 7000.0f; reactor.AutoTemp = true; reactor.Temperature = power; + + if (GameMain.Server != null) + { + reactorItem.CreateServerEvent(reactor); + } break; case "shake": GameMain.GameScreen.Cam.Shake = 10.0f; diff --git a/Subsurface/Source/Items/Components/Machines/Reactor.cs b/Subsurface/Source/Items/Components/Machines/Reactor.cs index 98b02238c..a73289e56 100644 --- a/Subsurface/Source/Items/Components/Machines/Reactor.cs +++ b/Subsurface/Source/Items/Components/Machines/Reactor.cs @@ -47,9 +47,7 @@ namespace Barotrauma.Items.Components private float[] loadGraph; private float load; - - private float lastUpdate; - + private PropertyTask powerUpTask; private GUITickBox autoTempTickBox; diff --git a/Subsurface/Source/Items/Components/Power/PowerContainer.cs b/Subsurface/Source/Items/Components/Power/PowerContainer.cs index 500c6fd88..55d587769 100644 --- a/Subsurface/Source/Items/Components/Power/PowerContainer.cs +++ b/Subsurface/Source/Items/Components/Power/PowerContainer.cs @@ -10,20 +10,22 @@ namespace Barotrauma.Items.Components class PowerContainer : Powered, IDrawableComponent, IServerSerializable, IClientSerializable { //[power/min] - float capacity; + private float capacity; - float charge; + private float charge; - float rechargeVoltage, outputVoltage; + private float rechargeVoltage, outputVoltage; //how fast the battery can be recharged - float maxRechargeSpeed; + private float maxRechargeSpeed; //how fast it's currently being recharged (can be changed, so that //charging can be slowed down or disabled if there's a shortage of power) - float rechargeSpeed; + private float rechargeSpeed; - float maxOutput; + private float maxOutput; + + private float lastSentCharge; public float CurrPowerOutput { @@ -53,6 +55,12 @@ namespace Barotrauma.Items.Components { if (!MathUtils.IsValid(value)) return; charge = MathHelper.Clamp(value, 0.0f, capacity); + + if (Math.Abs(charge - lastSentCharge) > 1.0f) + { + if (GameMain.Server != null) item.CreateServerEvent(this); + lastSentCharge = charge; + } } } @@ -281,8 +289,6 @@ namespace Barotrauma.Items.Components public void ServerWrite(NetBuffer msg, Client c, object[] extraData = null) { - - DebugConsole.NewMessage("writing recharge speed " + (rechargeSpeed / MaxRechargeSpeed * 10), Color.White); msg.WriteRangedInteger(0, 10, (int)(rechargeSpeed / MaxRechargeSpeed * 10)); float chargeRatio = MathHelper.Clamp(charge / capacity, 0.0f, 1.0f); diff --git a/Subsurface/Source/Items/Components/Turret.cs b/Subsurface/Source/Items/Components/Turret.cs index e78235a67..6d5547a72 100644 --- a/Subsurface/Source/Items/Components/Turret.cs +++ b/Subsurface/Source/Items/Components/Turret.cs @@ -405,6 +405,7 @@ namespace Barotrauma.Items.Components } Launch(projectile); + PlaySound(ActionType.OnUse, item.WorldPosition); } } } diff --git a/Subsurface/Source/Items/Item.cs b/Subsurface/Source/Items/Item.cs index e40515ec9..25326cc6a 100644 --- a/Subsurface/Source/Items/Item.cs +++ b/Subsurface/Source/Items/Item.cs @@ -16,7 +16,6 @@ using System.Xml.Linq; namespace Barotrauma { - public enum ActionType { Always, OnPicked, OnUse, OnSecondaryUse, @@ -28,6 +27,8 @@ namespace Barotrauma class Item : MapEntity, IDamageable, IPropertyObject, IServerSerializable, IClientSerializable { + const float MaxVel = 64.0f; + public static List ItemList = new List(); private ItemPrefab prefab; @@ -817,22 +818,19 @@ namespace Barotrauma Vector2 displayPos = ConvertUnits.ToDisplayUnits(body.SimPosition); rect.X = (int)(displayPos.X - rect.Width / 2.0f); rect.Y = (int)(displayPos.Y + rect.Height / 2.0f); + + if (Math.Abs(body.LinearVelocity.X) > MaxVel || Math.Abs(body.LinearVelocity.Y) > MaxVel) + { + body.LinearVelocity = new Vector2( + MathHelper.Clamp(body.LinearVelocity.X, -MaxVel, MaxVel), + MathHelper.Clamp(body.LinearVelocity.Y, -MaxVel, MaxVel)); + } } UpdateNetPosition(deltaTime); - - /*if (GameMain.Client != null) - { - body.MoveToTargetPosition(); - }*/ - - if (!inWater || Container != null || body == null) return; - - if (body.LinearVelocity != Vector2.Zero && body.LinearVelocity.Length() > 1000.0f) - { - body.ResetDynamics(); - } - + + if (!inWater || Container != null) return; + ApplyWaterForces(); if(CurrentHull != null) CurrentHull.ApplyFlowForces(deltaTime, this); @@ -2104,16 +2102,20 @@ namespace Barotrauma msg.WriteRangedSingle(MathUtils.WrapAngleTwoPi(body.Rotation), 0.0f, MathHelper.TwoPi, 7); #if DEBUG - if (Math.Abs(body.LinearVelocity.X) > 32.0f || Math.Abs(body.LinearVelocity.Y) > 32.0f) + if (Math.Abs(body.LinearVelocity.X) > MaxVel || Math.Abs(body.LinearVelocity.Y) > MaxVel) + { + DebugConsole.ThrowError("Item velocity out of range (" + body.LinearVelocity + ")"); + + } #endif msg.Write(body.FarseerBody.Awake); if (body.FarseerBody.Awake) { body.FarseerBody.Enabled = true; - msg.WriteRangedSingle(MathHelper.Clamp(body.LinearVelocity.X, -32.0f, 32.0f), -32.0f, 32.0f, 12); - msg.WriteRangedSingle(MathHelper.Clamp(body.LinearVelocity.Y, -32.0f, 32.0f), -32.0f, 32.0f, 12); + msg.WriteRangedSingle(MathHelper.Clamp(body.LinearVelocity.X, -MaxVel, MaxVel), -MaxVel, MaxVel, 12); + msg.WriteRangedSingle(MathHelper.Clamp(body.LinearVelocity.Y, -MaxVel, MaxVel), -MaxVel, MaxVel, 12); } msg.WritePadBits(); @@ -2136,9 +2138,9 @@ namespace Barotrauma if (body.FarseerBody.Awake) { newVelocity = new Vector2( - msg.ReadRangedSingle(-32.0f, 32.0f, 12), - msg.ReadRangedSingle(-32.0f, 32.0f, 12)); - if ((newVelocity-body.LinearVelocity).Length()>8.0f) body.LinearVelocity = newVelocity; + msg.ReadRangedSingle(-MaxVel, MaxVel, 12), + msg.ReadRangedSingle(-MaxVel, MaxVel, 12)); + if ((newVelocity - body.LinearVelocity).Length() > 8.0f) body.LinearVelocity = newVelocity; } else {