Esempio n. 1
0
    // Token: 0x06002338 RID: 9016 RVA: 0x000AE5F8 File Offset: 0x000AC7F8
    private PeltierCooler.MonitorState MonitorHeating(float dt)
    {
        //Debug.Log(" !!! Monitoring heat ");

        if (Grid.Mass[this.inputCell] <= this.minCellMass ||
            Grid.Mass[this.outputCell] <= this.minCellMass)
        {
            return(PeltierCooler.MonitorState.NotEnoughMass);
        }

        if (Grid.Temperature[this.inputCell] <= this.minInputTemperature)
        {
            return(PeltierCooler.MonitorState.TooCold);
        }

        // XXX: SimMessages.ModifyEnergy() gets close to max_temperature but it's never reached.
        if (Grid.Temperature[this.outputCell] >= this.maxOutputTemperature - 10)
        {
            return(PeltierCooler.MonitorState.TooHot);
        }

        float kjTransferred = this.kjTransferRate * dt;

        SimMessages.ModifyEnergy(this.inputCell, -kjTransferred, 5000f, SimMessages.EnergySourceID.StructureTemperature);
        SimMessages.ModifyEnergy(this.outputCell, kjTransferred, this.maxOutputTemperature, SimMessages.EnergySourceID.StructureTemperature);

        return(PeltierCooler.MonitorState.ReadyToHeat);
    }
 public override void InitializeStates(out BaseState default_state)
 {
     default_state = idle;
     idle.PlayAnim("grounded", KAnim.PlayMode.Loop).EventTransition(GameHashes.IgniteEngine, burning, null);
     burning.EventTransition(GameHashes.LandRocket, burnComplete, null).PlayAnim("launch_pre").QueueAnim("launch_loop", true, null)
     .Update(delegate(StatesInstance smi, float dt)
     {
         Vector3 pos = smi.master.gameObject.transform.GetPosition() + smi.master.GetComponent <KBatchedAnimController>().Offset;
         int num     = Grid.PosToCell(pos);
         if (Grid.IsValidCell(num))
         {
             SimMessages.EmitMass(num, (byte)ElementLoader.GetElementIndex(smi.master.exhaustElement), dt * smi.master.exhaustEmitRate, smi.master.exhaustTemperature, 0, 0, -1);
         }
         int num2 = 10;
         for (int i = 1; i < num2; i++)
         {
             int num3 = Grid.OffsetCell(num, -1, -i);
             int num4 = Grid.OffsetCell(num, 0, -i);
             int num5 = Grid.OffsetCell(num, 1, -i);
             if (Grid.IsValidCell(num3))
             {
                 SimMessages.ModifyEnergy(num3, smi.master.exhaustTemperature / (float)(i + 1), 3200f, SimMessages.EnergySourceID.Burner);
             }
             if (Grid.IsValidCell(num4))
             {
                 SimMessages.ModifyEnergy(num4, smi.master.exhaustTemperature / (float)i, 3200f, SimMessages.EnergySourceID.Burner);
             }
             if (Grid.IsValidCell(num5))
             {
                 SimMessages.ModifyEnergy(num5, smi.master.exhaustTemperature / (float)(i + 1), 3200f, SimMessages.EnergySourceID.Burner);
             }
         }
     }, UpdateRate.SIM_200ms, false);
     burnComplete.PlayAnim("grounded", KAnim.PlayMode.Loop).EventTransition(GameHashes.IgniteEngine, burning, null);
 }
Esempio n. 3
0
        public void Sim200ms(float dt)
        {
            operational.SetActive(operational.IsOperational);

            if (operational.IsActive)
            {
                if (anim.currentAnim != "on")
                {
                    anim.Play("on", KAnim.PlayMode.Paused);
                }

                float coldTemp = Grid.Temperature[coldCell];
                float hotTemp  = Grid.Temperature[hotCell];

                float dTemp = Mathf.Clamp(hotTemp - coldTemp, 0f, maxTempDiff);

                float heatMoved = maxHeatMovedkDTU - (heatMovedPerDegree * dTemp);
                heatMoved = Mathf.Clamp(heatMoved, 0, maxHeatMovedkDTU);

                float heatInColdCell = (coldTemp * Grid.Mass[coldCell] * Grid.Element[coldCell].specificHeatCapacity);
                if (heatMoved > heatInColdCell)
                {
                    heatMoved = heatInColdCell - 1;
                }

                if (heatMoved > 0)
                {
                    isMovingHeat = true;
                    float heatProduced = heatMoved + wasteHeatkDTU;
                    SimMessages.ModifyEnergy(coldCell, -heatMoved * 1000f, 5000f, SimMessages.EnergySourceID.StructureTemperature);
                    SimMessages.ModifyEnergy(hotCell, heatProduced * 1000f, 5000f, SimMessages.EnergySourceID.StructureTemperature);
                }
                else
                {
                    isMovingHeat = false;
                }
            }
            else
            {
                isMovingHeat = false;

                if (anim.currentAnim != "off")
                {
                    anim.Play("off");
                }
            }
        }
    public void Sim200ms(float dt)
    {
        float    num      = kjConsumptionRate * dt;
        Vector2I vector2I = maxCheckOffset - minCheckOffset + 1;
        int      num2     = vector2I.x * vector2I.y;
        float    num3     = num / (float)num2;

        Grid.PosToXY(base.transform.GetPosition(), out int x, out int y);
        for (int i = minCheckOffset.y; i <= maxCheckOffset.y; i++)
        {
            for (int j = minCheckOffset.x; j <= maxCheckOffset.x; j++)
            {
                int num4 = Grid.XYToCell(x + j, y + i);
                if (Grid.IsValidCell(num4) && Grid.Temperature[num4] > minTemperature)
                {
                    kjConsumed += num3;
                    SimMessages.ModifyEnergy(num4, 0f - num3, 5000f, SimMessages.EnergySourceID.HeatBulb);
                }
            }
        }
        float num5 = lightKJConsumptionRate * dt;

        if (kjConsumed > num5)
        {
            if (!lightSource.enabled)
            {
                kanim.Play("open", KAnim.PlayMode.Once, 1f, 0f);
                kanim.Queue("on", KAnim.PlayMode.Once, 1f, 0f);
                lightSource.enabled = true;
            }
            kjConsumed -= num5;
        }
        else
        {
            if (lightSource.enabled)
            {
                kanim.Play("close", KAnim.PlayMode.Once, 1f, 0f);
                kanim.Queue("off", KAnim.PlayMode.Once, 1f, 0f);
            }
            lightSource.enabled = false;
        }
    }
Esempio n. 5
0
            private static void AbsorbHeat(StatesInstance smi, float dt)
            {
                float    num1     = smi.master._kjConsumptionRate * dt;
                Vector2I vector2I = smi.master._maxCheckOffset - smi.master._minCheckOffset + 1;
                int      num2     = vector2I.x * vector2I.y;
                float    num3     = num1 / num2;

                Grid.PosToXY(smi.master.transform.position, out var x1, out var y1);
                for (int y2 = smi.master._minCheckOffset.y; y2 <= smi.master._maxCheckOffset.y; ++y2)
                {
                    for (int x2 = smi.master._minCheckOffset.x; x2 <= smi.master._maxCheckOffset.x; ++x2)
                    {
                        int cell = Grid.XYToCell(x1 + x2, y1 + y2);
                        if (Grid.IsValidCell(cell) && Grid.Temperature[cell] > (double)smi.master._minTemperature)
                        {
                            smi.master._kjConsumed += num3;
                            SimMessages.ModifyEnergy(cell, -num3, 3000f, SimMessages.EnergySourceID.HeatBulb);
                        }
                    }
                }
            }
Esempio n. 6
0
        private void PumpHeat(float dt)
        {
#if CONSUME_ALL_HEAT
            float workHeat = heatToPumpDTU;
#else
            float workHeat = heatToPumpDTU * currentEfficiency;
#endif

#if PRODUCE_LEFTOVER_HEAT
            currentGeneratedHeat = Mathf.Clamp(heatToPumpDTU - workHeat, 0, heatToPumpDTU);
#elif PRODUCE_CONSTANT_HEAT
            currentGeneratedHeat = 0f;
#elif PRODUCE_PROPORTIONAL_HEAT
            currentGeneratedHeat = workHeat * wasteHeatRatio;
#else
            currentGeneratedHeat = 1f;
#endif

            currentGeneratedPower = Mathf.Clamp(HeatToWatts(workHeat), 0, heatToPumpDTU);

            SimMessages.ModifyEnergy(heatSourceCell, -(heatToPumpDTU * dt / 1000f), 5000f, SimMessages.EnergySourceID.StructureTemperature);
        }
Esempio n. 7
0
            private static void AbsorbHeat(StatesInstance smi, float dt)
            {
                var consumedSinceLastUpdate = smi.master._kjConsumptionRate * dt;

                var vector2I = smi.master._maxCheckOffset - smi.master._minCheckOffset + 1;

                var affectedCells      = vector2I.x * vector2I.y;
                var consumptionPerCell = consumedSinceLastUpdate / affectedCells;

                Grid.PosToXY(smi.master.transform.position, out var x1, out var y1);

                for (var y2 = smi.master._minCheckOffset.y; y2 <= smi.master._maxCheckOffset.y; ++y2)
                {
                    for (var x2 = smi.master._minCheckOffset.x; x2 <= smi.master._maxCheckOffset.x; ++x2)
                    {
                        var cell = Grid.XYToCell(x1 + x2, y1 + y2);
                        if (Grid.IsValidCell(cell) && Grid.Temperature[cell] > smi.master._minTemperature)
                        {
                            smi.master._kjConsumed += consumptionPerCell;
                            SimMessages.ModifyEnergy(cell, -consumptionPerCell, 3000f, SimMessages.EnergySourceID.HeatBulb);
                        }
                    }
                }
            }
Esempio n. 8
0
    protected override void OnDragTool(int cell, int distFromOrigin)
    {
        if (Grid.IsValidCell(cell))
        {
            switch (type)
            {
            case Type.PaintPlant:
                break;

            case Type.Dig:
                SimMessages.Dig(cell, -1);
                break;

            case Type.Heat:
                SimMessages.ModifyEnergy(cell, 10000f, 10000f, SimMessages.EnergySourceID.DebugHeat);
                break;

            case Type.Cool:
                SimMessages.ModifyEnergy(cell, -10000f, 10000f, SimMessages.EnergySourceID.DebugCool);
                break;

            case Type.AddPressure:
                SimMessages.ModifyMass(cell, 10000f, byte.MaxValue, 0, CellEventLogger.Instance.DebugToolModifyMass, 293f, SimHashes.Oxygen);
                break;

            case Type.RemovePressure:
                SimMessages.ModifyMass(cell, -10000f, byte.MaxValue, 0, CellEventLogger.Instance.DebugToolModifyMass, 0f, SimHashes.Oxygen);
                break;

            case Type.ReplaceSubstance:
                DoReplaceSubstance(cell);
                break;

            case Type.FillReplaceSubstance:
            {
                GameUtil.FloodFillNext.Clear();
                GameUtil.FloodFillVisited.Clear();
                SimHashes elem_hash = Grid.Element[cell].id;
                GameUtil.FloodFillConditional(cell, delegate(int check_cell)
                    {
                        bool result = false;
                        if (Grid.Element[check_cell].id == elem_hash)
                        {
                            result = true;
                            DoReplaceSubstance(check_cell);
                        }
                        return(result);
                    }, GameUtil.FloodFillVisited, null);
                break;
            }

            case Type.Clear:
                ClearCell(cell);
                break;

            case Type.AddSelection:
                DebugBaseTemplateButton.Instance.AddToSelection(cell);
                break;

            case Type.RemoveSelection:
                DebugBaseTemplateButton.Instance.RemoveFromSelection(cell);
                break;

            case Type.Destroy:
                DestroyCell(cell);
                break;

            case Type.Deconstruct:
                DeconstructCell(cell);
                break;

            case Type.Sample:
                DebugPaintElementScreen.Instance.SampleCell(cell);
                break;
            }
        }
    }
Esempio n. 9
0
        /// <summary>
        /// Updates an active building's exhaust and self-heat.
        /// </summary>
        /// <param name="payload">The building being updated.</param>
        /// <param name="dt">The time since the last update in seconds.</param>
        /// <param name="energyCategory">The status item category for heat emission.</param>
        /// <param name="operatingEnergy">The status item to display when emitting heat.</param>
        /// <returns></returns>
        private static bool UpdateActive(ref StructureTemperaturePayload payload, float dt,
                                         StatusItemCategory energyCategory, StatusItem operatingEnergy)
        {
            bool        dirty        = false;
            const float MAX_PRESSURE = StructureTemperatureComponents.MAX_PRESSURE;
            var         operational  = payload.operational;

            if (operational == null || operational.IsActive)
            {
                float exhaust = payload.ExhaustKilowatts;
                if (!payload.isActiveStatusItemSet)
                {
                    // Turn on the "active" status item
                    if (payload.primaryElement.TryGetComponent(out KSelectable selectable))
                    {
                        selectable.SetStatusItem(energyCategory, operatingEnergy,
                                                 payload.simHandleCopy);
                    }
                    payload.isActiveStatusItemSet = true;
                }
                AccumulateProducedEnergy(ref payload.energySourcesKW, payload.
                                         OperatingKilowatts, STRINGS.BUILDING.STATUSITEMS.OPERATINGENERGY.
                                         OPERATING);
                if (exhaust != 0.0f)
                {
                    var   extents = payload.GetExtents();
                    int   h = extents.height, w = extents.width;
                    float kjPerM2 = exhaust * dt / (w * h);
                    int   gw = Grid.WidthInCells, cell = extents.y * gw + extents.x;
                    // Going up one row is +grid width -building width from the last cell of
                    // the previous row
                    gw -= w;
                    for (int y = h; y > 0; y--)
                    {
                        for (int x = w; x > 0; x--)
                        {
                            float mass = Grid.Mass[cell];
                            // Avoid emitting into Vacuum
                            if (mass > 0.0f)
                            {
                                SimMessages.ModifyEnergy(cell, kjPerM2 * Mathf.Min(mass,
                                                                                   MAX_PRESSURE) / MAX_PRESSURE, payload.maxTemperature,
                                                         SimMessages.EnergySourceID.StructureTemperature);
                            }
                            cell++;
                        }
                        cell += gw;
                    }
                    AccumulateProducedEnergy(ref payload.energySourcesKW, exhaust, STRINGS.
                                             BUILDING.STATUSITEMS.OPERATINGENERGY.EXHAUSTING);
                }
                dirty = true;
            }
            else if (payload.isActiveStatusItemSet)
            {
                // Turn off the "active" status item
                if (payload.primaryElement.TryGetComponent(out KSelectable selectable))
                {
                    selectable.SetStatusItem(energyCategory, null, null);
                }
                payload.isActiveStatusItemSet = false;
                dirty = true;
            }
            return(dirty);
        }