import org.bson.conversions.Bson
import org.litote.kmongo.*
import java.time.Instant
+import kotlin.random.Random
@Serializable
data class Admiral(
})
}
-fun genAI(faction: Faction, forBattleSize: BattleSize) = Admiral(
- id = Id("advanced_robotical_admiral"),
- owningUser = Id("fake_player_actually_an_AI"),
- name = "M-5 Computational Unit",
- isFemale = true,
- faction = faction,
- acumen = AdmiralRank.values().first {
- it.maxBattleSize >= forBattleSize
- }.minAcumen + 500,
- money = 0
-)
+fun genAIName(faction: Faction, isFemale: Boolean) = AdmiralNames.randomName(AdmiralNameFlavor.forFaction(faction).random(), isFemale)
+
+fun genAI(faction: Faction, forBattleSize: BattleSize): Admiral {
+ val isFemale = Random.nextBoolean()
+
+ return Admiral(
+ id = Id("advanced_robotical_admiral"),
+ owningUser = Id("fake_player_actually_an_AI"),
+ name = genAIName(faction, isFemale),
+ isFemale = isFemale,
+ faction = faction,
+ acumen = AdmiralRank.values().first {
+ it.maxBattleSize >= forBattleSize
+ }.minAcumen + 500,
+ money = 0
+ )
+}
infix fun AdmiralRank.Companion.eq(rank: AdmiralRank): Bson = when (rank.ordinal) {
0 -> Admiral::acumen lt AdmiralRank.values()[1].minAcumen
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import kotlin.coroutines.CoroutineContext
+import kotlin.coroutines.EmptyCoroutineContext
import kotlin.reflect.KClass
import kotlin.reflect.KProperty1
}
fun <T : DataDocument<T>> create(kclass: KClass<T>, initFunc: suspend DocumentTable<T>.() -> Unit = {}): DocumentTable<T> = DocumentTableImpl(kclass) {
- runBlocking {
+ val nameContext = kclass.simpleName?.let { name -> CoroutineName(name) } ?: EmptyCoroutineContext
+ runBlocking(coroutineContext + nameContext) {
it.initFunc()
}
}
}
override suspend fun index(vararg properties: KProperty1<T, *>) {
- collection().ensureIndex(*properties)
+ if (properties.isNotEmpty())
+ collection().ensureIndex(*properties)
}
override suspend fun unique(vararg properties: KProperty1<T, *>) {
- collection().ensureUniqueIndex(*properties)
+ if (properties.isNotEmpty())
+ collection().ensureUniqueIndex(*properties)
}
override suspend fun put(doc: T) {
}
override suspend fun put(docs: Iterable<T>) {
- collection().bulkWrite(
- docs.map { doc ->
- replaceOne(KMongoUtil.idFilterQuery(doc.id), doc, ReplaceOptions().upsert(true))
- },
- BulkWriteOptions().ordered(false)
- )
+ if (docs.any())
+ collection().bulkWrite(
+ docs.map { doc ->
+ replaceOne(KMongoUtil.idFilterQuery(doc.id), doc, ReplaceOptions().upsert(true))
+ },
+ BulkWriteOptions().ordered(false)
+ )
}
override suspend fun set(id: Id<T>, set: Bson): Boolean {
val deployWidth2 = battleWidth / 2
val deployLength2 = 875.0
- val hostDeployCenter = Position(Vec2(0.0, (-battleLength / 2) + deployLength2))
+ val deployWidth4 = deployWidth2 / 2
+
+ val hostDeployCenter1 = Position(Vec2(deployWidth4, (-battleLength / 2) + deployLength2))
+ val hostDeployCenter2 = Position(Vec2(-deployWidth4, (-battleLength / 2) + deployLength2))
val guestDeployCenter = Position(Vec2(0.0, (battleLength / 2) - deployLength2))
val aiAdmiral = genAI(enemyFaction, battleInfo.size)
hostStarts = mapOf(
GlobalShipController.Player1Disambiguation to PlayerStart(
- cameraPosition = hostDeployCenter,
+ cameraPosition = hostDeployCenter1,
cameraFacing = PI / 2,
- deployZone = PickBoundary.Rectangle(hostDeployCenter, deployWidth2, deployLength2),
+ deployZone = PickBoundary.Rectangle(hostDeployCenter1, deployWidth4, deployLength2),
deployFacing = PI / 2,
deployableFleet = getAdmiralsShips(player1Info.id.reinterpret()).filterValues { it.shipType.weightClass.tier <= battleInfo.size.maxTier },
deployPointsFactor = 0.75
),
GlobalShipController.Player2Disambiguation to PlayerStart(
- cameraPosition = hostDeployCenter,
+ cameraPosition = hostDeployCenter2,
cameraFacing = PI / 2,
- deployZone = PickBoundary.Rectangle(hostDeployCenter, deployWidth2, deployLength2),
+ deployZone = PickBoundary.Rectangle(hostDeployCenter2, deployWidth4, deployLength2),
deployFacing = PI / 2,
deployableFleet = getAdmiralsShips(player2Info.id.reinterpret()).filterValues { it.shipType.weightClass.tier <= battleInfo.size.maxTier },
deployPointsFactor = 0.75