예제 #1
0
        public override void CompTick()
        {
            base.CompTick();

            if (Find.TickManager.TicksAbs % 50 != 0)
            {
                return;
            }

            var def     = parent.Map.GetSpaceAtmosphereMapComponent().DefinitionAt(parent.Position);
            var calc    = new ShipDefinition.GasCalculator(def);
            var rg      = parent.GetRoomGroup();
            var roomGas = def.GetGas(rg);

            if (parent.Map.IsSpace())
            {
                //dump air into the current environment
                var pressureDif = GasMixture.EarthNorm.totalPressure - roomGas.mixture.totalPressure;
                if (pressureDif > 0.0f)
                {
                    //release enough gas (or whatever's left) to get the gas up to 101.325 kPa.
                    var pressureNeeded = pressureDif * rg.CellCount;

                    if (pressureNeeded > gas.totalPressure)
                    {
                        calc.GasExchange(rg, added: new GasVolume(GasMixture.atPressure(gas, gas.totalPressure / (float)rg.CellCount), rg.CellCount));
                    }
                    else
                    {
                        calc.GasExchange(rg, added: new GasVolume(GasMixture.atPressure(gas, pressureDif), rg.CellCount));
                    }
                    gas = gas - pressureNeeded;
                }
            }
            else
            {
                if (gas.totalPressure >= MaxPressure)
                {
                    return;
                }
                //don't steal gas from the ship while in atmo. Deal with this later.
                //calc.GasExchange(rg, removed: new GasVolume(roomGas.mixture, 2f));
                //calc.Execute();

                gas = gas + GasMixture.EarthNorm * 2f;

                if (gas.totalPressure > MaxPressure)
                {
                    gas = GasMixture.atPressure(gas, MaxPressure);
                }
            }
        }
        private void TryRepressurize()
        {
            Map currentMap = parent.Map;

            var def     = currentMap.GetSpaceAtmosphereMapComponent().DefinitionAt(parent.Position);
            var calc    = new ShipDefinition.GasCalculator(def);
            var rg      = parent.GetRoomGroup();
            var roomGas = def.GetGas(rg);

            gas += new GasMixture(0, 1000, 1000);

            var pressureDif = GasMixture.EarthNorm.totalPressure - roomGas.mixture.totalPressure;

            if (pressureDif > 0.0f)
            {
                //release enough gas (or whatever's left) to get the gas up to 101.325 kPa.
                var pressureNeeded = pressureDif * rg.CellCount;

                if (pressureNeeded > gas.totalPressure)
                {
                    calc.GasExchange(rg, added: new GasVolume(GasMixture.atPressure(gas, gas.totalPressure / (float)rg.CellCount), rg.CellCount));
                }
                else
                {
                    calc.GasExchange(rg, added: new GasVolume(GasMixture.atPressure(gas, pressureDif), rg.CellCount));
                }
                gas -= pressureNeeded;

                calc.Execute();

                if (gas.totalPressure < 0)
                {
                    gas += GasMixture.atPressure(SpaceConstants.EarthNorm, 0);
                }
            }
        }
        public override void CompTick()
        {
            base.CompTick();

            if (Find.TickManager.TicksAbs % 50 != 0)
            {
                return;
            }

            Map currentMap = parent.Map;

            if (currentMap.IsSpace())
            {
                var def     = currentMap.GetSpaceAtmosphereMapComponent().DefinitionAt(parent.Position);
                var calc    = new ShipDefinition.GasCalculator(def);
                var rg      = parent.GetRoomGroup();
                var roomGas = def.GetGas(rg);

                bool roomHasLifeSupport = !AtmosphereAssistant.IsMixtureToxic(roomGas.mixture);

                var pressureDif = GasMixture.EarthNorm.totalPressure - roomGas.mixture.totalPressure;

                bool roomAtPressure = pressureDif <= 0.0f;

                bool TankEmpty     = gas.totalPressure <= 0;
                bool TankFull      = gas.totalPressure >= MaxPressure;
                bool TankHasOxygen = gas.O2Partial > 0;
                bool TankHasCo2    = gas.Co2Partial > 0;

                if (roomAtPressure)
                {
                    bool recalc = false;


                    if (AtmosphereAssistant.IsMixtureCo2Toxic(roomGas.mixture))
                    {
                        if (!TankFull)
                        {
                            gas += new GasMixture(0, 0, 1);
                            calc.GasExchange(rg, removed: new GasVolume(new GasMixture(0, 0, 1), rg.CellCount));
                            recalc  = true;
                            BarType = 2;
                        }
                    }
                    else
                    {
                        if (BarType == 2)
                        {
                            BarType = 0;
                        }

                        if (TankHasCo2 && roomGas.mixture.Co2Partial < 1) //dump some co2 in for plants etc
                        {
                            gas -= new GasMixture(0, 0, 0.5f);
                            calc.GasExchange(rg, added: new GasVolume(new GasMixture(0, 0, 0.5f), rg.CellCount));
                            recalc  = true;
                            BarType = 2;
                        }
                    }

                    if (AtmosphereAssistant.MixtureHasInertGas(roomGas.mixture))
                    {
                        if (!TankFull)
                        {
                            gas += new GasMixture(1, 0, 0);
                            calc.GasExchange(rg, removed: new GasVolume(new GasMixture(1, 0, 0), rg.CellCount));
                            recalc = true;
                        }
                    }

                    if (recalc)
                    {
                        calc.Execute();
                        pressureDif    = GasMixture.EarthNorm.totalPressure - roomGas.mixture.totalPressure;
                        roomAtPressure = pressureDif <= 0.0f;
                    }

                    if (TankHasOxygen)
                    {
                        if (!roomAtPressure && !AtmosphereAssistant.IsOxygenRich(roomGas.mixture))
                        {
                            gas -= new GasMixture(0, 1, 0);
                            calc.GasExchange(rg, added: new GasVolume(new GasMixture(0, 1, 0), rg.CellCount));
                            recalc = true;

                            if (BarType == 0)
                            {
                                BarType = 1;
                            }
                        }
                        else
                        {
                            if (BarType == 1)
                            {
                                BarType = 0;
                            }
                        }
                    }

                    if (recalc)
                    {
                        calc.Execute();
                    }
                }
                else
                {
                    bool canReleaseGas = gas.totalPressure >= (MaxPressure * 0.005f);

                    if (AtmosphereAssistant.IsMixtureOxygenated(roomGas.mixture, 10f))
                    {
                        if (!TankFull)
                        {
                            float drainRate = 1f;

                            if (roomGas.mixture.O2Partial > 30)
                            {
                                drainRate = 2f;
                            }

                            gas += SpaceConstants.ShipNorm * (2f * drainRate);
                            // gas += new GasMixture(90, 0, SpaceConstants.EarthNorm.Co2Partial);
                            calc.GasExchange(rg, removed: new GasVolume(new GasMixture(0, drainRate, 0), rg.CellCount));
                        }
                    }


                    if (canReleaseGas)
                    {
                        var pressureNeeded = pressureDif * rg.CellCount;

                        if (pressureNeeded > gas.totalPressure)
                        {
                            calc.GasExchange(rg, added: new GasVolume(GasMixture.atPressure(gas, gas.totalPressure / (float)rg.CellCount), rg.CellCount));
                        }
                        else
                        {
                            calc.GasExchange(rg, added: new GasVolume(GasMixture.atPressure(gas, pressureDif), rg.CellCount));
                        }
                        gas -= pressureNeeded;

                        BarType = 1;

                        calc.Execute();

                        if (gas.totalPressure < 0)
                        {
                            gas += GasMixture.atPressure(SpaceConstants.EarthNorm, 0);
                        }
                    }
                    else
                    {
                        if (BarType != 0)
                        {
                            BarType = 0;
                        }

                        if (gas.totalPressure <= (MaxPressure * 0.005f) && roomGas.mixture.totalPressure < HalfEarthPressure)
                        {
                            gas    += new GasMixture(100, 0, SpaceConstants.EarthNorm.Co2Partial);
                            BarType = 2;
                        }
                        else
                        {
                            if (BarType == 2)
                            {
                                BarType = 0;
                            }
                        }
                    }

                    if (AtmosphereAssistant.IsMixtureCo2Toxic(roomGas.mixture))
                    {
                        if (!TankFull)
                        {
                            gas += new GasMixture(0, 0, 1);
                            calc.GasExchange(rg, removed: new GasVolume(new GasMixture(0, 0, 1), rg.CellCount));
                            calc.Execute();
                            BarType = 3;
                        }
                    }
                    else
                    {
                        if (BarType == 3)
                        {
                            BarType = 0;
                        }
                    }
                }
            }
            else
            {
                if (gas.totalPressure >= MaxPressure)
                {
                    return;
                }
                //don't steal gas from the ship while in atmo. Deal with this later.
                //calc.GasExchange(rg, removed: new GasVolume(roomGas.mixture, 2f));
                //calc.Execute();

                gas += GasMixture.EarthNorm * 2f;

                if (gas.totalPressure > MaxPressure)
                {
                    gas = GasMixture.atPressure(gas, MaxPressure);
                }
            }
        }