mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-26 13:27:22 -04:00
Show promises not to settle, ask on found city action (#4148)
This commit is contained in:
parent
5e1803c40a
commit
e1c6cef111
@ -86,6 +86,9 @@ We will remember this. =
|
||||
[civName] and [targetCivName] have signed a Peace Treaty! =
|
||||
[civName] and [targetCivName] have signed the Declaration of Friendship! =
|
||||
[civName] has denounced [targetCivName]! =
|
||||
Do you want to break your promise to [leaderName]? =
|
||||
We promised not to settle near them ([count] turns remaining) =
|
||||
They promised not to settle near us ([count] turns remaining) =
|
||||
|
||||
Unforgivable =
|
||||
Enemy =
|
||||
|
@ -352,11 +352,30 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
|
||||
if (!otherCiv.isPlayerCivilization()) { // human players make their own choices
|
||||
diplomacyTable.add(getRelationshipTable(otherCivDiplomacyManager)).row()
|
||||
diplomacyTable.add(getDiplomacyModifiersTable(otherCivDiplomacyManager)).row()
|
||||
val promisesTable = getPromisesTable(diplomacyManager, otherCivDiplomacyManager)
|
||||
if (promisesTable != null) diplomacyTable.add(promisesTable).row()
|
||||
}
|
||||
|
||||
return diplomacyTable
|
||||
}
|
||||
|
||||
private fun getPromisesTable(diplomacyManager: DiplomacyManager, otherCivDiplomacyManager: DiplomacyManager): Table? {
|
||||
val promisesTable = Table()
|
||||
|
||||
// Not for (flag in DiplomacyFlags.values()) - all other flags should result in DiplomaticModifiers or stay internal?
|
||||
val flag = DiplomacyFlags.AgreedToNotSettleNearUs
|
||||
if (otherCivDiplomacyManager.hasFlag(flag)) {
|
||||
val text = "We promised not to settle near them ([${otherCivDiplomacyManager.getFlag(flag)}] turns remaining)"
|
||||
promisesTable.add(text.toLabel(Color.LIGHT_GRAY)).row()
|
||||
}
|
||||
if (diplomacyManager.hasFlag(flag)) {
|
||||
val text = "They promised not to settle near us ([${diplomacyManager.getFlag(flag)}] turns remaining)"
|
||||
promisesTable.add(text.toLabel(Color.LIGHT_GRAY)).row()
|
||||
}
|
||||
|
||||
return if (promisesTable.cells.isEmpty) null else promisesTable
|
||||
}
|
||||
|
||||
private fun getDiplomacyModifiersTable(otherCivDiplomacyManager: DiplomacyManager): Table {
|
||||
val diplomacyModifiersTable = Table()
|
||||
for (modifier in otherCivDiplomacyManager.diplomaticModifiers) {
|
||||
|
@ -6,6 +6,7 @@ import com.unciv.logic.automation.UnitAutomation
|
||||
import com.unciv.logic.automation.WorkerAutomation
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.logic.civilization.NotificationIcon
|
||||
import com.unciv.logic.civilization.diplomacy.DiplomacyFlags
|
||||
import com.unciv.logic.civilization.diplomacy.DiplomaticModifiers
|
||||
import com.unciv.logic.map.MapUnit
|
||||
import com.unciv.logic.map.RoadStatus
|
||||
@ -17,6 +18,7 @@ import com.unciv.models.ruleset.Building
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.ui.pickerscreens.ImprovementPickerScreen
|
||||
import com.unciv.ui.pickerscreens.PromotionPickerScreen
|
||||
import com.unciv.ui.utils.Sounds
|
||||
import com.unciv.ui.utils.YesNoPopup
|
||||
import com.unciv.ui.utils.hasOpenPopups
|
||||
import com.unciv.ui.worldscreen.WorldScreen
|
||||
@ -143,14 +145,37 @@ object UnitActions {
|
||||
if (!unit.hasUnique("Founds a new city") || tile.isWater) return null
|
||||
return UnitAction(
|
||||
type = UnitActionType.FoundCity,
|
||||
uncivSound = UncivSound.Chimes,
|
||||
uncivSound = UncivSound.Silent,
|
||||
action = {
|
||||
UncivGame.Current.settings.addCompletedTutorialTask("Found city")
|
||||
unit.civInfo.addCity(tile.position)
|
||||
if (tile.ruleset.tileImprovements.containsKey("City center"))
|
||||
tile.improvement = "City center"
|
||||
unit.destroy()
|
||||
}.takeIf { unit.currentMovement > 0 && !tile.getTilesInDistance(3).any { it.isCityCenter() } })
|
||||
// check if we would be breaking a promise
|
||||
val civInfo = unit.civInfo
|
||||
val brokenPromises = HashSet<String>()
|
||||
for (otherCiv in civInfo.getKnownCivs().filter { it.isMajorCiv() && !civInfo.isAtWarWith(it) }) {
|
||||
val diplomacyManager = otherCiv.getDiplomacyManager(civInfo)
|
||||
if (diplomacyManager.hasFlag(DiplomacyFlags.AgreedToNotSettleNearUs)) {
|
||||
val citiesWithin6Tiles = otherCiv.cities
|
||||
.filter { it.getCenterTile().aerialDistanceTo(tile) <= 6 }
|
||||
.filter { otherCiv.exploredTiles.contains(it.location) }
|
||||
if (citiesWithin6Tiles.isNotEmpty()) brokenPromises += otherCiv.getLeaderDisplayName()
|
||||
}
|
||||
}
|
||||
val action = {
|
||||
Sounds.play(UncivSound.Chimes)
|
||||
UncivGame.Current.settings.addCompletedTutorialTask("Found city")
|
||||
unit.civInfo.addCity(tile.position)
|
||||
if (tile.ruleset.tileImprovements.containsKey("City center"))
|
||||
tile.improvement = "City center"
|
||||
unit.destroy()
|
||||
UncivGame.Current.worldScreen.shouldUpdate = true
|
||||
}
|
||||
if (brokenPromises.isEmpty()) action()
|
||||
else {
|
||||
// ask if we would be breaking a promise
|
||||
val text = "Do you want to break your promise to [" + brokenPromises.joinToString(", ") + "]?"
|
||||
YesNoPopup(text, action, UncivGame.Current.worldScreen).open(force = true)
|
||||
}
|
||||
}.takeIf { unit.currentMovement > 0 && !tile.getTilesInDistance(3).any { it.isCityCenter() } }
|
||||
)
|
||||
}
|
||||
|
||||
private fun addPromoteAction(unit: MapUnit, actionList: ArrayList<UnitAction>) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user