Skip to content
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
47 changes: 47 additions & 0 deletions caravan.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ specified, then the commands apply to all caravans on the map.
annoying merchants, etc.). Also causes caravans to return to the depot if
applicable.
- ``leave [IDS]``: makes caravans pack up and leave immediately.
- ``unload``: fixes endless unloading at the depot. Run this if merchant pack
animals were startled and now refuse to come to the trade depot.

]====]

Expand Down Expand Up @@ -95,6 +97,51 @@ function commands.leave(...)
end
end

local function isDisconnectedPackAnimal(unit)
if unit.following then
local dragger = unit.following
return (
unit.relationship_ids[ df.unit_relationship_type.Dragger ] == -1 and
dragger.relationship_ids[ df.unit_relationship_type.Draggee ] == -1
)
end
end

local function getPrintableUnitName(unit)
local visible_name = dfhack.units.getVisibleName(unit)
local profession_name = dfhack.units.getProfessionName(unit)
if visible_name.has_name then
return ('%s (%s)'):format(dfhack.TranslateName(visible_name), profession_name)
end
return profession_name -- for unnamed animals
end

local function rejoin_pack_animals()
print('Reconnecting disconnected pack animals...')
local found = false
for _, unit in pairs(df.global.world.units.active) do
if unit.flags1.merchant and isDisconnectedPackAnimal(unit) then
local dragger = unit.following
print((' %s <-> %s'):format(
dfhack.df2console(getPrintableUnitName(unit)),
dfhack.df2console(getPrintableUnitName(dragger))
))
unit.relationship_ids[ df.unit_relationship_type.Dragger ] = dragger.id
dragger.relationship_ids[ df.unit_relationship_type.Draggee ] = unit.id
found = true
end
end
if (found) then
print('All pack animals reconnected.')
else
print('No disconnected pack animals found.')
end
end

function commands.unload(...)
rejoin_pack_animals()
end

function commands.help()
print(dfhack.script_help())
end
Expand Down
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ that repo.

## Misc Improvements
- `build-now`: buildings that were just designated with `buildingplan` are now handled properly instead of being skipped (as long as there are items available to build the buildings with)
- `caravan`: new ``unload`` command, fixes endless unloading at the depot, by reconnecting merchant pack animals that were disconnected from their owners.
- `deteriorate`: new ``now`` command immediately deteriorates all items of the specified types.
- `list-agreements`: now displays translated Guild Names, worshiped Deity, age of petition, and "man" to race-specific professions (e.g. "Craftsman" -> "Craftsdwarf")
- `workorder`: doesn't check for an assigned manager anymore.
Expand Down