mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-25 23:29:47 +07:00
Added "unit upgrade" action for old units
This commit is contained in:
@ -21,7 +21,7 @@ android {
|
||||
applicationId "com.unciv.game"
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 26
|
||||
versionCode 64
|
||||
versionCode 65
|
||||
versionName "2.2.5"
|
||||
}
|
||||
buildTypes {
|
||||
|
@ -168,8 +168,8 @@ class CivilizationInfo {
|
||||
addNotification("A $greatPerson has been born!", randomCity.location)
|
||||
}
|
||||
|
||||
fun placeUnitNearTile(location: Vector2, unitName: String) {
|
||||
gameInfo.tileMap.placeUnitNearTile(location, unitName, this)
|
||||
fun placeUnitNearTile(location: Vector2, unitName: String): MapUnit {
|
||||
return gameInfo.tileMap.placeUnitNearTile(location, unitName, this)
|
||||
}
|
||||
|
||||
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()
|
||||
unit.owner = civInfo.civName
|
||||
unit.civInfo = civInfo
|
||||
val tilesInDistance = getTilesInDistance(position, 2)
|
||||
val unitToPlaceTile = tilesInDistance.firstOrNull { it.unit == null }
|
||||
if(unitToPlaceTile!=null) unitToPlaceTile.unit = unit // And if there's none, then kill me.
|
||||
return unit
|
||||
}
|
||||
|
||||
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.IConstruction
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.logic.map.MapUnit
|
||||
import com.unciv.logic.map.UnitType
|
||||
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
|
||||
}
|
||||
|
||||
override fun isBuildable(construction: CityConstructions): Boolean {
|
||||
val civInfo = construction.cityInfo.civInfo
|
||||
fun isBuildable(civInfo:CivilizationInfo): Boolean {
|
||||
if (unbuildable) return false
|
||||
if (requiredTech!=null && !civInfo.tech.isResearched(requiredTech!!)) return false
|
||||
if (obsoleteTech!=null && civInfo.tech.isResearched(obsoleteTech!!)) return false
|
||||
@ -84,6 +84,10 @@ class Unit : INamed, IConstruction, ICivilopedia {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun isBuildable(construction: CityConstructions): Boolean {
|
||||
return isBuildable(construction.cityInfo.civInfo)
|
||||
}
|
||||
|
||||
override fun postBuildEvent(construction: CityConstructions) {
|
||||
construction.cityInfo.civInfo.placeUnitNearTile(construction.cityInfo.location, name)
|
||||
}
|
||||
|
@ -48,6 +48,24 @@ class UnitActions {
|
||||
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") {
|
||||
actionList += UnitAction("Found city",
|
||||
{
|
||||
|
@ -17,6 +17,10 @@ import com.unciv.ui.worldscreen.WorldScreen
|
||||
class UnitActionsTable(val worldScreen: WorldScreen) : Table(){
|
||||
|
||||
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){
|
||||
"Move unit" -> return ImageGetter.getStatIcon("Movement")
|
||||
"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)
|
||||
actionButton.add(getIconForUnitAction(unitAction.name)).size(20f).pad(5f)
|
||||
actionButton.add(Label(unitAction.name,CameraStageBaseScreen.skin)
|
||||
.setFontColor(Color.WHITE))
|
||||
.setFontColor(Color.WHITE)).pad(5f)
|
||||
actionButton.pack()
|
||||
actionButton.addClickListener({ unitAction.action(); UnCivGame.Current.worldScreen!!.update() })
|
||||
if (!unitAction.canAct) actionButton.disable()
|
||||
|
Reference in New Issue
Block a user