Skip to content

Units::teleport: keep occupancy flags while other units remain on the tile - #5946

Merged
ab9rf merged 2 commits into
DFHack:developfrom
Alistair-Afton:fix-teleport-grounded-flag
Sep 19, 2026
Merged

ab9rf merged 2 commits into
DFHack:developfrom
Alistair-Afton:fix-teleport-grounded-flag

Conversation

@Alistair-Afton

Copy link
Copy Markdown
Contributor

Summary

Fixes #5938.

Units::teleport cleared the source tile's unit_grounded flag unconditionally, so teleporting one grounded unit away from a tile left the flag unset even when another grounded unit still occupied it. The game itself only clears the flag when the last grounded unit leaves the tile.

teleport now records which tiles still have a grounded or standing unit on them (honoring the 3x3 EQUIPMENT footprint) and only clears unit_grounded/unit when the departing unit was the last of its kind there.

Testing

  • New test/modules/units_fortress.lua covers both directions: teleporting one of two grounded units off a tile keeps unit_grounded, teleporting one of two standing units keeps unit, and removing the last unit still clears the flag.
  • 2/2 tests, 19/19 checks pass in-game on 53.16, plus a map-wide audit afterward found zero stale occupancy flags.
  • All modules tests pass (5/5; the 2 skipped are title-mode-only).

Comment thread library/modules/Units.cpp Resolved
SilasD
SilasD previously requested changes Sep 17, 2026

@SilasD SilasD left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one is NOT ready for prime-time.

I think this will work 99% of the time, but there are some interesting special cases that should be considered and possibly resolved.

this one probably needs attention from ab9rf or Quietust.

Comment thread library/modules/Units.cpp Resolved
Comment thread library/modules/Units.cpp Resolved
Comment thread test/modules/units_fortress.lua Resolved
Comment thread test/modules/units_fortress.lua Resolved
Comment thread test/modules/units_fortress.lua Resolved
Comment thread test/modules/units_fortress.lua Resolved
Comment thread test/modules/units_fortress.lua Resolved
Comment thread library/modules/Units.cpp Resolved
Caged units and in-flight projectiles do not set tile occupancy flags, so
they must not keep flags alive when other units leave a tile.

Test now uses dfhack.maps.getTileFlags, requires the destination tile to
be walkable, and returns a failure reason from free_tile_near.
@Alistair-Afton

Copy link
Copy Markdown
Contributor Author

For context on the "needs attention from ab9rf or Quietust" point: ab9rf already verified the underlying behavior on #5924 — from reverse engineering, equipment on the tile is the correct way to infer a 3x3 occupancy footprint, and he explicitly confirmed there that teleport incorrectly clearing unit_grounded while another grounded unit remains is a preexisting defect. This PR is that fix.

All of SilasD's special-case items are addressed in 86463ce plus the test-side fixes: caged and projectile units are skipped in the recompute scan (verified in-game that they set no occupancy), the source tile resolves through Units::getPosition, the test uses getTileFlags plus a walkable-tiletype check, and free_tile_near returns nil+message. The only unverifiable case is ghostly units (none in the test fort); they are left counted.

@SilasD
SilasD dismissed their stale review September 18, 2026 17:01

everything resolved.

@SilasD SilasD left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this covers my issues. All good to go.

if some user is teleporting a ghost around, or teleporting a unit onto a ghost's tile, they have bigger problems than occupancy flags.

as an aside, there is a flying unit flag but it has nothing to do with block occupancy.
from memory, it's unit.enemy.caste_flags.FLIER, and clearing it will cause a flying unit to plummet to the ground. this group of flags are a copy of the master flags in the unit's creature_raw's caste_raw.flags, and they are not "sticky" -- they are recreated during the map load.

@ab9rf
ab9rf merged commit 3fa5ef7 into DFHack:develop Sep 19, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

teleport does not properly adjust unit_grounded flags when teleporting a unit

3 participants