chore: convert 'provides resources' to separate function

This commit is contained in:
Yair Morgenstern
2023-03-05 22:29:45 +02:00
parent d3c084f89f
commit 7025bbb94a
2 changed files with 22 additions and 23 deletions

View File

@ -239,32 +239,17 @@ class City : IsPartOfGameInfoSerialization {
fun getTileResourceAmount(tile: Tile): Int {
if (tile.resource == null) return 0
if (!tile.providesResources(civ)) return 0
val resource = tile.tileResource
if (resource.revealedBy != null && !civ.tech.isResearched(resource.revealedBy!!)) return 0
// Even if the improvement exists (we conquered an enemy city or somesuch) or we have a city on it, we won't get the resource until the correct tech is researched
if (resource.getImprovements().any()) {
if (!resource.getImprovements().any { improvementString ->
val improvement = getRuleset().tileImprovements[improvementString]!!
improvement.techRequired == null || civ.tech.isResearched(improvement.techRequired!!)
}) return 0
}
if ((tile.getUnpillagedImprovement() != null && resource.isImprovedBy(tile.improvement!!)) || tile.isCityCenter()
// Per https://gaming.stackexchange.com/questions/53155/do-manufactories-and-customs-houses-sacrifice-the-strategic-or-luxury-resources
|| resource.resourceType == ResourceType.Strategic && tile.containsUnpillagedGreatImprovement()
) {
var amountToAdd = if (resource.resourceType == ResourceType.Strategic) tile.resourceAmount
else 1
if (resource.resourceType == ResourceType.Luxury
&& containsBuildingUnique(UniqueType.ProvidesExtraLuxuryFromCityResources)
)
&& containsBuildingUnique(UniqueType.ProvidesExtraLuxuryFromCityResources))
amountToAdd += 1
return amountToAdd
}
return 0
}
fun isGrowing() = foodForNextTurn() > 0
fun isStarving() = foodForNextTurn() < 0

View File

@ -495,6 +495,20 @@ open class Tile : IsPartOfGameInfoSerialization {
return fertility
}
fun providesResources(civInfo: Civilization): Boolean {
if (!hasViewableResource(civInfo)) return false
if (isCityCenter()) return true
val improvement = getUnpillagedTileImprovement()
if (improvement != null && improvement.name in tileResource.getImprovements()
&& (improvement.techRequired==null || civInfo.tech.isResearched(improvement.techRequired!!))) return true
// TODO: Generic-ify to unique
if (tileResource.resourceType==ResourceType.Strategic
&& improvement!=null
&& improvement.isGreatImprovement())
return true
return false
}
// This should be the only adjacency function
fun isAdjacentTo(terrainFilter:String): Boolean {
// Rivers are odd, as they aren't technically part of any specific tile but still count towards adjacency