Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
MemoryBankElectricElement.cs
浏览该文件的文档.
1namespace Game {
4
5 public float m_voltage;
6
7 public bool m_writeAllowed;
8
9 public bool m_clockAllowed;
10
11 public MemoryBankElectricElement(SubsystemElectricity subsystemElectricity, CellFace cellFace) : base(subsystemElectricity, cellFace) {
13 MemoryBankData blockData = m_subsystemMemoryBankBlockBehavior.GetBlockData(cellFace.Point);
14 if (blockData != null) {
15 m_voltage = blockData.LastOutput / 15f;
16 }
17 }
18
19 public override float GetOutputVoltage(int face) => m_voltage;
20
21 public override bool Simulate() {
22 float voltage = m_voltage;
23 bool flag = false;
24 bool flag2 = false;
25 bool flag3 = false;
26 float num = 0f;
27 int num2 = 0;
28 int num3 = 0;
29 int rotation = Rotation;
30 foreach (ElectricConnection connection in Connections) {
31 if (connection.ConnectorType != ElectricConnectorType.Output
32 && connection.NeighborConnectorType != 0) {
34 CellFaces[0].Face,
35 rotation,
36 connection.ConnectorFace
37 );
38 if (connectorDirection.HasValue) {
39 if (connectorDirection == ElectricConnectorDirection.Right) {
40 num2 = (int)MathF.Round(connection.NeighborElectricElement.GetOutputVoltage(connection.NeighborConnectorFace) * 15f);
41 }
42 else if (connectorDirection == ElectricConnectorDirection.Left) {
43 num3 = (int)MathF.Round(connection.NeighborElectricElement.GetOutputVoltage(connection.NeighborConnectorFace) * 15f);
44 }
45 else if (connectorDirection == ElectricConnectorDirection.Bottom) {
46 int num4 = (int)MathF.Round(connection.NeighborElectricElement.GetOutputVoltage(connection.NeighborConnectorFace) * 15f);
47 flag = num4 >= 8;
48 flag3 = num4 > 0 && num4 < 8;
49 flag2 = true;
50 }
51 else if (connectorDirection == ElectricConnectorDirection.In) {
53 }
54 }
55 }
56 }
57 MemoryBankData memoryBankData = m_subsystemMemoryBankBlockBehavior.GetBlockData(CellFaces[0].Point);
58 int address = num2 + (num3 << 4);
59 if (flag2) {
60 if (flag && m_clockAllowed) {
61 m_clockAllowed = false;
62 m_voltage = memoryBankData != null ? memoryBankData.Read(address) / 15f : 0f;
63 }
64 else if (flag3 && m_writeAllowed) {
65 m_writeAllowed = false;
66 if (memoryBankData == null) {
67 memoryBankData = new MemoryBankData();
68 m_subsystemMemoryBankBlockBehavior.SetBlockData(CellFaces[0].Point, memoryBankData);
69 }
70 memoryBankData.Write(address, (byte)MathF.Round(num * 15f));
71 }
72 }
73 else {
74 m_voltage = memoryBankData != null ? memoryBankData.Read(address) / 15f : 0f;
75 }
76 if (!flag) {
77 m_clockAllowed = true;
78 }
79 if (!flag3) {
80 m_writeAllowed = true;
81 }
82 if (memoryBankData != null) {
83 memoryBankData.LastOutput = (byte)MathF.Round(m_voltage * 15f);
84 }
85 return m_voltage != voltage;
86 }
87 }
88}
ElectricConnectorType ConnectorType
ElectricConnectorType NeighborConnectorType
virtual float GetOutputVoltage(int face)
List< ElectricConnection > Connections
ReadOnlyList< CellFace > CellFaces
void Write(int address, byte data)
SubsystemMemoryBankBlockBehavior m_subsystemMemoryBankBlockBehavior
MemoryBankElectricElement(SubsystemElectricity subsystemElectricity, CellFace cellFace)
RotateableElectricElement(SubsystemElectricity subsystemElectricity, CellFace cellFace)
static ? ElectricConnectorDirection GetConnectorDirection(int mountingFace, int rotation, int connectorFace)
virtual Subsystem FindSubsystem(Type type, string name, bool throwOnError)