Exemple #1
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 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 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);
            }
        }
Exemple #4
0
        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);
                }
            }
        }
Exemple #5
0
        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);
        }
Exemple #6
0
        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 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);
            }
        }
Exemple #8
0
        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);
                }
            }
        }
Exemple #9
0
        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);
                }
            }
        }
Exemple #10
0
        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);
        }