Allow settlers to be captured when worker replacements exist

This commit is contained in:
Yair Morgenstern 2023-02-19 08:18:33 +02:00
parent e40ab3e9da
commit 3a14ac6248
3 changed files with 23 additions and 28 deletions

View File

@ -1,7 +1,6 @@
package com.unciv
object Constants {
const val worker = "Worker"
const val settler = "Settler"
const val eraSpecificUnit = "Era Starting Unit"
const val spreadReligion = "Spread Religion"

View File

@ -625,20 +625,7 @@ object Battle {
attacker.getCivInfo().popupAlerts.add(PopupAlert(AlertType.RecapturedCivilian, capturedUnitTile.position.toString()))
}
// Captured settlers are converted to workers unless captured by barbarians (so they can be returned later).
capturedUnit.hasUnique(UniqueType.FoundCity) && !attacker.getCivInfo().isBarbarian() -> {
capturedUnit.destroy()
// This is so that future checks which check if a unit has been captured are caught give the right answer
// For example, in postBattleMoveToAttackedTile
capturedUnit.civ = attacker.getCivInfo()
val workerTypeUnit = attacker.getCivInfo().gameInfo.ruleset.units.values
.firstOrNull { it.isCivilian() && it.getMatchingUniques(UniqueType.BuildImprovements).any { it.params[0] == "Land" } }
if (workerTypeUnit != null)
attacker.getCivInfo().units.placeUnitNearTile(capturedUnitTile.position, workerTypeUnit.name)
}
else -> capturedUnit.capturedBy(attacker.getCivInfo())
else -> captureOrConvertToWorker(capturedUnit, attacker.getCivInfo())
}
if (!wasDestroyedInstead)
@ -653,6 +640,23 @@ object Battle {
capturedUnit.updateVisibleTiles()
}
fun captureOrConvertToWorker(capturedUnit: MapUnit, capturingCiv: Civilization){
// Captured settlers are converted to workers unless captured by barbarians (so they can be returned later).
if (capturedUnit.hasUnique(UniqueType.FoundCity) && !capturingCiv.isBarbarian()) {
capturedUnit.destroy()
// This is so that future checks which check if a unit has been captured are caught give the right answer
// For example, in postBattleMoveToAttackedTile
capturedUnit.civ = capturingCiv
val workerTypeUnit = capturingCiv.gameInfo.ruleset.units.values
.firstOrNull { it.isCivilian() && it.getMatchingUniques(UniqueType.BuildImprovements).any { it.params[0] == "Land" } }
if (workerTypeUnit != null)
capturingCiv.units.placeUnitNearTile(capturedUnit.currentTile.position, workerTypeUnit.name)
}
else capturedUnit.capturedBy(capturingCiv)
}
fun destroyIfDefeated(attackedCiv: Civilization, attacker: Civilization) {
if (attackedCiv.isDefeated()) {
if (attackedCiv.isCityState())

View File

@ -6,6 +6,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
import com.unciv.Constants
import com.unciv.UncivGame
import com.unciv.logic.battle.Battle
import com.unciv.logic.civilization.AlertType
import com.unciv.logic.civilization.Civilization
import com.unciv.logic.civilization.LocationAction
@ -13,14 +14,10 @@ import com.unciv.logic.civilization.NotificationCategory
import com.unciv.logic.civilization.PopupAlert
import com.unciv.logic.civilization.diplomacy.DiplomaticModifiers
import com.unciv.logic.civilization.diplomacy.RelationshipLevel
import com.unciv.models.ruleset.unique.UniqueType
import com.unciv.models.translations.fillPlaceholders
import com.unciv.models.translations.tr
import com.unciv.ui.audio.MusicMood
import com.unciv.ui.audio.MusicTrackChooserFlags
import com.unciv.ui.images.ImageGetter
import com.unciv.ui.popups.Popup
import com.unciv.ui.screens.diplomacyscreen.LeaderIntroTable
import com.unciv.ui.components.KeyCharAndCode
import com.unciv.ui.components.extensions.disable
import com.unciv.ui.components.extensions.keyShortcuts
@ -28,6 +25,9 @@ import com.unciv.ui.components.extensions.onActivation
import com.unciv.ui.components.extensions.pad
import com.unciv.ui.components.extensions.toLabel
import com.unciv.ui.components.extensions.toTextButton
import com.unciv.ui.images.ImageGetter
import com.unciv.ui.popups.Popup
import com.unciv.ui.screens.diplomacyscreen.LeaderIntroTable
import com.unciv.ui.screens.victoryscreen.VictoryScreen
import java.util.*
@ -363,15 +363,7 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu
})
responseTable.add(getCloseButton(Constants.no, 'n') {
// Take it for ourselves
// Settlers become workers at this point
if (capturedUnit.hasUnique(UniqueType.FoundCity)) {
capturedUnit.destroy()
// This is so that future checks which check if a unit has been captured are caught give the right answer
// For example, in postBattleMoveToAttackedTile
capturedUnit.civ = captor
captor.units.placeUnitNearTile(tile.position, Constants.worker)
} else
capturedUnit.capturedBy(captor)
Battle.captureOrConvertToWorker(capturedUnit, captor)
}).row()
add(responseTable)
}