mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 13:55:54 -04:00
Variable resource quantities (#5456)
* implement varying resource amounts * works on old maps * reviews
This commit is contained in:
parent
1a92f9c084
commit
36711f70ad
@ -6,7 +6,7 @@
|
|||||||
"terrainsCanBeFoundOn": ["Grassland"],
|
"terrainsCanBeFoundOn": ["Grassland"],
|
||||||
"food": 1,
|
"food": 1,
|
||||||
"improvement": "Pasture",
|
"improvement": "Pasture",
|
||||||
"improvementStats": {"production": 1},
|
"improvementStats": {"production": 1}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Sheep",
|
"name": "Sheep",
|
||||||
@ -75,7 +75,9 @@
|
|||||||
"terrainsCanBeFoundOn": ["Plains","Grassland","Hill","Desert"],
|
"terrainsCanBeFoundOn": ["Plains","Grassland","Hill","Desert"],
|
||||||
"production": 1,
|
"production": 1,
|
||||||
"improvement": "Pasture",
|
"improvement": "Pasture",
|
||||||
"improvementStats": {"production": 1}
|
"improvementStats": {"production": 1},
|
||||||
|
"majorDepositAmount": {"sparse": 4, "default": 4, "abundant": 6},
|
||||||
|
"minorDepositAmount": {"sparse": 1, "default": 2, "abundant": 3}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Iron",
|
"name": "Iron",
|
||||||
@ -84,7 +86,9 @@
|
|||||||
"terrainsCanBeFoundOn": ["Grassland","Plains","Desert","Tundra","Snow","Hill"],
|
"terrainsCanBeFoundOn": ["Grassland","Plains","Desert","Tundra","Snow","Hill"],
|
||||||
"production": 1,
|
"production": 1,
|
||||||
"improvement": "Mine",
|
"improvement": "Mine",
|
||||||
"improvementStats": {"production": 1}
|
"improvementStats": {"production": 1},
|
||||||
|
"majorDepositAmount": {"sparse": 4, "default": 6, "abundant": 9},
|
||||||
|
"minorDepositAmount": {"sparse": 1, "default": 2, "abundant": 3}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Coal",
|
"name": "Coal",
|
||||||
@ -93,7 +97,9 @@
|
|||||||
"terrainsCanBeFoundOn": ["Grassland","Plains","Hill"],
|
"terrainsCanBeFoundOn": ["Grassland","Plains","Hill"],
|
||||||
"production": 1,
|
"production": 1,
|
||||||
"improvement": "Mine",
|
"improvement": "Mine",
|
||||||
"improvementStats": {"production": 2}
|
"improvementStats": {"production": 2},
|
||||||
|
"majorDepositAmount": {"sparse": 5, "default": 7, "abundant": 10},
|
||||||
|
"minorDepositAmount": {"sparse": 2, "default": 3, "abundant": 3}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Oil",
|
"name": "Oil",
|
||||||
@ -102,7 +108,10 @@
|
|||||||
"terrainsCanBeFoundOn": ["Desert","Coast","Tundra","Snow","Marsh","Jungle"],
|
"terrainsCanBeFoundOn": ["Desert","Coast","Tundra","Snow","Marsh","Jungle"],
|
||||||
"production": 1,
|
"production": 1,
|
||||||
"improvement": "Oil well",
|
"improvement": "Oil well",
|
||||||
"improvementStats": {"production": 3}
|
"improvementStats": {"production": 3},
|
||||||
|
"uniques": ["Deposits in [Water] tiles always provide [4] resources"],
|
||||||
|
"majorDepositAmount": {"sparse": 5, "default": 7, "abundant": 9},
|
||||||
|
"minorDepositAmount": {"sparse": 2, "default": 3, "abundant": 3}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Aluminum",
|
"name": "Aluminum",
|
||||||
@ -111,7 +120,9 @@
|
|||||||
"terrainsCanBeFoundOn": ["Plains","Desert","Tundra","Hill"],
|
"terrainsCanBeFoundOn": ["Plains","Desert","Tundra","Hill"],
|
||||||
"production": 1,
|
"production": 1,
|
||||||
"improvement": "Mine",
|
"improvement": "Mine",
|
||||||
"improvementStats": {"production": 2}
|
"improvementStats": {"production": 2},
|
||||||
|
"majorDepositAmount": {"sparse": 5, "default": 8, "abundant": 10},
|
||||||
|
"minorDepositAmount": {"sparse": 2, "default": 3, "abundant": 3}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Uranium",
|
"name": "Uranium",
|
||||||
@ -120,7 +131,9 @@
|
|||||||
"terrainsCanBeFoundOn": ["Plains","Desert","Tundra","Hill","Snow","Forest","Desert","Marsh","Grassland"],
|
"terrainsCanBeFoundOn": ["Plains","Desert","Tundra","Hill","Snow","Forest","Desert","Marsh","Grassland"],
|
||||||
"production": 1,
|
"production": 1,
|
||||||
"improvement": "Mine",
|
"improvement": "Mine",
|
||||||
"improvementStats": {"production": 2}
|
"improvementStats": {"production": 2},
|
||||||
|
"majorDepositAmount": {"sparse": 2, "default": 4, "abundant": 4},
|
||||||
|
"minorDepositAmount": {"sparse": 1, "default": 2, "abundant": 3}
|
||||||
},
|
},
|
||||||
|
|
||||||
// Luxury resources
|
// Luxury resources
|
||||||
|
@ -356,14 +356,12 @@ class CityInfo {
|
|||||||
// Per https://gaming.stackexchange.com/questions/53155/do-manufactories-and-customs-houses-sacrifice-the-strategic-or-luxury-resources
|
// Per https://gaming.stackexchange.com/questions/53155/do-manufactories-and-customs-houses-sacrifice-the-strategic-or-luxury-resources
|
||||||
|| resource.resourceType == ResourceType.Strategic && tileInfo.containsGreatImprovement()
|
|| resource.resourceType == ResourceType.Strategic && tileInfo.containsGreatImprovement()
|
||||||
) {
|
) {
|
||||||
var amountToAdd = 1
|
var amountToAdd = if (resource.resourceType == ResourceType.Strategic) tileInfo.resourceAmount
|
||||||
if (resource.resourceType == ResourceType.Strategic) {
|
else 1
|
||||||
amountToAdd = 2
|
|
||||||
}
|
|
||||||
if (resource.resourceType == ResourceType.Luxury
|
if (resource.resourceType == ResourceType.Luxury
|
||||||
&& containsBuildingUnique("Provides 1 extra copy of each improved luxury resource near this City")
|
&& containsBuildingUnique("Provides 1 extra copy of each improved luxury resource near this City")
|
||||||
)
|
)
|
||||||
amountToAdd *= 2
|
amountToAdd += 1
|
||||||
|
|
||||||
return amountToAdd
|
return amountToAdd
|
||||||
}
|
}
|
||||||
|
@ -59,6 +59,7 @@ open class TileInfo {
|
|||||||
|
|
||||||
var naturalWonder: String? = null
|
var naturalWonder: String? = null
|
||||||
var resource: String? = null
|
var resource: String? = null
|
||||||
|
var resourceAmount: Int = 0
|
||||||
var improvement: String? = null
|
var improvement: String? = null
|
||||||
var improvementInProgress: String? = null
|
var improvementInProgress: String? = null
|
||||||
|
|
||||||
@ -88,6 +89,7 @@ open class TileInfo {
|
|||||||
toReturn.terrainFeatures.addAll(terrainFeatures)
|
toReturn.terrainFeatures.addAll(terrainFeatures)
|
||||||
toReturn.naturalWonder = naturalWonder
|
toReturn.naturalWonder = naturalWonder
|
||||||
toReturn.resource = resource
|
toReturn.resource = resource
|
||||||
|
toReturn.resourceAmount = resourceAmount
|
||||||
toReturn.improvement = improvement
|
toReturn.improvement = improvement
|
||||||
toReturn.improvementInProgress = improvementInProgress
|
toReturn.improvementInProgress = improvementInProgress
|
||||||
toReturn.roadStatus = roadStatus
|
toReturn.roadStatus = roadStatus
|
||||||
@ -561,7 +563,12 @@ open class TileInfo {
|
|||||||
if (isCityCenter()) lineList += getCity()!!.name
|
if (isCityCenter()) lineList += getCity()!!.name
|
||||||
lineList += baseTerrain
|
lineList += baseTerrain
|
||||||
for (terrainFeature in terrainFeatures) lineList += terrainFeature
|
for (terrainFeature in terrainFeatures) lineList += terrainFeature
|
||||||
if (resource != null) lineList += resource!!
|
if (resource != null) {
|
||||||
|
lineList += if (getTileResource().resourceType == ResourceType.Strategic)
|
||||||
|
"{$resourceAmount} {$resource}"
|
||||||
|
else
|
||||||
|
resource!!
|
||||||
|
}
|
||||||
if (naturalWonder != null) lineList += naturalWonder!!
|
if (naturalWonder != null) lineList += naturalWonder!!
|
||||||
if (roadStatus !== RoadStatus.None && !isCityCenter()) lineList += roadStatus.name
|
if (roadStatus !== RoadStatus.None && !isCityCenter()) lineList += roadStatus.name
|
||||||
if (improvement != null) lineList += improvement!!
|
if (improvement != null) lineList += improvement!!
|
||||||
@ -619,7 +626,10 @@ open class TileInfo {
|
|||||||
for (terrainFeature in terrainFeatures)
|
for (terrainFeature in terrainFeatures)
|
||||||
lineList += FormattedLine(terrainFeature, link="Terrain/$terrainFeature")
|
lineList += FormattedLine(terrainFeature, link="Terrain/$terrainFeature")
|
||||||
if (resource != null && (viewingCiv == null || hasViewableResource(viewingCiv)))
|
if (resource != null && (viewingCiv == null || hasViewableResource(viewingCiv)))
|
||||||
lineList += FormattedLine(resource!!, link="Resource/$resource")
|
lineList += if (getTileResource().resourceType == ResourceType.Strategic)
|
||||||
|
FormattedLine("{$resource} ($resourceAmount)", link="Resource/$resource")
|
||||||
|
else
|
||||||
|
FormattedLine(resource!!, link="Resource/$resource")
|
||||||
if (naturalWonder != null)
|
if (naturalWonder != null)
|
||||||
lineList += FormattedLine(naturalWonder!!, link="Terrain/$naturalWonder")
|
lineList += FormattedLine(naturalWonder!!, link="Terrain/$naturalWonder")
|
||||||
if (roadStatus !== RoadStatus.None && !isCityCenter())
|
if (roadStatus !== RoadStatus.None && !isCityCenter())
|
||||||
@ -702,6 +712,12 @@ open class TileInfo {
|
|||||||
isWater = getBaseTerrain().type == TerrainType.Water
|
isWater = getBaseTerrain().type == TerrainType.Water
|
||||||
isLand = getBaseTerrain().type == TerrainType.Land
|
isLand = getBaseTerrain().type == TerrainType.Land
|
||||||
isOcean = baseTerrain == Constants.ocean
|
isOcean = baseTerrain == Constants.ocean
|
||||||
|
|
||||||
|
// Resource amounts missing - Old save or bad mapgen?
|
||||||
|
if (resource != null && getTileResource().resourceType == ResourceType.Strategic && resourceAmount == 0) {
|
||||||
|
// Let's assume it's a small deposit
|
||||||
|
setTileResource(getTileResource(), majorDeposit = false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setUnitTransients(unitCivTransients: Boolean) {
|
fun setUnitTransients(unitCivTransients: Boolean) {
|
||||||
@ -716,6 +732,25 @@ open class TileInfo {
|
|||||||
fun stripUnits() {
|
fun stripUnits() {
|
||||||
for (unit in this.getUnits()) removeUnit(unit)
|
for (unit in this.getUnits()) removeUnit(unit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setTileResource(newResource: TileResource, majorDeposit: Boolean = false) {
|
||||||
|
resource = newResource.name
|
||||||
|
|
||||||
|
if (newResource.resourceType != ResourceType.Strategic) return
|
||||||
|
|
||||||
|
for (unique in newResource.getMatchingUniques(UniqueType.OverrideDepositAmountOnTileFilter)) {
|
||||||
|
if (matchesTerrainFilter(unique.params[0])) {
|
||||||
|
resourceAmount = unique.params[1].toInt()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stick to default for now
|
||||||
|
resourceAmount = if (majorDeposit)
|
||||||
|
newResource.majorDepositAmount.default
|
||||||
|
else
|
||||||
|
newResource.minorDepositAmount.default
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/** If the unit isn't in the ruleset we can't even know what type of unit this is! So check each place
|
/** If the unit isn't in the ruleset we can't even know what type of unit this is! So check each place
|
||||||
|
@ -187,7 +187,7 @@ class MapGenerator(val ruleset: Ruleset) {
|
|||||||
|
|
||||||
val locations = randomness.chooseSpreadOutLocations(resourcesPerType, suitableTiles, mapRadius)
|
val locations = randomness.chooseSpreadOutLocations(resourcesPerType, suitableTiles, mapRadius)
|
||||||
|
|
||||||
for (location in locations) location.resource = resource.name
|
for (location in locations) location.setTileResource(resource)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,11 +211,10 @@ class MapGenerator(val ruleset: Ruleset) {
|
|||||||
for (tile in locations) {
|
for (tile in locations) {
|
||||||
val possibleResources = resourcesOfType
|
val possibleResources = resourcesOfType
|
||||||
.filter { it.terrainsCanBeFoundOn.contains(tile.getLastTerrain().name) }
|
.filter { it.terrainsCanBeFoundOn.contains(tile.getLastTerrain().name) }
|
||||||
.map { it.name }
|
|
||||||
if (possibleResources.isEmpty()) continue
|
if (possibleResources.isEmpty()) continue
|
||||||
val resourceWithLeastAssignments = possibleResources.minByOrNull { resourceToNumber[it]!! }!!
|
val resourceWithLeastAssignments = possibleResources.minByOrNull { resourceToNumber[it.name]!! }!!
|
||||||
resourceToNumber.add(resourceWithLeastAssignments, 1)
|
resourceToNumber.add(resourceWithLeastAssignments.name, 1)
|
||||||
tile.resource = resourceWithLeastAssignments
|
tile.setTileResource(resourceWithLeastAssignments)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,9 @@ class TileResource : RulesetStatsObject() {
|
|||||||
var revealedBy: String? = null
|
var revealedBy: String? = null
|
||||||
@Deprecated("As of 3.16.16 - replaced by uniques")
|
@Deprecated("As of 3.16.16 - replaced by uniques")
|
||||||
var unique: String? = null
|
var unique: String? = null
|
||||||
|
var majorDepositAmount: DepositAmount = DepositAmount()
|
||||||
|
var minorDepositAmount: DepositAmount = DepositAmount()
|
||||||
|
|
||||||
override fun getUniqueTarget() = UniqueTarget.Resource
|
override fun getUniqueTarget() = UniqueTarget.Resource
|
||||||
|
|
||||||
|
|
||||||
@ -83,6 +86,12 @@ class TileResource : RulesetStatsObject() {
|
|||||||
|
|
||||||
return textList
|
return textList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class DepositAmount {
|
||||||
|
var sparse: Int = 1
|
||||||
|
var default: Int = 2
|
||||||
|
var abundant: Int = 3
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,6 +234,8 @@ enum class UniqueType(val text:String, vararg targets: UniqueTarget) {
|
|||||||
|
|
||||||
NoNaturalGeneration("Doesn't generate naturally", UniqueTarget.Terrain),
|
NoNaturalGeneration("Doesn't generate naturally", UniqueTarget.Terrain),
|
||||||
|
|
||||||
|
OverrideDepositAmountOnTileFilter("Deposits in [tileFilter] tiles always provide [amount] resources", UniqueTarget.Resource),
|
||||||
|
|
||||||
///////////////////////////////////////// CONDITIONALS /////////////////////////////////////////
|
///////////////////////////////////////// CONDITIONALS /////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
@ -292,7 +292,7 @@ class MapEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(CameraS
|
|||||||
if (resource.terrainsCanBeFoundOn.none { ruleset.terrains.containsKey(it) }) continue // This resource can't be placed
|
if (resource.terrainsCanBeFoundOn.none { ruleset.terrains.containsKey(it) }) continue // This resource can't be placed
|
||||||
val resourceHex = getHex(ImageGetter.getResourceImage(resource.name, 40f))
|
val resourceHex = getHex(ImageGetter.getResourceImage(resource.name, 40f))
|
||||||
resourceHex.onClick {
|
resourceHex.onClick {
|
||||||
tileAction = { it.resource = resource.name }
|
tileAction = { it.setTileResource(resource) }
|
||||||
|
|
||||||
// for the tile image
|
// for the tile image
|
||||||
val tileInfo = TileInfo()
|
val tileInfo = TileInfo()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user