Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[====[
- bugtest
- =====
- utilities for testing the Hauling items bug(s)
- Usage:
- Usage:
- IF UNIT SELECTED in Dwarf Fortress:
- :bugtest:
- dump whatever relevant inventory/hauling/job info I can collect for that unit
- OTHERWISE:
- :bugtest:
- among all active units, find those with Hauled items; add these units to burrow
- 'test'
- print counts for valid and bugged-looking items
- :bugtest -many:
- similar to previous, but only add units with *multiple* Hauled items in inventory
- to the 'test' burrow
- :bugtest -followup:
- consider only the units already in the 'test' burrow. print which ones still look
- bugged and which ones do not
- remove the un-bugged ones from 'test' burrow
- :bugtest -labors:
- for all units in 'test' burrow enable HAUL_STONE labor (this is to facilitate testing
- how readily they switch to some other available job activities)
- :bugtest -tscript:
- generate a simple filter script for Dwarf Therapist, that will show units in
- 'test' burrow
- :bugtest -dumpall
- data dump for all units in 'test' burrow
- ]====]
- local utils = require('utils')
- local validArgs = utils.invert({
- "help",
- "followup",
- "many",
- "labors",
- "tscript",
- "dumpall"
- })
- local utils = require 'utils'
- local args = utils.processArgs({...}, validArgs)
- if args.help then
- print(dfhack.script_help())
- return
- end
- local function enum2str(value, enumt)
- for index, val in ipairs(enumt) do
- if index == value then
- return val
- end
- end
- return "enum not found"
- end
- local function bitfield2str(bf)
- local retval = "{"
- local is1st = true
- for a, b in pairs(bf) do
- if b then
- if not is1st then
- retval = retval .. ","
- end
- is1st = false
- retval = retval .. a
- end
- end
- return retval .. "}"
- end
- local function unit_name(unit)
- return dfhack.df2console(dfhack.TranslateName(dfhack.units.getVisibleName(unit)))
- end
- local function dump_unit_data(unit)
- print(string.format("unit name: %s current_job: %s, unit.actions: %d", unit_name(unit), unit.job.current_job, #unit.actions))
- if unit.job.current_job then
- dfhack.job.printJobDetails(unit.job.current_job)
- end
- for i,a in ipairs(unit.actions) do
- local a_str = string.format("unit action [%d] type: %d (%s) id: %d raw_data: ", i, a.type, enum2str(a.type, df.unit_action_type), a.id)
- for _,v in ipairs(a.data.raw_data) do
- a_str = a_str .. " " .. v
- end
- print(a_str)
- end
- for k, inv_item in pairs(unit.inventory) do
- local item = inv_item.item
- print("inventory item [" .. k .. "]", "mode: ", inv_item.mode .. "(" .. enum2str(inv_item.mode, df.unit_inventory_item.T_mode) ..
- ")", "description:", dfhack.df2console( dfhack.items.getDescription(item, 0, true)) )
- print("item flags: ", bitfield2str(item.flags), "flags2: ", bitfield2str(item.flags2))
- end
- end
- print(string.format("year %d tick %d (day %d; day's ticks %d)", df.global.cur_year, df.global.cur_year_tick, df.global.cur_year_tick // 1200,
- (df.global.cur_year_tick) % 1200))
- unit = dfhack.gui.getSelectedUnit()
- if unit then
- dump_unit_data(unit)
- return
- end
- local b_test = dfhack.burrows.findByName("test")
- if not b_test then
- qerror('test burrow not found')
- end
- if args.followup then
- local bugged_found = 0
- local nonbugged_found = 0
- local test_units_n = #b_test.units
- local unbugged_units = ""
- for _,unit in ipairs(df.global.world.units.active) do
- if dfhack.burrows.isAssignedUnit(b_test,unit) then
- if dfhack.units.isCitizen(unit) and dfhack.units.isAdult(unit) then
- local hauled_count = 0
- local hauled_no_injob = 0
- for k, inv_item in pairs(unit.inventory) do
- local item = inv_item.item
- if inv_item.mode == df.unit_inventory_item.T_mode.Hauled then
- hauled_count = hauled_count + 1
- if not item.flags.in_job then
- hauled_no_injob = hauled_no_injob + 1
- end
- end
- end
- if hauled_no_injob > 0 then
- print(string.format("%s got bugged; hauled : %02d ; bugged(?): %02d", unit_name(unit),
- hauled_count, hauled_no_injob))
- if unit.job.current_job then
- dfhack.job.printJobDetails(unit.job.current_job)
- else
- print(string.format("job = nil, %d actions, %d individual_drills, %d social_activities, %d conversations, %d activities", #unit.actions,
- #unit.military.individual_drills, #unit.social_activities, #unit.conversations, #unit.activities))
- end
- bugged_found = bugged_found + 1;
- else
- nonbugged_found = nonbugged_found + 1;
- dfhack.burrows.setAssignedUnit(b_test,unit,false)
- unbugged_units = unbugged_units .. "unbugged: " .. unit_name(unit) .. "\n"
- end
- end
- end
- end
- print(string.format("test burrow had %d; found %d bugged, %d nonbugged. test burrow now has %d", test_units_n, bugged_found, nonbugged_found,
- #b_test.units))
- if (unbugged_units ~= "") then
- print(unbugged_units)
- end
- else
- dfhack.burrows.clearUnits(b_test)
- for _,unit in ipairs(df.global.world.units.active) do
- if dfhack.units.isCitizen(unit) and dfhack.units.isAdult(unit) then
- local hauled_count = 0
- local hauled_no_injob = 0
- for k, inv_item in pairs(unit.inventory) do
- local item = inv_item.item
- if inv_item.mode == df.unit_inventory_item.T_mode.Hauled then
- hauled_count = hauled_count + 1
- if not item.flags.in_job then
- hauled_no_injob = hauled_no_injob + 1
- end
- end
- end
- if hauled_count > 0 and not (args.many and hauled_count == 1) then
- print(string.format("%s hauled : %02d ; bugged(?): %02d", unit_name(unit),
- hauled_count, hauled_no_injob))
- dfhack.burrows.setAssignedUnit(b_test,unit,true)
- end
- end
- end
- end
- if (args.labors) then
- print(string.format("setting HAUL_STONE for units in 'test' burrow (%d units)", #b_test.units))
- local labors_changed = 0
- local labors_nonchanged = 0
- for _,unit in ipairs(df.global.world.units.active) do
- if dfhack.burrows.isAssignedUnit(b_test,unit) then
- local labors = unit.status.labors
- if labors.HAUL_STONE then
- labors_nonchanged = labors_nonchanged + 1
- else
- labors.HAUL_STONE = true
- labors_changed = labors_changed + 1
- end
- end
- end
- print(string.format("labor changed for %d, non changed for %d", labors_changed, labors_nonchanged))
- print("disabling HAUL_STONE for other units")
- for _,unit in ipairs(df.global.world.units.active) do
- if dfhack.units.isCitizen(unit) and dfhack.units.isAdult(unit) and not dfhack.burrows.isAssignedUnit(b_test,unit) then
- local labors = unit.status.labors
- labors.HAUL_STONE = false
- end
- end
- end
- if (args.tscript) then
- local is_first = true
- print("Dwarf Therapist script for units in 'test' burrow:")
- for _,unit in ipairs(df.global.world.units.active) do
- if dfhack.burrows.isAssignedUnit(b_test,unit) then
- local s = 'd.name_matches("' .. dfhack.TranslateName(dfhack.units.getVisibleName(unit)) .. '")'
- if not is_first then
- s = ' || ' .. s
- end
- is_first = false
- print(s)
- end
- end
- end
- if (args.dumpall) then
- print("data dump for all units in 'test' burrow:")
- for _,unit in ipairs(df.global.world.units.active) do
- if dfhack.burrows.isAssignedUnit(b_test,unit) then
- dump_unit_data(unit)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement