Beispiel #1
0
        public override bool Simulate()
        {
            int   num     = base.SubsystemElectricity.CircuitStep - m_lastChangeCircuitStep;
            float voltage = (CalculateHighInputsCount() > 0) ? 1 : 0;

            if (ElectricElement.IsSignalHigh(voltage) != ElectricElement.IsSignalHigh(m_voltage))
            {
                m_lastChangeCircuitStep = base.SubsystemElectricity.CircuitStep;
            }
            m_voltage = voltage;
            if (!ElectricElement.IsSignalHigh(m_voltage))
            {
                m_needsReset = false;
            }
            if (!m_needsReset)
            {
                if (num >= 10)
                {
                    if (ElectricElement.IsSignalHigh(m_voltage))
                    {
                        CellFace cellFace = base.CellFaces[0];
                        int      data     = Terrain.ExtractData(base.SubsystemElectricity.SubsystemTerrain.Terrain.GetCellValue(cellFace.X, cellFace.Y, cellFace.Z));
                        base.SubsystemElectricity.Project.FindSubsystem <SubsystemFenceGateBlockBehavior>(throwOnError: true).OpenCloseGate(cellFace.X, cellFace.Y, cellFace.Z, !FenceGateBlock.GetOpen(data));
                    }
                }
                else
                {
                    base.SubsystemElectricity.QueueElectricElementForSimulation(this, base.SubsystemElectricity.CircuitStep + 10 - num);
                }
            }
            return(false);
        }
        public override bool Simulate()
        {
            float voltage  = m_voltage;
            int   num      = 0;
            int   rotation = base.Rotation;

            foreach (ElectricConnection connection in base.Connections)
            {
                if (connection.ConnectorType != ElectricConnectorType.Output && connection.NeighborConnectorType != 0)
                {
                    ElectricConnectorDirection?connectorDirection = SubsystemElectricity.GetConnectorDirection(base.CellFaces[0].Face, rotation, connection.ConnectorFace);
                    if (connectorDirection.HasValue)
                    {
                        if (connectorDirection == ElectricConnectorDirection.Top)
                        {
                            if (ElectricElement.IsSignalHigh(connection.NeighborElectricElement.GetOutputVoltage(connection.NeighborConnectorFace)))
                            {
                                num |= 1;
                            }
                        }
                        else if (connectorDirection == ElectricConnectorDirection.Right)
                        {
                            if (ElectricElement.IsSignalHigh(connection.NeighborElectricElement.GetOutputVoltage(connection.NeighborConnectorFace)))
                            {
                                num |= 2;
                            }
                        }
                        else if (connectorDirection == ElectricConnectorDirection.Bottom)
                        {
                            if (ElectricElement.IsSignalHigh(connection.NeighborElectricElement.GetOutputVoltage(connection.NeighborConnectorFace)))
                            {
                                num |= 4;
                            }
                        }
                        else if (connectorDirection == ElectricConnectorDirection.Left && ElectricElement.IsSignalHigh(connection.NeighborElectricElement.GetOutputVoltage(connection.NeighborConnectorFace)))
                        {
                            num |= 8;
                        }
                    }
                }
            }
            TruthTableData blockData = m_subsystemTruthTableCircuitBlockBehavior.GetBlockData(base.CellFaces[0].Point);

            m_voltage = ((blockData != null) ? ((float)(int)blockData.Data[num] / 15f) : 0f);
            return(m_voltage != voltage);
        }
Beispiel #3
0
        public override bool Simulate()
        {
            int   num     = base.SubsystemElectricity.CircuitStep - m_lastChangeCircuitStep;
            float voltage = (CalculateHighInputsCount() > 0) ? 1 : 0;

            if (ElectricElement.IsSignalHigh(voltage) != ElectricElement.IsSignalHigh(m_voltage))
            {
                m_lastChangeCircuitStep = base.SubsystemElectricity.CircuitStep;
            }
            m_voltage = voltage;
            if (num >= 10)
            {
                CellFace cellFace  = base.CellFaces[0];
                int      cellValue = base.SubsystemElectricity.SubsystemTerrain.Terrain.GetCellValue(cellFace.X, cellFace.Y, cellFace.Z);
                int      data      = ChristmasTreeBlock.SetLightState(Terrain.ExtractData(cellValue), ElectricElement.IsSignalHigh(m_voltage));
                int      value     = Terrain.ReplaceData(cellValue, data);
                base.SubsystemElectricity.SubsystemTerrain.ChangeCell(cellFace.X, cellFace.Y, cellFace.Z, value);
            }
            else
            {
                base.SubsystemElectricity.QueueElectricElementForSimulation(this, base.SubsystemElectricity.CircuitStep + 10 - num);
            }
            return(false);
        }
        public override bool Simulate()
        {
            float voltage  = m_voltage;
            bool  flag     = false;
            bool  flag2    = false;
            bool  flag3    = false;
            bool  flag4    = false;
            int   rotation = base.Rotation;

            foreach (ElectricConnection connection in base.Connections)
            {
                if (connection.ConnectorType != ElectricConnectorType.Output && connection.NeighborConnectorType != 0)
                {
                    ElectricConnectorDirection?connectorDirection = SubsystemElectricity.GetConnectorDirection(base.CellFaces[0].Face, rotation, connection.ConnectorFace);
                    if (connectorDirection.HasValue)
                    {
                        if (connectorDirection == ElectricConnectorDirection.Right)
                        {
                            flag2 = ElectricElement.IsSignalHigh(connection.NeighborElectricElement.GetOutputVoltage(connection.NeighborConnectorFace));
                        }
                        else if (connectorDirection == ElectricConnectorDirection.Left)
                        {
                            flag = ElectricElement.IsSignalHigh(connection.NeighborElectricElement.GetOutputVoltage(connection.NeighborConnectorFace));
                        }
                        else if (connectorDirection == ElectricConnectorDirection.Bottom)
                        {
                            flag3 = ElectricElement.IsSignalHigh(connection.NeighborElectricElement.GetOutputVoltage(connection.NeighborConnectorFace));
                            flag4 = true;
                        }
                    }
                }
            }
            if (flag4)
            {
                if (flag3 && m_clockAllowed)
                {
                    m_clockAllowed = false;
                    if (flag && flag2)
                    {
                        m_voltage = ((!ElectricElement.IsSignalHigh(m_voltage)) ? 1 : 0);
                    }
                    else if (flag)
                    {
                        m_voltage = 1f;
                    }
                    else if (flag2)
                    {
                        m_voltage = 0f;
                    }
                }
            }
            else if (flag && m_setAllowed)
            {
                m_setAllowed = false;
                m_voltage    = 1f;
            }
            else if (flag2 && m_resetAllowed)
            {
                m_resetAllowed = false;
                m_voltage      = 0f;
            }
            if (!flag3)
            {
                m_clockAllowed = true;
            }
            if (!flag)
            {
                m_setAllowed = true;
            }
            if (!flag2)
            {
                m_resetAllowed = true;
            }
            if (m_voltage != voltage)
            {
                base.SubsystemElectricity.WritePersistentVoltage(base.CellFaces[0].Point, m_voltage);
                return(true);
            }
            return(false);
        }