public void EqualiseWithOutputs(List <PipeData> others) { bool DifferenceInPressure = false; float density = this.Density(); foreach (var Pipe in others) { if (Math.Abs(PipeFunctions.PipeOrNet(Pipe).Density() - density) > 0.001f) { DifferenceInPressure = true; break; } } if (DifferenceInPressure) { if (others.Count > 1) { EqualiseWithMultiple(others); } else if (others.Count > 0) { EqualiseWith(others[0]); } } }
public void EqualiseWith(PipeData Another, bool EqualiseGas, bool EqualiseLiquid) { if (EqualiseGas) { PipeFunctions.PipeOrNet(Another).gasMix = gasMix.MergeGasMix(PipeFunctions.PipeOrNet(Another).gasMix); } if (EqualiseLiquid) { float TotalVolume = Volume + PipeFunctions.PipeOrNet(Another).Volume; float TotalReagents = Mix.Total + PipeFunctions.PipeOrNet(Another).Mix.Total; if (TotalVolume == 0) { Logger.LogError(" divide by 0 in EqualiseWith TotalVolume "); } float TargetDensity = TotalReagents / TotalVolume; float thisAmount = TargetDensity * Volume; float AnotherAmount = TargetDensity * PipeFunctions.PipeOrNet(Another).Volume; if (thisAmount > Mix.Total) { PipeFunctions.PipeOrNet(Another).Mix .TransferTo(Mix, PipeFunctions.PipeOrNet(Another).Mix.Total - AnotherAmount); } else { this.Mix.TransferTo(PipeFunctions.PipeOrNet(Another).Mix, AnotherAmount - PipeFunctions.PipeOrNet(Another).Mix.Total); } } }
public void EqualiseWithMultiple(List <PipeData> others) { float TotalVolume = Volume; foreach (var Pipe in others) { TotalVolume += PipeFunctions.PipeOrNet(Pipe).Volume; } float TotalReagents = Mix.Total; foreach (var Pipe in others) { TotalReagents += PipeFunctions.PipeOrNet(Pipe).Mix.Total; } float TargetDensity = TotalReagents / TotalVolume; foreach (var Pipe in others) { PipeFunctions.PipeOrNet(Pipe).Mix.TransferTo(Mix, PipeFunctions.PipeOrNet(Pipe).Mix.Total); } foreach (var Pipe in others) { Mix.TransferTo(PipeFunctions.PipeOrNet(Pipe).Mix, TargetDensity * PipeFunctions.PipeOrNet(Pipe).Volume); } }
public virtual void ServerPerformInteraction(HandApply interaction) { if (Validations.HasItemTrait(interaction.UsedObject, CommonTraits.Instance.Wrench)) { var ZeroedLocation = new Vector3Int(x: registerItem.LocalPosition.x, y: registerItem.LocalPosition.y, 0); var metaData = registerItem.Matrix.MetaDataLayer.Get(ZeroedLocation); var thisConnections = GetConnections(); int Offset = PipeFunctions.GetOffsetAngle(transform.localEulerAngles.z); thisConnections.Rotate(Offset); foreach (var Pipeo in metaData.PipeData) { var TheConnection = Pipeo.pipeData.Connections; for (int i = 0; i < thisConnections.Directions.Length; i++) { if (thisConnections.Directions[i].Bool && TheConnection.Directions[i].Bool) { return; } } } BuildPipe(); } RotatePipe(); }
public void EqualiseWith(PipeData Another, bool EqualiseGas, bool EqualiseLiquid) { if (EqualiseGas) { PipeFunctions.PipeOrNet(Another).gasMix = gasMix.MergeGasMix(PipeFunctions.PipeOrNet(Another).gasMix); if (gasMix.Gases.Any(x => x < 0)) { Logger.Log("0!!!"); } } if (EqualiseLiquid) { float TotalVolume = Volume + PipeFunctions.PipeOrNet(Another).Volume; float TotalReagents = Mix.Total + PipeFunctions.PipeOrNet(Another).Mix.Total; float TargetDensity = TotalReagents / TotalVolume; float thisAmount = TargetDensity * Volume; float AnotherAmount = TargetDensity * PipeFunctions.PipeOrNet(Another).Volume; if (thisAmount > Mix.Total) { PipeFunctions.PipeOrNet(Another).Mix .TransferTo(Mix, PipeFunctions.PipeOrNet(Another).Mix.Total - AnotherAmount); } else { this.Mix.TransferTo(PipeFunctions.PipeOrNet(Another).Mix, AnotherAmount - PipeFunctions.PipeOrNet(Another).Mix.Total); } } }
public void ConnectedAdd(PipeData NewConnection) { ConnectedPipes.Add(NewConnection); if (NetCompatible == false) { //This is a special pipe if (NewConnection.NetCompatible == false) { //NewConnection is a special pipe if (PipeFunctions.IsPipeOutputTo(this, NewConnection) && PipeFunctions.CanEqualiseWith(this, NewConnection)) { Outputs.Add(NewConnection); } } else { //NewConnection is a Pipe net if (PipeFunctions.IsPipeOutputTo(this, NewConnection)) { //An input to the pipe net it does not need to be recorded Outputs.Add(NewConnection); } if (this.Connections.Directions[(int)PipeFunctions.PipesToDirections(this, NewConnection)].PortType .HasFlag(OutputType.Can_Equalise_With)) { NewConnection.OnNet.AddEqualiseWith(this); } } } }
public override bool AreUnderfloorSame(Matrix4x4 thisTransformMatrix, BasicTile basicTile, Matrix4x4 TransformMatrix) { if ((basicTile as PipeTile) != null) { var TilePipeTile = (PipeTile)basicTile; var TheConnection = TilePipeTile.Connections.Copy(); int Offset = PipeFunctions.GetOffsetAngle(TransformMatrix.rotation.eulerAngles.z); TheConnection.Rotate(Offset); var thisConnection = Connections.Copy(); int thisOffset = PipeFunctions.GetOffsetAngle(thisTransformMatrix.rotation.eulerAngles.z); thisConnection.Rotate(thisOffset); for (int i = 0; i < thisConnection.Directions.Length; i++) { if (thisConnection.Directions[i].Bool && TheConnection.Directions[i].Bool) { return(true); } } return(false); } return(base.AreUnderfloorSame(thisTransformMatrix, basicTile, TransformMatrix)); }
public static Connections GetRotatedConnection(PipeTile pipeTile, Matrix4x4 matrixStruct) { var offset = PipeFunctions.GetOffsetAngle(matrixStruct.rotation.eulerAngles.z); var connection = pipeTile.Connections.Copy(); connection.Rotate(offset); return(connection); }
public bool CanEqualiseWithThis(PipeData Pipe) { if (Pipe.NetCompatible == false) { return(PipeFunctions.CanEqualiseWith(this.pipeData, Pipe)); } return(true); }
public virtual void OnEnable() { if (PipeAction != null) { PipeAction.pipeData = this; } AtmosManager.Instance.inGameNewPipes.Add(this); ConnectedPipes = PipeFunctions.GetConnectedPipes(ConnectedPipes, this, MatrixPos, matrix); foreach (var Pipe in ConnectedPipes) { Pipe.NetHookUp(this); } if (OnNet == null && NetCompatible) { OnNet = LiquidPipeNet.MakeNewNet(this); } foreach (var Pipe in ConnectedPipes) { Pipe.ConnectedAdd(this); if (NetCompatible == false) { //This is a special pipe //so Determine If neighbours special or net if (Pipe.NetCompatible == false) { //What is connecting to is a special pipe if (PipeFunctions.IsPipeOutputTo(this, Pipe) && PipeFunctions.CanEqualiseWith(this, Pipe)) { Outputs.Add(Pipe); } //Shouldn't need to register outputs on Pipe Since it could handle itself } else { //What is connecting to is a Net if (PipeFunctions.IsPipeOutputTo(this, Pipe)) { Outputs.Add(Pipe); } //Can it accept input? if (this.Connections.Directions[(int)PipeFunctions.PipesToDirections(this, Pipe)].PortType .HasFlag(OutputType.Can_Equalise_With)) { Pipe.OnNet.AddEqualiseWith(this); } } } } }
public void InitialiseNode(Vector3Int Location, Matrix matrix) { var ZeroedLocation = new Vector3Int(x: Location.x, y: Location.y, 0); var metaData = matrix.MetaDataLayer.Get(ZeroedLocation); var pipeNode = new PipeNode(); var rotation = matrix.UnderFloorLayer.Tilemap.GetTransformMatrix(Location); int Offset = PipeFunctions.GetOffsetAngle(rotation.rotation.eulerAngles.z); pipeNode.Initialise(this, metaData, ZeroedLocation, matrix, Offset); metaData.PipeData.Add(pipeNode); }
public void InitialiseNodeNew(Vector3Int Location, Matrix matrix, Matrix4x4 Matrix4x4) { var ZeroedLocation = new Vector3Int(x: Location.x, y: Location.y, 0); var metaData = matrix.MetaDataLayer.Get(ZeroedLocation); var pipeNode = new PipeNode(); var rotation = Matrix4x4; int Offset = PipeFunctions.GetOffsetAngle(rotation.rotation.eulerAngles.z); pipeNode.Initialise(this, metaData, ZeroedLocation, matrix, Offset); metaData.PipeData.Add(pipeNode); }
public virtual void OnSpawnServer(SpawnInfo info) { if (pipeData.PipeAction == null) { pipeData.PipeAction = new MonoActions(); } registerTile.SetPipeData(pipeData); pipeData.MonoPipe = this; int Offset = PipeFunctions.GetOffsetAngle(transform.localRotation.eulerAngles.z); pipeData.Connections.Rotate(Offset); pipeData.OnEnable(); spritehandler?.SetColor(Colour); }
public override void TickUpdate() { if (IsOn == false) { return; } var PressureDensity = pipeData.mixAndVolume.Density(); if (PressureDensity.x > MaxPressure && PressureDensity.y > MaxPressure) { return; } var tomove = new Vector2(Mathf.Abs((PressureDensity.x / MaxPressure) - 1), Mathf.Abs((PressureDensity.y / MaxPressure) - 1)); Vector2 AvailableReagents = new Vector2(0f, 0f); foreach (var Pipe in pipeData.ConnectedPipes) { if (pipeData.Outputs.Contains(Pipe) == false && CanEqualiseWithThis(Pipe)) { var Data = PipeFunctions.PipeOrNet(Pipe); AvailableReagents += Data.Total; } } Vector2 TotalRemove = Vector2.zero; TotalRemove.x = (TransferMoles) > AvailableReagents.x ? AvailableReagents.x : TransferMoles; TotalRemove.y = (TransferMoles) > AvailableReagents.y ? AvailableReagents.y : TransferMoles; TotalRemove.x = tomove.x > 1 ? 0 : TotalRemove.x; TotalRemove.y = tomove.y > 1 ? 0 : TotalRemove.y; foreach (var Pipe in pipeData.ConnectedPipes) { if (pipeData.Outputs.Contains(Pipe) == false && CanEqualiseWithThis(Pipe)) { //TransferTo var Data = PipeFunctions.PipeOrNet(Pipe); Data.TransferTo(pipeData.mixAndVolume, (Data.Total / AvailableReagents) * TotalRemove); } } pipeData.mixAndVolume.EqualiseWithOutputs(pipeData.Outputs); }
public override void BuildPipe() { var searchVec = registerItem.LocalPosition; var Pipe = (GetPipeObject()); if (Pipe != null) { int Offset = PipeFunctions.GetOffsetAngle(transform.localEulerAngles.z); Quaternion?rot = Quaternion.Euler(0.0f, 0.0f, Offset); var New = Spawn.ServerPrefab(Pipe.gameObject, registerItem.WorldPositionServer, localRotation: rot); New.GameObject.GetComponent <MonoPipe>().SetColour(Colour); Despawn.ServerSingle(this.gameObject); } }
private void EnsureInit() { if (registerTile == null) { registerTile = GetComponent <RegisterTile>(); } registerTile.SetPipeData(pipeData); pipeData.MonoPipe = this; int Offset = PipeFunctions.GetOffsetAngle(this.transform.localRotation.eulerAngles.z); pipeData.Connections.Rotate(Offset); pipeData.OnEnable(); spritehandler?.SetColor(Colour); }
public virtual void BuildPipe() { var searchVec = objectBehaviour.registerTile.LocalPosition; var Tile = (GetPipeTile()); if (Tile != null) { int Offset = PipeFunctions.GetOffsetAngle(transform.localEulerAngles.z); Quaternion rot = Quaternion.Euler(0.0f, 0.0f, Offset); var Matrix = Matrix4x4.TRS(Vector3.zero, rot, Vector3.one); objectBehaviour.registerTile.Matrix.AddUnderFloorTile(searchVec, Tile, Matrix, Colour); Tile.InitialiseNode(searchVec, objectBehaviour.registerTile.Matrix); Despawn.ServerSingle(this.gameObject); } }
public override void BuildPipe() { var pipe = GetPipeObject(); if (pipe == null) { return; } int Offset = PipeFunctions.GetOffsetAngle(transform.localEulerAngles.z); Quaternion?rot = Quaternion.Euler(0.0f, 0.0f, Offset); var New = Spawn.ServerPrefab(pipe.gameObject, registerItem.WorldPositionServer, localRotation: rot); New.GameObject.GetComponent <MonoPipe>().SetColour(Colour); _ = Despawn.ServerSingle(gameObject); }
public void ConnectedAdd(PipeData NewConnection) { if (MonoPipe != null) { if (MonoPipe.name == "Filter (1)") { Logger.Log("yay"); } } ConnectedPipes.Add(NewConnection); var pipe1Connection = this.Connections.Directions[(int)PipeFunctions.PipesToDirections(this, NewConnection)]; pipe1Connection.Connected = NewConnection; if (NetCompatible == false) { //This is a special pipe if (NewConnection.NetCompatible == false) { //NewConnection is a special pipe if (PipeFunctions.IsPipeOutputTo(this, NewConnection) && PipeFunctions.CanEqualiseWith(this, NewConnection)) { pipe1Connection.Connected = NewConnection; Outputs.Add(NewConnection); } } else { //NewConnection is a Pipe net if (PipeFunctions.IsPipeOutputTo(this, NewConnection)) { //An input to the pipe net it does not need to be recorded Outputs.Add(NewConnection); } if (this.Connections.Directions[(int)PipeFunctions.PipesToDirections(this, NewConnection)].PortType .HasFlag(OutputType.Can_Equalise_With)) { NewConnection.OnNet.AddEqualiseWith(this); } } } }
public override void TickUpdate() { Vector2 AvailableReagents = new Vector2(0f, 0f); foreach (var Pipe in pipeData.ConnectedPipes) { if (pipeData.Outputs.Contains(Pipe) == false && CanEqualiseWithThis(Pipe)) { var Data = PipeFunctions.PipeOrNet(Pipe); AvailableReagents += Data.Total; } } Vector2 TotalRemove = Vector2.zero; if ((UnitPerTick * PowerPercentage) > AvailableReagents.x) { TotalRemove.x = AvailableReagents.x; } else { TotalRemove.x = (UnitPerTick * PowerPercentage); } if ((UnitPerTick * PowerPercentage) > AvailableReagents.y) { TotalRemove.y = AvailableReagents.y; } else { TotalRemove.y = (UnitPerTick * PowerPercentage); } foreach (var Pipe in pipeData.ConnectedPipes) { if (pipeData.Outputs.Contains(Pipe) == false && CanEqualiseWithThis(Pipe)) { //TransferTo var Data = PipeFunctions.PipeOrNet(Pipe); Data.TransferTo(pipeData.mixAndVolume, (Data.Total / AvailableReagents) * TotalRemove); } } pipeData.mixAndVolume.EqualiseWithOutputs(pipeData.Outputs); }
public override void BuildPipe() { var searchVec = registerItem.LocalPosition; var tile = GetPipeTile(); if (tile == null) { return; } int Offset = PipeFunctions.GetOffsetAngle(transform.localEulerAngles.z); Quaternion rot = Quaternion.Euler(0.0f, 0.0f, Offset); var Matrix = Matrix4x4.TRS(Vector3.zero, rot, Vector3.one); registerItem.Matrix.AddUnderFloorTile(searchVec, tile, Matrix, Colour); tile.InitialiseNodeNew(searchVec, registerItem.Matrix, Matrix); _ = Despawn.ServerSingle(this.gameObject); }
public void EqualiseWith(PipeData Another) { float TotalVolume = Volume + PipeFunctions.PipeOrNet(Another).Volume; float TotalReagents = Mix.Total + PipeFunctions.PipeOrNet(Another).Mix.Total; float TargetDensity = TotalReagents / TotalVolume; float thisAmount = TargetDensity * Volume; float AnotherAmount = TargetDensity * PipeFunctions.PipeOrNet(Another).Volume; if (thisAmount > Mix.Total) { PipeFunctions.PipeOrNet(Another).Mix.TransferTo(Mix, PipeFunctions.PipeOrNet(Another).Mix.Total - AnotherAmount); } else { this.Mix.TransferTo(PipeFunctions.PipeOrNet(Another).Mix, AnotherAmount - PipeFunctions.PipeOrNet(Another).Mix.Total); } }
public void EqualiseWithMultiple(List <PipeData> others, bool EqualiseGas, bool EqualiseLiquid) { if (EqualiseGas) { gasMix.MergeGasMixes(others); } if (EqualiseLiquid) { float TotalVolume = Volume; foreach (var Pipe in others) { TotalVolume += PipeFunctions.PipeOrNet(Pipe).Volume; } float TotalReagents = Mix.Total; foreach (var Pipe in others) { TotalReagents += PipeFunctions.PipeOrNet(Pipe).Mix.Total; } if (TotalVolume == 0) { Logger.LogError(" divide by 0 in EqualiseWithMultiple TotalVolume "); } float TargetDensity = TotalReagents / TotalVolume; foreach (var Pipe in others) { PipeFunctions.PipeOrNet(Pipe).Mix.TransferTo(Mix, PipeFunctions.PipeOrNet(Pipe).Mix.Total); } foreach (var Pipe in others) { Mix.TransferTo(PipeFunctions.PipeOrNet(Pipe).Mix, TargetDensity * PipeFunctions.PipeOrNet(Pipe).Volume); } } }
public void EqualiseWithOutputs(List <PipeData> others) { bool DifferenceInPressure = false; bool DifferenceInDensity = false; Vector2 density = this.Density(); foreach (var Pipe in others) { var DensityDelta = (PipeFunctions.PipeOrNet(Pipe).Density() - density); if (Mathf.Abs(DensityDelta.x) > 0.001f) { DifferenceInDensity = true; if (DifferenceInPressure) { break; } } if (Mathf.Abs(DensityDelta.y) > 0.001f) { DifferenceInPressure = true; if (DifferenceInDensity) { break; } } } if (DifferenceInPressure || DifferenceInDensity) { if (others.Count > 1) { EqualiseWithMultiple(others, DifferenceInPressure, DifferenceInDensity); } else if (others.Count > 0) { EqualiseWith(others[0], DifferenceInPressure, DifferenceInDensity); } } }
public void EqualiseWithMultiple(List <PipeData> others, bool EqualiseGas, bool EqualiseLiquid) { if (EqualiseGas) { gasMix.MergeGasMixes(others); if (gasMix.Gases.Any(x => x < 0)) { Logger.Log("0!!!"); } } if (EqualiseLiquid) { float TotalVolume = Volume; foreach (var Pipe in others) { TotalVolume += PipeFunctions.PipeOrNet(Pipe).Volume; } float TotalReagents = Mix.Total; foreach (var Pipe in others) { TotalReagents += PipeFunctions.PipeOrNet(Pipe).Mix.Total; } float TargetDensity = TotalReagents / TotalVolume; foreach (var Pipe in others) { PipeFunctions.PipeOrNet(Pipe).Mix.TransferTo(Mix, PipeFunctions.PipeOrNet(Pipe).Mix.Total); } foreach (var Pipe in others) { Mix.TransferTo(PipeFunctions.PipeOrNet(Pipe).Mix, TargetDensity * PipeFunctions.PipeOrNet(Pipe).Volume); } } }
public override void TickUpdate() { float AvailableReagents = 0; foreach (var Pipe in pipeData.ConnectedPipes) { if (pipeData.Outputs.Contains(Pipe) == false && CanEqualiseWithThis(Pipe)) { var Data = PipeFunctions.PipeOrNet(Pipe); AvailableReagents += Data.Mix.Total; } } float TotalRemove = 0; if ((UnitPerTick * PowerPercentage) > AvailableReagents) { TotalRemove = AvailableReagents; } else { TotalRemove = (UnitPerTick * PowerPercentage); } foreach (var Pipe in pipeData.ConnectedPipes) { if (pipeData.Outputs.Contains(Pipe) == false && CanEqualiseWithThis(Pipe)) { var Data = PipeFunctions.PipeOrNet(Pipe); Data.Mix.TransferTo(pipeData.mixAndVolume.Mix, (Data.Mix.Total / AvailableReagents) * TotalRemove); } } pipeData.mixAndVolume.EqualiseWithOutputs(pipeData.Outputs); }