From 6ca5a0300840dfc710ae6ab1dfb35fd78adff1dc Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Wed, 13 Jun 2012 10:54:28 +0400 Subject: [PATCH] Add 3 more lua scripts. --- scripts/devel/nuke-items.lua | 16 ++++++++++++ scripts/fix/dead-units.lua | 29 +++++++++++++++++++++ scripts/fix/stable-temp.lua | 49 ++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 scripts/devel/nuke-items.lua create mode 100644 scripts/fix/dead-units.lua create mode 100644 scripts/fix/stable-temp.lua diff --git a/scripts/devel/nuke-items.lua b/scripts/devel/nuke-items.lua new file mode 100644 index 000000000..aa3f5b840 --- /dev/null +++ b/scripts/devel/nuke-items.lua @@ -0,0 +1,16 @@ +-- Deletes ALL items not held by units, buildings or jobs. +-- +-- Intended solely for lag investigation. + +local count = 0 + +for _,v in ipairs(df.global.world.items.all) do + if not (v.flags.in_building or v.flags.construction or v.flags.in_job + or dfhack.items.getGeneralRef(v,df.general_ref_type.UNIT_HOLDER)) then + count = count + 1 + v.flags.forbid = true + v.flags.garbage_collect = true + end +end + +print('Deletion requested: '..count) diff --git a/scripts/fix/dead-units.lua b/scripts/fix/dead-units.lua new file mode 100644 index 000000000..2d5558179 --- /dev/null +++ b/scripts/fix/dead-units.lua @@ -0,0 +1,29 @@ +-- Remove uninteresting dead units from the unit list. + +local units = df.global.world.units.active +local dwarf_race = df.global.ui.race_id +local dwarf_civ = df.global.ui.civ_id +local count = 0 + +for i=#units-1,0,-1 do + local unit = units[i] + local flags1 = unit.flags1 + local flags2 = unit.flags2 + if flags1.dead and unit.race ~= dwarf_race then + local remove = false + if flags2.slaughter then + remove = true + elseif not unit.name.has_name then + remove = true + elseif unit.civ_id ~= dwarf_civ and + not (flags1.merchant or flags1.diplomat) then + remove = true + end + if remove then + count = count + 1 + units:erase(i) + end + end +end + +print('Units removed from active: '..count) diff --git a/scripts/fix/stable-temp.lua b/scripts/fix/stable-temp.lua new file mode 100644 index 000000000..d06d0fcce --- /dev/null +++ b/scripts/fix/stable-temp.lua @@ -0,0 +1,49 @@ +-- Reset item temperature to the value of their tile. + +local count = 0 +local types = {} + +local function update_temp(item,btemp) + if item.temperature ~= btemp then + count = count + 1 + local tid = item:getType() + types[tid] = (types[tid] or 0) + 1 + end + item.temperature = btemp + item.temperature_fraction = 0 + + if item.contaminants then + for _,c in ipairs(item.contaminants) do + c.temperature = btemp + c.temperature_fraction = 0 + end + end + + for _,sub in ipairs(dfhack.items.getContainedItems(item)) do + update_temp(sub,btemp) + end + + item:checkTemperatureDamage() +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 + +print('Items updated: '..count) + +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