Exits simulation mode when player wins or losses. (#2624)

* Exits simulation mode (simulateUntilTurnForDebug) when player wins or losses.

* Update core/src/com/unciv/logic/GameInfo.kt

Co-authored-by: AcridBrimistic <acridbrimistic@protonmail.com>

* Update core/src/com/unciv/UncivGame.kt

Co-authored-by: AcridBrimistic <acridbrimistic@protonmail.com>

* Update core/src/com/unciv/logic/GameInfo.kt

Co-authored-by: AcridBrimistic <acridbrimistic@protonmail.com>

* New parameter for simulation until any of player wins or loses or maximum turns reached.
Added battle logging flag.

Co-authored-by: AcridBrimistic <acridbrimistic@protonmail.com>
This commit is contained in:
Alexander Korolyov 2020-05-17 11:33:49 +02:00 committed by GitHub
parent 2444b2e1d2
commit 55fdb3a9e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 4 deletions

View File

@ -45,6 +45,17 @@ class UncivGame(
*/ */
val simulateUntilTurnForDebug: Int = 0 val simulateUntilTurnForDebug: Int = 0
/** Simulate until any player wins or loses,
* or turns exceeds indicated number
* Does not update World View changes until finished.
* Set to 0 to disable.
*/
var simulateUntilWinOrLose: Int = 1000
/** Console log battles
*/
val alertBattle = true
lateinit var worldScreen: WorldScreen lateinit var worldScreen: WorldScreen
var music: Music? = null var music: Music? = null
@ -198,4 +209,3 @@ class LoadingScreen:CameraStageBaseScreen() {
} }
} }

View File

@ -84,6 +84,7 @@ class GameInfo {
while (thisPlayer.playerType == PlayerType.AI while (thisPlayer.playerType == PlayerType.AI
|| UncivGame.Current.simulateUntilTurnForDebug > turns || UncivGame.Current.simulateUntilTurnForDebug > turns
|| UncivGame.Current.simulateUntilWinOrLose > turns
// For multiplayer, if there are 3+ players and one is defeated, // For multiplayer, if there are 3+ players and one is defeated,
// we'll want to skip over their turn // we'll want to skip over their turn
|| (thisPlayer.isDefeated() && gameParameters.isOnlineMultiplayer) || (thisPlayer.isDefeated() && gameParameters.isOnlineMultiplayer)
@ -95,6 +96,19 @@ class GameInfo {
if (thisPlayer.isBarbarian() if (thisPlayer.isBarbarian()
&& !gameParameters.noBarbarians && !gameParameters.noBarbarians
&& turns % 10 == 0) placeBarbarians() && turns % 10 == 0) placeBarbarians()
// exit simulation mode when player wins or loses
if (thisPlayer.isDefeated() || thisPlayer.victoryManager.hasWon()
&& UncivGame.Current.simulateUntilWinOrLose != 0
) {
// stop simulation
UncivGame.Current.simulateUntilWinOrLose = turns
println("Simulation stopped on turn $turns")
for (civ in UncivGame.Current.gameInfo.civilizations) {
val victoryType = civ.victoryManager.hasWonVictoryType()
if (civ.victoryManager.hasWon()) println("$civ won $victoryType victory")
}
}
} }
switchTurn() switchTurn()
} }
@ -369,4 +383,3 @@ class GameInfo {
} }

View File

@ -33,8 +33,10 @@ object Battle {
} }
fun attack(attacker: ICombatant, defender: ICombatant) { fun attack(attacker: ICombatant, defender: ICombatant) {
println(attacker.getCivInfo().civName+" "+attacker.getName()+" attacked "+ if (UncivGame.Current.alertBattle) {
defender.getCivInfo().civName+" "+defender.getName()) println(attacker.getCivInfo().civName+" "+attacker.getName()+" attacked "+
defender.getCivInfo().civName+" "+defender.getName())
}
val attackedTile = defender.getTile() val attackedTile = defender.getTile()
if(attacker is MapUnitCombatant && attacker.getUnitType().isAirUnit()){ if(attacker is MapUnitCombatant && attacker.getUnitType().isAirUnit()){