From 91f2f4f599413886192f1a34ae341443d7e5e04b Mon Sep 17 00:00:00 2001 From: 20kdc Date: Wed, 16 Dec 2020 13:31:47 +0000 Subject: [PATCH] Fix Antimatter engine maths and overplacing (#2736) * Antimatter engine parts can't be placed overlapping * Antimatter engine stability maths fixed * Antimatter engine: Clean up some unused stuff --- .../NodeContainer/NodeGroups/AMENodeGroup.cs | 44 ++++++++++++++++--- .../Power/AME/AMEControllerComponent.cs | 13 +++--- .../Components/Power/AME/AMEPartComponent.cs | 7 ++- .../Power/AME/AMEShieldComponent.cs | 5 --- 4 files changed, 51 insertions(+), 18 deletions(-) diff --git a/Content.Server/GameObjects/Components/NodeContainer/NodeGroups/AMENodeGroup.cs b/Content.Server/GameObjects/Components/NodeContainer/NodeGroups/AMENodeGroup.cs index f65c689253..7e7edea5e6 100644 --- a/Content.Server/GameObjects/Components/NodeContainer/NodeGroups/AMENodeGroup.cs +++ b/Content.Server/GameObjects/Components/NodeContainer/NodeGroups/AMENodeGroup.cs @@ -5,6 +5,9 @@ using Content.Server.Explosions; using Content.Server.GameObjects.Components.NodeContainer.Nodes; using Content.Server.GameObjects.Components.Power.AME; using Robust.Shared.GameObjects.Components.Transform; +using Robust.Shared.Interfaces.Random; +using Robust.Shared.Random; +using Robust.Shared.IoC; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.NodeContainer.NodeGroups @@ -23,6 +26,9 @@ namespace Content.Server.GameObjects.Components.NodeContainer.NodeGroups [ViewVariables] private AMEControllerComponent _masterController; + [Dependency] + private readonly IRobustRandom _random = default!; + public AMEControllerComponent MasterController => _masterController; private readonly List _cores = new(); @@ -95,16 +101,42 @@ namespace Content.Server.GameObjects.Components.NodeContainer.NodeGroups } } - public int InjectFuel(int injectionAmount) + public int InjectFuel(int fuel, out bool overloading) { - if(injectionAmount > 0 && CoreCount > 0) + overloading = false; + if(fuel > 0 && CoreCount > 0) { - var instability = 2 * (injectionAmount / CoreCount); - foreach(AMEShieldComponent core in _cores) + var safeFuelLimit = CoreCount * 2; + if (fuel > safeFuelLimit) { - core.CoreIntegrity -= instability; + // The AME is being overloaded. + // Note about these maths: I would assume the general idea here is to make larger engines less safe to overload. + // In other words, yes, those are supposed to be CoreCount, not safeFuelLimit. + var instability = 0; + var overloadVsSizeResult = fuel - CoreCount; + + // fuel > safeFuelLimit: Slow damage. Can safely run at this level for burst periods if the engine is small and someone is keeping an eye on it. + if (_random.Prob(0.5f)) + instability = 1; + // overloadVsSizeResult > 5: + if (overloadVsSizeResult > 5) + instability = 5; + // overloadVsSizeResult > 10: This will explode in at most 5 injections. + if (overloadVsSizeResult > 10) + instability = 20; + + // Apply calculated instability + if (instability != 0) + { + overloading = true; + foreach(AMEShieldComponent core in _cores) + { + core.CoreIntegrity -= instability; + } + } } - return CoreCount * injectionAmount * 15000; //2 core engine injecting 2 fuel per core = 60kW(?) + // Note the float conversions. The maths will completely fail if not done using floats. + return (int) ((((float) fuel) / CoreCount) * fuel * 20000); } return 0; } diff --git a/Content.Server/GameObjects/Components/Power/AME/AMEControllerComponent.cs b/Content.Server/GameObjects/Components/Power/AME/AMEControllerComponent.cs index 3f0f769938..8e5f590e24 100644 --- a/Content.Server/GameObjects/Components/Power/AME/AMEControllerComponent.cs +++ b/Content.Server/GameObjects/Components/Power/AME/AMEControllerComponent.cs @@ -85,11 +85,12 @@ namespace Content.Server.GameObjects.Components.Power.AME } _jarSlot.ContainedEntity.TryGetComponent(out var fuelJar); - if(fuelJar != null && _powerSupplier != null && fuelJar.FuelAmount > InjectionAmount) + if(fuelJar != null && _powerSupplier != null) { - _powerSupplier.SupplyRate = group.InjectFuel(InjectionAmount); - fuelJar.FuelAmount -= InjectionAmount; - InjectSound(); + var availableInject = fuelJar.FuelAmount >= InjectionAmount ? InjectionAmount : fuelJar.FuelAmount; + _powerSupplier.SupplyRate = group.InjectFuel(availableInject, out var overloading); + fuelJar.FuelAmount -= availableInject; + InjectSound(overloading); UpdateUserInterface(); } @@ -315,9 +316,9 @@ namespace Content.Server.GameObjects.Components.Power.AME } - private void InjectSound() + private void InjectSound(bool overloading) { - EntitySystem.Get().PlayFromEntity("/Audio/Effects/bang.ogg", Owner, AudioParams.Default.WithVolume(0f)); + EntitySystem.Get().PlayFromEntity("/Audio/Effects/bang.ogg", Owner, AudioParams.Default.WithVolume(overloading ? 10f : 0f)); } async Task IInteractUsing.InteractUsing(InteractUsingEventArgs args) diff --git a/Content.Server/GameObjects/Components/Power/AME/AMEPartComponent.cs b/Content.Server/GameObjects/Components/Power/AME/AMEPartComponent.cs index 044b7f2a6e..e6d84fb10d 100644 --- a/Content.Server/GameObjects/Components/Power/AME/AMEPartComponent.cs +++ b/Content.Server/GameObjects/Components/Power/AME/AMEPartComponent.cs @@ -1,4 +1,5 @@ using System.Threading.Tasks; +using System.Linq; using Content.Server.GameObjects.Components.Interactable; using Content.Server.Interfaces.GameObjects.Components.Items; using Content.Shared.GameObjects.Components.Interactable; @@ -35,8 +36,12 @@ namespace Content.Server.GameObjects.Components.Power.AME { var mapGrid = _mapManager.GetGrid(args.ClickLocation.GetGridId(_serverEntityManager)); - var tile = mapGrid.GetTileRef(args.ClickLocation); var snapPos = mapGrid.SnapGridCellFor(args.ClickLocation, SnapGridOffset.Center); + if (mapGrid.GetSnapGridCell(snapPos, SnapGridOffset.Center).Any(sc => sc.Owner.HasComponent())) + { + Owner.PopupMessage(args.User, Loc.GetString("Shielding is already there!")); + return true; + } var ent = _serverEntityManager.SpawnEntity("AMEShielding", mapGrid.GridTileToLocal(snapPos)); ent.Transform.LocalRotation = Owner.Transform.LocalRotation; diff --git a/Content.Server/GameObjects/Components/Power/AME/AMEShieldComponent.cs b/Content.Server/GameObjects/Components/Power/AME/AMEShieldComponent.cs index 4aa9be4e4e..f484b3cbe1 100644 --- a/Content.Server/GameObjects/Components/Power/AME/AMEShieldComponent.cs +++ b/Content.Server/GameObjects/Components/Power/AME/AMEShieldComponent.cs @@ -26,11 +26,6 @@ namespace Content.Server.GameObjects.Components.Power.AME Owner.TryGetComponent(out _pointLight); } - internal void OnUpdate(float frameTime) - { - throw new NotImplementedException(); - } - public void SetCore() { if(_isCore) { return; }