diff --git a/android/Images/TileSets/Default/road.png b/android/Images/TileSets/Default/Road.png similarity index 100% rename from android/Images/TileSets/Default/road.png rename to android/Images/TileSets/Default/Road.png diff --git a/android/Images/TileSets/FantasyHex/road.png b/android/Images/TileSets/FantasyHex/Road.png similarity index 100% rename from android/Images/TileSets/FantasyHex/road.png rename to android/Images/TileSets/FantasyHex/Road.png diff --git a/android/assets/game.atlas b/android/assets/game.atlas index b1ac1a4ae4..f8952ddb9e 100644 --- a/android/assets/game.atlas +++ b/android/assets/game.atlas @@ -2111,7 +2111,7 @@ ImprovementIcons/Railroad orig: 100, 100 offset: 0, 0 index: -1 -TileSets/Default/road +TileSets/Default/Road rotate: false xy: 1421, 1847 size: 61, 11 @@ -4085,7 +4085,7 @@ TileSets/FantasyHex/Units/Worker orig: 32, 28 offset: 0, 0 index: -1 -TileSets/FantasyHex/road +TileSets/FantasyHex/Road rotate: false xy: 1121, 1847 size: 61, 11 diff --git a/core/src/com/unciv/logic/HexMath.kt b/core/src/com/unciv/logic/HexMath.kt index fdfff1ef12..145a48d7bd 100644 --- a/core/src/com/unciv/logic/HexMath.kt +++ b/core/src/com/unciv/logic/HexMath.kt @@ -146,7 +146,7 @@ object HexMath { val current = origin.cpy().sub(distance.toFloat(), distance.toFloat()) // start at 6 o clock for (i in 0 until distance) { // From 6 to 8 vectors += current.cpy() - vectors += origin.cpy().scl(2f).sub(current) // Get vector on other side of cloick + vectors += origin.cpy().scl(2f).sub(current) // Get vector on other side of clock current.add(1f, 0f) } for (i in 0 until distance) { // 8 to 10 @@ -180,4 +180,17 @@ object HexMath { else return (abs(relative_x) + abs(relative_y)).toInt() } -} \ No newline at end of file + + // Statically allocate the Vectors (in World coordinates) + // of the 6 clock directions for border and road drawing in TileGroup + private val clockToWorldVectors: Map = mapOf( + 2 to hex2WorldCoords(Vector2(0f, -1f)), + 4 to hex2WorldCoords(Vector2(1f, 0f)), + 6 to hex2WorldCoords(Vector2(1f, 1f)), + 8 to hex2WorldCoords(Vector2(0f, 1f)), + 10 to hex2WorldCoords(Vector2(-1f, 0f)), + 12 to hex2WorldCoords(Vector2(-1f, -1f)) ) + + fun getClockDirectionToWorldVector(clockDirection: Int): Vector2 = + clockToWorldVectors[clockDirection] ?: Vector2.Zero +} diff --git a/core/src/com/unciv/logic/map/TileMap.kt b/core/src/com/unciv/logic/map/TileMap.kt index a5202d93fd..271a550a31 100644 --- a/core/src/com/unciv/logic/map/TileMap.kt +++ b/core/src/com/unciv/logic/map/TileMap.kt @@ -159,7 +159,7 @@ class TileMap { /** Tries to place the [unitName] into the [TileInfo] closest to the given [position] * @param position where to try to place the unit (or close - max 10 tiles distance) - * @param unitName name of the [BaseUnit] to create and place + * @param unitName name of the [BaseUnit][com.unciv.models.ruleset.unit.BaseUnit] to create and place * @param civInfo civilization to assign unit to * @return created [MapUnit] or null if no suitable location was found * */ @@ -335,9 +335,9 @@ class TileMap { * Returns -1 if not neighbors */ fun getNeighborTileClockPosition(tile: TileInfo, otherTile: TileInfo): Int { - var radius = mapParameters.mapSize.radius - if (mapParameters.shape == MapShape.rectangular) - radius = mapParameters.mapSize.width / 2 + val radius = if (mapParameters.shape == MapShape.rectangular) + mapParameters.mapSize.width / 2 + else mapParameters.mapSize.radius val xDifference = tile.position.x - otherTile.position.x val yDifference = tile.position.y - otherTile.position.y @@ -357,6 +357,14 @@ class TileMap { } } + /** Convert relative direction of otherTile seen from tile's position into a vector + * in world coordinates of length sqrt(3), so that it can be used to go from tile center to + * the edge of the hex in that direction (meaning the center of the border between the hexes) + */ + fun getNeighborTilePositionAsWorldCoords(tile: TileInfo, otherTile: TileInfo): Vector2 = + HexMath.getClockDirectionToWorldVector(getNeighborTileClockPosition(tile, otherTile)) + + /** * Returns the closest position to (0, 0) outside the map which can be wrapped * to the position of the given vector diff --git a/core/src/com/unciv/ui/tilegroups/TileGroup.kt b/core/src/com/unciv/ui/tilegroups/TileGroup.kt index 0dbb2a12f4..ff20c1738f 100644 --- a/core/src/com/unciv/ui/tilegroups/TileGroup.kt +++ b/core/src/com/unciv/ui/tilegroups/TileGroup.kt @@ -2,14 +2,12 @@ package com.unciv.ui.tilegroups import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g2d.Batch -import com.badlogic.gdx.math.Vector2 import com.badlogic.gdx.scenes.scene2d.Actor import com.badlogic.gdx.scenes.scene2d.Group import com.badlogic.gdx.scenes.scene2d.Touchable import com.badlogic.gdx.scenes.scene2d.ui.Image import com.badlogic.gdx.utils.Align import com.unciv.UncivGame -import com.unciv.logic.HexMath import com.unciv.logic.civilization.CivilizationInfo import com.unciv.logic.map.RoadStatus import com.unciv.logic.map.TileInfo @@ -444,16 +442,7 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings, } if (neighborOwner != tileOwner && !borderImages.containsKey(neighbor)) { // there should be a border here but there isn't - val relativeHexPosition = when (tileInfo.tileMap.getNeighborTileClockPosition(tileInfo, neighbor)){ - 2 -> Vector2(0f,-1f) - 4 -> Vector2(1f,0f) - 6 -> Vector2(1f,1f) - 8 -> Vector2(0f,1f) - 10 -> Vector2(-1f,0f) - 12 -> Vector2(-1f,-1f) - else -> Vector2.Zero - } - val relativeWorldPosition = HexMath.hex2WorldCoords(relativeHexPosition) + val relativeWorldPosition = tileInfo.tileMap.getNeighborTilePositionAsWorldCoords(tileInfo, neighbor) // This is some crazy voodoo magic so I'll explain. val images = mutableListOf() @@ -487,8 +476,7 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings, private fun updateRoadImages() { if (forMapEditorIcon) return for (neighbor in tileInfo.neighbors) { - if (!roadImages.containsKey(neighbor)) roadImages[neighbor] = RoadImage() - val roadImage = roadImages[neighbor]!! + val roadImage = roadImages[neighbor] ?: RoadImage().also { roadImages[neighbor] = it } val roadStatus = when { tileInfo.roadStatus == RoadStatus.None || neighbor.roadStatus === RoadStatus.None -> RoadStatus.None @@ -505,20 +493,10 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings, } if (roadStatus == RoadStatus.None) continue // no road image - val image = if (roadStatus == RoadStatus.Road) ImageGetter.getDot(Color.BROWN) - else ImageGetter.getImage(tileSetStrings.railroad) + val image = ImageGetter.getImage(tileSetStrings.roadsMap[roadStatus]!!) roadImage.image = image - val relativeHexPosition = when (tileInfo.tileMap.getNeighborTileClockPosition(neighbor, tileInfo)){ - 2 -> Vector2(0f,1f) - 4 -> Vector2(-1f,0f) - 6 -> Vector2(-1f,-1f) - 8 -> Vector2(0f,-1f) - 10 -> Vector2(1f,0f) - 12 -> Vector2(1f,1f) - else -> Vector2.Zero - } - val relativeWorldPosition = HexMath.hex2WorldCoords(relativeHexPosition) + val relativeWorldPosition = tileInfo.tileMap.getNeighborTilePositionAsWorldCoords(tileInfo, neighbor) // This is some crazy voodoo magic so I'll explain. image.moveBy(25f, 25f) // Move road to center of tile diff --git a/core/src/com/unciv/ui/tilegroups/TileSetStrings.kt b/core/src/com/unciv/ui/tilegroups/TileSetStrings.kt index e1261dc15c..0b65e463f3 100644 --- a/core/src/com/unciv/ui/tilegroups/TileSetStrings.kt +++ b/core/src/com/unciv/ui/tilegroups/TileSetStrings.kt @@ -1,6 +1,7 @@ package com.unciv.ui.tilegroups import com.unciv.UncivGame +import com.unciv.logic.map.RoadStatus import com.unciv.models.tilesets.TileSetCache import com.unciv.models.tilesets.TileSetConfig @@ -13,7 +14,10 @@ class TileSetStrings { val hexagon = tileSetLocation + "Hexagon" val crosshatchHexagon = tileSetLocation + "CrosshatchHexagon" val cityOverlay = tileSetLocation + "CityOverlay" - val railroad = tileSetLocation + "Railroad" + val roadsMap = RoadStatus.values() + .filterNot { it == RoadStatus.None } + .map { it to tileSetLocation + it.name } + .toMap() val naturalWonderOverlay = tileSetLocation + "NaturalWonderOverlay" val tilesLocation = tileSetLocation + "Tiles/"