mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-22 22:00:24 +07:00
Resolved #1404 - AI should no longer be able to win cultural victory after being defeated
This commit is contained in:
@ -21,8 +21,8 @@ android {
|
|||||||
applicationId "com.unciv.app"
|
applicationId "com.unciv.app"
|
||||||
minSdkVersion 14
|
minSdkVersion 14
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
versionCode 333
|
versionCode 334
|
||||||
versionName "3.3.3"
|
versionName "3.3.4"
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
|
@ -63,30 +63,13 @@ class GameInfo {
|
|||||||
var thisPlayer = previousHumanPlayer // not calling is currentPlayer because that's alreay taken and I can't think of a better name
|
var thisPlayer = previousHumanPlayer // not calling is currentPlayer because that's alreay taken and I can't think of a better name
|
||||||
var currentPlayerIndex = civilizations.indexOf(thisPlayer)
|
var currentPlayerIndex = civilizations.indexOf(thisPlayer)
|
||||||
|
|
||||||
|
|
||||||
fun switchTurn(){
|
fun switchTurn(){
|
||||||
thisPlayer.endTurn()
|
thisPlayer.endTurn()
|
||||||
currentPlayerIndex = (currentPlayerIndex+1) % civilizations.size
|
currentPlayerIndex = (currentPlayerIndex+1) % civilizations.size
|
||||||
if(currentPlayerIndex==0){
|
if(currentPlayerIndex==0){
|
||||||
turns++
|
turns++
|
||||||
if (turns % 10 == 0 && !gameParameters.noBarbarians) {
|
if (turns % 10 == 0 && !gameParameters.noBarbarians) placeBarbarians()
|
||||||
val encampments = tileMap.values.filter { it.improvement==Constants.barbarianEncampment }
|
|
||||||
|
|
||||||
if(encampments.size < civilizations.filter { it.isMajorCiv() }.size) {
|
|
||||||
val newEncampmentTile = placeBarbarianEncampment(encampments)
|
|
||||||
if (newEncampmentTile != null)
|
|
||||||
placeBarbarianUnit(newEncampmentTile)
|
|
||||||
}
|
|
||||||
|
|
||||||
val totalBarbariansAllowedOnMap = encampments.size*3
|
|
||||||
var extraBarbarians = totalBarbariansAllowedOnMap - getBarbarianCivilization().getCivUnits().size
|
|
||||||
|
|
||||||
for (tile in tileMap.values.filter { it.improvement == Constants.barbarianEncampment }) {
|
|
||||||
if(extraBarbarians<=0) break
|
|
||||||
extraBarbarians--
|
|
||||||
placeBarbarianUnit(tile)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
thisPlayer = civilizations[currentPlayerIndex]
|
thisPlayer = civilizations[currentPlayerIndex]
|
||||||
thisPlayer.startTurn()
|
thisPlayer.startTurn()
|
||||||
@ -95,7 +78,7 @@ class GameInfo {
|
|||||||
switchTurn()
|
switchTurn()
|
||||||
|
|
||||||
while(thisPlayer.playerType==PlayerType.AI){
|
while(thisPlayer.playerType==PlayerType.AI){
|
||||||
NextTurnAutomation().automateCivMoves(thisPlayer)
|
if(!thisPlayer.isDefeated()) NextTurnAutomation().automateCivMoves(thisPlayer)
|
||||||
switchTurn()
|
switchTurn()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,6 +86,10 @@ class GameInfo {
|
|||||||
currentPlayerCiv = getCivilization(currentPlayer)
|
currentPlayerCiv = getCivilization(currentPlayer)
|
||||||
|
|
||||||
// Start our turn immediately before the player can made decisions - affects whether our units can commit automated actions and then be attacked immediately etc.
|
// Start our turn immediately before the player can made decisions - affects whether our units can commit automated actions and then be attacked immediately etc.
|
||||||
|
notifyOfCloseEnemyUnits(thisPlayer)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun notifyOfCloseEnemyUnits(thisPlayer: CivilizationInfo) {
|
||||||
val viewableInvisibleTiles = thisPlayer.viewableInvisibleUnitsTiles.map { it.position }
|
val viewableInvisibleTiles = thisPlayer.viewableInvisibleUnitsTiles.map { it.position }
|
||||||
val enemyUnitsCloseToTerritory = thisPlayer.viewableTiles
|
val enemyUnitsCloseToTerritory = thisPlayer.viewableTiles
|
||||||
.filter {
|
.filter {
|
||||||
@ -113,14 +100,12 @@ class GameInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// enemy units ON our territory
|
// enemy units ON our territory
|
||||||
addEnemyUnitNotification(
|
addEnemyUnitNotification(thisPlayer,
|
||||||
thisPlayer,
|
|
||||||
enemyUnitsCloseToTerritory.filter { it.getOwner() == thisPlayer },
|
enemyUnitsCloseToTerritory.filter { it.getOwner() == thisPlayer },
|
||||||
"in"
|
"in"
|
||||||
)
|
)
|
||||||
// enemy units NEAR our territory
|
// enemy units NEAR our territory
|
||||||
addEnemyUnitNotification(
|
addEnemyUnitNotification(thisPlayer,
|
||||||
thisPlayer,
|
|
||||||
enemyUnitsCloseToTerritory.filter { it.getOwner() != thisPlayer },
|
enemyUnitsCloseToTerritory.filter { it.getOwner() != thisPlayer },
|
||||||
"near"
|
"near"
|
||||||
)
|
)
|
||||||
@ -140,6 +125,26 @@ class GameInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun placeBarbarians() {
|
||||||
|
val encampments = tileMap.values.filter { it.improvement == Constants.barbarianEncampment }
|
||||||
|
|
||||||
|
if (encampments.size < civilizations.filter { it.isMajorCiv() }.size) {
|
||||||
|
val newEncampmentTile = placeBarbarianEncampment(encampments)
|
||||||
|
if (newEncampmentTile != null)
|
||||||
|
placeBarbarianUnit(newEncampmentTile)
|
||||||
|
}
|
||||||
|
|
||||||
|
val totalBarbariansAllowedOnMap = encampments.size * 3
|
||||||
|
var extraBarbarians = totalBarbariansAllowedOnMap - getBarbarianCivilization().getCivUnits().size
|
||||||
|
|
||||||
|
for (tile in tileMap.values.filter { it.improvement == Constants.barbarianEncampment }) {
|
||||||
|
if (extraBarbarians <= 0) break
|
||||||
|
extraBarbarians--
|
||||||
|
placeBarbarianUnit(tile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun placeBarbarianEncampment(existingEncampments: List<TileInfo>): TileInfo? {
|
fun placeBarbarianEncampment(existingEncampments: List<TileInfo>): TileInfo? {
|
||||||
// Barbarians will only spawn in places that no one can see
|
// Barbarians will only spawn in places that no one can see
|
||||||
val allViewableTiles = civilizations.filterNot { it.isBarbarian() }
|
val allViewableTiles = civilizations.filterNot { it.isBarbarian() }
|
||||||
|
Reference in New Issue
Block a user