1
- -- Reset item temperature to the value of their tile.
2
- --[====[
3
-
4
- fix/stable-temp
5
- ===============
6
- Instantly sets the temperature of all free-lying items to be in equilibrium with
7
- the environment, which stops temperature updates until something changes.
8
- To maintain this efficient state, use `tweak fast-heat <tweak>`.
9
-
10
- ]====]
11
- local args = {... }
1
+ local args = { ... }
12
2
13
3
local apply = (args [1 ] == ' apply' )
14
4
15
5
local count = 0
16
6
local types = {} -- as:number[]
17
7
18
- local function update_temp (item ,btemp )
19
- local item = item -- as:df.item_actual
8
+ local function update_temp (item , btemp )
20
9
if item .temperature .whole ~= btemp then
21
10
count = count + 1
22
11
local tid = item :getType ()
@@ -28,46 +17,49 @@ local function update_temp(item,btemp)
28
17
item .temperature .fraction = 0
29
18
30
19
if item .contaminants then
31
- for _ ,c in ipairs (item .contaminants ) do
32
- c .temperature .whole = btemp
33
- c .temperature .fraction = 0
20
+ for _ , c in ipairs (item .contaminants ) do
21
+ c .base . temperature .whole = btemp
22
+ c .base . temperature .fraction = 0
34
23
end
35
24
end
36
25
end
37
26
38
- for _ ,sub in ipairs (dfhack .items .getContainedItems (item )) do -- as:df.item_actual
39
- update_temp (sub ,btemp )
27
+ for _ , sub in ipairs (dfhack .items .getContainedItems (item )) do -- as:df.item_actual
28
+ update_temp (sub , btemp )
40
29
end
41
30
42
31
if apply then
43
32
item :checkTemperatureDamage ()
44
33
end
45
34
end
46
35
47
- local last_frame = df .global .world .frame_counter - 1
36
+ local last_frame = df .global .world .frame_counter - 1
48
37
49
- for _ ,item in ipairs (df .global .world .items .other .IN_PLAY ) do
50
- local item = item -- as:df.item_actual
51
- if item .flags .on_ground and df .item_actual :is_instance (item ) and
52
- item .temp_updated_frame == last_frame then
53
- local pos = item .pos
54
- local block = dfhack .maps .getTileBlock (pos )
55
- if block then
56
- update_temp (item , block .temperature_1 [pos .x % 16 ][pos .y % 16 ])
57
- end
38
+ for _ , item in ipairs (df .global .world .items .other .IN_PLAY ) do
39
+ if not item .flags .on_ground or
40
+ not df .item_actual :is_instance (item ) or
41
+ item .temp_updated_frame ~= last_frame
42
+ then
43
+ goto continue
44
+ end
45
+ local pos = item .pos
46
+ local block = dfhack .maps .getTileBlock (pos )
47
+ if block then
48
+ update_temp (item , block .temperature_1 [pos .x % 16 ][pos .y % 16 ])
58
49
end
50
+ :: continue::
59
51
end
60
52
61
53
if apply then
62
- print (' Items updated: ' .. count )
54
+ print (' Items updated: ' .. count )
63
55
else
64
- print (" Use 'fix/stable-temp apply' to force-change temperature." )
65
- print (' Items not in equilibrium: ' .. count )
56
+ print (" Use 'fix/stable-temp apply' to normalize temperature." )
57
+ print (' Items not in equilibrium: ' .. count )
66
58
end
67
59
68
60
local tlist = {}
69
- for k ,_ in pairs (types ) do tlist [# tlist + 1 ] = k end
70
- table.sort (tlist , function (a ,b ) return types [a ] > types [b ] end )
71
- for _ ,k in ipairs (tlist ) do
72
- print (' ' .. df .item_type [k ].. ' :' , types [k ])
61
+ for k , _ in pairs (types ) do tlist [# tlist + 1 ] = k end
62
+ table.sort (tlist , function (a , b ) return types [a ] > types [b ] end )
63
+ for _ , k in ipairs (tlist ) do
64
+ print (' ' .. df .item_type [k ] .. ' :' , types [k ])
73
65
end
0 commit comments