Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[quickfort] allow stockpiles/workshops to be linked by id #807

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 14 additions & 3 deletions internal/quickfort/build.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 6 additions & 4 deletions internal/quickfort/place.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -357,19 +358,20 @@ 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

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
Expand All @@ -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
Expand All @@ -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
Expand Down