mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 14:24:43 -04:00
Units have full movement when starting a scenario map game
Units have full movement when bought when in Scenario Editor mode
This commit is contained in:
parent
24d5e08783
commit
6ebc4ebf6f
@ -31,6 +31,7 @@ object GameStarter {
|
|||||||
gameInfo.tileMap.gameInfo = gameInfo // need to set this transient before placing units in the map
|
gameInfo.tileMap.gameInfo = gameInfo // need to set this transient before placing units in the map
|
||||||
addCivilizations(gameSetupInfo.gameParameters, gameInfo, ruleset) // this is before gameInfo.setTransients, so gameInfo doesn't yet have the gameBasics
|
addCivilizations(gameSetupInfo.gameParameters, gameInfo, ruleset) // this is before gameInfo.setTransients, so gameInfo doesn't yet have the gameBasics
|
||||||
|
|
||||||
|
// Remove units for civs that aren't in this game
|
||||||
for (tile in gameInfo.tileMap.values)
|
for (tile in gameInfo.tileMap.values)
|
||||||
for (unit in tile.getUnits())
|
for (unit in tile.getUnits())
|
||||||
if (gameInfo.civilizations.none { it.civName == unit.owner }) {
|
if (gameInfo.civilizations.none { it.civName == unit.owner }) {
|
||||||
@ -46,7 +47,24 @@ object GameStarter {
|
|||||||
|
|
||||||
gameInfo.setTransients() // needs to be before placeBarbarianUnit because it depends on the tilemap having its gameinfo set
|
gameInfo.setTransients() // needs to be before placeBarbarianUnit because it depends on the tilemap having its gameinfo set
|
||||||
|
|
||||||
// Add Civ Technologies
|
addCivTechs(gameInfo, ruleset, gameSetupInfo)
|
||||||
|
|
||||||
|
// and only now do we add units for everyone, because otherwise both the gameInfo.setTransients() and the placeUnit will both add the unit to the civ's unit list!
|
||||||
|
if (gameSetupInfo.mapParameters.type != MapType.scenarioMap)
|
||||||
|
addCivStartingUnits(gameInfo)
|
||||||
|
|
||||||
|
// remove starting locations once we're done
|
||||||
|
for (tile in gameInfo.tileMap.values) {
|
||||||
|
if (tile.improvement != null && tile.improvement!!.startsWith("StartingLocation "))
|
||||||
|
tile.improvement = null
|
||||||
|
// set max starting movement for units loaded from map
|
||||||
|
for (unit in tile.getUnits()) unit.currentMovement = unit.getMaxMovement().toFloat()
|
||||||
|
}
|
||||||
|
|
||||||
|
return gameInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun addCivTechs(gameInfo: GameInfo, ruleset: Ruleset, gameSetupInfo: GameSetupInfo) {
|
||||||
for (civInfo in gameInfo.civilizations.filter { !it.isBarbarian() }) {
|
for (civInfo in gameInfo.civilizations.filter { !it.isBarbarian() }) {
|
||||||
|
|
||||||
if (!civInfo.isPlayerCivilization())
|
if (!civInfo.isPlayerCivilization())
|
||||||
@ -66,12 +84,6 @@ object GameStarter {
|
|||||||
|
|
||||||
civInfo.popupAlerts.clear() // Since adding technologies generates popups...
|
civInfo.popupAlerts.clear() // Since adding technologies generates popups...
|
||||||
}
|
}
|
||||||
|
|
||||||
// and only now do we add units for everyone, because otherwise both the gameInfo.setTransients() and the placeUnit will both add the unit to the civ's unit list!
|
|
||||||
if (gameSetupInfo.mapParameters.type != MapType.scenarioMap)
|
|
||||||
addCivStartingUnits(gameInfo)
|
|
||||||
|
|
||||||
return gameInfo
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addCivilizations(newGameParameters: GameParameters, gameInfo: GameInfo, ruleset: Ruleset) {
|
private fun addCivilizations(newGameParameters: GameParameters, gameInfo: GameInfo, ruleset: Ruleset) {
|
||||||
@ -123,15 +135,6 @@ object GameStarter {
|
|||||||
gameInfo.civilizations.filter { !it.isBarbarian() },
|
gameInfo.civilizations.filter { !it.isBarbarian() },
|
||||||
gameInfo.tileMap)
|
gameInfo.tileMap)
|
||||||
|
|
||||||
// remove starting locations once we're done
|
|
||||||
for (tile in gameInfo.tileMap.values) {
|
|
||||||
if (tile.improvement != null && tile.improvement!!.startsWith("StartingLocation "))
|
|
||||||
tile.improvement = null
|
|
||||||
// set max starting movement for units loaded from map
|
|
||||||
for (unit in tile.getUnits()) unit.currentMovement = unit.getMaxMovement().toFloat()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// For later starting eras, or for civs like Polynesia with a different Warrior, we need different starting units
|
// For later starting eras, or for civs like Polynesia with a different Warrior, we need different starting units
|
||||||
fun getWarriorEquivalent(civ: CivilizationInfo): String {
|
fun getWarriorEquivalent(civ: CivilizationInfo): String {
|
||||||
val availableMilitaryUnits = gameInfo.ruleSet.units.values.filter {
|
val availableMilitaryUnits = gameInfo.ruleSet.units.values.filter {
|
||||||
|
@ -149,17 +149,18 @@ class BaseUnit : INamed, IConstruction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun postBuildEvent(construction: CityConstructions, wasBought: Boolean): Boolean {
|
override fun postBuildEvent(construction: CityConstructions, wasBought: Boolean): Boolean {
|
||||||
val unit = construction.cityInfo.civInfo.placeUnitNearTile(construction.cityInfo.location, name)
|
val civInfo = construction.cityInfo.civInfo
|
||||||
|
val unit = civInfo.placeUnitNearTile(construction.cityInfo.location, name)
|
||||||
if (unit == null) return false // couldn't place the unit, so there's actually no unit =(
|
if (unit == null) return false // couldn't place the unit, so there's actually no unit =(
|
||||||
|
|
||||||
//movement penalty
|
//movement penalty
|
||||||
if (wasBought && !unit.hasUnique("Can move directly once bought"))
|
if (wasBought && !unit.hasUnique("Can move directly once bought") && !civInfo.gameInfo.gameParameters.godMode)
|
||||||
unit.currentMovement = 0f
|
unit.currentMovement = 0f
|
||||||
|
|
||||||
if (this.unitType.isCivilian()) return true // tiny optimization makes save files a few bytes smaller
|
if (this.unitType.isCivilian()) return true // tiny optimization makes save files a few bytes smaller
|
||||||
|
|
||||||
var XP = construction.getBuiltBuildings().sumBy { it.xpForNewUnits }
|
var XP = construction.getBuiltBuildings().sumBy { it.xpForNewUnits }
|
||||||
for (unique in construction.cityInfo.civInfo.getMatchingUniques("New military units start with [] Experience"))
|
for (unique in civInfo.getMatchingUniques("New military units start with [] Experience"))
|
||||||
XP += unique.params[0].toInt()
|
XP += unique.params[0].toInt()
|
||||||
unit.promotions.XP = XP
|
unit.promotions.XP = XP
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user