using Unity.Mathematics; namespace ProjectM.Simulation { /// /// Pure, deterministic composition math for the expedition zone-enemy wave — no RNG state, no wall-clock — so the /// per-epoch wave is reproducible across restarts/saves and EditMode-unit-testable without an ECS world (mirrors /// / ProductionMath). The highest-leverage Slice-3 variety lever: the encounter /// COMPOSITION shifts grunt-heavy -> charger-heavy as the expedition epoch climbs (grunt count stays /// fixed; the per-epoch growth is all chargers). /// public static class ZoneEnemyMath { /// /// Total enemies in this epoch's wave: the baked + /// baseline plus one extra per epoch beyond the first (a gentle ramp). Lower-bounded at 1 so an occupied /// expedition always has a fight. is the monotonic sortie counter (>=1 in practice). /// public static int WaveSize(int epoch, int gruntsPerWave, int chargersPerWave) { int e = math.max(1, epoch); int baseCount = math.max(0, gruntsPerWave) + math.max(0, chargersPerWave); return math.max(1, baseCount + (e - 1)); } /// /// Deterministic grunt/charger pick for spawn of this epoch's wave. The charger /// count is + (epoch - 1), clamped to the wave size, assigned to the LAST /// slots; everything earlier is a Grunt. So the grunt count stays fixed at /// and the wave skews charger-heavy as the epoch climbs. Returns true for a Charger slot. Stable per /// (epoch, slot) — a replayed wave is identical. Pure integer math (Burst-safe; no enum, no RNG). /// public static bool IsChargerSlot(int epoch, int slot, int gruntsPerWave, int chargersPerWave) { int e = math.max(1, epoch); int size = WaveSize(epoch, gruntsPerWave, chargersPerWave); int chargers = math.clamp(math.max(0, chargersPerWave) + (e - 1), 0, size); int s = ((slot % size) + size) % size; return s >= size - chargers; } // ---- MC-2: 4-type weighted composition (Grunt/Charger/Spitter/Swarmer), shared by both directors ---- // Kind bytes (NO C# enum — directors index a per-Kind prefab buffer by these; EnemyAISystem is Bursted). public const byte KindGrunt = 0; public const byte KindCharger = 1; public const byte KindSpitter = 2; public const byte KindSwarmer = 3; /// /// Total SLOTS in this epoch/wave under : GruntBase + the per-kind ramped counts /// (charger/spitter/swarmer-slot = base + perEpoch*(epoch-1)). Lower-bounded at 1 so there is always a fight. /// A swarmer SLOT expands to a pack at spawn (), so this counts packs, not /// individual swarmers. For the LEGACY band it equals (parity-tested). Pure integer. /// public static int WaveSlots(int epoch, in MixBands bands) { int e = math.max(1, epoch); int grunts = math.max(0, bands.GruntBase); int chargers = math.max(0, bands.ChargerBase + bands.ChargerPerEpoch * (e - 1)); int spitters = math.max(0, bands.SpitterBase + bands.SpitterPerEpoch * (e - 1)); int swarmers = math.max(0, bands.SwarmerSlotBase + bands.SwarmerSlotPerEpoch * (e - 1)); return math.max(1, grunts + chargers + spitters + swarmers); } /// /// Deterministic Kind byte for spawn of this epoch/wave. Slots are partitioned in a /// FIXED order — Grunts, then Spitters, then Chargers, then Swarmer-slots last — so the wave skews threat-heavy /// as the ramped counts climb (Grunts are the remainder = a fixed floor). Any leftover slot (when the kinds /// under-fill the max(1,..) floor) defaults to Grunt. Stable per (epoch, slot). For the LEGACY band this /// returns KindCharger on exactly the slots the old did (parity-tested). Pure. /// public static byte KindForSlot(int epoch, int slot, in MixBands bands) { int e = math.max(1, epoch); int size = WaveSlots(epoch, bands); int chargers = math.max(0, bands.ChargerBase + bands.ChargerPerEpoch * (e - 1)); int spitters = math.max(0, bands.SpitterBase + bands.SpitterPerEpoch * (e - 1)); int swarmers = math.max(0, bands.SwarmerSlotBase + bands.SwarmerSlotPerEpoch * (e - 1)); int grunts = math.max(0, size - chargers - spitters - swarmers); // remainder = fixed grunt floor int s = ((slot % size) + size) % size; if (s < grunts) return KindGrunt; s -= grunts; if (s < spitters) return KindSpitter; s -= spitters; if (s < chargers) return KindCharger; s -= chargers; if (s < swarmers) return KindSwarmer; return KindGrunt; // defensive: unreachable while counts sum to size } /// /// Swarmer cluster size for a swarmer slot: plus the (default-0) /// ramp. Lower-bounded at 1. v1 bakes the ramp 0 -> a fixed pack; /// the field is exposed for later tuning. /// public static int PackSizeForSlot(int epoch, int slot, in MixBands bands, int basePackSize) { int e = math.max(1, epoch); return math.max(1, basePackSize + math.max(0, bands.SwarmerPackPerEpoch) * (e - 1)); } } }