Skip to content

Commit d207453

Browse files
committed
adapt to updated structures
1 parent 53a7da7 commit d207453

File tree

2 files changed

+28
-36
lines changed

2 files changed

+28
-36
lines changed

fix/stable-temp.lua

+27-35
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
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 = { ... }
122

133
local apply = (args[1] == 'apply')
144

155
local count = 0
166
local types = {} --as:number[]
177

18-
local function update_temp(item,btemp)
19-
local item = item --as:df.item_actual
8+
local function update_temp(item, btemp)
209
if item.temperature.whole ~= btemp then
2110
count = count + 1
2211
local tid = item:getType()
@@ -28,46 +17,49 @@ local function update_temp(item,btemp)
2817
item.temperature.fraction = 0
2918

3019
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
3423
end
3524
end
3625
end
3726

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)
4029
end
4130

4231
if apply then
4332
item:checkTemperatureDamage()
4433
end
4534
end
4635

47-
local last_frame = df.global.world.frame_counter-1
36+
local last_frame = df.global.world.frame_counter - 1
4837

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])
5849
end
50+
::continue::
5951
end
6052

6153
if apply then
62-
print('Items updated: '..count)
54+
print('Items updated: ' .. count)
6355
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)
6658
end
6759

6860
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])
7365
end

modtools/item-trigger.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ function handler(data)
165165

166166
if data.item.contaminants and #data.item.contaminants > 0 then --hint:df.item_actual
167167
for _, contaminant in ipairs(data.item.contaminants or {}) do --hint:df.item_actual
168-
local contaminantMat = dfhack.matinfo.decode(contaminant.mat_type, contaminant.mat_index)
168+
local contaminantMat = dfhack.matinfo.decode(contaminant.base.mat_type, contaminant.base.mat_index)
169169
data.contaminantMat = contaminantMat
170170
checkForTrigger(data)
171171
data.contaminantMat = nil

0 commit comments

Comments
 (0)