Skip to content

Commit

Permalink
protect against wandering adventurers
Browse files Browse the repository at this point in the history
  • Loading branch information
myk002 committed May 12, 2024
1 parent 228119a commit 83c9941
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions gui/sitemap.lua
@@ -1,4 +1,5 @@
local gui = require('gui')
local utils = require('utils')
local widgets = require('gui.widgets')

--
Expand Down Expand Up @@ -66,8 +67,10 @@ local function get_choices(site)
table.insert(choices, {
text=get_label(loc, zones),
data={
zones=zones,
next_idx=0,
-- clone since an adventurer might wander off the site
-- and the vector gets deallocated
zones=utils.clone(zones),
next_idx=1,
},
})
::continue::
Expand All @@ -78,13 +81,13 @@ end
local function zoom_to(_, choice)
local data = choice.data
if #data.zones == 0 then return end
if data.next_idx >= #data.zones then data.next_idx = 0 end
if data.next_idx > #data.zones then data.next_idx = 1 end
local bld = df.building.find(data.zones[data.next_idx])
if bld then
dfhack.gui.revealInDwarfmodeMap(
xyz2pos(bld.centerx, bld.centery, bld.z), true, true)
end
data.next_idx = (data.next_idx + 1) % #data.zones
data.next_idx = data.next_idx % #data.zones + 1
end

function Sitemap:init()
Expand Down

0 comments on commit 83c9941

Please sign in to comment.