-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes bad unit/building occupancy flags
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
-- Fix occupancy flags at a given tile | ||
|
||
--[====[ | ||
fix/tile-occupancy | ||
================== | ||
Clears bad occupancy flags at the selected tile. Useful for getting rid of | ||
phantom "building present" messages. Currently only supports issues with | ||
building and unit occupancy. Requires that a tile is selected with the in-game | ||
cursor (``k``). | ||
Can be used to fix problematic tiles caused by :issue:`1047`. | ||
]====] | ||
|
||
if #{...} > 0 then | ||
qerror('This script takes no arguments.') | ||
end | ||
|
||
function findUnit(x, y, z) | ||
for _, u in pairs(df.global.world.units.active) do | ||
if u.pos.x == x and u.pos.y == y and u.pos.z == z then | ||
return true | ||
end | ||
end | ||
return false | ||
end | ||
|
||
cursor = df.global.cursor | ||
changed = false | ||
function report(flag) | ||
print('Cleared occupancy flag: ' .. flag) | ||
changed = true | ||
end | ||
|
||
if cursor.x == -30000 then | ||
qerror('Cursor not active.') | ||
end | ||
|
||
occ = dfhack.maps.getTileBlock(pos2xyz(cursor)).occupancy[cursor.x % 16][cursor.y % 16] | ||
|
||
if occ.building ~= 0 and not dfhack.buildings.findAtTile(pos2xyz(cursor)) then | ||
occ.building = 0 | ||
report('building') | ||
end | ||
|
||
for _, flag in pairs{'unit', 'unit_grounded'} do | ||
if occ[flag] and not findUnit(pos2xyz(cursor)) then | ||
occ[flag] = false | ||
report(flag) | ||
end | ||
end | ||
|
||
if not changed then | ||
print('No changes made at this tile.') | ||
end |