mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-25 21:03:15 -04:00
Add uniques and constants for unit supply (#6146)
* Code readability * Uniques & constants for unit supply * Fixed tests * Added a cityFilter to the 'supply per pop' unique
This commit is contained in:
parent
f03a6bd6b3
commit
f5e9952caf
@ -112,9 +112,25 @@ class CivInfoStats(val civInfo: CivilizationInfo) {
|
||||
return supply
|
||||
}
|
||||
|
||||
fun getBaseUnitSupply(): Int = civInfo.getDifficulty().unitSupplyBase
|
||||
fun getUnitSupplyFromCities(): Int = civInfo.cities.size * civInfo.getDifficulty().unitSupplyPerCity
|
||||
fun getUnitSupplyFromPop(): Int = civInfo.cities.sumOf { it.population.population } / 2
|
||||
fun getBaseUnitSupply(): Int {
|
||||
return civInfo.getDifficulty().unitSupplyBase +
|
||||
civInfo.getMatchingUniques(UniqueType.BaseUnitSupply).sumOf { it.params[0].toInt() }
|
||||
}
|
||||
fun getUnitSupplyFromCities(): Int {
|
||||
return civInfo.cities.size *
|
||||
(civInfo.getDifficulty().unitSupplyPerCity + civInfo.getMatchingUniques(UniqueType.UnitSupplyPerCity).sumOf { it.params[0].toInt() })
|
||||
}
|
||||
fun getUnitSupplyFromPop(): Int {
|
||||
var totalSupply = civInfo.cities.sumOf { it.population.population } * civInfo.gameInfo.ruleSet.modOptions.constants.unitSupplyPerPopulation
|
||||
|
||||
for (unique in civInfo.getMatchingUniques(UniqueType.UnitSupplyPerPop)) {
|
||||
val applicablePopulation = civInfo.cities
|
||||
.filter { it.matchesFilter(unique.params[1]) }
|
||||
.sumOf { it.population.population }
|
||||
totalSupply += unique.params[0].toDouble() * applicablePopulation
|
||||
}
|
||||
return totalSupply.toInt()
|
||||
}
|
||||
fun getUnitSupplyDeficit(): Int = max(0,civInfo.getCivUnitsSize() - getUnitSupply())
|
||||
|
||||
/** Per each supply missing, a player gets -10% production. Capped at -70%. */
|
||||
|
@ -575,7 +575,7 @@ class CivilizationInfo {
|
||||
if (otherCiv.civName == civName) return false // never at war with itself
|
||||
if (otherCiv.isBarbarian() || isBarbarian()) return true
|
||||
val diplomacyManager = diplomacy[otherCiv.civName]
|
||||
?: return false // not encountered yet
|
||||
?: return false // not encountered yet
|
||||
return diplomacyManager.diplomaticStatus == DiplomaticStatus.War
|
||||
}
|
||||
|
||||
|
@ -82,13 +82,15 @@ class UnitMovementAlgorithms(val unit:MapUnit) {
|
||||
return terrainCost + extraCost // no road or other movement cost reduction
|
||||
}
|
||||
|
||||
fun getTilesExertingZoneOfControl(tileInfo: TileInfo, civInfo: CivilizationInfo): Sequence<TileInfo> {
|
||||
return tileInfo.neighbors.filter {
|
||||
it.isCityCenter() && civInfo.isAtWarWith(it.getOwner()!!)
|
||||
||
|
||||
it.militaryUnit != null &&
|
||||
civInfo.isAtWarWith(it.militaryUnit!!.civInfo) &&
|
||||
(it.militaryUnit!!.type.isWaterUnit() || (!it.militaryUnit!!.isEmbarked() && unit.type.isLandUnit()))
|
||||
private fun getTilesExertingZoneOfControl(tileInfo: TileInfo, civInfo: CivilizationInfo) = sequence {
|
||||
for (tile in tileInfo.neighbors) {
|
||||
if (tile.isCityCenter() && civInfo.isAtWarWith(tile.getOwner()!!)) {
|
||||
yield(tile)
|
||||
}
|
||||
else if (tile.militaryUnit != null && civInfo.isAtWarWith(tile.militaryUnit!!.civInfo)) {
|
||||
if (tile.militaryUnit!!.type.isWaterUnit() || (unit.type.isLandUnit() && tile.militaryUnit!!.isEmbarked()))
|
||||
yield(tile)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,5 +17,12 @@ class ModConstants {
|
||||
val cityStrengthFromTechsExponent = 2.8
|
||||
val cityStrengthFromTechsFullMultiplier = 1.0
|
||||
val cityStrengthFromGarrison = 0.2
|
||||
|
||||
|
||||
// Formula for Unit Supply:
|
||||
// Supply = unitSupplyBase (difficulties.json)
|
||||
// unitSupplyPerCity * amountOfCities + (difficulties.json)
|
||||
// unitSupplyPerPopulation * amountOfPopulationInAllCities
|
||||
// unitSupplyBase and unitSupplyPerCity can be found in difficulties.json
|
||||
// unitSupplyBase, unitSupplyPerCity and unitSupplyPerPopulation can also be increased through uniques
|
||||
val unitSupplyPerPopulation = 0.5
|
||||
}
|
@ -289,6 +289,10 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags:
|
||||
StartsWithTech("Starts with [tech]", UniqueTarget.Nation),
|
||||
ResearchableMultipleTimes("Can be continually researched", UniqueTarget.Global),
|
||||
|
||||
BaseUnitSupply("[amount] Unit Supply", UniqueTarget.Global),
|
||||
UnitSupplyPerPop("[amount] Unit Supply per [amount] population [cityFilter]", UniqueTarget.Global),
|
||||
UnitSupplyPerCity("[amount] Unit Supply per city", UniqueTarget.Global),
|
||||
|
||||
SpawnRebels("Rebel units may spawn", UniqueTarget.Global),
|
||||
|
||||
//endregion
|
||||
|
@ -448,6 +448,21 @@ Applicable to: Global, FollowerBelief
|
||||
#### Can be continually researched
|
||||
Applicable to: Global
|
||||
|
||||
#### [amount] Unit Supply
|
||||
Example: "[20] Unit Supply"
|
||||
|
||||
Applicable to: Global
|
||||
|
||||
#### [amount] Unit Supply per [amount] population [cityFilter]
|
||||
Example: "[20] Unit Supply per [20] population [in all cities]"
|
||||
|
||||
Applicable to: Global
|
||||
|
||||
#### [amount] Unit Supply per city
|
||||
Example: "[20] Unit Supply per city"
|
||||
|
||||
Applicable to: Global
|
||||
|
||||
#### Rebel units may spawn
|
||||
Applicable to: Global
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user