Files
Project-M/Assets/_Project/Scripts/Simulation/Combat/ZoneEnemyComponents.cs
T
kronic 56cf60cce3 Slice Combat Depth (MC-2): enemy-variety server spine — Spitter, Swarmer, 4-type mix (DR-041)
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>
2026-06-24 20:06:56 -07:00

68 lines
3.5 KiB
C#

using Unity.Entities;
namespace ProjectM.Simulation
{
/// <summary>
/// Marker on a runtime-spawned EXPEDITION combat enemy (a Husk variant the server's ZoneEnemyDirectorSystem
/// instantiates in the expedition region). Distinguishes zone enemies from base-siege Husks for the single
/// teardown point in ExpeditionFieldSystem and for the per-epoch clear count. Zone enemies ALSO keep
/// <c>EnemyTag</c> + <c>RegionTag{Expedition}</c>, so Slice-1 readability/health-bars/telegraphs/damage and the
/// per-region AI target filter all work for them unchanged.
/// </summary>
public struct ZoneEnemyTag : IComponentData { }
/// <summary>
/// Baked config for the expedition zone-enemy director (one singleton in the gameplay subscene; the server-only
/// ZoneEnemyDirectorSystem reads it). One epoch-seeded wave per sortie: a <see cref="GruntsPerWave"/> +
/// <see cref="ChargersPerWave"/> baseline that shifts grunt-&gt;charger as the expedition epoch climbs (the
/// highest-leverage variety lever), spawned one every <see cref="SpawnIntervalTicks"/> at a deterministic ring of
/// <see cref="RingSlots"/> slots / <see cref="RingRadius"/> around the expedition origin, capped at
/// <see cref="MaxAlive"/> concurrent (the v1 ghost-relevancy mitigation). On a real clear the returning player
/// banks <see cref="RewardOre"/> to the shared ledger, once per epoch.
/// </summary>
public struct ZoneEnemyDirector : IComponentData
{
public int MaxAlive;
public float RingRadius;
public int RingSlots;
public int SpawnIntervalTicks;
public int GruntsPerWave;
public int ChargersPerWave;
// MC-2 mix bands (the director builds a ZoneEnemyMath.MixBands from these): GruntsPerWave/ChargersPerWave
// above are the Grunt/Charger BASE counts; these add the Spitter/Swarmer bases + per-epoch ramps + the pack.
public int SpitterBase;
public int SwarmerSlotBase;
public int ChargerPerEpoch;
public int SpitterPerEpoch;
public int SwarmerSlotPerEpoch;
public int SwarmerPackSize; // swarmers per swarmer-slot cluster (>=1)
public int SwarmerPackPerEpoch; // exposed pack ramp (v1 default 0 = fixed)
public float ClusterTightRadius; // tight ring radius for a swarmer pack
public int RewardOre;
}
/// <summary>
/// Baked pool of zone-enemy prefab variants the director draws from by composition. Index 0 = Grunt variant,
/// index 1 = Charger variant (see <see cref="ZoneEnemyMath.IsChargerSlot"/>). Aliases the existing Husk ghost
/// prefabs so zone enemies reuse the whole combat/readability stack with no new ghost type.
/// </summary>
public struct ZoneEnemyPrefab : IBufferElementData
{
public Entity Prefab;
}
/// <summary>
/// Runtime state of the zone-enemy director (server-only singleton; NOT replicated). Tracks its OWN spawn
/// counter (never WaveState.SpawnCounter), how many enemies remain to spawn for the current epoch's wave, the
/// next spawn tick, and the epoch the current wave was seeded for (re-syncs when CycleRuntime.ExpeditionEpoch
/// bumps). All session-scoped: 0-defaults safely on load (no SaveData field — DR-040 defers SaveData v6).
/// </summary>
public struct ZoneEnemyState : IComponentData
{
public uint SpawnCounter;
public int RemainingToSpawn;
public uint NextSpawnTick;
public int SeededEpoch;
}
}