Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
CounterElectricElement.cs
浏览该文件的文档.
1namespace Game {
3 public bool m_plusAllowed = true;
4
5 public bool m_minusAllowed = true;
6
7 public bool m_resetAllowed = true;
8
9 public int m_counter;
10
11 public bool m_overflow;
12
13 public CounterElectricElement(SubsystemElectricity subsystemElectricity, CellFace cellFace) : base(subsystemElectricity, cellFace) {
14 float? num = subsystemElectricity.ReadPersistentVoltage(cellFace.Point);
15 if (num.HasValue) {
16 m_counter = (int)MathF.Round(MathF.Abs(num.Value) * 15f);
17 m_overflow = num.Value < 0f;
18 }
19 }
20
21 public override float GetOutputVoltage(int face) {
23 if (connectorDirection.HasValue) {
24 if (connectorDirection.Value == ElectricConnectorDirection.Top) {
25 return m_counter / 15f;
26 }
27 if (connectorDirection.Value == ElectricConnectorDirection.Bottom) {
28 return m_overflow ? 1 : 0;
29 }
30 }
31 return 0f;
32 }
33
34 public override bool Simulate() {
35 int counter = m_counter;
36 bool overflow = m_overflow;
37 bool flag = false;
38 bool flag2 = false;
39 bool flag3 = false;
40 int rotation = Rotation;
41 foreach (ElectricConnection connection in Connections) {
42 if (connection.ConnectorType != ElectricConnectorType.Output
43 && connection.NeighborConnectorType != 0) {
45 CellFaces[0].Face,
46 rotation,
47 connection.ConnectorFace
48 );
49 if (connectorDirection.HasValue) {
50 if (connectorDirection == ElectricConnectorDirection.Right) {
52 }
53 else if (connectorDirection == ElectricConnectorDirection.Left) {
55 }
56 else if (connectorDirection == ElectricConnectorDirection.In) {
58 }
59 }
60 }
61 }
62 if (flag && m_plusAllowed) {
63 m_plusAllowed = false;
64 if (m_counter < 15) {
65 m_counter++;
66 m_overflow = false;
67 }
68 else {
69 m_counter = 0;
70 m_overflow = true;
71 }
72 }
73 else if (flag2 && m_minusAllowed) {
74 m_minusAllowed = false;
75 if (m_counter > 0) {
76 m_counter--;
77 m_overflow = false;
78 }
79 else {
80 m_counter = 15;
81 m_overflow = true;
82 }
83 }
84 else if (flag3 && m_resetAllowed) {
85 m_counter = 0;
86 m_overflow = false;
87 }
88 if (!flag) {
89 m_plusAllowed = true;
90 }
91 if (!flag2) {
92 m_minusAllowed = true;
93 }
94 if (!flag3) {
95 m_resetAllowed = true;
96 }
97 if (m_counter != counter
98 || m_overflow != overflow) {
100 return true;
101 }
102 return false;
103 }
104 }
105}
override float GetOutputVoltage(int face)
CounterElectricElement(SubsystemElectricity subsystemElectricity, CellFace cellFace)
ElectricConnectorType ConnectorType
ElectricConnectorType NeighborConnectorType
static bool IsSignalHigh(float voltage)
virtual float GetOutputVoltage(int face)
List< ElectricConnection > Connections
ReadOnlyList< CellFace > CellFaces
RotateableElectricElement(SubsystemElectricity subsystemElectricity, CellFace cellFace)
static ? ElectricConnectorDirection GetConnectorDirection(int mountingFace, int rotation, int connectorFace)
void WritePersistentVoltage(Point3 point, float voltage)