Escort movement fix (#11810)

* Wrote some failing unit tests to simulate the crash

* Fix escort movement crash

* getDistanceToTiles now searches once using both escorting units

* Added an extra test

* Moved checking for escort unit movement outside of getMovementCostBetweenAdjacentTiles
This commit is contained in:
Oskar Niesen
2024-07-14 01:22:28 -05:00
committed by GitHub
parent 8912f6adc1
commit 2ffcc48bbf
3 changed files with 89 additions and 19 deletions

View File

@ -278,4 +278,58 @@ internal class UnitFormationTests {
assertTrue(civilianUnit.isEscorting())
assertTrue(TargetHelper.getAttackableEnemies(scout, scout.movement.getDistanceToTiles()).isEmpty())
}
@Test
fun `test escort path with hills one turn civilian`() {
setUp(3)
val centerTile = testGame.getTile(Vector2(0f,0f))
val hillTile = testGame.getTile(Vector2(1f,1f))
val destinationTile = testGame.getTile(Vector2(1f,2f))
val militaryUnit = testGame.addUnit("Mechanized Infantry", civInfo, centerTile)
val civilianUnit = testGame.addUnit("Worker", civInfo, centerTile)
hillTile.addTerrainFeature("Hill")
destinationTile.addTerrainFeature("Hill")
civilianUnit.startEscorting()
civilianUnit.movement.moveToTile(destinationTile)
assertEquals(civilianUnit.getTile(), destinationTile)
assertEquals(militaryUnit.getTile(), destinationTile)
}
@Test
fun `test escort path with hills one turn military`() {
setUp(3)
val centerTile = testGame.getTile(Vector2(0f,0f))
val hillTile = testGame.getTile(Vector2(1f,1f))
val destinationTile = testGame.getTile(Vector2(1f,2f))
val militaryUnit = testGame.addUnit("Mechanized Infantry", civInfo, centerTile)
val civilianUnit = testGame.addUnit("Worker", civInfo, centerTile)
hillTile.addTerrainFeature("Hill")
destinationTile.addTerrainFeature("Hill")
militaryUnit.startEscorting()
militaryUnit.movement.moveToTile(destinationTile)
assertEquals(civilianUnit.getTile(), destinationTile)
assertEquals(militaryUnit.getTile(), destinationTile)
}
@Test
fun `test escort with ignore terrain cost unit`() {
setUp(5)
val centerTile = testGame.getTile(Vector2(0f,0f))
val marsh = testGame.getTile(Vector2(1f,1f))
marsh.addTerrainFeature("Marsh")
val jungle = testGame.getTile(Vector2(2f,2f))
jungle.addTerrainFeature("Jungle")
testGame.getTile(Vector2(3f,3f)).addTerrainFeature("Hill")
testGame.getTile(Vector2(3f,4f)).addTerrainFeature("Hill")
val destinationTile = testGame.getTile(Vector2(4f,5f))
val tileReached = testGame.getTile(Vector2(1f,2f));
val militaryUnit = testGame.addUnit("Scout", civInfo, centerTile)
val civilianUnit = testGame.addUnit("Worker", civInfo, centerTile)
militaryUnit.startEscorting()
val shortestPath = militaryUnit.movement.getShortestPath(destinationTile)
assertEquals(true, shortestPath.count() == 3)
assertEquals(false, shortestPath.contains(jungle))
assertEquals(false, shortestPath.contains(marsh))
}
}