Skip to content

Commit

Permalink
Soft-Refactor Geiger Counters (Simple-Station#615)
Browse files Browse the repository at this point in the history
# Description

This refactors Geiger Counters so that their behavior of "Only making
sound to a person holding them" is no longer hardcoded. The
GeigerCounterComponent now can define how loud it ticks, how far away
people can hear the ticks, and whether it plays only for the person
holding it or for anyone nearby. This PR partially fulfills one of the
"Nice To Have" features requested for
Simple-Station#341 by making it
possible to create stationary radiation alarm objects. It also serves as
a substantial quality of life improvement for Engineering and Science
crew, since it's now possible to place an active Geiger counter in the
artifact lab, and then be able to audibly hear if the lab becomes
radioactive due to an artifact.

<details><summary><h1>Media</h1></summary>
<p>



https://github.com/user-attachments/assets/74122135-7345-4995-bb0e-d1216e1d53b6



https://github.com/user-attachments/assets/de79db6f-e1c1-471f-88b5-0a47ff4bfa16


</p>
</details>

# Changelog

:cl:
- add: Geiger Counters other than ones installed in Hardsuits now
generate an audible sound when active and exposed to radiation.
- add: Wall mounted geiger counters have been added to the game.

---------

Signed-off-by: VMSolidus <[email protected]>
  • Loading branch information
VMSolidus authored and tim-mcqueen-ttec committed Aug 18, 2024
1 parent cddbbbd commit 90d93d3
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 19 deletions.
28 changes: 14 additions & 14 deletions Content.Server/Radiation/Systems/GeigerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
using Content.Shared.Radiation.Components;
using Content.Shared.Radiation.Systems;
using Robust.Server.Audio;
using Robust.Server.GameObjects;
using Robust.Server.Player;
using Robust.Shared.Player;

namespace Content.Server.Radiation.Systems;

Expand Down Expand Up @@ -152,19 +152,19 @@ private void UpdateSound(EntityUid uid, GeigerComponent? component = null)

component.Stream = _audio.Stop(component.Stream);

if (!component.Sounds.TryGetValue(component.DangerLevel, out var sounds))
return;

if (component.User == null)
return;

if (!_player.TryGetSessionByEntity(component.User.Value, out var session))
return;

var sound = _audio.GetSound(sounds);
var param = sounds.Params.WithLoop(true).WithVolume(-4f);

component.Stream = _audio.PlayGlobal(sound, session, param)?.Entity;
if (component.Sounds.TryGetValue(component.DangerLevel, out var sounds))
{
var sound = _audio.GetSound(sounds);

if (component.LocalSoundOnly
&& component.User is not null
&& _player.TryGetSessionByEntity(component.User.Value, out var session))
{
component.Stream = _audio.PlayGlobal(sound, session, component.AudioParameters)?.Entity;
return;
}
component.Stream = _audio.PlayEntity(sound, Filter.Pvs(uid), uid, true, component.AudioParameters)?.Entity;
}
}

public static GeigerDangerLevel RadsToLevel(float rads)
Expand Down
19 changes: 14 additions & 5 deletions Content.Shared/Radiation/Components/GeigerComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@ public sealed partial class GeigerComponent : Component
/// <summary>
/// Should it shows examine message with current radiation level?
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField]
public bool ShowExamine;

/// <summary>
/// Should it shows item control when equipped by player?
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField]
public bool ShowControl;

Expand All @@ -55,7 +53,7 @@ public sealed partial class GeigerComponent : Component
/// <summary>
/// Current radiation level in rad per second.
/// </summary>
[ViewVariables(VVAccess.ReadOnly), AutoNetworkedField]
[DataField, AutoNetworkedField]
public float CurrentRadiation;

/// <summary>
Expand All @@ -66,8 +64,6 @@ public sealed partial class GeigerComponent : Component

/// <summary>
/// Current player that equipped geiger counter.
/// Because sound is annoying, geiger counter clicks will play
/// only for player that equipped it.
/// </summary>
[ViewVariables(VVAccess.ReadOnly), AutoNetworkedField]
public EntityUid? User;
Expand All @@ -83,6 +79,19 @@ public sealed partial class GeigerComponent : Component
/// Played only for current user.
/// </summary>
public EntityUid? Stream;

/// <summary>
/// Controls whether the geiger counter plays only for the local player, or plays for everyone nearby.
/// Useful for things like hardsuits with integrated geigers. Alternatively, to create stationary radiation alarm objects.
/// </summary>
[DataField]
public bool LocalSoundOnly = false;

/// <summary>
/// Used for all geiger counter audio controls, allowing entities to override default audio parameters.
/// </summary>
[DataField]
public AudioParams AudioParameters;
}

[Serializable, NetSerializable]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@
- type: Clothing
equipDelay: 2.5 # Hardsuits are heavy and take a while to put on/off.
unequipDelay: 2.5
- type: Geiger
attachedToSuit: true
localSoundOnly: true
- type: StaminaDamageResistance
coefficient: 0.75 # 25%

Expand Down
51 changes: 51 additions & 0 deletions Resources/Prototypes/Entities/Structures/Wallmounts/radalarm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
- type: entity
id: GeigerCounterWallMount
name: wall-mounted Geiger counter
description: A stationary device that emits a warning tone when it detects radiation pulses.
placement:
mode: SnapgridCenter
snap:
- Wallmount
components:
- type: InteractionOutline
- type: Clickable
- type: Rotatable
rotateWhileAnchored: false
rotateWhilePulling: true
- type: WallMount
- type: Transform
noRot: false
anchored: true
- type: Sprite
noRot: true
drawdepth: WallMountedItems
sprite: Structures/Wallmounts/radalarm.rsi
layers:
- state: geiger_base
- state: geiger_on_idle
map: ["enum.GeigerLayers.Screen"]
shader: unshaded
visible: false
- type: Geiger
showControl: true
showExamine: true
localSoundOnly: false
audioParameters:
volume: -4
maxDistance: 10
rolloffFactor: 4
- type: Appearance
- type: GenericVisualizer
visuals:
enum.GeigerVisuals.IsEnabled:
GeigerLayers.Screen:
True: { visible: True }
False: { visible: False }
enum.GeigerVisuals.DangerLevel:
GeigerLayers.Screen:
None: {state: geiger_on_idle}
Low: {state: geiger_on_low}
Med: {state: geiger_on_med}
High: {state: geiger_on_high}
Extreme: {state: geiger_on_ext}

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions Resources/Textures/Structures/Wallmounts/radalarm.rsi/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"version": 1,
"size": {
"x": 32,
"y": 32
},
"license": "CC-BY-SA-3.0",
"copyright": "Made by @dootythefrooty (Discord)",
"states": [
{
"name": "geiger_base",
"directions": 4
},
{
"name": "geiger_on_idle",
"directions": 4
},
{
"name": "geiger_on_low",
"directions": 4
},
{
"name": "geiger_on_med",
"directions": 4
},
{
"name": "geiger_on_high",
"directions": 4
},
{
"name": "geiger_on_ext",
"directions": 4
}
]
}

0 comments on commit 90d93d3

Please sign in to comment.