Ejemplo n.º 1
0
        /// <summary>
        /// Applied before SpawnBreath runs.
        /// </summary>
        internal static bool Prefix(Vector3 position, float mass, float temperature)
        {
            var offsets = OxygenBreather.DEFAULT_BREATHABLE_OFFSETS;
            int gameCell = Grid.PosToCell(position), count = offsets.Length, spawnCell = -1;

            for (int i = 0; i < count; i++)
            {
                int testCell = Grid.OffsetCell(gameCell, offsets[i]);
                if (Grid.IsValidCell(testCell))
                {
                    var element = Grid.Element[testCell];
                    // Prioritize oxygen, polluted oxygen, salty oxygen (!), CO2
                    if (element.id == SimHashes.CarbonDioxide || element.HasTag(GameTags.
                                                                                Breathable))
                    {
                        spawnCell = testCell;
                        break;
                    }
                    else if (element.IsGas)
                    {
                        // Only in gases, not in vacuums, liquids, or solids
                        spawnCell = testCell;
                    }
                }
            }
            if (spawnCell >= 0)
            {
                SimMessages.ModifyMass(spawnCell, mass, byte.MaxValue, 0, CellEventLogger.
                                       Instance.CO2ManagerFixedUpdate, temperature, SimHashes.CarbonDioxide);
            }
            return(false);
        }
Ejemplo n.º 2
0
        public void Sim200ms(float dt)
        {
            GameObject     storedObject = this.storage.FindFirst(elementTag);
            PrimaryElement component    = null;
            float          stored       = 0f;

            if (storedObject != null)
            {
                component = storedObject.GetComponent <PrimaryElement>();
                stored    = component.Mass;
            }

            if (stored > 0f && dispenser != null)
            {
                if (!dispenser.IsConnected)
                {
                    Element element     = component.Element;
                    float   temperature = component.Temperature;
                    int     disease     = component.DiseaseCount;

                    int outputCell = dispenser.UtilityCell;

                    if (element.IsGas)
                    {
                        Console.WriteLine("Outputing " + stored.ToString() + " of " + elementHash.CreateTag() + " at " + outputCell.ToString());
                        SimMessages.ModifyMass(outputCell, stored, 255, disease, CellEventLogger.Instance.EnergyGeneratorModifyMass, temperature, elementHash);
                    }
                    else if (element.IsLiquid)
                    {
                        int elementIndex = ElementLoader.GetElementIndex(elementHash);
                        FallingWater.instance.AddParticle(outputCell, (byte)elementIndex, stored, temperature, 255, disease, true, false, false, false);
                    }
                    else
                    {
                        element.substance.SpawnResource(Grid.CellToPosCCC(outputCell, Grid.SceneLayer.Front), stored, temperature, 255, disease, true, false, false);
                    }
                    storage.ConsumeIgnoringDisease(storedObject);
                    stored = 0f;
                }
            }
            bool overfilled = stored >= capacity;

            this.operational.SetFlag(outputFlag, !overfilled);
        }
        private void Emit(EnergyGenerator.OutputItem output, float dt, PrimaryElement root_pe)
        {
            Element element = ElementLoader.FindElementByHash(output.element);
            float   num     = output.creationRate * dt;

            if (output.store)
            {
                if (element.IsGas)
                {
                    this.storage.AddGasChunk(output.element, num, root_pe.Temperature, 255, 0, true, true);
                }
                else if (element.IsLiquid)
                {
                    this.storage.AddLiquid(output.element, num, root_pe.Temperature, 255, 0, true, true);
                }
                else
                {
                    GameObject go = element.substance.SpawnResource(base.transform.GetPosition(), num, root_pe.Temperature, 255, 0, false, false, false);
                    this.storage.Store(go, true, false, true, false);
                }
            }
            else
            {
                int   cell        = Grid.PosToCell(base.transform.GetPosition());
                int   num2        = Grid.OffsetCell(cell, output.emitOffset);
                float temperature = Mathf.Max(root_pe.Temperature, output.minTemperature);
                if (element.IsGas)
                {
                    SimMessages.ModifyMass(num2, num, 255, 0, CellEventLogger.Instance.EnergyGeneratorModifyMass, temperature, output.element);
                }
                else if (element.IsLiquid)
                {
                    int elementIndex = ElementLoader.GetElementIndex(output.element);
                    FallingWater.instance.AddParticle(num2, (byte)elementIndex, num, temperature, 255, 0, true, false, false, false);
                }
                else
                {
                    element.substance.SpawnResource(Grid.CellToPosCCC(num2, Grid.SceneLayer.Front), num, temperature, 255, 0, true, false, false);
                }
            }
        }
Ejemplo n.º 4
0
    public void Sim33ms(float dt)
    {
        Vector2I xy     = default(Vector2I);
        Vector2I xy2    = default(Vector2I);
        Vector3  vector = acceleration * dt;
        int      num    = co2Items.Count;

        for (int i = 0; i < num; i++)
        {
            CO2 cO = co2Items[i];
            cO.velocity          += vector;
            cO.lifetimeRemaining -= dt;
            Grid.PosToXY(cO.transform.GetPosition(), out xy);
            cO.transform.SetPosition(cO.transform.GetPosition() + cO.velocity * dt);
            Grid.PosToXY(cO.transform.GetPosition(), out xy2);
            int num2 = Grid.XYToCell(xy.x, xy.y);
            int num3 = num2;
            for (int num4 = xy.y; num4 >= xy2.y; num4--)
            {
                int  num5 = Grid.XYToCell(xy.x, num4);
                bool flag = !Grid.IsValidCell(num5) || cO.lifetimeRemaining <= 0f;
                if (!flag)
                {
                    Element element = Grid.Element[num5];
                    flag = (element.IsLiquid || element.IsSolid);
                }
                if (flag)
                {
                    bool flag2 = false;
                    int  num6;
                    if (num3 != num5)
                    {
                        num6  = num3;
                        flag2 = true;
                    }
                    else
                    {
                        num6 = num5;
                        while (Grid.IsValidCell(num6))
                        {
                            Element element2 = Grid.Element[num6];
                            if (!element2.IsLiquid && !element2.IsSolid)
                            {
                                flag2 = true;
                                break;
                            }
                            num6 = Grid.CellAbove(num6);
                        }
                    }
                    cO.TriggerDestroy();
                    if (flag2)
                    {
                        SimMessages.ModifyMass(num6, cO.mass, byte.MaxValue, 0, CellEventLogger.Instance.CO2ManagerFixedUpdate, cO.temperature, SimHashes.CarbonDioxide);
                        num--;
                        co2Items[i] = co2Items[num];
                        co2Items.RemoveAt(num);
                    }
                    else
                    {
                        DebugUtil.LogWarningArgs("Couldn't emit CO2");
                    }
                    break;
                }
                num3 = num5;
            }
        }
    }
Ejemplo n.º 5
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;
            }
        }
    }