-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathANDSwitch.cs
62 lines (55 loc) · 1.51 KB
/
ANDSwitch.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using UnityEngine;
public class ANDSwitch : IOEntity
{
private int input1Amount;
private int input2Amount;
public override int ConsumptionAmount()
{
return 0;
}
public override bool WantsPower(int inputIndex)
{
if (input1Amount == 0 || input2Amount == 0)
{
return false;
}
if (input1Amount == input2Amount)
{
return inputIndex == 0;
}
int num = ((input1Amount <= input2Amount) ? 1 : 0);
return inputIndex == num;
}
public override int GetPassthroughAmount(int outputSlot = 0)
{
if (input1Amount <= 0 || input2Amount <= 0)
{
return 0;
}
return Mathf.Max(input1Amount, input2Amount);
}
public override void UpdateHasPower(int inputAmount, int inputSlot)
{
SetFlag(Flags.Reserved8, input1Amount > 0 || input2Amount > 0, recursive: false, networkupdate: false);
}
public override void UpdateFromInput(int inputAmount, int slot)
{
switch (slot)
{
case 0:
input1Amount = inputAmount;
break;
case 1:
input2Amount = inputAmount;
break;
}
int num = ((input1Amount > 0 && input2Amount > 0) ? (input1Amount + input2Amount) : 0);
bool b = num > 0;
SetFlag(Flags.Reserved1, input1Amount > 0, recursive: false, networkupdate: false);
SetFlag(Flags.Reserved2, input2Amount > 0, recursive: false, networkupdate: false);
SetFlag(Flags.Reserved3, b, recursive: false, networkupdate: false);
SetFlag(Flags.Reserved4, input1Amount > 0 && input2Amount > 0, recursive: false, networkupdate: false);
SetFlag(Flags.On, num > 0);
base.UpdateFromInput(inputAmount, slot);
}
}