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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Ic2ExpReactorPlanner.components;
import java.util.ArrayList;
import java.util.List;
import gregtech.api.objects.GT_ItemStack;
/**
* Represents a heat exchanger of some sort in a reactor.
* @author Brian McCloud
*/
public class Exchanger extends ReactorItem {
private final int switchSide;
private final int switchReactor;
public Exchanger(final int id, final String baseName, GT_ItemStack aItem, final double maxDamage, final double maxHeat, final String sourceMod, final int switchSide, final int switchReactor) {
super(id, baseName, aItem, maxDamage, maxHeat, sourceMod);
this.switchSide = switchSide;
this.switchReactor = switchReactor;
}
public Exchanger(final Exchanger other) {
super(other);
this.switchSide = other.switchSide;
this.switchReactor = other.switchReactor;
}
@Override
public void transfer() {
List<ReactorItem> heatableNeighbors = new ArrayList<>(4);
ReactorItem component = parent.getComponentAt(row, col - 1);
if (component != null && component.isHeatAcceptor()) {
heatableNeighbors.add(component);
}
component = parent.getComponentAt(row, col + 1);
if (component != null && component.isHeatAcceptor()) {
heatableNeighbors.add(component);
}
component = parent.getComponentAt(row - 1, col);
if (component != null && component.isHeatAcceptor()) {
heatableNeighbors.add(component);
}
component = parent.getComponentAt(row + 1, col);
if (component != null && component.isHeatAcceptor()) {
heatableNeighbors.add(component);
}
// Code adapted from decompiled IC2 code, class ItemReactorHeatSwitch, with permission from Thunderdark.
double myHeat = 0;
if (switchSide > 0) {
for (ReactorItem heatableNeighbor : heatableNeighbors) {
double mymed = getCurrentHeat() * 100.0 / getMaxHeat();
double heatablemed = heatableNeighbor.getCurrentHeat() * 100.0 / heatableNeighbor.getMaxHeat();
double add = (int) (heatableNeighbor.getMaxHeat() / 100.0 * (heatablemed + mymed / 2.0));
if (add > switchSide) {
add = switchSide;
}
if (heatablemed + mymed / 2.0 < 1.0) {
add = switchSide / 2;
}
if (heatablemed + mymed / 2.0 < 0.75) {
add = switchSide / 4;
}
if (heatablemed + mymed / 2.0 < 0.5) {
add = switchSide / 8;
}
if (heatablemed + mymed / 2.0 < 0.25) {
add = 1;
}
if (Math.round(heatablemed * 10.0) / 10.0 > Math.round(mymed * 10.0) / 10.0) {
add -= 2 * add;
} else if (Math.round(heatablemed * 10.0) / 10.0 == Math.round(mymed * 10.0) / 10.0) {
add = 0;
}
myHeat -= add;
if (add > 0) {
currentComponentHeating += add;
}
add = heatableNeighbor.adjustCurrentHeat(add);
myHeat += add;
}
}
if (switchReactor > 0) {
double mymed = getCurrentHeat() * 100.0 / getMaxHeat();
double Reactormed = parent.getCurrentHeat() * 100.0 / parent.getMaxHeat();
int add = (int) Math.round(parent.getMaxHeat() / 100.0 * (Reactormed + mymed / 2.0));
if (add > switchReactor) {
add = switchReactor;
}
if (Reactormed + mymed / 2.0 < 1.0) {
add = switchSide / 2;
}
if (Reactormed + mymed / 2.0 < 0.75) {
add = switchSide / 4;
}
if (Reactormed + mymed / 2.0 < 0.5) {
add = switchSide / 8;
}
if (Reactormed + mymed / 2.0 < 0.25) {
add = 1;
}
if (Math.round(Reactormed * 10.0) / 10.0 > Math.round(mymed * 10.0) / 10.0) {
add -= 2 * add;
} else if (Math.round(Reactormed * 10.0) / 10.0 == Math.round(mymed * 10.0) / 10.0) {
add = 0;
}
myHeat -= add;
parent.adjustCurrentHeat(add);
if (add > 0) {
currentHullHeating = add;
} else {
currentHullCooling = -add;
}
}
adjustCurrentHeat(myHeat);
}
@Override
public double getHullCoolingCapacity() {
return switchReactor;
}
}
|