mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-18 11:49:19 +07:00
Fixed more bugs (#4360)
* Fixed city states spawning with multiple settlers * Renamed icon for the huns
This commit is contained in:
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
@ -176,10 +176,18 @@ object GameStarter {
|
|||||||
|
|
||||||
private fun addCivStartingUnits(gameInfo: GameInfo) {
|
private fun addCivStartingUnits(gameInfo: GameInfo) {
|
||||||
|
|
||||||
|
val ruleSet = gameInfo.ruleSet
|
||||||
|
val startingEra = gameInfo.gameParameters.startingEra
|
||||||
|
var startingUnits: MutableList<String>
|
||||||
|
var eraUnitReplacement: String
|
||||||
|
|
||||||
val startingLocations = getStartingLocations(
|
val startingLocations = getStartingLocations(
|
||||||
gameInfo.civilizations.filter { !it.isBarbarian() },
|
gameInfo.civilizations.filter { !it.isBarbarian() },
|
||||||
gameInfo.tileMap)
|
gameInfo.tileMap)
|
||||||
|
|
||||||
|
val settlerLikeUnits = ruleSet.units.filter {
|
||||||
|
it.value.uniqueObjects.any { it.placeholderText == Constants.settlerUnique }
|
||||||
|
}
|
||||||
|
|
||||||
// no starting units for Barbarians and Spectators
|
// no starting units for Barbarians and Spectators
|
||||||
for (civ in gameInfo.civilizations.filter { !it.isBarbarian() && !it.isSpectator() }) {
|
for (civ in gameInfo.civilizations.filter { !it.isBarbarian() && !it.isSpectator() }) {
|
||||||
@ -192,14 +200,8 @@ object GameStarter {
|
|||||||
civ.placeUnitNearTile(startingLocation.position, unitName)
|
civ.placeUnitNearTile(startingLocation.position, unitName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We are using an older mod, so we only look at the difficulty file
|
||||||
// Determine starting units based on starting era
|
if (ruleSet.eras.isEmpty()) {
|
||||||
val ruleSet = gameInfo.ruleSet
|
|
||||||
val startingEra = gameInfo.gameParameters.startingEra
|
|
||||||
var startingUnits: MutableList<String>
|
|
||||||
var eraUnitReplacement: String
|
|
||||||
|
|
||||||
if (ruleSet.eras.isEmpty()) { // We are using an older mod, so we only look at the difficulty file
|
|
||||||
startingUnits = (when {
|
startingUnits = (when {
|
||||||
civ.isPlayerCivilization() -> gameInfo.getDifficulty().startingUnits
|
civ.isPlayerCivilization() -> gameInfo.getDifficulty().startingUnits
|
||||||
civ.isMajorCiv() -> gameInfo.getDifficulty().aiMajorCivStartingUnits
|
civ.isMajorCiv() -> gameInfo.getDifficulty().aiMajorCivStartingUnits
|
||||||
@ -218,8 +220,8 @@ object GameStarter {
|
|||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Determine starting units based on starting era
|
||||||
if (startingEra in ruleSet.eras.keys) {
|
if (startingEra in ruleSet.eras.keys) {
|
||||||
startingUnits = ruleSet.eras[startingEra]!!.getStartingUnits().toMutableList()
|
startingUnits = ruleSet.eras[startingEra]!!.getStartingUnits().toMutableList()
|
||||||
eraUnitReplacement = ruleSet.eras[startingEra]!!.startingMilitaryUnit
|
eraUnitReplacement = ruleSet.eras[startingEra]!!.startingMilitaryUnit
|
||||||
@ -234,31 +236,41 @@ object GameStarter {
|
|||||||
civ.isMajorCiv() -> gameInfo.getDifficulty().aiMajorCivBonusStartingUnits
|
civ.isMajorCiv() -> gameInfo.getDifficulty().aiMajorCivBonusStartingUnits
|
||||||
else -> gameInfo.getDifficulty().aiCityStateBonusStartingUnits
|
else -> gameInfo.getDifficulty().aiCityStateBonusStartingUnits
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
fun getEquivalentUnit(civ: CivilizationInfo, unitParam: String): String? {
|
fun getEquivalentUnit(civ: CivilizationInfo, unitParam: String): String? {
|
||||||
var unit = unitParam // We want to change it and this is the easiest way to do so
|
var unit = unitParam // We want to change it and this is the easiest way to do so
|
||||||
if (unit == Constants.eraSpecificUnit) unit = eraUnitReplacement
|
if (unit == Constants.eraSpecificUnit) unit = eraUnitReplacement
|
||||||
if (unit == "Settler" && "Settler" !in ruleSet.units) {
|
if (unit == "Settler" && "Settler" !in ruleSet.units) {
|
||||||
val settlerLikeUnits = ruleSet.units.filter {
|
val buildableSettlerLikeUnits =
|
||||||
it.value.uniqueObjects.any { it.placeholderText == Constants.settlerUnique }
|
settlerLikeUnits.filter {
|
||||||
&& it.value.isBuildable(civ)
|
it.value.isBuildable(civ)
|
||||||
&& it.value.unitType.isCivilian()
|
&& it.value.unitType.isCivilian()
|
||||||
}
|
}
|
||||||
if (settlerLikeUnits.isEmpty()) return null // No settlers in this mod
|
if (buildableSettlerLikeUnits.isEmpty()) return null // No settlers in this mod
|
||||||
return civ.getEquivalentUnit(settlerLikeUnits.keys.random()).name
|
return civ.getEquivalentUnit(buildableSettlerLikeUnits.keys.random()).name
|
||||||
}
|
}
|
||||||
if (unit == "Worker" && "Worker" !in ruleSet.units) {
|
if (unit == "Worker" && "Worker" !in ruleSet.units) {
|
||||||
val workerLikeUnits = ruleSet.units.filter {
|
val buildableWorkerLikeUnits = ruleSet.units.filter {
|
||||||
it.value.uniqueObjects.any { it.placeholderText == Constants.canBuildImprovements }
|
it.value.uniqueObjects.any { it.placeholderText == Constants.canBuildImprovements }
|
||||||
&& it.value.isBuildable(civ)
|
&& it.value.isBuildable(civ)
|
||||||
&& it.value.unitType.isCivilian()
|
&& it.value.unitType.isCivilian()
|
||||||
}
|
}
|
||||||
if (workerLikeUnits.isEmpty()) return null // No workers in this mod
|
if (buildableWorkerLikeUnits.isEmpty()) return null // No workers in this mod
|
||||||
return civ.getEquivalentUnit(workerLikeUnits.keys.random()).name
|
return civ.getEquivalentUnit(buildableWorkerLikeUnits.keys.random()).name
|
||||||
}
|
}
|
||||||
return civ.getEquivalentUnit(unit).name
|
return civ.getEquivalentUnit(unit).name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (civ.isCityState()) {
|
||||||
|
val startingSettlers = startingUnits.filter { settlerLikeUnits.contains(it) }
|
||||||
|
if (startingSettlers.count() > 1) {
|
||||||
|
startingUnits = startingUnits.filter { !settlerLikeUnits.contains(it) }.toMutableList()
|
||||||
|
startingUnits.add(startingSettlers.random())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (unit in startingUnits) {
|
for (unit in startingUnits) {
|
||||||
val unitToAdd = getEquivalentUnit(civ, unit)
|
val unitToAdd = getEquivalentUnit(civ, unit)
|
||||||
if (unitToAdd != null) placeNearStartingPosition(unitToAdd)
|
if (unitToAdd != null) placeNearStartingPosition(unitToAdd)
|
||||||
|
Reference in New Issue
Block a user