No longer displays red circle in attackable tiles (from range) but not viewed - gave away enemy positions!

This commit is contained in:
Yair Morgenstern 2018-04-18 15:33:53 +03:00
parent d0f3a10728
commit 42ed4e5749
4 changed files with 20 additions and 11 deletions

View File

@ -50,13 +50,14 @@ class UnCivGame : Game() {
else gameInfo = GameInfo() else gameInfo = GameInfo()
gameInfo.tileMap = TileMap(20) gameInfo.tileMap = TileMap(20)
gameInfo.civilizations.add(CivilizationInfo("Babylon", Vector2.Zero, gameInfo)) gameInfo.civilizations.add(CivilizationInfo("Babylon", Vector2.Zero, gameInfo)) // first one is player civ
gameInfo.civilizations.add(CivilizationInfo("Greece", Vector2(3f,5f), gameInfo))
val barbarianCivilization = CivilizationInfo() val barbarianCivilization = CivilizationInfo()
gameInfo.civilizations.add(barbarianCivilization)// second is barbarian civ
gameInfo.civilizations.add(CivilizationInfo("Greece", Vector2(3f,5f), gameInfo)) // all the rest whatever
barbarianCivilization.civName = "Barbarians" barbarianCivilization.civName = "Barbarians"
gameInfo.civilizations.add(barbarianCivilization)
(1..5).forEach { gameInfo.placeBarbarianUnit() } (1..5).forEach { gameInfo.placeBarbarianUnit() }
gameInfo.setTransients() gameInfo.setTransients()

View File

@ -7,6 +7,7 @@ import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.logic.civilization.Notification import com.unciv.logic.civilization.Notification
import com.unciv.logic.map.TileMap import com.unciv.logic.map.TileMap
import com.unciv.logic.map.UnitType import com.unciv.logic.map.UnitType
import com.unciv.models.gamebasics.GameBasics
import com.unciv.ui.utils.getRandom import com.unciv.ui.utils.getRandom
import com.unciv.ui.worldscreen.unit.UnitActions import com.unciv.ui.worldscreen.unit.UnitActions
@ -34,11 +35,11 @@ class GameInfo {
// maybe one of them has a wonder that affects the stats of all the rest of the cities // maybe one of them has a wonder that affects the stats of all the rest of the cities
for (civInfo in civilizations){ for (civInfo in civilizations){
if(!civInfo.isPlayerCivilization())
automateMoves(civInfo)
for (city in civInfo.cities) for (city in civInfo.cities)
city.cityStats.update() city.cityStats.update()
civInfo.happiness = civInfo.getHappinessForNextTurn() civInfo.happiness = civInfo.getHappinessForNextTurn()
if(!civInfo.isPlayerCivilization())
automateMoves(civInfo)
} }
if(turns%10 == 0){ // every 10 turns add a barbarian in a random place if(turns%10 == 0){ // every 10 turns add a barbarian in a random place
@ -74,6 +75,12 @@ class GameInfo {
private fun automateMoves(civInfo: CivilizationInfo) { private fun automateMoves(civInfo: CivilizationInfo) {
if(civInfo.tech.techsToResearch.isEmpty()) {
val researchableTechs = GameBasics.Technologies.values.filter { civInfo.tech.canBeResearched(it.name) }
val techToResearch = researchableTechs.minBy { it.cost }
civInfo.tech.techsResearched.add(techToResearch!!.name)
}
for(unit in civInfo.getCivUnits()){ for(unit in civInfo.getCivUnits()){
if(unit.name=="Settler") { if(unit.name=="Settler") {

View File

@ -149,9 +149,9 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
// This is some crazy voodoo magic so I'll explain. // This is some crazy voodoo magic so I'll explain.
image.setSize(40f, 2f) image.setSize(35f, 2f)
image.moveBy(this.width/2-image.width/2, image.moveBy(width/2-image.width/2, // center
this.height/2-image.height/2) height/2-image.height/2)
// in addTiles, we set the position of groups by relative world position *0.8*groupSize, filter groupSize = 50 // in addTiles, we set the position of groups by relative world position *0.8*groupSize, filter groupSize = 50
// Here, we want to have the borders start HALFWAY THERE and extend towards the tiles, so we give them a position of 0.8*25. // Here, we want to have the borders start HALFWAY THERE and extend towards the tiles, so we give them a position of 0.8*25.
// BUT, we don't actually want it all the way out there, because we want to display the borders of 2 different civs! // BUT, we don't actually want it all the way out there, because we want to display the borders of 2 different civs!

View File

@ -89,7 +89,8 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
WG.update(false) WG.update(false)
} }
for (string in civInfo.getViewableTiles() val civViewableTiles = civInfo.getViewableTiles()
for (string in civViewableTiles
.filter { tileGroups.containsKey(it) }) { .filter { tileGroups.containsKey(it) }) {
tileGroups[string]!!.run { tileGroups[string]!!.run {
@ -112,7 +113,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
UnitType.Ranged -> attackableTiles = unit.getTile().getTilesInDistance(2) UnitType.Ranged -> attackableTiles = unit.getTile().getTilesInDistance(2)
} }
for (tile in attackableTiles.filter { it.unit!=null && it.unit!!.owner != unit.owner }) for (tile in attackableTiles.filter { it.unit!=null && it.unit!!.owner != unit.owner && civViewableTiles.contains(it)})
tileGroups[tile]!!.showCircle(Color(237/255f,41/255f,57/255f,1f)) tileGroups[tile]!!.showCircle(Color(237/255f,41/255f,57/255f,1f))
} }
} }