Map: fix immobile-unit bookkeeping and refresh gradients on painted forbidden area - #187
Merged
Conversation
Map::setSize filled immobileUnits with 0, which is team 0's marker; the "no unit here" sentinel is IMMOBILE_UNIT_NONE, as MapIO uses on load. On any freshly built map (random maps, the editor, harnesses) every free tile counted as blocked by an immobile unit, the local gradient marked the whole window forbidden, the building was declared unreachable, and every unit fell through to the full-map global gradient. Loaded maps were unaffected. Map::updateLocalGradient indexed immobileUnits with the local-window index instead of the map index used for cases[] on the line above and by MapGradientBuilding.cpp, so an immobile unit blocked whichever window tile shared its number with the unit's map index, never its own tile. test/ImmobileUnitGradientHarness.cpp links the real engine on a 64x64 map and checks both: a fresh map has no immobile unit and reachable local gradients, and a marked unit blocks exactly its own tile. Each scenario fails on its unfixed line. Fable 5.1 helped authoring this commit.
Game::executeAlterForbidden dropped the team's building gradients only when area was erased. After a paint, every gradient still led through the tiles just closed; units kept walking toward a former gap until one of them reached the wall and the near-field check refused the step, and the global gradient is recomputed at most once per 128 ticks on top of that. Painting now invalidates like erasing does. Team::dirtyGlobalGradient also marks the local gradients dirty. They depend on the same forbidden bits, and nothing else ever invalidated them; on generated maps this was masked until the immobile-unit fix made local gradients usable at all. The harness paints two forbidden rows through OrderAlterForbidden with one gap, checks that a unit inside the local window and one outside it both route through the gap, closes it and checks that both are cut off at once. It fails on the unfixed code. Fable 5.1 helped authoring this commit.
Contributor
|
Bradley approved #187 subject to removing the obsolete local-gradient changes. The adapted head is The remaining production changes initialize Verified with Apple Clang release builds in an isolated local build checkout:
Commands, controls, logs and repeatability digests are retained locally in |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix two pathfinding bookkeeping problems on the weighted-gradient engine now in master.
Fresh-map occupancy.
Map::setSizeinitializedimmobileUnitswith zero, which denotes team 0 rather than an empty tile. Initialize it toIMMOBILE_UNIT_NONE(255), matching the loader. Empty cells on new maps no longer masquerade as immobile-unit obstacles.Forbidden-area painting. Adding forbidden tiles now invalidates the team's cached building gradients, just as erasing already does. The next query rebuilds a route using the new restrictions. This invalidates all allocated swim classes through the existing
resetPathfindGradientsimplementation; it does not add another refresh policy.The original local-gradient indexing fix and local-dirty-flag changes are no longer part of the patch: #184 removed that pathfinder. The regression now uses full-map Uint16 gradients and all seven swim classes. It covers fresh-map occupancy, immobile units blocking exactly their own cells, closing the only gap through actual paint orders, and reopening it through an erase order. The new harness runs in Linux CI.
Validation on the adapted patch:
Run
scons release=1 server=0 immobile-unit-gradient-testand./build/src/ImmobileUnitGradientHarness; usefresh,occupancyorforbiddento select a scenario. Normal game data is required; no display or external save fixture is needed.This intentionally corrects routing behavior. Existing replay outcomes can change; repeatability of the fixed simulation is checked separately from equivalence to the broken behavior. Broad invalidation after painting may require more gradient rebuilding during brush use; allocation and rebuild remain on demand. Bradley approved the PR subject to this cleanup.