mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-04 15:27:50 +07:00
Entiirely removed Linq - now only using Kotlin extensions!
This commit is contained in:
@ -4,14 +4,13 @@ import com.badlogic.gdx.math.Vector2
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.logic.civilization.Notification
|
||||
import com.unciv.logic.map.TileMap
|
||||
import com.unciv.models.linq.Linq
|
||||
|
||||
class GameInfo {
|
||||
|
||||
var notifications = Linq<Notification>()
|
||||
var notifications = mutableListOf<Notification>()
|
||||
|
||||
var tutorial = Linq<String>()
|
||||
var civilizations = Linq<CivilizationInfo>()
|
||||
var tutorial = mutableListOf<String>()
|
||||
var civilizations = mutableListOf<CivilizationInfo>()
|
||||
var tileMap: TileMap = TileMap()
|
||||
var turns = 1
|
||||
|
||||
@ -26,15 +25,18 @@ class GameInfo {
|
||||
|
||||
for (civInfo in civilizations) civInfo.nextTurn()
|
||||
|
||||
for (tile in tileMap.values.where { it.unit != null })
|
||||
for (tile in tileMap.values.filter { it.unit != null })
|
||||
tile.nextTurn()
|
||||
|
||||
// We need to update the stats after ALL the cities are done updating because
|
||||
// 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){
|
||||
for (city in civInfo.cities)
|
||||
city.cityStats.update()
|
||||
civInfo.happiness = civInfo.getHappinessForNextTurn()
|
||||
}
|
||||
|
||||
|
||||
turns++
|
||||
}
|
||||
|
@ -1,26 +1,24 @@
|
||||
package com.unciv.logic.city
|
||||
|
||||
import com.unciv.models.linq.Linq
|
||||
import com.unciv.models.gamebasics.Building
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.models.stats.Stats
|
||||
|
||||
import java.util.HashMap
|
||||
import java.util.*
|
||||
|
||||
|
||||
class CityConstructions {
|
||||
@Transient
|
||||
lateinit var cityInfo: CityInfo
|
||||
|
||||
var builtBuildings = Linq<String>()
|
||||
var builtBuildings = ArrayList<String>()
|
||||
private val inProgressConstructions = HashMap<String, Int>()
|
||||
var currentConstruction: String = "Monument" // default starting building!
|
||||
|
||||
|
||||
private val buildableBuildings: Linq<String>
|
||||
private val buildableBuildings: List<String>
|
||||
get() {
|
||||
return Linq(GameBasics.Buildings.values)
|
||||
.where { it.isBuildable(this) }.select { it.name }
|
||||
return GameBasics.Buildings.values
|
||||
.filter { it.isBuildable(this) }.map { it.name }
|
||||
}
|
||||
|
||||
// Library and public school unique (not actualy unique, though...hmm)
|
||||
@ -36,7 +34,7 @@ class CityConstructions {
|
||||
|
||||
fun getStatPercentBonuses(): Stats {
|
||||
val stats = Stats()
|
||||
for (building in getBuiltBuildings().where { it.percentStatBonus != null })
|
||||
for (building in getBuiltBuildings().filter { it.percentStatBonus != null })
|
||||
stats.add(building.percentStatBonus!!)
|
||||
return stats
|
||||
}
|
||||
@ -75,7 +73,7 @@ class CityConstructions {
|
||||
throw Exception(constructionName+ " is not a building or a unit!")
|
||||
}
|
||||
|
||||
internal fun getBuiltBuildings(): Linq<Building> = builtBuildings.select { GameBasics.Buildings[it] }
|
||||
internal fun getBuiltBuildings(): List<Building> = builtBuildings.map { GameBasics.Buildings[it]!! }
|
||||
|
||||
fun addConstruction(constructionToAdd: Int) {
|
||||
if (!inProgressConstructions.containsKey(currentConstruction)) inProgressConstructions[currentConstruction] = 0
|
||||
@ -139,7 +137,7 @@ class CityConstructions {
|
||||
}
|
||||
|
||||
fun addCultureBuilding() {
|
||||
val cultureBuildingToBuild = Linq("Monument", "Temple", "Opera House", "Museum").first { !builtBuildings.contains(it) }
|
||||
val cultureBuildingToBuild = listOf("Monument", "Temple", "Opera House", "Museum").firstOrNull { !builtBuildings.contains(it) }
|
||||
if (cultureBuildingToBuild == null) return
|
||||
builtBuildings.add(cultureBuildingToBuild)
|
||||
if (currentConstruction == cultureBuildingToBuild)
|
||||
|
@ -25,7 +25,7 @@ class CityExpansionManager {
|
||||
cultureStored -= cultureToNextTile
|
||||
|
||||
for (i in 2..3) {
|
||||
val tiles = cityInfo.civInfo.gameInfo.tileMap.getTilesInDistance(cityInfo.cityLocation, i).where { it.owner == null }
|
||||
val tiles = cityInfo.civInfo.gameInfo.tileMap.getTilesInDistance(cityInfo.cityLocation, i).filter { it.owner == null }
|
||||
if (tiles.size == 0) continue
|
||||
val chosenTile = tiles.maxBy { cityInfo.rankTile(it) }
|
||||
chosenTile!!.owner = cityInfo.civInfo.civName
|
||||
|
@ -5,10 +5,9 @@ import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.logic.map.RoadStatus
|
||||
import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.logic.map.TileMap
|
||||
import com.unciv.models.linq.Linq
|
||||
import com.unciv.models.linq.LinqCounter
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.models.gamebasics.TileResource
|
||||
import com.unciv.models.linq.Counter
|
||||
import com.unciv.models.stats.Stats
|
||||
|
||||
class CityInfo {
|
||||
@ -27,14 +26,14 @@ class CityInfo {
|
||||
|
||||
val tile: TileInfo
|
||||
get() = tileMap[cityLocation]
|
||||
val tilesInRange: Linq<TileInfo>
|
||||
get() = tileMap.getTilesInDistance(cityLocation, 3).where { civInfo.civName == it.owner }
|
||||
val tilesInRange: List<TileInfo>
|
||||
get() = tileMap.getTilesInDistance(cityLocation, 3).filter { civInfo.civName == it.owner }
|
||||
|
||||
private val CityNames = arrayOf("New Bark", "Cherrygrove", "Violet", "Azalea", "Goldenrod", "Ecruteak", "Olivine", "Cianwood", "Mahogany", "Blackthorn", "Pallet", "Viridian", "Pewter", "Cerulean", "Vermillion", "Lavender", "Celadon", "Fuchsia", "Saffron", "Cinnibar")
|
||||
|
||||
// Remove resources required by buildings
|
||||
fun getCityResources(): LinqCounter<TileResource> {
|
||||
val cityResources = LinqCounter<TileResource>()
|
||||
fun getCityResources(): Counter<TileResource> {
|
||||
val cityResources = Counter<TileResource>()
|
||||
|
||||
for (tileInfo in tilesInRange.filter { it.resource != null }) {
|
||||
val resource = tileInfo.tileResource
|
||||
@ -49,8 +48,8 @@ class CityInfo {
|
||||
return cityResources
|
||||
}
|
||||
|
||||
val buildingUniques: Linq<String>
|
||||
get() = cityConstructions.getBuiltBuildings().where { it.unique!=null }.select { it.unique }
|
||||
val buildingUniques: List<String?>
|
||||
get() = cityConstructions.getBuiltBuildings().filter { it.unique!=null }.map { it.unique }
|
||||
|
||||
val greatPersonPoints: Stats
|
||||
get() {
|
||||
@ -95,7 +94,7 @@ class CityInfo {
|
||||
val tile = tile
|
||||
tile.workingCity = this.name
|
||||
tile.roadStatus = RoadStatus.Railroad
|
||||
if (Linq("Forest", "Jungle", "Marsh").contains(tile.terrainFeature))
|
||||
if (listOf("Forest", "Jungle", "Marsh").contains(tile.terrainFeature))
|
||||
tile.terrainFeature = null
|
||||
|
||||
population.autoAssignWorker()
|
||||
|
@ -4,7 +4,6 @@ import com.unciv.logic.map.RoadStatus
|
||||
import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.models.gamebasics.Building
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.models.linq.Linq
|
||||
import com.unciv.models.stats.Stats
|
||||
|
||||
|
||||
@ -16,7 +15,7 @@ class CityStats {
|
||||
private val statsFromTiles: Stats
|
||||
get() {
|
||||
val stats = Stats()
|
||||
for (cell in cityInfo.tilesInRange.where { cityInfo.name == it.workingCity })
|
||||
for (cell in cityInfo.tilesInRange.filter { cityInfo.name == it.workingCity })
|
||||
stats.add(cell.getTileStats(cityInfo, cityInfo.civInfo))
|
||||
return stats
|
||||
}
|
||||
@ -98,35 +97,34 @@ class CityStats {
|
||||
// needs to be a separate function because we need to know the global happiness state
|
||||
// in order to determine how much food is produced in a city!
|
||||
// -3 happiness per city
|
||||
val cityHappiness: Float
|
||||
get() {
|
||||
val civInfo = cityInfo.civInfo
|
||||
var happiness = -3f
|
||||
var unhappinessFromCitizens = cityInfo.population.population.toFloat()
|
||||
if (civInfo.policies.isAdopted("Democracy"))
|
||||
unhappinessFromCitizens -= cityInfo.population.numberOfSpecialists * 0.5f
|
||||
if (civInfo.buildingUniques.contains("CitizenUnhappinessDecreased"))
|
||||
unhappinessFromCitizens *= 0.9f
|
||||
if (civInfo.policies.isAdopted("Aristocracy"))
|
||||
unhappinessFromCitizens *= 0.95f
|
||||
happiness -= unhappinessFromCitizens
|
||||
fun getCityHappiness(): Float {
|
||||
val civInfo = cityInfo.civInfo
|
||||
var happiness = -3f
|
||||
var unhappinessFromCitizens = cityInfo.population.population.toFloat()
|
||||
if (civInfo.policies.isAdopted("Democracy"))
|
||||
unhappinessFromCitizens -= cityInfo.population.numberOfSpecialists * 0.5f
|
||||
if (civInfo.buildingUniques.contains("CitizenUnhappinessDecreased"))
|
||||
unhappinessFromCitizens *= 0.9f
|
||||
if (civInfo.policies.isAdopted("Aristocracy"))
|
||||
unhappinessFromCitizens *= 0.95f
|
||||
happiness -= unhappinessFromCitizens
|
||||
|
||||
if (civInfo.policies.isAdopted("Aristocracy"))
|
||||
happiness += (cityInfo.population.population / 10).toFloat()
|
||||
if (civInfo.policies.isAdopted("Monarchy") && isCapital)
|
||||
happiness += (cityInfo.population.population / 2).toFloat()
|
||||
if (civInfo.policies.isAdopted("Meritocracy") && isConnectedToCapital(RoadStatus.Road))
|
||||
happiness += 1f
|
||||
if (civInfo.policies.isAdopted("Aristocracy"))
|
||||
happiness += (cityInfo.population.population / 10).toFloat()
|
||||
if (civInfo.policies.isAdopted("Monarchy") && isCapital)
|
||||
happiness += (cityInfo.population.population / 2).toFloat()
|
||||
if (civInfo.policies.isAdopted("Meritocracy") && isConnectedToCapital(RoadStatus.Road))
|
||||
happiness += 1f
|
||||
|
||||
happiness += cityInfo.cityConstructions.getStats().happiness.toInt().toFloat()
|
||||
happiness += cityInfo.cityConstructions.getStats().happiness.toInt().toFloat()
|
||||
|
||||
return happiness
|
||||
}
|
||||
return happiness
|
||||
}
|
||||
|
||||
private val isCapital: Boolean
|
||||
get() = cityInfo.civInfo.capital === cityInfo
|
||||
|
||||
private fun getStatsFromSpecialists(specialists: Stats, policies: Linq<String>): Stats {
|
||||
private fun getStatsFromSpecialists(specialists: Stats, policies: List<String>): Stats {
|
||||
val stats = Stats()
|
||||
|
||||
// Specialists
|
||||
@ -141,7 +139,7 @@ class CityStats {
|
||||
return stats
|
||||
}
|
||||
|
||||
private fun getStatsFromPolicies(adoptedPolicies: Linq<String>): Stats {
|
||||
private fun getStatsFromPolicies(adoptedPolicies: List<String>): Stats {
|
||||
val stats = Stats()
|
||||
if (adoptedPolicies.contains("Tradition") && isCapital)
|
||||
stats.culture += 3f
|
||||
@ -169,7 +167,7 @@ class CityStats {
|
||||
return stats
|
||||
}
|
||||
|
||||
private fun getStatPercentBonusesFromPolicies(policies: Linq<String>, cityConstructions: CityConstructions): Stats {
|
||||
private fun getStatPercentBonusesFromPolicies(policies: List<String>, cityConstructions: CityConstructions): Stats {
|
||||
val stats = Stats()
|
||||
|
||||
if (policies.contains("Collective Rule") && isCapital
|
||||
@ -239,7 +237,7 @@ class CityStats {
|
||||
if(cityInfo.civInfo.cities.count()<2) return false// first city!
|
||||
val capitalTile = cityInfo.civInfo.capital.tile
|
||||
val tilesReached = HashSet<TileInfo>()
|
||||
var tilesToCheck : List<TileInfo> = Linq<TileInfo>(cityInfo.tile)
|
||||
var tilesToCheck : List<TileInfo> = listOf(cityInfo.tile)
|
||||
while (tilesToCheck.any()) {
|
||||
val newTiles = tilesToCheck
|
||||
.flatMap { cityInfo.tileMap.getTilesInDistance(it.position, 1) }.distinct()
|
||||
|
@ -1,11 +1,10 @@
|
||||
package com.unciv.logic.city
|
||||
|
||||
import com.unciv.models.linq.Linq
|
||||
import com.unciv.models.stats.INamed
|
||||
|
||||
interface IConstruction : INamed {
|
||||
fun getProductionCost(adoptedPolicies: Linq<String>): Int
|
||||
fun getGoldCost(adoptedPolicies: Linq<String>): Int
|
||||
fun getProductionCost(adoptedPolicies: List<String>): Int
|
||||
fun getGoldCost(adoptedPolicies: List<String>): Int
|
||||
fun isBuildable(construction: CityConstructions): Boolean
|
||||
fun postBuildEvent(construction: CityConstructions) // Yes I'm hilarious.
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.unciv.logic.city
|
||||
|
||||
import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.models.linq.LinqHashMap
|
||||
import com.unciv.models.stats.Stats
|
||||
|
||||
class PopulationManager {
|
||||
@ -11,7 +10,7 @@ class PopulationManager {
|
||||
@JvmField var population = 1
|
||||
@JvmField var foodStored = 0
|
||||
|
||||
@JvmField var buildingsSpecialists = LinqHashMap<String, Stats>()
|
||||
@JvmField var buildingsSpecialists = HashMap<String, Stats>()
|
||||
|
||||
val specialists: Stats
|
||||
get() {
|
||||
@ -64,7 +63,7 @@ class PopulationManager {
|
||||
}
|
||||
|
||||
internal fun autoAssignWorker() {
|
||||
var toWork: TileInfo? = cityInfo!!.tilesInRange.where { it.workingCity==null }.maxBy { cityInfo!!.rankTile(it) }
|
||||
val toWork: TileInfo? = cityInfo!!.tilesInRange.filter { it.workingCity==null }.maxBy { cityInfo!!.rankTile(it) }
|
||||
if (toWork != null) // This is when we've run out of tiles!
|
||||
toWork.workingCity = cityInfo!!.name
|
||||
}
|
||||
|
@ -1,14 +1,13 @@
|
||||
package com.unciv.logic.civilization
|
||||
|
||||
import com.badlogic.gdx.math.Vector2
|
||||
import com.unciv.logic.GameInfo
|
||||
import com.unciv.logic.city.CityInfo
|
||||
import com.unciv.logic.map.RoadStatus
|
||||
import com.unciv.logic.GameInfo
|
||||
import com.unciv.models.linq.Linq
|
||||
import com.unciv.models.linq.LinqCounter
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.models.gamebasics.ResourceType
|
||||
import com.unciv.models.gamebasics.TileResource
|
||||
import com.unciv.models.linq.Counter
|
||||
import com.unciv.models.stats.Stats
|
||||
|
||||
|
||||
@ -27,7 +26,7 @@ class CivilizationInfo {
|
||||
private var greatPeople = GreatPersonManager()
|
||||
var scienceVictory = ScienceVictoryManager()
|
||||
|
||||
var cities = Linq<CityInfo>()
|
||||
var cities = ArrayList<CityInfo>()
|
||||
|
||||
val capital: CityInfo
|
||||
get() = cities.first { it.cityConstructions.isBuilt("Palace") }
|
||||
@ -61,26 +60,26 @@ class CivilizationInfo {
|
||||
}
|
||||
|
||||
// base happiness
|
||||
private fun getHappinessForNextTurn(): Int {
|
||||
fun getHappinessForNextTurn(): Int {
|
||||
var happiness = 15
|
||||
var happinessPerUniqueLuxury = 5
|
||||
if (policies.isAdopted("Protectionism")) happinessPerUniqueLuxury += 1
|
||||
happiness += getCivResources().keys
|
||||
.count { it.resourceType === ResourceType.Luxury } * happinessPerUniqueLuxury
|
||||
happiness += cities.sumBy { it.cityStats.cityHappiness.toInt() }
|
||||
happiness += cities.sumBy { it.cityStats.getCityHappiness().toInt() }
|
||||
if (buildingUniques.contains("HappinessPerSocialPolicy"))
|
||||
happiness += policies.getAdoptedPolicies().count { !it.endsWith("Complete") }
|
||||
return happiness
|
||||
}
|
||||
|
||||
fun getCivResources(): LinqCounter<TileResource> {
|
||||
val civResources = LinqCounter<TileResource>()
|
||||
fun getCivResources(): Counter<TileResource> {
|
||||
val civResources = Counter<TileResource>()
|
||||
for (city in cities) civResources.add(city.getCityResources())
|
||||
return civResources
|
||||
}
|
||||
|
||||
val buildingUniques: Linq<String>
|
||||
get() = cities.selectMany { it.cityConstructions.getBuiltBuildings().select { it.unique }.filterNotNull() }.unique()
|
||||
val buildingUniques: List<String>
|
||||
get() = cities.flatMap{ it.cityConstructions.getBuiltBuildings().map { it.unique }.filterNotNull() }.distinct()
|
||||
|
||||
|
||||
constructor()
|
||||
@ -115,7 +114,6 @@ class CivilizationInfo {
|
||||
|
||||
fun nextTurn() {
|
||||
val nextTurnStats = getStatsForNextTurn()
|
||||
happiness = nextTurnStats.happiness.toInt()
|
||||
policies.nextTurn(nextTurnStats.culture.toInt())
|
||||
gold += nextTurnStats.gold.toInt()
|
||||
|
||||
@ -135,9 +133,9 @@ class CivilizationInfo {
|
||||
}
|
||||
|
||||
fun addGreatPerson(greatPerson: String) {
|
||||
val randomCity = cities.random
|
||||
placeUnitNearTile(cities.random.cityLocation, greatPerson)
|
||||
gameInfo.addNotification("A $greatPerson has been born!", randomCity!!.cityLocation)
|
||||
val randomCity = cities.getRandom()
|
||||
placeUnitNearTile(cities.getRandom().cityLocation, greatPerson)
|
||||
gameInfo.addNotification("A $greatPerson has been born!", randomCity.cityLocation)
|
||||
}
|
||||
|
||||
fun placeUnitNearTile(location: Vector2, unitName: String) {
|
||||
@ -145,3 +143,4 @@ class CivilizationInfo {
|
||||
}
|
||||
}
|
||||
|
||||
fun <E> List<E>.getRandom(): E = if (size == 0) throw Exception() else get((Math.random() * size).toInt())
|
@ -2,7 +2,6 @@ package com.unciv.logic.civilization
|
||||
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.models.gamebasics.Policy
|
||||
import com.unciv.models.linq.Linq
|
||||
import com.unciv.ui.UnCivGame
|
||||
import com.unciv.ui.pickerscreens.GreatPersonPickerScreen
|
||||
|
||||
@ -14,7 +13,7 @@ class PolicyManager {
|
||||
|
||||
var freePolicies = 0
|
||||
var storedCulture = 0
|
||||
internal val adoptedPolicies = Linq<String>()
|
||||
internal val adoptedPolicies = ArrayList<String>()
|
||||
var shouldOpenPolicyPicker = false
|
||||
|
||||
// from https://forums.civfanatics.com/threads/the-number-crunching-thread.389702/
|
||||
@ -31,7 +30,7 @@ class PolicyManager {
|
||||
}
|
||||
|
||||
|
||||
fun getAdoptedPolicies(): Linq<String> = adoptedPolicies
|
||||
fun getAdoptedPolicies(): List<String> = adoptedPolicies
|
||||
|
||||
fun isAdopted(policyName: String): Boolean = adoptedPolicies.contains(policyName)
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
package com.unciv.logic.civilization
|
||||
|
||||
import com.unciv.models.linq.LinqCounter
|
||||
import com.unciv.models.linq.Counter
|
||||
|
||||
class ScienceVictoryManager {
|
||||
|
||||
var requiredParts = LinqCounter<String>()
|
||||
var currentParts = LinqCounter<String>()
|
||||
var requiredParts = Counter<String>()
|
||||
var currentParts = Counter<String>()
|
||||
|
||||
fun unconstructedParts(): LinqCounter<String> {
|
||||
fun unconstructedParts(): Counter<String> {
|
||||
val counter = requiredParts.clone()
|
||||
counter.remove(currentParts)
|
||||
return counter
|
||||
|
@ -1,12 +1,9 @@
|
||||
package com.unciv.logic.civilization
|
||||
|
||||
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.models.gamebasics.Technology
|
||||
|
||||
|
||||
import java.util.ArrayList
|
||||
import java.util.HashMap
|
||||
import java.util.HashSet
|
||||
import java.util.*
|
||||
|
||||
class TechManager {
|
||||
@Transient
|
||||
@ -54,14 +51,14 @@ class TechManager {
|
||||
techsResearched.add(currentTechnology)
|
||||
civInfo.gameInfo.addNotification("Research of $currentTechnology has completed!", null)
|
||||
|
||||
val revealedResource = GameBasics.TileResources.linqValues().first { currentTechnology == it.revealedBy }
|
||||
val revealedResource = GameBasics.TileResources.values.firstOrNull { currentTechnology == it.revealedBy }
|
||||
|
||||
if (revealedResource == null) return
|
||||
for (tileInfo in civInfo.gameInfo.tileMap.values
|
||||
.where { it.resource == revealedResource.name && civInfo.civName == it.owner }) {
|
||||
.filter { it.resource == revealedResource.name && civInfo.civName == it.owner }) {
|
||||
|
||||
val closestCityTile = civInfo.gameInfo.tileMap.getTilesInDistance(tileInfo.position, 4)
|
||||
.first { it.isCityCenter }
|
||||
.firstOrNull { it.isCityCenter }
|
||||
if (closestCityTile != null) {
|
||||
civInfo.gameInfo.addNotification(
|
||||
revealedResource.name + " revealed near " + closestCityTile.city!!.name, tileInfo.position)
|
||||
|
@ -54,30 +54,19 @@ class MapUnit {
|
||||
|
||||
private fun getPriority(tileInfo: TileInfo): Int {
|
||||
var priority = 0
|
||||
if (tileInfo.workingCity != null) priority += 2
|
||||
if (tileInfo.hasViewableResource(civInfo)) priority += 1
|
||||
if (tileInfo.workingCity != null) priority += 3
|
||||
if (tileInfo.owner == owner) priority += 2
|
||||
if (tileInfo.hasViewableResource(civInfo)) priority += 1
|
||||
else if (tileInfo.neighbors.any { it.owner != null }) priority += 1
|
||||
return priority
|
||||
}
|
||||
|
||||
private fun findTileToWork(currentTile: TileInfo): TileInfo {
|
||||
var selectedTile = currentTile
|
||||
var selectedTilePriority =
|
||||
if (currentTile.improvement == null && currentTile.canBuildImprovement(chooseImprovement(currentTile), civInfo))
|
||||
getPriority(currentTile)
|
||||
else
|
||||
1 // min rank to get selected is 2
|
||||
|
||||
for (i in 1..4)
|
||||
for (tile in civInfo.gameInfo.tileMap.getTilesAtDistance(currentTile.position, i))
|
||||
if (tile.unit == null && tile.improvement == null && getPriority(tile) > selectedTilePriority
|
||||
&& tile.canBuildImprovement(chooseImprovement(tile), civInfo)) {
|
||||
selectedTile = tile
|
||||
selectedTilePriority = getPriority(tile)
|
||||
}
|
||||
|
||||
return selectedTile
|
||||
val selectedTile = civInfo.gameInfo.tileMap.getTilesInDistance(currentTile.position, 4)
|
||||
.filter { (it.unit==null || it==currentTile ) && it.improvement==null && it.canBuildImprovement(chooseImprovement(it),civInfo) }
|
||||
.maxBy { getPriority(it) }
|
||||
if(selectedTile!=null && getPriority(selectedTile) > 1) return selectedTile
|
||||
else return currentTile
|
||||
}
|
||||
|
||||
fun doAutomatedAction(tile: TileInfo) {
|
||||
|
@ -1,12 +1,11 @@
|
||||
package com.unciv.logic.map
|
||||
|
||||
import com.badlogic.gdx.math.Vector2
|
||||
import com.unciv.logic.civilization.getRandom
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.models.gamebasics.ResourceType
|
||||
import com.unciv.models.gamebasics.TerrainType
|
||||
import com.unciv.models.gamebasics.TileResource
|
||||
import com.unciv.models.linq.Linq
|
||||
import com.unciv.models.linq.LinqHashMap
|
||||
import com.unciv.ui.utils.HexMath
|
||||
|
||||
class RandomMapGenerator {
|
||||
@ -14,15 +13,15 @@ class RandomMapGenerator {
|
||||
private fun addRandomTile(position: Vector2): TileInfo {
|
||||
val tileInfo = TileInfo()
|
||||
tileInfo.position = position
|
||||
val terrains = GameBasics.Terrains.linqValues()
|
||||
val terrains = GameBasics.Terrains.values
|
||||
|
||||
val baseTerrain = terrains.where { it.type === TerrainType.BaseTerrain && it.name != "Lakes" }.random
|
||||
tileInfo.baseTerrain = baseTerrain!!.name
|
||||
val baseTerrain = terrains.filter { it.type === TerrainType.BaseTerrain && it.name != "Lakes" }.getRandom()
|
||||
tileInfo.baseTerrain = baseTerrain.name
|
||||
|
||||
if (baseTerrain.canHaveOverlay) {
|
||||
if (Math.random() > 0.7f) {
|
||||
val SecondaryTerrain = terrains.where { it.type === TerrainType.TerrainFeature && it.occursOn!!.contains(baseTerrain.name) }.random
|
||||
if (SecondaryTerrain != null) tileInfo.terrainFeature = SecondaryTerrain.name
|
||||
val secondaryTerrains = terrains.filter { it.type === TerrainType.TerrainFeature && it.occursOn!!.contains(baseTerrain.name) }
|
||||
if (secondaryTerrains.any()) tileInfo.terrainFeature = secondaryTerrains.getRandom().name
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,31 +30,29 @@ class RandomMapGenerator {
|
||||
return tileInfo
|
||||
}
|
||||
|
||||
internal fun addRandomResourceToTile(tileInfo: TileInfo) {
|
||||
private fun addRandomResourceToTile(tileInfo: TileInfo) {
|
||||
|
||||
var TileResources = GameBasics.TileResources.linqValues()
|
||||
var tileResources = GameBasics.TileResources.values.toList()
|
||||
|
||||
// Resources are placed according to TerrainFeature, if exists, otherwise according to BaseLayer.
|
||||
TileResources = TileResources.where { it.terrainsCanBeFoundOn.contains(tileInfo.lastTerrain.name) }
|
||||
tileResources = tileResources.filter { it.terrainsCanBeFoundOn.contains(tileInfo.lastTerrain.name) }
|
||||
|
||||
var resource: TileResource? = null
|
||||
if (Math.random() < 1 / 5f) {
|
||||
resource = GetRandomResource(TileResources, ResourceType.Bonus)
|
||||
} else if (Math.random() < 1 / 7f) {
|
||||
resource = GetRandomResource(TileResources, ResourceType.Strategic)
|
||||
} else if (Math.random() < 1 / 15f) {
|
||||
resource = GetRandomResource(TileResources, ResourceType.Luxury)
|
||||
when {
|
||||
Math.random() < 1 / 5f -> resource = getRandomResource(tileResources, ResourceType.Bonus)
|
||||
Math.random() < 1 / 7f -> resource = getRandomResource(tileResources, ResourceType.Strategic)
|
||||
Math.random() < 1 / 15f -> resource = getRandomResource(tileResources, ResourceType.Luxury)
|
||||
}
|
||||
if (resource != null) tileInfo.resource = resource.name
|
||||
}
|
||||
|
||||
internal fun GetRandomResource(resources: Linq<TileResource>, resourceType: ResourceType): TileResource? {
|
||||
return resources.where { it.resourceType == resourceType }.random
|
||||
private fun getRandomResource(resources: List<TileResource>, resourceType: ResourceType): TileResource? {
|
||||
return resources.filter { it.resourceType == resourceType }.getRandom()
|
||||
}
|
||||
|
||||
|
||||
fun generateMap(distance: Int): LinqHashMap<String, TileInfo> {
|
||||
val map = LinqHashMap<String, TileInfo>()
|
||||
fun generateMap(distance: Int): HashMap<String, TileInfo> {
|
||||
val map = HashMap<String, TileInfo>()
|
||||
for (vector in HexMath.GetVectorsInDistance(Vector2.Zero, distance))
|
||||
map[vector.toString()] = addRandomTile(vector)
|
||||
return map
|
||||
|
@ -7,7 +7,6 @@ import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.models.gamebasics.Terrain
|
||||
import com.unciv.models.gamebasics.TileImprovement
|
||||
import com.unciv.models.gamebasics.TileResource
|
||||
import com.unciv.models.linq.Linq
|
||||
import com.unciv.models.stats.Stats
|
||||
|
||||
class TileInfo {
|
||||
@ -33,21 +32,21 @@ class TileInfo {
|
||||
get() = if (terrainFeature == null) getBaseTerrain() else getTerrainFeature()!!
|
||||
|
||||
val tileResource: TileResource
|
||||
get() = if (resource == null) throw Exception("No resource exists for this tile!") else GameBasics.TileResources[resource]!!
|
||||
get() = if (resource == null) throw Exception("No resource exists for this tile!") else GameBasics.TileResources[resource!!]!!
|
||||
|
||||
val isCityCenter: Boolean
|
||||
get() = city != null && position == city!!.cityLocation
|
||||
|
||||
val tileImprovement: TileImprovement?
|
||||
get() = if (improvement == null) null else GameBasics.TileImprovements[improvement]
|
||||
get() = if (improvement == null) null else GameBasics.TileImprovements[improvement!!]
|
||||
|
||||
val neighbors: Linq<TileInfo>
|
||||
val neighbors: List<TileInfo>
|
||||
get() = tileMap!!.getTilesAtDistance(position, 1)
|
||||
|
||||
val height: Int
|
||||
get() {
|
||||
var height = 0
|
||||
if (Linq("Forest", "Jungle").contains(terrainFeature)) height += 1
|
||||
if (listOf("Forest", "Jungle").contains(terrainFeature)) height += 1
|
||||
if ("Hill" == baseTerrain) height += 2
|
||||
return height
|
||||
}
|
||||
@ -62,7 +61,7 @@ class TileInfo {
|
||||
}
|
||||
|
||||
fun getTerrainFeature(): Terrain? {
|
||||
return if (terrainFeature == null) null else GameBasics.Terrains[terrainFeature]
|
||||
return if (terrainFeature == null) null else GameBasics.Terrains[terrainFeature!!]
|
||||
}
|
||||
|
||||
|
||||
@ -85,7 +84,7 @@ class TileInfo {
|
||||
val resource = tileResource
|
||||
stats.add(tileResource) // resource base
|
||||
if (resource.building != null && city != null && city.cityConstructions.isBuilt(resource.building!!)) {
|
||||
stats.add(resource.GetBuilding()!!.resourceBonusStats!!) // resource-specific building (eg forge, stable) bonus
|
||||
stats.add(resource.getBuilding()!!.resourceBonusStats!!) // resource-specific building (eg forge, stable) bonus
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,7 +98,7 @@ class TileInfo {
|
||||
if (improvement.improvingTech != null && observingCiv.tech.isResearched(improvement.improvingTech!!)) stats.add(improvement.improvingTechStats!!) // eg Chemistry for mines
|
||||
if (improvement.name == "Trading post" && city != null && city.civInfo.policies.isAdopted("Free Thought"))
|
||||
stats.science += 1f
|
||||
if (Linq("Academy", "Landmark", "Manufactory", "Customs House").contains(improvement.name) && observingCiv.policies.isAdopted("Freedom Complete"))
|
||||
if (listOf("Academy", "Landmark", "Manufactory", "Customs House").contains(improvement.name) && observingCiv.policies.isAdopted("Freedom Complete"))
|
||||
stats.add(improvement) // again, for the double effect
|
||||
}
|
||||
|
||||
|
@ -4,8 +4,6 @@ import com.badlogic.gdx.math.Vector2
|
||||
import com.unciv.logic.GameInfo
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.models.linq.Linq
|
||||
import com.unciv.models.linq.LinqHashMap
|
||||
import com.unciv.ui.utils.HexMath
|
||||
|
||||
class TileMap {
|
||||
@ -13,12 +11,12 @@ class TileMap {
|
||||
@Transient
|
||||
@JvmField var gameInfo: GameInfo? = null
|
||||
|
||||
private var tiles = LinqHashMap<String, TileInfo>()
|
||||
private var tiles = HashMap<String, TileInfo>()
|
||||
|
||||
constructor() // for json parsing, we need to have a default constructor
|
||||
|
||||
val values: Linq<TileInfo>
|
||||
get() = tiles.linqValues()
|
||||
val values: MutableCollection<TileInfo>
|
||||
get() = tiles.values
|
||||
|
||||
|
||||
constructor(distance: Int) {
|
||||
@ -34,21 +32,21 @@ class TileMap {
|
||||
return tiles[vector.toString()]!!
|
||||
}
|
||||
|
||||
fun getTilesInDistance(origin: Vector2, distance: Int): Linq<TileInfo> {
|
||||
return HexMath.GetVectorsInDistance(origin, distance).where{contains(it)}.select { get(it) }
|
||||
fun getTilesInDistance(origin: Vector2, distance: Int): List<TileInfo> {
|
||||
return HexMath.GetVectorsInDistance(origin, distance).filter {contains(it)}.map { get(it) }
|
||||
}
|
||||
|
||||
fun getTilesAtDistance(origin: Vector2, distance: Int): Linq<TileInfo> {
|
||||
return HexMath.GetVectorsAtDistance(origin, distance).where{contains(it)}.select { get(it) }
|
||||
fun getTilesAtDistance(origin: Vector2, distance: Int): List<TileInfo> {
|
||||
return HexMath.GetVectorsAtDistance(origin, distance).filter {contains(it)}.map { get(it) }
|
||||
|
||||
}
|
||||
|
||||
fun getDistanceToTilesWithinTurn(origin: Vector2, currentUnitMovement: Float, machineryIsResearched: Boolean): LinqHashMap<TileInfo, Float> {
|
||||
val distanceToTiles = LinqHashMap<TileInfo, Float>()
|
||||
fun getDistanceToTilesWithinTurn(origin: Vector2, currentUnitMovement: Float, machineryIsResearched: Boolean): HashMap<TileInfo, Float> {
|
||||
val distanceToTiles = HashMap<TileInfo, Float>()
|
||||
distanceToTiles[get(origin)] = 0f
|
||||
var tilesToCheck = Linq<TileInfo>(get(origin))
|
||||
var tilesToCheck = listOf(get(origin))
|
||||
while (!tilesToCheck.isEmpty()) {
|
||||
val updatedTiles = Linq<TileInfo>()
|
||||
val updatedTiles = ArrayList<TileInfo>()
|
||||
for (tileToCheck in tilesToCheck)
|
||||
for (maybeUpdatedTile in getTilesInDistance(tileToCheck.position, 1)) {
|
||||
var distanceBetweenTiles = maybeUpdatedTile.lastTerrain.movementCost.toFloat() // no road
|
||||
@ -75,13 +73,13 @@ class TileMap {
|
||||
}
|
||||
|
||||
fun getShortestPath(origin: Vector2, destination: Vector2, currentMovement: Float, maxMovement: Int, isMachineryResearched: Boolean): List<TileInfo> {
|
||||
var tilesToCheck: Linq<TileInfo> = Linq(get(origin))
|
||||
val movementTreeParents = LinqHashMap<TileInfo, TileInfo>() // contains a map of "you can get from X to Y in that turn"
|
||||
var tilesToCheck: List<TileInfo> = listOf(get(origin))
|
||||
val movementTreeParents = HashMap<TileInfo, TileInfo?>() // contains a map of "you can get from X to Y in that turn"
|
||||
movementTreeParents[get(origin)] = null
|
||||
|
||||
var distance = 1
|
||||
while (true) {
|
||||
val newTilesToCheck = Linq<TileInfo>()
|
||||
val newTilesToCheck = ArrayList<TileInfo>()
|
||||
val distanceToDestination = HashMap<TileInfo, Float>()
|
||||
val movementThisTurn = if (distance == 1) currentMovement else maxMovement.toFloat()
|
||||
for (tileToCheck in tilesToCheck) {
|
||||
@ -99,7 +97,7 @@ class TileMap {
|
||||
}
|
||||
|
||||
if (distanceToDestination.isNotEmpty()) {
|
||||
val path = Linq<TileInfo>() // Traverse the tree upwards to get the list of tiles leading to the destination,
|
||||
val path = ArrayList<TileInfo>() // Traverse the tree upwards to get the list of tiles leading to the destination,
|
||||
var currentTile = distanceToDestination.minBy { it.value }!!.key
|
||||
while (currentTile.position != origin) {
|
||||
path.add(currentTile)
|
||||
@ -117,12 +115,12 @@ class TileMap {
|
||||
val unit = GameBasics.Units[unitName]!!.mapUnit
|
||||
unit.owner = civInfo.civName
|
||||
unit.civInfo = civInfo
|
||||
getTilesInDistance(position, 2).first { it.unit == null }!!.unit = unit // And if there's none, then kill me.
|
||||
getTilesInDistance(position, 2).first { it.unit == null }.unit = unit // And if there's none, then kill me.
|
||||
}
|
||||
|
||||
fun getViewableTiles(position: Vector2, sightDistance: Int): Linq<TileInfo> {
|
||||
fun getViewableTiles(position: Vector2, sightDistance: Int): MutableList<TileInfo> {
|
||||
var sightDistance = sightDistance
|
||||
val viewableTiles = getTilesInDistance(position, 1)
|
||||
val viewableTiles = getTilesInDistance(position, 1).toMutableList()
|
||||
if (get(position).baseTerrain == "Hill") sightDistance += 1
|
||||
for (i in 1..sightDistance) { // in each layer,
|
||||
getTilesAtDistance(position, i).filterTo(viewableTiles) // take only tiles which have a visible neighbor, which is lower than the tile
|
||||
|
@ -2,7 +2,6 @@ package com.unciv.models.gamebasics
|
||||
|
||||
import com.unciv.logic.city.CityConstructions
|
||||
import com.unciv.logic.city.IConstruction
|
||||
import com.unciv.models.linq.Linq
|
||||
import com.unciv.models.stats.NamedStats
|
||||
import com.unciv.models.stats.Stats
|
||||
import com.unciv.ui.ScienceVictoryScreen
|
||||
@ -13,7 +12,7 @@ import com.unciv.ui.pickerscreens.PolicyPickerScreen
|
||||
class Building : NamedStats(), IConstruction, ICivilopedia {
|
||||
private lateinit var baseDescription: String
|
||||
override val description: String
|
||||
get() = getDescription(false, Linq())
|
||||
get() = getDescription(false, listOf())
|
||||
|
||||
@JvmField var requiredTech: String? = null
|
||||
|
||||
@ -30,7 +29,7 @@ class Building : NamedStats(), IConstruction, ICivilopedia {
|
||||
/** A strategic resource that will be consumed by this building */
|
||||
@JvmField var requiredResource: String? = null
|
||||
/** City can only be built if one of these resources is nearby - it must be improved! */
|
||||
@JvmField var requiredNearbyImprovedResources: Linq<String>? = null
|
||||
@JvmField var requiredNearbyImprovedResources: List<String>? = null
|
||||
@JvmField var cannotBeBuiltWith: String? = null
|
||||
|
||||
// Uniques
|
||||
@ -46,18 +45,18 @@ class Building : NamedStats(), IConstruction, ICivilopedia {
|
||||
|
||||
fun getRequiredTech(): Technology = GameBasics.Technologies[requiredTech]!!
|
||||
|
||||
fun getStats(adoptedPolicies: Linq<String>): Stats {
|
||||
fun getStats(adoptedPolicies: List<String>): Stats {
|
||||
val stats = this.clone()
|
||||
if (adoptedPolicies.contains("Organized Religion") && Linq("Monument", "Temple", "Monastery").contains(name))
|
||||
if (adoptedPolicies.contains("Organized Religion") && listOf("Monument", "Temple", "Monastery").contains(name))
|
||||
stats.happiness += 1
|
||||
|
||||
if (adoptedPolicies.contains("Free Religion") && Linq("Monument", "Temple", "Monastery").contains(name))
|
||||
if (adoptedPolicies.contains("Free Religion") && listOf("Monument", "Temple", "Monastery").contains(name))
|
||||
stats.culture += 1f
|
||||
|
||||
if (adoptedPolicies.contains("Entrepreneurship") && Linq("Mint", "Market", "Bank", "Stock Market").contains(name))
|
||||
if (adoptedPolicies.contains("Entrepreneurship") && listOf("Mint", "Market", "Bank", "Stock Market").contains(name))
|
||||
stats.science += 1f
|
||||
|
||||
if (adoptedPolicies.contains("Humanism") && Linq("University", "Observatory", "Public School").contains(name))
|
||||
if (adoptedPolicies.contains("Humanism") && listOf("University", "Observatory", "Public School").contains(name))
|
||||
stats.science += 1f
|
||||
|
||||
if (adoptedPolicies.contains("Theocracy") && name == "Temple")
|
||||
@ -80,7 +79,7 @@ class Building : NamedStats(), IConstruction, ICivilopedia {
|
||||
}
|
||||
|
||||
|
||||
fun getDescription(forBuildingPickerScreen: Boolean, adoptedPolicies: Linq<String>): String {
|
||||
fun getDescription(forBuildingPickerScreen: Boolean, adoptedPolicies: List<String>): String {
|
||||
val stats = getStats(adoptedPolicies)
|
||||
val stringBuilder = StringBuilder()
|
||||
if (!forBuildingPickerScreen) stringBuilder.appendln("Cost: " + cost)
|
||||
@ -111,7 +110,7 @@ class Building : NamedStats(), IConstruction, ICivilopedia {
|
||||
if (gpp.culture != 0f) stringBuilder.appendln("+" + gpp.culture.toInt() + " Great Artist points")
|
||||
}
|
||||
if (resourceBonusStats != null) {
|
||||
val resources = GameBasics.TileResources.linqValues().where { name == it.building }.select { it.name }.joinToString()
|
||||
val resources = GameBasics.TileResources.values.filter { name == it.building }.joinToString { it.name }
|
||||
stringBuilder.appendln("$resources provide $resourceBonusStats")
|
||||
}
|
||||
if (maintenance != 0)
|
||||
@ -119,12 +118,12 @@ class Building : NamedStats(), IConstruction, ICivilopedia {
|
||||
return stringBuilder.toString()
|
||||
}
|
||||
|
||||
override fun getProductionCost(adoptedPolicies: Linq<String>): Int {
|
||||
override fun getProductionCost(adoptedPolicies: List<String>): Int {
|
||||
return if (!isWonder && culture != 0f && adoptedPolicies.contains("Piety")) (cost * 0.85).toInt()
|
||||
else cost
|
||||
}
|
||||
|
||||
override fun getGoldCost(adoptedPolicies: Linq<String>): Int {
|
||||
override fun getGoldCost(adoptedPolicies: List<String>): Int {
|
||||
var cost = Math.pow((30 * getProductionCost(adoptedPolicies)).toDouble(), 0.75) * (1 + hurryCostModifier / 100)
|
||||
if (adoptedPolicies.contains("Mercantilism")) cost *= 0.75
|
||||
if (adoptedPolicies.contains("Patronage")) cost *= 0.5
|
||||
@ -145,16 +144,16 @@ class Building : NamedStats(), IConstruction, ICivilopedia {
|
||||
if (cannotBeBuiltWith != null && construction.isBuilt(cannotBeBuiltWith!!)) return false
|
||||
if ("MustBeNextToDesert" == unique && !civInfo.gameInfo.tileMap.getTilesInDistance(construction.cityInfo.cityLocation, 1).any { it.baseTerrain == "Desert" })
|
||||
return false
|
||||
if (requiredResource != null && !civInfo.getCivResources().containsKey(GameBasics.TileResources[requiredResource]))
|
||||
if (requiredResource != null && !civInfo.getCivResources().containsKey(GameBasics.TileResources[requiredResource!!]))
|
||||
return false
|
||||
|
||||
|
||||
if (requiredNearbyImprovedResources != null) {
|
||||
val containsResourceWithImprovement = construction.cityInfo.tilesInRange
|
||||
.any { tile ->
|
||||
(tile.resource != null
|
||||
&& requiredNearbyImprovedResources!!.contains(tile.resource)
|
||||
&& tile.tileResource.improvement == tile.improvement)
|
||||
.any {
|
||||
it.resource != null
|
||||
&& requiredNearbyImprovedResources!!.contains(it.resource!!)
|
||||
&& it.tileResource.improvement == it.improvement
|
||||
}
|
||||
if (!containsResourceWithImprovement) return false
|
||||
}
|
||||
@ -178,8 +177,8 @@ class Building : NamedStats(), IConstruction, ICivilopedia {
|
||||
}
|
||||
construction.builtBuildings.add(name)
|
||||
|
||||
if (providesFreeBuilding != null && !construction.builtBuildings.contains(providesFreeBuilding))
|
||||
construction.builtBuildings.add(providesFreeBuilding)
|
||||
if (providesFreeBuilding != null && !construction.builtBuildings.contains(providesFreeBuilding!!))
|
||||
construction.builtBuildings.add(providesFreeBuilding!!)
|
||||
when (unique) {
|
||||
"ApolloProgram" -> UnCivGame.Current.screen = ScienceVictoryScreen(civInfo)
|
||||
"EmpireEntersGoldenAge" -> civInfo.goldenAges.enterGoldenAge()
|
||||
|
@ -1,16 +1,12 @@
|
||||
package com.unciv.models.gamebasics
|
||||
|
||||
import com.unciv.models.linq.LinqHashMap
|
||||
|
||||
import java.util.LinkedHashMap
|
||||
|
||||
object GameBasics {
|
||||
@JvmField var Buildings: LinqHashMap<String, Building> = LinqHashMap()
|
||||
@JvmField var Terrains: LinqHashMap<String, Terrain> = LinqHashMap()
|
||||
@JvmField var TileResources: LinqHashMap<String, TileResource> = LinqHashMap()
|
||||
@JvmField var TileImprovements: LinqHashMap<String, TileImprovement> = LinqHashMap()
|
||||
@JvmField var Technologies: LinqHashMap<String, Technology> = LinqHashMap()
|
||||
@JvmField var Helps: LinqHashMap<String, BasicHelp> = LinqHashMap()
|
||||
@JvmField var Units: LinqHashMap<String, Unit> = LinqHashMap()
|
||||
@JvmField var PolicyBranches: LinqHashMap<String, PolicyBranch> = LinqHashMap()
|
||||
@JvmField var Buildings: HashMap<String, Building> = HashMap()
|
||||
@JvmField var Terrains: HashMap<String, Terrain> = HashMap()
|
||||
@JvmField var TileResources: HashMap<String, TileResource> = HashMap()
|
||||
@JvmField var TileImprovements: HashMap<String, TileImprovement> = HashMap()
|
||||
@JvmField var Technologies: HashMap<String, Technology> = HashMap()
|
||||
@JvmField var Helps: HashMap<String, BasicHelp> = HashMap()
|
||||
@JvmField var Units: HashMap<String, Unit> = HashMap()
|
||||
@JvmField var PolicyBranches: HashMap<String, PolicyBranch> = HashMap()
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package com.unciv.models.gamebasics
|
||||
|
||||
import com.unciv.models.linq.Linq
|
||||
import com.unciv.models.stats.INamed
|
||||
|
||||
open class Policy : INamed {
|
||||
@ -9,7 +8,7 @@ open class Policy : INamed {
|
||||
@JvmField var branch: String? = null
|
||||
@JvmField var row: Int = 0
|
||||
@JvmField var column: Int = 0
|
||||
@JvmField var requires: Linq<String>? = null
|
||||
@JvmField var requires: ArrayList<String>? = null
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.unciv.models.gamebasics
|
||||
|
||||
import com.unciv.models.linq.Linq
|
||||
|
||||
class PolicyBranch : Policy() {
|
||||
@JvmField var policies: Linq<Policy> = Linq()
|
||||
var policies: ArrayList<Policy> = arrayListOf()
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.unciv.models.gamebasics
|
||||
|
||||
import com.unciv.models.linq.Linq
|
||||
import com.unciv.models.stats.NamedStats
|
||||
import com.unciv.models.stats.Stats
|
||||
|
||||
@ -17,7 +16,7 @@ class TileResource : NamedStats(), ICivilopedia {
|
||||
}
|
||||
|
||||
@JvmField var resourceType: ResourceType = ResourceType.Bonus
|
||||
@JvmField var terrainsCanBeFoundOn: Linq<String> = Linq()
|
||||
@JvmField var terrainsCanBeFoundOn: List<String> = listOf()
|
||||
@JvmField var improvement: String? = null
|
||||
@JvmField var improvementStats: Stats? = null
|
||||
|
||||
@ -27,8 +26,8 @@ class TileResource : NamedStats(), ICivilopedia {
|
||||
@JvmField var building: String? = null
|
||||
@JvmField var revealedBy: String? = null
|
||||
|
||||
fun GetBuilding(): Building? {
|
||||
return if (building == null) null else GameBasics.Buildings[building]
|
||||
fun getBuilding(): Building? {
|
||||
return if (building == null) null else GameBasics.Buildings[building!!]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,8 @@
|
||||
package com.unciv.models.gamebasics
|
||||
|
||||
import com.unciv.logic.city.IConstruction
|
||||
import com.unciv.logic.city.CityConstructions
|
||||
import com.unciv.logic.city.IConstruction
|
||||
import com.unciv.logic.map.MapUnit
|
||||
import com.unciv.models.linq.Linq
|
||||
import com.unciv.models.stats.INamed
|
||||
|
||||
class Unit : INamed, IConstruction {
|
||||
@ -27,11 +26,11 @@ class Unit : INamed, IConstruction {
|
||||
}
|
||||
|
||||
|
||||
override fun getProductionCost(adoptedPolicies: Linq<String>): Int {
|
||||
override fun getProductionCost(adoptedPolicies: List<String>): Int {
|
||||
return cost
|
||||
}
|
||||
|
||||
override fun getGoldCost(adoptedPolicies: Linq<String>): Int {
|
||||
override fun getGoldCost(adoptedPolicies: List<String>): Int {
|
||||
return (Math.pow((30 * cost).toDouble(), 0.75) * (1 + hurryCostModifier / 100) / 10).toInt() * 10
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ package com.unciv.models.linq;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public class LinqCounter<K> extends LinkedHashMap<K,Integer> {
|
||||
public class Counter<K> extends LinkedHashMap<K,Integer> {
|
||||
|
||||
public Integer get(Object key){ // don't return null if empty
|
||||
if(containsKey(key)) return super.get(key);
|
||||
@ -15,21 +15,21 @@ public class LinqCounter<K> extends LinkedHashMap<K,Integer> {
|
||||
if(get(key)==0) remove(key); // No objects of this sort left, no need to count
|
||||
}
|
||||
|
||||
public void add(LinqCounter<K> other){
|
||||
public void add(Counter<K> other){
|
||||
for (K key : other.keySet()) {
|
||||
add(key,other.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(LinqCounter<K> other){
|
||||
public void remove(Counter<K> other){
|
||||
for (K key : other.keySet()) {
|
||||
add(key,-other.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LinqCounter<K> clone() {
|
||||
LinqCounter<K> newCounter = new LinqCounter<K>();
|
||||
public Counter<K> clone() {
|
||||
Counter<K> newCounter = new Counter<K>();
|
||||
newCounter.add(this);
|
||||
return newCounter;
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
package com.unciv.models.linq;
|
||||
|
||||
import com.badlogic.gdx.utils.Predicate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
* Created by LENOVO on 10/20/2017.
|
||||
*/
|
||||
|
||||
public class Linq<T> extends ArrayList<T> {
|
||||
public Linq() {
|
||||
}
|
||||
|
||||
public Linq(Collection<? extends T> objects) {
|
||||
addAll(objects);
|
||||
}
|
||||
|
||||
public Linq(T ... objects) {
|
||||
addAll(Arrays.asList(objects));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public Linq<T> where(Predicate<T> p) {
|
||||
Linq<T> newCollection = new Linq<T>();
|
||||
for (T t : this) if (p.evaluate(t)) newCollection.add(t);
|
||||
return newCollection;
|
||||
}
|
||||
|
||||
public T first(Predicate<T> p) {
|
||||
for (T t : this) if (p.evaluate(t)) return t;
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean any(Predicate<T> p){ return first(p) != null;}
|
||||
|
||||
public <T2> Linq<T2> select(Func<T, T2> selector) {
|
||||
Linq<T2> newCollection = new Linq<T2>();
|
||||
for (T t : this) newCollection.add(selector.GetBy(t));
|
||||
return newCollection;
|
||||
}
|
||||
|
||||
public <T2> Linq<T2> selectMany(Func<T,Collection<? extends T2>> multiSelector){
|
||||
Linq<T2> newCollection = new Linq<T2>();
|
||||
for(T t:this) newCollection.addAll(multiSelector.GetBy(t));
|
||||
return newCollection;
|
||||
}
|
||||
|
||||
public T getRandom(){
|
||||
if(size()==0) return null;
|
||||
return get((int) (Math.random() * (size())));
|
||||
}
|
||||
|
||||
public Linq<T> unique() {
|
||||
return new Linq<T>(new HashSet<T>(this)); // Shove it all into a hashset and build a new one around the results.
|
||||
}
|
||||
|
||||
public interface Func<T1, T2> {
|
||||
T2 GetBy(T1 arg0);
|
||||
}
|
||||
|
||||
public <T2> Linq<T2> as(Class<T2> t2Class){
|
||||
Linq<T2> newCollection = new Linq<T2>();
|
||||
for (T t:this) newCollection.add((T2)t);
|
||||
return newCollection;
|
||||
}
|
||||
|
||||
public Linq<T> clone(){
|
||||
return new Linq<T>(this);
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package com.unciv.models.linq;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public class LinqHashMap <K,V> extends LinkedHashMap<K,V> {
|
||||
public Linq<V> linqValues() {
|
||||
return new Linq<V>(super.values());
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.unciv.ui
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.*
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.List
|
||||
@ -13,7 +12,6 @@ import java.util.*
|
||||
|
||||
class CivilopediaScreen : CameraStageBaseScreen() {
|
||||
init {
|
||||
Gdx.input.inputProcessor = stage
|
||||
val buttonTable = Table()
|
||||
buttonTable.pad(15f)
|
||||
val entryTable = Table()
|
||||
@ -35,11 +33,11 @@ class CivilopediaScreen : CameraStageBaseScreen() {
|
||||
|
||||
val map = LinkedHashMap<String, Collection<ICivilopedia>>()
|
||||
|
||||
map["Basics"] = GameBasics.Helps.linqValues().`as`(ICivilopedia::class.java)
|
||||
map["Buildings"] = GameBasics.Buildings.linqValues().`as`(ICivilopedia::class.java)
|
||||
map["Resources"] = GameBasics.TileResources.linqValues().`as`(ICivilopedia::class.java)
|
||||
map["Terrains"] = GameBasics.Terrains.linqValues().`as`(ICivilopedia::class.java)
|
||||
map["Tile Improvements"] = GameBasics.TileImprovements.linqValues().`as`(ICivilopedia::class.java)
|
||||
map["Basics"] = GameBasics.Helps.values
|
||||
map["Buildings"] = GameBasics.Buildings.values
|
||||
map["Resources"] = GameBasics.TileResources.values
|
||||
map["Terrains"] = GameBasics.Terrains.values
|
||||
map["Tile Improvements"] = GameBasics.TileImprovements.values
|
||||
|
||||
val nameList = List<ICivilopedia>(CameraStageBaseScreen.skin)
|
||||
|
||||
|
@ -4,8 +4,7 @@ import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.scenes.scene2d.Touchable
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.models.linq.Linq
|
||||
import com.unciv.models.linq.LinqCounter
|
||||
import com.unciv.models.linq.Counter
|
||||
import com.unciv.ui.pickerscreens.PickerScreen
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
|
||||
@ -27,8 +26,8 @@ class ScienceVictoryScreen(internal val civInfo: CivilizationInfo) : PickerScree
|
||||
else
|
||||
descriptionLabel.setText("Apollo program is built - you may construct spaceship parts in your cities!")
|
||||
|
||||
val tutorial = Linq<String>()
|
||||
tutorial.add("This is the science victory screen, where you" +
|
||||
val tutorial = ArrayList<String>()
|
||||
tutorial.add("This is the science victory screen, filter you" +
|
||||
"\r\n can see your progress towards constructing a " +
|
||||
"\r\n spaceship to propel you towards the stars.")
|
||||
tutorial.add("There are 6 spaceship parts you must build, " + "\r\n and they all require advanced technologies")
|
||||
@ -37,7 +36,7 @@ class ScienceVictoryScreen(internal val civInfo: CivilizationInfo) : PickerScree
|
||||
displayTutorials("ScienceVictoryScreenEntered", tutorial)
|
||||
}
|
||||
|
||||
private fun addPartButton(partName: String, parts: LinqCounter<String>) {
|
||||
private fun addPartButton(partName: String, parts: Counter<String>) {
|
||||
topTable.row()
|
||||
val button = TextButton(partName, CameraStageBaseScreen.skin)
|
||||
button.touchable = Touchable.disabled
|
||||
|
@ -9,14 +9,9 @@ import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.logic.map.TileMap
|
||||
import com.unciv.models.gamebasics.*
|
||||
import com.unciv.models.gamebasics.Unit
|
||||
import com.unciv.models.linq.Linq
|
||||
import com.unciv.models.linq.LinqHashMap
|
||||
import com.unciv.models.stats.INamed
|
||||
import com.unciv.ui.utils.GameSaver
|
||||
import com.unciv.ui.worldscreen.WorldScreen
|
||||
import kotlin.Array
|
||||
import kotlin.Exception
|
||||
import kotlin.String
|
||||
|
||||
class UnCivGame : Game() {
|
||||
var gameInfo: GameInfo = GameInfo()
|
||||
@ -61,8 +56,8 @@ class UnCivGame : Game() {
|
||||
return Json().fromJson(tClass, jsonText)
|
||||
}
|
||||
|
||||
private fun <T : INamed> createHashmap(items: Array<T>): LinqHashMap<String, T> {
|
||||
val hashMap = LinqHashMap<String, T>()
|
||||
private fun <T : INamed> createHashmap(items: Array<T>): HashMap<String, T> {
|
||||
val hashMap = HashMap<String, T>()
|
||||
for (item in items)
|
||||
hashMap[item.name] = item
|
||||
return hashMap
|
||||
@ -78,7 +73,7 @@ class UnCivGame : Game() {
|
||||
GameBasics.PolicyBranches = createHashmap(getFromJson(Array<PolicyBranch>::class.java, "Policies"))
|
||||
|
||||
val techColumns = getFromJson(Array<TechColumn>::class.java, "Techs")
|
||||
GameBasics.Technologies = LinqHashMap()
|
||||
GameBasics.Technologies = HashMap()
|
||||
for (techColumn in techColumns) {
|
||||
for (tech in techColumn.techs) {
|
||||
tech.cost = techColumn.techCost
|
||||
@ -94,12 +89,12 @@ class UnCivGame : Game() {
|
||||
}
|
||||
|
||||
for (branch in GameBasics.PolicyBranches.values) {
|
||||
branch.requires = Linq()
|
||||
branch.requires = ArrayList()
|
||||
branch.branch = branch.name
|
||||
for (policy in branch.policies) {
|
||||
policy.branch = branch.name
|
||||
if (policy.requires == null) {
|
||||
policy.requires = Linq()
|
||||
policy.requires = ArrayList()
|
||||
policy.requires!!.add(branch.name)
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import com.badlogic.gdx.scenes.scene2d.ui.Label
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener
|
||||
import com.unciv.models.gamebasics.Building
|
||||
import com.unciv.models.linq.Linq
|
||||
import com.unciv.models.stats.Stat
|
||||
import com.unciv.models.stats.Stats
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
@ -21,9 +20,9 @@ class BuildingsTable(private val cityScreen: CityScreen) : Table() {
|
||||
clear()
|
||||
val skin = CameraStageBaseScreen.skin
|
||||
val cityInfo = cityScreen.city
|
||||
val wonders = Linq<Building>()
|
||||
val specialistBuildings = Linq<Building>()
|
||||
val others = Linq<Building>()
|
||||
val wonders = mutableListOf<Building>()
|
||||
val specialistBuildings = mutableListOf<Building>()
|
||||
val others = mutableListOf<Building>()
|
||||
|
||||
for (building in cityInfo.cityConstructions.getBuiltBuildings()) {
|
||||
when {
|
||||
|
@ -10,7 +10,6 @@ import com.badlogic.gdx.utils.Align
|
||||
import com.unciv.logic.city.CityInfo
|
||||
import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.models.gamebasics.Building
|
||||
import com.unciv.models.linq.Linq
|
||||
import com.unciv.ui.tilegroups.TileGroup
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
import com.unciv.ui.utils.HexMath
|
||||
@ -59,7 +58,7 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
|
||||
stage.addActor(buildingsTableContainer)
|
||||
update()
|
||||
|
||||
val tutorial = Linq<String>()
|
||||
val tutorial = mutableListOf<String>()
|
||||
tutorial.add("Welcome to your first city!" +
|
||||
"\r\nAs on now, you only have 1 population," +
|
||||
"\r\n but this will grow when you amass enough surplus food")
|
||||
|
@ -13,7 +13,7 @@ class GreatPersonPickerScreen : PickerScreen() {
|
||||
|
||||
init {
|
||||
rightSideButton.setText("Choose a free great person")
|
||||
for (unit in GameBasics.Units.linqValues()) {
|
||||
for (unit in GameBasics.Units.values) {
|
||||
if (!unit.name.startsWith("Great")) continue
|
||||
val button = TextButton(unit.name, CameraStageBaseScreen.skin)
|
||||
button.addClickListener {
|
||||
|
@ -9,7 +9,6 @@ import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.models.gamebasics.Policy
|
||||
import com.unciv.models.gamebasics.StringUtils
|
||||
import com.unciv.models.linq.Linq
|
||||
import com.unciv.ui.cityscreen.addClickListener
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
import com.unciv.ui.utils.ImageGetter
|
||||
@ -21,7 +20,7 @@ class PolicyPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen(
|
||||
init {
|
||||
|
||||
val policies = civInfo.policies
|
||||
val tutorial = Linq<String>()
|
||||
val tutorial = mutableListOf<String>()
|
||||
tutorial.add("Each turn, the culture you gain from all your " +
|
||||
"\r\n cities is added to your Civilization's culture." +
|
||||
"\r\nWhen you have enough culture, you may pick a " +
|
||||
@ -98,7 +97,7 @@ class PolicyPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen(
|
||||
}
|
||||
pickedPolicy = policy
|
||||
var policyText = policy.name + "\r\n" + policy.description + "\r\n"
|
||||
if (!policy.name.endsWith("Complete") && policy.requires!!.size > 0)
|
||||
if (!policy.name.endsWith("Complete") && policy.requires!!.isNotEmpty())
|
||||
policyText += "Requires " + StringUtils.join(", ", policy.requires)
|
||||
descriptionLabel.setText(policyText)
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.logic.civilization.TechManager
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.models.gamebasics.Technology
|
||||
import com.unciv.models.linq.Linq
|
||||
import com.unciv.ui.cityscreen.addClickListener
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
import java.util.*
|
||||
@ -30,7 +29,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen()
|
||||
|
||||
val techMatrix = Array<Array<Technology?>>(17) { arrayOfNulls(10) } // Divided into columns, then rows
|
||||
|
||||
for (technology in GameBasics.Technologies.linqValues()) {
|
||||
for (technology in GameBasics.Technologies.values) {
|
||||
techMatrix[technology.column!!.columnNumber - 1][technology.row - 1] = technology
|
||||
}
|
||||
|
||||
@ -69,7 +68,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen()
|
||||
dispose()
|
||||
}
|
||||
|
||||
val tutorial = Linq<String>()
|
||||
val tutorial = mutableListOf<String>()
|
||||
tutorial.add("Technology is central to your civilization," +
|
||||
"\r\n as technological progress brings with it" +
|
||||
"\r\n more construction options, improvements, and abilities")
|
||||
@ -133,15 +132,15 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen()
|
||||
techsToResearch.add(tech.name)
|
||||
} else {
|
||||
val prerequisites = Stack<String>()
|
||||
val CheckPrerequisites = ArrayDeque<String>()
|
||||
CheckPrerequisites.add(tech.name)
|
||||
while (!CheckPrerequisites.isEmpty()) {
|
||||
val techNameToCheck = CheckPrerequisites.pop()
|
||||
val checkPrerequisites = ArrayDeque<String>()
|
||||
checkPrerequisites.add(tech.name)
|
||||
while (!checkPrerequisites.isEmpty()) {
|
||||
val techNameToCheck = checkPrerequisites.pop()
|
||||
if (civTech.isResearched(techNameToCheck) || prerequisites.contains(techNameToCheck))
|
||||
continue //no need to add or check prerequisites
|
||||
val techToCheck = GameBasics.Technologies[techNameToCheck]
|
||||
for (str in techToCheck!!.prerequisites)
|
||||
if (!CheckPrerequisites.contains(str)) CheckPrerequisites.add(str)
|
||||
if (!checkPrerequisites.contains(str)) checkPrerequisites.add(str)
|
||||
prerequisites.add(techNameToCheck)
|
||||
}
|
||||
techsToResearch.clear()
|
||||
|
@ -7,7 +7,6 @@ import com.badlogic.gdx.scenes.scene2d.ui.Image
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||
import com.unciv.logic.map.RoadStatus
|
||||
import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.models.linq.LinqHashMap
|
||||
import com.unciv.ui.utils.HexMath
|
||||
import com.unciv.ui.utils.ImageGetter
|
||||
|
||||
@ -19,7 +18,7 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
|
||||
protected var improvementImage: Image? =null
|
||||
private var improvementType: String? = null
|
||||
var populationImage: Image? = null
|
||||
private var roadImages = LinqHashMap<String, Image>()
|
||||
private var roadImages = HashMap<String, Image>()
|
||||
protected var hexagon: Image? = null
|
||||
|
||||
protected var cityButton: Container<TextButton>? = null
|
||||
@ -121,7 +120,7 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
|
||||
|
||||
// This is some crazy voodoo magic so I'll explain.
|
||||
image.moveBy(25f, 25f) // Move road to center of tile
|
||||
// in addTiles, we set the position of groups by relative world position *0.8*groupSize, where 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 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)
|
||||
image.setSize(10f, 2f)
|
||||
|
@ -13,21 +13,19 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||
import com.badlogic.gdx.utils.Align
|
||||
import com.badlogic.gdx.utils.viewport.ExtendViewport
|
||||
import com.unciv.models.linq.Linq
|
||||
import com.unciv.ui.UnCivGame
|
||||
import com.unciv.ui.cityscreen.addClickListener
|
||||
|
||||
open class CameraStageBaseScreen : Screen {
|
||||
|
||||
var game: UnCivGame
|
||||
var game: UnCivGame = UnCivGame.Current
|
||||
var stage: Stage
|
||||
|
||||
private val tutorialTexts = Linq<String>()
|
||||
private val tutorialTexts = mutableListOf<String>()
|
||||
|
||||
internal var isTutorialShowing = false
|
||||
private var isTutorialShowing = false
|
||||
|
||||
init {
|
||||
this.game = UnCivGame.Current
|
||||
stage = Stage(ExtendViewport(1000f, 600f
|
||||
), batch)// FitViewport(1000,600)
|
||||
Gdx.input.inputProcessor = stage
|
||||
@ -56,14 +54,14 @@ open class CameraStageBaseScreen : Screen {
|
||||
|
||||
override fun dispose() {}
|
||||
|
||||
fun displayTutorials(name: String, texts: Linq<String>) {
|
||||
fun displayTutorials(name: String, texts: List<String>) {
|
||||
if (game.gameInfo.tutorial.contains(name)) return
|
||||
game.gameInfo.tutorial.add(name)
|
||||
tutorialTexts.addAll(texts)
|
||||
if (!isTutorialShowing) displayTutorial()
|
||||
}
|
||||
|
||||
fun displayTutorial() {
|
||||
private fun displayTutorial() {
|
||||
isTutorialShowing = true
|
||||
val tutorialTable = Table().pad(10f)
|
||||
tutorialTable.background(ImageGetter.getDrawable("skin/tileTableBackground.png")
|
||||
|
@ -1,9 +1,7 @@
|
||||
package com.unciv.ui.utils
|
||||
|
||||
import com.badlogic.gdx.math.Vector2
|
||||
import com.unciv.models.linq.Linq
|
||||
|
||||
import java.util.ArrayList
|
||||
import java.util.*
|
||||
|
||||
object HexMath {
|
||||
|
||||
@ -41,8 +39,8 @@ object HexMath {
|
||||
return vectors
|
||||
}
|
||||
|
||||
fun GetVectorsAtDistance(origin: Vector2, distance: Int): Linq<Vector2> {
|
||||
val vectors = Linq<Vector2>()
|
||||
fun GetVectorsAtDistance(origin: Vector2, distance: Int): List<Vector2> {
|
||||
val vectors = mutableListOf<Vector2>()
|
||||
if (distance == 0) {
|
||||
vectors.add(origin.cpy())
|
||||
return vectors
|
||||
@ -66,8 +64,8 @@ object HexMath {
|
||||
return vectors
|
||||
}
|
||||
|
||||
fun GetVectorsInDistance(origin: Vector2, distance: Int): Linq<Vector2> {
|
||||
val hexesToReturn = Linq<Vector2>()
|
||||
fun GetVectorsInDistance(origin: Vector2, distance: Int): List<Vector2> {
|
||||
val hexesToReturn = mutableListOf<Vector2>()
|
||||
for (i in 0 until distance + 1) {
|
||||
hexesToReturn.addAll(GetVectorsAtDistance(origin, i))
|
||||
}
|
||||
|
@ -5,12 +5,11 @@ import com.badlogic.gdx.scenes.scene2d.ui.Label
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.unciv.logic.civilization.Notification
|
||||
import com.unciv.models.linq.Linq
|
||||
import com.unciv.ui.cityscreen.addClickListener
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
import com.unciv.ui.utils.ImageGetter
|
||||
|
||||
class NotificationsScroll(private val notifications: Linq<Notification>, internal val worldScreen: WorldScreen) : ScrollPane(null) {
|
||||
class NotificationsScroll(private val notifications: List<Notification>, internal val worldScreen: WorldScreen) : ScrollPane(null) {
|
||||
private var notificationsTable = Table()
|
||||
|
||||
init {
|
||||
|
@ -8,8 +8,6 @@ import com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.logic.map.TileMap
|
||||
import com.unciv.models.linq.Linq
|
||||
import com.unciv.models.linq.LinqHashMap
|
||||
import com.unciv.ui.cityscreen.addClickListener
|
||||
import com.unciv.ui.tilegroups.WorldTileGroup
|
||||
import com.unciv.ui.utils.HexMath
|
||||
@ -17,7 +15,7 @@ import com.unciv.ui.utils.HexMath
|
||||
class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap: TileMap, internal val civInfo: CivilizationInfo) : ScrollPane(null) {
|
||||
internal var selectedTile: TileInfo? = null
|
||||
//internal var unitTile: TileInfo? = null
|
||||
val tileGroups = LinqHashMap<String, WorldTileGroup>()
|
||||
val tileGroups = HashMap<String, WorldTileGroup>()
|
||||
|
||||
internal fun addTiles() {
|
||||
val allTiles = Group()
|
||||
@ -31,7 +29,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
|
||||
val group = WorldTileGroup(tileInfo)
|
||||
|
||||
group.addClickListener {
|
||||
val tutorial = Linq<String>()
|
||||
val tutorial = mutableListOf<String>()
|
||||
tutorial.add("Clicking on a tile selects that tile," +
|
||||
"\r\n and displays information on that tile on the bottom-right," +
|
||||
"\r\n as well as unit actions, if the tile contains a unit")
|
||||
@ -56,7 +54,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
|
||||
bottomY = Math.min(bottomY, group.y)
|
||||
}
|
||||
|
||||
for (group in tileGroups.linqValues()) {
|
||||
for (group in tileGroups.values) {
|
||||
group.moveBy(-bottomX + 50, -bottomY + 50)
|
||||
}
|
||||
|
||||
@ -87,16 +85,16 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
|
||||
}
|
||||
|
||||
internal fun updateTiles() {
|
||||
for (WG in tileGroups.linqValues()) WG.update(worldScreen)
|
||||
for (WG in tileGroups.values) WG.update(worldScreen)
|
||||
|
||||
|
||||
for (WG in tileGroups.linqValues()) WG.setIsViewable(false)
|
||||
for (WG in tileGroups.values) WG.setIsViewable(false)
|
||||
var viewablePositions = emptyList<Vector2>()
|
||||
if(worldScreen.unitTable.currentlyExecutingAction == null) {
|
||||
viewablePositions += tileMap.values.where { it.owner == civInfo.civName }
|
||||
viewablePositions += tileMap.values.filter { it.owner == civInfo.civName }
|
||||
.flatMap { HexMath.GetAdjacentVectors(it.position) } // tiles adjacent to city tiles
|
||||
viewablePositions += tileMap.values.where { it.unit != null }
|
||||
.flatMap { tileMap.getViewableTiles(it.position, 2).select { it.position } } // Tiles within 2 tiles of units
|
||||
viewablePositions += tileMap.values.filter { it.unit != null }
|
||||
.flatMap { tileMap.getViewableTiles(it.position, 2).map { it.position } } // Tiles within 2 tiles of units
|
||||
}
|
||||
|
||||
else
|
||||
@ -108,13 +106,13 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
|
||||
}
|
||||
|
||||
fun setCenterPosition(vector: Vector2) {
|
||||
val tileGroup = tileGroups.linqValues().first { it.tileInfo.position == vector }
|
||||
val tileGroup = tileGroups.values.first { it.tileInfo.position == vector }
|
||||
selectedTile = tileGroup.tileInfo
|
||||
if(selectedTile!!.unit!=null) worldScreen.unitTable.selectedUnitTile = selectedTile
|
||||
layout() // Fit the scroll pane to the contents - otherwise, setScroll won't work!
|
||||
// We want to center on the middle of TG (TG.getX()+TG.getWidth()/2)
|
||||
// and so the scroll position (== where the screen starts) needs to be half a screen away
|
||||
scrollX = tileGroup!!.x + tileGroup.width / 2 - worldScreen.stage.width / 2
|
||||
// and so the scroll position (== filter the screen starts) needs to be half a screen away
|
||||
scrollX = tileGroup.x + tileGroup.width / 2 - worldScreen.stage.width / 2
|
||||
// Here it's the same, only the Y axis is inverted - when at 0 we're at the top, not bottom - so we invert it back.
|
||||
scrollY = maxY - (tileGroup.y + tileGroup.width / 2 - worldScreen.stage.height / 2)
|
||||
updateVisualScroll()
|
||||
|
@ -4,7 +4,6 @@ import com.badlogic.gdx.math.Vector2
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.models.linq.Linq
|
||||
import com.unciv.ui.cityscreen.addClickListener
|
||||
import com.unciv.ui.pickerscreens.PolicyPickerScreen
|
||||
import com.unciv.ui.pickerscreens.TechPickerScreen
|
||||
@ -49,7 +48,7 @@ class WorldScreen : CameraStageBaseScreen() {
|
||||
createNextTurnButton() // needs civ table to be positioned
|
||||
stage.addActor(optionsTable)
|
||||
|
||||
val beginningTutorial = Linq<String>()
|
||||
val beginningTutorial = mutableListOf<String>()
|
||||
beginningTutorial.add("Hello, and welcome to Unciv!" +
|
||||
"\r\nCivilization games can be complex, so we'll" +
|
||||
"\r\n be guiding you along your first journey." +
|
||||
@ -68,7 +67,7 @@ class WorldScreen : CameraStageBaseScreen() {
|
||||
|
||||
fun update() {
|
||||
if (game.gameInfo.tutorial.contains("CityEntered")) {
|
||||
val tutorial = Linq<String>()
|
||||
val tutorial = ArrayList<String>()
|
||||
tutorial.add("Once you've done everything you can, " + "\r\nclick the next turn button on the top right to continue.")
|
||||
tutorial.add("Each turn, science, culture and gold are added" +
|
||||
"\r\n to your civilization, your cities' construction" +
|
||||
@ -91,7 +90,7 @@ class WorldScreen : CameraStageBaseScreen() {
|
||||
}
|
||||
|
||||
private fun updateTechButton() {
|
||||
techButton.isVisible = civInfo.cities.size != 0
|
||||
techButton.isVisible = civInfo.cities.isNotEmpty()
|
||||
techButton.clearListeners()
|
||||
techButton.addClickListener {
|
||||
game.screen = TechPickerScreen(civInfo)
|
||||
@ -110,7 +109,7 @@ class WorldScreen : CameraStageBaseScreen() {
|
||||
private fun createNextTurnButton() {
|
||||
val nextTurnButton = TextButton("Next turn", CameraStageBaseScreen.skin)
|
||||
nextTurnButton.addClickListener {
|
||||
if (civInfo.tech.currentTechnology() == null && civInfo.cities.size != 0) {
|
||||
if (civInfo.tech.currentTechnology() == null && civInfo.cities.isNotEmpty()) {
|
||||
game.screen = TechPickerScreen(civInfo)
|
||||
return@addClickListener
|
||||
}
|
||||
@ -120,7 +119,7 @@ class WorldScreen : CameraStageBaseScreen() {
|
||||
GameSaver.SaveGame(game, "Autosave")
|
||||
update()
|
||||
|
||||
val tutorial = Linq<String>()
|
||||
val tutorial = ArrayList<String>()
|
||||
tutorial.add("In your first couple of turns," +
|
||||
"\r\n you will have very little options," +
|
||||
"\r\n but as your civilization grows, so do the " +
|
||||
|
@ -20,12 +20,12 @@ class WorldScreenOptionsTable internal constructor(worldScreen: WorldScreen, pri
|
||||
|
||||
isVisible = false
|
||||
|
||||
val OpenCivilopediaButton = TextButton("Civilopedia", CameraStageBaseScreen.skin)
|
||||
OpenCivilopediaButton.addClickListener {
|
||||
val openCivilopediaButton = TextButton("Civilopedia", CameraStageBaseScreen.skin)
|
||||
openCivilopediaButton.addClickListener {
|
||||
worldScreen.game.screen = CivilopediaScreen()
|
||||
isVisible = false
|
||||
}
|
||||
add(OpenCivilopediaButton).pad(10f)
|
||||
add(openCivilopediaButton).pad(10f)
|
||||
row()
|
||||
|
||||
val StartNewGameButton = TextButton("Start new game", CameraStageBaseScreen.skin)
|
||||
|
@ -11,7 +11,7 @@ import com.unciv.ui.worldscreen.WorldScreen
|
||||
class IdleUnitButton internal constructor(internal val worldScreen: WorldScreen) : TextButton("Select next idle unit", CameraStageBaseScreen.skin) {
|
||||
init {
|
||||
addClickListener {
|
||||
val tilesWithIdleUnits = worldScreen.civInfo.gameInfo.tileMap.values.where { it.hasIdleUnit() }
|
||||
val tilesWithIdleUnits = worldScreen.civInfo.gameInfo.tileMap.values.filter { it.hasIdleUnit() }
|
||||
|
||||
val tileToSelect: TileInfo
|
||||
if (!tilesWithIdleUnits.contains(worldScreen.tileMapHolder.selectedTile))
|
||||
|
@ -7,7 +7,6 @@ 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.models.linq.Linq
|
||||
import com.unciv.ui.UnCivGame
|
||||
import com.unciv.ui.cityscreen.addClickListener
|
||||
import com.unciv.ui.pickerscreens.ImprovementPickerScreen
|
||||
@ -37,7 +36,7 @@ class UnitActions {
|
||||
actionList += getUnitActionButton(unit, "Move unit", true, {
|
||||
unitTable.currentlyExecutingAction = "moveTo"
|
||||
// Set all tiles transparent except those in unit range
|
||||
for (TG in tileMapHolder.tileGroups.linqValues()) TG.setColor(0f, 0f, 0f, 0.3f)
|
||||
for (TG in tileMapHolder.tileGroups.values) TG.setColor(0f, 0f, 0f, 0.3f)
|
||||
|
||||
val distanceToTiles = tileMapHolder.tileMap.getDistanceToTilesWithinTurn(
|
||||
unitTable.selectedUnitTile!!.position,
|
||||
@ -61,7 +60,7 @@ class UnitActions {
|
||||
actionList += getUnitActionButton(unit, "Found City",
|
||||
!tileMapHolder.tileMap.getTilesInDistance(tile.position, 2).any { it.isCityCenter },
|
||||
{
|
||||
val tutorial = Linq<String>()
|
||||
val tutorial = mutableListOf<String>()
|
||||
tutorial.add("You have founded a city!" +
|
||||
"\r\nCities are the lifeblood of your empire," +
|
||||
"\r\n providing gold and science empire-wide," +
|
||||
@ -87,7 +86,7 @@ class UnitActions {
|
||||
if (tile.improvementInProgress == null) "Construct\r\nimprovement"
|
||||
else tile.improvementInProgress!! + "\r\nin progress"
|
||||
actionList += getUnitActionButton(unit, improvementButtonText,
|
||||
!tile.isCityCenter || GameBasics.TileImprovements.linqValues().any { tile.canBuildImprovement(it, unit.civInfo) },
|
||||
!tile.isCityCenter || GameBasics.TileImprovements.values.any { tile.canBuildImprovement(it, unit.civInfo) },
|
||||
{ worldScreen.game.screen = ImprovementPickerScreen(tile) })
|
||||
|
||||
if("automation" == tile.unit!!.action){
|
||||
|
@ -6,7 +6,6 @@ import com.badlogic.gdx.scenes.scene2d.ui.Label
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.unciv.logic.map.MapUnit
|
||||
import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.models.linq.LinqHashMap
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
import com.unciv.ui.utils.ImageGetter
|
||||
import com.unciv.ui.worldscreen.WorldScreen
|
||||
@ -37,7 +36,6 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
|
||||
|
||||
fun update() {
|
||||
idleUnitButton.update()
|
||||
|
||||
unitActionsTable.clear()
|
||||
if(selectedUnitTile!=null && selectedUnitTile!!.unit==null) selectedUnitTile=null // The unit that was there no longer exists
|
||||
|
||||
@ -47,6 +45,8 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
|
||||
unitActionsTable.add(button).colspan(2).pad(5f)
|
||||
.size(button.width * worldScreen.buttonScale, button.height * worldScreen.buttonScale).row()
|
||||
}
|
||||
else unitLabel.setText("")
|
||||
|
||||
unitActionsTable.pack()
|
||||
pack()
|
||||
|
||||
@ -65,7 +65,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
|
||||
if(selectedTile.unit!=null) selectedUnitTile = selectedTile
|
||||
}
|
||||
|
||||
private fun getDistanceToTiles(): LinqHashMap<TileInfo, Float> {
|
||||
private fun getDistanceToTiles(): HashMap<TileInfo, Float> {
|
||||
return worldScreen.tileMapHolder.tileMap.getDistanceToTilesWithinTurn(selectedUnitTile!!.position,
|
||||
getSelectedUnit().currentMovement,
|
||||
getSelectedUnit().civInfo.tech.isResearched("Machinery"))
|
||||
|
Reference in New Issue
Block a user