Minor improvements

This commit is contained in:
yairm210
2021-09-10 13:42:37 +03:00
parent 19837c235a
commit 66d7e8cbd0
3 changed files with 15 additions and 18 deletions

View File

@ -714,7 +714,7 @@ class CityInfo {
}
fun getNeighbouringCivs(): List<String> {
fun getNeighbouringCivs(): Set<String> {
val tilesList: HashSet<TileInfo> = getTiles().toHashSet()
val cityPositionList: ArrayList<TileInfo> = arrayListOf()
@ -726,12 +726,8 @@ class CityInfo {
return cityPositionList
.asSequence()
.mapNotNull { it.getOwner()?.civName }
.distinct()
.toList()
.toSet()
}
fun getImprovableTiles(): Sequence<TileInfo> = getTiles()
.filter { it.hasViewableResource(civInfo) && it.improvement == null }
//endregion
}

View File

@ -163,15 +163,14 @@ class TradeEvaluation {
}
}
}
private fun surroundedByOurCities(city: CityInfo, civInfo: CivilizationInfo): Int{
val borderingCivs: List<String> = city.getNeighbouringCivs()
if (borderingCivs.size == 1 && borderingCivs.contains(civInfo.civName)){
return 10*civInfo.getEraNumber() // if the city is surrounded only by trading civ
private fun surroundedByOurCities(city: CityInfo, civInfo: CivilizationInfo): Int {
val borderingCivs: Set<String> = city.getNeighbouringCivs()
if (borderingCivs.size == 1 && borderingCivs.contains(civInfo.civName)) {
return 10 * civInfo.getEraNumber() // if the city is surrounded only by trading civ
}
if (borderingCivs.contains(civInfo.civName))
return 2*civInfo.getEraNumber() // if the city has a border with trading civ
return 2 * civInfo.getEraNumber() // if the city has a border with trading civ
return 0
}
private fun evaluateSellCost(offer: TradeOffer, civInfo: CivilizationInfo, tradePartner: CivilizationInfo): Int {

View File

@ -328,13 +328,12 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
otherCivDiplomacyManager: DiplomacyManager
): TextButton? {
if (otherCiv.cities.isEmpty()) return null
val improvableTiles = otherCiv.getCapital().getImprovableTiles()
.filterNot { it.getTileResource().resourceType == ResourceType.Bonus }.toList()
val improvableResourceTiles = getImprovableResourceTiles(otherCiv)
val improvements =
otherCiv.gameInfo.ruleSet.tileImprovements.filter { it.value.turnsToBuild != 0 }
var needsImprovements = false
for (improvableTile in improvableTiles)
for (improvableTile in improvableResourceTiles)
for (tileImprovement in improvements.values)
if (improvableTile.canBuildImprovement(
tileImprovement,
@ -401,16 +400,19 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
return diplomacyTable
}
fun getImprovableResourceTiles(otherCiv:CivilizationInfo) = otherCiv.getCapital().getTiles()
.filter { it.hasViewableResource(otherCiv) && it.improvement == null
&& it.getTileResource().resourceType!=ResourceType.Bonus }
private fun getImprovementGiftTable(otherCiv: CivilizationInfo): Table {
val improvementGiftTable = getCityStateDiplomacyTableHeader(otherCiv)
improvementGiftTable.addSeparator()
val improvableTiles = otherCiv.getCapital().getImprovableTiles()
.filterNot { it.getTileResource().resourceType == ResourceType.Bonus }.toList()
val improvableResourceTiles = getImprovableResourceTiles(otherCiv)
val tileImprovements =
otherCiv.gameInfo.ruleSet.tileImprovements.filter { it.value.turnsToBuild != 0 }
for (improvableTile in improvableTiles) {
for (improvableTile in improvableResourceTiles) {
for (tileImprovement in tileImprovements.values) {
if (improvableTile.canBuildImprovement(tileImprovement, otherCiv) &&
improvableTile.getTileResource().improvement == tileImprovement.name