Skip to content

Commit 9ecdc0d

Browse files
committed
Allow overriding individual AtmosFixMarkers with custom atmosphere
This mostly exists so freezers in a ship bought with pure nitrogen atmosphere also actually contain a pure nitrogen atmosphere instead of the regular freezer mix, which would immediately trigger air alarms. As an aside: why the heck is the list of possible markers hardcoded in fixgridatmos. You can just put the atmosphere definition on the marker component. It's going to be fine. Nobody is running fixgridatmos in a tight loop.
1 parent 4a9f5e0 commit 9ecdc0d

File tree

3 files changed

+51
-13
lines changed

3 files changed

+51
-13
lines changed

Content.Server/_NF/Shipyard/Systems/ShipyardSystem.CustomAtmos.cs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Linq;
21
using Content.Server._NF.Shipyard.Components;
32
using Content.Server.Atmos.Components;
43
using Content.Server.Atmos.Monitor.Components;
@@ -52,10 +51,12 @@ private void ReplaceShuttleAtmosphere(
5251
{
5352
var mapGrid = shuttleGrid.Comp3!;
5453

55-
var mix = new GasMixture(Atmospherics.CellVolume) { Temperature = atmos.Temperature };
56-
foreach (var (gas, moles) in atmos.Atmosphere)
54+
var defaultAtmosMix = MakeGasMixFromDefinition(atmos);
55+
56+
var overrides = new Dictionary<int, GasMixture>();
57+
foreach (var (marker, definition) in atmos.AtmosFixOverrides)
5758
{
58-
mix.SetMoles(gas, moles);
59+
overrides[marker] = MakeGasMixFromDefinition(definition);
5960
}
6061

6162
var query = GetEntityQuery<AtmosFixMarkerComponent>();
@@ -69,15 +70,34 @@ private void ReplaceShuttleAtmosphere(
6970
if (_atmosphere.GetTileMixture(shuttleGrid, null, position, true) is not { Immutable: false } air)
7071
continue;
7172

72-
// Skip any tiles with an AtmosFixMarker; they already have the correct atmosphere from FixGridAtmosCommand
73-
if (_map.GetAnchoredEntities((shuttleGrid.Owner, mapGrid), position).Any(query.HasComp))
74-
continue;
73+
var targetMixture = defaultAtmosMix;
74+
75+
// Check whether we need to override any AtmosFixMarker on this tile
76+
foreach (var entity in _map.GetAnchoredEntities((shuttleGrid.Owner, mapGrid), position))
77+
{
78+
if (query.TryComp(entity, out var marker))
79+
{
80+
targetMixture = overrides.GetValueOrDefault(marker.Mode, defaultAtmosMix);
81+
break;
82+
}
83+
}
7584

7685
// Replace atmosphere
77-
air.CopyFrom(mix);
86+
air.CopyFrom(targetMixture);
7887
}
7988
}
8089

90+
private static GasMixture MakeGasMixFromDefinition(AtmosphereDefinition atmos)
91+
{
92+
var mix = new GasMixture(Atmospherics.CellVolume) { Temperature = atmos.Temperature };
93+
foreach (var (gas, moles) in atmos.Atmosphere)
94+
{
95+
mix.SetMoles(gas, moles);
96+
}
97+
98+
return mix;
99+
}
100+
81101
// Assumption: There are way fewer shuttles in the game than there are top-level entities on the new grid, so
82102
// it's faster to look up all distro machines and check that they're on the shuttle we're setting up than going
83103
// through all entities on the shuttle and check that they have the atmos component

Content.Shared/_NF/Shipyard/Prototypes/ShuttleAtmospherePrototype.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,30 @@
55

66
namespace Content.Shared._NF.Shipyard.Prototypes;
77

8+
public abstract class AtmosphereDefinition
9+
{
10+
[DataField]
11+
public float Temperature = Atmospherics.T20C;
12+
13+
[DataField(required: true)]
14+
public Dictionary<Gas, float> Atmosphere = default!;
15+
}
16+
817
[Prototype]
9-
public sealed class ShuttleAtmospherePrototype : IPrototype
18+
public sealed class ShuttleAtmospherePrototype : AtmosphereDefinition, IPrototype
1019
{
1120
[IdDataField]
1221
public string ID { get; } = default!;
1322

1423
[DataField(required: true)]
1524
public string Name = string.Empty;
1625

26+
/// <summary>
27+
/// A set of atmosphere overrides for individual AtmosFixMarker tiles.
28+
/// See Content.Server.Atmos.EntitySystems.AtmosphereSystem.FixGridAtmosCommand for a list of valid keys.
29+
/// </summary>
1730
[DataField]
18-
public float Temperature = Atmospherics.T20C;
19-
20-
[DataField(required: true)]
21-
public Dictionary<Gas, float> Atmosphere = default!;
31+
public Dictionary<int, ShuttleAtmosphereFixMarkerOverride> AtmosFixOverrides = [];
2232

2333
[DataField]
2434
public ShuttleAtmosphereAlarms? Alarms;
@@ -27,6 +37,9 @@ public sealed class ShuttleAtmospherePrototype : IPrototype
2737
public List<Gas>? FilterGases;
2838
}
2939

40+
[DataDefinition]
41+
public sealed partial class ShuttleAtmosphereFixMarkerOverride : AtmosphereDefinition;
42+
3043
[DataDefinition]
3144
public sealed partial class ShuttleAtmosphereAlarms
3245
{

Resources/Prototypes/_NF/Shipyard/Base/atmos.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
gasThresholdPrototypes:
2424
Oxygen: voxOxygen
2525
Nitrogen: voxNitrogen
26+
atmosFixOverrides:
27+
6: # Freezer
28+
temperature: 235
29+
atmosphere:
30+
Nitrogen: 129.64464
2631
filterGases:
2732
- Oxygen
2833
- CarbonDioxide

0 commit comments

Comments
 (0)