From 1dd82f6f58f899b8b9f5b0591bcb6459984f20d4 Mon Sep 17 00:00:00 2001 From: Federico Luongo Date: Tue, 6 Oct 2020 12:59:54 +0200 Subject: [PATCH] Find Natural Wonder Quest implemented (#3211) * Find Natural Wonder Quest implemented * List to sequence to list --- .../assets/jsons/Civ V - Vanilla/Quests.json | 6 +++--- .../unciv/logic/civilization/QuestManager.kt | 17 ++++++++++++++++- core/src/com/unciv/logic/map/TileMap.kt | 1 + 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/android/assets/jsons/Civ V - Vanilla/Quests.json b/android/assets/jsons/Civ V - Vanilla/Quests.json index a682af2fba..144e9f08ff 100644 --- a/android/assets/jsons/Civ V - Vanilla/Quests.json +++ b/android/assets/jsons/Civ V - Vanilla/Quests.json @@ -23,7 +23,7 @@ { "name": "Acquire Great Person", "description": "Great People can change the course of a Civilization! You will be rewarded for acquiring a new [greatPerson]." - }/*, + },/* { "name": "Conquer City State", "description": "You will be rewarded for conquering the city state of [cityState]!", @@ -33,11 +33,11 @@ "name": "Find Player", "description": "You have yet to discover where [civName] set up their cities. You will be rewarded for finding their territories.", "influence": 35 - }, + },*/ { "name": "Find Natural Wonder", "description": "Send your best explorers on a quest to discover Natural Wonders. Nobody knows the location of [naturalWonder] yet." - }*/ + } /* G&K */ /* { diff --git a/core/src/com/unciv/logic/civilization/QuestManager.kt b/core/src/com/unciv/logic/civilization/QuestManager.kt index 2583470d42..c6652ad31d 100644 --- a/core/src/com/unciv/logic/civilization/QuestManager.kt +++ b/core/src/com/unciv/logic/civilization/QuestManager.kt @@ -251,6 +251,7 @@ class QuestManager { QuestName.ConnectResource.value -> data1 = getResourceForQuest(assignee)!!.name QuestName.ConstructWonder.value -> data1 = getWonderToBuildForQuest(assignee)!!.name QuestName.GreatPerson.value -> data1 = getGreatPersonForQuest(assignee)!!.name + QuestName.FindNaturalWonder.value -> data1 = getNaturalWonderToFindForQuest(assignee)!! } val newQuest = AssignedQuest( @@ -289,6 +290,7 @@ class QuestManager { QuestName.ConnectResource.value -> civInfo.hasEverBeenFriendWith(challenger) && getResourceForQuest(challenger) != null QuestName.ConstructWonder.value -> civInfo.hasEverBeenFriendWith(challenger) && getWonderToBuildForQuest(challenger) != null QuestName.GreatPerson.value -> civInfo.hasEverBeenFriendWith(challenger) && getGreatPersonForQuest(challenger) != null + QuestName.FindNaturalWonder.value -> civInfo.hasEverBeenFriendWith(challenger) && getNaturalWonderToFindForQuest(challenger) != null else -> true } } @@ -301,6 +303,7 @@ class QuestManager { 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) } QuestName.GreatPerson.value -> assignee.getCivGreatPeople().any { it.baseUnit.getReplacedUnit(civInfo.gameInfo.ruleSet).name == assignedQuest.data1 } + QuestName.FindNaturalWonder.value -> assignee.naturalWonders.contains(assignedQuest.data1) else -> false } } @@ -371,6 +374,18 @@ class QuestManager { return null } + /** + * Returns a random [NaturalWonder] not yet discovered by [challenger]. + */ + private fun getNaturalWonderToFindForQuest(challenger: CivilizationInfo): String? { + val naturalWondersToFind = civInfo.gameInfo.tileMap.naturalWonders.subtract(challenger.naturalWonders) + + if (naturalWondersToFind.isNotEmpty()) + return naturalWondersToFind.random() + + return null + } + /** * Returns a Great Person [BaseUnit] that is not owned by both the [challenger] and the [civInfo] */ @@ -387,7 +402,7 @@ class QuestManager { .distinct() .filter { !challengerGreatPeople.contains(it) && !cityStateGreatPeople.contains(it) } .toList() - + if (greatPeople.isNotEmpty()) return greatPeople.random() diff --git a/core/src/com/unciv/logic/map/TileMap.kt b/core/src/com/unciv/logic/map/TileMap.kt index 6b74f87b09..2398daf522 100644 --- a/core/src/com/unciv/logic/map/TileMap.kt +++ b/core/src/com/unciv/logic/map/TileMap.kt @@ -18,6 +18,7 @@ class TileMap { @Transient var bottomY = 0 @delegate:Transient val maxLatitude: Float by lazy { if (values.isEmpty()) 0f else values.map { abs(it.latitude) }.max()!! } @delegate:Transient val maxLongitude: Float by lazy { if (values.isEmpty()) 0f else values.map { abs(it.longitude) }.max()!! } + @delegate:Transient val naturalWonders: List by lazy { tileList.asSequence().filter { it.isNaturalWonder() }.map { it.naturalWonder!! }.distinct().toList() } var mapParameters = MapParameters()