Combat java.util.star-import (#9382)

This commit is contained in:
SomeTroglodyte
2023-05-13 20:50:55 +02:00
committed by GitHub
parent d2eaae0922
commit 97769b89b6
35 changed files with 81 additions and 78 deletions

View File

@ -1,6 +1,6 @@
package com.unciv.logic
import java.util.*
import java.util.Locale
import kotlin.math.abs
/**
@ -112,5 +112,3 @@ object IdChecker {
return (10 - (sum % 10)) % 10
}
}

View File

@ -8,7 +8,7 @@ import com.unciv.logic.civilization.Civilization
import com.unciv.logic.map.tile.Tile
import com.unciv.logic.map.TileMap
import com.unciv.utils.Log
import java.util.*
import java.util.UUID
import kotlin.collections.ArrayList
import kotlin.collections.HashMap

View File

@ -11,10 +11,10 @@ import com.unciv.logic.map.TileMap
import com.unciv.logic.map.tile.Tile
import com.unciv.models.ruleset.unique.UniqueType
import com.unciv.ui.components.extensions.randomWeighted
import java.util.*
import kotlin.math.max
import kotlin.math.min
import kotlin.math.pow
import kotlin.random.Random
class BarbarianManager : IsPartOfGameInfoSerialization {
/** Deprecated */
@ -78,7 +78,7 @@ class BarbarianManager : IsPartOfGameInfoSerialization {
fun placeBarbarianEncampment() {
// Before we do the expensive stuff, do a roll to see if we will place a camp at all
if (gameInfo.turns > 1 && Random().nextBoolean())
if (gameInfo.turns > 1 && Random.Default.nextBoolean())
return
// Barbarians will only spawn in places that no one can see
@ -119,7 +119,7 @@ class BarbarianManager : IsPartOfGameInfoSerialization {
var tile: Tile?
var addedCamps = 0
var biasCoast = Random().nextInt(6) == 0
var biasCoast = Random.Default.nextInt(6) == 0
// Add the camps
while (addedCamps < campsToAdd) {
@ -146,7 +146,7 @@ class BarbarianManager : IsPartOfGameInfoSerialization {
// Remove some newly non-viable tiles
viableTiles.removeAll(tile.getTilesInDistance(7).toSet())
// Reroll bias
biasCoast = Random().nextInt(6) == 0
biasCoast = Random.Default.nextInt(6) == 0
}
}
}
@ -280,7 +280,7 @@ class Encampment() : IsPartOfGameInfoSerialization {
/** When a barbarian is spawned, seed the counter for next spawn */
private fun resetCountdown() {
// Base 8-12 turns
countdown = 8 + Random().nextInt(5)
countdown = 8 + Random.Default.nextInt(5)
// Quicker on Raging Barbarians
if (gameInfo.gameParameters.ragingBarbarians)
countdown /= 2

View File

@ -45,7 +45,8 @@ import com.unciv.models.ruleset.unit.BaseUnit
import com.unciv.models.stats.Stat
import com.unciv.models.translations.tr
import com.unciv.ui.screens.victoryscreen.RankingType
import java.util.*
import java.util.SortedMap
import java.util.TreeMap
import kotlin.math.min
object NextTurnAutomation {
@ -701,7 +702,7 @@ object NextTurnAutomation {
(it.type == beliefType || beliefType == BeliefType.Any)
&& !additionalBeliefsToExclude.contains(it)
&& civInfo.religionManager.getReligionWithBelief(it) == null
&& it.getMatchingUniques(UniqueType.OnlyAvailableWhen).none { !it.conditionalsApply(civInfo) }
&& it.getMatchingUniques(UniqueType.OnlyAvailableWhen).none { unique -> !unique.conditionalsApply(civInfo) }
}
.maxByOrNull { ReligionAutomation.rateBelief(civInfo, it) }
}
@ -762,7 +763,6 @@ object NextTurnAutomation {
@Suppress("unused") //todo: Work in Progress?
private fun offerDeclarationOfFriendship(civInfo: Civilization) {
val civsThatWeCanDeclareFriendshipWith = civInfo.getKnownCivs()
.asSequence()
.filter {
it.isMajorCiv() && !it.isAtWarWith(civInfo)
&& it.getDiplomacyManager(civInfo).isRelationshipLevelGT(RelationshipLevel.Neutral)
@ -781,7 +781,6 @@ object NextTurnAutomation {
if (!civInfo.diplomacyFunctions.canSignResearchAgreement()) return // don't waste your time
val canSignResearchAgreementCiv = civInfo.getKnownCivs()
.asSequence()
.filter {
civInfo.diplomacyFunctions.canSignResearchAgreementsWith(it)
&& !civInfo.getDiplomacyManager(it).hasFlag(DiplomacyFlags.DeclinedResearchAgreement)

View File

@ -28,9 +28,9 @@ import com.unciv.models.stats.Stat
import com.unciv.models.stats.Stats
import com.unciv.ui.components.extensions.toPercent
import com.unciv.utils.debug
import java.util.*
import kotlin.math.max
import kotlin.math.min
import kotlin.random.Random
/**
* Damage calculations according to civ v wiki and https://steamcommunity.com/sharedfiles/filedetails/?id=170194443
@ -358,7 +358,7 @@ object Battle {
//so...for each round, we randomize who gets the attack in. Seems to be a good way to work for now.
while (potentialDamageToDefender + potentialDamageToAttacker > 0) {
if (Random().nextInt(potentialDamageToDefender + potentialDamageToAttacker) < potentialDamageToDefender) {
if (Random.Default.nextInt(potentialDamageToDefender + potentialDamageToAttacker) < potentialDamageToDefender) {
potentialDamageToDefender--
defender.takeDamage(1)
if (defender.isDefeated()) break
@ -707,7 +707,8 @@ object Battle {
capturedUnit.civ = capturingCiv
val workerTypeUnit = capturingCiv.gameInfo.ruleset.units.values
.firstOrNull { it.isCivilian() && it.getMatchingUniques(UniqueType.BuildImprovements).any { it.params[0] == "Land" } }
.firstOrNull { it.isCivilian() && it.getMatchingUniques(UniqueType.BuildImprovements)
.any { unique -> unique.params[0] == "Land" } }
if (workerTypeUnit != null)
capturingCiv.units.placeUnitNearTile(capturedUnit.currentTile.position, workerTypeUnit.name)
@ -843,9 +844,9 @@ object Battle {
if (defender.unit.isCivilian() || nukeStrength >= 2) {
unit.destroy()
} else if (nukeStrength == 1) {
defender.takeDamage(((40 + Random().nextInt(60)) * damageModifierFromMissingResource).toInt())
defender.takeDamage(((40 + Random.Default.nextInt(60)) * damageModifierFromMissingResource).toInt())
} else if (nukeStrength == 0) {
defender.takeDamage(((20 + Random().nextInt(30)) * damageModifierFromMissingResource).toInt())
defender.takeDamage(((20 + Random.Default.nextInt(30)) * damageModifierFromMissingResource).toInt())
}
postBattleNotifications(attacker, defender, defender.getTile())
destroyIfDefeated(defender.getCivInfo(), attacker.getCivInfo())
@ -865,13 +866,13 @@ object Battle {
if (tile.terrainHasUnique(UniqueType.DestroyableByNukesChance)) {
for (terrainFeature in tile.terrainFeatureObjects) {
for (unique in terrainFeature.getMatchingUniques(UniqueType.DestroyableByNukesChance)) {
if (Random().nextFloat() >= unique.params[0].toFloat() / 100f) continue
if (Random.Default.nextFloat() >= unique.params[0].toFloat() / 100f) continue
tile.removeTerrainFeature(terrainFeature.name)
if (!tile.terrainFeatures.contains("Fallout"))
tile.addTerrainFeature("Fallout")
}
}
} else if (Random().nextFloat() < 0.5f && !tile.terrainFeatures.contains("Fallout")) {
} else if (Random.Default.nextFloat() < 0.5f && !tile.terrainFeatures.contains("Fallout")) {
tile.addTerrainFeature("Fallout")
}
}
@ -888,8 +889,8 @@ object Battle {
var populationLoss = targetedCity.population.population *
when (nukeStrength) {
0 -> 0f
1 -> (30 + Random().nextInt(40)) / 100f
2 -> (60 + Random().nextInt(20)) / 100f
1 -> (30 + Random.Default.nextInt(40)) / 100f
2 -> (60 + Random.Default.nextInt(20)) / 100f
else -> 1f
}
for (unique in targetedCity.getMatchingUniques(UniqueType.PopulationLossFromNukes)) {
@ -1031,7 +1032,7 @@ object Battle {
if (defender != null && defender is MapUnitCombatant && interceptor == defender.unit) continue
interceptor.attacksThisTurn++ // even if you miss, you took the shot
// Does Intercept happen? If not, exit
if (Random().nextFloat() > interceptor.interceptChance() / 100f) return
if (Random.Default.nextFloat() > interceptor.interceptChance() / 100f) return
var damage = BattleDamage.calculateDamageToDefender(
MapUnitCombatant(interceptor),

View File

@ -9,11 +9,11 @@ import com.unciv.models.ruleset.unique.UniqueTarget
import com.unciv.models.ruleset.unique.UniqueType
import com.unciv.models.translations.tr
import com.unciv.ui.components.extensions.toPercent
import java.util.*
import kotlin.collections.set
import kotlin.math.max
import kotlin.math.pow
import kotlin.math.roundToInt
import kotlin.random.Random
object BattleDamage {

View File

@ -22,7 +22,7 @@ import com.unciv.models.ruleset.unique.Unique
import com.unciv.models.ruleset.unique.UniqueType
import com.unciv.models.ruleset.unit.BaseUnit
import com.unciv.models.stats.Stat
import java.util.*
import java.util.UUID
import kotlin.math.roundToInt
enum class CityFlags {

View File

@ -7,8 +7,8 @@ import com.unciv.logic.civilization.NotificationCategory
import com.unciv.logic.civilization.NotificationIcon
import com.unciv.models.ruleset.tile.ResourceType
import com.unciv.models.ruleset.unique.UniqueType
import java.util.*
import kotlin.math.min
import kotlin.random.Random
class CityTurnManager(val city: City) {
@ -41,7 +41,7 @@ class CityTurnManager(val city: City) {
if (city.demandedResource == "" && !city.hasFlag(CityFlags.ResourceDemand)) {
city.setFlag(
CityFlags.ResourceDemand,
(if (city.isCapital()) 25 else 15) + Random().nextInt(10))
(if (city.isCapital()) 25 else 15) + Random.Default.nextInt(10))
}
}
@ -103,7 +103,7 @@ class CityTurnManager(val city: City) {
if (chosenResource != null)
city.demandedResource = chosenResource.name
if (city.demandedResource == "") // Failed to get a valid resource, try again some time later
city.setFlag(CityFlags.ResourceDemand, 15 + Random().nextInt(10))
city.setFlag(CityFlags.ResourceDemand, 15 + Random.Default.nextInt(10))
else
city.civ.addNotification("[${city.name}] demands [${city.demandedResource}]!",
city.location, NotificationCategory.General, NotificationIcon.City, "ResourceIcons/${city.demandedResource}")

View File

@ -22,9 +22,9 @@ import com.unciv.models.ruleset.unique.UniqueType
import com.unciv.models.ruleset.unit.BaseUnit
import com.unciv.models.stats.Stat
import com.unciv.ui.screens.victoryscreen.RankingType
import java.util.*
import kotlin.math.min
import kotlin.math.pow
import kotlin.random.Random
/** Class containing city-state-specific functions */
class CityStateFunctions(val civInfo: Civilization) {
@ -67,7 +67,7 @@ class CityStateFunctions(val civInfo: Civilization) {
return true
}
fun turnsForGreatPersonFromCityState(): Int = ((37 + Random().nextInt(7)) * civInfo.gameInfo.speed.modifier).toInt()
fun turnsForGreatPersonFromCityState(): Int = ((37 + Random.Default.nextInt(7)) * civInfo.gameInfo.speed.modifier).toInt()
/** Gain a random great person from the city state */
fun giveGreatPersonToPatron(receivingCiv: Civilization) {
@ -552,7 +552,7 @@ class CityStateFunctions(val civInfo: Civilization) {
civInfo.getDiplomacyManager(attacker).becomeWary()
}
else if (attacker.isMinorCivAggressor()) { // They've attacked a few
if (Random().nextBoolean()) { // 50% chance
if (Random.Default.nextBoolean()) { // 50% chance
civInfo.getDiplomacyManager(attacker).becomeWary()
}
}
@ -591,7 +591,7 @@ class CityStateFunctions(val civInfo: Civilization) {
if (cityState.isAtWarWith(attacker))
probability += 50
if (Random().nextInt(100) <= probability) {
if (Random.Default.nextInt(100) <= probability) {
cityState.getDiplomacyManager(attacker).becomeWary()
}
}
@ -684,7 +684,7 @@ class CityStateFunctions(val civInfo: Civilization) {
):Sequence<Unique> {
if (civInfo.isCityState()) return emptySequence()
return civInfo.getKnownCivs().asSequence().filter { it.isCityState() }
return civInfo.getKnownCivs().filter { it.isCityState() }
.flatMap {
// We don't use DiplomacyManager.getRelationshipLevel for performance reasons - it tries to calculate getTributeWillingness which is heavy
val relationshipLevel =

View File

@ -20,9 +20,9 @@ import com.unciv.models.ruleset.unique.endTurn
import com.unciv.models.stats.Stats
import com.unciv.ui.components.MayaCalendar
import com.unciv.utils.Log
import java.util.*
import kotlin.math.max
import kotlin.math.min
import kotlin.random.Random
class TurnManager(val civInfo: Civilization) {
@ -173,7 +173,7 @@ class TurnManager(val civInfo: Civilization) {
return
}
val random = Random()
val random = Random.Default
val rebelCount = 1 + random.nextInt(100 + 20 * (civInfo.cities.size - 1)) / 100
val spawnCity = civInfo.cities.maxByOrNull { random.nextInt(it.population.population + 10) } ?: return
val spawnTile = spawnCity.getTiles().maxByOrNull { rateTileForRevoltSpawn(it) } ?: return
@ -215,7 +215,7 @@ class TurnManager(val civInfo: Civilization) {
}
private fun getTurnsBeforeRevolt() =
((4 + Random().nextInt(3)) * max(civInfo.gameInfo.speed.modifier, 1f)).toInt()
((4 + Random.Default.nextInt(3)) * max(civInfo.gameInfo.speed.modifier, 1f)).toInt()
fun endTurn() {

View File

@ -4,7 +4,7 @@ import com.badlogic.gdx.utils.Json
import com.badlogic.gdx.utils.JsonValue
import com.unciv.logic.IsPartOfGameInfoSerialization
import com.unciv.logic.map.tile.TileHistory.TileHistoryState.CityCenterType
import java.util.*
import java.util.TreeMap
/**
* Records events throughout the game related to a tile.

View File

@ -28,7 +28,7 @@ import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.launchIn
import java.time.Duration
import java.time.Instant
import java.util.*
import java.util.Collections
import java.util.concurrent.atomic.AtomicReference
@ -139,12 +139,11 @@ class OnlineMultiplayer {
*/
suspend fun addGame(gameId: String, gameName: String? = null) {
val saveFileName = if (gameName.isNullOrBlank()) gameId else gameName
var gamePreview: GameInfoPreview
try {
gamePreview = multiplayerFiles.tryDownloadGamePreview(gameId)
val gamePreview: GameInfoPreview = try {
multiplayerFiles.tryDownloadGamePreview(gameId)
} catch (ex: MultiplayerFileNotFoundException) {
// Game is so old that a preview could not be found on dropbox lets try the real gameInfo instead
gamePreview = multiplayerFiles.tryDownloadGame(gameId).asPreview()
multiplayerFiles.tryDownloadGame(gameId).asPreview()
}
addGame(gamePreview, saveFileName)
}
@ -459,4 +458,3 @@ suspend fun <T> attemptAction(
fun GameInfoPreview.isUsersTurn() = getCivilization(currentPlayer).playerId == UncivGame.Current.settings.multiplayer.userId
fun GameInfo.isUsersTurn() = getCivilization(currentPlayer).playerId == UncivGame.Current.settings.multiplayer.userId

View File

@ -11,7 +11,8 @@ import java.io.InputStreamReader
import java.net.HttpURLConnection
import java.net.URL
import java.nio.charset.Charset
import java.util.*
import java.util.Date
import java.util.Timer
import kotlin.concurrent.timer
@ -156,10 +157,10 @@ object DropBox: FileStorage {
// var has_more = false
// }
@Suppress("PropertyName")
@Suppress("PropertyName") // and don't make that private or this suppress won't work
private class MetaData: FileMetaData {
// var name = ""
private var server_modified = ""
var server_modified = ""
override fun getLastModified(): Date {
return server_modified.parseDate()

View File

@ -1,7 +1,8 @@
package com.unciv.logic.multiplayer.storage
import com.unciv.logic.UncivShowableException
import java.util.*
import java.util.Date
import java.io.FileNotFoundException // Kdoc only
class FileStorageConflictException : Exception()
class FileStorageRateLimitReached(val limitRemainingSeconds: Int) : UncivShowableException("Server limit reached! Please wait for [${limitRemainingSeconds}] seconds")

View File

@ -1,7 +1,6 @@
package com.unciv.logic.trade
import com.unciv.logic.IsPartOfGameInfoSerialization
import java.util.*
class TradeOffersList: ArrayList<TradeOffer>(), IsPartOfGameInfoSerialization {
override fun add(element: TradeOffer): Boolean {