diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-03-01 21:52:49 +0100 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-03-01 21:52:49 +0100 |
| commit | 5728ebc309b4753c939d751c7fd489b108e5dc09 (patch) | |
| tree | 6bcbe6058a5cfa1e55941702d5fdb6c359d0f5f7 /integration_test.go | |
| parent | ffff169f10b35efaf9f793f745bdfed473ca4d9a (diff) | |
fix: prevent entities from overlapping when arriving at the same cell
Update UpdateMoveSystem to maintain the moveMap as entities move
within a tick. When an entity snaps to a grid cell:
- Block the new cell in the moveMap immediately
- Unblock the old cell
Before snapping, check if the target cell was already claimed by
another entity earlier in the same tick. If so, repath instead of
overlapping.
Diffstat (limited to 'integration_test.go')
| -rw-r--r-- | integration_test.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/integration_test.go b/integration_test.go index 8305719..b8f9ba5 100644 --- a/integration_test.go +++ b/integration_test.go @@ -5,6 +5,8 @@ import ( "time" "age_of_empires/physics" + + "github.com/stretchr/testify/assert" ) func TestGatherLoop(t *testing.T) { @@ -62,3 +64,31 @@ func TestGatherLoop(t *testing.T) { t.Errorf("Unit failed to gather resources within %d ticks. ResourceAmount: %d", maxTicks, game.ResourceAmount) } } + +func TestTwoEntitiesMovingToSameCellDontOverlap(t *testing.T) { + // Two units close together both ordered to the same cell should not overlap. + game := &Game{} + + target := physics.Point{X: 500, Y: 0} + + unitA := game.Append(NewEntityBuilder(). + WithPosition(physics.Point{X: 200, Y: 0}). + WithMove().WithOrder().Build()) + unitB := game.Append(NewEntityBuilder(). + WithPosition(physics.Point{X: 100, Y: 0}). + WithMove().WithOrder().Build()) + + moveMap := game.getMoveMap() + MainAction(game, unitA, target, moveMap) + MainAction(game, unitB, target, moveMap) + + // MOVE_SPEED=10, cell=100 → 10 ticks per cell. B detours around A → ~60 ticks. + for range 60 { + game.Update() + } + + assert.False(t, game.Move[unitA].IsActive, "Entity A should have stopped moving") + assert.False(t, game.Move[unitB].IsActive, "Entity B should have stopped moving") + assert.NotEqual(t, game.Position[unitA], game.Position[unitB], + "Entity A and B should NOT overlap: A at %s, B at %s", game.Position[unitA], game.Position[unitB]) +} |
