Skip to content

Commit

Permalink
fix: user only receives yellow resource notification if it is researc…
Browse files Browse the repository at this point in the history
…hed (#12337)

* When resource is not researched, don't allow the user to scan the map for it

* inline ruleset.getResource() in getExploredResourcesNotification (resolved review comment)

* changed TechManager.isRevealed (review feedback)

---------

Co-authored-by: M. Rittweger <[email protected]>
  • Loading branch information
sulai and mrimvo authored Oct 24, 2024
1 parent e348b7c commit 32247fe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion core/src/com/unciv/logic/GameInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ class GameInfo : IsPartOfGameInfoSerialization, HasGameInfoSerializationVersion
return true
}

/** Generate a notification pointing out resources.
/** Generate a notification pointing out resources. Only researched Resources are considered.
* @param maxDistance from next City, default removes distance limitation.
* @param filter optional tile filter predicate, e.g. to exclude foreign territory.
* @return `null` if no resources were found, otherwise a Notification instance.
Expand All @@ -548,6 +548,12 @@ class GameInfo : IsPartOfGameInfoSerialization, HasGameInfoSerializationVersion
maxDistance: Int = Int.MAX_VALUE,
filter: (Tile) -> Boolean = { true }
): Notification? {

val resource = ruleset.tileResources[resourceName] ?: return null
if (!civ.tech.isRevealed(resource)) {
return null
}

data class CityTileAndDistance(val city: City, val tile: Tile, val distance: Int)

// Include your city-state allies' cities with your own for the purpose of showing the closest city
Expand Down
7 changes: 7 additions & 0 deletions core/src/com/unciv/logic/civilization/managers/TechManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.unciv.logic.map.tile.RoadStatus
import com.unciv.models.ruleset.INonPerpetualConstruction
import com.unciv.models.ruleset.tech.Era
import com.unciv.models.ruleset.tech.Technology
import com.unciv.models.ruleset.tile.TileResource
import com.unciv.models.ruleset.unique.StateForConditionals
import com.unciv.models.ruleset.unique.UniqueMap
import com.unciv.models.ruleset.unique.UniqueTriggerActivation
Expand Down Expand Up @@ -155,6 +156,12 @@ class TechManager : IsPartOfGameInfoSerialization {

fun isResearched(construction: INonPerpetualConstruction): Boolean = construction.requiredTechs().all{ requiredTech -> isResearched(requiredTech) }

/** resources which need no research count as researched */
fun isRevealed(resource: TileResource): Boolean {
val revealedBy = resource.revealedBy ?: return true
return isResearched(revealedBy)
}

fun isObsolete(unit: BaseUnit): Boolean = unit.techsThatObsoleteThis().any{ obsoleteTech -> isResearched(obsoleteTech) }

fun isUnresearchable(tech: Technology): Boolean {
Expand Down

0 comments on commit 32247fe

Please sign in to comment.