Skip to content

Commit

Permalink
City states adjustments (#4597)
Browse files Browse the repository at this point in the history
* city-state AI

* City-state spawns

* City-state border expansion

* City-state border expansion adjustment

* Food and production multipliers for city states

* 6 CS as default
  • Loading branch information
SimonCeder authored Jul 22, 2021
1 parent e41ba0d commit f41d30e
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 6 deletions.
8 changes: 4 additions & 4 deletions core/src/com/unciv/logic/GameStarter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,11 @@ object GameStarter {


if (civ.isCityState()) {
// City states should spawn with one settler only irregardless of era and difficulty
val startingSettlers = startingUnits.filter { settlerLikeUnits.contains(it) }
if (startingSettlers.count() > 1) {
startingUnits = startingUnits.filter { !settlerLikeUnits.contains(it) }.toMutableList()
startingUnits.add(startingSettlers.random())
}

startingUnits.clear()
startingUnits.add( startingSettlers.random() )
}

for (unit in startingUnits) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ object SpecificUnitAutomation {
}
}

if (unit.getTile().militaryUnit == null) return // Don't move until you're accompanied by a military unit
if (unit.getTile().militaryUnit == null // Don't move until you're accompanied by a military unit
&& !unit.civInfo.isCityState()) return // ..unless you're a city state that was unable to settle its city on turn 1

val tilesNearCities = unit.civInfo.gameInfo.getCities().asSequence()
.flatMap {
Expand Down
1 change: 1 addition & 0 deletions core/src/com/unciv/logic/automation/UnitAutomation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ object UnitAutomation {
&& (tile.getOwner() == null || !tile.getOwner()!!.isCityState())
&& tile.neighbors.any { it.position !in unit.civInfo.exploredTiles }
&& unit.movement.canReach(tile)
&& (!unit.civInfo.isCityState() || tile.neighbors.any { it.getOwner() == unit.civInfo }) // Don't want city-states exploring far outside their borders
}

internal fun tryExplore(unit: MapUnit): Boolean {
Expand Down
5 changes: 5 additions & 0 deletions core/src/com/unciv/logic/city/CityExpansionManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.unciv.logic.map.TileInfo
import com.unciv.ui.utils.withItem
import com.unciv.ui.utils.withoutItem
import kotlin.math.max
import kotlin.math.min
import kotlin.math.pow
import kotlin.math.roundToInt

Expand Down Expand Up @@ -35,6 +36,10 @@ class CityExpansionManager {
// The second seems to be more based, so I'll go with that
fun getCultureToNextTile(): Int {
var cultureToNextTile = 6 * (max(0, tilesClaimed()) + 1.4813).pow(1.3)

if (cityInfo.civInfo.isCityState())
cultureToNextTile *= 1.5f // City states grow slower, perhaps 150% cost?

for (unique in cityInfo.civInfo.getMatchingUniques("-[]% Culture cost of acquiring tiles []")) {
if (cityInfo.matchesFilter(unique.params[1]))
cultureToNextTile *= (100 - unique.params[0].toFloat()) / 100
Expand Down
2 changes: 2 additions & 0 deletions core/src/com/unciv/logic/city/PopulationManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class PopulationManager {
fun getFoodToNextPopulation(): Int {
// civ v math, civilization.wikia
var foodRequired = 15 + 6 * (population - 1) + floor((population - 1).toDouble().pow(1.8))
if (cityInfo.civInfo.isCityState())
foodRequired *= 1.5f
if (!cityInfo.civInfo.isPlayerCivilization())
foodRequired *= cityInfo.civInfo.gameInfo.getDifficulty().aiCityGrowthModifier
return foodRequired.toInt()
Expand Down
2 changes: 1 addition & 1 deletion core/src/com/unciv/models/metadata/GameParameters.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class GameParameters { // Default values are the default new game
add(Player().apply { playerType = PlayerType.Human })
for (i in 1..3) add(Player())
}
var numberOfCityStates = 2
var numberOfCityStates = 6

var noBarbarians = false
var oneCityChallenge = false
Expand Down
2 changes: 2 additions & 0 deletions core/src/com/unciv/models/ruleset/Building.kt
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ class Building : NamedStats(), IConstruction, ICivilopediaText {
for (unique in uniqueObjects.filter { it.placeholderText == "Cost increases by [] per owned city" })
productionCost += civInfo.cities.count() * unique.params[0].toInt()

if (civInfo.isCityState())
productionCost *= 1.5f
if (civInfo.isPlayerCivilization()) {
if (!isWonder)
productionCost *= civInfo.getDifficulty().buildingCostModifier
Expand Down
2 changes: 2 additions & 0 deletions core/src/com/unciv/models/ruleset/unit/BaseUnit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ class BaseUnit : INamed, IConstruction, CivilopediaText() {

override fun getProductionCost(civInfo: CivilizationInfo): Int {
var productionCost = cost.toFloat()
if (civInfo.isCityState())
productionCost *= 1.5f
if (civInfo.isPlayerCivilization())
productionCost *= civInfo.getDifficulty().unitCostModifier
else
Expand Down

0 comments on commit f41d30e

Please sign in to comment.