mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-22 05:41:11 +07:00
Action strings are now constants
This commit is contained in:
@ -4,6 +4,7 @@ class Constants{
|
|||||||
companion object {
|
companion object {
|
||||||
const val worker="Worker"
|
const val worker="Worker"
|
||||||
const val settler="Settler"
|
const val settler="Settler"
|
||||||
|
|
||||||
const val ocean="Ocean"
|
const val ocean="Ocean"
|
||||||
const val mountain="Mountain"
|
const val mountain="Mountain"
|
||||||
const val forest = "Forest"
|
const val forest = "Forest"
|
||||||
@ -11,10 +12,17 @@ class Constants{
|
|||||||
const val hill = "Hill"
|
const val hill = "Hill"
|
||||||
const val coast = "Coast"
|
const val coast = "Coast"
|
||||||
const val plains = "Plains"
|
const val plains = "Plains"
|
||||||
const val peaceTreaty = "Peace Treaty"
|
|
||||||
const val barbarianEncampment = "Barbarian encampment"
|
const val barbarianEncampment = "Barbarian encampment"
|
||||||
const val ancientRuins = "Ancient ruins"
|
const val ancientRuins = "Ancient ruins"
|
||||||
|
|
||||||
|
const val peaceTreaty = "Peace Treaty"
|
||||||
const val random = "Random"
|
const val random = "Random"
|
||||||
val greatImprovements = listOf("Academy", "Landmark", "Manufactory", "Customs house")
|
val greatImprovements = listOf("Academy", "Landmark", "Manufactory", "Customs house")
|
||||||
|
|
||||||
|
val unitActionSetUp = "Set Up"
|
||||||
|
val unitActionSleep = "Sleep"
|
||||||
|
val unitActionAutomation = "automation"
|
||||||
|
val unitActionExplore = "Explore"
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -207,7 +207,7 @@ class UnitAutomation{
|
|||||||
val tilesToAttackFrom = unitDistanceToTiles.asSequence()
|
val tilesToAttackFrom = unitDistanceToTiles.asSequence()
|
||||||
.filter {
|
.filter {
|
||||||
val movementPointsToExpendAfterMovement = if(unitMustBeSetUp) 1 else 0
|
val movementPointsToExpendAfterMovement = if(unitMustBeSetUp) 1 else 0
|
||||||
val movementPointsToExpendHere = if(unitMustBeSetUp && unit.action != "Set Up") 1 else 0
|
val movementPointsToExpendHere = if(unitMustBeSetUp && unit.action != Constants.unitActionSetUp) 1 else 0
|
||||||
val movementPointsToExpendBeforeAttack = if(it.key==unit.currentTile) movementPointsToExpendHere else movementPointsToExpendAfterMovement
|
val movementPointsToExpendBeforeAttack = if(it.key==unit.currentTile) movementPointsToExpendHere else movementPointsToExpendAfterMovement
|
||||||
unit.currentMovement - it.value.totalDistance - movementPointsToExpendBeforeAttack > 0.1 } // still got leftover movement points after all that, to attack (0.1 is because of Float nensense, see MapUnit.moveToTile(...)
|
unit.currentMovement - it.value.totalDistance - movementPointsToExpendBeforeAttack > 0.1 } // still got leftover movement points after all that, to attack (0.1 is because of Float nensense, see MapUnit.moveToTile(...)
|
||||||
.map { it.key }
|
.map { it.key }
|
||||||
|
@ -22,8 +22,8 @@ class Battle(val gameInfo:GameInfo) {
|
|||||||
fun moveAndAttack(attacker: ICombatant, attackableTile: UnitAutomation.AttackableTile){
|
fun moveAndAttack(attacker: ICombatant, attackableTile: UnitAutomation.AttackableTile){
|
||||||
if (attacker is MapUnitCombatant) {
|
if (attacker is MapUnitCombatant) {
|
||||||
attacker.unit.movement.moveToTile(attackableTile.tileToAttackFrom)
|
attacker.unit.movement.moveToTile(attackableTile.tileToAttackFrom)
|
||||||
if (attacker.unit.hasUnique("Must set up to ranged attack") && attacker.unit.action != "Set Up") {
|
if (attacker.unit.hasUnique("Must set up to ranged attack") && attacker.unit.action != Constants.unitActionSetUp) {
|
||||||
attacker.unit.action = "Set Up"
|
attacker.unit.action = Constants.unitActionSetUp
|
||||||
attacker.unit.useMovementPoints(1f)
|
attacker.unit.useMovementPoints(1f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -144,7 +144,7 @@ class Battle(val gameInfo:GameInfo) {
|
|||||||
}
|
}
|
||||||
else unit.currentMovement = 0f
|
else unit.currentMovement = 0f
|
||||||
unit.attacksThisTurn+=1
|
unit.attacksThisTurn+=1
|
||||||
if(unit.isFortified() || unit.action=="Sleep")
|
if(unit.isFortified() || unit.action == Constants.unitActionSleep)
|
||||||
attacker.unit.action=null // but not, for instance, if it's Set Up - then it should definitely keep the action!
|
attacker.unit.action=null // but not, for instance, if it's Set Up - then it should definitely keep the action!
|
||||||
} else if (attacker is CityCombatant) {
|
} else if (attacker is CityCombatant) {
|
||||||
attacker.city.attackedThisTurn = true
|
attacker.city.attackedThisTurn = true
|
||||||
|
@ -55,7 +55,7 @@ class MapUnit {
|
|||||||
|
|
||||||
return null // unit has no action
|
return null // unit has no action
|
||||||
}
|
}
|
||||||
set(value) { mapUnitAction = value?.let{ StringAction(this, value) } } // wrap traditional string-encoded actions into StringAction
|
set(value) { mapUnitAction = if (value == null) null else StringAction(this, value) } // wrap traditional string-encoded actions into StringAction
|
||||||
|
|
||||||
|
|
||||||
var attacksThisTurn = 0
|
var attacksThisTurn = 0
|
||||||
@ -165,7 +165,7 @@ class MapUnit {
|
|||||||
if (name == Constants.worker && getTile().improvementInProgress != null) return false
|
if (name == Constants.worker && getTile().improvementInProgress != null) return false
|
||||||
if (hasUnique("Can construct roads") && currentTile.improvementInProgress=="Road") return false
|
if (hasUnique("Can construct roads") && currentTile.improvementInProgress=="Road") return false
|
||||||
if (isFortified()) return false
|
if (isFortified()) return false
|
||||||
if (action=="Sleep") return false
|
if (action==Constants.unitActionSleep || action == Constants.unitActionAutomation) return false
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,9 +298,9 @@ class MapUnit {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action == "automation") WorkerAutomation(this).automateWorkerAction()
|
if (action == Constants.unitActionAutomation) WorkerAutomation(this).automateWorkerAction()
|
||||||
|
|
||||||
if(action == "Explore") UnitAutomation().automatedExplore(this)
|
if(action == Constants.unitActionExplore) UnitAutomation().automatedExplore(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun doPostTurnAction() {
|
private fun doPostTurnAction() {
|
||||||
|
@ -233,7 +233,7 @@ class UnitMovementAlgorithms(val unit:MapUnit) {
|
|||||||
|
|
||||||
unit.currentMovement -= distanceToTiles[destination]!!.totalDistance
|
unit.currentMovement -= distanceToTiles[destination]!!.totalDistance
|
||||||
if (unit.currentMovement < 0.1) unit.currentMovement = 0f // silly floats which are "almost zero"
|
if (unit.currentMovement < 0.1) unit.currentMovement = 0f // silly floats which are "almost zero"
|
||||||
if(unit.isFortified() || unit.action=="Set Up" || unit.action=="Sleep")
|
if(unit.isFortified() || unit.action==Constants.unitActionSetUp || unit.action==Constants.unitActionSleep)
|
||||||
unit.action=null // unfortify/setup after moving
|
unit.action=null // unfortify/setup after moving
|
||||||
|
|
||||||
unit.removeFromTile()
|
unit.removeFromTile()
|
||||||
|
@ -38,9 +38,9 @@ class UnitActions {
|
|||||||
val workingOnImprovement = unit.hasUnique("Can build improvements on tiles") && unit.currentTile.hasImprovementInProgress()
|
val workingOnImprovement = unit.hasUnique("Can build improvements on tiles") && unit.currentTile.hasImprovementInProgress()
|
||||||
if(!unit.isFortified() && (!unit.canFortify() || unit.health<100) && unit.currentMovement >0
|
if(!unit.isFortified() && (!unit.canFortify() || unit.health<100) && unit.currentMovement >0
|
||||||
&& !workingOnImprovement) {
|
&& !workingOnImprovement) {
|
||||||
val sleeping = unit.action == "Sleep"
|
val isSleeping = unit.action == Constants.unitActionSleep
|
||||||
actionList += UnitAction("Sleep", !sleeping, sleeping) {
|
actionList += UnitAction("Sleep", !isSleeping, isSleeping) {
|
||||||
unit.action = "Sleep"
|
unit.action = Constants.unitActionSleep
|
||||||
unitTable.selectedUnit = null
|
unitTable.selectedUnit = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -60,10 +60,10 @@ class UnitActions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(unit.type == UnitType.Scout){
|
if(unit.type == UnitType.Scout){
|
||||||
if(unit.action != "Explore")
|
if(unit.action != Constants.unitActionExplore)
|
||||||
actionList += UnitAction("Explore",true) {
|
actionList += UnitAction("Explore",true) {
|
||||||
UnitAutomation().automatedExplore(unit)
|
UnitAutomation().automatedExplore(unit)
|
||||||
unit.action = "Explore"
|
unit.action = Constants.unitActionExplore
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
actionList += UnitAction("Stop exploration", true) { unit.action = null }
|
actionList += UnitAction("Stop exploration", true) { unit.action = null }
|
||||||
@ -124,7 +124,7 @@ class UnitActions {
|
|||||||
if(unit.hasUnique("Must set up to ranged attack") && !unit.isEmbarked()) {
|
if(unit.hasUnique("Must set up to ranged attack") && !unit.isEmbarked()) {
|
||||||
val setUp = unit.action == "Set Up"
|
val setUp = unit.action == "Set Up"
|
||||||
actionList+=UnitAction("Set up", unit.currentMovement >0 && !setUp, currentAction = setUp ) {
|
actionList+=UnitAction("Set up", unit.currentMovement >0 && !setUp, currentAction = setUp ) {
|
||||||
unit.action="Set Up"
|
unit.action=Constants.unitActionSetUp
|
||||||
unit.useMovementPoints(1f)
|
unit.useMovementPoints(1f)
|
||||||
}.sound("setup")
|
}.sound("setup")
|
||||||
}
|
}
|
||||||
@ -148,13 +148,13 @@ class UnitActions {
|
|||||||
currentAction = unit.currentTile.hasImprovementInProgress()
|
currentAction = unit.currentTile.hasImprovementInProgress()
|
||||||
) { worldScreen.game.screen = ImprovementPickerScreen(tile) { unitTable.selectedUnit = null } }
|
) { worldScreen.game.screen = ImprovementPickerScreen(tile) { unitTable.selectedUnit = null } }
|
||||||
|
|
||||||
if("automation" == unit.action){
|
if(Constants.unitActionAutomation == unit.action){
|
||||||
actionList += UnitAction("Stop automation", true) {unit.action = null}
|
actionList += UnitAction("Stop automation", true) {unit.action = null}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
actionList += UnitAction("Automate", unit.currentMovement >0)
|
actionList += UnitAction("Automate", unit.currentMovement >0)
|
||||||
{
|
{
|
||||||
unit.action = "automation"
|
unit.action = Constants.unitActionAutomation
|
||||||
WorkerAutomation(unit).automateWorkerAction()
|
WorkerAutomation(unit).automateWorkerAction()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user