Generate ships for fleet
authorTheSaminator <thesaminator@users.noreply.github.com>
Mon, 4 Jul 2022 20:55:31 +0000 (16:55 -0400)
committerTheSaminator <thesaminator@users.noreply.github.com>
Mon, 4 Jul 2022 20:55:31 +0000 (16:55 -0400)
src/jvmMain/kotlin/net/starshipfights/campaign/cluster_fleets.kt [new file with mode: 0644]
src/jvmMain/kotlin/net/starshipfights/campaign/cluster_test.kt

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 (file)
index 0000000..85cf934
--- /dev/null
@@ -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<Id<Ship>, 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<String>()
+       return chosenShipTypes.mapNotNull { shipType ->
+               newShipName(owner.shipSource, shipType.weightClass, chosenNames)?.let { name ->
+                       Ship(
+                               id = Id(),
+                               name = name,
+                               shipType = shipType,
+                               shipFlavor = owner
+                       )
+               }
+       }.associateBy { it.id }
+}
index 84d4778f4b2df81658f0305e92060be3830781ca..252c6b9b9a81c7f5851799ec7b4713a0180a4062 100644 (file)
@@ -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<FleetPresence>() 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
                        )
                }