diff --git a/android/assets/jsons/Civ V - Vanilla/Quests.json b/android/assets/jsons/Civ V - Vanilla/Quests.json index 9de675927f..08b646a3f5 100644 --- a/android/assets/jsons/Civ V - Vanilla/Quests.json +++ b/android/assets/jsons/Civ V - Vanilla/Quests.json @@ -11,11 +11,11 @@ "type": "Global", "influence": 50, "minimumCivs": 1 - }, + },*/ { "name": "Connect Resource", "description": "In order to make our civilizations stronger, connect [tileResource] to your trade network." - },*/ + }, { "name": "Construct Wonder", "description": "We recommend you to start building [wonder] to show the whole world your civilization strength." diff --git a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt index 2b8568676d..5ea33b47c9 100644 --- a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt +++ b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt @@ -165,6 +165,10 @@ class CivilizationInfo { return newResourceSupplyList } + fun getViewableResources(): List = + gameInfo.ruleSet.tileResources.values + .filter { it.revealedBy == null || tech.isResearched(it.revealedBy!!) } + fun isCapitalConnectedToCity(city: CityInfo): Boolean = citiesConnectedToCapitalToMediums.keys.contains(city) diff --git a/core/src/com/unciv/logic/civilization/QuestManager.kt b/core/src/com/unciv/logic/civilization/QuestManager.kt index 816c36b69b..f881909669 100644 --- a/core/src/com/unciv/logic/civilization/QuestManager.kt +++ b/core/src/com/unciv/logic/civilization/QuestManager.kt @@ -246,6 +246,7 @@ class QuestManager { var data2 = "" when (quest.name) { + QuestName.ConnectResource.value -> data1 = getResourceForQuest(assignee)!!.name QuestName.ConstructWonder.value -> data1 = getWonderToBuildForQuest(assignee)!!.name } @@ -282,6 +283,7 @@ class QuestManager { return when (quest.name) { QuestName.Route.value -> civInfo.hasEverBeenFriendWith(challenger) && !civInfo.isCapitalConnectedToCity(challenger.getCapital()) + QuestName.ConnectResource.value -> civInfo.hasEverBeenFriendWith(challenger) && getResourceForQuest(challenger) != null QuestName.ConstructWonder.value -> civInfo.hasEverBeenFriendWith(challenger) && getWonderToBuildForQuest(challenger) != null else -> true } @@ -292,6 +294,7 @@ class QuestManager { val assignee = civInfo.gameInfo.getCivilization(assignedQuest.assignee) return when (assignedQuest.questName) { QuestName.Route.value -> civInfo.isCapitalConnectedToCity(assignee.getCapital()) + QuestName.ConnectResource.value -> assignee.detailedCivResources.map { it.resource }.contains(civInfo.gameInfo.ruleSet.tileResources[assignedQuest.data1]) QuestName.ConstructWonder.value -> assignee.cities.any { it.cityConstructions.isBuilt(assignedQuest.data1) } else -> false } @@ -326,6 +329,29 @@ class QuestManager { } //region get-quest-target + + /** + * Returns a random resource to be connected to the [challenger]'s trade route as a quest. + * The resource must be a [ResourceType.Luxury] or [ResourceType.Strategic], must not be owned + * by the [civInfo] and the [challenger], and must be viewable by the [challenger]; + * if none exists, it returns null. + */ + private fun getResourceForQuest(challenger: CivilizationInfo): TileResource? { + val ownedByCityStateResources = civInfo.detailedCivResources.map { it.resource } + val ownedByMajorResources = challenger.detailedCivResources.map { it.resource } + + val notOwnedResources = challenger.getViewableResources().filter { + it.resourceType != ResourceType.Bonus && + !ownedByCityStateResources.contains(it) && + !ownedByMajorResources.contains(it) + } + + if (notOwnedResources.isNotEmpty()) + return notOwnedResources.random() + + return null + } + private fun getWonderToBuildForQuest(challenger: CivilizationInfo): Building? { val wonders = civInfo.gameInfo.ruleSet.buildings.values .filter { building ->