2012-06-13 00:54:28 -06:00
|
|
|
-- Reset item temperature to the value of their tile.
|
2015-10-23 08:37:39 -06:00
|
|
|
--[[=begin
|
2012-06-13 00:54:28 -06:00
|
|
|
|
2015-10-23 08:37:39 -06:00
|
|
|
fix/stable-temp
|
|
|
|
===============
|
|
|
|
Instantly sets the temperature of all free-lying items to be in equilibrium with
|
2015-10-28 19:44:49 -06:00
|
|
|
the environment, which stops temperature updates until something changes.
|
|
|
|
To maintain this efficient state, use `tweak fast-heat <tweak>`.
|
2015-10-23 08:37:39 -06:00
|
|
|
|
|
|
|
=end]]
|
2012-09-14 02:14:36 -06:00
|
|
|
local args = {...}
|
|
|
|
|
|
|
|
local apply = (args[1] == 'apply')
|
|
|
|
|
2012-06-13 00:54:28 -06:00
|
|
|
local count = 0
|
|
|
|
local types = {}
|
|
|
|
|
|
|
|
local function update_temp(item,btemp)
|
2012-11-12 10:54:21 -07:00
|
|
|
if item.temperature.whole ~= btemp then
|
2012-06-13 00:54:28 -06:00
|
|
|
count = count + 1
|
|
|
|
local tid = item:getType()
|
|
|
|
types[tid] = (types[tid] or 0) + 1
|
|
|
|
end
|
|
|
|
|
2012-09-14 02:14:36 -06:00
|
|
|
if apply then
|
2012-11-12 10:54:21 -07:00
|
|
|
item.temperature.whole = btemp
|
|
|
|
item.temperature.fraction = 0
|
2012-09-14 02:14:36 -06:00
|
|
|
|
|
|
|
if item.contaminants then
|
|
|
|
for _,c in ipairs(item.contaminants) do
|
2012-11-12 10:54:21 -07:00
|
|
|
c.temperature.whole = btemp
|
|
|
|
c.temperature.fraction = 0
|
2012-09-14 02:14:36 -06:00
|
|
|
end
|
2012-06-13 00:54:28 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
for _,sub in ipairs(dfhack.items.getContainedItems(item)) do
|
|
|
|
update_temp(sub,btemp)
|
|
|
|
end
|
|
|
|
|
2012-09-14 02:14:36 -06:00
|
|
|
if apply then
|
|
|
|
item:checkTemperatureDamage()
|
|
|
|
end
|
2012-06-13 00:54:28 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
local last_frame = df.global.world.frame_counter-1
|
|
|
|
|
|
|
|
for _,item in ipairs(df.global.world.items.all) do
|
|
|
|
if item.flags.on_ground and df.item_actual:is_instance(item) and
|
|
|
|
item.temp_updated_frame == last_frame then
|
|
|
|
local pos = item.pos
|
|
|
|
local block = dfhack.maps.getTileBlock(pos)
|
|
|
|
if block then
|
|
|
|
update_temp(item, block.temperature_1[pos.x%16][pos.y%16])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-14 02:14:36 -06:00
|
|
|
if apply then
|
|
|
|
print('Items updated: '..count)
|
|
|
|
else
|
2015-10-28 19:44:49 -06:00
|
|
|
print("Use 'fix/stable-temp apply' to force-change temperature.")
|
2012-09-14 02:14:36 -06:00
|
|
|
print('Items not in equilibrium: '..count)
|
|
|
|
end
|
2012-06-13 00:54:28 -06:00
|
|
|
|
|
|
|
local tlist = {}
|
|
|
|
for k,_ in pairs(types) do tlist[#tlist+1] = k end
|
|
|
|
table.sort(tlist, function(a,b) return types[a] > types[b] end)
|
|
|
|
for _,k in ipairs(tlist) do
|
|
|
|
print(' '..df.item_type[k]..':', types[k])
|
|
|
|
end
|