-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_heat.lua
More file actions
233 lines (223 loc) · 5.99 KB
/
node_heat.lua
File metadata and controls
233 lines (223 loc) · 5.99 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
local function check_has_air(pos)
-- check if near air...
local pos1 = vector.subtract(pos, {
x = 2,
y = 1,
z = 2
})
local pos2 = vector.add(pos, {
x = 2,
y = 2,
z = 2
})
local near_air = core.find_nodes_in_area(pos1, pos2, {"air", "ctg_airs:atmos_warm"})
if #near_air >= 1 then
local nair = 0
for _, n in pairs(near_air) do
local d = vector.distance(pos, n)
if d < 1.65 then
nair = nair + 1
end
end
return nair
end
return 0
end
local function check_has_air_hot(pos)
-- check if near hot air...
local pos1 = vector.subtract(pos, {
x = 2,
y = 2,
z = 2
})
local pos2 = vector.add(pos, {
x = 2,
y = 2,
z = 2
})
local near_air = core.find_nodes_in_area(pos1, pos2, {"ctg_airs:atmos_hot", "ctg_airs:atmos_warm"})
if #near_air >= 1 then
local nair = 0
for _, n in pairs(near_air) do
local d = vector.distance(pos, n)
if d < 1.95 then
nair = nair + 1
end
end
return nair
end
return 0
end
local function check_has_vac(pos)
-- check if near vacuum...
local pos1 = vector.subtract(pos, {
x = 2,
y = 1,
z = 2
})
local pos2 = vector.add(pos, {
x = 2,
y = 2,
z = 2
})
local near_air = core.find_nodes_in_area(pos1, pos2, {"vacuum:vacuum", "vacuum:atmos_thin"})
if #near_air >= 1 then
local nair = 0
for _, n in pairs(near_air) do
local d = vector.distance(pos, n)
if d < 1.95 then
nair = nair + 1
end
end
return nair
end
return 0
end
-- heat nearby air
local function do_near_heat(pos, stren)
stren = stren or 0
testcoin.fill_atmos_hot(pos, 1 + stren)
end
-- handle temperature effects and changes
local function handle_temp(pos, min, max, vac, air)
local meta = core.get_meta(pos)
local temp = meta:get_int("temp")
if temp == nil then
meta:set_int("temp", 20)
end
if meta:get_int("temp_over") == nil then
meta:set_int("temp_over", 0)
end
if meta:get_int("temp_over_tick") == nil then
meta:set_int("temp_over_tick", 0)
end
local bias = 0
-- temp over nominal
if temp > 30 then
bias = -1
end
-- temp below nominal
if temp < 10 then
bias = 2
elseif temp < 20 then
bias = 1
end
-- vacuum is cold
if vac > 1 then
bias = bias - vac
end
-- if not near too much cold, check for heat...
if vac < 2 or air < 7 then
local has_heat = check_has_air_hot(pos)
if has_heat > 4 then
bias = bias + 3
elseif has_heat > 2 then
bias = bias + 2
elseif has_heat > 0 then
bias = bias + math.random(0, 1)
end
end
-- if near air, bias cooling
if air > 4 then
bias = bias - math.random(0, 3)
if temp > 60 then
min = min - 2
elseif temp > 21 then
min = min - 1
end
if temp > 27 then
max = max - 1
end
end
-- near air and temp is cool
if air > 5 and temp < 25 then
bias = bias + 2
elseif air > 1 and temp < 20 then
bias = bias + 1
end
-- bias cooling when kinda hot...
if temp > 75 then
bias = bias - math.random(1, 3)
end
-- apply new temperature with bias + range
local new_temp = temp + bias + math.random(min, max)
-- temperature min
if new_temp < 0 then
new_temp = -1
end
-- temperature max
if new_temp > 100 then
new_temp = 100
end
meta:set_int("temp", new_temp)
return new_temp
end
-- apply heat from miner work
local function apply_miner_heat(pos, miner, has_vac, has_air)
local temp = miner.temp
local mt = miner.miners.total
local heat = 2
if miner.miners.pow_miner > 0 then
heat = heat + (miner.miners.pow_miner * 0.34)
end
if miner.miners.asic_miner > 0 then
heat = heat + (miner.miners.asic_miner * 0.67)
end
if mt > 3 then
temp = handle_temp(pos, 1, heat, has_vac, has_air)
if temp > 90 then
do_near_heat(pos, 5)
elseif temp > 80 then
do_near_heat(pos, 4)
elseif temp > 70 then
do_near_heat(pos, 3)
else
do_near_heat(pos, 2)
end
elseif mt > 0 then
temp = handle_temp(pos, 0, heat, has_vac, has_air)
if temp > 64 then
do_near_heat(pos, 4)
elseif temp > 55 then
do_near_heat(pos, 3)
else
do_near_heat(pos, 2)
end
end
end
-- apply heat based on input temp and parameters
local function apply_temp_heat(pos, temp, has_air, has_vac)
if has_air > 1 then
local r = 1
if has_air > 2 then
r = math.random(0, 1)
end
if temp > 88 and has_air > 3 then
temp = handle_temp(pos, -5, 1, has_vac, has_air)
elseif temp > 80 and has_air > 2 then
temp = handle_temp(pos, -3, 1, has_vac, has_air)
elseif temp > 50 then
temp = handle_temp(pos, -2, r, has_vac, has_air)
else
temp = handle_temp(pos, -1, r, has_vac, has_air)
end
else
temp = handle_temp(pos, 0, 2, has_vac, has_air)
end
if has_vac > 1 then
temp = handle_temp(pos, -10, -(math.max(7, has_vac)), has_vac, has_air)
end
return temp
end
-------------------------------------------------------
-------------------------------------------------------
-- Export
local node_heat = {}
node_heat.check_has_air = check_has_air
node_heat.check_has_air_hot = check_has_air_hot
node_heat.check_has_vac = check_has_vac
node_heat.do_near_heat = do_near_heat
node_heat.handle_temp = handle_temp
node_heat.apply_miner_heat = apply_miner_heat
node_heat.apply_temp_heat = apply_temp_heat
return node_heat