Skip to content

Commit

Permalink
Upstream 19.08.2024
Browse files Browse the repository at this point in the history
Merge pull request #56 from MetalSage/upstream
  • Loading branch information
doublechest0 authored Aug 20, 2024
2 parents b556487 + d16c913 commit ee5a7b3
Show file tree
Hide file tree
Showing 308 changed files with 18,044 additions and 10,141 deletions.
27 changes: 27 additions & 0 deletions Content.Client/Materials/RecyclerVisualizerSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Content.Shared.Conveyor;
using Content.Shared.Materials;
using Robust.Client.GameObjects;

namespace Content.Client.Materials;

public sealed class RecyclerVisualizerSystem : VisualizerSystem<RecyclerVisualsComponent>
{
protected override void OnAppearanceChange(EntityUid uid, RecyclerVisualsComponent component, ref AppearanceChangeEvent args)
{
if (args.Sprite == null || !args.Sprite.LayerMapTryGet(RecyclerVisualLayers.Main, out var layer))
return;

AppearanceSystem.TryGetData<ConveyorState>(uid, ConveyorVisuals.State, out var running);
AppearanceSystem.TryGetData<bool>(uid, RecyclerVisuals.Bloody, out var bloody);
AppearanceSystem.TryGetData<bool>(uid, RecyclerVisuals.Broken, out var broken);

var activityState = running == ConveyorState.Off ? 0 : 1;
if (broken) //breakage overrides activity
activityState = 2;

var bloodyKey = bloody ? component.BloodyKey : string.Empty;

var state = $"{component.BaseKey}{activityState}{bloodyKey}";
args.Sprite.LayerSetState(layer, state);
}
}
17 changes: 17 additions & 0 deletions Content.Client/Materials/RecyclerVisualsComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Content.Client.Materials;

[RegisterComponent]
public sealed partial class RecyclerVisualsComponent : Component
{
/// <summary>
/// Key appended to state string if bloody.
/// </summary>
[DataField]
public string BloodyKey = "bld";

/// <summary>
/// Base key for the visual state.
/// </summary>
[DataField]
public string BaseKey = "grinder-o";
}
17 changes: 1 addition & 16 deletions Content.Server/Actions/ActionOnInteractSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,6 @@ private void OnAfterInteract(EntityUid uid, ActionOnInteractComponent component,
args.Handled = true;
}

private bool ValidAction(BaseActionComponent action, bool canReach = true)
{
if (!action.Enabled)
return false;

if (action.Charges.HasValue && action.Charges <= 0)
return false;

var curTime = _timing.CurTime;
if (action.Cooldown.HasValue && action.Cooldown.Value.End > curTime)
return false;

return canReach || action is BaseTargetActionComponent { CheckCanAccess: false };
}

private List<(EntityUid Id, T Comp)> GetValidActions<T>(List<EntityUid>? actions, bool canReach = true) where T : BaseActionComponent
{
var valid = new List<(EntityUid Id, T Comp)>();
Expand All @@ -180,7 +165,7 @@ private bool ValidAction(BaseActionComponent action, bool canReach = true)
{
if (!_actions.TryGetActionData(id, out var baseAction) ||
baseAction as T is not { } action ||
!ValidAction(action, canReach))
!_actions.ValidAction(action, canReach))
{
continue;
}
Expand Down
22 changes: 20 additions & 2 deletions Content.Server/Botany/Systems/MutationSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ private void MutateFloat(ref float val, float min, float max, int bits, int tota
if (!Random(probBitflip))
return;

if (min == max)
{
val = min;
return;
}

// Starting number of bits that are high, between 0 and bits.
// In other words, it's val mapped linearly from range [min, max] to range [0, bits], and then rounded.
int valInt = (int)MathF.Round((val - min) / (max - min) * bits);
Expand Down Expand Up @@ -186,10 +192,22 @@ private void MutateInt(ref int val, int min, int max, int bits, int totalbits, f
if (!Random(probBitflip))
return;

if (min == max)
{
val = min;
return;
}

// Starting number of bits that are high, between 0 and bits.
// In other words, it's val mapped linearly from range [min, max] to range [0, bits], and then rounded.
int valInt = (int)MathF.Round((val - min) / (max - min) * bits);
// val may be outside the range of min/max due to starting prototype values, so clamp.
valInt = Math.Clamp(valInt, 0, bits);

// Probability that the bit flip increases n.
// The higher the current value is, the lower the probability of increasing value is, and the higher the probability of decreasive it it.
// The higher the current value is, the lower the probability of increasing value is, and the higher the probability of decreasing it.
// In other words, it tends to go to the middle.
float probIncrease = 1 - (float)val / bits;
float probIncrease = 1 - (float)valInt / bits;
int valMutated;
if (Random(probIncrease))
{
Expand Down
3 changes: 1 addition & 2 deletions Content.Server/Botany/Systems/PlantHolderSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -522,10 +522,9 @@ public void Update(EntityUid uid, PlantHolderComponent? component = null)

var environment = _atmosphere.GetContainingMixture(uid, true, true) ?? GasMixture.SpaceGas;

component.MissingGas = 0;
if (component.Seed.ConsumeGasses.Count > 0)
{
component.MissingGas = 0;

foreach (var (gas, amount) in component.Seed.ConsumeGasses)
{
if (environment.GetMoles(gas) < amount)
Expand Down
22 changes: 20 additions & 2 deletions Content.Server/Chat/Systems/ChatSystem.Emote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,32 @@ public bool TryPlayEmoteSound(EntityUid uid, EmoteSoundsPrototype? proto, string
/// <param name="textInput"></param>
private void TryEmoteChatInput(EntityUid uid, string textInput)
{
var actionLower = textInput.ToLower();
if (!_wordEmoteDict.TryGetValue(actionLower, out var emote))
var actionTrimmedLower = TrimPunctuation(textInput.ToLower());
if (!_wordEmoteDict.TryGetValue(actionTrimmedLower, out var emote))
return;

if (!AllowedToUseEmote(uid, emote))
return;

InvokeEmoteEvent(uid, emote);
return;

static string TrimPunctuation(string textInput)
{
var trimEnd = textInput.Length;
while (trimEnd > 0 && char.IsPunctuation(textInput[trimEnd - 1]))
{
trimEnd--;
}

var trimStart = 0;
while (trimStart < trimEnd && char.IsPunctuation(textInput[trimStart]))
{
trimStart++;
}

return textInput[trimStart..trimEnd];
}
}
/// <summary>
/// Checks if we can use this emote based on the emotes whitelist, blacklist, and availibility to the entity.
Expand Down
5 changes: 3 additions & 2 deletions Content.Server/Construction/Completions/PlaySound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ public sealed partial class PlaySound : IGraphAction
public void PerformAction(EntityUid uid, EntityUid? userUid, IEntityManager entityManager)
{
var scale = (float) IoCManager.Resolve<IRobustRandom>().NextGaussian(1, Variation);
entityManager.EntitySysManager.GetEntitySystem<SharedAudioSystem>()
.PlayPvs(Sound, uid, AudioParams.WithPitchScale(scale));
if (entityManager.TryGetComponent<TransformComponent>(uid, out var xform))
entityManager.EntitySysManager.GetEntitySystem<SharedAudioSystem>()
.PlayPvs(Sound, xform.Coordinates, AudioParams.WithPitchScale(scale));
}
}
}
40 changes: 40 additions & 0 deletions Content.Server/DeviceLinking/Components/MemoryCellComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Content.Server.DeviceLinking.Systems;
using Content.Shared.DeviceLinking;
using Robust.Shared.Prototypes;

namespace Content.Server.DeviceLinking.Components;

/// <summary>
/// Memory cell that sets the output to the input when enabled.
/// </summary>
[RegisterComponent, Access(typeof(MemoryCellSystem))]
public sealed partial class MemoryCellComponent : Component
{
/// <summary>
/// Name of the input port.
/// </summary>
[DataField]
public ProtoId<SinkPortPrototype> InputPort = "MemoryInput";

/// <summary>
/// Name of the enable port.
/// </summary>
[DataField]
public ProtoId<SinkPortPrototype> EnablePort = "MemoryEnable";

/// <summary>
/// Name of the output port.
/// </summary>
[DataField]
public ProtoId<SourcePortPrototype> OutputPort = "Output";

// State
[DataField]
public SignalState InputState = SignalState.Low;

[DataField]
public SignalState EnableState = SignalState.Low;

[DataField]
public bool LastOutput;
}
74 changes: 74 additions & 0 deletions Content.Server/DeviceLinking/Systems/MemoryCellSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using Content.Server.DeviceLinking.Components;
using Content.Server.DeviceLinking.Events;
using Content.Server.DeviceNetwork;
using Content.Shared.DeviceLinking;

namespace Content.Server.DeviceLinking.Systems;

/// <summary>
/// Handles the control of output based on the input and enable ports.
/// </summary>
public sealed class MemoryCellSystem : EntitySystem
{
[Dependency] private readonly DeviceLinkSystem _deviceLink = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<MemoryCellComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<MemoryCellComponent, SignalReceivedEvent>(OnSignalReceived);
}

public override void Update(float deltaTime)
{
base.Update(deltaTime);

var query = EntityQueryEnumerator<MemoryCellComponent, DeviceLinkSourceComponent>();
while (query.MoveNext(out var uid, out var comp, out var source))
{
if (comp.InputState == SignalState.Momentary)
comp.InputState = SignalState.Low;
if (comp.EnableState == SignalState.Momentary)
comp.EnableState = SignalState.Low;

UpdateOutput((uid, comp, source));
}
}

private void OnInit(Entity<MemoryCellComponent> ent, ref ComponentInit args)
{
var (uid, comp) = ent;
_deviceLink.EnsureSinkPorts(uid, comp.InputPort, comp.EnablePort);
_deviceLink.EnsureSourcePorts(uid, comp.OutputPort);
}

private void OnSignalReceived(Entity<MemoryCellComponent> ent, ref SignalReceivedEvent args)
{
var state = SignalState.Momentary;
args.Data?.TryGetValue(DeviceNetworkConstants.LogicState, out state);

if (args.Port == ent.Comp.InputPort)
ent.Comp.InputState = state;
else if (args.Port == ent.Comp.EnablePort)
ent.Comp.EnableState = state;

UpdateOutput(ent);
}

private void UpdateOutput(Entity<MemoryCellComponent, DeviceLinkSourceComponent?> ent)
{
if (!Resolve(ent, ref ent.Comp2))
return;

if (ent.Comp1.EnableState == SignalState.Low)
return;

var value = ent.Comp1.InputState != SignalState.Low;
if (value == ent.Comp1.LastOutput)
return;

ent.Comp1.LastOutput = value;
_deviceLink.SendSignal(ent, ent.Comp1.OutputPort, value, ent.Comp2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ public enum DeviceNetIdDefaults
[DataField("sendBroadcastAttemptEvent")]
public bool SendBroadcastAttemptEvent = false;

/// <summary>
/// Whether this device's address can be saved to device-lists
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("savableAddress")]
public bool SavableAddress = true;

/// <summary>
/// A list of device-lists that this device is on.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ private void TryAddNetworkDevice(EntityUid configuratorUid, EntityUid? targetUid
if (!targetUid.HasValue || !Resolve(targetUid.Value, ref device, false))
return;

//This checks if the device is marked as having a savable address,
//to avoid adding pdas and whatnot to air alarms. This flag is true
//by default, so this will only prevent devices from being added to
//network configurator lists if manually set to false in the prototype
if (!device.SavableAddress)
return;

var address = device.Address;
if (string.IsNullOrEmpty(address))
{
Expand Down
4 changes: 3 additions & 1 deletion Content.Server/Disposal/Tube/DisposalTubeSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public sealed class DisposalTubeSystem : EntitySystem
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
[Dependency] private readonly AtmosphereSystem _atmosSystem = default!;
[Dependency] private readonly TransformSystem _transform = default!;
[Dependency] private readonly SharedMapSystem _map = default!;

public override void Initialize()
{
base.Initialize();
Expand Down Expand Up @@ -345,7 +347,7 @@ private void UpdateAnchored(EntityUid uid, DisposalTubeComponent component, bool
return null;

var position = xform.Coordinates;
foreach (var entity in grid.GetInDir(position, nextDirection))
foreach (var entity in _map.GetInDir(xform.GridUid.Value, grid, position, nextDirection))
{
if (!TryComp(entity, out DisposalTubeComponent? tube))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public sealed class DisposalUnitSystem : SharedDisposalUnitSystem
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
[Dependency] private readonly TransformSystem _transformSystem = default!;
[Dependency] private readonly UserInterfaceSystem _ui = default!;
[Dependency] private readonly SharedMapSystem _map = default!;

public override void Initialize()
{
Expand Down Expand Up @@ -474,7 +475,7 @@ public bool TryInsert(EntityUid unitId, EntityUid toInsertId, EntityUid? userId,
var delay = insertingSelf ? unit.EntryDelay : unit.DraggedEntryDelay;

if (userId != null && !insertingSelf)
_popupSystem.PopupEntity(Loc.GetString("disposal-unit-being-inserted", ("user", Identity.Entity((EntityUid) userId, EntityManager))), toInsertId, toInsertId, PopupType.Large);
_popupSystem.PopupEntity(Loc.GetString("disposal-unit-being-inserted", ("user", Identity.Entity((EntityUid)userId, EntityManager))), toInsertId, toInsertId, PopupType.Large);

if (delay <= 0 || userId == null)
{
Expand Down Expand Up @@ -520,7 +521,7 @@ public bool TryFlush(EntityUid uid, SharedDisposalUnitComponent component)
return false;

var coords = xform.Coordinates;
var entry = grid.GetLocal(coords)
var entry = _map.GetLocal(xform.GridUid.Value, grid, coords)
.FirstOrDefault(HasComp<DisposalEntryComponent>);

if (entry == default || component is not DisposalUnitComponent sDisposals)
Expand Down
8 changes: 7 additions & 1 deletion Content.Server/IP/IPAddressExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ public static bool IsInSubnet(this System.Net.IPAddress address, (System.Net.IPA

public static bool IsInSubnet(this System.Net.IPAddress address, System.Net.IPAddress maskAddress, int maskLength)
{
if (maskAddress.AddressFamily != address.AddressFamily)
{
// We got something like an IPV4-Address for an IPv6-Mask. This is not valid.
return false;
}

if (maskAddress.AddressFamily == AddressFamily.InterNetwork)
{
// Convert the mask address to an unsigned integer.
Expand Down Expand Up @@ -89,7 +95,7 @@ public static bool IsInSubnet(this System.Net.IPAddress address, System.Net.IPAd

if (maskAddressBits.Length != ipAddressBits.Length)
{
throw new ArgumentException("Length of IP Address and Subnet Mask do not match.");
return false;
}

// Compare the prefix bits.
Expand Down
Loading

0 comments on commit ee5a7b3

Please sign in to comment.