Resolved #2818 - Can no longer build improvements outside your borders

This commit is contained in:
Yair Morgenstern 2020-08-07 17:22:48 +03:00
parent faaab3173b
commit ae60aab7e5
7 changed files with 54 additions and 61 deletions

View file

@ -95,12 +95,14 @@
{
"name": "Road",
"turnsToBuild": 4,
"techRequired": "The Wheel"
"techRequired": "The Wheel",
"uniques": ["Can be built outside your borders"]
},
{
"name": "Railroad",
"turnsToBuild": 4,
"techRequired": "Railroad"
"techRequired": "Railroad",
"uniques": ["Can be built outside your borders"]
},
// Removals

View file

@ -507,6 +507,8 @@ Working... =
Waiting for other players... =
in =
Next turn =
1 turn =
[numberOfTurns] turns =
Turn =
turns =
turn =
@ -659,6 +661,7 @@ Landing =
Flanking =
vs [unitType] =
Terrain =
Tile =
Missing resource =

View file

@ -178,12 +178,7 @@ object BattleDamage {
if (!defender.unit.hasUnique("No defensive terrain bonus")) {
val tileDefenceBonus = tile.getDefensiveBonus()
if (tileDefenceBonus > 0)
modifiers["Terrain"] = tileDefenceBonus
val improvement = tile.getTileImprovement()
if (improvement != null && tile.isFriendlyTerritory(defender.getCivInfo()))
if (improvement.hasUnique("Gives a defensive bonus of 50%")) modifiers[improvement.name] = 0.50f
else if (improvement.hasUnique("Gives a defensive bonus of 100%")) modifiers[improvement.name] = 1.0f
modifiers["Tile"] = tileDefenceBonus
}
if(attacker.isRanged()) {

View file

@ -272,6 +272,9 @@ open class TileInfo {
improvement.techRequired?.let { civInfo.tech.isResearched(it) } == false -> false
"Cannot be built on bonus resource" in improvement.uniques && resource != null
&& getTileResource().resourceType == ResourceType.Bonus -> false
!improvement.hasUnique("Can be built outside your borders")
&& getOwner() != civInfo -> false
improvement.terrainsCanBeBuiltOn.contains(topTerrain.name) -> true
improvement.name == "Road" && roadStatus == RoadStatus.None -> true
improvement.name == "Railroad" && this.roadStatus != RoadStatus.Railroad -> true
@ -308,6 +311,12 @@ open class TileInfo {
fun getDefensiveBonus(): Float {
var bonus = getBaseTerrain().defenceBonus
if (terrainFeature != null) bonus += getTerrainFeature()!!.defenceBonus
val tileImprovement = getTileImprovement()
if (tileImprovement != null) {
for (unique in tileImprovement.uniqueObjects)
if (unique.placeholderText == "Gives a defensive bonus of []%")
bonus += unique.params[0].toFloat() / 100
}
return bonus
}
@ -361,7 +370,7 @@ open class TileInfo {
if (roadStatus !== RoadStatus.None && !isCityCenter()) lineList += roadStatus.toString().tr()
if (improvement != null) lineList += improvement!!.tr()
if (improvementInProgress != null && isViewableToPlayer)
lineList += "{$improvementInProgress}\r\n{in} $turnsToImprovement {turns}".tr() // todo change to [] translation notation
lineList += "{$improvementInProgress}\r\n $turnsToImprovement {turns}".tr() // todo change to [] translation notation
if (civilianUnit != null && isViewableToPlayer)
lineList += civilianUnit!!.name.tr() + " - " + civilianUnit!!.civInfo.civName.tr()
if (militaryUnit != null && isViewableToPlayer) {
@ -371,12 +380,6 @@ open class TileInfo {
lineList += milUnitString
}
var defenceBonus = getDefensiveBonus()
val tileImprovement = getTileImprovement()
if (tileImprovement != null) {
for (unique in tileImprovement.uniqueObjects)
if (unique.placeholderText == "Gives a defensive bonus of []%")
defenceBonus += unique.params[0].toFloat() / 100
}
if (defenceBonus != 0.0f) {
var defencePercentString = (defenceBonus * 100).toInt().toString() + "%"
if (!defencePercentString.startsWith("-")) defencePercentString = "+$defencePercentString"

View file

@ -247,7 +247,8 @@ class PlayerPickerTable(val previousScreen: IPreviousScreen, var gameParameters:
}).pad(10f).width(nationsPopupWidth).row()
}
nationsPopup.add(ScrollPane(nationListTable)).height(previousScreen.stage.height * 0.8f)
nationsPopup.add(ScrollPane(nationListTable).apply { setOverscroll(false,false) })
.height(previousScreen.stage.height * 0.8f)
nationsPopup.pack()
val closeImage = ImageGetter.getImage("OtherIcons/Close")

View file

@ -5,7 +5,6 @@ import com.badlogic.gdx.scenes.scene2d.Group
import com.badlogic.gdx.scenes.scene2d.Touchable
import com.badlogic.gdx.scenes.scene2d.ui.Button
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup
import com.badlogic.gdx.utils.Align
import com.unciv.Constants
import com.unciv.logic.map.RoadStatus
@ -15,75 +14,65 @@ import com.unciv.models.translations.tr
import com.unciv.ui.utils.*
import kotlin.math.round
class ImprovementPickerScreen(tileInfo: TileInfo, onAccept: ()->Unit) : PickerScreen() {
class ImprovementPickerScreen(val tileInfo: TileInfo, val onAccept: ()->Unit) : PickerScreen() {
private var selectedImprovement: TileImprovement? = null
val currentPlayerCiv = game.gameInfo.getCurrentPlayerCivilization()
fun accept(improvement: TileImprovement?) {
if (improvement == null) return
if (improvement.name == Constants.cancelImprovementOrder) {
tileInfo.stopWorkingOnImprovement()
// no onAccept() - Worker can stay selected
} else {
tileInfo.startWorkingOnImprovement(improvement, currentPlayerCiv)
if (tileInfo.civilianUnit != null) tileInfo.civilianUnit!!.action = null // this is to "wake up" the worker if it's sleeping
onAccept()
}
game.setWorldScreen()
dispose()
}
init {
val currentPlayerCiv = game.gameInfo.getCurrentPlayerCivilization()
setDefaultCloseAction()
fun accept(improvement: TileImprovement?) {
if (improvement != null) {
if (improvement.name == Constants.cancelImprovementOrder ) {
tileInfo.stopWorkingOnImprovement()
// no onAccept() - Worker can stay selected
} else {
tileInfo.startWorkingOnImprovement(improvement, currentPlayerCiv)
if (tileInfo.civilianUnit != null) tileInfo.civilianUnit!!.action = null // this is to "wake up" the worker if it's sleeping
onAccept()
}
game.setWorldScreen()
dispose()
}
}
rightSideButton.setText("Pick improvement".tr())
rightSideButton.onClick {
accept(selectedImprovement)
}
if(tileInfo.improvementInProgress!=null){
val currentImprovementText = "{${tileInfo.improvementInProgress}} {in} ${tileInfo.turnsToImprovement} {turns}"
topTable.add(currentImprovementText.toLabel()).padBottom(10f).row()
}
val regularImprovements = Table()
regularImprovements.defaults().pad(5f)
for (improvement in tileInfo.tileMap.gameInfo.ruleSet.tileImprovements.values) {
if (!tileInfo.canBuildImprovement(improvement, currentPlayerCiv)) continue
if(improvement.name == tileInfo.improvement) continue
if(improvement.name == tileInfo.improvementInProgress) continue
if (improvement.name == tileInfo.improvement) continue
val group = Table()
val improvementButtonTable = Table()
val image = ImageGetter.getImprovementIcon(improvement.name,30f)
val image = ImageGetter.getImprovementIcon(improvement.name, 30f)
group.add(image).size(30f).pad(10f)
improvementButtonTable.add(image).size(30f).pad(10f)
var labelText = improvement.name.tr()
val turnsToBuild = improvement.getTurnsToBuild(currentPlayerCiv)
if (turnsToBuild > 0) labelText += " - $turnsToBuild {turns}"
val provideResource = tileInfo.hasViewableResource(currentPlayerCiv) && tileInfo.getTileResource().improvement == improvement.name
if (provideResource) labelText += "\n"+"Provides [${tileInfo.resource}]".tr()
val removeImprovement = (improvement.name!=RoadStatus.Road.name
&& improvement.name!=RoadStatus.Railroad.name && !improvement.name.startsWith("Remove") && improvement.name != Constants.cancelImprovementOrder)
if (tileInfo.improvement!=null && removeImprovement) labelText += "\n" + "Replaces [${tileInfo.improvement}]".tr()
if (provideResource) labelText += "\n" + "Provides [${tileInfo.resource}]".tr()
val removeImprovement = (improvement.name != RoadStatus.Road.name
&& improvement.name != RoadStatus.Railroad.name && !improvement.name.startsWith("Remove") && improvement.name != Constants.cancelImprovementOrder)
if (tileInfo.improvement != null && removeImprovement) labelText += "\n" + "Replaces [${tileInfo.improvement}]".tr()
group.add(labelText.toLabel()).pad(10f)
improvementButtonTable.add(labelText.toLabel()).pad(10f)
group.touchable = Touchable.enabled
group.onClick {
improvementButtonTable.touchable = Touchable.enabled
improvementButtonTable.onClick {
selectedImprovement = improvement
pick(improvement.name.tr())
val ruleSet = tileInfo.tileMap.gameInfo.ruleSet
descriptionLabel.setText(improvement.getDescription(ruleSet))
}
val pickNow = "Pick now!".toLabel()
pickNow.onClick {
accept(improvement)
}
val pickNow = "Pick now!".toLabel().onClick { accept(improvement) }
val statIcons = Table()
@ -91,8 +80,7 @@ class ImprovementPickerScreen(tileInfo: TileInfo, onAccept: ()->Unit) : PickerSc
val stats = tileInfo.getImprovementStats(improvement, currentPlayerCiv, tileInfo.getCity())
// subtract the benefits of the replaced improvement, if any
val existingImprovement = tileInfo.getTileImprovement()
if (existingImprovement!=null && removeImprovement)
{
if (existingImprovement != null && removeImprovement) {
val existingStats = tileInfo.getImprovementStats(existingImprovement, currentPlayerCiv, tileInfo.getCity())
stats.add(existingStats.times(-1.0f))
}
@ -100,7 +88,7 @@ class ImprovementPickerScreen(tileInfo: TileInfo, onAccept: ()->Unit) : PickerSc
// icons of benefits (food, gold, etc) by improvement
val statsTable = Table()
statsTable.defaults()
for(stat in stats.toHashMap()) {
for (stat in stats.toHashMap()) {
val statValue = round(stat.value).toInt()
if (statValue == 0) continue
@ -120,7 +108,7 @@ class ImprovementPickerScreen(tileInfo: TileInfo, onAccept: ()->Unit) : PickerSc
if (removeImprovement && tileInfo.hasViewableResource(currentPlayerCiv) && tileInfo.getTileResource().improvement == tileInfo.improvement) {
val crossedResource = Group()
val cross = ImageGetter.getImage("OtherIcons/Close")
cross.setSize(30f,30f)
cross.setSize(30f, 30f)
cross.color = Color.RED
val resourceIcon = ImageGetter.getResourceImage(tileInfo.resource.toString(), 30f)
crossedResource.addActor(resourceIcon)
@ -132,7 +120,8 @@ class ImprovementPickerScreen(tileInfo: TileInfo, onAccept: ()->Unit) : PickerSc
regularImprovements.add(statIcons).align(Align.right)
val improvementButton = Button(skin)
improvementButton.add(group).pad(5f).fillY()
improvementButton.add(improvementButtonTable).pad(5f).fillY()
if (improvement.name == tileInfo.improvementInProgress) improvementButton.color= Color.GREEN
regularImprovements.add(improvementButton)
regularImprovements.add(pickNow).padLeft(10f)
regularImprovements.row()

View file

@ -63,7 +63,7 @@ class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() {
for (resource in revealedStrategicResources) {
val resourceImage = ImageGetter.getResourceImage(resource.name, 20f)
resourceImages[resource.name] = resourceImage
resourceTable.add(resourceImage)
resourceTable.add(resourceImage).padRight(0f)
val resourceLabel = "0".toLabel()
resourceLabels[resource.name] = resourceLabel
resourceTable.add(resourceLabel)