mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-13 12:27:40 +07:00
Merge remote-tracking branch 'upstream/master'
update
This commit is contained in:
commit
f5f62496bb
@ -22,7 +22,7 @@ android {
|
|||||||
minSdkVersion 14
|
minSdkVersion 14
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
versionCode 301
|
versionCode 301
|
||||||
versionName "3.1.0"
|
versionName "3.1.0-patch1"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Had to add this crap for Travis to build, it wanted to sign the app
|
// Had to add this crap for Travis to build, it wanted to sign the app
|
||||||
|
@ -77,7 +77,7 @@ class GameStarter{
|
|||||||
civ.placeUnitNearTile(startingLocation.position, "Warrior")
|
civ.placeUnitNearTile(startingLocation.position, "Warrior")
|
||||||
civ.placeUnitNearTile(startingLocation.position, "Scout")
|
civ.placeUnitNearTile(startingLocation.position, "Scout")
|
||||||
|
|
||||||
if (!civ.isPlayerCivilization()) {
|
if (!civ.isPlayerCivilization() && civ.isMajorCiv()) {
|
||||||
for (unit in gameInfo.getDifficulty().aiFreeUnits) {
|
for (unit in gameInfo.getDifficulty().aiFreeUnits) {
|
||||||
civ.placeUnitNearTile(startingLocation.position, unit)
|
civ.placeUnitNearTile(startingLocation.position, unit)
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,37 @@ class Battle(val gameInfo:GameInfo) {
|
|||||||
|
|
||||||
private fun postBattleAction(attacker: ICombatant, defender: ICombatant, attackedTile:TileInfo) {
|
private fun postBattleAction(attacker: ICombatant, defender: ICombatant, attackedTile:TileInfo) {
|
||||||
|
|
||||||
|
postBattleNotifications(attacker, defender, attackedTile)
|
||||||
|
|
||||||
|
tryHealAfterAttacking(attacker, defender)
|
||||||
|
|
||||||
|
postBattleNationUniques(defender, attackedTile, attacker)
|
||||||
|
|
||||||
|
// This needs to come BEFORE the move-to-tile, because if we haven't conquered it we can't move there =)
|
||||||
|
if (defender.isDefeated() && defender is CityCombatant && attacker.isMelee())
|
||||||
|
conquerCity(defender.city, attacker)
|
||||||
|
|
||||||
|
// we're a melee unit and we destroyed\captured an enemy unit
|
||||||
|
postBattleMoveToAttackedTile(attacker, defender, attackedTile)
|
||||||
|
|
||||||
|
reduceAttackerMovementPointsAndAttacks(attacker, defender)
|
||||||
|
|
||||||
|
postBattleAddXp(attacker, defender)
|
||||||
|
|
||||||
|
// Add culture when defeating a barbarian when Honor policy is adopted (can be either attacker or defender!)
|
||||||
|
tryGetCultureFromHonor(attacker, defender)
|
||||||
|
tryGetCultureFromHonor(defender, attacker)
|
||||||
|
|
||||||
|
if (defender.isDefeated() && defender is MapUnitCombatant && !defender.getUnitType().isCivilian()
|
||||||
|
&& attacker.getCivInfo().policies.isAdopted("Honor Complete"))
|
||||||
|
attacker.getCivInfo().gold += defender.unit.baseUnit.getProductionCost(attacker.getCivInfo()) / 10
|
||||||
|
|
||||||
|
if (attacker is MapUnitCombatant && attacker.unit.action != null
|
||||||
|
&& attacker.unit.action!!.startsWith("moveTo"))
|
||||||
|
attacker.unit.action = null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun postBattleNotifications(attacker: ICombatant, defender: ICombatant, attackedTile: TileInfo) {
|
||||||
if (attacker.getCivInfo() != defender.getCivInfo()) { // If what happened was that a civilian unit was captures, that's dealt with in the CaptureCilvilianUnit function
|
if (attacker.getCivInfo() != defender.getCivInfo()) { // If what happened was that a civilian unit was captures, that's dealt with in the CaptureCilvilianUnit function
|
||||||
val whatHappenedString =
|
val whatHappenedString =
|
||||||
if (attacker !is CityCombatant && attacker.isDefeated()) " {was destroyed while attacking}"
|
if (attacker !is CityCombatant && attacker.isDefeated()) " {was destroyed while attacking}"
|
||||||
@ -80,8 +111,9 @@ class Battle(val gameInfo:GameInfo) {
|
|||||||
val notificationString = attackerString + whatHappenedString + defenderString
|
val notificationString = attackerString + whatHappenedString + defenderString
|
||||||
defender.getCivInfo().addNotification(notificationString, attackedTile.position, Color.RED)
|
defender.getCivInfo().addNotification(notificationString, attackedTile.position, Color.RED)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Units that heal when killing
|
private fun tryHealAfterAttacking(attacker: ICombatant, defender: ICombatant) {
|
||||||
if (defender.isDefeated()
|
if (defender.isDefeated()
|
||||||
&& defender is MapUnitCombatant
|
&& defender is MapUnitCombatant
|
||||||
&& attacker is MapUnitCombatant) {
|
&& attacker is MapUnitCombatant) {
|
||||||
@ -93,8 +125,9 @@ class Battle(val gameInfo:GameInfo) {
|
|||||||
attacker.unit.healBy(amountToHeal)
|
attacker.unit.healBy(amountToHeal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun postBattleNationUniques(defender: ICombatant, attackedTile: TileInfo, attacker: ICombatant) {
|
||||||
// German unique - needs to be checked before we try to move to the enemy tile, since the encampment disappears after we move in
|
// German unique - needs to be checked before we try to move to the enemy tile, since the encampment disappears after we move in
|
||||||
if (defender.isDefeated() && defender.getCivInfo().isBarbarian()
|
if (defender.isDefeated() && defender.getCivInfo().isBarbarian()
|
||||||
&& attackedTile.improvement == Constants.barbarianEncampment
|
&& attackedTile.improvement == Constants.barbarianEncampment
|
||||||
@ -111,9 +144,10 @@ class Battle(val gameInfo:GameInfo) {
|
|||||||
&& Random().nextDouble() > 0.33) {
|
&& Random().nextDouble() > 0.33) {
|
||||||
attacker.getCivInfo().placeUnitNearTile(attackedTile.position, defender.getName())
|
attacker.getCivInfo().placeUnitNearTile(attackedTile.position, defender.getName())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// we're a melee unit and we destroyed\captured an enemy unit
|
private fun postBattleMoveToAttackedTile(attacker: ICombatant, defender: ICombatant, attackedTile: TileInfo) {
|
||||||
else if (attacker.isMelee()
|
if (attacker.isMelee()
|
||||||
&& (defender.isDefeated() || defender.getCivInfo() == attacker.getCivInfo())
|
&& (defender.isDefeated() || defender.getCivInfo() == attacker.getCivInfo())
|
||||||
// This is so that if we attack e.g. a barbarian in enemy territory that we can't enter, we won't enter it
|
// This is so that if we attack e.g. a barbarian in enemy territory that we can't enter, we won't enter it
|
||||||
&& (attacker as MapUnitCombatant).unit.movement.canMoveTo(attackedTile)) {
|
&& (attacker as MapUnitCombatant).unit.movement.canMoveTo(attackedTile)) {
|
||||||
@ -122,8 +156,22 @@ class Battle(val gameInfo:GameInfo) {
|
|||||||
captureCivilianUnit(attacker, MapUnitCombatant(attackedTile.civilianUnit!!))
|
captureCivilianUnit(attacker, MapUnitCombatant(attackedTile.civilianUnit!!))
|
||||||
attacker.unit.movement.moveToTile(attackedTile)
|
attacker.unit.movement.moveToTile(attackedTile)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun postBattleAddXp(attacker: ICombatant, defender: ICombatant) {
|
||||||
|
if (attacker.isMelee()) {
|
||||||
|
if (!defender.getUnitType().isCivilian()) // unit was not captured but actually attacked
|
||||||
|
{
|
||||||
|
addXp(attacker, 5, defender)
|
||||||
|
addXp(defender, 4, attacker)
|
||||||
|
}
|
||||||
|
} else { // ranged attack
|
||||||
|
addXp(attacker, 2, defender)
|
||||||
|
addXp(defender, 2, attacker)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun reduceAttackerMovementPointsAndAttacks(attacker: ICombatant, defender: ICombatant) {
|
||||||
if (attacker is MapUnitCombatant) {
|
if (attacker is MapUnitCombatant) {
|
||||||
val unit = attacker.unit
|
val unit = attacker.unit
|
||||||
if (unit.hasUnique("Can move after attacking")
|
if (unit.hasUnique("Can move after attacking")
|
||||||
@ -140,37 +188,6 @@ class Battle(val gameInfo:GameInfo) {
|
|||||||
} else if (attacker is CityCombatant) {
|
} else if (attacker is CityCombatant) {
|
||||||
attacker.city.attackedThisTurn = true
|
attacker.city.attackedThisTurn = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (defender.isDefeated()
|
|
||||||
&& defender is CityCombatant
|
|
||||||
&& attacker.isMelee())
|
|
||||||
conquerCity(defender.city, attacker)
|
|
||||||
|
|
||||||
|
|
||||||
if (attacker.isMelee()) {
|
|
||||||
if (!defender.getUnitType().isCivilian()) // unit was not captured but actually attacked
|
|
||||||
{
|
|
||||||
addXp(attacker, 5, defender)
|
|
||||||
addXp(defender, 4, attacker)
|
|
||||||
}
|
|
||||||
} else { // ranged attack
|
|
||||||
addXp(attacker, 2, defender)
|
|
||||||
addXp(defender, 2, attacker)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Add culture when defeating a barbarian when Honor policy is adopted (can be either attacker or defender!)
|
|
||||||
tryGetCultureFromHonor(attacker, defender)
|
|
||||||
tryGetCultureFromHonor(defender, attacker)
|
|
||||||
|
|
||||||
if (defender.isDefeated() && defender is MapUnitCombatant && !defender.getUnitType().isCivilian()
|
|
||||||
&& attacker.getCivInfo().policies.isAdopted("Honor Complete"))
|
|
||||||
attacker.getCivInfo().gold += defender.unit.baseUnit.getProductionCost(attacker.getCivInfo()) / 10
|
|
||||||
|
|
||||||
if (attacker is MapUnitCombatant && attacker.unit.action != null
|
|
||||||
&& attacker.unit.action!!.startsWith("moveTo"))
|
|
||||||
attacker.unit.action = null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun tryGetCultureFromHonor(civUnit:ICombatant, barbarianUnit:ICombatant){
|
private fun tryGetCultureFromHonor(civUnit:ICombatant, barbarianUnit:ICombatant){
|
||||||
@ -209,6 +226,7 @@ class Battle(val gameInfo:GameInfo) {
|
|||||||
if(civilianUnit!=null) captureCivilianUnit(attacker, MapUnitCombatant(civilianUnit!!))
|
if(civilianUnit!=null) captureCivilianUnit(attacker, MapUnitCombatant(civilianUnit!!))
|
||||||
for(airUnit in airUnits.toList()) airUnit.destroy()
|
for(airUnit in airUnits.toList()) airUnit.destroy()
|
||||||
}
|
}
|
||||||
|
city.hasJustBeenConquered = true
|
||||||
|
|
||||||
if (attacker.getCivInfo().isPlayerCivilization())
|
if (attacker.getCivInfo().isPlayerCivilization())
|
||||||
attackerCiv.popupAlerts.add(PopupAlert(AlertType.CityConquered, city.name))
|
attackerCiv.popupAlerts.add(PopupAlert(AlertType.CityConquered, city.name))
|
||||||
|
@ -61,9 +61,10 @@ class CityConstructions {
|
|||||||
val currentConstructionSnapshot = currentConstruction // See below
|
val currentConstructionSnapshot = currentConstruction // See below
|
||||||
var result = currentConstructionSnapshot.tr()
|
var result = currentConstructionSnapshot.tr()
|
||||||
if (currentConstructionSnapshot!=""
|
if (currentConstructionSnapshot!=""
|
||||||
&& SpecialConstruction.getSpecialConstructions().none { it.name==currentConstructionSnapshot })
|
&& SpecialConstruction.getSpecialConstructions().none { it.name==currentConstructionSnapshot }) {
|
||||||
result += ("\r\nCost " + getConstruction(currentConstruction).getProductionCost(cityInfo.civInfo).toString()).tr()
|
result += ("\r\nCost " + getConstruction(currentConstruction).getProductionCost(cityInfo.civInfo).toString()).tr()
|
||||||
result += "\r\n" + turnsToConstruction(currentConstructionSnapshot ) + " {turns}".tr()
|
result += "\r\n" + turnsToConstruction(currentConstructionSnapshot) + " {turns}".tr()
|
||||||
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,8 +116,11 @@ class CityConstructions {
|
|||||||
else return 0
|
else return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getRemainingWork(constructionName: String) =
|
fun getRemainingWork(constructionName: String): Int {
|
||||||
getConstruction(constructionName).getProductionCost(cityInfo.civInfo) - getWorkDone(constructionName)
|
val constr = getConstruction(constructionName)
|
||||||
|
if (constr is SpecialConstruction) return 0
|
||||||
|
return constr.getProductionCost(cityInfo.civInfo) - getWorkDone(constructionName)
|
||||||
|
}
|
||||||
|
|
||||||
fun turnsToConstruction(constructionName: String): Int {
|
fun turnsToConstruction(constructionName: String): Int {
|
||||||
val workLeft = getRemainingWork(constructionName)
|
val workLeft = getRemainingWork(constructionName)
|
||||||
|
@ -26,6 +26,7 @@ class CityInfo {
|
|||||||
@Transient val range = 2
|
@Transient val range = 2
|
||||||
@Transient lateinit var tileMap: TileMap
|
@Transient lateinit var tileMap: TileMap
|
||||||
@Transient lateinit var tilesInRange:HashSet<TileInfo>
|
@Transient lateinit var tilesInRange:HashSet<TileInfo>
|
||||||
|
@Transient var hasJustBeenConquered = false // this is so that military units can enter the city, even before we decide what to do with it
|
||||||
|
|
||||||
var location: Vector2 = Vector2.Zero
|
var location: Vector2 = Vector2.Zero
|
||||||
var name: String = ""
|
var name: String = ""
|
||||||
@ -271,10 +272,8 @@ class CityInfo {
|
|||||||
getCenterTile().improvement="City ruins"
|
getCenterTile().improvement="City ruins"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun annexCity(conqueringCiv: CivilizationInfo) {
|
fun annexCity() {
|
||||||
puppetCity(conqueringCiv)
|
if(!civInfo.policies.isAdopted("Police State")) {
|
||||||
|
|
||||||
if(!conqueringCiv.policies.isAdopted("Police State")) {
|
|
||||||
expansion.cultureStored = 0
|
expansion.cultureStored = 0
|
||||||
expansion.reset()
|
expansion.reset()
|
||||||
}
|
}
|
||||||
@ -327,7 +326,8 @@ class CityInfo {
|
|||||||
/* Liberating is returning a city to its founder - makes you LOSE warmongering points **/
|
/* Liberating is returning a city to its founder - makes you LOSE warmongering points **/
|
||||||
fun liberateCity(conqueringCiv: CivilizationInfo) {
|
fun liberateCity(conqueringCiv: CivilizationInfo) {
|
||||||
if (foundingCiv == "") { // this should never happen but just in case...
|
if (foundingCiv == "") { // this should never happen but just in case...
|
||||||
annexCity(conqueringCiv)
|
puppetCity(conqueringCiv)
|
||||||
|
annexCity()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -367,6 +367,7 @@ class CityInfo {
|
|||||||
civInfo.cities = civInfo.cities.toMutableList().apply { remove(this@CityInfo) }
|
civInfo.cities = civInfo.cities.toMutableList().apply { remove(this@CityInfo) }
|
||||||
newCivInfo.cities = newCivInfo.cities.toMutableList().apply { add(this@CityInfo) }
|
newCivInfo.cities = newCivInfo.cities.toMutableList().apply { add(this@CityInfo) }
|
||||||
civInfo = newCivInfo
|
civInfo = newCivInfo
|
||||||
|
hasJustBeenConquered=false
|
||||||
|
|
||||||
// now that the tiles have changed, we need to reassign population
|
// now that the tiles have changed, we need to reassign population
|
||||||
workedTiles.filterNot { tiles.contains(it) }
|
workedTiles.filterNot { tiles.contains(it) }
|
||||||
|
@ -228,7 +228,7 @@ class UnitMovementAlgorithms(val unit:MapUnit) {
|
|||||||
if (!distanceToTiles.containsKey(destination))
|
if (!distanceToTiles.containsKey(destination))
|
||||||
throw YouCantGetThereFromHereException("$unit can't get from ${unit.currentTile.position} to ${destination.position}.")
|
throw YouCantGetThereFromHereException("$unit can't get from ${unit.currentTile.position} to ${destination.position}.")
|
||||||
|
|
||||||
if(destination.isCityCenter() && destination.getOwner()!=unit.civInfo)
|
if(destination.isCityCenter() && destination.getOwner()!=unit.civInfo && !destination.getCity()!!.hasJustBeenConquered)
|
||||||
throw Exception("This is an enemy city, you can't go here!")
|
throw Exception("This is an enemy city, you can't go here!")
|
||||||
|
|
||||||
unit.currentMovement -= distanceToTiles[destination]!!.totalDistance
|
unit.currentMovement -= distanceToTiles[destination]!!.totalDistance
|
||||||
@ -290,7 +290,7 @@ class UnitMovementAlgorithms(val unit:MapUnit) {
|
|||||||
|
|
||||||
val tileOwner = tile.getOwner()
|
val tileOwner = tile.getOwner()
|
||||||
if(tileOwner!=null && tileOwner.civName!=unit.owner) {
|
if(tileOwner!=null && tileOwner.civName!=unit.owner) {
|
||||||
if (tile.isCityCenter()) return false
|
if (tile.isCityCenter() && !tile.getCity()!!.hasJustBeenConquered) return false
|
||||||
if (!unit.civInfo.canEnterTiles(tileOwner)
|
if (!unit.civInfo.canEnterTiles(tileOwner)
|
||||||
&& !(unit.civInfo.isPlayerCivilization() && tileOwner.isCityState())) return false
|
&& !(unit.civInfo.isPlayerCivilization() && tileOwner.isCityState())) return false
|
||||||
// AIs won't enter city-state's border.
|
// AIs won't enter city-state's border.
|
||||||
|
@ -117,7 +117,9 @@ class TradeEvaluation{
|
|||||||
return 50 * amountToBuyInOffer
|
return 50 * amountToBuyInOffer
|
||||||
}
|
}
|
||||||
|
|
||||||
TradeType.Technology -> return sqrt(GameBasics.Technologies[offer.name]!!.cost.toDouble()).toInt()*20
|
TradeType.Technology ->
|
||||||
|
return (sqrt(GameBasics.Technologies[offer.name]!!.cost.toDouble())
|
||||||
|
* civInfo.gameInfo.gameParameters.gameSpeed.getModifier()).toInt()*20
|
||||||
TradeType.Introduction -> return 250
|
TradeType.Introduction -> return 250
|
||||||
TradeType.WarDeclaration -> {
|
TradeType.WarDeclaration -> {
|
||||||
val nameOfCivToDeclareWarOn = offer.name.removePrefix("Declare war on ")
|
val nameOfCivToDeclareWarOn = offer.name.removePrefix("Declare war on ")
|
||||||
|
@ -168,9 +168,7 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
|
|||||||
val annexCityButton = TextButton("Annex city".tr(), skin)
|
val annexCityButton = TextButton("Annex city".tr(), skin)
|
||||||
annexCityButton.labelCell.pad(10f)
|
annexCityButton.labelCell.pad(10f)
|
||||||
annexCityButton.onClick {
|
annexCityButton.onClick {
|
||||||
city.isPuppet=false
|
city.annexCity()
|
||||||
city.isBeingRazed=false
|
|
||||||
city.resistanceCounter = city.population.population
|
|
||||||
update()
|
update()
|
||||||
}
|
}
|
||||||
razeCityButtonHolder.add(annexCityButton).colspan(cityPickerTable.columns)
|
razeCityButtonHolder.add(annexCityButton).colspan(cityPickerTable.columns)
|
||||||
|
@ -72,7 +72,8 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu
|
|||||||
}).row()
|
}).row()
|
||||||
}
|
}
|
||||||
add(TextButton("Annex".tr(), skin).onClick {
|
add(TextButton("Annex".tr(), skin).onClick {
|
||||||
city.annexCity(conqueringCiv)
|
city.puppetCity(conqueringCiv)
|
||||||
|
city.annexCity()
|
||||||
worldScreen.shouldUpdate=true
|
worldScreen.shouldUpdate=true
|
||||||
close()
|
close()
|
||||||
}).row()
|
}).row()
|
||||||
@ -82,7 +83,8 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu
|
|||||||
close()
|
close()
|
||||||
}).row()
|
}).row()
|
||||||
add(TextButton("Raze".tr(), skin).onClick {
|
add(TextButton("Raze".tr(), skin).onClick {
|
||||||
city.annexCity(conqueringCiv)
|
city.puppetCity(conqueringCiv)
|
||||||
|
city.annexCity()
|
||||||
city.isBeingRazed = true
|
city.isBeingRazed = true
|
||||||
worldScreen.shouldUpdate=true
|
worldScreen.shouldUpdate=true
|
||||||
close()
|
close()
|
||||||
|
Loading…
Reference in New Issue
Block a user