mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-25 07:09:16 +07:00
Linting - removed about 40 lines, hopefully makes the file easier to parse
This commit is contained in:
@ -29,23 +29,16 @@ object UnitActions {
|
|||||||
val unitTable = worldScreen.bottomUnitTable
|
val unitTable = worldScreen.bottomUnitTable
|
||||||
val actionList = ArrayList<UnitAction>()
|
val actionList = ArrayList<UnitAction>()
|
||||||
|
|
||||||
if (unit.isMoving()) {
|
if (unit.isMoving()) actionList += UnitAction(UnitActionType.StopMovement) { unit.action = null }
|
||||||
actionList += UnitAction(
|
|
||||||
type = UnitActionType.StopMovement,
|
|
||||||
action = { unit.action = null }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
val workingOnImprovement = unit.hasUnique("Can build improvements on tiles")
|
val workingOnImprovement = unit.hasUnique("Can build improvements on tiles")
|
||||||
&& unit.currentTile.hasImprovementInProgress()
|
&& unit.currentTile.hasImprovementInProgress()
|
||||||
if (!unit.isFortified() && !unit.canFortify()
|
if (!unit.isFortified() && !unit.canFortify() && unit.currentMovement > 0 && !workingOnImprovement) {
|
||||||
&& unit.currentMovement > 0 && !workingOnImprovement) {
|
|
||||||
addSleepActions(actionList, unit, unitTable)
|
addSleepActions(actionList, unit, unitTable)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unit.canFortify()) {
|
if (unit.canFortify()) addFortifyActions(actionList, unit, unitTable)
|
||||||
addFortifyActions(actionList, unit, unitTable)
|
else if (unit.isFortified()) {
|
||||||
} else if (unit.isFortified()) {
|
|
||||||
actionList += UnitAction(
|
actionList += UnitAction(
|
||||||
type = if (unit.action!!.endsWith(" until healed"))
|
type = if (unit.action!!.endsWith(" until healed"))
|
||||||
UnitActionType.FortifyUntilHealed else
|
UnitActionType.FortifyUntilHealed else
|
||||||
@ -73,9 +66,7 @@ object UnitActions {
|
|||||||
|
|
||||||
|
|
||||||
private fun addDisbandAction(actionList: ArrayList<UnitAction>, unit: MapUnit, worldScreen: WorldScreen) {
|
private fun addDisbandAction(actionList: ArrayList<UnitAction>, unit: MapUnit, worldScreen: WorldScreen) {
|
||||||
actionList += UnitAction(
|
actionList += UnitAction(type = UnitActionType.DisbandUnit, action = {
|
||||||
type = UnitActionType.DisbandUnit,
|
|
||||||
action = {
|
|
||||||
if (!worldScreen.hasOpenPopups()) {
|
if (!worldScreen.hasOpenPopups()) {
|
||||||
val disbandText = if (unit.currentTile.getOwner() == unit.civInfo)
|
val disbandText = if (unit.currentTile.getOwner() == unit.civInfo)
|
||||||
"Disband this unit for [${unit.baseUnit.getDisbandGold(unit.civInfo)}] gold?".tr()
|
"Disband this unit for [${unit.baseUnit.getDisbandGold(unit.civInfo)}] gold?".tr()
|
||||||
@ -99,9 +90,7 @@ object UnitActions {
|
|||||||
&& tile.getTileResource().improvement == improvement
|
&& tile.getTileResource().improvement == improvement
|
||||||
&& unit.civInfo.tech.isResearched(unit.civInfo.gameInfo.ruleSet.tileImprovements[improvement]!!.techRequired!!)
|
&& unit.civInfo.tech.isResearched(unit.civInfo.gameInfo.ruleSet.tileImprovements[improvement]!!.techRequired!!)
|
||||||
)
|
)
|
||||||
return UnitAction(
|
return UnitAction(UnitActionType.Create, "Create [$improvement]",
|
||||||
type = UnitActionType.Create,
|
|
||||||
title = "Create [$improvement]",
|
|
||||||
action = {
|
action = {
|
||||||
tile.improvement = improvement
|
tile.improvement = improvement
|
||||||
unit.destroy()
|
unit.destroy()
|
||||||
@ -117,8 +106,7 @@ object UnitActions {
|
|||||||
&& tile.improvementInProgress != "Road"
|
&& tile.improvementInProgress != "Road"
|
||||||
&& tile.isLand
|
&& tile.isLand
|
||||||
&& (improvement.techRequired == null || unit.civInfo.tech.isResearched(improvement.techRequired!!)))
|
&& (improvement.techRequired == null || unit.civInfo.tech.isResearched(improvement.techRequired!!)))
|
||||||
actionList += UnitAction(
|
actionList += UnitAction(UnitActionType.ConstructRoad,
|
||||||
type = UnitActionType.ConstructRoad,
|
|
||||||
action = {
|
action = {
|
||||||
tile.improvementInProgress = "Road"
|
tile.improvementInProgress = "Road"
|
||||||
tile.turnsToImprovement = improvement.getTurnsToBuild(unit.civInfo)
|
tile.turnsToImprovement = improvement.getTurnsToBuild(unit.civInfo)
|
||||||
@ -145,8 +133,7 @@ object UnitActions {
|
|||||||
private fun addPromoteAction(unit: MapUnit, actionList: ArrayList<UnitAction>) {
|
private fun addPromoteAction(unit: MapUnit, actionList: ArrayList<UnitAction>) {
|
||||||
if (unit.type.isCivilian() || !unit.promotions.canBePromoted()) return
|
if (unit.type.isCivilian() || !unit.promotions.canBePromoted()) return
|
||||||
// promotion does not consume movement points, so we can do it always
|
// promotion does not consume movement points, so we can do it always
|
||||||
actionList += UnitAction(
|
actionList += UnitAction(UnitActionType.Promote,
|
||||||
type = UnitActionType.Promote,
|
|
||||||
uncivSound = UncivSound.Promote,
|
uncivSound = UncivSound.Promote,
|
||||||
action = {
|
action = {
|
||||||
UncivGame.Current.setScreen(PromotionPickerScreen(unit))
|
UncivGame.Current.setScreen(PromotionPickerScreen(unit))
|
||||||
@ -156,8 +143,7 @@ object UnitActions {
|
|||||||
private fun addSetupAction(unit: MapUnit, actionList: ArrayList<UnitAction>) {
|
private fun addSetupAction(unit: MapUnit, actionList: ArrayList<UnitAction>) {
|
||||||
if (!unit.hasUnique("Must set up to ranged attack") || unit.isEmbarked()) return
|
if (!unit.hasUnique("Must set up to ranged attack") || unit.isEmbarked()) return
|
||||||
val isSetUp = unit.action == "Set Up"
|
val isSetUp = unit.action == "Set Up"
|
||||||
actionList += UnitAction(
|
actionList += UnitAction(UnitActionType.SetUp,
|
||||||
type = UnitActionType.SetUp,
|
|
||||||
isCurrentAction = isSetUp,
|
isCurrentAction = isSetUp,
|
||||||
uncivSound = UncivSound.Setup,
|
uncivSound = UncivSound.Setup,
|
||||||
action = {
|
action = {
|
||||||
@ -183,8 +169,7 @@ object UnitActions {
|
|||||||
val tile = unit.currentTile
|
val tile = unit.currentTile
|
||||||
if (unit.type.isCivilian() || tile.improvement == null) return null
|
if (unit.type.isCivilian() || tile.improvement == null) return null
|
||||||
|
|
||||||
return UnitAction(
|
return UnitAction(UnitActionType.Pillage,
|
||||||
type = UnitActionType.Pillage,
|
|
||||||
action = {
|
action = {
|
||||||
// http://well-of-souls.com/civ/civ5_improvements.html says that naval improvements are destroyed upon pilllage
|
// http://well-of-souls.com/civ/civ5_improvements.html says that naval improvements are destroyed upon pilllage
|
||||||
// and I can't find any other sources so I'll go with that
|
// and I can't find any other sources so I'll go with that
|
||||||
@ -200,25 +185,17 @@ object UnitActions {
|
|||||||
if (!freePillage) unit.useMovementPoints(1f)
|
if (!freePillage) unit.useMovementPoints(1f)
|
||||||
|
|
||||||
unit.healBy(25)
|
unit.healBy(25)
|
||||||
|
|
||||||
}.takeIf { unit.currentMovement > 0 && canPillage(unit, tile) })
|
}.takeIf { unit.currentMovement > 0 && canPillage(unit, tile) })
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addExplorationActions(unit: MapUnit, actionList: ArrayList<UnitAction>) {
|
private fun addExplorationActions(unit: MapUnit, actionList: ArrayList<UnitAction>) {
|
||||||
if (unit.type.isAirUnit()) return
|
if (unit.type.isAirUnit()) return
|
||||||
if (unit.action != Constants.unitActionExplore) {
|
if (unit.action != Constants.unitActionExplore) {
|
||||||
actionList += UnitAction(
|
actionList += UnitAction(UnitActionType.Explore) {
|
||||||
type = UnitActionType.Explore,
|
|
||||||
action = {
|
|
||||||
unit.action = Constants.unitActionExplore
|
unit.action = Constants.unitActionExplore
|
||||||
if (unit.currentMovement > 0) UnitAutomation.automatedExplore(unit)
|
if (unit.currentMovement > 0) UnitAutomation.automatedExplore(unit)
|
||||||
})
|
|
||||||
} else {
|
|
||||||
actionList += UnitAction(
|
|
||||||
type = UnitActionType.StopExploration,
|
|
||||||
action = { unit.action = null }
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
} else actionList += UnitAction(UnitActionType.StopExploration) { unit.action = null }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addUnitUpgradeAction(unit: MapUnit, actionList: ArrayList<UnitAction>) {
|
private fun addUnitUpgradeAction(unit: MapUnit, actionList: ArrayList<UnitAction>) {
|
||||||
@ -233,8 +210,7 @@ object UnitActions {
|
|||||||
val goldCostOfUpgrade = unit.getCostOfUpgrade()
|
val goldCostOfUpgrade = unit.getCostOfUpgrade()
|
||||||
val upgradedUnit = unit.getUnitToUpgradeTo()
|
val upgradedUnit = unit.getUnitToUpgradeTo()
|
||||||
|
|
||||||
return UnitAction(
|
return UnitAction(UnitActionType.Upgrade,
|
||||||
type = UnitActionType.Upgrade,
|
|
||||||
title = "Upgrade to [${upgradedUnit.name}] ([$goldCostOfUpgrade] gold)",
|
title = "Upgrade to [${upgradedUnit.name}] ([$goldCostOfUpgrade] gold)",
|
||||||
uncivSound = UncivSound.Upgrade,
|
uncivSound = UncivSound.Upgrade,
|
||||||
action = {
|
action = {
|
||||||
@ -264,13 +240,9 @@ object UnitActions {
|
|||||||
|
|
||||||
// Allow automate/unautomate when embarked, but not building improvements - see #1963
|
// Allow automate/unautomate when embarked, but not building improvements - see #1963
|
||||||
if (Constants.unitActionAutomation == unit.action) {
|
if (Constants.unitActionAutomation == unit.action) {
|
||||||
actionList += UnitAction(
|
actionList += UnitAction(UnitActionType.StopAutomation) { unit.action = null }
|
||||||
type = UnitActionType.StopAutomation,
|
|
||||||
action = { unit.action = null }
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
actionList += UnitAction(
|
actionList += UnitAction(UnitActionType.Automate,
|
||||||
type = UnitActionType.Automate,
|
|
||||||
action = {
|
action = {
|
||||||
unit.action = Constants.unitActionAutomation
|
unit.action = Constants.unitActionAutomation
|
||||||
WorkerAutomation(unit).automateWorkerAction()
|
WorkerAutomation(unit).automateWorkerAction()
|
||||||
@ -281,10 +253,9 @@ object UnitActions {
|
|||||||
|
|
||||||
val canConstruct = unit.currentMovement > 0
|
val canConstruct = unit.currentMovement > 0
|
||||||
&& !tile.isCityCenter()
|
&& !tile.isCityCenter()
|
||||||
&& unit.civInfo.gameInfo.ruleSet.tileImprovements.values
|
&& unit.civInfo.gameInfo.ruleSet.tileImprovements.values.any { tile.canBuildImprovement(it, unit.civInfo) }
|
||||||
.any { tile.canBuildImprovement(it, unit.civInfo) }
|
|
||||||
actionList += UnitAction(
|
actionList += UnitAction(UnitActionType.ConstructImprovement,
|
||||||
type = UnitActionType.ConstructImprovement,
|
|
||||||
isCurrentAction = unit.currentTile.hasImprovementInProgress(),
|
isCurrentAction = unit.currentTile.hasImprovementInProgress(),
|
||||||
action = {
|
action = {
|
||||||
worldScreen.game.setScreen(ImprovementPickerScreen(tile) { unitTable.selectUnit() })
|
worldScreen.game.setScreen(ImprovementPickerScreen(tile) { unitTable.selectUnit() })
|
||||||
@ -295,8 +266,7 @@ object UnitActions {
|
|||||||
|
|
||||||
if (unit.currentMovement > 0) for (unique in unit.getUniques()) when (unique.placeholderText) {
|
if (unit.currentMovement > 0) for (unique in unit.getUniques()) when (unique.placeholderText) {
|
||||||
"Can hurry technology research" -> {
|
"Can hurry technology research" -> {
|
||||||
actionList += UnitAction(
|
actionList += UnitAction(UnitActionType.HurryResearch,
|
||||||
type = UnitActionType.HurryResearch,
|
|
||||||
uncivSound = UncivSound.Chimes,
|
uncivSound = UncivSound.Chimes,
|
||||||
action = {
|
action = {
|
||||||
unit.civInfo.tech.addScience(unit.civInfo.tech.getScienceFromGreatScientist())
|
unit.civInfo.tech.addScience(unit.civInfo.tech.getScienceFromGreatScientist())
|
||||||
@ -306,8 +276,7 @@ object UnitActions {
|
|||||||
}
|
}
|
||||||
"Can start an []-turn golden age" -> {
|
"Can start an []-turn golden age" -> {
|
||||||
val turnsToGoldenAge = unique.params[0].toInt()
|
val turnsToGoldenAge = unique.params[0].toInt()
|
||||||
actionList += UnitAction(
|
actionList += UnitAction(UnitActionType.StartGoldenAge,
|
||||||
type = UnitActionType.StartGoldenAge,
|
|
||||||
uncivSound = UncivSound.Chimes,
|
uncivSound = UncivSound.Chimes,
|
||||||
action = {
|
action = {
|
||||||
unit.civInfo.goldenAges.enterGoldenAge(turnsToGoldenAge)
|
unit.civInfo.goldenAges.enterGoldenAge(turnsToGoldenAge)
|
||||||
@ -322,8 +291,7 @@ object UnitActions {
|
|||||||
if (currentConstruction !is Building) false
|
if (currentConstruction !is Building) false
|
||||||
else currentConstruction.isWonder || currentConstruction.isNationalWonder
|
else currentConstruction.isWonder || currentConstruction.isNationalWonder
|
||||||
}
|
}
|
||||||
actionList += UnitAction(
|
actionList += UnitAction(UnitActionType.HurryWonder,
|
||||||
type = UnitActionType.HurryWonder,
|
|
||||||
uncivSound = UncivSound.Chimes,
|
uncivSound = UncivSound.Chimes,
|
||||||
action = {
|
action = {
|
||||||
tile.getCity()!!.cityConstructions.apply {
|
tile.getCity()!!.cityConstructions.apply {
|
||||||
@ -338,8 +306,7 @@ object UnitActions {
|
|||||||
val canConductTradeMission = tile.owningCity?.civInfo?.isCityState() == true
|
val canConductTradeMission = tile.owningCity?.civInfo?.isCityState() == true
|
||||||
&& tile.owningCity?.civInfo?.isAtWarWith(unit.civInfo) == false
|
&& tile.owningCity?.civInfo?.isAtWarWith(unit.civInfo) == false
|
||||||
val influenceEarned = unique.params[0].toInt()
|
val influenceEarned = unique.params[0].toInt()
|
||||||
actionList += UnitAction(
|
actionList += UnitAction(UnitActionType.ConductTradeMission,
|
||||||
type = UnitActionType.ConductTradeMission,
|
|
||||||
uncivSound = UncivSound.Chimes,
|
uncivSound = UncivSound.Chimes,
|
||||||
action = {
|
action = {
|
||||||
// http://civilization.wikia.com/wiki/Great_Merchant_(Civ5)
|
// http://civilization.wikia.com/wiki/Great_Merchant_(Civ5)
|
||||||
@ -364,13 +331,12 @@ object UnitActions {
|
|||||||
val improvementName = unique.params[0]
|
val improvementName = unique.params[0]
|
||||||
val improvement = tile.ruleset.tileImprovements[improvementName]
|
val improvement = tile.ruleset.tileImprovements[improvementName]
|
||||||
if (improvement == null) continue
|
if (improvement == null) continue
|
||||||
finalActions += UnitAction(
|
finalActions += UnitAction(UnitActionType.Create,
|
||||||
type = UnitActionType.Create,
|
|
||||||
title = "Create [$improvementName]",
|
title = "Create [$improvementName]",
|
||||||
uncivSound = UncivSound.Chimes,
|
uncivSound = UncivSound.Chimes,
|
||||||
action = {
|
action = {
|
||||||
val unitTile = unit.getTile()
|
val unitTile = unit.getTile()
|
||||||
for (terrainFeature in tile.terrainFeatures.filter{ unitTile.ruleset.tileImprovements.containsKey("Remove $it") })
|
for (terrainFeature in tile.terrainFeatures.filter { unitTile.ruleset.tileImprovements.containsKey("Remove $it") })
|
||||||
unitTile.terrainFeatures.remove(terrainFeature)// remove forest/jungle/marsh
|
unitTile.terrainFeatures.remove(terrainFeature)// remove forest/jungle/marsh
|
||||||
unitTile.improvement = improvementName
|
unitTile.improvement = improvementName
|
||||||
unitTile.improvementInProgress = null
|
unitTile.improvementInProgress = null
|
||||||
@ -432,8 +398,7 @@ object UnitActions {
|
|||||||
|
|
||||||
private fun addFortifyActions(actionList: ArrayList<UnitAction>, unit: MapUnit, unitTable: UnitTable) {
|
private fun addFortifyActions(actionList: ArrayList<UnitAction>, unit: MapUnit, unitTable: UnitTable) {
|
||||||
|
|
||||||
val action = UnitAction(
|
val action = UnitAction(UnitActionType.Fortify,
|
||||||
type = UnitActionType.Fortify,
|
|
||||||
uncivSound = UncivSound.Fortify,
|
uncivSound = UncivSound.Fortify,
|
||||||
action = {
|
action = {
|
||||||
unit.fortify()
|
unit.fortify()
|
||||||
@ -441,8 +406,7 @@ object UnitActions {
|
|||||||
}.takeIf { unit.currentMovement > 0 })
|
}.takeIf { unit.currentMovement > 0 })
|
||||||
|
|
||||||
if (unit.health < 100) {
|
if (unit.health < 100) {
|
||||||
val actionForWounded = action.copy(
|
val actionForWounded = action.copy(UnitActionType.FortifyUntilHealed,
|
||||||
type = UnitActionType.FortifyUntilHealed,
|
|
||||||
title = UnitActionType.FortifyUntilHealed.value,
|
title = UnitActionType.FortifyUntilHealed.value,
|
||||||
action = {
|
action = {
|
||||||
unit.fortifyUntilHealed()
|
unit.fortifyUntilHealed()
|
||||||
@ -455,11 +419,9 @@ object UnitActions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun addSleepActions(actionList: ArrayList<UnitAction>, unit: MapUnit, unitTable: UnitTable) {
|
private fun addSleepActions(actionList: ArrayList<UnitAction>, unit: MapUnit, unitTable: UnitTable) {
|
||||||
|
|
||||||
val isSleeping = unit.isSleeping()
|
val isSleeping = unit.isSleeping()
|
||||||
|
|
||||||
val action = UnitAction(
|
val action = UnitAction(UnitActionType.Sleep,
|
||||||
type = UnitActionType.Sleep,
|
|
||||||
isCurrentAction = isSleeping,
|
isCurrentAction = isSleeping,
|
||||||
action = {
|
action = {
|
||||||
unit.action = Constants.unitActionSleep
|
unit.action = Constants.unitActionSleep
|
||||||
@ -467,8 +429,7 @@ object UnitActions {
|
|||||||
}.takeIf { !isSleeping })
|
}.takeIf { !isSleeping })
|
||||||
|
|
||||||
if (unit.health < 100 && !isSleeping) {
|
if (unit.health < 100 && !isSleeping) {
|
||||||
val actionForWounded = action.copy(
|
val actionForWounded = action.copy(UnitActionType.SleepUntilHealed,
|
||||||
type = UnitActionType.SleepUntilHealed,
|
|
||||||
title = UnitActionType.SleepUntilHealed.value,
|
title = UnitActionType.SleepUntilHealed.value,
|
||||||
action = {
|
action = {
|
||||||
unit.action = Constants.unitActionSleepUntilHealed
|
unit.action = Constants.unitActionSleepUntilHealed
|
||||||
|
Reference in New Issue
Block a user