Action strings are now constants

This commit is contained in:
Yair Morgenstern 2019-08-21 23:55:12 +03:00
parent c685e0f528
commit 0a777e5b59
6 changed files with 26 additions and 18 deletions

View file

@ -4,6 +4,7 @@ class Constants{
companion object {
const val worker="Worker"
const val settler="Settler"
const val ocean="Ocean"
const val mountain="Mountain"
const val forest = "Forest"
@ -11,10 +12,17 @@ class Constants{
const val hill = "Hill"
const val coast = "Coast"
const val plains = "Plains"
const val peaceTreaty = "Peace Treaty"
const val barbarianEncampment = "Barbarian encampment"
const val ancientRuins = "Ancient ruins"
const val peaceTreaty = "Peace Treaty"
const val random = "Random"
val greatImprovements = listOf("Academy", "Landmark", "Manufactory", "Customs house")
val unitActionSetUp = "Set Up"
val unitActionSleep = "Sleep"
val unitActionAutomation = "automation"
val unitActionExplore = "Explore"
}
}

View file

@ -207,7 +207,7 @@ class UnitAutomation{
val tilesToAttackFrom = unitDistanceToTiles.asSequence()
.filter {
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
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 }

View file

@ -22,8 +22,8 @@ class Battle(val gameInfo:GameInfo) {
fun moveAndAttack(attacker: ICombatant, attackableTile: UnitAutomation.AttackableTile){
if (attacker is MapUnitCombatant) {
attacker.unit.movement.moveToTile(attackableTile.tileToAttackFrom)
if (attacker.unit.hasUnique("Must set up to ranged attack") && attacker.unit.action != "Set Up") {
attacker.unit.action = "Set Up"
if (attacker.unit.hasUnique("Must set up to ranged attack") && attacker.unit.action != Constants.unitActionSetUp) {
attacker.unit.action = Constants.unitActionSetUp
attacker.unit.useMovementPoints(1f)
}
}
@ -144,7 +144,7 @@ class Battle(val gameInfo:GameInfo) {
}
else unit.currentMovement = 0f
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!
} else if (attacker is CityCombatant) {
attacker.city.attackedThisTurn = true

View file

@ -55,7 +55,7 @@ class MapUnit {
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
@ -165,7 +165,7 @@ class MapUnit {
if (name == Constants.worker && getTile().improvementInProgress != null) return false
if (hasUnique("Can construct roads") && currentTile.improvementInProgress=="Road") return false
if (isFortified()) return false
if (action=="Sleep") return false
if (action==Constants.unitActionSleep || action == Constants.unitActionAutomation) return false
return true
}
@ -298,9 +298,9 @@ class MapUnit {
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() {

View file

@ -233,7 +233,7 @@ class UnitMovementAlgorithms(val unit:MapUnit) {
unit.currentMovement -= distanceToTiles[destination]!!.totalDistance
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.removeFromTile()

View file

@ -38,9 +38,9 @@ class UnitActions {
val workingOnImprovement = unit.hasUnique("Can build improvements on tiles") && unit.currentTile.hasImprovementInProgress()
if(!unit.isFortified() && (!unit.canFortify() || unit.health<100) && unit.currentMovement >0
&& !workingOnImprovement) {
val sleeping = unit.action == "Sleep"
actionList += UnitAction("Sleep", !sleeping, sleeping) {
unit.action = "Sleep"
val isSleeping = unit.action == Constants.unitActionSleep
actionList += UnitAction("Sleep", !isSleeping, isSleeping) {
unit.action = Constants.unitActionSleep
unitTable.selectedUnit = null
}
}
@ -60,10 +60,10 @@ class UnitActions {
}
if(unit.type == UnitType.Scout){
if(unit.action != "Explore")
if(unit.action != Constants.unitActionExplore)
actionList += UnitAction("Explore",true) {
UnitAutomation().automatedExplore(unit)
unit.action = "Explore"
unit.action = Constants.unitActionExplore
}
else
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()) {
val setUp = unit.action == "Set Up"
actionList+=UnitAction("Set up", unit.currentMovement >0 && !setUp, currentAction = setUp ) {
unit.action="Set Up"
unit.action=Constants.unitActionSetUp
unit.useMovementPoints(1f)
}.sound("setup")
}
@ -148,13 +148,13 @@ class UnitActions {
currentAction = unit.currentTile.hasImprovementInProgress()
) { 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}
}
else {
actionList += UnitAction("Automate", unit.currentMovement >0)
{
unit.action = "automation"
unit.action = Constants.unitActionAutomation
WorkerAutomation(unit).automateWorkerAction()
}
}