Пример #1
0
    public void ExposeHotspot(Vector3Int localPosition, float temperature, float volume)
    {
        if (hotspots.ContainsKey(localPosition) && hotspots[localPosition].Hotspot != null)
        {
            // TODO soh?
            hotspots[localPosition].Hotspot.UpdateValues(volume * 25, temperature);
        }
        else
        {
            Profiler.BeginSample("MarkForAddition");
            MetaDataNode node   = metaDataLayer.Get(localPosition);
            GasMix       gasMix = node.GasMix;

            if (gasMix.GetMoles(Gas.Plasma) > 0.5 && gasMix.GetMoles(Gas.Oxygen) > 0.5 && temperature > Reactions.PlasmaMaintainFire)
            {
                // igniting
                //addition will be done later in Update
                hotspotsToAdd.Add(new Hotspot(node, temperature, volume * 25));
            }
            Profiler.EndSample();
        }

        if (hotspots.ContainsKey(localPosition) && hotspots[localPosition].Hotspot != null)
        {
            //expose everything on this tile
            Expose(localPosition, localPosition);

            //expose impassable things on the adjacent tile
            Expose(localPosition, localPosition + Vector3Int.right);
            Expose(localPosition, localPosition + Vector3Int.left);
            Expose(localPosition, localPosition + Vector3Int.up);
            Expose(localPosition, localPosition + Vector3Int.down);
        }
    }
Пример #2
0
        private void UpdateState()
        {
            isOperating = powerState == PowerState.Off ? false : isTurnedOn;

            if (CustomNetworkManager.IsServer)
            {
                switch (operatingMode)
                {
                default:
                case Mode.Injecting:
                    sourceMix = pipeMix;
                    targetMix = metaNode.GasMix;
                    break;

                case Mode.Extracting:
                    sourceMix = metaNode.GasMix;
                    targetMix = pipeMix;
                    break;
                }
            }


            Sprite sprite = operatingMode == Mode.Injecting ? Sprite.Injecting : Sprite.On;

            sprite = isOperating ? sprite : Sprite.Off;
            spritehandler.ChangeSprite((int)sprite);
        }
Пример #3
0
        /// <summary>
        /// Takes gases from a GasMix and puts them into blood as a reagent
        /// </summary>
        public void GasExchangeToBlood(GasMix atmos, ReagentMix blood, ReagentMix toProcess, float LungCapacity)
        {
            lock (toProcess.reagents)
            {
                foreach (var Reagent in toProcess.reagents.m_dict)
                {
                    blood.Add(Reagent.Key, Reagent.Value);
                }
            }


            if (!canBreathAnywhere)
            {
                if (LungCapacity + 0.1f > atmos.Moles)                 //Just so scenario where there isn't Gas * 0 = 0
                {
                    atmos.MultiplyGas(0.01f);
                }
                else
                {
                    if (atmos.Moles == 0)
                    {
                        return;
                    }

                    var percentageRemaining = 1 - (LungCapacity / atmos.Moles);
                    atmos.MultiplyGas(percentageRemaining);
                }
            }
        }
Пример #4
0
        //update DCompMatrix by index
        public void add(int depth, DCompRow row, GasMix gasMix)
        {
            if (!m_AirTable.ContainsKey(depth))
            {
                m_AirTable.Add(depth, new DCompMatrix());
            }
            if (!m_AirO2Table.ContainsKey(depth))
            {
                m_AirO2Table.Add(depth, new DCompMatrix());
            }
            switch (gasMix)
            {
            case GasMix.AIR:
                m_AirTable[depth].addDComp(row);
                break;

            case GasMix.AIRO2:
                m_AirO2Table[depth].addDComp(row);
                break;

            case GasMix.NONE:
            default:
                Console.Write("failed to add element on DCompTable");
                break;
            }


            //implemented in updateBTLUT
            //g_depthList.Add(depth);
        }
Пример #5
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);
        }
Пример #6
0
        public DCompRow(int bottomTime, int timeToFirstStop, GasMix gasMix, double chamberO2Periods, char repeatGroup, params int[] DCompTimeFromFile)
        {
            m_DCompStops        = new SortedDictionary <int, int>();
            m_DComp_pauses_data = new SortedDictionary <int, List <int> >();
            m_DCompStops_including_pause_time = new SortedDictionary <int, int>();

            var keys = m_DCompStops.Keys.ToList();

            for (int idx = 0; idx < DCompTimeFromFile.Length; idx++)
            {
                m_DCompStops.Add((20 + idx * 10), DCompTimeFromFile[idx]);
                m_TDT += DCompTimeFromFile[idx];
                //m_DCompStops[keys.ElementAt(idx)] = mapList[idx];
            }

            m_BottomTime       = bottomTime;
            m_TimeToFirstStop  = timeToFirstStop;
            m_GasMix           = gasMix;
            m_ChamberO2Periods = chamberO2Periods;
            m_RepeatGroup      = repeatGroup;

            this.UpdatePauseData();
            this.UpdateTimeIncludingPauses();

            isInitialized = true;
        }
Пример #7
0
        public void React(GasMix gasMix, Vector3 tilePos, Matrix matrix)
        {
            var oxyMoles = gasMix.GetMoles(Gas.Oxygen);

            gasMix.AddGas(Gas.Plasma, oxyMoles);
            gasMix.RemoveGas(Gas.Oxygen, oxyMoles);
        }
Пример #8
0
        public void VentContents()
        {
            var metaDataLayer = MatrixManager.AtPoint(Vector3Int.RoundToInt(transform.position), true).MetaDataLayer;

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

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

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

                GasMix.TransferGas(node.GasMix, GasMix, ratio);

                metaDataLayer.UpdateSystemsAt(localPosition, SystemType.AtmosSystem);

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

                foreach (Gas gas in Gas.All)
                {
                    Gases[gas] = GasMix.Gases[gas];
                }
            }
        }
Пример #9
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];
                    }
                }
            }
        }
Пример #10
0
    private bool Breathe(IGasMixContainer node)
    {
        breatheCooldown--;          //not timebased, but tickbased
        if (breatheCooldown > 0)
        {
            return(false);
        }
        // if no internal breathing is possible, get the from the surroundings
        IGasMixContainer container = GetInternalGasMix() ?? node;

        GasMix gasMix       = container.GasMix;
        GasMix breathGasMix = gasMix.RemoveVolume(AtmosConstants.BREATH_VOLUME, true);

        float oxygenUsed = HandleBreathing(breathGasMix);

        if (oxygenUsed > 0)
        {
            breathGasMix.RemoveGas(Gas.Oxygen, oxygenUsed);
            node.GasMix.AddGas(Gas.CarbonDioxide, oxygenUsed);
            registerTile.Matrix.MetaDataLayer.UpdateSystemsAt(registerTile.LocalPositionClient);
        }

        gasMix          += breathGasMix;
        container.GasMix = gasMix;

        return(oxygenUsed > 0);
    }
Пример #11
0
        public void Divide(float DivideAmount, bool ChangeVolume = true)
        {
            if (DivideAmount == 0)
            {
                Logger.LogError(" divide by 0 in Divide");
            }

            float GasVolume = gasMix.Volume;

            if (ChangeVolume)
            {
                GasVolume = GasVolume / DivideAmount;
            }

            Mix.Divide(DivideAmount);

            var Newone = new float[gasMix.Gases.Length];

            for (int i = 0; i < gasMix.Gases.Length; i++)
            {
                Newone[i] = gasMix.Gases[i] / DivideAmount;
            }

            gasMix = GasMix.FromTemperature(Newone, gasMix.Temperature, GasVolume);
        }
Пример #12
0
    private float HandleBreathing(GasMix breathGasMix)
    {
        float oxygenPressure = breathGasMix.GetPressure(Gas.Oxygen);

        float oxygenUsed = 0;

        if (oxygenPressure < OXYGEN_SAFE_MIN)
        {
            if (Random.value < 0.1)
            {
                Chat.AddActionMsgToChat(gameObject, "You gasp for breath", $"{gameObject.name} gasps");
            }

            if (oxygenPressure > 0)
            {
                float ratio = 1 - oxygenPressure / OXYGEN_SAFE_MIN;
                bloodSystem.OxygenDamage += 1 * ratio;
                oxygenUsed = breathGasMix.GetMoles(Gas.Oxygen) * ratio;
            }
            else
            {
                bloodSystem.OxygenDamage += 1;
            }
            IsSuffocating = true;
        }
        else
        {
            oxygenUsed                = breathGasMix.GetMoles(Gas.Oxygen);
            IsSuffocating             = false;
            bloodSystem.OxygenDamage -= 2.5f;
            breatheCooldown           = 4;
        }
        return(oxygenUsed);
    }
Пример #13
0
 public void Add(MixAndVolume mixAndVolume)
 {
     Mix.Add(mixAndVolume.Mix);
     Volume = Volume + mixAndVolume.Volume;
     gasMix = gasMix + mixAndVolume.gasMix;
     gasMix.ChangeVolumeValue(mixAndVolume.gasMix.Volume);
 }
Пример #14
0
        public void React(GasMix gasMix, MetaDataNode node)
        {
            var oxyMoles = gasMix.GetMoles(Gas.Oxygen);

            gasMix.AddGas(Gas.Plasma, oxyMoles);
            gasMix.RemoveGas(Gas.Oxygen, oxyMoles);
        }
Пример #15
0
        void UpdateGasMix()
        {
            if (this.RB_GAS_AIR.Checked)
            {
                g_GasMix = GasMix.AIR;
            }
            else if (this.RB_GAS_AIRO2.Checked)
            {
                g_GasMix = GasMix.AIRO2;
            }
            else
            {
                g_GasMix = GasMix.NONE;
            }

            switch (g_GasMix)
            {
            case GasMix.AIR:
                TB_Travel_Shift_Vent_Time.Text = colonizeTime(40, ColonType.SEC_ONLY);
                TB_Ascent_Time_Water.Text      = "";
                break;

            case GasMix.AIRO2:
                TB_Travel_Shift_Vent_Time.Text = colonizeTime(2);
                TB_Ascent_Time_Water.Text      = colonizeTime(40, ColonType.SEC_ONLY);
                break;

            case GasMix.NONE:
            default:
                break;
            }
        }
Пример #16
0
        public Tuple <ReagentMix, GasMix> Take(MixAndVolume InmixAndVolume, bool removeVolume = true)
        {
            if (Volume == 0)
            {
                Logger.LogError(" divide by 0 in Take ");
            }

            float Percentage      = InmixAndVolume.Volume / Volume;
            float RemoveGasVolume = gasMix.Volume;
            float GasVolume       = gasMix.Volume;

            if (removeVolume)
            {
                RemoveGasVolume = RemoveGasVolume * Percentage;
                GasVolume       = GasVolume * (1 - Percentage);
            }

            var ReturnMix = Mix.Take(Mix.Total * Percentage);

            var Newone       = new float[gasMix.Gases.Length];
            var RemoveNewone = new float[gasMix.Gases.Length];

            for (int i = 0; i < gasMix.Gases.Length; i++)
            {
                RemoveNewone[i] = gasMix.Gases[i] * Percentage;
                Newone[i]       = gasMix.Gases[i] * (1 - Percentage);
            }

            gasMix = GasMix.FromTemperature(Newone, gasMix.Temperature, GasVolume);

            return(new Tuple <ReagentMix, GasMix>(ReturnMix,
                                                  GasMix.FromTemperature(RemoveNewone, gasMix.Temperature, RemoveGasVolume)));
        }
Пример #17
0
    public void ExposeHotspot(Vector3Int localPosition, float temperature, float volume)
    {
        if (hotspots.ContainsKey(localPosition) && hotspots[localPosition].Hotspot != null)
        {
            // TODO soh?
            hotspots[localPosition].Hotspot.UpdateValues(volume * 25, temperature);
        }
        else
        {
            MetaDataNode node   = metaDataLayer.Get(localPosition);
            GasMix       gasMix = node.GasMix;

            if (gasMix.GetMoles(Gas.Plasma) > 0.5 && gasMix.GetMoles(Gas.Oxygen) > 0.5 && temperature > Reactions.PLASMA_MINIMUM_BURN_TEMPERATURE)
            {
                // igniting
                Hotspot hotspot = new Hotspot(node, temperature, volume * 25);
                node.Hotspot            = hotspot;
                hotspots[localPosition] = node;
            }
        }

        if (hotspots.ContainsKey(localPosition) && hotspots[localPosition].Hotspot != null)
        {
            //expose everything on this tile
            Expose(localPosition, localPosition);

            //expose impassable things on the adjacent tile
            Expose(localPosition, localPosition + Vector3Int.right);
            Expose(localPosition, localPosition + Vector3Int.left);
            Expose(localPosition, localPosition + Vector3Int.up);
            Expose(localPosition, localPosition + Vector3Int.down);
        }
    }
Пример #18
0
    private float HandleBreathing(GasMix breathGasMix)
    {
        float oxygenPressure = breathGasMix.GetPressure(Gas.Oxygen);

        float oxygenUsed = 0;

        if (oxygenPressure < OXYGEN_SAFE_MIN)
        {
            if (Random.value < 0.2)
            {
                PostToChatMessage.Send("gasp", ChatChannel.Local);
            }

            if (oxygenPressure > 0)
            {
                float ratio = 1 - oxygenPressure / OXYGEN_SAFE_MIN;

                ApplyDamage(Mathf.Min(5 * ratio, 3), DamageType.Oxy);
                bloodSystem.OxygenLevel += 30 * ratio;

                oxygenUsed = breathGasMix.GetMoles(Gas.Oxygen) * ratio;
            }
            else
            {
                ApplyDamage(3, DamageType.Oxy);
            }
        }
        else
        {
            oxygenUsed = breathGasMix.GetMoles(Gas.Oxygen);
            bloodSystem.OxygenLevel += 30;
        }

        return(oxygenUsed);
    }
Пример #19
0
    public void ExposeHotspot(Vector3Int position, float temperature, float volume)
    {
        if (hotspots.ContainsKey(position) && hotspots[position].Hotspot != null)
        {
            // TODO soh?
            hotspots[position].Hotspot.UpdateValues(volume * 25, temperature);
        }
        else
        {
            MetaDataNode node   = metaDataLayer.Get(position);
            GasMix       gasMix = node.GasMix;

            if (gasMix.GetMoles(Gas.Plasma) > 0.5 && gasMix.GetMoles(Gas.Oxygen) > 0.5 && temperature > Reactions.PLASMA_MINIMUM_BURN_TEMPERATURE)
            {
                // igniting
                Hotspot hotspot = new Hotspot(node, temperature, volume * 25);
                node.Hotspot       = hotspot;
                hotspots[position] = node;
            }
        }

        if (hotspots.ContainsKey(position) && hotspots[position].Hotspot != null)
        {
            List <LivingHealthBehaviour> healths = matrix.Get <LivingHealthBehaviour>(position);

            foreach (LivingHealthBehaviour health in healths)
            {
                health.ApplyDamage(null, 1, DamageType.Burn);
            }
        }
    }
Пример #20
0
    private float HandleBreathing(GasMix breathGasMix)
    {
        float oxygenPressure = breathGasMix.GetPressure(Gas.Oxygen);

        float oxygenUsed = 0;

        if (oxygenPressure < OXYGEN_SAFE_MIN)
        {
            if (Random.value < 0.1)
            {
                PostToChatMessage.SendGasp(base.gameObject);
            }

            if (oxygenPressure > 0)
            {
                float ratio = 1 - oxygenPressure / OXYGEN_SAFE_MIN;
                bloodSystem.OxygenDamage += 1 * ratio;
                oxygenUsed = breathGasMix.GetMoles(Gas.Oxygen) * ratio;
            }
            else
            {
                bloodSystem.OxygenDamage += 1;
            }
            IsSuffocating = true;
        }
        else
        {
            oxygenUsed                = breathGasMix.GetMoles(Gas.Oxygen);
            IsSuffocating             = false;
            bloodSystem.OxygenDamage -= 2.5f;
            breatheCooldown           = 4;
        }
        return(oxygenUsed);
    }
Пример #21
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)
            {
                GasMix.TransferGas(pipeNode.IsOn.GasMix, ToSpill.Item2, ToSpill.Item2.Moles);
            }
            else
            {
                GasMix.TransferGas(matrix.GetMetaDataNode(ZeroedLocation).GasMix, ToSpill.Item2, ToSpill.Item2.Moles);
            }
            metaDataLayer.UpdateSystemsAt(ZeroedLocation, SystemType.AtmosSystem);
        }
Пример #22
0
        static GasMixes()
        {
            float[] gases = new float[Gas.Count];
            gases[Gas.Oxygen]   = 16.628484400890768491815384755837f / 2 * 2.5f;
            gases[Gas.Nitrogen] = 66.513937603563073967261539023347f / 2 * 2.5f;

            Air = GasMix.FromTemperature(gases, Reactions.T0C + 20);
        }
Пример #23
0
 private void TransferGas(GasMix pipeMix, float molesTransferred)
 {
     if (molesTransferred > pipeMix.Moles)
     {
         molesTransferred = pipeMix.Moles;
     }
     GasMix.TransferGas(metaNode.GasMix, pipeMix, molesTransferred);
 }
Пример #24
0
        public float React(ref GasMix gasMix, Vector3 tilePos)
        {
            gasMix.AddGas(Gas.Plasma, 1f);

            gasMix.RemoveGas(Gas.Oxygen, 1f);

            return(0f);
        }
Пример #25
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);
        }
Пример #26
0
    public void ChangeGasMix(GasMix newGasMix)
    {
        AtmosSimulation.RemovalAllGasOverlays(this);

        GasMix = newGasMix;

        AtmosSimulation.GasVisualEffects(this);
    }
Пример #27
0
        public override void OnSpawnServer(SpawnInfo info)
        {
            metaDataLayer = MatrixManager.AtPoint(registerTile.WorldPositionServer, true).MetaDataLayer;
            metaNode      = metaDataLayer.Get(registerTile.LocalPositionServer, false);
            pipeMix       = pipeData.GetMixAndVolume.GetGasMix();

            UpdateState();
            base.OnSpawnServer(info);
        }
Пример #28
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);
        }
Пример #29
0
        public void MergeCanisterAndTank()
        {
            GasContainer canisterTank = GetComponent <GasContainer>();
            GasContainer externalTank = InsertedContainer.GetComponent <GasContainer>();
            GasMix       canisterGas  = canisterTank.GasMix;
            GasMix       tankGas      = externalTank.GasMix;

            canisterTank.GasMix = tankGas.MergeGasMix(canisterGas);
            externalTank.GasMix = tankGas;
        }
Пример #30
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);
     }
 }