Skip to content

Commit 1cbbced

Browse files
committed
Add fix/tile-occupancy
Fixes bad unit/building occupancy flags
1 parent 619d5b3 commit 1cbbced

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

fix/tile-occupancy.lua

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
-- Fix occupancy flags at a given tile
2+
3+
--[====[
4+
5+
fix/tile-occupancy
6+
==================
7+
Clears bad occupancy flags at the selected tile. Useful for getting rid of
8+
phantom "building present" messages. Currently only supports issues with
9+
building and unit occupancy. Requires that a tile is selected with the in-game
10+
cursor (``k``).
11+
12+
Can be used to fix problematic tiles caused by :issue:`1047`.
13+
14+
]====]
15+
16+
if #{...} > 0 then
17+
qerror('This script takes no arguments.')
18+
end
19+
20+
function findUnit(x, y, z)
21+
for _, u in pairs(df.global.world.units.active) do
22+
if u.pos.x == x and u.pos.y == y and u.pos.z == z then
23+
return true
24+
end
25+
end
26+
return false
27+
end
28+
29+
cursor = df.global.cursor
30+
changed = false
31+
function report(flag)
32+
print('Cleared occupancy flag: ' .. flag)
33+
changed = true
34+
end
35+
36+
if cursor.x == -30000 then
37+
qerror('Cursor not active.')
38+
end
39+
40+
occ = dfhack.maps.getTileBlock(pos2xyz(cursor)).occupancy[cursor.x % 16][cursor.y % 16]
41+
42+
if occ.building ~= 0 and not dfhack.buildings.findAtTile(pos2xyz(cursor)) then
43+
occ.building = 0
44+
report('building')
45+
end
46+
47+
for _, flag in pairs{'unit', 'unit_grounded'} do
48+
if occ[flag] and not findUnit(pos2xyz(cursor)) then
49+
occ[flag] = false
50+
report(flag)
51+
end
52+
end
53+
54+
if not changed then
55+
print('No changes made at this tile.')
56+
end

0 commit comments

Comments
 (0)