mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-06 00:09:23 +07:00
Connect Resource Quest implemented (#3209)
* Removed superfluous filters in getResourceForQuest
This commit is contained in:
@ -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."
|
||||
|
@ -165,6 +165,10 @@ class CivilizationInfo {
|
||||
return newResourceSupplyList
|
||||
}
|
||||
|
||||
fun getViewableResources(): List<TileResource> =
|
||||
gameInfo.ruleSet.tileResources.values
|
||||
.filter { it.revealedBy == null || tech.isResearched(it.revealedBy!!) }
|
||||
|
||||
fun isCapitalConnectedToCity(city: CityInfo): Boolean = citiesConnectedToCapitalToMediums.keys.contains(city)
|
||||
|
||||
|
||||
|
@ -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 ->
|
||||
|
Reference in New Issue
Block a user