Ejemplo n.º 1
0
        private void CheckRelease()
        {
            if (Opened)
            {
                MetaDataLayer metaDataLayer = MatrixManager.AtPoint(Vector3Int.RoundToInt(transform.position), true)
                                              .MetaDataLayer;

                Vector3Int   position = transform.localPosition.RoundToInt();
                MetaDataNode node     = metaDataLayer.Get(position, false);

                float deltaPressure = Mathf.Min(GasMix.Pressure, ReleasePressure) - node.GasMix.Pressure;

                if (deltaPressure > 0)
                {
                    float ratio = deltaPressure / GasMix.Pressure * Time.deltaTime;

                    node.GasMix += GasMix * ratio;

                    GasMix *= (1 - ratio);

                    metaDataLayer.UpdateSystemsAt(position);

                    Volume      = GasMix.Volume;
                    Temperature = GasMix.Temperature;

                    foreach (Gas gas in Gas.All)
                    {
                        Gases[gas] = GasMix.Gases[gas];
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void CheckAtmos()
        {
            // FIXME I'm just handling the exception here, I'm no atmos nerd so I don't know what's happening.
            // maybe it is just an initialization order problem?
            if (metaNode == null)
            {
                Logger.LogError("Scrubber found metadaNode to be null. Returning with no op.", Category.Atmos);
                return;
            }

            if (SelfSufficient == false)
            {
                var pressureDensity = pipeData.mixAndVolume.Density();

                if (pressureDensity.y > MaxInternalPressure || metaNode.GasMix.Pressure < MMinimumPressure)
                {
                    return;
                }
            }
            else
            {
                if (metaNode.GasMix.Pressure < MMinimumPressure)
                {
                    return;
                }
            }

            if (metaNode.GasMix.Pressure == 0)
            {
                return;
            }

            float available = MMinimumPressure / metaNode.GasMix.Pressure * metaNode.GasMix.Moles;

            if (available < 0)
            {
                return;
            }

            if (MaxTransferMoles < available)
            {
                available = MaxTransferMoles;
            }

            var    gasOnNode = metaNode.GasMix;
            GasMix pipeMix;

            if (SelfSufficient)
            {
                pipeMix = GasMix.NewGasMix(GasMixes.Air);                 //TODO: get some immutable gasmix to avoid GC
            }
            else
            {
                pipeMix = pipeData.mixAndVolume.GetGasMix();
            }

            GasMix.TransferGas(pipeMix, gasOnNode, available);

            metaDataLayer.UpdateSystemsAt(registerTile.LocalPositionServer, SystemType.AtmosSystem);
        }
Ejemplo n.º 3
0
        public void SpillContent(Tuple <ReagentMix, GasMix> ToSpill)
        {
            if (pipeNode == null && MonoPipe == null)
            {
                return;
            }

            Vector3Int ZeroedLocation = Vector3Int.zero;

            if (pipeNode != null)
            {
                ZeroedLocation = pipeNode.NodeLocation;
            }
            else
            {
                ZeroedLocation = MonoPipe.MatrixPos;
            }

            ZeroedLocation.z = 0;
            var tileWorldPosition = MatrixManager.LocalToWorld(ZeroedLocation, matrix).RoundToInt();

            MatrixManager.ReagentReact(ToSpill.Item1, tileWorldPosition);
            MetaDataLayer metaDataLayer = MatrixManager.AtPoint(tileWorldPosition, true).MetaDataLayer;

            if (pipeNode != null)
            {
                pipeNode.IsOn.GasMix += ToSpill.Item2;
            }
            else
            {
                matrix.GetMetaDataNode(ZeroedLocation).GasMix += ToSpill.Item2;
            }
            metaDataLayer.UpdateSystemsAt(ZeroedLocation, SystemType.AtmosSystem);
        }
Ejemplo n.º 4
0
        public override void TickUpdate()
        {
            base.TickUpdate();
            pipeData.mixAndVolume.EqualiseWithOutputs(pipeData.Outputs);

            if (IsOperating == false || isWelded)
            {
                return;
            }
            if (CanTransfer() == false)
            {
                return;
            }

            switch (OperatingMode)
            {
            case Mode.Scrubbing:
                ModeScrub();
                break;

            case Mode.Siphoning:
                ModeSiphon();
                break;
            }

            metaDataLayer.UpdateSystemsAt(registerTile.LocalPositionServer, SystemType.AtmosSystem);

            if (selfSufficient)
            {
                pipeMix.Copy(GasMixes.BaseEmptyMix);                 // We don't need to do this, just void the gas
            }
        }
Ejemplo n.º 5
0
        private void ReleaseContentsInstantly()
        {
            MetaDataLayer metaDataLayer = MatrixManager.AtPoint(WorldPosition, true).MetaDataLayer;
            MetaDataNode  node          = metaDataLayer.Get(LocalPosition, false);

            GasMix.TransferGas(node.GasMix, GasMix, GasMix.Moles);
            metaDataLayer.UpdateSystemsAt(LocalPosition, SystemType.AtmosSystem);
        }
Ejemplo n.º 6
0
        private void CheckAtmos()
        {
            //metaNode.GasMix = pipeData.mixAndVolume.EqualiseWithExternal(metaNode.GasMix);
            if (metaNode.GasMix.Pressure > MaxOutletPressure)
            {
                return;
            }

            float Available =
                ((MaxOutletPressure / metaNode.GasMix.Pressure) * metaNode.GasMix.Moles) - metaNode.GasMix.Moles;

            if (MaxTransferMoles < Available)
            {
                Available = MaxTransferMoles;
            }

            if (SelfSufficient)
            {
                if (Available > GasMixes.Air.Moles)
                {
                    Available = GasMixes.Air.Moles;
                }
            }
            else
            {
                if (Available > pipeData.mixAndVolume.Total.y)
                {
                    Available = pipeData.mixAndVolume.Total.y;
                }
            }


            var Gasonnnode = metaNode.GasMix;
            var pipeMix    = new GasMix(GasMixes.Empty);

            if (SelfSufficient)
            {
                pipeMix = new GasMix(GasMixes.Air);
            }
            else
            {
                pipeMix = pipeData.mixAndVolume.GetGasMix();
            }


            var TransferringGas = pipeMix.RemoveMoles(Available);

            if (!SelfSufficient)
            {
                pipeData.mixAndVolume.SetGasMix(pipeMix);
            }


            metaNode.GasMix = (Gasonnnode + TransferringGas);
            metaDataLayer.UpdateSystemsAt(registerTile.LocalPositionServer);
        }
Ejemplo n.º 7
0
 private void CheckAtmos()
 {
     if (metaNode.GasMix.Pressure > MinimumPressure)
     {
         var suckedAir = metaNode.GasMix / 2;
         pipenet.gasMix  += suckedAir;
         metaNode.GasMix -= suckedAir;
         metaDataLayer.UpdateSystemsAt(registerTile.WorldPositionServer);
     }
 }
Ejemplo n.º 8
0
        public override void TickUpdate()
        {
            pipeData.mixAndVolume.EqualiseWithOutputs(pipeData.Outputs);

            if (isOperating)
            {
                GasMix.TransferGas(targetMix, sourceMix, molesRate * Effectiveness);
                metaDataLayer.UpdateSystemsAt(registerTile.LocalPositionServer, SystemType.AtmosSystem);
            }
        }
Ejemplo n.º 9
0
 private void CheckAtmos()
 {
     if (metaNode.GasMix.Pressure < MinimumPressure)
     {
         GasMix gasMix = pipenet.gasMix;
         pipenet.gasMix  = gasMix / 2;
         metaNode.GasMix = metaNode.GasMix + gasMix;
         metaDataLayer.UpdateSystemsAt(registerTile.WorldPositionServer);
     }
 }
Ejemplo n.º 10
0
        private void CheckAtmos()
        {
            if (SelfSufficient == false)
            {
                var pressureDensity = pipeData.mixAndVolume.Density();

                if (pressureDensity.y > MaxInternalPressure || metaNode.GasMix.Pressure < MMinimumPressure)
                {
                    return;
                }
            }
            else
            {
                if (metaNode.GasMix.Pressure < MMinimumPressure)
                {
                    return;
                }
            }

            if (metaNode.GasMix.Pressure == 0)
            {
                return;
            }

            float available = MMinimumPressure / metaNode.GasMix.Pressure * metaNode.GasMix.Moles;

            if (available < 0)
            {
                return;
            }

            if (MaxTransferMoles < available)
            {
                available = MaxTransferMoles;
            }

            var    gasOnNode = metaNode.GasMix;
            GasMix pipeMix;

            if (SelfSufficient)
            {
                pipeMix = GasMix.NewGasMix(GasMixes.Air);                 //TODO: get some immutable gasmix to avoid GC
            }
            else
            {
                pipeMix = pipeData.mixAndVolume.GetGasMix();
            }

            GasMix.TransferGas(pipeMix, gasOnNode, available);

            metaDataLayer.UpdateSystemsAt(registerTile.LocalPositionServer, SystemType.AtmosSystem);
        }
Ejemplo n.º 11
0
        private void CheckAtmos()
        {
            // FIXME I'm just handling the exception here, I'm no atmos nerd so I don't know what's happening.
            // maybe it is just an initialization order problem?
            if (metaNode == null)
            {
                Logger.LogError("Airvent found metadaNode to be null. Returning with no op.", Category.Atmos);
                return;
            }

            //metaNode.GasMix = pipeData.mixAndVolume.EqualiseWithExternal(metaNode.GasMix);
            if (metaNode.GasMix.Pressure > MaxOutletPressure)
            {
                return;
            }

            float molesTransferred;

            if (metaNode.GasMix.Pressure != 0)
            {
                molesTransferred = ((MaxOutletPressure / metaNode.GasMix.Pressure) * metaNode.GasMix.Moles) - metaNode.GasMix.Moles;
                if (MaxTransferMoles < molesTransferred)
                {
                    molesTransferred = MaxTransferMoles;
                }
            }
            else
            {
                molesTransferred = MaxTransferMoles;
            }

            GasMix pipeMix;

            if (SelfSufficient)
            {
                pipeMix = GasMix.NewGasMix(GasMixes.Air);                 //TODO: get some immutable gasmix to avoid GC
                if (molesTransferred > GasMixes.Air.Moles)
                {
                    molesTransferred = GasMixes.Air.Moles;
                }
            }
            else
            {
                pipeMix = pipeData.mixAndVolume.GetGasMix();
                if (molesTransferred > pipeMix.Moles)
                {
                    molesTransferred = pipeMix.Moles;
                }
            }
            GasMix.TransferGas(metaNode.GasMix, pipeMix, molesTransferred);
            metaDataLayer.UpdateSystemsAt(registerTile.LocalPositionServer, SystemType.AtmosSystem);
        }
Ejemplo n.º 12
0
        private void CheckAtmos()
        {
            if (SelfSufficient == false)
            {
                var pressureDensity = pipeData.mixAndVolume.Density();

                if (pressureDensity.y > MaxInternalPressure || metaNode.GasMix.Pressure < MMinimumPressure)
                {
                    return;
                }
            }
            else
            {
                if (metaNode.GasMix.Pressure < MMinimumPressure)
                {
                    return;
                }
            }

            if (metaNode.GasMix.Pressure == 0)
            {
                return;
            }

            float available = MMinimumPressure / metaNode.GasMix.Pressure * metaNode.GasMix.Moles;

            if (available < 0)
            {
                return;
            }

            if (MaxTransferMoles < available)
            {
                available = MaxTransferMoles;
            }

            var gasOnNode = metaNode.GasMix;

            if (SelfSufficient)
            {
                GasMix.TransferGas(selfSufficientGas, gasOnNode, available);
                selfSufficientGas.Copy(GasMixes.BaseAirMix);
            }
            else
            {
                var pipeMix = pipeData.mixAndVolume.GetGasMix();
                GasMix.TransferGas(pipeMix, gasOnNode, available);
            }

            metaDataLayer.UpdateSystemsAt(registerTile.LocalPositionServer, SystemType.AtmosSystem);
        }
Ejemplo n.º 13
0
        private void CheckAtmos()
        {
            if (SelfSufficient == false)
            {
                var PressureDensity = pipeData.mixAndVolume.Density();
                if (PressureDensity.y > MaxInternalPressure || metaNode.GasMix.Pressure < MMinimumPressure)
                {
                    return;
                }
            }
            else
            {
                if (metaNode.GasMix.Pressure < MMinimumPressure)
                {
                    return;
                }
            }

            float Available = 0;

            if (metaNode.GasMix.Pressure != 0)
            {
                Available = ((MMinimumPressure / metaNode.GasMix.Pressure) * metaNode.GasMix.Moles);
            }
            else
            {
                return;
            }

            if (Available < 0)
            {
                return;
            }

            if (MaxTransferMoles < Available)
            {
                Available = MaxTransferMoles;
            }

            var Gasonnnode      = metaNode.GasMix;
            var TransferringGas = Gasonnnode.RemoveMoles(Available);

            metaNode.GasMix = Gasonnnode;
            if (SelfSufficient == false)
            {
                pipeData.mixAndVolume.Add(TransferringGas);
            }

            metaDataLayer.UpdateSystemsAt(registerTile.LocalPositionServer, SystemType.AtmosSystem);
        }
Ejemplo n.º 14
0
        private void Operate()
        {
            GasMix sourceGasMix = pipeMix;
            GasMix targetGasMix = metaNode.GasMix;

            if (OperatingMode == Mode.In)
            {
                sourceGasMix = metaNode.GasMix;
                targetGasMix = pipeMix;
            }

            GasMix.TransferGas(targetGasMix, sourceGasMix, GetTransferableMoles(sourceGasMix));
            metaDataLayer.UpdateSystemsAt(registerTile.LocalPositionServer, SystemType.AtmosSystem);
        }
Ejemplo n.º 15
0
        private void OperateAirPump()
        {
            MetaDataLayer metadata = registerObject.Matrix.MetaDataLayer;
            GasMix        tileMix  = metadata.Get(registerObject.LocalPositionServer, false).GasMix;

            // TODO: add voltage multiplier when bins are powered
            var molesToTransfer = (tileMix.Moles - (tileMix.Moles * (CHARGED_PRESSURE / gasContainer.GasMix.Pressure))) * -1;

            molesToTransfer *= 0.5f;

            GasMix.TransferGas(gasContainer.GasMix, tileMix, molesToTransfer.Clamp(0, 8));
            metadata.UpdateSystemsAt(registerObject.LocalPositionServer, SystemType.AtmosSystem);

            chargePressure = gasContainer.GasMix.Pressure;
        }
Ejemplo n.º 16
0
 private void CheckAtmos()
 {
     if (metaNode.GasMix.Pressure < MinimumPressure)
     {
         //TODO: Can restore this when pipenets are implemented so they actually pull from what
         //they are connected to. In the meantime
         //we are reverting scrubbers / airvents to the old behavior of just shoving or removing air
         //regardless of what they are connected to.
         // GasMix gasMix = pipenet.gasMix;
         // pipenet.gasMix = gasMix / 2;
         // metaNode.GasMix = metaNode.GasMix + gasMix;
         metaNode.GasMix = new GasMix(GasMixes.Air);
         metaDataLayer.UpdateSystemsAt(RegisterTile.LocalPositionServer);
     }
 }
Ejemplo n.º 17
0
        public override void TickUpdate()
        {
            pipeData.mixAndVolume.EqualiseWithOutputs(pipeData.Outputs);

            if (isOperating)
            {
                if (operatingMode == Mode.Extracting && pipeData.mixAndVolume.Density().y > MaxInternalPressure)
                {
                    return;
                }

                GasMix.TransferGas(targetMix, sourceMix, molesRate * Effectiveness);
                metaDataLayer.UpdateSystemsAt(registerTile.LocalPositionServer, SystemType.AtmosSystem);
            }
        }
Ejemplo n.º 18
0
    private void CheckAtmos()
    {
        if (metaNode.GasMix.Pressure > MinimumPressure)
        {
            //TODO: Can restore this when pipenets are implemented so they actually pull from what
            //they are connected to. In the meantime
            //we are reverting scrubbers / airvents to the old behavior of just shoving or removing air
            //regardless of what they are connected to.
            // var suckedAir =  metaNode.GasMix / 2;
            // pipenet.gasMix += suckedAir;
            // metaNode.GasMix -= suckedAir;

            //suck out a fraction of the current gasmix
            var suckedAir = metaNode.GasMix / 4;
            metaNode.GasMix -= suckedAir;
            metaDataLayer.UpdateSystemsAt(RegisterTile.LocalPositionServer);
        }
    }
Ejemplo n.º 19
0
        private void OnWillDestroyServer(DestructionInfo info)
        {
            var tileWorldPosition = gameObject.TileWorldPosition().To3Int();
            //release all of our gases at once when destroyed
            MetaDataLayer metaDataLayer  = MatrixManager.AtPoint(tileWorldPosition, true).MetaDataLayer;
            Vector3Int    position       = transform.localPosition.RoundToInt();
            MetaDataNode  node           = metaDataLayer.Get(position, false);
            var           shakeIntensity = (byte)Mathf.Lerp(byte.MinValue, byte.MaxValue / 2, GasMix.Pressure / MAX_EXPLOSION_EFFECT_PRESSURE);
            var           shakeDistance  = Mathf.Lerp(1, 64, GasMix.Pressure / MAX_EXPLOSION_EFFECT_PRESSURE);

            node.GasMix += GasMix;
            metaDataLayer.UpdateSystemsAt(position);
            Chat.AddLocalMsgToChat($"{name} exploded!", gameObject.TileWorldPosition());

            ObjectFactory.SpawnMetal(2, tileWorldPosition.To2Int(), parent: transform.parent);

            ExplosionUtils.PlaySoundAndShake(tileWorldPosition, shakeIntensity, (int)shakeDistance);
        }
Ejemplo n.º 20
0
        private void CheckAtmos()
        {
            //metaNode.GasMix = pipeData.mixAndVolume.EqualiseWithExternal(metaNode.GasMix);
            if (metaNode.GasMix.Pressure > MaxOutletPressure)
            {
                return;
            }

            float molesTransferred;

            if (metaNode.GasMix.Pressure != 0)
            {
                molesTransferred = ((MaxOutletPressure / metaNode.GasMix.Pressure) * metaNode.GasMix.Moles) - metaNode.GasMix.Moles;
                if (MaxTransferMoles < molesTransferred)
                {
                    molesTransferred = MaxTransferMoles;
                }
            }
            else
            {
                molesTransferred = MaxTransferMoles;
            }

            GasMix pipeMix;

            if (SelfSufficient)
            {
                pipeMix = GasMix.NewGasMix(GasMixes.Air);                 //TODO: get some immutable gasmix to avoid GC
                if (molesTransferred > GasMixes.Air.Moles)
                {
                    molesTransferred = GasMixes.Air.Moles;
                }
            }
            else
            {
                pipeMix = pipeData.mixAndVolume.GetGasMix();
                if (molesTransferred > pipeMix.Moles)
                {
                    molesTransferred = pipeMix.Moles;
                }
            }
            GasMix.TransferGas(metaNode.GasMix, pipeMix, molesTransferred);
            metaDataLayer.UpdateSystemsAt(registerTile.LocalPositionServer, SystemType.AtmosSystem);
        }
Ejemplo n.º 21
0
        private void OnWillDestroyServer(DestructionInfo info)
        {
            var tileWorldPosition = gameObject.TileWorldPosition().To3Int();
            //release all of our gases at once when destroyed
            MetaDataLayer metaDataLayer  = MatrixManager.AtPoint(tileWorldPosition, true).MetaDataLayer;
            Vector3Int    position       = transform.localPosition.RoundToInt();
            MetaDataNode  node           = metaDataLayer.Get(position, false);
            var           shakeIntensity = (byte)Mathf.Lerp(byte.MinValue, byte.MaxValue / 2, GasMix.Pressure / MAX_EXPLOSION_EFFECT_PRESSURE);
            var           shakeDistance  = Mathf.Lerp(1, 64, GasMix.Pressure / MAX_EXPLOSION_EFFECT_PRESSURE);

            node.GasMix += GasMix;
            metaDataLayer.UpdateSystemsAt(position);
            Chat.AddLocalDestroyMsgToChat(gameObject.ExpensiveName(), " exploded!", gameObject.TileWorldPosition());

            Spawn.ServerPrefab("Metal", gameObject.TileWorldPosition().To3Int(), transform.parent, count: 2,
                               scatterRadius: Spawn.DefaultScatterRadius, cancelIfImpassable: true);

            ExplosionUtils.PlaySoundAndShake(tileWorldPosition, shakeIntensity, (int)shakeDistance);
        }
Ejemplo n.º 22
0
        private void CheckRelease()
        {
            if (Opened)
            {
                MetaDataLayer metaDataLayer = MatrixManager.AtPoint(Vector3Int.RoundToInt(transform.position)).MetaDataLayer;

                Vector3Int   position = transform.localPosition.RoundToInt();
                MetaDataNode node     = metaDataLayer.Get(position, false);

                float deltaPressure = Mathf.Min(GasMix.Pressure, ReleasePressure) - node.Atmos.Pressure;

                if (deltaPressure > 0)
                {
                    float ratio = deltaPressure / GasMix.Pressure * Time.deltaTime;

                    node.Atmos += GasMix * ratio;

                    GasMix *= (1 - ratio);

                    metaDataLayer.UpdateSystemsAt(position);
                }
            }
        }
Ejemplo n.º 23
0
        private void CheckAtmos()
        {
            //metaNode.GasMix = pipeData.mixAndVolume.EqualiseWithExternal(metaNode.GasMix);
            if (metaNode.GasMix.Pressure > MaxOutletPressure)
            {
                return;
            }

            float molesTransferred;

            if (metaNode.GasMix.Pressure != 0)
            {
                molesTransferred = ((MaxOutletPressure / metaNode.GasMix.Pressure) * metaNode.GasMix.Moles) - metaNode.GasMix.Moles;
                if (MaxTransferMoles < molesTransferred)
                {
                    molesTransferred = MaxTransferMoles;
                }
            }
            else
            {
                molesTransferred = MaxTransferMoles;
            }

            if (SelfSufficient)
            {
                TransferGas(selfSufficientGas, molesTransferred);
                selfSufficientGas.Copy(GasMixes.Air);
            }
            else
            {
                var pipeMix = pipeData.mixAndVolume.GetGasMix();
                TransferGas(pipeMix, molesTransferred);
            }

            metaDataLayer.UpdateSystemsAt(registerTile.LocalPositionServer, SystemType.AtmosSystem);
        }