From: TheSaminator Date: Mon, 4 Jul 2022 20:55:31 +0000 (-0400) Subject: Generate ships for fleet X-Git-Url: https://gitweb.starshipfights.net/?a=commitdiff_plain;h=1975078b2e3bf0bd3f6f921f8c3a9c78661fc890;p=starship-fights Generate ships for fleet --- diff --git a/src/jvmMain/kotlin/net/starshipfights/campaign/cluster_fleets.kt b/src/jvmMain/kotlin/net/starshipfights/campaign/cluster_fleets.kt new file mode 100644 index 0000000..85cf934 --- /dev/null +++ b/src/jvmMain/kotlin/net/starshipfights/campaign/cluster_fleets.kt @@ -0,0 +1,63 @@ +package net.starshipfights.campaign + +import net.starshipfights.data.Id +import net.starshipfights.data.admiralty.newShipName +import net.starshipfights.data.invoke +import net.starshipfights.game.* +import net.starshipfights.game.ai.weightedRandom + +val FactionFlavor.shipSource: Faction + get() = when (this) { + FactionFlavor.MECHYRDIA -> Faction.MECHYRDIA + FactionFlavor.TYLA -> Faction.MECHYRDIA + FactionFlavor.OLYMPIA -> Faction.MECHYRDIA + FactionFlavor.TEXANDRIA -> Faction.MECHYRDIA + + FactionFlavor.NDRC -> Faction.NDRC + FactionFlavor.CCC -> Faction.NDRC + FactionFlavor.MJOLNIR_ENERGY -> Faction.NDRC + + FactionFlavor.MASRA_DRAETSEN -> Faction.MASRA_DRAETSEN + FactionFlavor.AEDON_CULTISTS -> Faction.MASRA_DRAETSEN + FactionFlavor.FERTHLON_EXILES -> Faction.MASRA_DRAETSEN + + FactionFlavor.RES_NOSTRA -> Faction.FELINAE_FELICES + FactionFlavor.CORSAIRS -> Faction.FELINAE_FELICES + FactionFlavor.FELINAE_FELICES -> Faction.FELINAE_FELICES + + FactionFlavor.ISARNAREYKK -> Faction.ISARNAREYKK + FactionFlavor.SWARTAREYKK -> Faction.ISARNAREYKK + FactionFlavor.THEUDAREYKK -> Faction.ISARNAREYKK + FactionFlavor.STAHLAREYKK -> Faction.ISARNAREYKK + FactionFlavor.LYUDAREYKK -> Faction.ISARNAREYKK + FactionFlavor.NEUIA_FULKREYKK -> Faction.ISARNAREYKK + + FactionFlavor.CORVUS_CLUSTER_VESTIGIUM -> Faction.VESTIGIUM + FactionFlavor.COLEMAN_SF_BASE_VESTIGIUM -> Faction.VESTIGIUM + } + +fun genNPCFleet(owner: FactionFlavor, rank: AdmiralRank): Map, Ship> { + val battleSize = BattleSize.values().filter { rank >= it.minRank }.associateWith { 100.0 / it.numPoints }.weightedRandom() + + val possibleShips = ShipType.values().filter { it.faction == owner.shipSource && it.weightClass.tier <= battleSize.maxTier } + val maxPoints = battleSize.numPoints + + val chosenShipTypes = buildList { + while (true) + this += possibleShips.filter { ship -> + this.sumOf { it.pointCost } + ship.pointCost <= maxPoints + }.randomOrNull() ?: break + } + + val chosenNames = mutableSetOf() + return chosenShipTypes.mapNotNull { shipType -> + newShipName(owner.shipSource, shipType.weightClass, chosenNames)?.let { name -> + Ship( + id = Id(), + name = name, + shipType = shipType, + shipFlavor = owner + ) + } + }.associateBy { it.id } +} diff --git a/src/jvmMain/kotlin/net/starshipfights/campaign/cluster_test.kt b/src/jvmMain/kotlin/net/starshipfights/campaign/cluster_test.kt index 84d4778..252c6b9 100644 --- a/src/jvmMain/kotlin/net/starshipfights/campaign/cluster_test.kt +++ b/src/jvmMain/kotlin/net/starshipfights/campaign/cluster_test.kt @@ -22,15 +22,17 @@ fun StarClusterView.testPostProcess(): StarClusterView { val numOfFleets = (0..2).random() + (0..2).random() + 1 val fleets = (1..numOfFleets).associate { _ -> + val admiralRank = AdmiralRank.values().random() val admiralIsFemale = flavor == FactionFlavor.FELINAE_FELICES || Random.nextBoolean() + val admiralFleet = genNPCFleet(flavor, admiralRank) Id() to FleetPresence( name = flavor.genFleetName(), owner = flavor, - ships = emptyMap(), + ships = admiralFleet, admiralName = AdmiralNames.randomName(AdmiralNameFlavor.forFactionFlavor(flavor).random(), admiralIsFemale), admiralIsFemale = admiralIsFemale, - admiralRank = AdmiralRank.values().random() + admiralRank = admiralRank ) }