56cf60cce3
Adds the server-authoritative mechanics for three new enemy archetypes on top of the Grunt/Charger base, plus the weighted wave-composition that introduces them: - Spitter: a ranged Husk variant (SpitterState) that holds a preferred range-band (advance/retreat/hold via EnemyAIMath.BandVelocity) and fires a telegraphed, dodgeable EnemyProjectile. New server EnemyProjectileMoveSystem (integrate + store LastStep) + EnemyProjectileDamageSystem (region-filtered swept hit-test rebuilt from LastStep — DR-018 anti-tunnelling; players use HitRadius, structures a const radius; at-most-once destroy). Concurrent-spit soft cap, soft-fail retry. - Swarmer: marker tag + deterministic cluster spawn (1 slot = 1 pack; EnemyAIMath.ClusterOffset), MaxAlive counts ENTITIES so a pack defers if it won't fit. - 4-type weighted mix: MixBands -> ZoneEnemyMath.WaveSlots/KindForSlot/ PackSizeForSlot drives both the expedition director and (fork-4a) the base siege, with a mandatory MaxAlive cap. Legacy WaveSize/IsChargerSlot kept + parity-tested. - Discriminator stays component-presence (no enum in Bursted systems): query- partition guards keep each enemy moved by exactly one EnemyAISystem pass (sole-Position-writer). EnemyTelegraph.IsCharger -> Kind byte for the client cue. New authoring (Spitter/Swarmer/EnemyProjectile) + expanded director authorings with tunable mix/cluster defaults. 13 new EditMode tests (mix composition + legacy parity, band/cluster math, projectile move + cross-region + swept anti-tunnelling regressions); full suite green before commit. Dormant until the prefab/subscene wiring lands (next): the new systems guard on TryGetSingleton/RequireForUpdate, so with no prefabs wired the new types stay inert. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
104 lines
5.9 KiB
C#
104 lines
5.9 KiB
C#
using Unity.Mathematics;
|
|
|
|
namespace ProjectM.Simulation
|
|
{
|
|
/// <summary>
|
|
/// 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
|
|
/// <see cref="EnemyAIMath"/> / <c>ProductionMath</c>). The highest-leverage Slice-3 variety lever: the encounter
|
|
/// COMPOSITION shifts grunt-heavy -> charger-heavy as the expedition <c>epoch</c> climbs (grunt count stays
|
|
/// fixed; the per-epoch growth is all chargers).
|
|
/// </summary>
|
|
public static class ZoneEnemyMath
|
|
{
|
|
/// <summary>
|
|
/// Total enemies in this epoch's wave: the baked <paramref name="gruntsPerWave"/> + <paramref name="chargersPerWave"/>
|
|
/// baseline plus one extra per epoch beyond the first (a gentle ramp). Lower-bounded at 1 so an occupied
|
|
/// expedition always has a fight. <paramref name="epoch"/> is the monotonic sortie counter (>=1 in practice).
|
|
/// </summary>
|
|
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));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Deterministic grunt/charger pick for spawn <paramref name="slot"/> of this epoch's wave. The charger
|
|
/// count is <paramref name="chargersPerWave"/> + (epoch - 1), clamped to the wave size, assigned to the LAST
|
|
/// slots; everything earlier is a Grunt. So the grunt count stays fixed at <paramref name="gruntsPerWave"/>
|
|
/// 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).
|
|
/// </summary>
|
|
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;
|
|
|
|
/// <summary>
|
|
/// Total SLOTS in this epoch/wave under <paramref name="bands"/>: 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 (<see cref="PackSizeForSlot"/>), so this counts packs, not
|
|
/// individual swarmers. For the LEGACY band it equals <see cref="WaveSize"/> (parity-tested). Pure integer.
|
|
/// </summary>
|
|
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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Deterministic Kind byte for spawn <paramref name="slot"/> 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 <see cref="IsChargerSlot"/> did (parity-tested). Pure.
|
|
/// </summary>
|
|
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
|
|
}
|
|
|
|
/// <summary>
|
|
/// Swarmer cluster size for a swarmer slot: <paramref name="basePackSize"/> plus the (default-0)
|
|
/// <see cref="MixBands.SwarmerPackPerEpoch"/> ramp. Lower-bounded at 1. v1 bakes the ramp 0 -> a fixed pack;
|
|
/// the field is exposed for later tuning.
|
|
/// </summary>
|
|
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));
|
|
}
|
|
}
|
|
}
|