mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-26 13:27:22 -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"],
|
||||
"food": 1,
|
||||
"improvement": "Pasture",
|
||||
"improvementStats": {"production": 1},
|
||||
"improvementStats": {"production": 1}
|
||||
},
|
||||
{
|
||||
"name": "Sheep",
|
||||
@ -75,7 +75,9 @@
|
||||
"terrainsCanBeFoundOn": ["Plains","Grassland","Hill","Desert"],
|
||||
"production": 1,
|
||||
"improvement": "Pasture",
|
||||
"improvementStats": {"production": 1}
|
||||
"improvementStats": {"production": 1},
|
||||
"majorDepositAmount": {"sparse": 4, "default": 4, "abundant": 6},
|
||||
"minorDepositAmount": {"sparse": 1, "default": 2, "abundant": 3}
|
||||
},
|
||||
{
|
||||
"name": "Iron",
|
||||
@ -84,7 +86,9 @@
|
||||
"terrainsCanBeFoundOn": ["Grassland","Plains","Desert","Tundra","Snow","Hill"],
|
||||
"production": 1,
|
||||
"improvement": "Mine",
|
||||
"improvementStats": {"production": 1}
|
||||
"improvementStats": {"production": 1},
|
||||
"majorDepositAmount": {"sparse": 4, "default": 6, "abundant": 9},
|
||||
"minorDepositAmount": {"sparse": 1, "default": 2, "abundant": 3}
|
||||
},
|
||||
{
|
||||
"name": "Coal",
|
||||
@ -93,7 +97,9 @@
|
||||
"terrainsCanBeFoundOn": ["Grassland","Plains","Hill"],
|
||||
"production": 1,
|
||||
"improvement": "Mine",
|
||||
"improvementStats": {"production": 2}
|
||||
"improvementStats": {"production": 2},
|
||||
"majorDepositAmount": {"sparse": 5, "default": 7, "abundant": 10},
|
||||
"minorDepositAmount": {"sparse": 2, "default": 3, "abundant": 3}
|
||||
},
|
||||
{
|
||||
"name": "Oil",
|
||||
@ -102,7 +108,10 @@
|
||||
"terrainsCanBeFoundOn": ["Desert","Coast","Tundra","Snow","Marsh","Jungle"],
|
||||
"production": 1,
|
||||
"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",
|
||||
@ -111,7 +120,9 @@
|
||||
"terrainsCanBeFoundOn": ["Plains","Desert","Tundra","Hill"],
|
||||
"production": 1,
|
||||
"improvement": "Mine",
|
||||
"improvementStats": {"production": 2}
|
||||
"improvementStats": {"production": 2},
|
||||
"majorDepositAmount": {"sparse": 5, "default": 8, "abundant": 10},
|
||||
"minorDepositAmount": {"sparse": 2, "default": 3, "abundant": 3}
|
||||
},
|
||||
{
|
||||
"name": "Uranium",
|
||||
@ -120,7 +131,9 @@
|
||||
"terrainsCanBeFoundOn": ["Plains","Desert","Tundra","Hill","Snow","Forest","Desert","Marsh","Grassland"],
|
||||
"production": 1,
|
||||
"improvement": "Mine",
|
||||
"improvementStats": {"production": 2}
|
||||
"improvementStats": {"production": 2},
|
||||
"majorDepositAmount": {"sparse": 2, "default": 4, "abundant": 4},
|
||||
"minorDepositAmount": {"sparse": 1, "default": 2, "abundant": 3}
|
||||
},
|
||||
|
||||
// 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
|
||||
|| resource.resourceType == ResourceType.Strategic && tileInfo.containsGreatImprovement()
|
||||
) {
|
||||
var amountToAdd = 1
|
||||
if (resource.resourceType == ResourceType.Strategic) {
|
||||
amountToAdd = 2
|
||||
}
|
||||
var amountToAdd = if (resource.resourceType == ResourceType.Strategic) tileInfo.resourceAmount
|
||||
else 1
|
||||
if (resource.resourceType == ResourceType.Luxury
|
||||
&& containsBuildingUnique("Provides 1 extra copy of each improved luxury resource near this City")
|
||||
)
|
||||
amountToAdd *= 2
|
||||
amountToAdd += 1
|
||||
|
||||
return amountToAdd
|
||||
}
|
||||
|
@ -59,6 +59,7 @@ open class TileInfo {
|
||||
|
||||
var naturalWonder: String? = null
|
||||
var resource: String? = null
|
||||
var resourceAmount: Int = 0
|
||||
var improvement: String? = null
|
||||
var improvementInProgress: String? = null
|
||||
|
||||
@ -88,6 +89,7 @@ open class TileInfo {
|
||||
toReturn.terrainFeatures.addAll(terrainFeatures)
|
||||
toReturn.naturalWonder = naturalWonder
|
||||
toReturn.resource = resource
|
||||
toReturn.resourceAmount = resourceAmount
|
||||
toReturn.improvement = improvement
|
||||
toReturn.improvementInProgress = improvementInProgress
|
||||
toReturn.roadStatus = roadStatus
|
||||
@ -561,7 +563,12 @@ open class TileInfo {
|
||||
if (isCityCenter()) lineList += getCity()!!.name
|
||||
lineList += baseTerrain
|
||||
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 (roadStatus !== RoadStatus.None && !isCityCenter()) lineList += roadStatus.name
|
||||
if (improvement != null) lineList += improvement!!
|
||||
@ -619,7 +626,10 @@ open class TileInfo {
|
||||
for (terrainFeature in terrainFeatures)
|
||||
lineList += FormattedLine(terrainFeature, link="Terrain/$terrainFeature")
|
||||
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)
|
||||
lineList += FormattedLine(naturalWonder!!, link="Terrain/$naturalWonder")
|
||||
if (roadStatus !== RoadStatus.None && !isCityCenter())
|
||||
@ -702,6 +712,12 @@ open class TileInfo {
|
||||
isWater = getBaseTerrain().type == TerrainType.Water
|
||||
isLand = getBaseTerrain().type == TerrainType.Land
|
||||
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) {
|
||||
@ -716,6 +732,25 @@ open class TileInfo {
|
||||
fun stripUnits() {
|
||||
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
|
||||
|
@ -187,7 +187,7 @@ class MapGenerator(val ruleset: Ruleset) {
|
||||
|
||||
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) {
|
||||
val possibleResources = resourcesOfType
|
||||
.filter { it.terrainsCanBeFoundOn.contains(tile.getLastTerrain().name) }
|
||||
.map { it.name }
|
||||
if (possibleResources.isEmpty()) continue
|
||||
val resourceWithLeastAssignments = possibleResources.minByOrNull { resourceToNumber[it]!! }!!
|
||||
resourceToNumber.add(resourceWithLeastAssignments, 1)
|
||||
tile.resource = resourceWithLeastAssignments
|
||||
val resourceWithLeastAssignments = possibleResources.minByOrNull { resourceToNumber[it.name]!! }!!
|
||||
resourceToNumber.add(resourceWithLeastAssignments.name, 1)
|
||||
tile.setTileResource(resourceWithLeastAssignments)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,9 @@ class TileResource : RulesetStatsObject() {
|
||||
var revealedBy: String? = null
|
||||
@Deprecated("As of 3.16.16 - replaced by uniques")
|
||||
var unique: String? = null
|
||||
var majorDepositAmount: DepositAmount = DepositAmount()
|
||||
var minorDepositAmount: DepositAmount = DepositAmount()
|
||||
|
||||
override fun getUniqueTarget() = UniqueTarget.Resource
|
||||
|
||||
|
||||
@ -83,6 +86,12 @@ class TileResource : RulesetStatsObject() {
|
||||
|
||||
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),
|
||||
|
||||
OverrideDepositAmountOnTileFilter("Deposits in [tileFilter] tiles always provide [amount] resources", UniqueTarget.Resource),
|
||||
|
||||
///////////////////////////////////////// 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
|
||||
val resourceHex = getHex(ImageGetter.getResourceImage(resource.name, 40f))
|
||||
resourceHex.onClick {
|
||||
tileAction = { it.resource = resource.name }
|
||||
tileAction = { it.setTileResource(resource) }
|
||||
|
||||
// for the tile image
|
||||
val tileInfo = TileInfo()
|
||||
|
Loading…
x
Reference in New Issue
Block a user