Submarine is invisible now, except to submarines and destroyers. But it still can be aimed by everybody.

This commit is contained in:
Duan Tao 2018-12-12 22:47:49 +08:00
parent 209eb4c73b
commit 36d7b30279
8 changed files with 39 additions and 10 deletions

View file

@ -467,7 +467,7 @@
strength:55,
cost: 375,
requiredTech:"Combustion",
uniques:[], // todo: add interception and bonus vs submarines once we have air and submarine units
uniques:["Can attack submarines"], // todo: add interception and bonus vs submarines once we have air and submarine units
hurryCostModifier:20
},
{
@ -491,7 +491,7 @@
rangedStrength: 60,
cost: 325,
requiredTech:"Refrigeration",
uniques:["Bonus as Attacker 75%", "Invisible to others", "Can Only Attack Water"], //to do: 3 uniques
uniques:["Bonus as Attacker 75%", "Invisible to others", "Can Only Attack Water", "Can attack submarines"], //to do: 3 uniques
hurryCostModifier:20
},
{

View file

@ -33,6 +33,7 @@ class CivilizationInfo {
*/
@Transient private var units=ArrayList<MapUnit>()
@Transient var viewableTiles = HashSet<TileInfo>()
@Transient var viewableInvisibleUnitsTiles = HashSet<TileInfo>()
var gold = 0
var happiness = 15
@ -228,6 +229,9 @@ class CivilizationInfo {
newViewableTiles.addAll(getCivUnits().flatMap { it.getViewableTiles()})
viewableTiles = newViewableTiles // to avoid concurrent modification problems
val newViewableInvisibleTiles = HashSet<TileInfo>()
newViewableInvisibleTiles.addAll(getCivUnits().filter {it.hasUnique("Can attack submarines")}.flatMap {it.getViewableTiles()})
viewableInvisibleUnitsTiles = newViewableInvisibleTiles
// updating the viewable tiles also affects the explored tiles, obvs
val newExploredTiles = HashSet<Vector2>(exploredTiles)

View file

@ -177,6 +177,12 @@ class MapUnit {
return currentTile.baseTerrain=="Ocean"||currentTile.baseTerrain=="Coast"
}
fun isInvisible(): Boolean {
if(hasUnique("Invisible to others"))
return true
return false
}
fun getEmbarkedMovement(): Int {
var movement=2
movement += civInfo.tech.getUniques().count { it == "Increases embarked movement +1" }

View file

@ -281,5 +281,14 @@ open class TileInfo {
turnsToImprovement = improvement.getTurnsToBuild(civInfo)
}
fun hasEnemySubmarine(): Boolean {
val unitsInTile = getUnits()
if (unitsInTile.isEmpty()) return false
if (!unitsInTile.first().civInfo.isPlayerCivilization() &&
unitsInTile.firstOrNull {it.isInvisible() == true} != null) {
return true
}
return false
}
//endregion
}

View file

@ -23,8 +23,10 @@ class CityTileGroup(private val city: CityInfo, tileInfo: TileInfo) : TileGroup(
fun update() {
val canSeeTile = UnCivGame.Current.viewEntireMapForDebug
|| city.civInfo.viewableTiles.contains(tileInfo)
super.update(canSeeTile,true)
val showSubmarine = UnCivGame.Current.viewEntireMapForDebug
|| city.civInfo.viewableInvisibleUnitsTiles.contains(tileInfo)
|| (!tileInfo.hasEnemySubmarine())
super.update(canSeeTile,true, showSubmarine)
updatePopulationImage()
if (improvementImage != null) improvementImage!!.setColor(1f, 1f, 1f, 0.5f)

View file

@ -133,7 +133,7 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
}
open fun update(isViewable: Boolean, showResourcesAndImprovements:Boolean) {
open fun update(isViewable: Boolean, showResourcesAndImprovements:Boolean, showSubmarine: Boolean) {
hideCircle()
if (!UnCivGame.Current.viewEntireMapForDebug
&& !tileInfo.tileMap.gameInfo.getPlayerCivilization().exploredTiles.contains(tileInfo.position)) {
@ -150,7 +150,7 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
civilianUnitImage = newUnitImage(tileInfo.civilianUnit, civilianUnitImage, isViewable, -20f)
militaryUnitImage = newUnitImage(tileInfo.militaryUnit, militaryUnitImage, isViewable, 20f)
militaryUnitImage = newUnitImage(tileInfo.militaryUnit, militaryUnitImage, isViewable && showSubmarine, 20f)
updateRoadImages()
updateBorderImages()

View file

@ -23,7 +23,7 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
}
fun update(isViewable: Boolean) {
fun update(isViewable: Boolean, showSubmarine: Boolean) {
val city = tileInfo.getCity()
removePopulationIcon()
@ -36,7 +36,7 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
updateCityButton(city, isViewable || UnCivGame.Current.viewEntireMapForDebug) // needs to be before the update so the units will be above the city button
super.update(isViewable || UnCivGame.Current.viewEntireMapForDebug,
UnCivGame.Current.settings.showResourcesAndImprovements)
UnCivGame.Current.settings.showResourcesAndImprovements, showSubmarine)
yieldGroup.isVisible = !UnCivGame.Current.settings.showResourcesAndImprovements
if (yieldGroup.isVisible)

View file

@ -180,6 +180,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
internal fun updateTiles(civInfo: CivilizationInfo) {
val playerViewableTilePositions = civInfo.viewableTiles.map { it.position }.toHashSet()
val playerViewableInvisibleUnitsTilePositions = civInfo.viewableInvisibleUnitsTiles.map { it.position }.toHashSet()
cityButtonOverlays.forEach{it.remove()}
cityButtonOverlays.clear()
@ -187,9 +188,16 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
for (tileGroup in tileGroups.values){
val canSeeTile = UnCivGame.Current.viewEntireMapForDebug
|| playerViewableTilePositions.contains(tileGroup.tileInfo.position)
tileGroup.update(canSeeTile)
val showSubmarine = UnCivGame.Current.viewEntireMapForDebug
|| playerViewableInvisibleUnitsTilePositions.contains(tileGroup.tileInfo.position)
|| (!tileGroup.tileInfo.hasEnemySubmarine())
tileGroup.update(canSeeTile, showSubmarine)
val unitsInTile = tileGroup.tileInfo.getUnits()
if(canSeeTile && unitsInTile.isNotEmpty() && !unitsInTile.first().civInfo.isPlayerCivilization())
val canSeeEnemy = unitsInTile.isNotEmpty() && !unitsInTile.first().civInfo.isPlayerCivilization()
&& (showSubmarine || unitsInTile.firstOrNull {!it.isInvisible()}!=null)
if(canSeeTile && canSeeEnemy)
tileGroup.showCircle(Color.RED) // Display ALL viewable enemies with a red circle so that users don't need to go "hunting" for enemy units
}