Skip to content

Commit

Permalink
Add fix/stuck-merchants
Browse files Browse the repository at this point in the history
  • Loading branch information
lethosor committed Jun 18, 2017
1 parent 81479bb commit d461a84
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions fix/stuck-merchants.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
-- Dismisses stuck merchants that haven't entered the map yet

help = [====[
fix/stuck-merchants
===================
Dismisses merchants that haven't entered the map yet. This can fix :bug:`9593`.
This script should probably not be run if any merchants are on the map, so using
it with `repeat` is not recommended.
Run ``fix/stuck-merchants -n`` or ``fix/stuck-merchants --dry-run`` to list all
merchants that would be dismissed but make no changes.
]====]


function getEntityName(u)
local civ = df.historical_entity.find(u.civ_id)
if not civ then return 'unknown civ' end
return dfhack.TranslateName(civ.name)
end

function getEntityRace(u)
local civ = df.historical_entity.find(u.civ_id)
if civ then
local craw = df.creature_raw.find(civ.race)
if craw then
return craw.name[0]
end
end
return 'unknown race'
end

function dismissMerchants(args)
local dry_run = false
for _, arg in pairs(args) do
if args[1]:match('-h') or args[1]:match('help') then
print(help)
return
elseif args[1]:match('-n') or args[1]:match('dry') then
dry_run = true
end
end
for _,u in pairs(df.global.world.units.active) do
if u.flags1.merchant and u.flags1.dead then
print(('%s unit %d: %s (%s), civ %d (%s, %s)'):format(
dry_run and 'Would remove' or 'Removing',
u.id,
dfhack.df2console(dfhack.TranslateName(dfhack.units.getVisibleName(u))),
df.creature_raw.find(u.race).name[0],
u.civ_id,
dfhack.df2console(getEntityName(u)),
getEntityRace(u)
))
if not dry_run then
u.flags1.left = true
end
end
end
end

if not dfhack_flags.module then
dismissMerchants{...}
end

0 comments on commit d461a84

Please sign in to comment.