mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-26 13:27:22 -04:00
Fix crash in Tactical Analysis Map (#8441)
* Fix crash due to out of looking at index == array length * Fix dimension and swap x and y * Some more cleanup * Rewrite loop * Even more cleanup * Set function back to private * Half total number of iterations needed
This commit is contained in:
parent
2167f65c1b
commit
c5667d1685
@ -296,45 +296,21 @@ class TacticalAnalysisMap {
|
|||||||
for (zone in zones)
|
for (zone in zones)
|
||||||
zone.neighboringZones.clear()
|
zone.neighboringZones.clear()
|
||||||
|
|
||||||
val tileMatrix = game.tileMap.tileMatrix
|
val tileMap = game.tileMap
|
||||||
|
val directionsToCheck = setOf(12, 4, 8) // each tile only needs to check 3 directions for every possible neighboringZone to be identified
|
||||||
|
|
||||||
val gridH = tileMatrix.size-1
|
for (tile in tileMap.values) {
|
||||||
val gridW = tileMatrix.size-1
|
val zoneA = getZoneByTile(tile)
|
||||||
|
val zoneAId = zoneA!!.id
|
||||||
for (y in 0 until gridH) {
|
for (neighbor in directionsToCheck.mapNotNull { tileMap.getClockPositionNeighborTile(tile, it) }) {
|
||||||
for (x in 0 until gridW) {
|
val zoneB = getZoneByTile(neighbor)!!
|
||||||
val tileA = tileMatrix[y][x]
|
val zoneBId = zoneB.id
|
||||||
val tileB = tileMatrix[y+1][x]
|
if (zoneAId != zoneBId) {
|
||||||
val tileC = tileMatrix[y][x+1]
|
|
||||||
val tileD = tileMatrix[y+1][x+1]
|
|
||||||
|
|
||||||
val zoneA = if (tileA == null) getZoneById("UNKNOWN") else getZoneByTile(tileA)
|
|
||||||
val zoneB = if (tileB == null) getZoneById("UNKNOWN") else getZoneByTile(tileB)
|
|
||||||
val zoneC = if (tileC == null) getZoneById("UNKNOWN") else getZoneByTile(tileC)
|
|
||||||
val zoneD = if (tileD == null) getZoneById("UNKNOWN") else getZoneByTile(tileD)
|
|
||||||
|
|
||||||
val zoneAId = zoneA!!.id
|
|
||||||
val zoneBId = zoneB!!.id
|
|
||||||
val zoneCId = zoneC!!.id
|
|
||||||
val zoneDId = zoneD!!.id
|
|
||||||
|
|
||||||
if (zoneAId != "UNKNOWN" && zoneBId != "UNKNOWN" && zoneAId != zoneBId) {
|
|
||||||
zoneA.neighboringZones.add(zoneB.id)
|
zoneA.neighboringZones.add(zoneB.id)
|
||||||
zoneB.neighboringZones.add(zoneA.id)
|
zoneB.neighboringZones.add(zoneA.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zoneAId != "UNKNOWN" && zoneCId != "UNKNOWN" && zoneAId != zoneCId) {
|
|
||||||
zoneA.neighboringZones.add(zoneC.id)
|
|
||||||
zoneC.neighboringZones.add(zoneA.id)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (zoneAId != "UNKNOWN" && zoneDId != "UNKNOWN" && zoneAId != zoneDId) {
|
|
||||||
zoneA.neighboringZones.add(zoneD.id)
|
|
||||||
zoneD.neighboringZones.add(zoneA.id)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun debugOutput() {
|
fun debugOutput() {
|
||||||
|
@ -153,13 +153,8 @@ class TileMap : IsPartOfGameInfoSerialization {
|
|||||||
tileMatrix[x - leftX][y - bottomY]!!
|
tileMatrix[x - leftX][y - bottomY]!!
|
||||||
|
|
||||||
/** @return tile at hex coordinates ([x],[y]) or null if they are outside the map. Does *not* respect world wrap, use [getIfTileExistsOrNull] for that. */
|
/** @return tile at hex coordinates ([x],[y]) or null if they are outside the map. Does *not* respect world wrap, use [getIfTileExistsOrNull] for that. */
|
||||||
private fun getOrNull (x: Int, y: Int): Tile? {
|
private fun getOrNull (x: Int, y: Int): Tile? =
|
||||||
val arrayXIndex = x - leftX
|
tileMatrix.getOrNull(x - leftX)?.getOrNull(y - bottomY)
|
||||||
if (arrayXIndex < 0 || arrayXIndex >= tileMatrix.size) return null
|
|
||||||
val arrayYIndex = y - bottomY
|
|
||||||
if (arrayYIndex < 0 || arrayYIndex >= tileMatrix[arrayXIndex].size) return null
|
|
||||||
return tileMatrix[arrayXIndex][arrayYIndex]
|
|
||||||
}
|
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
//region Pure Functions
|
//region Pure Functions
|
||||||
|
Loading…
x
Reference in New Issue
Block a user