2020-08-12 16:12:53 -06:00
|
|
|
local _ENV = mkmodule('plugins.buildingplan')
|
|
|
|
|
2020-08-16 00:03:49 -06:00
|
|
|
--[[
|
|
|
|
|
2023-03-09 22:18:45 -07:00
|
|
|
Public native functions:
|
2020-08-16 00:03:49 -06:00
|
|
|
|
2020-10-16 14:52:23 -06:00
|
|
|
* bool isPlannableBuilding(df::building_type type, int16_t subtype, int32_t custom)
|
2020-11-13 11:18:54 -07:00
|
|
|
* bool isPlannedBuilding(df::building *bld)
|
2020-08-16 00:03:49 -06:00
|
|
|
* void addPlannedBuilding(df::building *bld)
|
|
|
|
* void doCycle()
|
2020-10-16 14:52:23 -06:00
|
|
|
* void scheduleCycle()
|
2020-08-16 00:03:49 -06:00
|
|
|
|
|
|
|
--]]
|
|
|
|
|
2023-01-17 05:05:17 -07:00
|
|
|
local argparse = require('argparse')
|
2023-03-09 22:18:45 -07:00
|
|
|
local inspector = require('plugins.buildingplan.inspectoroverlay')
|
|
|
|
local pens = require('plugins.buildingplan.pens')
|
|
|
|
local planner = require('plugins.buildingplan.planneroverlay')
|
2020-10-16 15:03:05 -06:00
|
|
|
require('dfhack.buildings')
|
|
|
|
|
2023-01-17 05:05:17 -07:00
|
|
|
local function process_args(opts, args)
|
|
|
|
if args[1] == 'help' then
|
|
|
|
opts.help = true
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
return argparse.processArgsGetopt(args, {
|
|
|
|
{'h', 'help', handler=function() opts.help = true end},
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
function parse_commandline(...)
|
|
|
|
local args, opts = {...}, {}
|
|
|
|
local positionals = process_args(opts, args)
|
|
|
|
|
|
|
|
if opts.help then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2023-02-08 19:47:10 -07:00
|
|
|
local command = table.remove(positionals, 1)
|
|
|
|
if not command or command == 'status' then
|
|
|
|
printStatus()
|
2023-03-09 22:18:45 -07:00
|
|
|
elseif command == 'set' and positionals then
|
2023-02-08 19:47:10 -07:00
|
|
|
setSetting(positionals[1], positionals[2] == 'true')
|
2023-03-15 15:02:59 -06:00
|
|
|
elseif command == 'reset' then
|
|
|
|
resetFilters()
|
2023-02-08 19:47:10 -07:00
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2023-01-17 05:05:17 -07:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2023-03-27 03:24:56 -06:00
|
|
|
function is_suspendmanager_enabled()
|
|
|
|
local ok, sm = pcall(reqscript, 'suspendmanager')
|
|
|
|
return ok and sm.isEnabled()
|
|
|
|
end
|
|
|
|
|
2020-10-16 15:08:52 -06:00
|
|
|
function get_num_filters(btype, subtype, custom)
|
2023-02-09 01:13:53 -07:00
|
|
|
local filters = dfhack.buildings.getFiltersByType({}, btype, subtype, custom)
|
|
|
|
return filters and #filters or 0
|
2020-10-16 15:08:52 -06:00
|
|
|
end
|
|
|
|
|
2023-02-15 17:54:38 -07:00
|
|
|
function get_job_item(btype, subtype, custom, index)
|
|
|
|
local filters = dfhack.buildings.getFiltersByType({}, btype, subtype, custom)
|
|
|
|
if not filters or not filters[index] then return nil end
|
|
|
|
local obj = df.job_item:new()
|
|
|
|
obj:assign(filters[index])
|
|
|
|
return obj
|
|
|
|
end
|
|
|
|
|
2023-03-05 20:15:04 -07:00
|
|
|
local function to_title_case(str)
|
|
|
|
str = str:gsub('(%a)([%w_]*)',
|
|
|
|
function (first, rest) return first:upper()..rest:lower() end)
|
|
|
|
str = str:gsub('_', ' ')
|
|
|
|
return str
|
|
|
|
end
|
|
|
|
|
|
|
|
function get_desc(filter)
|
|
|
|
local desc = 'Unknown'
|
|
|
|
if filter.has_tool_use and filter.has_tool_use > -1 then
|
|
|
|
desc = to_title_case(df.tool_uses[filter.has_tool_use])
|
|
|
|
elseif filter.flags2 and filter.flags2.screw then
|
|
|
|
desc = 'Screw'
|
|
|
|
elseif filter.item_type and filter.item_type > -1 then
|
|
|
|
desc = to_title_case(df.item_type[filter.item_type])
|
|
|
|
elseif filter.vector_id and filter.vector_id > -1 then
|
|
|
|
desc = to_title_case(df.job_item_vector_id[filter.vector_id])
|
|
|
|
elseif filter.flags2 and filter.flags2.building_material then
|
|
|
|
if filter.flags2.magma_safe then
|
2023-03-09 22:18:45 -07:00
|
|
|
desc = 'Magma-safe material'
|
|
|
|
elseif filter.flags2.fire_safe then
|
|
|
|
desc = 'Fire-safe material'
|
|
|
|
else
|
|
|
|
desc = 'Building material'
|
2023-03-05 20:15:04 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if desc:endswith('s') then
|
|
|
|
desc = desc:sub(1,-2)
|
|
|
|
end
|
|
|
|
if desc == 'Trappart' then
|
|
|
|
desc = 'Mechanism'
|
|
|
|
elseif desc == 'Wood' then
|
|
|
|
desc = 'Log'
|
|
|
|
end
|
2023-02-09 01:13:53 -07:00
|
|
|
|
2023-03-09 22:18:45 -07:00
|
|
|
return desc
|
2023-02-16 19:02:15 -07:00
|
|
|
end
|
|
|
|
|
2023-03-09 22:18:45 -07:00
|
|
|
function reload_pens()
|
|
|
|
pens.reload_pens()
|
2023-02-26 23:54:15 -07:00
|
|
|
end
|
|
|
|
|
2023-03-09 22:18:45 -07:00
|
|
|
function signal_reset()
|
|
|
|
planner.reset_counts_flag = true
|
|
|
|
inspector.reset_inspector_flag = true
|
2023-02-08 20:26:39 -07:00
|
|
|
end
|
|
|
|
|
2023-03-09 22:18:45 -07:00
|
|
|
-- for use during development to reload all buildingplan modules
|
|
|
|
function reload_modules()
|
|
|
|
reload('plugins.buildingplan.pens')
|
|
|
|
reload('plugins.buildingplan.filterselection')
|
|
|
|
reload('plugins.buildingplan.itemselection')
|
|
|
|
reload('plugins.buildingplan.planneroverlay')
|
|
|
|
reload('plugins.buildingplan.inspectoroverlay')
|
|
|
|
reload('plugins.buildingplan')
|
2023-02-08 20:26:39 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
OVERLAY_WIDGETS = {
|
2023-03-09 22:18:45 -07:00
|
|
|
planner=planner.PlannerOverlay,
|
|
|
|
inspector=inspector.InspectorOverlay,
|
2023-02-08 20:26:39 -07:00
|
|
|
}
|
|
|
|
|
2020-08-12 16:12:53 -06:00
|
|
|
return _ENV
|