Add department-specific radio channels (#9061)
* Add department-specific radio channels
This commit adds working department-specific radio channels, while
minimizing damage to the current codebase. It is expected that a future
refactor will clean this up a bit.
ChatSystem now has a RadioPrefix() method that recognizes
department-specific channels (e.g. ":e" and ":m") in addition to the
global channel (";"). It strips the prefix from the message and assigns
messages an integer representing the destination channel, if any.
IListen and IRadio now accept optional 'channel' arguments with this
channel in mind.
The ugly is that the integer channel number is hard-coded and also shows
up in chat.
Comms are not modeled at this time. You cannot break comms (yet).
All headsets have channels soldered into them. You cannot change
encryption keys to hop on new channels. Steal a headset instead.
* Remove debugging print
* Convert to prototypes
* Use prototype names in headset prototype
* Adjust list style
* Document prototype fields
* cringe
* some cleanup
* colours
* Remove alphas at least
* cc
Co-authored-by: Kevin Zheng <kevinz5000@gmail.com>
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
using Content.Server.Chat;
|
||||
using Content.Server.Chat.Systems;
|
||||
using Content.Server.Radio.EntitySystems;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Radio;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
||||
|
||||
namespace Content.Server.Radio.Components
|
||||
{
|
||||
@@ -18,12 +23,16 @@ namespace Content.Server.Radio.Components
|
||||
private RadioSystem _radioSystem = default!;
|
||||
|
||||
private bool _radioOn;
|
||||
[DataField("channels")]
|
||||
private List<int> _channels = new(){1459};
|
||||
[DataField("channels", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<RadioChannelPrototype>))]
|
||||
private HashSet<string> _channels = new();
|
||||
|
||||
public int BroadcastFrequency => IoCManager.Resolve<IPrototypeManager>()
|
||||
.Index<RadioChannelPrototype>(BroadcastChannel).Frequency;
|
||||
|
||||
// TODO: Assert in componentinit that channels has this.
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("broadcastChannel")]
|
||||
public int BroadcastFrequency { get; set; } = 1459;
|
||||
[DataField("broadcastChannel", customTypeSerializer: typeof(PrototypeIdSerializer<RadioChannelPrototype>))]
|
||||
public string BroadcastChannel { get; set; } = "Common";
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)] [DataField("listenRange")] public int ListenRange { get; private set; } = 7;
|
||||
|
||||
@@ -38,8 +47,6 @@ namespace Content.Server.Radio.Components
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables] public IReadOnlyList<int> Channels => _channels;
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -66,28 +73,30 @@ namespace Content.Server.Radio.Components
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CanListen(string message, EntityUid source)
|
||||
public bool CanListen(string message, EntityUid source, RadioChannelPrototype prototype)
|
||||
{
|
||||
if (!_channels.Contains(prototype.ID)) return false;
|
||||
|
||||
return RadioOn &&
|
||||
EntitySystem.Get<SharedInteractionSystem>().InRangeUnobstructed(Owner, source, range: ListenRange);
|
||||
}
|
||||
|
||||
public void Receive(string message, int channel, EntityUid speaker)
|
||||
public void Receive(string message, RadioChannelPrototype channel, EntityUid speaker)
|
||||
{
|
||||
if (RadioOn)
|
||||
if (_channels.Contains(channel.ID) && RadioOn)
|
||||
{
|
||||
Speak(message);
|
||||
}
|
||||
}
|
||||
|
||||
public void Listen(string message, EntityUid speaker)
|
||||
public void Listen(string message, EntityUid speaker, RadioChannelPrototype channel)
|
||||
{
|
||||
Broadcast(message, speaker);
|
||||
Broadcast(message, speaker, channel);
|
||||
}
|
||||
|
||||
public void Broadcast(string message, EntityUid speaker)
|
||||
public void Broadcast(string message, EntityUid speaker, RadioChannelPrototype channel)
|
||||
{
|
||||
_radioSystem.SpreadMessage(this, speaker, message, BroadcastFrequency);
|
||||
_radioSystem.SpreadMessage(this, speaker, message, channel);
|
||||
}
|
||||
|
||||
void IActivate.Activate(ActivateEventArgs eventArgs)
|
||||
|
||||
Reference in New Issue
Block a user