From 7025bbb94abc8dbe2ffae3d23b22daf91172281f Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sun, 5 Mar 2023 22:29:45 +0200 Subject: [PATCH] chore: convert 'provides resources' to separate function --- core/src/com/unciv/logic/city/City.kt | 31 ++++++----------------- core/src/com/unciv/logic/map/tile/Tile.kt | 14 ++++++++++ 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/core/src/com/unciv/logic/city/City.kt b/core/src/com/unciv/logic/city/City.kt index e385ad915d..58ce99ab89 100644 --- a/core/src/com/unciv/logic/city/City.kt +++ b/core/src/com/unciv/logic/city/City.kt @@ -239,31 +239,16 @@ 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 + var amountToAdd = if (resource.resourceType == ResourceType.Strategic) tile.resourceAmount + else 1 + if (resource.resourceType == ResourceType.Luxury + && containsBuildingUnique(UniqueType.ProvidesExtraLuxuryFromCityResources)) + amountToAdd += 1 - // 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) - ) - amountToAdd += 1 - - return amountToAdd - } - return 0 + return amountToAdd } fun isGrowing() = foodForNextTurn() > 0 diff --git a/core/src/com/unciv/logic/map/tile/Tile.kt b/core/src/com/unciv/logic/map/tile/Tile.kt index 24bcb94ca3..1c3df99858 100644 --- a/core/src/com/unciv/logic/map/tile/Tile.kt +++ b/core/src/com/unciv/logic/map/tile/Tile.kt @@ -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