Files
crystall-punk-14/Content.Shared/Atmos/PipeDirection.cs

171 lines
5.5 KiB
C#
Raw Permalink Normal View History

using Robust.Shared.Serialization;
Atmos pipe rework (#3833) * Initial * Cleanup a bunch of things * some changes dunno * RequireAnchored * a * stuff * more work * Lots of progress * delete pipe visualizer * a * b * pipenet and pipenode cleanup * Fixes * Adds GasValve * Adds GasMiner * Fix stuff, maybe? * More fixes * Ignored components on the client * Adds thermomachine behavior, change a bunch of stuff * Remove Anchored * some work, but it's shitcode * significantly more ECS * ECS AtmosDevices * Cleanup * fix appearance * when the pipe direction is sus * Gas tanks and canisters * pipe anchoring and stuff * coding is my passion * Unsafe pipes take longer to unanchor * turns out we're no longer using eris canisters * Gas canister inserted tank appearance, improvements * Work on a bunch of appearances * Scrubber appearance * Reorganize AtmosphereSystem.Piping into a bunch of different systems * Appearance for vent/scrubber/pump turns off when leaving atmosphere * ThermoMachine appearance * Cleanup gas tanks * Remove passive gate unused imports * remove old canister UI functionality * PipeNode environment air, make everything use AssumeAir instead of merging manually * a * Reorganize atmos to follow new structure * ????? * Canister UI, restructure client * Restructure shared * Fix build tho * listen, at least the canister UI works entirely... * fix build : ) * Atmos device prototypes have names and descriptions * gas canister ui slider doesn't jitter * trinary prototypes * sprite for miners * ignore components * fix YAML * Fix port system doing useless thing * Fix build * fix thinking moment * fix build again because * canister direction * pipenode is a word * GasTank Air will throw on invalid states * fix build.... * Unhardcode volume pump thresholds * Volume pump and filter take time into account * Rename Join/Leave atmosphere events to AtmosDeviceEnabled/Disabled Event * Gas tank node volume is set by initial mixtuer * I love node container
2021-06-19 13:25:05 +02:00
namespace Content.Shared.Atmos
{
[Serializable, NetSerializable]
public enum PipeVisuals
{
VisualState
}
[Flags]
[Serializable, NetSerializable]
public enum PipeDirection
{
None = 0,
//Half of a pipe in a direction
North = 1 << 0,
South = 1 << 1,
Atmos pipe rework (#3833) * Initial * Cleanup a bunch of things * some changes dunno * RequireAnchored * a * stuff * more work * Lots of progress * delete pipe visualizer * a * b * pipenet and pipenode cleanup * Fixes * Adds GasValve * Adds GasMiner * Fix stuff, maybe? * More fixes * Ignored components on the client * Adds thermomachine behavior, change a bunch of stuff * Remove Anchored * some work, but it's shitcode * significantly more ECS * ECS AtmosDevices * Cleanup * fix appearance * when the pipe direction is sus * Gas tanks and canisters * pipe anchoring and stuff * coding is my passion * Unsafe pipes take longer to unanchor * turns out we're no longer using eris canisters * Gas canister inserted tank appearance, improvements * Work on a bunch of appearances * Scrubber appearance * Reorganize AtmosphereSystem.Piping into a bunch of different systems * Appearance for vent/scrubber/pump turns off when leaving atmosphere * ThermoMachine appearance * Cleanup gas tanks * Remove passive gate unused imports * remove old canister UI functionality * PipeNode environment air, make everything use AssumeAir instead of merging manually * a * Reorganize atmos to follow new structure * ????? * Canister UI, restructure client * Restructure shared * Fix build tho * listen, at least the canister UI works entirely... * fix build : ) * Atmos device prototypes have names and descriptions * gas canister ui slider doesn't jitter * trinary prototypes * sprite for miners * ignore components * fix YAML * Fix port system doing useless thing * Fix build * fix thinking moment * fix build again because * canister direction * pipenode is a word * GasTank Air will throw on invalid states * fix build.... * Unhardcode volume pump thresholds * Volume pump and filter take time into account * Rename Join/Leave atmosphere events to AtmosDeviceEnabled/Disabled Event * Gas tank node volume is set by initial mixtuer * I love node container
2021-06-19 13:25:05 +02:00
West = 1 << 2,
East = 1 << 3,
//Straight pipes
Longitudinal = North | South,
Lateral = West | East,
//Bends
NWBend = North | West,
NEBend = North | East,
SWBend = South | West,
SEBend = South | East,
//T-Junctions
TNorth = North | Lateral,
TSouth = South | Lateral,
TWest = West | Longitudinal,
TEast = East | Longitudinal,
//Four way
Fourway = North | South | East | West,
All = -1,
}
public enum PipeShape
{
Half,
Straight,
Bend,
TJunction,
Fourway
}
public static class PipeShapeHelpers
{
/// <summary>
/// Gets the direction of a shape when facing 0 degrees (the initial direction of entities).
/// </summary>
public static PipeDirection ToBaseDirection(this PipeShape shape)
{
return shape switch
{
PipeShape.Half => PipeDirection.South,
PipeShape.Straight => PipeDirection.Longitudinal,
PipeShape.Bend => PipeDirection.SWBend,
PipeShape.TJunction => PipeDirection.TSouth,
PipeShape.Fourway => PipeDirection.Fourway,
_ => throw new ArgumentOutOfRangeException(nameof(shape), $"{shape} does not have an associated {nameof(PipeDirection)}."),
};
}
}
public static class PipeDirectionHelpers
{
public const int PipeDirections = 4;
Atmos pipe rework (#3833) * Initial * Cleanup a bunch of things * some changes dunno * RequireAnchored * a * stuff * more work * Lots of progress * delete pipe visualizer * a * b * pipenet and pipenode cleanup * Fixes * Adds GasValve * Adds GasMiner * Fix stuff, maybe? * More fixes * Ignored components on the client * Adds thermomachine behavior, change a bunch of stuff * Remove Anchored * some work, but it's shitcode * significantly more ECS * ECS AtmosDevices * Cleanup * fix appearance * when the pipe direction is sus * Gas tanks and canisters * pipe anchoring and stuff * coding is my passion * Unsafe pipes take longer to unanchor * turns out we're no longer using eris canisters * Gas canister inserted tank appearance, improvements * Work on a bunch of appearances * Scrubber appearance * Reorganize AtmosphereSystem.Piping into a bunch of different systems * Appearance for vent/scrubber/pump turns off when leaving atmosphere * ThermoMachine appearance * Cleanup gas tanks * Remove passive gate unused imports * remove old canister UI functionality * PipeNode environment air, make everything use AssumeAir instead of merging manually * a * Reorganize atmos to follow new structure * ????? * Canister UI, restructure client * Restructure shared * Fix build tho * listen, at least the canister UI works entirely... * fix build : ) * Atmos device prototypes have names and descriptions * gas canister ui slider doesn't jitter * trinary prototypes * sprite for miners * ignore components * fix YAML * Fix port system doing useless thing * Fix build * fix thinking moment * fix build again because * canister direction * pipenode is a word * GasTank Air will throw on invalid states * fix build.... * Unhardcode volume pump thresholds * Volume pump and filter take time into account * Rename Join/Leave atmosphere events to AtmosDeviceEnabled/Disabled Event * Gas tank node volume is set by initial mixtuer * I love node container
2021-06-19 13:25:05 +02:00
/// <summary>
/// Includes the Up and Down directions.
/// </summary>
public const int AllPipeDirections = 6;
public static bool HasDirection(this PipeDirection pipeDirection, PipeDirection other)
{
return (pipeDirection & other) == other;
}
public static Angle ToAngle(this PipeDirection pipeDirection)
{
return pipeDirection.ToDirection().ToAngle();
}
public static PipeDirection ToPipeDirection(this Direction direction)
{
return direction switch
{
Direction.North => PipeDirection.North,
Direction.South => PipeDirection.South,
Direction.East => PipeDirection.East,
Direction.West => PipeDirection.West,
_ => throw new ArgumentOutOfRangeException(nameof(direction)),
};
}
public static Direction ToDirection(this PipeDirection pipeDirection)
{
return pipeDirection switch
{
PipeDirection.North => Direction.North,
PipeDirection.South => Direction.South,
PipeDirection.East => Direction.East,
PipeDirection.West => Direction.West,
_ => throw new ArgumentOutOfRangeException(nameof(pipeDirection)),
};
}
public static PipeDirection GetOpposite(this PipeDirection pipeDirection)
{
return pipeDirection switch
{
PipeDirection.North => PipeDirection.South,
PipeDirection.South => PipeDirection.North,
PipeDirection.East => PipeDirection.West,
PipeDirection.West => PipeDirection.East,
_ => throw new ArgumentOutOfRangeException(nameof(pipeDirection)),
};
}
public static PipeShape PipeDirectionToPipeShape(this PipeDirection pipeDirection)
{
return pipeDirection switch
{
PipeDirection.North => PipeShape.Half,
PipeDirection.South => PipeShape.Half,
PipeDirection.East => PipeShape.Half,
PipeDirection.West => PipeShape.Half,
PipeDirection.Lateral => PipeShape.Straight,
PipeDirection.Longitudinal => PipeShape.Straight,
PipeDirection.NEBend => PipeShape.Bend,
PipeDirection.NWBend => PipeShape.Bend,
PipeDirection.SEBend => PipeShape.Bend,
PipeDirection.SWBend => PipeShape.Bend,
PipeDirection.TNorth => PipeShape.TJunction,
PipeDirection.TSouth => PipeShape.TJunction,
PipeDirection.TEast => PipeShape.TJunction,
PipeDirection.TWest => PipeShape.TJunction,
PipeDirection.Fourway => PipeShape.Fourway,
_ => throw new ArgumentOutOfRangeException(nameof(pipeDirection)),
};
}
public static PipeDirection RotatePipeDirection(this PipeDirection pipeDirection, double diff)
{
var newPipeDir = PipeDirection.None;
for (var i = 0; i < PipeDirections; i++)
{
var currentPipeDirection = (PipeDirection) (1 << i);
if (!pipeDirection.HasFlag(currentPipeDirection)) continue;
var angle = currentPipeDirection.ToAngle();
angle += diff;
newPipeDir |= angle.GetCardinalDir().ToPipeDirection();
}
return newPipeDir;
}
}
}