Skip to content

Commit

Permalink
support setting the civalert burrow from quickfort
Browse files Browse the repository at this point in the history
  • Loading branch information
myk002 committed Nov 3, 2023
1 parent e0dd34d commit 25db4b6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
15 changes: 15 additions & 0 deletions gui/civ-alert.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ local function clear_alarm()
df.global.plotinfo.alerts.civ_alert_idx = 0
end

function set_civalert_burrow_if_unset(burrow)
local burrows = get_civ_alert().burrows
if #burrows == 0 then
burrows:insert('#', burrow.id)
end
end

function unset_civalert_burrow_if_set(burrow)
local burrows = get_civ_alert().burrows
if #burrows > 0 and burrows[0] == burrow.id then
burrows:resize(0)
clear_alarm()
end
end

local function toggle_civalert_burrow(id)
local burrows = get_civ_alert().burrows
if #burrows == 0 then
Expand Down
12 changes: 12 additions & 0 deletions internal/quickfort/burrow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ if not dfhack_flags.module then
qerror('this script cannot be called directly')
end

local civalert = reqscript('gui/civ-alert')
local quickfort_common = reqscript('internal/quickfort/common')
local quickfort_map = reqscript('internal/quickfort/map')
local quickfort_parse = reqscript('internal/quickfort/parse')
Expand Down Expand Up @@ -32,6 +33,10 @@ local function custom_burrow(_, keys)
db_entry.create = true
props.create = nil
end
if db_entry.add and props.civalert == 'true' then
db_entry.civalert = true
props.civalert = nil
end

for k,v in pairs(props) do
dfhack.printerr(('unhandled property for symbol "%s": "%s"="%s"'):format(
Expand Down Expand Up @@ -76,6 +81,13 @@ local function do_burrow(ctx, db_entry, pos)
dfhack.burrows.setAssignedTile(b, pos, db_entry.add)
stats['burrow_tiles_'..(db_entry.add and 'added' or 'removed')].value =
stats['burrow_tiles_'..(db_entry.add and 'added' or 'removed')].value + 1
if db_entry.civalert then
if db_entry.add then
civalert.set_civalert_burrow_if_unset(b)
else
civalert.unset_civalert_burrow_if_set(b)
end
end
if not db_entry.add and db_entry.create and #dfhack.burrows.listBlocks(b) == 0 then
dfhack.burrows.clearTiles(b)
local _, _, idx = utils.binsearch(burrows.list, b.id, 'id')
Expand Down

0 comments on commit 25db4b6

Please sign in to comment.