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", "name": "Road",
"turnsToBuild": 4, "turnsToBuild": 4,
"techRequired": "The Wheel" "techRequired": "The Wheel",
"uniques": ["Can be built outside your borders"]
}, },
{ {
"name": "Railroad", "name": "Railroad",
"turnsToBuild": 4, "turnsToBuild": 4,
"techRequired": "Railroad" "techRequired": "Railroad",
"uniques": ["Can be built outside your borders"]
}, },
// Removals // Removals

View file

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

View file

@ -178,12 +178,7 @@ object BattleDamage {
if (!defender.unit.hasUnique("No defensive terrain bonus")) { if (!defender.unit.hasUnique("No defensive terrain bonus")) {
val tileDefenceBonus = tile.getDefensiveBonus() val tileDefenceBonus = tile.getDefensiveBonus()
if (tileDefenceBonus > 0) if (tileDefenceBonus > 0)
modifiers["Terrain"] = tileDefenceBonus modifiers["Tile"] = 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
} }
if(attacker.isRanged()) { if(attacker.isRanged()) {

View file

@ -272,6 +272,9 @@ open class TileInfo {
improvement.techRequired?.let { civInfo.tech.isResearched(it) } == false -> false improvement.techRequired?.let { civInfo.tech.isResearched(it) } == false -> false
"Cannot be built on bonus resource" in improvement.uniques && resource != null "Cannot be built on bonus resource" in improvement.uniques && resource != null
&& getTileResource().resourceType == ResourceType.Bonus -> false && getTileResource().resourceType == ResourceType.Bonus -> false
!improvement.hasUnique("Can be built outside your borders")
&& getOwner() != civInfo -> false
improvement.terrainsCanBeBuiltOn.contains(topTerrain.name) -> true improvement.terrainsCanBeBuiltOn.contains(topTerrain.name) -> true
improvement.name == "Road" && roadStatus == RoadStatus.None -> true improvement.name == "Road" && roadStatus == RoadStatus.None -> true
improvement.name == "Railroad" && this.roadStatus != RoadStatus.Railroad -> true improvement.name == "Railroad" && this.roadStatus != RoadStatus.Railroad -> true
@ -308,6 +311,12 @@ open class TileInfo {
fun getDefensiveBonus(): Float { fun getDefensiveBonus(): Float {
var bonus = getBaseTerrain().defenceBonus var bonus = getBaseTerrain().defenceBonus
if (terrainFeature != null) bonus += getTerrainFeature()!!.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 return bonus
} }
@ -361,7 +370,7 @@ open class TileInfo {
if (roadStatus !== RoadStatus.None && !isCityCenter()) lineList += roadStatus.toString().tr() if (roadStatus !== RoadStatus.None && !isCityCenter()) lineList += roadStatus.toString().tr()
if (improvement != null) lineList += improvement!!.tr() if (improvement != null) lineList += improvement!!.tr()
if (improvementInProgress != null && isViewableToPlayer) 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) if (civilianUnit != null && isViewableToPlayer)
lineList += civilianUnit!!.name.tr() + " - " + civilianUnit!!.civInfo.civName.tr() lineList += civilianUnit!!.name.tr() + " - " + civilianUnit!!.civInfo.civName.tr()
if (militaryUnit != null && isViewableToPlayer) { if (militaryUnit != null && isViewableToPlayer) {
@ -371,12 +380,6 @@ open class TileInfo {
lineList += milUnitString lineList += milUnitString
} }
var defenceBonus = getDefensiveBonus() 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) { if (defenceBonus != 0.0f) {
var defencePercentString = (defenceBonus * 100).toInt().toString() + "%" var defencePercentString = (defenceBonus * 100).toInt().toString() + "%"
if (!defencePercentString.startsWith("-")) defencePercentString = "+$defencePercentString" if (!defencePercentString.startsWith("-")) defencePercentString = "+$defencePercentString"

View file

@ -247,7 +247,8 @@ class PlayerPickerTable(val previousScreen: IPreviousScreen, var gameParameters:
}).pad(10f).width(nationsPopupWidth).row() }).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() nationsPopup.pack()
val closeImage = ImageGetter.getImage("OtherIcons/Close") 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.Touchable
import com.badlogic.gdx.scenes.scene2d.ui.Button import com.badlogic.gdx.scenes.scene2d.ui.Button
import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup
import com.badlogic.gdx.utils.Align import com.badlogic.gdx.utils.Align
import com.unciv.Constants import com.unciv.Constants
import com.unciv.logic.map.RoadStatus import com.unciv.logic.map.RoadStatus
@ -15,75 +14,65 @@ import com.unciv.models.translations.tr
import com.unciv.ui.utils.* import com.unciv.ui.utils.*
import kotlin.math.round 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 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 { init {
val currentPlayerCiv = game.gameInfo.getCurrentPlayerCivilization()
setDefaultCloseAction() 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.setText("Pick improvement".tr())
rightSideButton.onClick { rightSideButton.onClick {
accept(selectedImprovement) accept(selectedImprovement)
} }
if(tileInfo.improvementInProgress!=null){
val currentImprovementText = "{${tileInfo.improvementInProgress}} {in} ${tileInfo.turnsToImprovement} {turns}"
topTable.add(currentImprovementText.toLabel()).padBottom(10f).row()
}
val regularImprovements = Table() val regularImprovements = Table()
regularImprovements.defaults().pad(5f) regularImprovements.defaults().pad(5f)
for (improvement in tileInfo.tileMap.gameInfo.ruleSet.tileImprovements.values) { for (improvement in tileInfo.tileMap.gameInfo.ruleSet.tileImprovements.values) {
if (!tileInfo.canBuildImprovement(improvement, currentPlayerCiv)) continue if (!tileInfo.canBuildImprovement(improvement, currentPlayerCiv)) continue
if(improvement.name == tileInfo.improvement) continue if (improvement.name == tileInfo.improvement) continue
if(improvement.name == tileInfo.improvementInProgress) 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() var labelText = improvement.name.tr()
val turnsToBuild = improvement.getTurnsToBuild(currentPlayerCiv) val turnsToBuild = improvement.getTurnsToBuild(currentPlayerCiv)
if (turnsToBuild > 0) labelText += " - $turnsToBuild {turns}" if (turnsToBuild > 0) labelText += " - $turnsToBuild {turns}"
val provideResource = tileInfo.hasViewableResource(currentPlayerCiv) && tileInfo.getTileResource().improvement == improvement.name val provideResource = tileInfo.hasViewableResource(currentPlayerCiv) && tileInfo.getTileResource().improvement == improvement.name
if (provideResource) labelText += "\n"+"Provides [${tileInfo.resource}]".tr() if (provideResource) labelText += "\n" + "Provides [${tileInfo.resource}]".tr()
val removeImprovement = (improvement.name!=RoadStatus.Road.name val removeImprovement = (improvement.name != RoadStatus.Road.name
&& improvement.name!=RoadStatus.Railroad.name && !improvement.name.startsWith("Remove") && improvement.name != Constants.cancelImprovementOrder) && 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 (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 improvementButtonTable.touchable = Touchable.enabled
group.onClick { improvementButtonTable.onClick {
selectedImprovement = improvement selectedImprovement = improvement
pick(improvement.name.tr()) pick(improvement.name.tr())
val ruleSet = tileInfo.tileMap.gameInfo.ruleSet val ruleSet = tileInfo.tileMap.gameInfo.ruleSet
descriptionLabel.setText(improvement.getDescription(ruleSet)) descriptionLabel.setText(improvement.getDescription(ruleSet))
} }
val pickNow = "Pick now!".toLabel() val pickNow = "Pick now!".toLabel().onClick { accept(improvement) }
pickNow.onClick {
accept(improvement)
}
val statIcons = Table() val statIcons = Table()
@ -91,8 +80,7 @@ class ImprovementPickerScreen(tileInfo: TileInfo, onAccept: ()->Unit) : PickerSc
val stats = tileInfo.getImprovementStats(improvement, currentPlayerCiv, tileInfo.getCity()) val stats = tileInfo.getImprovementStats(improvement, currentPlayerCiv, tileInfo.getCity())
// subtract the benefits of the replaced improvement, if any // subtract the benefits of the replaced improvement, if any
val existingImprovement = tileInfo.getTileImprovement() val existingImprovement = tileInfo.getTileImprovement()
if (existingImprovement!=null && removeImprovement) if (existingImprovement != null && removeImprovement) {
{
val existingStats = tileInfo.getImprovementStats(existingImprovement, currentPlayerCiv, tileInfo.getCity()) val existingStats = tileInfo.getImprovementStats(existingImprovement, currentPlayerCiv, tileInfo.getCity())
stats.add(existingStats.times(-1.0f)) 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 // icons of benefits (food, gold, etc) by improvement
val statsTable = Table() val statsTable = Table()
statsTable.defaults() statsTable.defaults()
for(stat in stats.toHashMap()) { for (stat in stats.toHashMap()) {
val statValue = round(stat.value).toInt() val statValue = round(stat.value).toInt()
if (statValue == 0) continue 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) { if (removeImprovement && tileInfo.hasViewableResource(currentPlayerCiv) && tileInfo.getTileResource().improvement == tileInfo.improvement) {
val crossedResource = Group() val crossedResource = Group()
val cross = ImageGetter.getImage("OtherIcons/Close") val cross = ImageGetter.getImage("OtherIcons/Close")
cross.setSize(30f,30f) cross.setSize(30f, 30f)
cross.color = Color.RED cross.color = Color.RED
val resourceIcon = ImageGetter.getResourceImage(tileInfo.resource.toString(), 30f) val resourceIcon = ImageGetter.getResourceImage(tileInfo.resource.toString(), 30f)
crossedResource.addActor(resourceIcon) crossedResource.addActor(resourceIcon)
@ -132,7 +120,8 @@ class ImprovementPickerScreen(tileInfo: TileInfo, onAccept: ()->Unit) : PickerSc
regularImprovements.add(statIcons).align(Align.right) regularImprovements.add(statIcons).align(Align.right)
val improvementButton = Button(skin) 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(improvementButton)
regularImprovements.add(pickNow).padLeft(10f) regularImprovements.add(pickNow).padLeft(10f)
regularImprovements.row() regularImprovements.row()

View file

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