示例#1
0
    /// <summary>
    /// Moves gas to another atmosphere. Temperature is transferred accordingly.
    /// </summary>
    /// <param name="destination">Destination of the gas.</param>
    /// <param name="amount">Amount of gas to move.</param>
    public void MoveGasTo(AtmosphereComponent destination, float amount)
    {
        if (destination == null)
        {
            UnityDebugger.Debugger.LogError("MoveGasTo -- Destination can not be null");
            return;
        }

        if (amount < 0 || float.IsNaN(amount))
        {
            UnityDebugger.Debugger.LogError("MoveGasTo -- Amount can not be negative: " + amount);
            return;
        }

        amount = Mathf.Min(this.TotalGas, amount);

        string[] gasNames = this.GetGasNames();
        for (int i = 0; i < gasNames.Length; i++)
        {
            float partialAmount = amount * GetGasFraction(gasNames[i]);
            this.ChangeGas(gasNames[i], -partialAmount);
            destination.ChangeGas(gasNames[i], partialAmount);
        }

        float thermalDelta = amount * internalTemperature.InKelvin;

        this.ThermalEnergy        -= thermalDelta;
        destination.ThermalEnergy += thermalDelta;
    }
    /// <summary>
    /// Moves gas to another atmosphere. Thermal energy is transferred accordingly.
    /// </summary>
    /// <param name="destination">Destination of the gas.</param>
    /// <param name="amount">Amount of gas to move.</param>
    public void MoveGasTo(AtmosphereComponent destination, float amount)
    {
        if (destination == null)
        {
            UnityDebugger.Debugger.LogError("MoveGasTo -- Destination can not be null");
            return;
        }

        if (amount < 0 || float.IsNaN(amount))
        {
            UnityDebugger.Debugger.LogError("MoveGasTo -- Amount can not be negative: " + amount);
            return;
        }

        amount = Mathf.Min(this.TotalGas, amount);

        float thermalDelta = amount * this.GetTemperature();

        this.ThermalEnergy        -= thermalDelta;
        destination.ThermalEnergy += thermalDelta;

        foreach (var gasName in this.GetGasNames())
        {
            float partialAmount = amount * GetGasFraction(gasName);
            this.ChangeGas(gasName, -partialAmount);
            destination.ChangeGas(gasName, partialAmount);
        }
    }
示例#3
0
 public Room()
 {
     tiles         = new List <Tile>();
     Atmosphere    = new AtmosphereComponent();
     deltaGas      = new Dictionary <string, string>();
     RoomBehaviors = new Dictionary <string, RoomBehavior>();
 }
示例#4
0
    public static void MovePercentageOfAtmosphere(AtmosphereComponent source, AtmosphereComponent destination, float ratio)
    {
        if (ratio < 0 || ratio > 1)
        {
            UnityDebugger.Debugger.Log("MovePercentageOfAtmosphere -- Ratio is out of bounds: " + ratio);
        }

        source.MoveGasTo(destination, ratio * source.TotalGas);
    }
示例#5
0
        public Room()
        {
            tiles         = new HashSet <Tile>();
            boundaryTiles = new HashSet <Tile>();
            Atmosphere    = new AtmosphereComponent();

            // deltaGas = new Dictionary<string, string>();
            RoomBehaviors = new Dictionary <string, RoomBehavior>();
        }
示例#6
0
    public void Setup()
    {
        empty1 = new AtmosphereComponent();

        notEmpty1 = new AtmosphereComponent();
        notEmpty2 = new AtmosphereComponent();
        notEmpty1.CreateGas("gas", 1.0f, 1.0f);
        notEmpty2.CreateGas("gas", 2.0f, 2.0f);
    }
    public void MoveGasTo(AtmosphereComponent destination, string gasName, float amount)
    {
        if (amount < 0)
        {
            UnityDebugger.Debugger.LogError("MoveGasTo -- Amount can not be negative: " + amount);
            return;
        }

        amount = Mathf.Min(this.GetGasAmount(gasName), amount);
        this.ChangeGas(gasName, -amount);
        destination.ChangeGas(gasName, amount);

        float thermalDelta = amount * internalTemperature.InKelvin;

        this.ThermalEnergy        -= thermalDelta;
        destination.ThermalEnergy += thermalDelta;
    }
    /// <summary>
    /// Moves gas to another atmosphere. Temperature is transferred accordingly.
    /// </summary>
    /// <param name="destination">Destination of the gas.</param>
    /// <param name="amount">Amount of gas to move.</param>
    public void MoveGasTo(AtmosphereComponent destination, float amount)
    {
        if (destination == null)
        {
            UnityDebugger.Debugger.LogError("MoveGasTo -- Destination can not be null");
            return;
        }

        if (amount < 0 || float.IsNaN(amount))
        {
            UnityDebugger.Debugger.LogError("MoveGasTo -- Amount can not be negative: " + amount);
            return;
        }

        amount = Mathf.Min(this.TotalGas, amount);

        string[] gasNames = this.GetGasNames();

        // HACK: tracking the amount to transfer with an array and a separate loop is likely
        // innefficient, it may instead be better to adjust amount appropriately by the amount
        // removed. In our standard rooms gas ratio should remain 20% O2, 80% N2
        float[] partialAmounts = new float[gasNames.Length];
        for (int i = 0; i < gasNames.Length; i++)
        {
            partialAmounts[i] = amount * GetGasFraction(gasNames[i]);
        }

        for (int i = 0; i < gasNames.Length; i++)
        {
            this.ChangeGas(gasNames[i], -partialAmounts[i]);
            destination.ChangeGas(gasNames[i], partialAmounts[i]);
        }

        float thermalDelta = amount * internalTemperature.InKelvin;

        this.ThermalEnergy        -= thermalDelta;
        destination.ThermalEnergy += thermalDelta;
    }