mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-23 06:08:46 +07:00
Added "unit upgrade" action for old units
This commit is contained in:
@ -21,7 +21,7 @@ android {
|
|||||||
applicationId "com.unciv.game"
|
applicationId "com.unciv.game"
|
||||||
minSdkVersion 14
|
minSdkVersion 14
|
||||||
targetSdkVersion 26
|
targetSdkVersion 26
|
||||||
versionCode 64
|
versionCode 65
|
||||||
versionName "2.2.5"
|
versionName "2.2.5"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
|
@ -168,8 +168,8 @@ class CivilizationInfo {
|
|||||||
addNotification("A $greatPerson has been born!", randomCity.location)
|
addNotification("A $greatPerson has been born!", randomCity.location)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun placeUnitNearTile(location: Vector2, unitName: String) {
|
fun placeUnitNearTile(location: Vector2, unitName: String): MapUnit {
|
||||||
gameInfo.tileMap.placeUnitNearTile(location, unitName, this)
|
return gameInfo.tileMap.placeUnitNearTile(location, unitName, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getCivUnits(): List<MapUnit> {
|
fun getCivUnits(): List<MapUnit> {
|
||||||
|
@ -42,13 +42,14 @@ class TileMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun placeUnitNearTile(position: Vector2, unitName: String, civInfo: CivilizationInfo) {
|
fun placeUnitNearTile(position: Vector2, unitName: String, civInfo: CivilizationInfo): MapUnit {
|
||||||
val unit = GameBasics.Units[unitName]!!.getMapUnit()
|
val unit = GameBasics.Units[unitName]!!.getMapUnit()
|
||||||
unit.owner = civInfo.civName
|
unit.owner = civInfo.civName
|
||||||
unit.civInfo = civInfo
|
unit.civInfo = civInfo
|
||||||
val tilesInDistance = getTilesInDistance(position, 2)
|
val tilesInDistance = getTilesInDistance(position, 2)
|
||||||
val unitToPlaceTile = tilesInDistance.firstOrNull { it.unit == null }
|
val unitToPlaceTile = tilesInDistance.firstOrNull { it.unit == null }
|
||||||
if(unitToPlaceTile!=null) unitToPlaceTile.unit = unit // And if there's none, then kill me.
|
if(unitToPlaceTile!=null) unitToPlaceTile.unit = unit // And if there's none, then kill me.
|
||||||
|
return unit
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getViewableTiles(position: Vector2, sightDistance: Int): MutableList<TileInfo> {
|
fun getViewableTiles(position: Vector2, sightDistance: Int): MutableList<TileInfo> {
|
||||||
|
@ -2,6 +2,7 @@ package com.unciv.models.gamebasics
|
|||||||
|
|
||||||
import com.unciv.logic.city.CityConstructions
|
import com.unciv.logic.city.CityConstructions
|
||||||
import com.unciv.logic.city.IConstruction
|
import com.unciv.logic.city.IConstruction
|
||||||
|
import com.unciv.logic.civilization.CivilizationInfo
|
||||||
import com.unciv.logic.map.MapUnit
|
import com.unciv.logic.map.MapUnit
|
||||||
import com.unciv.logic.map.UnitType
|
import com.unciv.logic.map.UnitType
|
||||||
import com.unciv.models.stats.INamed
|
import com.unciv.models.stats.INamed
|
||||||
@ -75,8 +76,7 @@ class Unit : INamed, IConstruction, ICivilopedia {
|
|||||||
return (Math.pow((30 * cost).toDouble(), 0.75) * (1 + hurryCostModifier / 100) / 10).toInt() * 10
|
return (Math.pow((30 * cost).toDouble(), 0.75) * (1 + hurryCostModifier / 100) / 10).toInt() * 10
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isBuildable(construction: CityConstructions): Boolean {
|
fun isBuildable(civInfo:CivilizationInfo): Boolean {
|
||||||
val civInfo = construction.cityInfo.civInfo
|
|
||||||
if (unbuildable) return false
|
if (unbuildable) return false
|
||||||
if (requiredTech!=null && !civInfo.tech.isResearched(requiredTech!!)) return false
|
if (requiredTech!=null && !civInfo.tech.isResearched(requiredTech!!)) return false
|
||||||
if (obsoleteTech!=null && civInfo.tech.isResearched(obsoleteTech!!)) return false
|
if (obsoleteTech!=null && civInfo.tech.isResearched(obsoleteTech!!)) return false
|
||||||
@ -84,6 +84,10 @@ class Unit : INamed, IConstruction, ICivilopedia {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun isBuildable(construction: CityConstructions): Boolean {
|
||||||
|
return isBuildable(construction.cityInfo.civInfo)
|
||||||
|
}
|
||||||
|
|
||||||
override fun postBuildEvent(construction: CityConstructions) {
|
override fun postBuildEvent(construction: CityConstructions) {
|
||||||
construction.cityInfo.civInfo.placeUnitNearTile(construction.cityInfo.location, name)
|
construction.cityInfo.civInfo.placeUnitNearTile(construction.cityInfo.location, name)
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,24 @@ class UnitActions {
|
|||||||
actionList += UnitAction("Fortify",{unit.action="Fortify 0"}, unit.currentMovement != 0f)
|
actionList += UnitAction("Fortify",{unit.action="Fortify 0"}, unit.currentMovement != 0f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(unit.getBaseUnit().upgradesTo!=null) {
|
||||||
|
val upgradedUnit = GameBasics.Units[unit.getBaseUnit().upgradesTo!!]!!
|
||||||
|
if (upgradedUnit.isBuildable(unit.civInfo)) {
|
||||||
|
val goldCostOfUpgrade = (upgradedUnit.cost - unit.getBaseUnit().cost) * 2 + 10
|
||||||
|
actionList += UnitAction("Upgrade to ${upgradedUnit.name} ($goldCostOfUpgrade gold)",
|
||||||
|
{
|
||||||
|
unit.civInfo.gold -= goldCostOfUpgrade
|
||||||
|
val unitTile = unit.getTile()
|
||||||
|
unitTile.unit = null
|
||||||
|
val newunit = unit.civInfo.placeUnitNearTile(unitTile.position, upgradedUnit.name)
|
||||||
|
newunit.health = unit.health
|
||||||
|
newunit.currentMovement=0f
|
||||||
|
},
|
||||||
|
unit.civInfo.gold >= goldCostOfUpgrade
|
||||||
|
&& unit.currentMovement == unit.maxMovement.toFloat() )
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (unit.name == "Settler") {
|
if (unit.name == "Settler") {
|
||||||
actionList += UnitAction("Found city",
|
actionList += UnitAction("Found city",
|
||||||
{
|
{
|
||||||
|
@ -17,6 +17,10 @@ import com.unciv.ui.worldscreen.WorldScreen
|
|||||||
class UnitActionsTable(val worldScreen: WorldScreen) : Table(){
|
class UnitActionsTable(val worldScreen: WorldScreen) : Table(){
|
||||||
|
|
||||||
fun getIconForUnitAction(unitAction:String): Image {
|
fun getIconForUnitAction(unitAction:String): Image {
|
||||||
|
if(unitAction.startsWith("Upgrade to")){
|
||||||
|
val unitToUpgradeTo = Regex("""Upgrade to (\S*)""").find(unitAction)!!.groups[1]!!.value
|
||||||
|
return ImageGetter.getUnitIcon(unitToUpgradeTo)
|
||||||
|
}
|
||||||
when(unitAction){
|
when(unitAction){
|
||||||
"Move unit" -> return ImageGetter.getStatIcon("Movement")
|
"Move unit" -> return ImageGetter.getStatIcon("Movement")
|
||||||
"Stop movement"-> return ImageGetter.getStatIcon("Movement").apply { color= Color.RED }
|
"Stop movement"-> return ImageGetter.getStatIcon("Movement").apply { color= Color.RED }
|
||||||
@ -51,7 +55,7 @@ class UnitActionsTable(val worldScreen: WorldScreen) : Table(){
|
|||||||
val actionButton = Button(CameraStageBaseScreen.skin)
|
val actionButton = Button(CameraStageBaseScreen.skin)
|
||||||
actionButton.add(getIconForUnitAction(unitAction.name)).size(20f).pad(5f)
|
actionButton.add(getIconForUnitAction(unitAction.name)).size(20f).pad(5f)
|
||||||
actionButton.add(Label(unitAction.name,CameraStageBaseScreen.skin)
|
actionButton.add(Label(unitAction.name,CameraStageBaseScreen.skin)
|
||||||
.setFontColor(Color.WHITE))
|
.setFontColor(Color.WHITE)).pad(5f)
|
||||||
actionButton.pack()
|
actionButton.pack()
|
||||||
actionButton.addClickListener({ unitAction.action(); UnCivGame.Current.worldScreen!!.update() })
|
actionButton.addClickListener({ unitAction.action(); UnCivGame.Current.worldScreen!!.update() })
|
||||||
if (!unitAction.canAct) actionButton.disable()
|
if (!unitAction.canAct) actionButton.disable()
|
||||||
|
Reference in New Issue
Block a user