diff --git a/changelog.txt b/changelog.txt index 01d32e09d4..0c0ad99f10 100644 --- a/changelog.txt +++ b/changelog.txt @@ -45,6 +45,7 @@ Template for new versions: ## Misc Improvements - `devel/lsmem`: added support for filtering by memory addresses and filenames +- `quickfort`: linked stockpiles and workshops can now be specified by ID instead of only by name. this is mostly useful when dynamically generating blueprints and applying them via the `quickfort` API - `suspendmanager`: display a different color for jobs suspended by suspendmanager ## Removed diff --git a/internal/quickfort/build.lua b/internal/quickfort/build.lua index 53f50b105c..750c6f050b 100644 --- a/internal/quickfort/build.lua +++ b/internal/quickfort/build.lua @@ -313,10 +313,13 @@ local function do_trackstop_adjust(db_entry, bld) local from_names = {} for _,from_name in ipairs(db_entry.route.from_names) do from_names[from_name:lower()] = true + if tonumber(from_name) then + from_names[tonumber(from_name)] = true + end end for _, pile in ipairs(df.global.world.buildings.other.STOCKPILE) do local name = string.lower(pile.name) - if from_names[name] then + if from_names[name] or from_names[pile.id] then stop.stockpiles:insert('#', { new=df.route_stockpile_link, building_id=pile.id, @@ -1146,8 +1149,12 @@ local function create_building(b, cache, dry_run) utils.insert_sorted(bld.profile.links.give_to_pile, to, 'id') utils.insert_sorted(to.links.take_from_workshop, bld, 'id') end + elseif cache.piles[tonumber(recipient)] then + local to = cache.piles[tonumber(recipient)] + utils.insert_sorted(bld.profile.links.give_to_pile, to, 'id') + utils.insert_sorted(to.links.take_from_workshop, bld, 'id') else - dfhack.printerr(('cannot find stockpile named "%s" to give to'):format(recipient)) + dfhack.printerr(('cannot find stockpile with name or id "%s" to give to'):format(recipient)) end end for _,supplier in ipairs(db_entry.links.take_from) do @@ -1157,8 +1164,12 @@ local function create_building(b, cache, dry_run) utils.insert_sorted(bld.profile.links.take_from_pile, from, 'id') utils.insert_sorted(from.links.give_to_workshop, bld, 'id') end + elseif cache.piles[tonumber(supplier)] then + local from = cache.piles[tonumber(supplier)] + utils.insert_sorted(bld.profile.links.take_from_pile, from, 'id') + utils.insert_sorted(from.links.give_to_workshop, bld, 'id') else - dfhack.printerr(('cannot find stockpile named "%s" to take from'):format(supplier)) + dfhack.printerr(('cannot find stockpile with name or id "%s" to take from'):format(supplier)) end end if buildingplan and buildingplan.isEnabled() and diff --git a/internal/quickfort/place.lua b/internal/quickfort/place.lua index 4da103a016..66eccda46c 100644 --- a/internal/quickfort/place.lua +++ b/internal/quickfort/place.lua @@ -347,6 +347,7 @@ function get_stockpiles_by_name() if #pile.name > 0 then table.insert(ensure_key(piles, pile.name), pile) end + piles[pile.id] = pile end return piles end @@ -357,6 +358,7 @@ local function get_workshops_by_name() if #shop.name > 0 then table.insert(ensure_key(shops, shop.name), shop) end + shops[shop.id] = shop end return shops end @@ -364,12 +366,12 @@ end local function get_pile_targets(name, peer_piles, all_piles) if peer_piles[name] then return peer_piles[name], all_piles end all_piles = all_piles or get_stockpiles_by_name() - return all_piles[name], all_piles + return all_piles[name] or (all_piles[tonumber(name)] and {all_piles[tonumber(name)]}), all_piles end local function get_shop_targets(name, all_shops) all_shops = all_shops or get_workshops_by_name() - return all_shops[name], all_shops + return all_shops[name] or (all_shops[tonumber(name)] and {all_shops[tonumber(name)]}), all_shops end -- will link to stockpiles created in this blueprint @@ -394,7 +396,7 @@ local function link_stockpiles(link_data) utils.insert_sorted(node.to.links.take_from_workshop, from, 'id') end else - dfhack.printerr(('cannot find stockpile or workshop named "%s" to take from'):format(name)) + dfhack.printerr(('cannot find stockpile or workshop with name or id "%s" to take from'):format(name)) end end elseif type(node.to) == 'string' then @@ -413,7 +415,7 @@ local function link_stockpiles(link_data) utils.insert_sorted(to.profile.links.take_from_pile, node.from, 'id') end else - dfhack.printerr(('cannot find stockpile or workshop named "%s" to give to'):format(name)) + dfhack.printerr(('cannot find stockpile or workshop with name or id "%s" to give to'):format(name)) end end end