Moved notifications to CivInfo, notifications on enemy actions removed
This commit is contained in:
parent
51148ac347
commit
d0f3a10728
24 changed files with 161 additions and 140 deletions
|
@ -20,6 +20,7 @@
|
|||
description: "Has no abilites, can only explore",
|
||||
unbuildable:true,
|
||||
unitType:"Melee",
|
||||
strength:5,
|
||||
movement:2
|
||||
},
|
||||
{
|
||||
|
@ -27,7 +28,7 @@
|
|||
description: "A basic fighting unit",
|
||||
unitType:"Melee",
|
||||
movement:2,
|
||||
strength:2,
|
||||
strength:8,
|
||||
cost: 40,
|
||||
hurryCostModifier:20
|
||||
},
|
||||
|
@ -36,8 +37,8 @@
|
|||
description: "A basic fighting unit",
|
||||
unitType:"Ranged",
|
||||
movement:2,
|
||||
strength:2,
|
||||
rangedStrength:3,
|
||||
strength:5,
|
||||
rangedStrength:7,
|
||||
cost: 40,
|
||||
requiredTech:"Writing",
|
||||
hurryCostModifier:20
|
||||
|
|
|
@ -51,13 +51,13 @@ class UnCivGame : Game() {
|
|||
|
||||
gameInfo.tileMap = TileMap(20)
|
||||
gameInfo.civilizations.add(CivilizationInfo("Babylon", Vector2.Zero, gameInfo))
|
||||
|
||||
gameInfo.civilizations.add(CivilizationInfo("Greece", Vector2(3f,5f), gameInfo))
|
||||
|
||||
val barbarianCivilization = CivilizationInfo()
|
||||
barbarianCivilization.civName = "Barbarians"
|
||||
gameInfo.civilizations.add(barbarianCivilization)
|
||||
|
||||
for(i in 1..5) {
|
||||
gameInfo.placeBarbarianUnit()
|
||||
}
|
||||
(1..5).forEach { gameInfo.placeBarbarianUnit() }
|
||||
|
||||
gameInfo.setTransients()
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.unciv.logic
|
||||
|
||||
import com.badlogic.gdx.math.Vector2
|
||||
import com.unciv.UnCivGame
|
||||
import com.unciv.logic.battle.Battle
|
||||
import com.unciv.logic.battle.MapUnitCombatant
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
|
@ -8,6 +8,7 @@ import com.unciv.logic.civilization.Notification
|
|||
import com.unciv.logic.map.TileMap
|
||||
import com.unciv.logic.map.UnitType
|
||||
import com.unciv.ui.utils.getRandom
|
||||
import com.unciv.ui.worldscreen.unit.UnitActions
|
||||
|
||||
class GameInfo {
|
||||
|
||||
|
@ -22,11 +23,6 @@ class GameInfo {
|
|||
fun getPlayerCivilization(): CivilizationInfo = civilizations[0]
|
||||
fun getBarbarianCivilization(): CivilizationInfo = civilizations[1]
|
||||
|
||||
|
||||
fun addNotification(text: String, location: Vector2?) {
|
||||
notifications.add(Notification(text, location))
|
||||
}
|
||||
|
||||
fun nextTurn() {
|
||||
notifications.clear()
|
||||
|
||||
|
@ -127,7 +123,7 @@ class GameInfo {
|
|||
val unitToAttack =unitTileToAttack.unit!!
|
||||
if(unitToAttack.getBaseUnit().unitType == UnitType.Civilian){ // kill
|
||||
if(unitToAttack.civInfo == getPlayerCivilization())
|
||||
addNotification("Our "+unitToAttack.name+" was destroyed by an enemy "+unit.name+"!", unitTileToAttack.position)
|
||||
getPlayerCivilization().addNotification("Our "+unitToAttack.name+" was destroyed by an enemy "+unit.name+"!", unitTileToAttack.position)
|
||||
unitTileToAttack.unit=null
|
||||
unit.headTowards(unitTileToAttack.position)
|
||||
continue
|
||||
|
|
|
@ -97,7 +97,7 @@ class Battle(val gameInfo:GameInfo) {
|
|||
if (defender.getCombatantType() == CombatantType.City) defender.getName()
|
||||
else " our " + defender.getName()
|
||||
val notificationString = "An enemy " + attacker.getName() + whatHappenedString + defenderString
|
||||
gameInfo.addNotification(notificationString, attackedTile.position)
|
||||
gameInfo.getPlayerCivilization().addNotification(notificationString, attackedTile.position)
|
||||
}
|
||||
|
||||
if (defender.isDefeated() && attacker.getCombatantType() == CombatantType.Melee)
|
||||
|
|
|
@ -9,7 +9,7 @@ import kotlin.math.max
|
|||
class CityCombatant(val city: CityInfo) : ICombatant {
|
||||
override fun getHealth(): Int = city.health
|
||||
override fun getCivilization(): CivilizationInfo = city.civInfo
|
||||
override fun getTile(): TileInfo = city.tile
|
||||
override fun getTile(): TileInfo = city.getTile()
|
||||
override fun getName(): String = city.name
|
||||
override fun isDefeated(): Boolean = city.health==1
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.unciv.logic.city
|
||||
|
||||
import com.unciv.logic.map.UnitType
|
||||
import com.unciv.models.gamebasics.Building
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.models.stats.Stats
|
||||
|
@ -15,11 +16,8 @@ class CityConstructions {
|
|||
var currentConstruction: String = "Monument" // default starting building!
|
||||
|
||||
|
||||
private val buildableBuildings: List<String>
|
||||
get() {
|
||||
return GameBasics.Buildings.values
|
||||
.filter { it.isBuildable(this) }.map { it.name }
|
||||
}
|
||||
private fun getBuildableBuildings(): List<String> = GameBasics.Buildings.values
|
||||
.filter { it.isBuildable(this) }.map { it.name }
|
||||
|
||||
// Library and public school unique (not actualy unique, though...hmm)
|
||||
fun getStats(): Stats {
|
||||
|
@ -70,7 +68,7 @@ class CityConstructions {
|
|||
else if (GameBasics.Units.containsKey(constructionName))
|
||||
return GameBasics.Units[constructionName]!!
|
||||
|
||||
throw Exception(constructionName+ " is not a building or a unit!")
|
||||
throw Exception("$constructionName is not a building or a unit!")
|
||||
}
|
||||
|
||||
internal fun getBuiltBuildings(): List<Building> = builtBuildings.map { GameBasics.Buildings[it]!! }
|
||||
|
@ -88,7 +86,7 @@ class CityConstructions {
|
|||
currentConstruction = "lie"
|
||||
if (!construction.isBuildable(this)) {
|
||||
// We can't build this building anymore! (Wonder has been built / resource is gone / etc.)
|
||||
cityInfo.civInfo.gameInfo.addNotification("Cannot continue work on " + saveCurrentConstruction, cityInfo.cityLocation)
|
||||
cityInfo.civInfo.addNotification("Cannot continue work on $saveCurrentConstruction", cityInfo.cityLocation)
|
||||
chooseNextConstruction()
|
||||
construction = getConstruction(currentConstruction)
|
||||
} else
|
||||
|
@ -99,7 +97,7 @@ class CityConstructions {
|
|||
if (inProgressConstructions[currentConstruction]!! >= productionCost) {
|
||||
construction.postBuildEvent(this)
|
||||
inProgressConstructions.remove(currentConstruction)
|
||||
cityInfo.civInfo.gameInfo.addNotification(currentConstruction + " has been built in " + cityInfo.name, cityInfo.cityLocation)
|
||||
cityInfo.civInfo.addNotification(currentConstruction + " has been built in " + cityInfo.name, cityInfo.cityLocation)
|
||||
|
||||
chooseNextConstruction()
|
||||
}
|
||||
|
@ -107,14 +105,25 @@ class CityConstructions {
|
|||
}
|
||||
|
||||
fun chooseNextConstruction() {
|
||||
val buildableNotWonders = buildableBuildings.filterNot{(getConstruction(it) as Building).isWonder}
|
||||
if(buildableNotWonders.isEmpty()) currentConstruction = Worker
|
||||
else currentConstruction = buildableNotWonders.first()
|
||||
cityInfo.civInfo.gameInfo.addNotification("Work has started on " + currentConstruction, cityInfo.cityLocation)
|
||||
val buildableNotWonders = getBuildableBuildings().filterNot{(getConstruction(it) as Building).isWonder}
|
||||
if(!buildableNotWonders.isEmpty()){
|
||||
currentConstruction = buildableNotWonders.first()
|
||||
}
|
||||
else {
|
||||
val militaryUnits = cityInfo.civInfo.getCivUnits().filter { it.getBaseUnit().unitType != UnitType.Civilian }.size
|
||||
if (cityInfo.civInfo.getCivUnits().none { it.name== Worker } || militaryUnits > cityInfo.civInfo.cities.size*2) {
|
||||
currentConstruction = Worker
|
||||
} else {
|
||||
currentConstruction = "Archer"
|
||||
}
|
||||
}
|
||||
if(cityInfo.civInfo == cityInfo.civInfo.gameInfo.getPlayerCivilization())
|
||||
cityInfo.civInfo.addNotification("Work has started on $currentConstruction", cityInfo.cityLocation)
|
||||
}
|
||||
|
||||
private fun workDone(constructionName: String): Int {
|
||||
return if (inProgressConstructions.containsKey(constructionName)) inProgressConstructions[constructionName]!! else 0
|
||||
if (inProgressConstructions.containsKey(constructionName)) return inProgressConstructions[constructionName]!!
|
||||
else return 0
|
||||
}
|
||||
|
||||
fun turnsToConstruction(constructionName: String): Int {
|
||||
|
|
|
@ -39,7 +39,7 @@ class CityExpansionManager {
|
|||
cultureStored += culture.toInt()
|
||||
if (cultureStored >= cultureToNextTile) {
|
||||
addNewTileWithCulture()
|
||||
cityInfo.civInfo.gameInfo.addNotification(cityInfo.name + " has expanded its borders!", cityInfo.cityLocation)
|
||||
cityInfo.civInfo.addNotification(cityInfo.name + " has expanded its borders!", cityInfo.cityLocation)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,17 +26,16 @@ class CityInfo {
|
|||
internal val tileMap: TileMap
|
||||
get() = civInfo.gameInfo.tileMap
|
||||
|
||||
val tile: TileInfo
|
||||
get() = tileMap[cityLocation]
|
||||
val tilesInRange: List<TileInfo>
|
||||
get() = tileMap.getTilesInDistance(cityLocation, 3).filter { civInfo.civName == it.owner }
|
||||
fun getTile(): TileInfo = tileMap[cityLocation]
|
||||
|
||||
fun getTilesInRange(): List<TileInfo> = tileMap.getTilesInDistance(cityLocation, 3).filter { civInfo.civName == it.owner }
|
||||
|
||||
|
||||
// Remove resources required by buildings
|
||||
fun getCityResources(): Counter<TileResource> {
|
||||
val cityResources = Counter<TileResource>()
|
||||
|
||||
for (tileInfo in tilesInRange.filter { it.resource != null }) {
|
||||
for (tileInfo in getTilesInRange().filter { it.resource != null }) {
|
||||
val resource = tileInfo.tileResource
|
||||
if (resource.improvement == tileInfo.improvement || tileInfo.isCityCenter)
|
||||
cityResources.add(resource, 1)
|
||||
|
@ -54,7 +53,7 @@ class CityInfo {
|
|||
|
||||
val greatPersonPoints: Stats
|
||||
get() {
|
||||
var greatPersonPoints = population.specialists.times(3f)
|
||||
var greatPersonPoints = population.getSpecialists().times(3f)
|
||||
|
||||
for (building in cityConstructions.getBuiltBuildings())
|
||||
if (building.greatPersonPoints != null)
|
||||
|
@ -81,7 +80,8 @@ class CityInfo {
|
|||
name = civInfo.getCivilization().cities[civInfo.cities.size]
|
||||
this.cityLocation = cityLocation
|
||||
civInfo.cities.add(this)
|
||||
civInfo.gameInfo.addNotification("$name has been founded!", cityLocation)
|
||||
if(civInfo == civInfo.gameInfo.getPlayerCivilization())
|
||||
civInfo.addNotification("$name has been founded!", cityLocation)
|
||||
if (civInfo.policies.isAdopted("Legalism") && civInfo.cities.size <= 4) cityConstructions.addCultureBuilding()
|
||||
if (civInfo.cities.size == 1) {
|
||||
cityConstructions.builtBuildings.add("Palace")
|
||||
|
@ -92,7 +92,7 @@ class CityInfo {
|
|||
tileInfo.owner = civInfo.civName
|
||||
}
|
||||
|
||||
val tile = tile
|
||||
val tile = getTile()
|
||||
tile.workingCity = this.name
|
||||
tile.roadStatus = RoadStatus.Railroad
|
||||
if (listOf("Forest", "Jungle", "Marsh").contains(tile.terrainFeature))
|
||||
|
|
|
@ -17,7 +17,7 @@ class CityStats {
|
|||
|
||||
private fun getStatsFromTiles(): Stats {
|
||||
val stats = Stats()
|
||||
for (cell in cityInfo.tilesInRange.filter { cityInfo.name == it.workingCity })
|
||||
for (cell in cityInfo.getTilesInRange().filter { cityInfo.name == it.workingCity })
|
||||
stats.add(cell.getTileStats(cityInfo, cityInfo.civInfo))
|
||||
return stats
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ class CityStats {
|
|||
var happiness = -3f
|
||||
var unhappinessFromCitizens = cityInfo.population.population.toFloat()
|
||||
if (civInfo.policies.isAdopted("Democracy"))
|
||||
unhappinessFromCitizens -= cityInfo.population.numberOfSpecialists * 0.5f
|
||||
unhappinessFromCitizens -= cityInfo.population.getNumberOfSpecialists() * 0.5f
|
||||
if (civInfo.buildingUniques.contains("CitizenUnhappinessDecreased"))
|
||||
unhappinessFromCitizens *= 0.9f
|
||||
if (civInfo.policies.isAdopted("Aristocracy"))
|
||||
|
@ -128,7 +128,7 @@ class CityStats {
|
|||
stats.production += specialists.production * 2
|
||||
stats.science += specialists.science * 3
|
||||
stats.gold += specialists.gold * 2
|
||||
val numOfSpecialists = cityInfo.population.numberOfSpecialists
|
||||
val numOfSpecialists = cityInfo.population.getNumberOfSpecialists()
|
||||
if (policies.contains("Commerce Complete")) stats.gold += numOfSpecialists.toFloat()
|
||||
if (policies.contains("Secularism")) stats.science += (numOfSpecialists * 2).toFloat()
|
||||
|
||||
|
@ -190,9 +190,9 @@ class CityStats {
|
|||
val civInfo = cityInfo.civInfo
|
||||
|
||||
baseStatList["Population"] = Stats().add(Stat.Science,cityInfo.population.population.toFloat())
|
||||
.add(Stat.Production,cityInfo.population.freePopulation.toFloat())
|
||||
.add(Stat.Production,cityInfo.population.getFreePopulation().toFloat())
|
||||
baseStatList["Tile yields"] = getStatsFromTiles()
|
||||
baseStatList["Specialists"] = getStatsFromSpecialists(cityInfo.population.specialists, civInfo.policies.adoptedPolicies)
|
||||
baseStatList["Specialists"] = getStatsFromSpecialists(cityInfo.population.getSpecialists(), civInfo.policies.adoptedPolicies)
|
||||
baseStatList["Trade route"] = getStatsFromTradeRoute()
|
||||
baseStatList["Buildings"] = cityInfo.cityConstructions.getStats()
|
||||
baseStatList["Policies"] = getStatsFromPolicies(civInfo.policies.adoptedPolicies)
|
||||
|
@ -221,7 +221,7 @@ class CityStats {
|
|||
baseStatList["Population"]!!.food -= foodEaten // to display it to the user
|
||||
stats.food -= foodEaten // Food reduced after the bonus
|
||||
if (civInfo.policies.isAdopted("Civil Society"))
|
||||
stats.food += cityInfo.population.numberOfSpecialists.toFloat()
|
||||
stats.food += cityInfo.population.getNumberOfSpecialists().toFloat()
|
||||
|
||||
if (isUnhappy) stats.food /= 4f // Reduce excess food to 1/4 per the same
|
||||
stats.food *= 1 + getGrowthBonusFromPolicies()
|
||||
|
@ -234,9 +234,9 @@ class CityStats {
|
|||
|
||||
private fun isConnectedToCapital(roadType: RoadStatus): Boolean {
|
||||
if(cityInfo.civInfo.cities.count()<2) return false// first city!
|
||||
val capitalTile = cityInfo.civInfo.capital.tile
|
||||
val capitalTile = cityInfo.civInfo.capital.getTile()
|
||||
val tilesReached = HashSet<TileInfo>()
|
||||
var tilesToCheck : List<TileInfo> = listOf(cityInfo.tile)
|
||||
var tilesToCheck : List<TileInfo> = listOf(cityInfo.getTile())
|
||||
while (tilesToCheck.isNotEmpty()) {
|
||||
val newTiles = tilesToCheck
|
||||
.flatMap { cityInfo.tileMap.getTilesInDistance(it.position, 1) }.distinct()
|
||||
|
|
|
@ -12,34 +12,30 @@ class PopulationManager {
|
|||
|
||||
@JvmField var buildingsSpecialists = HashMap<String, Stats>()
|
||||
|
||||
val specialists: Stats
|
||||
get() {
|
||||
val allSpecialists = Stats()
|
||||
for (stats in buildingsSpecialists.values)
|
||||
allSpecialists.add(stats)
|
||||
return allSpecialists
|
||||
}
|
||||
fun getSpecialists(): Stats {
|
||||
val allSpecialists = Stats()
|
||||
for (stats in buildingsSpecialists.values)
|
||||
allSpecialists.add(stats)
|
||||
return allSpecialists
|
||||
}
|
||||
|
||||
val numberOfSpecialists: Int
|
||||
get() {
|
||||
val specialists = specialists
|
||||
return (specialists.science + specialists.production + specialists.culture + specialists.gold).toInt()
|
||||
}
|
||||
fun getNumberOfSpecialists(): Int {
|
||||
val specialists = getSpecialists()
|
||||
return (specialists.science + specialists.production + specialists.culture + specialists.gold).toInt()
|
||||
}
|
||||
|
||||
|
||||
// 1 is the city center
|
||||
val freePopulation: Int
|
||||
get() {
|
||||
val workingPopulation = cityInfo!!.tilesInRange.count { cityInfo!!.name == it.workingCity } - 1
|
||||
return population - workingPopulation - numberOfSpecialists
|
||||
}
|
||||
fun getFreePopulation(): Int {
|
||||
val workingPopulation = cityInfo!!.getTilesInRange().count { cityInfo!!.name == it.workingCity } - 1
|
||||
return population - workingPopulation - getNumberOfSpecialists()
|
||||
}
|
||||
|
||||
|
||||
val foodToNextPopulation: Int
|
||||
get() {
|
||||
// civ v math,civilization.wikia
|
||||
return 15 + 6 * (population - 1) + Math.floor(Math.pow((population - 1).toDouble(), 1.8)).toInt()
|
||||
}
|
||||
fun getFoodToNextPopulation(): Int {
|
||||
// civ v math,civilization.wikia
|
||||
return 15 + 6 * (population - 1) + Math.floor(Math.pow((population - 1).toDouble(), 1.8)).toInt()
|
||||
}
|
||||
|
||||
|
||||
fun nextTurn(food: Float) {
|
||||
|
@ -49,21 +45,21 @@ class PopulationManager {
|
|||
{
|
||||
population--
|
||||
foodStored = 0
|
||||
cityInfo!!.civInfo.gameInfo.addNotification(cityInfo!!.name + " is starving!", cityInfo!!.cityLocation)
|
||||
cityInfo!!.civInfo.addNotification(cityInfo!!.name + " is starving!", cityInfo!!.cityLocation)
|
||||
}
|
||||
if (foodStored >= foodToNextPopulation)
|
||||
if (foodStored >= getFoodToNextPopulation())
|
||||
// growth!
|
||||
{
|
||||
foodStored -= foodToNextPopulation
|
||||
if (cityInfo!!.buildingUniques.contains("FoodCarriesOver")) foodStored += (0.4f * foodToNextPopulation).toInt() // Aqueduct special
|
||||
foodStored -= getFoodToNextPopulation()
|
||||
if (cityInfo!!.buildingUniques.contains("FoodCarriesOver")) foodStored += (0.4f * getFoodToNextPopulation()).toInt() // Aqueduct special
|
||||
population++
|
||||
autoAssignWorker()
|
||||
cityInfo!!.civInfo.gameInfo.addNotification(cityInfo!!.name + " has grown!", cityInfo!!.cityLocation)
|
||||
cityInfo!!.civInfo.addNotification(cityInfo!!.name + " has grown!", cityInfo!!.cityLocation)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun autoAssignWorker() {
|
||||
val toWork: TileInfo? = cityInfo!!.tilesInRange.filter { it.workingCity==null }.maxBy { cityInfo!!.rankTile(it) }
|
||||
val toWork: TileInfo? = cityInfo!!.getTilesInRange().filter { it.workingCity==null }.maxBy { cityInfo!!.rankTile(it) }
|
||||
if (toWork != null) // This is when we've run out of tiles!
|
||||
toWork.workingCity = cityInfo!!.name
|
||||
}
|
||||
|
|
|
@ -155,7 +155,7 @@ class CivilizationInfo {
|
|||
fun addGreatPerson(greatPerson: String) {
|
||||
val randomCity = cities.getRandom()
|
||||
placeUnitNearTile(cities.getRandom().cityLocation, greatPerson)
|
||||
gameInfo.addNotification("A $greatPerson has been born!", randomCity.cityLocation)
|
||||
addNotification("A $greatPerson has been born!", randomCity.cityLocation)
|
||||
}
|
||||
|
||||
fun placeUnitNearTile(location: Vector2, unitName: String) {
|
||||
|
@ -175,4 +175,8 @@ class CivilizationInfo {
|
|||
return viewablePositions
|
||||
}
|
||||
|
||||
fun addNotification(text: String, location: Vector2?) {
|
||||
if(isPlayerCivilization())
|
||||
gameInfo.notifications.add(Notification(text, location))
|
||||
}
|
||||
}
|
|
@ -19,7 +19,7 @@ class GoldenAgeManager {
|
|||
if (civInfo.buildingUniques.contains("GoldenAgeLengthIncrease")) turnsToGoldenAge *= 1.5
|
||||
if (civInfo.policies.isAdopted("Freedom Complete")) turnsToGoldenAge *= 1.5
|
||||
turnsLeftForCurrentGoldenAge += turnsToGoldenAge.toInt()
|
||||
civInfo.gameInfo.addNotification("You have entered a golden age!", null)
|
||||
civInfo.addNotification("You have entered a golden age!", null)
|
||||
}
|
||||
|
||||
fun nextTurn(happiness: Int) {
|
||||
|
|
|
@ -53,7 +53,7 @@ class TechManager {
|
|||
techsInProgress.remove(currentTechnology)
|
||||
techsToResearch.remove(currentTechnology)
|
||||
techsResearched.add(currentTechnology)
|
||||
civInfo.gameInfo.addNotification("Research of $currentTechnology has completed!", null)
|
||||
civInfo.addNotification("Research of $currentTechnology has completed!", null)
|
||||
|
||||
val revealedResource = GameBasics.TileResources.values.firstOrNull { currentTechnology == it.revealedBy }
|
||||
|
||||
|
@ -64,7 +64,7 @@ class TechManager {
|
|||
val closestCityTile = civInfo.gameInfo.tileMap.getTilesInDistance(tileInfo.position, 4)
|
||||
.firstOrNull { it.isCityCenter }
|
||||
if (closestCityTile != null) {
|
||||
civInfo.gameInfo.addNotification(
|
||||
civInfo.addNotification(
|
||||
revealedResource.name + " revealed near " + closestCityTile.city!!.name, tileInfo.position)
|
||||
break
|
||||
}
|
||||
|
|
|
@ -149,7 +149,7 @@ class Building : NamedStats(), IConstruction, ICivilopedia {
|
|||
|
||||
|
||||
if (requiredNearbyImprovedResources != null) {
|
||||
val containsResourceWithImprovement = construction.cityInfo.tilesInRange
|
||||
val containsResourceWithImprovement = construction.cityInfo.getTilesInRange()
|
||||
.any {
|
||||
it.resource != null
|
||||
&& requiredNearbyImprovedResources!!.contains(it.resource!!)
|
||||
|
|
|
@ -12,7 +12,7 @@ class Unit : INamed, IConstruction {
|
|||
var cost: Int = 0
|
||||
var hurryCostModifier: Int = 0
|
||||
var movement: Int = 0
|
||||
var strength:Int = 1
|
||||
var strength:Int = 0
|
||||
var rangedStrength:Int = 0
|
||||
lateinit var unitType: UnitType
|
||||
internal var unbuildable: Boolean = false // for special units like great people
|
||||
|
|
|
@ -84,7 +84,7 @@ class BuildingsTable(private val cityScreen: CityScreen) : Table() {
|
|||
val cityInfo = cityScreen.city
|
||||
when {
|
||||
isFilled -> cityInfo.population.buildingsSpecialists[building]!!.add(stat,-1f) //unassign
|
||||
cityInfo.population.freePopulation == 0 -> return@addClickListener
|
||||
cityInfo.population.getFreePopulation() == 0 -> return@addClickListener
|
||||
else -> {
|
||||
if (!cityInfo.population.buildingsSpecialists.containsKey(building))
|
||||
cityInfo.population.buildingsSpecialists[building] = Stats()
|
||||
|
|
|
@ -160,13 +160,13 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
|
|||
update()
|
||||
}
|
||||
|
||||
if (!cityInfo.tilesInRange.contains(tileInfo) || tileInfo.workingCity != null && tileInfo.workingCity != cityInfo.name) {
|
||||
if (!cityInfo.getTilesInRange().contains(tileInfo) || tileInfo.workingCity != null && tileInfo.workingCity != cityInfo.name) {
|
||||
group.setColor(0f, 0f, 0f, 0.3f)
|
||||
group.yieldGroup.isVisible = false
|
||||
} else if (!tileInfo.isCityCenter) {
|
||||
group.addPopulationIcon()
|
||||
group.populationImage!!.addClickListener {
|
||||
if (tileInfo.workingCity == null && cityInfo.population.freePopulation > 0)
|
||||
if (tileInfo.workingCity == null && cityInfo.population.getFreePopulation() > 0)
|
||||
tileInfo.workingCity = cityInfo.name
|
||||
else if (cityInfo.name == tileInfo.workingCity) tileInfo.workingCity = null
|
||||
cityInfo.cityStats.update()
|
||||
|
|
|
@ -30,12 +30,12 @@ class CityStatsTable(val cityScreen: CityScreen) : Table(){
|
|||
val cityStatsValues = LinkedHashMap<String, String>()
|
||||
cityStatsValues["Production"] = Math.round(stats.production).toString() + city.cityConstructions.getAmountConstructedText()
|
||||
cityStatsValues["Food"] = (Math.round(stats.food).toString()
|
||||
+ " (" + city.population.foodStored + "/" + city.population.foodToNextPopulation + ")")
|
||||
+ " (" + city.population.foodStored + "/" + city.population.getFoodToNextPopulation() + ")")
|
||||
cityStatsValues["Gold"] = Math.round(stats.gold).toString() + ""
|
||||
cityStatsValues["Science"] = Math.round(stats.science).toString() + ""
|
||||
cityStatsValues["Culture"] = (Math.round(stats.culture).toString()
|
||||
+ " (" + city.expansion.cultureStored + "/" + city.expansion.cultureToNextTile + ")")
|
||||
cityStatsValues["Population"] = city.population.freePopulation.toString() + "/" + city.population.population
|
||||
cityStatsValues["Population"] = city.population.getFreePopulation().toString() + "/" + city.population.population
|
||||
|
||||
for (key in cityStatsValues.keys) {
|
||||
add(ImageGetter.getStatIcon(key)).align(Align.right)
|
||||
|
|
|
@ -58,7 +58,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen()
|
|||
if (isFreeTechPick) {
|
||||
civTech.techsResearched.add(selectedTech!!.name)
|
||||
civTech.freeTechs -= 1
|
||||
civInfo.gameInfo.addNotification("We have stumbled upon the discovery of " + selectedTech!!.name + "!", null)
|
||||
civInfo.addNotification("We have stumbled upon the discovery of " + selectedTech!!.name + "!", null)
|
||||
if (selectedTech!!.name == civTech.currentTechnology())
|
||||
civTech.techsToResearch.remove(selectedTech!!.name)
|
||||
} else
|
||||
|
|
|
@ -149,12 +149,14 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
|
|||
|
||||
// This is some crazy voodoo magic so I'll explain.
|
||||
|
||||
image.setSize(20f, 2f)
|
||||
image.setSize(40f, 2f)
|
||||
image.moveBy(this.width/2-image.width/2,
|
||||
this.height/2-image.height/2)
|
||||
// in addTiles, we set the position of groups by relative world position *0.8*groupSize, filter groupSize = 50
|
||||
// Here, we want to have the roads start HALFWAY THERE and extend towards the tiles, so we give them a position of 0.8*25.
|
||||
image.moveBy(-relativeWorldPosition.x * 0.8f * 25f, -relativeWorldPosition.y * 0.8f * 25f)
|
||||
// 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!
|
||||
// So we set it to 0.75
|
||||
image.moveBy(-relativeWorldPosition.x * 0.75f * 25f, -relativeWorldPosition.y * 0.75f * 25f)
|
||||
|
||||
image.color = tileInfo.getOwner()!!.getCivilization().getColor()
|
||||
image.setOrigin(image.width/2, image.height/2) // This is so that the rotation is calculated from the middle of the road and not the edge
|
||||
|
|
|
@ -47,6 +47,7 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
|
|||
|
||||
override fun update(isViewable: Boolean) {
|
||||
super.update(isViewable)
|
||||
if (!tileInfo.explored) return
|
||||
|
||||
if (populationImage != null) removePopulationIcon()
|
||||
if (tileInfo.workingCity != null && !tileInfo.isCityCenter && populationImage == null) addPopulationIcon()
|
||||
|
@ -68,9 +69,10 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
|
|||
val labelStyle = Label.LabelStyle(label.style)
|
||||
labelStyle.fontColor= city.civInfo.getCivilization().getColor()
|
||||
label.style=labelStyle
|
||||
label.addClickListener {
|
||||
UnCivGame.Current.screen = CityScreen(city)
|
||||
}
|
||||
if(city.civInfo.isPlayerCivilization())
|
||||
label.addClickListener {
|
||||
UnCivGame.Current.screen = CityScreen(city)
|
||||
}
|
||||
|
||||
cityButton!!.run {
|
||||
clear()
|
||||
|
|
|
@ -3,9 +3,9 @@ package com.unciv.ui.worldscreen
|
|||
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||
import com.unciv.UnCivGame
|
||||
import com.unciv.logic.battle.*
|
||||
import com.unciv.logic.map.UnitType
|
||||
import com.unciv.UnCivGame
|
||||
import com.unciv.ui.cityscreen.addClickListener
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
import com.unciv.ui.utils.disable
|
||||
|
@ -20,9 +20,12 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
|
|||
|
||||
fun update() {
|
||||
if (worldScreen.unitTable.selectedUnit == null
|
||||
|| worldScreen.unitTable.selectedUnit!!.getBaseUnit().unitType == UnitType.Civilian) return // no attacker
|
||||
val attacker = MapUnitCombatant(worldScreen.unitTable.selectedUnit!!)
|
||||
|| worldScreen.unitTable.selectedUnit!!.getBaseUnit().unitType == UnitType.Civilian){
|
||||
clear()
|
||||
return
|
||||
} // no attacker
|
||||
|
||||
val attacker = MapUnitCombatant(worldScreen.unitTable.selectedUnit!!)
|
||||
|
||||
if (worldScreen.tileMapHolder.selectedTile == null) return
|
||||
val selectedTile = worldScreen.tileMapHolder.selectedTile!!
|
||||
|
|
|
@ -1,20 +1,21 @@
|
|||
package com.unciv.ui.worldscreen.unit
|
||||
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||
import com.unciv.UnCivGame
|
||||
import com.unciv.logic.map.MapUnit
|
||||
import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.models.gamebasics.Building
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.UnCivGame
|
||||
import com.unciv.ui.cityscreen.addClickListener
|
||||
import com.unciv.ui.pickerscreens.ImprovementPickerScreen
|
||||
import com.unciv.ui.pickerscreens.TechPickerScreen
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
import com.unciv.ui.utils.disable
|
||||
import com.unciv.ui.utils.enable
|
||||
import com.unciv.ui.worldscreen.WorldScreen
|
||||
import java.util.*
|
||||
|
||||
class UnitAction(var name: String, var action:()->Unit, var canAct:Boolean)
|
||||
|
||||
class UnitActions {
|
||||
|
||||
private fun constructImprovementAndDestroyUnit(tileInfo: TileInfo, improvementName: String): () -> Unit {
|
||||
|
@ -24,35 +25,37 @@ class UnitActions {
|
|||
}
|
||||
}
|
||||
|
||||
fun getUnitActions(unit:MapUnit,worldScreen: WorldScreen): List<TextButton> {
|
||||
fun getUnitActionButtons(unit:MapUnit,worldScreen: WorldScreen): List<TextButton> {
|
||||
return getUnitActions(unit, worldScreen).map { getUnitActionButton(it) }
|
||||
}
|
||||
|
||||
fun getUnitActions(unit:MapUnit,worldScreen: WorldScreen): List<UnitAction> {
|
||||
|
||||
val tile = unit.getTile()
|
||||
|
||||
val tileMapHolder = worldScreen.tileMapHolder
|
||||
val unitTable = worldScreen.unitTable
|
||||
|
||||
val actionList = ArrayList<TextButton>()
|
||||
val actionList = ArrayList<UnitAction>()
|
||||
|
||||
if (unitTable.currentlyExecutingAction != "moveTo"
|
||||
&& (unit.action==null || !unit.action!!.startsWith("moveTo") )){
|
||||
actionList += getUnitActionButton(unit, "Move unit", true, {
|
||||
actionList += UnitAction("Move unit", {
|
||||
unitTable.currentlyExecutingAction = "moveTo"
|
||||
})
|
||||
}, unit.currentMovement != 0f )
|
||||
}
|
||||
|
||||
else {
|
||||
val stopUnitAction =getUnitActionButton(unit, "Stop movement", true, {
|
||||
actionList +=
|
||||
UnitAction("Stop movement", {
|
||||
unitTable.currentlyExecutingAction = null
|
||||
unit.action=null
|
||||
tileMapHolder.updateTiles()
|
||||
})
|
||||
stopUnitAction.enable() // Stopping automation is always enabled;
|
||||
actionList += stopUnitAction
|
||||
},unit.currentMovement != 0f)
|
||||
}
|
||||
|
||||
if (unit.name == "Settler") {
|
||||
actionList += getUnitActionButton(unit, "Found city",
|
||||
!tileMapHolder.tileMap.getTilesInDistance(tile.position, 2).any { it.isCityCenter },
|
||||
actionList += UnitAction("Found city",
|
||||
{
|
||||
worldScreen.displayTutorials("CityFounded")
|
||||
|
||||
|
@ -60,86 +63,91 @@ class UnitActions {
|
|||
unitTable.currentlyExecutingAction = null // In case the settler was in the middle of doing something and we then founded a city with it
|
||||
tile.unit = null // Remove settler!
|
||||
worldScreen.update()
|
||||
})
|
||||
},
|
||||
unit.currentMovement != 0f &&
|
||||
!tileMapHolder.tileMap.getTilesInDistance(tile.position, 2).any { it.isCityCenter })
|
||||
}
|
||||
|
||||
if (unit.name == "Worker") {
|
||||
val improvementButtonText: String
|
||||
if (tile.improvementInProgress == null) improvementButtonText = "Construct\r\nimprovement"
|
||||
else improvementButtonText = tile.improvementInProgress!! + "\r\nin progress"
|
||||
actionList += getUnitActionButton(unit, improvementButtonText,
|
||||
!tile.isCityCenter || GameBasics.TileImprovements.values.any { tile.canBuildImprovement(it, unit.civInfo) },
|
||||
{ worldScreen.game.screen = ImprovementPickerScreen(tile) })
|
||||
actionList += UnitAction(improvementButtonText,
|
||||
{ worldScreen.game.screen = ImprovementPickerScreen(tile) },
|
||||
unit.currentMovement != 0f &&
|
||||
!tile.isCityCenter || GameBasics.TileImprovements.values.any { tile.canBuildImprovement(it, unit.civInfo) })
|
||||
|
||||
if("automation" == unit.action){
|
||||
val automationAction = getUnitActionButton(unit,"Stop automation",true,
|
||||
{unit.action = null})
|
||||
automationAction.enable() // Stopping automation is always enabled;
|
||||
actionList += automationAction
|
||||
actionList += UnitAction("Stop automation",
|
||||
{unit.action = null},unit.currentMovement != 0f)
|
||||
}
|
||||
else {
|
||||
actionList += getUnitActionButton(unit, "Automate", true,
|
||||
actionList += UnitAction("Automate",
|
||||
{
|
||||
tile.unit!!.action = "automation"
|
||||
tile.unit!!.doAutomatedAction()
|
||||
}
|
||||
},unit.currentMovement != 0f
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (unit.name == "Great Scientist") {
|
||||
actionList += getUnitActionButton(unit, "Discover Technology", true,
|
||||
actionList += UnitAction( "Discover Technology",
|
||||
{
|
||||
unit.civInfo.tech.freeTechs += 1
|
||||
tile.unit = null// destroy!
|
||||
worldScreen.game.screen = TechPickerScreen(true, unit.civInfo)
|
||||
|
||||
})
|
||||
actionList += getUnitActionButton(unit, "Construct Academy", true,
|
||||
constructImprovementAndDestroyUnit(tile, "Academy"))
|
||||
},unit.currentMovement != 0f)
|
||||
actionList += UnitAction("Construct Academy",
|
||||
constructImprovementAndDestroyUnit(tile, "Academy"),unit.currentMovement != 0f)
|
||||
}
|
||||
|
||||
if (unit.name == "Great Artist") {
|
||||
actionList += getUnitActionButton(unit, "Start Golden Age", true,
|
||||
actionList += UnitAction( "Start Golden Age",
|
||||
{
|
||||
unit.civInfo.goldenAges.enterGoldenAge()
|
||||
tile.unit = null// destroy!
|
||||
worldScreen.update()
|
||||
}
|
||||
},unit.currentMovement != 0f
|
||||
)
|
||||
actionList += getUnitActionButton(unit, "Construct Landmark", true,
|
||||
constructImprovementAndDestroyUnit(tile, "Landmark"))
|
||||
actionList += UnitAction("Construct Landmark",
|
||||
constructImprovementAndDestroyUnit(tile, "Landmark"),unit.currentMovement != 0f)
|
||||
}
|
||||
|
||||
if (unit.name == "Great Engineer") {
|
||||
actionList += getUnitActionButton(unit, "Hurry Wonder", tile.isCityCenter &&
|
||||
tile.city!!.cityConstructions.getCurrentConstruction() is Building &&
|
||||
(tile.city!!.cityConstructions.getCurrentConstruction() as Building).isWonder,
|
||||
actionList += UnitAction( "Hurry Wonder",
|
||||
{
|
||||
tile.city!!.cityConstructions.addConstruction(300 + 30 * tile.city!!.population.population) //http://civilization.wikia.com/wiki/Great_engineer_(Civ5)
|
||||
tile.unit = null // destroy!
|
||||
})
|
||||
actionList += getUnitActionButton(unit, "Construct Manufactory", true,
|
||||
constructImprovementAndDestroyUnit(tile, "Manufactory"))
|
||||
},
|
||||
unit.currentMovement != 0f &&
|
||||
tile.isCityCenter &&
|
||||
tile.city!!.cityConstructions.getCurrentConstruction() is Building &&
|
||||
(tile.city!!.cityConstructions.getCurrentConstruction() as Building).isWonder)
|
||||
|
||||
actionList += UnitAction("Construct Manufactory",
|
||||
constructImprovementAndDestroyUnit(tile, "Manufactory"),unit.currentMovement != 0f)
|
||||
}
|
||||
|
||||
if (unit.name == "Great Merchant") {
|
||||
actionList += getUnitActionButton(unit, "Conduct Trade Mission", true,
|
||||
actionList += UnitAction("Conduct Trade Mission",
|
||||
{
|
||||
unit.civInfo.gold += 350 // + 50 * era_number - todo!
|
||||
tile.unit = null // destroy!
|
||||
})
|
||||
actionList += getUnitActionButton(unit, "Construct Customs House", true,
|
||||
constructImprovementAndDestroyUnit(tile, "Customs House"))
|
||||
},unit.currentMovement != 0f)
|
||||
actionList += UnitAction( "Construct Customs House",
|
||||
constructImprovementAndDestroyUnit(tile, "Customs House"),
|
||||
unit.currentMovement != 0f)
|
||||
}
|
||||
|
||||
return actionList
|
||||
}
|
||||
|
||||
private fun getUnitActionButton(unit: MapUnit, actionText: String, canAct: Boolean, action: () -> Unit): TextButton {
|
||||
val actionButton = TextButton(actionText, CameraStageBaseScreen.skin)
|
||||
actionButton.addClickListener({ action(); UnCivGame.Current.worldScreen!!.update() })
|
||||
if (unit.currentMovement == 0f || !canAct) actionButton.disable()
|
||||
private fun getUnitActionButton(unitAction: UnitAction): TextButton {
|
||||
val actionButton = TextButton(unitAction.name, CameraStageBaseScreen.skin)
|
||||
actionButton.addClickListener({ unitAction.action(); UnCivGame.Current.worldScreen!!.update() })
|
||||
if (!unitAction.canAct) actionButton.disable()
|
||||
return actionButton
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
|
|||
|
||||
unitLabel.setText(unitLabelText)
|
||||
|
||||
for (button in UnitActions().getUnitActions(selectedUnit!!, worldScreen))
|
||||
for (button in UnitActions().getUnitActionButtons(selectedUnit!!, worldScreen))
|
||||
unitActionsTable.add(button).colspan(2).pad(5f)
|
||||
.size(button.width * worldScreen.buttonScale, button.height * worldScreen.buttonScale).row()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue